blob_id stringlengths 40 40 | directory_id stringlengths 40 40 | path stringlengths 2 247 | content_id stringlengths 40 40 | detected_licenses listlengths 0 57 | license_type stringclasses 2 values | repo_name stringlengths 4 111 | snapshot_id stringlengths 40 40 | revision_id stringlengths 40 40 | branch_name stringlengths 4 58 | visit_date timestamp[ns]date 2015-07-25 18:16:41 2023-09-06 10:45:08 | revision_date timestamp[ns]date 1970-01-14 14:03:36 2023-09-06 06:22:19 | committer_date timestamp[ns]date 1970-01-14 14:03:36 2023-09-06 06:22:19 | github_id int64 3.89k 689M ⌀ | star_events_count int64 0 209k | fork_events_count int64 0 110k | gha_license_id stringclasses 25 values | gha_event_created_at timestamp[ns]date 2012-06-07 00:51:45 2023-09-14 21:58:52 ⌀ | gha_created_at timestamp[ns]date 2008-03-27 23:40:48 2023-08-24 19:49:39 ⌀ | gha_language stringclasses 159 values | src_encoding stringclasses 34 values | language stringclasses 1 value | is_vendor bool 1 class | is_generated bool 2 classes | length_bytes int64 7 10.5M | extension stringclasses 111 values | filename stringlengths 1 195 | text stringlengths 7 10.5M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ccb1bd98228fe07456deae4f81b92c808a16c35c | bd498cbbb28e33370298a84b693f93a3058d3138 | /Fujitsu/benchmarks/resnet/implementations/implementation_open/mxnet/src/executor/conv_bn_fuse_pass.cc | d3c64d2114dd7e4139ff87f073e32ac274b88885 | [
"Apache-2.0",
"BSD-3-Clause",
"LicenseRef-scancode-generic-cla",
"Zlib",
"BSD-2-Clause-Views",
"NCSA",
"OFL-1.0",
"Unlicense",
"BSL-1.0",
"BSD-2-Clause",
"MIT"
] | permissive | piyushghai/training_results_v0.7 | afb303446e75e3e9789b0f6c40ce330b6b83a70c | e017c9359f66e2d814c6990d1ffa56654a73f5b0 | refs/heads/master | 2022-12-19T16:50:17.372320 | 2020-09-24T01:02:00 | 2020-09-24T18:01:01 | 298,127,245 | 0 | 1 | Apache-2.0 | 2020-09-24T00:27:21 | 2020-09-24T00:27:21 | null | UTF-8 | C++ | false | false | 7,716 | cc | conv_bn_fuse_pass.cc | /*
* 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.
*/
/*!
* Copyright (c) 2019 by Contributors
* \file convbn_fuse_pass.cc
* \brief detect whether fused conv + bn is possible
* \author Clement Fuji Tsang
*/
#include <mxnet/base.h>
#include <mxnet/operator.h>
#include <mxnet/op_attr_types.h>
#include <nnvm/graph_attr_types.h>
#include "./exec_pass.h"
#include "../operator/nn/activation-inl.h"
#include "../operator/nn/batch_norm-inl.h"
#include "../operator/nn/convolution-inl.h"
#include "../operator/nn/norm_convolution-inl.h"
#include "../operator/tensor/broadcast_reduce_op.h"
namespace mxnet {
namespace exec {
using namespace mxnet::op;
namespace {
#if DEBUG
void PrintGraph(const Graph& g) {
LOG(INFO) << "######## GRAPH IS ########";
const auto ne_counter = GetNodeEntryCount(g);
DFSVisit(g.outputs, [&ne_counter](const nnvm::NodePtr& n) {
if (n->op() == nullptr) {
LOG(INFO) << n->attrs.name << ":";
} else {
LOG(INFO) << n->attrs.name << ": " << n->op()->name;
}
if (n->op() != nullptr) {
if (n->op() == Op::Get("NormalizedConvolution") ||
n->op() == Op::Get("Convolution") ||
n->op() == Op::Get("BatchNorm")) {
for (const auto& p : n->attrs.dict) {
LOG(INFO) << " - " << p.first << ": " << p.second;
}
}
LOG(INFO) << " INPUTS:";
for (const auto& e : n->inputs) {
LOG(INFO) << " - " << e.node->attrs.name << " | " << e.index
<< " | " << ne_counter.at(e);
}
}
});
}
#endif
bool IsCompatibleBN(const nnvm::NodePtr& node, const TShape& shape) {
if (node->op() != Op::Get("BatchNorm"))
return false;
auto param = nnvm::get<BatchNormParam>(node->attrs.parsed);
return (shape.ndim() - 1 == param.axis || param.axis == -1);
}
void ConvToNormConv(const nnvm::NodePtr& node) {
static const Op* norm_conv_op = Op::Get("NormConvolution");
nnvm::NodeAttrs attrs;
attrs.name = node->attrs.name + "_normalized";
std::vector<std::string> transferable_conv_dict_params =
{"kernel", "stride", "dilate", "pad", "num_filter", "num_group", "layout"};
for (auto& s : transferable_conv_dict_params) {
const auto& it = node->attrs.dict.find(s);
if (it != node->attrs.dict.end())
attrs.dict.insert({s, it->second});
}
attrs.dict.insert({"no_norm", "True"});
attrs.op = norm_conv_op;
norm_conv_op->attr_parser(&attrs);
node->attrs = attrs;
}
void NormConvToConv(const nnvm::NodePtr& node) {
static const Op* conv_op = Op::Get("Convolution");
node->attrs.name.erase(node->attrs.name.end() - 11, node->attrs.name.end());
node->attrs.op = conv_op;
node->attrs.dict.erase("no_norm");
node->attrs.dict.insert({"no_bias", "True"});
conv_op->attr_parser(&(node->attrs));
}
void FuseBatchNorm(const nnvm::NodePtr prev_conv, const nnvm::NodePtr bn,
const nnvm::NodePtr next_conv,
nnvm::NodeEntryMap<nnvm::NodeEntry>* entry_map) {
next_conv->attrs.dict["no_norm"] = "False";
std::vector<std::string> transferable_bn_dict_params =
{"act_type", "eps", "momentum", "fix_gamma", "use_global_stats", "output_mean_var"};
for (auto& s : transferable_bn_dict_params) {
const auto& it = bn->attrs.dict.find(s);
if (it != bn->attrs.dict.end())
next_conv->attrs.dict.insert({s, it->second});
}
next_conv->inputs.resize(8);
next_conv->inputs[norm_conv::kData] =
nnvm::NodeEntry{prev_conv, norm_conv::kOut, 0};
next_conv->inputs[norm_conv::kWeight] =
next_conv->inputs[norm_conv::kWeightNoNorm];
next_conv->inputs[norm_conv::kInSum] =
nnvm::NodeEntry{prev_conv, norm_conv::kOutSum, 0};
next_conv->inputs[norm_conv::kInSumOfSquares] =
nnvm::NodeEntry{prev_conv, norm_conv::kOutSumOfSquares, 0};
next_conv->inputs[norm_conv::kGamma] =
bn->inputs[batchnorm::kGamma];
next_conv->inputs[norm_conv::kBeta] =
bn->inputs[batchnorm::kBeta];
next_conv->inputs[norm_conv::kMovingMean] =
bn->inputs[batchnorm::kInMovingMean];
next_conv->inputs[norm_conv::kMovingVar] =
bn->inputs[batchnorm::kInMovingVar];
next_conv->op()->attr_parser(&(next_conv->attrs));
entry_map->insert({nnvm::NodeEntry{bn, batchnorm::kMean, 0},
nnvm::NodeEntry{next_conv, norm_conv::kSavedMean, 0}});
entry_map->insert({nnvm::NodeEntry{bn, batchnorm::kVar, 0},
nnvm::NodeEntry{next_conv, norm_conv::kSavedInvStdDev, 0}});
}
} // namespace
Graph FuseConvBN(Graph&& g) {
// shapes, dtypes and context are necessary for checking compatibility with NormConvolution
const auto& shape_vec = g.GetAttr<mxnet::ShapeVector>("shape");
const auto& dtype_vec = g.GetAttr<nnvm::DTypeVector>("dtype");
const auto& context_vec = g.GetAttr<ContextVector>("context");
auto& idx = g.indexed_graph();
// NormConvolution can have the same behavior than Convolution
// So we convert compatible Convolution regardless of BN presence
// We can always convert back to Convolution after
DFSVisit(g.outputs, [&idx, &shape_vec, &dtype_vec, &context_vec](const nnvm::NodePtr node) {
if (node->op() == Op::Get("Convolution")) {
auto eid = idx.entry_id(node->inputs[0]);
auto nid = idx.node_id(node.get());
if (norm_conv::IsCompatibleConvolution(node, dtype_vec[eid], shape_vec[eid],
context_vec[nid]))
ConvToNormConv(node);
}
});
// Fuse NormConv + BN + NormConv => NormConv + NormConv
auto ne_counter = GetNodeEntryCount(g);
nnvm::NodeEntryMap<nnvm::NodeEntry> entry_map;
DFSVisit(g.outputs, [&idx, &shape_vec, &ne_counter, &entry_map](const nnvm::NodePtr& next) {
if (next->op() == Op::Get("NormConvolution")) {
auto node = next->inputs[0].node;
auto eid = idx.entry_id(idx.node_id(node.get()), 0);
if (IsCompatibleBN(node, shape_vec[eid]) &&
next->inputs[0].index == 0 &&
ne_counter[next->inputs[0]] == 1) {
auto prev = node->inputs[0].node;
if (prev->op() == Op::Get("NormConvolution") &&
ne_counter[node->inputs[0]] == 1) {
FuseBatchNorm(prev, node, next, &entry_map);
}
}
}
});
g = ReplaceNodeEntries(std::move(g), entry_map);
// Transform NormalizedConvolution without any ApplyStats or GenStats to Convolution
ne_counter = GetNodeEntryCount(g);
DFSVisit(g.outputs, [&ne_counter](const nnvm::NodePtr& n) {
if (n->op() == Op::Get("NormConvolution")) {
auto const& param = nnvm::get<NormConvolutionParam>(n->attrs.parsed);
if (param.no_norm &&
ne_counter[nnvm::NodeEntry{n, 1, 0}] == 0 &&
ne_counter[nnvm::NodeEntry{n, 2, 0}] == 0) {
NormConvToConv(n);
}
}
});
return g;
}
} // namespace exec
} // namespace mxnet
|
b197eec0ec2df7549bb16f74d10f9abc7695bd44 | 0abb6aef68b81b6d616658e408ee2979a6104798 | /10950.cpp | 1ae57b4293acde93e0de44ae3a1fe3a5d28ffd38 | [] | no_license | seongwpa/PS | c44b44691a4038dc326a9198d373629f86bf6dc6 | 3f77020becf5eb989cc146b63d550b461af02dbd | refs/heads/master | 2022-10-08T20:39:09.352637 | 2020-06-08T08:21:15 | 2020-06-08T08:21:15 | 270,530,344 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 227 | cpp | 10950.cpp | #include <stdio.h>
int A[100], B[100];
int main() {
int T;
scanf_s("%d", &T);
for (int i = 0; i < T; i++)
scanf_s("%d %d", &A[i], &B[i]);
for (int i = 0; i < T; i++)
printf("%d\n", A[i] + B[i]);
return 0;
} |
7e89cea740349a827aa1f17ca22831812a8921fd | a162830776a07c5d16f1c43b70c17b979af24526 | /poj/star_ship_trooper_1011.cpp | 4208d4cca6ec3bcfa8e1d14a77dd6c87df729e25 | [] | no_license | fancy2110/algorithm | e46c9440b05ca2b69f8fae6cfe0fef6caf5d1cb6 | d564763b28e2141981c0a974455ced1b490cc7ae | refs/heads/master | 2022-02-22T15:15:12.575997 | 2022-01-28T03:57:09 | 2022-01-28T03:57:09 | 107,639,570 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,214 | cpp | star_ship_trooper_1011.cpp | /**
* http://acm.hdu.edu.cn/showproblem.php?pid=1011
*
* input :
*
5 10
50 10
40 10
40 20
65 30
70 30
1 2
1 3
2 4
2 5
1 1
20 7
8 2
0 0
0 9
0 8
0 4
0 7
0 3
0 2
0 1
1 2
1 3
2 4
2 5
4 6
6 7
7 8
5 2
0 1
0 1
0 5
0 1
0 2
1 2
1 3
2 4
2 5
-1 -1
*
* output:
* 50
* 7
*/
#include <iostream>
#include <stdlib.h>
#include <cstring>
struct room
{
//bug count
int count = 0;
//brain possiblity
int percent = 0;
//
bool isOcupy = false;
};
#define DEBUG false
#define EMPTY 0
#define OCUPY 1
#define MAX_TROOPERS = 100
#define RATIO = 20
#define MAX_ROOM = 100
int m, n = 0;
struct room nodes[101];
int tunnels[101][101] = {0};
//为每个节点构建一个访问结果记录
int p[100 + 1][100 + 1] = {0};
int tmp[100 + 1] = {0};
using namespace std;
/**
* 返回值为剩余的兵力
*/
bool get_posibility(int start, int troopers);
void print_result()
{
if (!DEBUG)
return;
cout << "-------------------------------" << endl;
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= m; j++)
{
cout << p[i][j] << ",";
}
cout << endl;
}
cout << endl;
}
bool get_posibility(int start, int troopers)
{
if (troopers == 0)
return false;
struct room &item = nodes[start];
if (DEBUG)
cout << "room[" << start << "] isOcupy:" << item.isOcupy << ", count:" << item.count << ", posibility:" << item.percent << endl;
if (item.isOcupy) //已经被占领了
return false;
if (item.count > troopers * 20) //已经没有足够兵力了
return false;
item.isOcupy = true;
int cost = 0;
if (item.count != 0)
{
int mod_left = item.count % 20;
cost = item.count / 20;
if (mod_left > 0)
{
cost++;
}
}
for (int i = cost; i <= m; i++)
{
p[start][i] = item.percent;
}
for (size_t i = 1; i <= n; i++)
{
if (DEBUG)
cout << "tunnel(" << start << "," << i << "): " << tunnels[start][i] << endl;
if (tunnels[start][i] == 0 || i == start) //没有通道
continue;
int left_troopers = troopers - cost;
if (!get_posibility(i, left_troopers))
continue;
memset(tmp, 0, sizeof(tmp));
for (int j = cost; j <= m; j++)
{
tmp[j] = p[start][j];
}
if (DEBUG)
{
cout << "from " << start << " ocupy(" << i << "), cost:" << cost << ", percent :" << item.percent << endl;
cout << "base room: ";
for (size_t j = 0; j <= m; j++)
{
cout << tmp[j] << ",";
}
cout << endl;
cout << "copy room: ";
for (size_t j = 0; j <= m; j++)
{
cout << p[i][j] << ",";
}
cout << endl;
}
for (size_t t = cost; t <= m; t++)
{
int old_p = tmp[t];
for (size_t o = 1; o + t <= m; o++)
{
int new_p = old_p + p[i][o];
if (new_p > p[start][t + o])
{
p[start][t + o] = new_p;
}
}
}
print_result();
}
item.isOcupy = false;
return true;
}
int main(int argc, char const *argv[])
{
while (true)
{
cin >> n >> m;
if (DEBUG)
cout << "n:" << n << ", m:" << m << endl;
if (n < 0 && m < 0)
break;
int i = 1;
while (i <= n)
{
cin >> nodes[i].count >> nodes[i].percent;
nodes[i].isOcupy = false;
i++;
}
memset(tunnels, 0, sizeof(tunnels));
i = 1;
while (i <= n - 1)
{
int x, y = 0;
cin >> x >> y;
tunnels[x][y] = 1;
tunnels[y][x] = 1;
i++;
}
memset(p, 0, sizeof(p));
int total_trooper = m;
get_posibility(1, total_trooper);
int max = 0;
int position = 0;
if (DEBUG)
print_result();
cout << p[1][m] << endl;
}
}
|
cf220bda41757ac8af266c00d097aa8ea1b07f77 | 90625321434d29be8ccde3355b7d0b4de311f795 | /R823_T/R832ImgFile.cpp | 44c4edd6abdb711b177f168adb34c62dcd31292d | [] | no_license | zhouzhenyou/WIN_Data_Acquisition | 15d927c91c66489c98d9383206b96f45034da8b6 | e797a97b2f5d6160db4c69cffaba4d3d4c62ce98 | refs/heads/master | 2020-05-29T21:01:11.940913 | 2015-01-21T06:23:57 | 2015-01-21T06:23:57 | 23,988,011 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 982 | cpp | R832ImgFile.cpp | /**
*
* CopyRight (c) 2012 IVTCorporation
* All rights reserved
*
* FileName: DFUFile.cpp
*
* Abstract:
*
*
* Author: zhou zhenyou
*
* Modification history:
* 1.1 2012/18/6 File created
* 1.2 2012/7/26 Remold this class
* */
#include "R832ImgFile.h"
// Constructors
ImgFile::ImgFile(const char* file, int Type)
:GSFile(file, Type)
{
memset(&m_img_header, 0, sizeof(img_file_header));
}
ImgFile::~ImgFile()
{
}
void ImgFile::FileReadInit()
{
if (mFp == NULL)
{
return;
}
//fseek(mFp, 0, SEEK_SET);
fread(&m_img_header, 1, sizeof(img_file_header), mFp);
}
void ImgFile::FileWriteInit()
{
if (mFp == NULL)
{
return;
}
m_img_header.file_version = FILE_IMG_TYPE;
fwrite(&m_img_header, 1, sizeof(img_file_header), mFp);
}
void ImgFile::SetRecordHeader(img_record_item arg)
{
m_img_record_header = arg;
}
int ImgFile::GetFileVersion()
{
return m_img_header.file_version;
} |
5f297e56a91abfb784186adf06609ab40fce2950 | 4bfc9fc8924f61de5a3cf16ad23b7c7d64e926c6 | /PrettyEngine/src/engine/Core/Scene3D.h | acca548e6392ffb1ad621f30aebcdcb797d27c06 | [
"Apache-2.0"
] | permissive | wwwK/Pretty_Engine | ad8786c3aa827150c827c3f6b0f5a4f7d7cdb593 | 53a5d305b3de5786223e3ad6775199dbc7b5e90c | refs/heads/master | 2022-09-16T00:02:39.080355 | 2020-05-22T11:43:10 | 2020-05-22T11:43:10 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,226 | h | Scene3D.h | #pragma once
#include "Scene.h"
#include "engine\ECS\Entity.h"
#include "engine\Graphics\Cameras\StaticCamera.h"
#include "engine\Graphics\Renderer3D.h"
namespace PrettyEngine {
class Scene3D : public Scene
{
public:
Scene3D(Camera* camera);
~Scene3D();
virtual void Submit() override;
virtual void RenderScene() override;
virtual void OnEvent(Event & ev) override;
virtual Entity* GetEntityByTag(const String& tag) override;
virtual void AddInternal(void* renderable) override {
if (static_cast<Entity*>(renderable))
{
m_Entities.push_back((Entity*)renderable);
return;
}
if (static_cast<StaticCamera*>(renderable))
{
m_Cameras.push_back((StaticCamera*)renderable);
return;
}
}
virtual void RemoveInternal(void* renderable) override
{
if (static_cast<Entity*>(renderable))
{
auto it = std::find(m_Entities.begin(), m_Entities.end(), renderable);
if (it != m_Entities.end())
{
m_Entities.erase(it);
}
}
}
virtual const std::vector<Entity*>& GetEntitiesInternal() const override { return m_Entities; }
private:
Renderer3D* m_Renderer;
std::vector<Entity*> m_Entities;
std::vector<StaticCamera*> m_Cameras;
};
} |
39b25efc474baf2d53323881187b14d6000d30c1 | 0a997fec3e67f39574797f4f1b81807c530e557f | /src/Location.hpp | d26260bc92ea63082212f40a6cc20bcbbfb5582c | [
"MIT"
] | permissive | davidstraka2/gamebook-engine | f007ec49755b6fbf728fd5bc89c72775cf982a24 | 53fa8d825a056e28ddd90e718af73ab691019fe5 | refs/heads/master | 2020-07-30T11:08:03.725876 | 2019-10-31T12:29:34 | 2019-10-31T12:29:34 | 210,207,667 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,500 | hpp | Location.hpp | #pragma once
#include "Creature.hpp"
#include "Option.hpp"
#include <map>
#include <string>
#include <vector>
class Location {
public:
/** Creature container type */
typedef std::map<std::string, Creature> CreatureContainer;
/** Option container type */
typedef std::vector<Option> OptionContainer;
Location() {}
Location(const std::string& name);
/** Get const access to creatures */
const CreatureContainer& creatures() const;
/** Get non-const access to creatures */
CreatureContainer& creatures();
/** Get const access to options */
const OptionContainer& options() const;
/** Get non-const access to options */
OptionContainer& options();
/** Get name */
const std::string& name() const;
/** Set name */
void name(const std::string& value);
/** Get text */
const std::string& text() const;
/** Set text */
void text(const std::string& value);
/** Add empty option and get non-const access to it */
Option& addOption();
/** Append text to location text (space is auto added before text) */
void appendText(const std::string& text);
/** List all options */
void listOptions(std::vector<std::string>& list) const;
private:
CreatureContainer m_creatures;
OptionContainer m_options;
std::string m_name;
std::string m_text;
};
|
6d1bbb0586abcd0f18ad7f1c421ec911c4538180 | 9497a1cccdc1e2de34c88ad3fafed3ef0fe41102 | /ed-arrays-cc-development/src/main.cc | 4af897da6ccbd0f75f8131e4895d6615c593841c | [] | no_license | rept114/ed-arrays-cc-development | e8c60a22b69d7e1374a76aa97b876ec08d3a6eeb | ae15adf2eba5670cc5b1f49b229895adb7a64f50 | refs/heads/master | 2022-12-23T13:21:58.279429 | 2020-09-07T03:04:46 | 2020-09-07T03:04:46 | 293,408,030 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 610 | cc | main.cc | #include<iostream>
int main()
{
int numbers[6]{100, 87982, 3456, 465, 885, 86};
std::cout << "Array memmory: " << numbers << std::endl;
std::cout << "Array memmory: " << *numbers << std::endl;
/*for(int i = 0; i < 6; i++)
{
std::cout << &numbers[i] << "\t";
}*/
/*for(int i = 0; i < 6; i++)
{
std::cout << numbers + i << "\t";
}*/
/*for(int n : numbers)
{
std::cout << &n << "\t";
}*/
/*for(auto n : numbers)
{
std::cout << n << "\t";
}*/
std::cout << std::endl;
std::cin.get();
return 0;
} |
0879c1c2146b61d55046953ce29ce1db1758898e | 98e657765290c2bbbd12f51788e2880a0b0d16d8 | /bobcat/milter/data.cc | fca770e58435acf74d74a87c32fe621e7f3b72bf | [] | no_license | RoseySoft/bobcat | 70f7394ebfa752a04aeaafa043c2a26f2ab09bd7 | ec358733b07fb1a8018602a46e92e7511ba5a97f | refs/heads/master | 2018-02-24T06:07:50.699146 | 2016-08-17T08:32:41 | 2016-08-17T08:32:41 | 67,193,814 | 1 | 0 | null | 2016-09-02T05:46:56 | 2016-09-02T05:46:55 | null | UTF-8 | C++ | false | false | 145 | cc | data.cc | #include "milter.ih"
string Milter::s_name;
Milter *Milter::s_mp;
bool Milter::s_callClose;
unordered_map<SMFICTX *, Milter *> Milter::s_map;
|
b5b0721697794ce1b5cba55e75191b583852deea | 28dba754ddf8211d754dd4a6b0704bbedb2bd373 | /Topcoder/CandyCollection.cpp | 1d986aafa0809ec33de4530792b4f3b2767378b3 | [] | no_license | zjsxzy/algo | 599354679bd72ef20c724bb50b42fce65ceab76f | a84494969952f981bfdc38003f7269e5c80a142e | refs/heads/master | 2023-08-31T17:00:53.393421 | 2023-08-19T14:20:31 | 2023-08-19T14:20:31 | 10,140,040 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 4,159 | cpp | CandyCollection.cpp | #line 2 "CandyCollection.cpp"
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cassert>
#include <climits>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define abs(x) ((x) > 0 ? (x) : -(x))
#define FOREACH(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
typedef long long LL;
class CandyCollection {
public:
int solve(vector <int> Type1, vector <int> Number1, vector <int> Type2, vector <int> Number2) {
}
// BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arr0[] = {0,0}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1,1}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = {1,1}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); int Arr3[] = {1,1}; vector <int> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); int Arg4 = 2; verify_case(0, Arg4, solve(Arg0, Arg1, Arg2, Arg3)); }
void test_case_1() { int Arr0[] = {0,0}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {2,5}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = {1,1}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); int Arr3[] = {2,5}; vector <int> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); int Arg4 = 3; verify_case(1, Arg4, solve(Arg0, Arg1, Arg2, Arg3)); }
void test_case_2() { int Arr0[] = {0,0,2,3}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1,1,2,2}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = {1,1,3,2}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); int Arr3[] = {1,1,2,2}; vector <int> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); int Arg4 = 5; verify_case(2, Arg4, solve(Arg0, Arg1, Arg2, Arg3)); }
void test_case_3() { int Arr0[] = {0,1,2,3}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {5,5,10,13}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = {1,2,3,0}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); int Arr3[] = {8,8,10,15}; vector <int> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); int Arg4 = 20; verify_case(3, Arg4, solve(Arg0, Arg1, Arg2, Arg3)); }
void test_case_4() { int Arr0[] = {12,9,0,16,9,18,12,3,6,0,8,2,10,6,5,2,14,10,5,13}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {895,704,812,323,334,674,665,142,712,254,869,548,645,663,758,38,860,724,742,530}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = {1,4,7,11,15,8,18,13,17,17,19,14,7,11,4,1,15,19,3,16}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); int Arr3[] = {779,317,36,191,843,289,107,41,943,265,649,447,806,891,730,371,351,7,102,394}; vector <int> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); int Arg4 = 5101; verify_case(4, Arg4, solve(Arg0, Arg1, Arg2, Arg3)); }
// END CUT HERE
};
// BEGIN CUT HERE
int main() {
CandyCollection ___test;
___test.run_test(-1);
return 0;
}
// END CUT HERE
|
c5ca87199038bbf1e9c247f5d58e20abd1ab85bb | 8969abd3550b6dc303ba497ad722f42c4ba2e121 | /elfsectionheaders.h | e7553dc69c0b40b56a8102215a60335572d67a9b | [
"MIT"
] | permissive | justinleona/capstone | a636c1bdfa7e6eb1457e528b7d3e8302471940ad | 4a525cad12fba07a43452776a0e289148f04a12d | refs/heads/master | 2020-08-12T08:17:18.737805 | 2019-10-21T05:00:27 | 2019-10-21T05:00:27 | 214,727,175 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 711 | h | elfsectionheaders.h | #pragma once
#include <iostream>
#include <vector>
#include "elfbinary.h"
#include "elfsectionheader.h"
#include "indent.h"
class ElfSectionHeaders : public Indentable {
const ElfBinary& bin;
std::vector<ElfSectionHeader> sections;
public:
using const_iterator = std::vector<ElfSectionHeader>::const_iterator;
ElfSectionHeaders(const ElfBinary& bin);
ElfSectionHeaders(const ElfBinary& bin, Indent& indent);
/* range of sections, starting with the special "init" section */
const_iterator begin() const;
const_iterator end() const;
friend std::ostream& operator<<(std::ostream& ost, const ElfSectionHeaders&);
friend std::istream& operator>>(std::istream& ist, ElfSectionHeaders&);
};
|
b9c3f200709ac7415d74bed1ac09d58ef65d2d08 | 7cffa9b29f855c68ec5efcf049f596dc7be6bff6 | /src/color/cmy/make/coral.hpp | 3214776ef9fe98dea0d56df9715b2a1ada18beed | [
"Apache-2.0"
] | permissive | lzs4073/color | c4e12e26cfe96022e0a5e6736a7abaadf9912c14 | 290c2c1550c499465f814ba89a214cbec19a72df | refs/heads/master | 2020-04-03T07:16:33.120894 | 2016-02-02T16:18:25 | 2016-02-02T16:18:25 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,835 | hpp | coral.hpp | #ifndef color_cmy_make_coral
#define color_cmy_make_coral
// ::color::make::coral( c )
namespace color
{
namespace make
{ //RGB equivalents: std::array<double,3>( { 0, 0.5, 0.69 } ) - rgb(255,127,79) - #ff7f4f
inline
void coral( ::color::_internal::model< ::color::category::cmy_uint8 > & color_parameter )
{
color_parameter.container() = std::array< std::uint8_t, 3 >( { 0x00, 0x7f, 0xaf } );
}
inline
void coral( ::color::_internal::model< ::color::category::cmy_uint16 > & color_parameter )
{
color_parameter.container() = std::array< std::uint16_t, 3 >( { 0x0000, 0x7fff, 0xb0a3 } );
}
inline
void coral( ::color::_internal::model< ::color::category::cmy_uint32 > & color_parameter )
{
color_parameter.container() = std::array< std::uint32_t, 3 >( { 0x00000000, 0x7fffffff, 0xb0a3d709 } );
}
inline
void coral( ::color::_internal::model< ::color::category::cmy_uint64 > & color_parameter )
{
color_parameter.container() = std::array< std::uint64_t, 3 >( { 0x0000000000000000ull, 0x8000000000000000ull, 0xb0a3d70a3d70a000ull } );
}
inline
void coral( ::color::_internal::model< ::color::category::cmy_float > & color_parameter )
{
color_parameter.container() = std::array<float,3>( { 0, 0.5, 0.69 } );
}
inline
void coral( ::color::_internal::model< ::color::category::cmy_double> & color_parameter )
{
color_parameter.container() = std::array<double,3>( { 0, 0.5, 0.69 } );
}
inline
void coral( ::color::_internal::model< ::color::category::cmy_ldouble> & color_parameter )
{
color_parameter.container() = std::array<long double,3>( { 0, 0.5, 0.69 } );
}
}
}
#endif
|
9e2814a6955c817574b1af97670c338c9afb0d9b | f6b781ce73b63296e3b736d3174d716b0f1b4350 | /SingleList.cpp | eb4bdaaf45a3204466e22bd21207d4906b9ecbac | [] | no_license | Yanyu-CQU/DataStructSample | 542a4d3de2db734275ab279c6ee70451bda9d821 | 28cb4ff24b92a3ca2a66e2c8ea47f6d1294fed75 | refs/heads/master | 2020-03-13T10:52:06.507772 | 2018-08-26T07:13:59 | 2018-08-26T07:13:59 | 131,091,496 | 5 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 9,387 | cpp | SingleList.cpp | #include <iostream>
#include <set>
template <typename T>
struct Node
{
Node* next;
T val;
Node(const T& v = T(),Node* n = nullptr) : val(v), next(n) {};
};
template <typename T>
class SingleList
{
public:
SingleList();
~SingleList();
int getSize();
Node<T>* getHead();
bool isEmpty();
void insert(int pos, const T& v);
void erase(int pos);
void clear();
void print();
void rPrint(Node<T>* pNode);
Node<T>* getPos(int pos);
Node<T>* rGetKthNode(int k);
void reverse();
void selectSort();
void bubbleSort();
void mergeSortedList(SingleList<T>& listMerge);
bool isCircle();
Node<T>* getCircleNode();
bool isHaveInts(SingleList<T>& cmp);
Node<T>* setHead(Node<T>* h){
if(h != nullptr)
head = h;
};
void deleteNode(Node<T>* pNode);
private:
Node<T>* head;
int size;
};
template <typename T>
SingleList<T>::SingleList() : head(nullptr), size(0)
{
}
template <typename T>
SingleList<T>::~SingleList()
{
clear();
}
template <typename T>
int SingleList<T>::getSize()
{
return size;
}
template <typename T>
bool SingleList<T>::isEmpty()
{
return (size == 0);
}
template <typename T>
void SingleList<T>::insert(int pos, const T& v)
{
if (pos < 0 || pos > size) return;
if (head == nullptr) {
head = new Node<T>(v);
head->next = nullptr;
} else if(pos == 0) {
Node<T>* newNode = new Node<T>(v);
newNode->next = head;
head = newNode;
} else {
Node<T>* newNode = new Node<T>(v);
Node<T>* tempNode = head;
for (int i = 0; i < pos - 1; ++i) {
tempNode = tempNode->next;
}
newNode->next = tempNode->next;
tempNode->next = newNode;
}
++size;
return;
}
template <typename T>
void SingleList<T>::erase(int pos)
{
if (pos < 0 || pos >= size) return;
if (pos == 0) {
Node<T>* delNode = head;
head = head->next;
delete delNode;
} else {
Node<T>* tempNode = head;
Node<T>* delNode = nullptr;
for (int i = 0; i < pos - 1; ++i) {
tempNode = tempNode->next;
}
delNode = tempNode->next;
tempNode->next = delNode->next;
delete delNode;
}
--size;
}
template <typename T>
void SingleList<T>::clear()
{
Node<T>* tempNode = head;
Node<T>* delNode = nullptr;
while (tempNode != nullptr) {
delNode = tempNode;
tempNode = tempNode->next;
delete delNode;
}
size = 0;
head = nullptr;
return;
}
template <typename T>
void SingleList<T>::print()
{
Node<T>* printNode = head;
while (printNode != nullptr) {
std::cout << printNode->val << "\t";
printNode = printNode->next;
}
std::cout << "\n";
return;
}
template <typename T>
Node<T>* SingleList<T>:: getPos(int pos)
{
if (pos < 0 || pos >= size) return nullptr;
Node<T>* node = head;
for (int i = 0; i < pos; ++i) {
node = node->next;
}
return node;
}
template <typename T>
Node<T>* SingleList<T>::rGetKthNode(int k)//不知道链表size的写法。。。。。
{
//if (k >= size) return nullptr;
Node<T>* fir = head;
Node<T>* sec = head;
while (k != 0 && fir != nullptr)
{
fir = fir->next;
--k;
}
if (k > 0 || fir == nullptr) return nullptr;
while(fir->next != nullptr)
{
fir = fir->next;
sec = sec->next;
}
return sec;
}
template <typename T>
void SingleList<T>::reverse()
{
if (head == nullptr) return;
Node<T>* pre = head;
Node<T>* cur = head->next;
Node<T>* tempNext = nullptr;
while (cur != nullptr)
{
tempNext = cur->next;
cur->next = pre;
pre = cur;
cur = tempNext;
}
head->next = nullptr;
head = pre;
return;
}
template <typename T>
Node<T>* SingleList<T>::getHead()
{
return this->head;
}
template <typename T>
void SingleList<T>::rPrint(Node<T>* pNode)
{
if (pNode == nullptr) return;
else rPrint(pNode->next);
std::cout << pNode->val << "\t";
if (pNode == head) std::cout << "\n";
}
template <typename T>
void SingleList<T>::selectSort()
{
if (head == nullptr) return;
Node<T>* cur = head;
Node<T>* cmp = nullptr;
while (cur != nullptr)
{
cmp = cur->next;
while (cmp != nullptr)
{
if (cmp->val < cur->val)
{
T t = cur->val;
cur->val = cmp->val;
cmp->val = t;
}
cmp = cmp->next;
}
cur = cur->next;
}
return;
}
template <typename T>
void SingleList<T>::mergeSortedList(SingleList<T>& listMerge)
{
if (head == nullptr || listMerge.getHead() == nullptr) return;
Node<T>* cur = head;
Node<T>* cmp = listMerge.getHead();
int pos = 0;//cur的位置
while (cur != nullptr && cmp != nullptr)
{
if (cur->val > cmp->val)
{
insert(pos,cmp->val);//插入cur前面
pos++;
cmp = cmp->next;
}
else if (cur->val <= cmp->val && cur->next != nullptr && cur->next->val >= cmp->val)//插入cur后面
{
insert(pos + 1, cmp->val);
cmp = cmp->next;
}
else
{
cur = cur->next;
}
}
while (cmp != nullptr)
{
insert(size,cmp->val);
cmp = cmp->next;
}
return;
}
template <typename T>
bool SingleList<T>::isCircle()
{
Node<T>* fir = head;
Node<T>* sec = head;
while (fir != nullptr && fir->next != nullptr)
{
fir = fir->next->next;
sec = sec->next;
if (fir == sec) return true;
}
return false;
}
template <typename T>
Node<T>* SingleList<T>::getCircleNode()
{
if (head == nullptr) return nullptr;
std::set<Node<T>*> count;
count.insert(head);
Node<T>* temp = head->next;
Node<T>* pre = head;
while (temp != nullptr)
{
if (count.insert(temp).second == 0) return pre;
pre = temp;
temp = temp->next;
}
return nullptr;
}
template <typename T>
bool SingleList<T>::isHaveInts(SingleList<T>& cmp)
{
if (head == nullptr || cmp.getHead() == nullptr)
return false;
Node<T>* end1 = head;
Node<T>* end2 = cmp.getHead();
while (end1->next != nullptr)
{
end1 = end1->next;
}
while (end2->next != nullptr)
{
end2 = end2->next;
}
return (end1 == end2);
}
template <typename T>
void SingleList<T>::deleteNode(Node<T>* pNode)
{
if(head == nullptr) return;
else if (head == pNode) erase(0);
else
{
if (pNode->next != nullptr)
{
Node<T>* pNext = pNode->next;
pNode->val = pNext->val;
pNode->next = pNext->next;
delete pNext;
--size;
}
else
{
Node<T>* temp = head;
while (temp->next->next != nullptr)
{
temp = temp->next;
}
temp->next = nullptr;
delete pNode;
--size;
}
}
return;
}
template <typename T>
void SingleList<T>::bubbleSort()
{
for (Node<T>* q = head; q->next != nullptr; q = q->next)
{
Node<T>* p = head;
while (p->next != nullptr)
{
if (p->val > p->next->val)
{
T temp = p->val;
p->val = p->next->val;
p->next->val = temp;
}
p = p->next;
}
}
}
int main()
{
SingleList<int> list;
list.insert(0,1);
std::cout << "insert 1:" << std::endl;
list.print();
list.insert(1,2);
std::cout << "insert 2:" << std::endl;
list.print();
list.insert(2,3);
std::cout << "insert 3:" << std::endl;
list.print();
list.erase(1);
std::cout << "erase pos 1:" << std::endl;
list.print();
list.insert(1,4);
std::cout << "insert 4:" << std::endl;
list.print();
list.erase(0);
std::cout << "erase pos 0:" << std::endl;
list.print();
list.erase(list.getSize() - 1);
std::cout << "erase pos tail:" << std::endl;
list.print();
list.insert(0,5);
std::cout << "insert 5:" << std::endl;
list.print();
list.insert(0,6);
std::cout << "insert 6:" << std::endl;
list.print();
std::cout << "get pos 0: " << list.getPos(0)->val << std::endl;
std::cout << "get pos 1: " << list.getPos(1)->val << std::endl;
std::cout << "get pos tail: " << list.getPos(list.getSize() - 1)->val << std::endl;
std::cout << "get rpos 1: " << list.rGetKthNode(1)->val << std::endl;
list.reverse();
std::cout << "reverse:" << std::endl;
list.print();
std::cout << "reverse print:" << std::endl;
list.rPrint(list.getHead());
/*list.selectSort();
std::cout << "select sort:" << std::endl;
list.print();*/
list.bubbleSort();
std::cout << "bubble sort:" << std::endl;
list.print();
SingleList<int> listMerge;
listMerge.insert(0,5);
listMerge.insert(0,7);
listMerge.insert(0,1);
listMerge.insert(0,8);
listMerge.insert(0,7);
listMerge.selectSort();
std::cout << "listMerge after select sort:" << std::endl;
listMerge.print();
list.mergeSortedList(listMerge);
std::cout << "after merge:" << std::endl;
list.print();
list.getPos(list.getSize() - 1)->next = list.getHead();//强行制造一个环
std::cout << "is have circle:" << list.isCircle() << std::endl;
//list.print();//无限循环打印
Node<int>* end = list.getCircleNode();
end->next = nullptr;
std::cout << "solute the cirle:" << std::endl;
list.print();
/*listMerge.clear();
listMerge.setHead(list.getHead());
std::cout << "make listMerge same as list:" << std::endl;
listMerge.print();*///强行制造相同节点
std::cout << "is have same node:" << list.isHaveInts(listMerge) << std::endl;
list.deleteNode(list.getHead()->next);
std::cout << "delete pos 1 with O(1) time:" << std::endl;
list.print();
list.clear();
std::cout << "clear:" << std::endl;
list.print();
return 1;
}
|
b7ef9999b452757123d2e96d701dfeeff7788f69 | 0eff74b05b60098333ad66cf801bdd93becc9ea4 | /second/download/CMake/CMake/CMake-joern/Kitware_CMake_repos_function_2164.cpp | 4a88573bf631042b5b4c6d97d276bdf95e233e5b | [] | no_license | niuxu18/logTracker-old | 97543445ea7e414ed40bdc681239365d33418975 | f2b060f13a0295387fe02187543db124916eb446 | refs/heads/master | 2021-09-13T21:39:37.686481 | 2017-12-11T03:36:34 | 2017-12-11T03:36:34 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 47 | cpp | Kitware_CMake_repos_function_2164.cpp | void secondone()
{
printf("Hello again\n");
} |
2e6aeadba408639051bb16bbc4257c989afab664 | 0ac7388d092db127a5f34952a985ee3cfb3ca028 | /deps/libgdal/gdal/port/cpl_vsil_s3.cpp | 032885944b81621d81681cc1a11e18656c37a974 | [
"LicenseRef-scancode-warranty-disclaimer",
"SunPro",
"LicenseRef-scancode-info-zip-2005-02",
"BSD-3-Clause",
"MIT",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"Zlib",
"LicenseRef-scancode-info-zip-2009-01"
] | permissive | mmomtchev/node-gdal-async | 49161ab6864341b1f0dd8b656c74290c63061c77 | 5c75d3d98989c4c246e54bb7ccff3a00d5cc3417 | refs/heads/main | 2023-08-07T11:44:44.011002 | 2023-07-30T17:41:18 | 2023-07-30T17:41:18 | 300,949,372 | 96 | 18 | Apache-2.0 | 2023-09-13T17:43:40 | 2020-10-03T18:28:43 | C++ | UTF-8 | C++ | false | false | 182,652 | cpp | cpl_vsil_s3.cpp | /******************************************************************************
*
* Project: CPL - Common Portability Library
* Purpose: Implement VSI large file api for AWS S3
* Author: Even Rouault, even.rouault at spatialys.com
*
******************************************************************************
* Copyright (c) 2010-2018, Even Rouault <even.rouault at spatialys.com>
*
* 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 "cpl_atomic_ops.h"
#include "cpl_port.h"
#include "cpl_http.h"
#include "cpl_md5.h"
#include "cpl_minixml.h"
#include "cpl_multiproc.h"
#include "cpl_time.h"
#include "cpl_vsil_curl_priv.h"
#include "cpl_vsil_curl_class.h"
#include <errno.h>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <memory>
#include <utility>
#include "cpl_aws.h"
#ifndef HAVE_CURL
void VSIInstallS3FileHandler(void)
{
// Not supported.
}
#else
//! @cond Doxygen_Suppress
#ifndef DOXYGEN_SKIP
#define ENABLE_DEBUG 0
constexpr int knMAX_PART_NUMBER = 10000; // Limitation from S3
#define unchecked_curl_easy_setopt(handle, opt, param) \
CPL_IGNORE_RET_VAL(curl_easy_setopt(handle, opt, param))
namespace cpl
{
/************************************************************************/
/* VSIDIRS3 */
/************************************************************************/
struct VSIDIRS3 : public VSIDIRWithMissingDirSynthesis
{
int nRecurseDepth = 0;
CPLString osNextMarker{};
int nPos = 0;
CPLString osBucket{};
CPLString osObjectKey{};
VSICurlFilesystemHandlerBase *poFS = nullptr;
IVSIS3LikeFSHandler *poS3FS = nullptr;
IVSIS3LikeHandleHelper *poS3HandleHelper = nullptr;
int nMaxFiles = 0;
bool bCacheEntries = true;
bool m_bSynthetizeMissingDirectories = false;
std::string m_osFilterPrefix{};
explicit VSIDIRS3(IVSIS3LikeFSHandler *poFSIn)
: poFS(poFSIn), poS3FS(poFSIn)
{
}
explicit VSIDIRS3(VSICurlFilesystemHandlerBase *poFSIn) : poFS(poFSIn)
{
}
~VSIDIRS3()
{
delete poS3HandleHelper;
}
VSIDIRS3(const VSIDIRS3 &) = delete;
VSIDIRS3 &operator=(const VSIDIRS3 &) = delete;
const VSIDIREntry *NextDirEntry() override;
bool IssueListDir();
bool
AnalyseS3FileList(const CPLString &osBaseURL, const char *pszXML,
const std::set<std::string> &oSetIgnoredStorageClasses,
bool &bIsTruncated);
void clear();
};
/************************************************************************/
/* clear() */
/************************************************************************/
void VSIDIRS3::clear()
{
osNextMarker.clear();
nPos = 0;
aoEntries.clear();
}
/************************************************************************/
/* SynthetizeMissingDirectories() */
/************************************************************************/
void VSIDIRWithMissingDirSynthesis::SynthetizeMissingDirectories(
const std::string &osCurSubdir, bool bAddEntryForThisSubdir)
{
const auto nLastSlashPos = osCurSubdir.rfind('/');
if (nLastSlashPos == std::string::npos)
{
m_aosSubpathsStack = {osCurSubdir};
}
else if (m_aosSubpathsStack.empty())
{
SynthetizeMissingDirectories(osCurSubdir.substr(0, nLastSlashPos),
true);
m_aosSubpathsStack.emplace_back(osCurSubdir);
}
else if (osCurSubdir.compare(0, nLastSlashPos, m_aosSubpathsStack.back()) ==
0)
{
m_aosSubpathsStack.emplace_back(osCurSubdir);
}
else
{
size_t depth = 1;
for (char c : osCurSubdir)
{
if (c == '/')
depth++;
}
while (depth <= m_aosSubpathsStack.size())
m_aosSubpathsStack.resize(m_aosSubpathsStack.size() - 1);
if (!m_aosSubpathsStack.empty() &&
osCurSubdir.compare(0, nLastSlashPos, m_aosSubpathsStack.back()) !=
0)
{
SynthetizeMissingDirectories(osCurSubdir.substr(0, nLastSlashPos),
true);
}
m_aosSubpathsStack.emplace_back(osCurSubdir);
}
if (bAddEntryForThisSubdir)
{
aoEntries.push_back(std::unique_ptr<VSIDIREntry>(new VSIDIREntry()));
auto &entry = aoEntries.back();
entry->pszName = CPLStrdup(osCurSubdir.c_str());
entry->nMode = S_IFDIR;
entry->bModeKnown = true;
}
}
/************************************************************************/
/* AnalyseS3FileList() */
/************************************************************************/
bool VSIDIRS3::AnalyseS3FileList(
const CPLString &osBaseURL, const char *pszXML,
const std::set<std::string> &oSetIgnoredStorageClasses, bool &bIsTruncated)
{
#if DEBUG_VERBOSE
const char *pszDebugPrefix = poS3FS ? poS3FS->GetDebugKey() : "S3";
CPLDebug(pszDebugPrefix, "%s", pszXML);
#endif
CPLXMLNode *psTree = CPLParseXMLString(pszXML);
if (psTree == nullptr)
return false;
CPLXMLNode *psListBucketResult = CPLGetXMLNode(psTree, "=ListBucketResult");
CPLXMLNode *psListAllMyBucketsResultBuckets =
(psListBucketResult != nullptr)
? nullptr
: CPLGetXMLNode(psTree, "=ListAllMyBucketsResult.Buckets");
bool ret = true;
bIsTruncated = false;
if (psListBucketResult)
{
ret = false;
CPLString osPrefix = CPLGetXMLValue(psListBucketResult, "Prefix", "");
if (osPrefix.empty())
{
// in the case of an empty bucket
ret = true;
}
if (osPrefix.endsWith(m_osFilterPrefix))
{
osPrefix.resize(osPrefix.size() - m_osFilterPrefix.size());
}
bIsTruncated = CPLTestBool(
CPLGetXMLValue(psListBucketResult, "IsTruncated", "false"));
// Count the number of occurrences of a path. Can be 1 or 2. 2 in the
// case that both a filename and directory exist
std::map<CPLString, int> aoNameCount;
for (CPLXMLNode *psIter = psListBucketResult->psChild;
psIter != nullptr; psIter = psIter->psNext)
{
if (psIter->eType != CXT_Element)
continue;
if (strcmp(psIter->pszValue, "Contents") == 0)
{
ret = true;
const char *pszKey = CPLGetXMLValue(psIter, "Key", nullptr);
if (pszKey && strlen(pszKey) > osPrefix.size())
{
aoNameCount[pszKey + osPrefix.size()]++;
}
}
else if (strcmp(psIter->pszValue, "CommonPrefixes") == 0)
{
const char *pszKey = CPLGetXMLValue(psIter, "Prefix", nullptr);
if (pszKey && strncmp(pszKey, osPrefix, osPrefix.size()) == 0)
{
CPLString osKey = pszKey;
if (!osKey.empty() && osKey.back() == '/')
osKey.resize(osKey.size() - 1);
if (osKey.size() > osPrefix.size())
{
ret = true;
aoNameCount[osKey.c_str() + osPrefix.size()]++;
}
}
}
}
for (CPLXMLNode *psIter = psListBucketResult->psChild;
psIter != nullptr; psIter = psIter->psNext)
{
if (psIter->eType != CXT_Element)
continue;
if (strcmp(psIter->pszValue, "Contents") == 0)
{
const char *pszKey = CPLGetXMLValue(psIter, "Key", nullptr);
if (bIsTruncated && nRecurseDepth < 0 && pszKey)
{
osNextMarker = pszKey;
}
if (pszKey && strlen(pszKey) > osPrefix.size())
{
const char *pszStorageClass =
CPLGetXMLValue(psIter, "StorageClass", "");
if (oSetIgnoredStorageClasses.find(pszStorageClass) !=
oSetIgnoredStorageClasses.end())
{
continue;
}
const std::string osKeySuffix = pszKey + osPrefix.size();
if (m_bSynthetizeMissingDirectories)
{
const auto nLastSlashPos = osKeySuffix.rfind('/');
if (nLastSlashPos != std::string::npos &&
(m_aosSubpathsStack.empty() ||
osKeySuffix.compare(0, nLastSlashPos,
m_aosSubpathsStack.back()) !=
0))
{
const bool bAddEntryForThisSubdir =
nLastSlashPos != osKeySuffix.size() - 1;
SynthetizeMissingDirectories(
osKeySuffix.substr(0, nLastSlashPos),
bAddEntryForThisSubdir);
}
}
aoEntries.push_back(
std::unique_ptr<VSIDIREntry>(new VSIDIREntry()));
auto &entry = aoEntries.back();
entry->pszName = CPLStrdup(osKeySuffix.c_str());
entry->nSize = static_cast<GUIntBig>(
CPLAtoGIntBig(CPLGetXMLValue(psIter, "Size", "0")));
entry->bSizeKnown = true;
entry->nMode =
entry->pszName[0] != 0 &&
entry->pszName[strlen(entry->pszName) - 1] ==
'/'
? S_IFDIR
: S_IFREG;
if (entry->nMode == S_IFDIR &&
aoNameCount[entry->pszName] < 2)
{
entry->pszName[strlen(entry->pszName) - 1] = 0;
}
entry->bModeKnown = true;
CPLString ETag = CPLGetXMLValue(psIter, "ETag", "");
if (ETag.size() > 2 && ETag[0] == '"' && ETag.back() == '"')
{
ETag = ETag.substr(1, ETag.size() - 2);
entry->papszExtra = CSLSetNameValue(
entry->papszExtra, "ETag", ETag.c_str());
}
int nYear = 0;
int nMonth = 0;
int nDay = 0;
int nHour = 0;
int nMin = 0;
int nSec = 0;
if (sscanf(CPLGetXMLValue(psIter, "LastModified", ""),
"%04d-%02d-%02dT%02d:%02d:%02d", &nYear, &nMonth,
&nDay, &nHour, &nMin, &nSec) == 6)
{
struct tm brokendowntime;
brokendowntime.tm_year = nYear - 1900;
brokendowntime.tm_mon = nMonth - 1;
brokendowntime.tm_mday = nDay;
brokendowntime.tm_hour = nHour;
brokendowntime.tm_min = nMin;
brokendowntime.tm_sec = nSec;
entry->nMTime = CPLYMDHMSToUnixTime(&brokendowntime);
entry->bMTimeKnown = true;
}
if (nMaxFiles != 1 && bCacheEntries)
{
FileProp prop;
prop.nMode = entry->nMode;
prop.eExists = EXIST_YES;
prop.bHasComputedFileSize = true;
prop.fileSize = entry->nSize;
prop.bIsDirectory = (entry->nMode == S_IFDIR);
prop.mTime = static_cast<time_t>(entry->nMTime);
prop.ETag = ETag;
CPLString osCachedFilename =
osBaseURL + CPLAWSURLEncode(osPrefix, false) +
CPLAWSURLEncode(entry->pszName, false);
#if DEBUG_VERBOSE
CPLDebug(pszDebugPrefix, "Cache %s",
osCachedFilename.c_str());
#endif
poFS->SetCachedFileProp(osCachedFilename, prop);
}
if (nMaxFiles > 0 &&
aoEntries.size() >= static_cast<unsigned>(nMaxFiles))
break;
}
}
else if (strcmp(psIter->pszValue, "CommonPrefixes") == 0)
{
const char *pszKey = CPLGetXMLValue(psIter, "Prefix", nullptr);
if (pszKey && strncmp(pszKey, osPrefix, osPrefix.size()) == 0)
{
CPLString osKey = pszKey;
if (!osKey.empty() && osKey.back() == '/')
osKey.resize(osKey.size() - 1);
if (osKey.size() > osPrefix.size())
{
aoEntries.push_back(
std::unique_ptr<VSIDIREntry>(new VSIDIREntry()));
auto &entry = aoEntries.back();
entry->pszName =
CPLStrdup(osKey.c_str() + osPrefix.size());
if (aoNameCount[entry->pszName] == 2)
{
// Add a / suffix to disambiguish the situation
// Normally we don't suffix directories with /, but
// we have no alternative here
CPLString osTemp(entry->pszName);
osTemp += '/';
CPLFree(entry->pszName);
entry->pszName = CPLStrdup(osTemp);
}
entry->nMode = S_IFDIR;
entry->bModeKnown = true;
if (nMaxFiles != 1 && bCacheEntries)
{
FileProp prop;
prop.eExists = EXIST_YES;
prop.bIsDirectory = true;
prop.bHasComputedFileSize = true;
prop.fileSize = 0;
prop.mTime = 0;
prop.nMode = S_IFDIR;
CPLString osCachedFilename =
osBaseURL + CPLAWSURLEncode(osPrefix, false) +
CPLAWSURLEncode(entry->pszName, false);
#if DEBUG_VERBOSE
CPLDebug(pszDebugPrefix, "Cache %s",
osCachedFilename.c_str());
#endif
poFS->SetCachedFileProp(osCachedFilename, prop);
}
if (nMaxFiles > 0 &&
aoEntries.size() >=
static_cast<unsigned>(nMaxFiles))
break;
}
}
}
}
if (nRecurseDepth == 0)
{
osNextMarker = CPLGetXMLValue(psListBucketResult, "NextMarker", "");
}
}
else if (psListAllMyBucketsResultBuckets != nullptr)
{
CPLXMLNode *psIter = psListAllMyBucketsResultBuckets->psChild;
for (; psIter != nullptr; psIter = psIter->psNext)
{
if (psIter->eType != CXT_Element)
continue;
if (strcmp(psIter->pszValue, "Bucket") == 0)
{
const char *pszName = CPLGetXMLValue(psIter, "Name", nullptr);
if (pszName)
{
aoEntries.push_back(
std::unique_ptr<VSIDIREntry>(new VSIDIREntry()));
auto &entry = aoEntries.back();
entry->pszName = CPLStrdup(pszName);
entry->nMode = S_IFDIR;
entry->bModeKnown = true;
if (nMaxFiles != 1 && bCacheEntries)
{
FileProp prop;
prop.eExists = EXIST_YES;
prop.bIsDirectory = true;
prop.bHasComputedFileSize = true;
prop.fileSize = 0;
prop.mTime = 0;
prop.nMode = S_IFDIR;
CPLString osCachedFilename =
osBaseURL + CPLAWSURLEncode(pszName, false);
#if DEBUG_VERBOSE
CPLDebug(pszDebugPrefix, "Cache %s",
osCachedFilename.c_str());
#endif
poFS->SetCachedFileProp(osCachedFilename, prop);
}
}
}
}
}
CPLDestroyXMLNode(psTree);
return ret;
}
/************************************************************************/
/* IssueListDir() */
/************************************************************************/
bool VSIDIRS3::IssueListDir()
{
CPLString osMaxKeys = CPLGetConfigOption("AWS_MAX_KEYS", "");
if (nMaxFiles > 0 && nMaxFiles <= 100 &&
(osMaxKeys.empty() || nMaxFiles < atoi(osMaxKeys)))
{
osMaxKeys.Printf("%d", nMaxFiles);
}
NetworkStatisticsFileSystem oContextFS(poS3FS->GetFSPrefix());
NetworkStatisticsAction oContextAction("ListBucket");
const CPLString l_osNextMarker(osNextMarker);
clear();
while (true)
{
poS3HandleHelper->ResetQueryParameters();
const CPLString osBaseURL(poS3HandleHelper->GetURL());
CURL *hCurlHandle = curl_easy_init();
if (!osBucket.empty())
{
if (nRecurseDepth == 0)
poS3HandleHelper->AddQueryParameter("delimiter", "/");
if (!l_osNextMarker.empty())
poS3HandleHelper->AddQueryParameter("marker", l_osNextMarker);
if (!osMaxKeys.empty())
poS3HandleHelper->AddQueryParameter("max-keys", osMaxKeys);
if (!osObjectKey.empty())
poS3HandleHelper->AddQueryParameter(
"prefix", osObjectKey + "/" + m_osFilterPrefix);
else if (!m_osFilterPrefix.empty())
poS3HandleHelper->AddQueryParameter("prefix", m_osFilterPrefix);
}
struct curl_slist *headers =
VSICurlSetOptions(hCurlHandle, poS3HandleHelper->GetURL(), nullptr);
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders("GET", headers));
// Disable automatic redirection
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_FOLLOWLOCATION, 0);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_RANGE, nullptr);
CurlRequestHelper requestHelper;
const long response_code =
requestHelper.perform(hCurlHandle, headers, poFS, poS3HandleHelper);
NetworkStatisticsLogger::LogGET(requestHelper.sWriteFuncData.nSize);
if (response_code != 200 ||
requestHelper.sWriteFuncData.pBuffer == nullptr)
{
bool bUpdateMap = true;
if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false,
&bUpdateMap))
{
if (bUpdateMap)
{
poS3FS->UpdateMapFromHandle(poS3HandleHelper);
}
}
else
{
CPLDebug(poS3FS->GetDebugKey(), "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
curl_easy_cleanup(hCurlHandle);
return false;
}
}
else
{
bool bIsTruncated;
bool ret = AnalyseS3FileList(
osBaseURL, requestHelper.sWriteFuncData.pBuffer,
VSICurlFilesystemHandlerBase::GetS3IgnoredStorageClasses(),
bIsTruncated);
curl_easy_cleanup(hCurlHandle);
return ret;
}
curl_easy_cleanup(hCurlHandle);
}
}
/************************************************************************/
/* NextDirEntry() */
/************************************************************************/
const VSIDIREntry *VSIDIRS3::NextDirEntry()
{
while (true)
{
if (nPos < static_cast<int>(aoEntries.size()))
{
auto &entry = aoEntries[nPos];
nPos++;
return entry.get();
}
if (osNextMarker.empty())
{
return nullptr;
}
if (!IssueListDir())
{
return nullptr;
}
}
}
/************************************************************************/
/* AnalyseS3FileList() */
/************************************************************************/
bool VSICurlFilesystemHandlerBase::AnalyseS3FileList(
const CPLString &osBaseURL, const char *pszXML, CPLStringList &osFileList,
int nMaxFiles, const std::set<std::string> &oSetIgnoredStorageClasses,
bool &bIsTruncated)
{
VSIDIRS3 oDir(this);
oDir.nMaxFiles = nMaxFiles;
bool ret = oDir.AnalyseS3FileList(osBaseURL, pszXML,
oSetIgnoredStorageClasses, bIsTruncated);
for (const auto &entry : oDir.aoEntries)
{
osFileList.AddString(entry->pszName);
}
return ret;
}
/************************************************************************/
/* VSIS3FSHandler */
/************************************************************************/
class VSIS3FSHandler final : public IVSIS3LikeFSHandler
{
CPL_DISALLOW_COPY_ASSIGN(VSIS3FSHandler)
const std::string m_osPrefix;
std::set<CPLString> DeleteObjects(const char *pszBucket,
const char *pszXML);
protected:
VSICurlHandle *CreateFileHandle(const char *pszFilename) override;
CPLString GetURLFromFilename(const CPLString &osFilename) override;
const char *GetDebugKey() const override
{
return "S3";
}
IVSIS3LikeHandleHelper *CreateHandleHelper(const char *pszURI,
bool bAllowNoObject) override;
CPLString GetFSPrefix() const override
{
return m_osPrefix;
}
void ClearCache() override;
bool IsAllowedHeaderForObjectCreation(const char *pszHeaderName) override
{
return STARTS_WITH(pszHeaderName, "x-amz-");
}
public:
explicit VSIS3FSHandler(const char *pszPrefix) : m_osPrefix(pszPrefix)
{
}
~VSIS3FSHandler() override;
VSIVirtualHandle *Open(const char *pszFilename, const char *pszAccess,
bool bSetError, CSLConstList papszOptions) override;
void UpdateMapFromHandle(IVSIS3LikeHandleHelper *poS3HandleHelper) override;
void UpdateHandleFromMap(IVSIS3LikeHandleHelper *poS3HandleHelper) override;
const char *GetOptions() override;
char *GetSignedURL(const char *pszFilename,
CSLConstList papszOptions) override;
int *UnlinkBatch(CSLConstList papszFiles) override;
int RmdirRecursive(const char *pszDirname) override;
char **GetFileMetadata(const char *pszFilename, const char *pszDomain,
CSLConstList papszOptions) override;
bool SetFileMetadata(const char *pszFilename, CSLConstList papszMetadata,
const char *pszDomain,
CSLConstList papszOptions) override;
bool SupportsParallelMultipartUpload() const override
{
return true;
}
bool SupportsSequentialWrite(const char * /* pszPath */,
bool /* bAllowLocalTempFile */) override
{
return true;
}
bool SupportsRandomWrite(const char * /* pszPath */,
bool /* bAllowLocalTempFile */) override;
std::string
GetStreamingFilename(const std::string &osFilename) const override;
VSIFilesystemHandler *Duplicate(const char *pszPrefix) override
{
return new VSIS3FSHandler(pszPrefix);
}
};
/************************************************************************/
/* VSIS3Handle */
/************************************************************************/
class VSIS3Handle final : public IVSIS3LikeHandle
{
CPL_DISALLOW_COPY_ASSIGN(VSIS3Handle)
VSIS3HandleHelper *m_poS3HandleHelper = nullptr;
protected:
struct curl_slist *
GetCurlHeaders(const CPLString &osVerb,
const struct curl_slist *psExistingHeaders) override;
bool CanRestartOnError(const char *, const char *, bool) override;
bool AllowAutomaticRedirection() override
{
return m_poS3HandleHelper->AllowAutomaticRedirection();
}
public:
VSIS3Handle(VSIS3FSHandler *poFS, const char *pszFilename,
VSIS3HandleHelper *poS3HandleHelper);
~VSIS3Handle() override;
};
/************************************************************************/
/* VSIS3WriteHandle() */
/************************************************************************/
VSIS3WriteHandle::VSIS3WriteHandle(IVSIS3LikeFSHandler *poFS,
const char *pszFilename,
IVSIS3LikeHandleHelper *poS3HandleHelper,
bool bUseChunked, CSLConstList papszOptions)
: m_poFS(poFS), m_osFilename(pszFilename),
m_poS3HandleHelper(poS3HandleHelper), m_bUseChunked(bUseChunked),
m_aosOptions(papszOptions),
m_aosHTTPOptions(CPLHTTPGetOptionsFromEnv(pszFilename)),
m_nMaxRetry(
atoi(VSIGetPathSpecificOption(pszFilename, "GDAL_HTTP_MAX_RETRY",
CPLSPrintf("%d", CPL_HTTP_MAX_RETRY)))),
// coverity[tainted_data]
m_dfRetryDelay(CPLAtof(
VSIGetPathSpecificOption(pszFilename, "GDAL_HTTP_RETRY_DELAY",
CPLSPrintf("%f", CPL_HTTP_RETRY_DELAY))))
{
// AWS S3, OSS and GCS can use the mulipart upload mechanism, which has
// the advantage of being retryable in case of errors.
// Swift only supports the "Transfer-Encoding: chunked" PUT mechanism.
// So two different implementations.
if (!m_bUseChunked)
{
const int nChunkSizeMB = atoi(VSIGetPathSpecificOption(
pszFilename,
(std::string("VSI") + poFS->GetDebugKey() + "_CHUNK_SIZE").c_str(),
"50"));
if (nChunkSizeMB <= 0 || nChunkSizeMB > 1000)
m_nBufferSize = 0;
else
m_nBufferSize = nChunkSizeMB * 1024 * 1024;
// For testing only !
const char *pszChunkSizeBytes = VSIGetPathSpecificOption(
pszFilename,
(std::string("VSI") + poFS->GetDebugKey() + "_CHUNK_SIZE_BYTES")
.c_str(),
nullptr);
if (pszChunkSizeBytes)
m_nBufferSize = atoi(pszChunkSizeBytes);
if (m_nBufferSize <= 0 || m_nBufferSize > 1000 * 1024 * 1024)
m_nBufferSize = 50 * 1024 * 1024;
m_pabyBuffer = static_cast<GByte *>(VSIMalloc(m_nBufferSize));
if (m_pabyBuffer == nullptr)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot allocate working buffer for %s",
m_poFS->GetFSPrefix().c_str());
}
}
}
/************************************************************************/
/* ~VSIS3WriteHandle() */
/************************************************************************/
VSIS3WriteHandle::~VSIS3WriteHandle()
{
VSIS3WriteHandle::Close();
delete m_poS3HandleHelper;
CPLFree(m_pabyBuffer);
if (m_hCurlMulti)
{
if (m_hCurl)
{
curl_multi_remove_handle(m_hCurlMulti, m_hCurl);
curl_easy_cleanup(m_hCurl);
}
curl_multi_cleanup(m_hCurlMulti);
}
CPLFree(m_sWriteFuncHeaderData.pBuffer);
}
/************************************************************************/
/* Seek() */
/************************************************************************/
int VSIS3WriteHandle::Seek(vsi_l_offset nOffset, int nWhence)
{
if (!((nWhence == SEEK_SET && nOffset == m_nCurOffset) ||
(nWhence == SEEK_CUR && nOffset == 0) ||
(nWhence == SEEK_END && nOffset == 0)))
{
CPLError(CE_Failure, CPLE_NotSupported,
"Seek not supported on writable %s files",
m_poFS->GetFSPrefix().c_str());
m_bError = true;
return -1;
}
return 0;
}
/************************************************************************/
/* Tell() */
/************************************************************************/
vsi_l_offset VSIS3WriteHandle::Tell()
{
return m_nCurOffset;
}
/************************************************************************/
/* Read() */
/************************************************************************/
size_t VSIS3WriteHandle::Read(void * /* pBuffer */, size_t /* nSize */,
size_t /* nMemb */)
{
CPLError(CE_Failure, CPLE_NotSupported,
"Read not supported on writable %s files",
m_poFS->GetFSPrefix().c_str());
m_bError = true;
return 0;
}
/************************************************************************/
/* InitiateMultipartUpload() */
/************************************************************************/
CPLString IVSIS3LikeFSHandler::InitiateMultipartUpload(
const std::string &osFilename, IVSIS3LikeHandleHelper *poS3HandleHelper,
int nMaxRetry, double dfRetryDelay, CSLConstList papszOptions)
{
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsFile oContextFile(osFilename.c_str());
NetworkStatisticsAction oContextAction("InitiateMultipartUpload");
const CPLStringList aosHTTPOptions(
CPLHTTPGetOptionsFromEnv(osFilename.c_str()));
CPLString osUploadID;
bool bRetry;
int nRetryCount = 0;
do
{
bRetry = false;
CURL *hCurlHandle = curl_easy_init();
poS3HandleHelper->AddQueryParameter("uploads", "");
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_CUSTOMREQUEST, "POST");
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, poS3HandleHelper->GetURL().c_str(),
aosHTTPOptions.List()));
headers = VSICurlSetCreationHeadersFromOptions(headers, papszOptions,
osFilename.c_str());
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders("POST", headers));
headers = curl_slist_append(
headers, "Content-Length: 0"); // Required by GCS in HTTP 1.1
CurlRequestHelper requestHelper;
const long response_code =
requestHelper.perform(hCurlHandle, headers, this, poS3HandleHelper);
NetworkStatisticsLogger::LogPOST(0, requestHelper.sWriteFuncData.nSize);
if (response_code != 200 ||
requestHelper.sWriteFuncData.pBuffer == nullptr)
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
poS3HandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
UpdateMapFromHandle(poS3HandleHelper);
bRetry = true;
}
else
{
CPLDebug(GetDebugKey(), "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined,
"InitiateMultipartUpload of %s failed",
osFilename.c_str());
}
}
else
{
InvalidateCachedData(poS3HandleHelper->GetURL().c_str());
InvalidateDirContent(CPLGetDirname(osFilename.c_str()));
CPLXMLNode *psNode =
CPLParseXMLString(requestHelper.sWriteFuncData.pBuffer);
if (psNode)
{
osUploadID = CPLGetXMLValue(
psNode, "=InitiateMultipartUploadResult.UploadId", "");
CPLDebug(GetDebugKey(), "UploadId: %s", osUploadID.c_str());
CPLDestroyXMLNode(psNode);
}
if (osUploadID.empty())
{
CPLError(
CE_Failure, CPLE_AppDefined,
"InitiateMultipartUpload of %s failed: cannot get UploadId",
osFilename.c_str());
}
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
return osUploadID;
}
/************************************************************************/
/* UploadPart() */
/************************************************************************/
bool VSIS3WriteHandle::UploadPart()
{
++m_nPartNumber;
if (m_nPartNumber > knMAX_PART_NUMBER)
{
m_bError = true;
CPLError(
CE_Failure, CPLE_AppDefined,
"%d parts have been uploaded for %s failed. "
"This is the maximum. "
"Increase VSIS3_CHUNK_SIZE to a higher value (e.g. 500 for 500 MB)",
knMAX_PART_NUMBER, m_osFilename.c_str());
return false;
}
const CPLString osEtag = m_poFS->UploadPart(
m_osFilename, m_nPartNumber, m_osUploadID,
static_cast<vsi_l_offset>(m_nBufferSize) * (m_nPartNumber - 1),
m_pabyBuffer, m_nBufferOff, m_poS3HandleHelper, m_nMaxRetry,
m_dfRetryDelay, nullptr);
m_nBufferOff = 0;
if (!osEtag.empty())
{
m_aosEtags.push_back(osEtag);
}
return !osEtag.empty();
}
CPLString IVSIS3LikeFSHandler::UploadPart(
const CPLString &osFilename, int nPartNumber, const std::string &osUploadID,
vsi_l_offset /* nPosition */, const void *pabyBuffer, size_t nBufferSize,
IVSIS3LikeHandleHelper *poS3HandleHelper, int nMaxRetry,
double dfRetryDelay, CSLConstList /* papszOptions */)
{
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsFile oContextFile(osFilename);
NetworkStatisticsAction oContextAction("UploadPart");
bool bRetry;
int nRetryCount = 0;
CPLString osEtag;
const CPLStringList aosHTTPOptions(
CPLHTTPGetOptionsFromEnv(osFilename.c_str()));
do
{
bRetry = false;
CURL *hCurlHandle = curl_easy_init();
poS3HandleHelper->AddQueryParameter("partNumber",
CPLSPrintf("%d", nPartNumber));
poS3HandleHelper->AddQueryParameter("uploadId", osUploadID);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_UPLOAD, 1L);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_READFUNCTION,
PutData::ReadCallBackBuffer);
PutData putData;
putData.pabyData = static_cast<const GByte *>(pabyBuffer);
putData.nOff = 0;
putData.nTotalSize = nBufferSize;
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_READDATA, &putData);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_INFILESIZE,
nBufferSize);
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, poS3HandleHelper->GetURL().c_str(),
aosHTTPOptions));
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders("PUT", headers,
pabyBuffer, nBufferSize));
CurlRequestHelper requestHelper;
const long response_code =
requestHelper.perform(hCurlHandle, headers, this, poS3HandleHelper);
NetworkStatisticsLogger::LogPUT(nBufferSize);
if (response_code != 200 ||
requestHelper.sWriteFuncHeaderData.pBuffer == nullptr)
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
poS3HandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
UpdateMapFromHandle(poS3HandleHelper);
bRetry = true;
}
else
{
CPLDebug(GetDebugKey(), "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined,
"UploadPart(%d) of %s failed", nPartNumber,
osFilename.c_str());
}
}
else
{
CPLString osHeader(requestHelper.sWriteFuncHeaderData.pBuffer);
size_t nPos = osHeader.ifind("ETag: ");
if (nPos != std::string::npos)
{
osEtag = osHeader.substr(nPos + strlen("ETag: "));
const size_t nPosEOL = osEtag.find("\r");
if (nPosEOL != std::string::npos)
osEtag.resize(nPosEOL);
CPLDebug(GetDebugKey(), "Etag for part %d is %s", nPartNumber,
osEtag.c_str());
}
else
{
CPLError(CE_Failure, CPLE_AppDefined,
"UploadPart(%d) of %s (uploadId = %s) failed",
nPartNumber, osFilename.c_str(), osUploadID.c_str());
}
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
return osEtag;
}
/************************************************************************/
/* ReadCallBackBufferChunked() */
/************************************************************************/
size_t VSIS3WriteHandle::ReadCallBackBufferChunked(char *buffer, size_t size,
size_t nitems,
void *instream)
{
VSIS3WriteHandle *poThis = static_cast<VSIS3WriteHandle *>(instream);
if (poThis->m_nChunkedBufferSize == 0)
{
// CPLDebug("VSIS3WriteHandle", "Writing 0 byte (finish)");
return 0;
}
const size_t nSizeMax = size * nitems;
size_t nSizeToWrite = nSizeMax;
size_t nChunkedBufferRemainingSize =
poThis->m_nChunkedBufferSize - poThis->m_nChunkedBufferOff;
if (nChunkedBufferRemainingSize < nSizeToWrite)
nSizeToWrite = nChunkedBufferRemainingSize;
memcpy(buffer,
static_cast<const GByte *>(poThis->m_pBuffer) +
poThis->m_nChunkedBufferOff,
nSizeToWrite);
poThis->m_nChunkedBufferOff += nSizeToWrite;
// CPLDebug("VSIS3WriteHandle", "Writing %d bytes", nSizeToWrite);
return nSizeToWrite;
}
/************************************************************************/
/* WriteChunked() */
/************************************************************************/
size_t VSIS3WriteHandle::WriteChunked(const void *pBuffer, size_t nSize,
size_t nMemb)
{
const size_t nBytesToWrite = nSize * nMemb;
if (m_hCurlMulti == nullptr)
{
m_hCurlMulti = curl_multi_init();
}
WriteFuncStruct sWriteFuncData;
double dfRetryDelay = m_dfRetryDelay;
int nRetryCount = 0;
// We can only easily retry at the first chunk of a transfer
bool bCanRetry = (m_hCurl == nullptr);
bool bRetry;
do
{
bRetry = false;
struct curl_slist *headers = nullptr;
if (m_hCurl == nullptr)
{
CURL *hCurlHandle = curl_easy_init();
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_UPLOAD, 1L);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_READFUNCTION,
ReadCallBackBufferChunked);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_READDATA, this);
VSICURLInitWriteFuncStruct(&sWriteFuncData, nullptr, nullptr,
nullptr);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_WRITEDATA,
&sWriteFuncData);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_WRITEFUNCTION,
VSICurlHandleWriteFunc);
VSICURLInitWriteFuncStruct(&m_sWriteFuncHeaderData, nullptr,
nullptr, nullptr);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_HEADERDATA,
&m_sWriteFuncHeaderData);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_HEADERFUNCTION,
VSICurlHandleWriteFunc);
headers = static_cast<struct curl_slist *>(CPLHTTPSetOptions(
hCurlHandle, m_poS3HandleHelper->GetURL().c_str(),
m_aosHTTPOptions.List()));
headers = VSICurlSetCreationHeadersFromOptions(
headers, m_aosOptions.List(), m_osFilename.c_str());
headers = VSICurlMergeHeaders(
headers, m_poS3HandleHelper->GetCurlHeaders("PUT", headers));
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_HTTPHEADER,
headers);
m_osCurlErrBuf.resize(CURL_ERROR_SIZE + 1);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_ERRORBUFFER,
&m_osCurlErrBuf[0]);
curl_multi_add_handle(m_hCurlMulti, hCurlHandle);
m_hCurl = hCurlHandle;
}
m_pBuffer = pBuffer;
m_nChunkedBufferOff = 0;
m_nChunkedBufferSize = nBytesToWrite;
int repeats = 0;
while (m_nChunkedBufferOff < m_nChunkedBufferSize && !bRetry)
{
int still_running;
memset(&m_osCurlErrBuf[0], 0, m_osCurlErrBuf.size());
while (curl_multi_perform(m_hCurlMulti, &still_running) ==
CURLM_CALL_MULTI_PERFORM &&
// cppcheck-suppress knownConditionTrueFalse
m_nChunkedBufferOff < m_nChunkedBufferSize)
{
// loop
}
// cppcheck-suppress knownConditionTrueFalse
if (!still_running || m_nChunkedBufferOff == m_nChunkedBufferSize)
break;
CURLMsg *msg;
do
{
int msgq = 0;
msg = curl_multi_info_read(m_hCurlMulti, &msgq);
if (msg && (msg->msg == CURLMSG_DONE))
{
CURL *e = msg->easy_handle;
if (e == m_hCurl)
{
long response_code;
curl_easy_getinfo(m_hCurl, CURLINFO_RESPONSE_CODE,
&response_code);
if (response_code != 200 && response_code != 201)
{
// Look if we should attempt a retry
const double dfNewRetryDelay =
bCanRetry ? CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code),
dfRetryDelay,
m_sWriteFuncHeaderData.pBuffer,
m_osCurlErrBuf.c_str())
: 0.0;
if (dfNewRetryDelay > 0 &&
nRetryCount < m_nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
m_poS3HandleHelper->GetURL().c_str(),
dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (sWriteFuncData.pBuffer != nullptr &&
m_poS3HandleHelper->CanRestartOnError(
sWriteFuncData.pBuffer,
m_sWriteFuncHeaderData.pBuffer, false))
{
m_poFS->UpdateMapFromHandle(m_poS3HandleHelper);
bRetry = true;
}
else
{
CPLError(CE_Failure, CPLE_AppDefined,
"Error %d: %s",
static_cast<int>(response_code),
m_osCurlErrBuf.c_str());
curl_slist_free_all(headers);
bRetry = false;
}
curl_multi_remove_handle(m_hCurlMulti, m_hCurl);
curl_easy_cleanup(m_hCurl);
CPLFree(sWriteFuncData.pBuffer);
CPLFree(m_sWriteFuncHeaderData.pBuffer);
m_hCurl = nullptr;
sWriteFuncData.pBuffer = nullptr;
m_sWriteFuncHeaderData.pBuffer = nullptr;
if (!bRetry)
return 0;
}
}
}
} while (msg);
CPLMultiPerformWait(m_hCurlMulti, repeats);
}
m_nWrittenInPUT += nBytesToWrite;
curl_slist_free_all(headers);
m_pBuffer = nullptr;
if (!bRetry)
{
long response_code;
curl_easy_getinfo(m_hCurl, CURLINFO_RESPONSE_CODE, &response_code);
if (response_code != 100)
{
// Look if we should attempt a retry
const double dfNewRetryDelay =
bCanRetry
? CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
m_sWriteFuncHeaderData.pBuffer,
m_osCurlErrBuf.c_str())
: 0.0;
if (dfNewRetryDelay > 0 && nRetryCount < m_nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
m_poS3HandleHelper->GetURL().c_str(),
dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (sWriteFuncData.pBuffer != nullptr &&
m_poS3HandleHelper->CanRestartOnError(
sWriteFuncData.pBuffer,
m_sWriteFuncHeaderData.pBuffer, false))
{
m_poFS->UpdateMapFromHandle(m_poS3HandleHelper);
bRetry = true;
}
else
{
CPLError(CE_Failure, CPLE_AppDefined, "Error %d: %s",
static_cast<int>(response_code),
m_osCurlErrBuf.c_str());
bRetry = false;
nMemb = 0;
}
curl_multi_remove_handle(m_hCurlMulti, m_hCurl);
curl_easy_cleanup(m_hCurl);
CPLFree(sWriteFuncData.pBuffer);
CPLFree(m_sWriteFuncHeaderData.pBuffer);
m_hCurl = nullptr;
sWriteFuncData.pBuffer = nullptr;
m_sWriteFuncHeaderData.pBuffer = nullptr;
}
}
} while (bRetry);
return nMemb;
}
/************************************************************************/
/* FinishChunkedTransfer() */
/************************************************************************/
int VSIS3WriteHandle::FinishChunkedTransfer()
{
if (m_hCurl == nullptr)
return -1;
NetworkStatisticsFileSystem oContextFS(m_poFS->GetFSPrefix());
NetworkStatisticsFile oContextFile(m_osFilename.c_str());
NetworkStatisticsAction oContextAction("Write");
NetworkStatisticsLogger::LogPUT(m_nWrittenInPUT);
m_nWrittenInPUT = 0;
m_pBuffer = nullptr;
m_nChunkedBufferOff = 0;
m_nChunkedBufferSize = 0;
MultiPerform(m_hCurlMulti);
long response_code;
curl_easy_getinfo(m_hCurl, CURLINFO_RESPONSE_CODE, &response_code);
if (response_code == 200 || response_code == 201)
{
InvalidateParentDirectory();
}
else
{
CPLError(CE_Failure, CPLE_AppDefined, "Error %d: %s",
static_cast<int>(response_code), m_osCurlErrBuf.c_str());
return -1;
}
return 0;
}
/************************************************************************/
/* Write() */
/************************************************************************/
size_t VSIS3WriteHandle::Write(const void *pBuffer, size_t nSize, size_t nMemb)
{
if (m_bError)
return 0;
size_t nBytesToWrite = nSize * nMemb;
if (nBytesToWrite == 0)
return 0;
if (m_bUseChunked)
{
return WriteChunked(pBuffer, nSize, nMemb);
}
const GByte *pabySrcBuffer = reinterpret_cast<const GByte *>(pBuffer);
while (nBytesToWrite > 0)
{
const int nToWriteInBuffer = static_cast<int>(std::min(
static_cast<size_t>(m_nBufferSize - m_nBufferOff), nBytesToWrite));
memcpy(m_pabyBuffer + m_nBufferOff, pabySrcBuffer, nToWriteInBuffer);
pabySrcBuffer += nToWriteInBuffer;
m_nBufferOff += nToWriteInBuffer;
m_nCurOffset += nToWriteInBuffer;
nBytesToWrite -= nToWriteInBuffer;
if (m_nBufferOff == m_nBufferSize)
{
if (m_nCurOffset == static_cast<vsi_l_offset>(m_nBufferSize))
{
m_osUploadID = m_poFS->InitiateMultipartUpload(
m_osFilename, m_poS3HandleHelper, m_nMaxRetry,
m_dfRetryDelay, m_aosOptions.List());
if (m_osUploadID.empty())
{
m_bError = true;
return 0;
}
}
if (!UploadPart())
{
m_bError = true;
return 0;
}
m_nBufferOff = 0;
}
}
return nMemb;
}
/************************************************************************/
/* Eof() */
/************************************************************************/
int VSIS3WriteHandle::Eof()
{
return FALSE;
}
/************************************************************************/
/* InvalidateParentDirectory() */
/************************************************************************/
void VSIS3WriteHandle::InvalidateParentDirectory()
{
m_poFS->InvalidateCachedData(m_poS3HandleHelper->GetURL().c_str());
CPLString osFilenameWithoutSlash(m_osFilename);
if (!osFilenameWithoutSlash.empty() && osFilenameWithoutSlash.back() == '/')
osFilenameWithoutSlash.resize(osFilenameWithoutSlash.size() - 1);
m_poFS->InvalidateDirContent(CPLGetDirname(osFilenameWithoutSlash));
}
/************************************************************************/
/* DoSinglePartPUT() */
/************************************************************************/
bool VSIS3WriteHandle::DoSinglePartPUT()
{
bool bSuccess = true;
bool bRetry;
double dfRetryDelay = m_dfRetryDelay;
int nRetryCount = 0;
NetworkStatisticsFileSystem oContextFS(m_poFS->GetFSPrefix());
NetworkStatisticsFile oContextFile(m_osFilename.c_str());
NetworkStatisticsAction oContextAction("Write");
do
{
bRetry = false;
PutData putData;
putData.pabyData = m_pabyBuffer;
putData.nOff = 0;
putData.nTotalSize = m_nBufferOff;
CURL *hCurlHandle = curl_easy_init();
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_UPLOAD, 1L);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_READFUNCTION,
PutData::ReadCallBackBuffer);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_READDATA, &putData);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_INFILESIZE,
m_nBufferOff);
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, m_poS3HandleHelper->GetURL().c_str(),
m_aosHTTPOptions.List()));
headers = VSICurlSetCreationHeadersFromOptions(
headers, m_aosOptions.List(), m_osFilename.c_str());
headers = VSICurlMergeHeaders(
headers, m_poS3HandleHelper->GetCurlHeaders(
"PUT", headers, m_pabyBuffer, m_nBufferOff));
headers = curl_slist_append(headers, "Expect: 100-continue");
CurlRequestHelper requestHelper;
const long response_code = requestHelper.perform(
hCurlHandle, headers, m_poFS, m_poS3HandleHelper);
NetworkStatisticsLogger::LogPUT(m_nBufferOff);
if (response_code != 200 && response_code != 201)
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < m_nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
m_poS3HandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
m_poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
m_poFS->UpdateMapFromHandle(m_poS3HandleHelper);
bRetry = true;
}
else
{
CPLDebug("S3", "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined,
"DoSinglePartPUT of %s failed", m_osFilename.c_str());
bSuccess = false;
}
}
else
{
InvalidateParentDirectory();
}
if (requestHelper.sWriteFuncHeaderData.pBuffer != nullptr)
{
const char *pzETag =
strstr(requestHelper.sWriteFuncHeaderData.pBuffer, "ETag: \"");
if (pzETag)
{
pzETag += strlen("ETag: \"");
const char *pszEndOfETag = strchr(pzETag, '"');
if (pszEndOfETag)
{
FileProp oFileProp;
oFileProp.eExists = EXIST_YES;
oFileProp.fileSize = m_nBufferOff;
oFileProp.bHasComputedFileSize = true;
oFileProp.ETag.assign(pzETag, pszEndOfETag - pzETag);
m_poFS->SetCachedFileProp(
m_poFS->GetURLFromFilename(m_osFilename), oFileProp);
}
}
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
return bSuccess;
}
/************************************************************************/
/* CompleteMultipart() */
/************************************************************************/
bool IVSIS3LikeFSHandler::CompleteMultipart(
const CPLString &osFilename, const CPLString &osUploadID,
const std::vector<CPLString> &aosEtags, vsi_l_offset /* nTotalSize */,
IVSIS3LikeHandleHelper *poS3HandleHelper, int nMaxRetry,
double dfRetryDelay)
{
bool bSuccess = true;
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsFile oContextFile(osFilename);
NetworkStatisticsAction oContextAction("CompleteMultipart");
CPLString osXML = "<CompleteMultipartUpload>\n";
for (size_t i = 0; i < aosEtags.size(); i++)
{
osXML += "<Part>\n";
osXML +=
CPLSPrintf("<PartNumber>%d</PartNumber>", static_cast<int>(i + 1));
osXML += "<ETag>" + aosEtags[i] + "</ETag>";
osXML += "</Part>\n";
}
osXML += "</CompleteMultipartUpload>\n";
#ifdef DEBUG_VERBOSE
CPLDebug(GetDebugKey(), "%s", osXML.c_str());
#endif
const CPLStringList aosHTTPOptions(
CPLHTTPGetOptionsFromEnv(osFilename.c_str()));
int nRetryCount = 0;
bool bRetry;
do
{
bRetry = false;
PutData putData;
putData.pabyData = reinterpret_cast<const GByte *>(osXML.data());
putData.nOff = 0;
putData.nTotalSize = osXML.size();
CURL *hCurlHandle = curl_easy_init();
poS3HandleHelper->AddQueryParameter("uploadId", osUploadID);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_UPLOAD, 1L);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_READFUNCTION,
PutData::ReadCallBackBuffer);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_READDATA, &putData);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_INFILESIZE,
static_cast<int>(osXML.size()));
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_CUSTOMREQUEST, "POST");
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, poS3HandleHelper->GetURL().c_str(),
aosHTTPOptions.List()));
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders(
"POST", headers, osXML.c_str(), osXML.size()));
CurlRequestHelper requestHelper;
const long response_code =
requestHelper.perform(hCurlHandle, headers, this, poS3HandleHelper);
NetworkStatisticsLogger::LogPOST(
osXML.size(), requestHelper.sWriteFuncHeaderData.nSize);
if (response_code != 200)
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
poS3HandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
UpdateMapFromHandle(poS3HandleHelper);
bRetry = true;
}
else
{
CPLDebug("S3", "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined,
"CompleteMultipart of %s (uploadId=%s) failed",
osFilename.c_str(), osUploadID.c_str());
bSuccess = false;
}
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
return bSuccess;
}
/************************************************************************/
/* AbortMultipart() */
/************************************************************************/
bool IVSIS3LikeFSHandler::AbortMultipart(
const CPLString &osFilename, const CPLString &osUploadID,
IVSIS3LikeHandleHelper *poS3HandleHelper, int nMaxRetry,
double dfRetryDelay)
{
bool bSuccess = true;
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsFile oContextFile(osFilename);
NetworkStatisticsAction oContextAction("AbortMultipart");
const CPLStringList aosHTTPOptions(
CPLHTTPGetOptionsFromEnv(osFilename.c_str()));
int nRetryCount = 0;
bool bRetry;
do
{
bRetry = false;
CURL *hCurlHandle = curl_easy_init();
poS3HandleHelper->AddQueryParameter("uploadId", osUploadID);
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_CUSTOMREQUEST,
"DELETE");
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, poS3HandleHelper->GetURL().c_str(),
aosHTTPOptions.List()));
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders("DELETE", headers));
CurlRequestHelper requestHelper;
const long response_code =
requestHelper.perform(hCurlHandle, headers, this, poS3HandleHelper);
NetworkStatisticsLogger::LogDELETE();
if (response_code != 204)
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
poS3HandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
UpdateMapFromHandle(poS3HandleHelper);
bRetry = true;
}
else
{
CPLDebug("S3", "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined,
"AbortMultipart of %s (uploadId=%s) failed",
osFilename.c_str(), osUploadID.c_str());
bSuccess = false;
}
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
return bSuccess;
}
/************************************************************************/
/* AbortPendingUploads() */
/************************************************************************/
bool IVSIS3LikeFSHandler::AbortPendingUploads(const char *pszFilename)
{
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsFile oContextFile(pszFilename);
NetworkStatisticsAction oContextAction("AbortPendingUploads");
// coverity[tainted_data]
const double dfInitialRetryDelay = CPLAtof(
VSIGetPathSpecificOption(pszFilename, "GDAL_HTTP_RETRY_DELAY",
CPLSPrintf("%f", CPL_HTTP_RETRY_DELAY)));
const int nMaxRetry =
atoi(VSIGetPathSpecificOption(pszFilename, "GDAL_HTTP_MAX_RETRY",
CPLSPrintf("%d", CPL_HTTP_MAX_RETRY)));
CPLString osDirnameWithoutPrefix = pszFilename + GetFSPrefix().size();
if (!osDirnameWithoutPrefix.empty() && osDirnameWithoutPrefix.back() == '/')
{
osDirnameWithoutPrefix.resize(osDirnameWithoutPrefix.size() - 1);
}
CPLString osBucket(osDirnameWithoutPrefix);
CPLString osObjectKey;
size_t nSlashPos = osDirnameWithoutPrefix.find('/');
if (nSlashPos != std::string::npos)
{
osBucket = osDirnameWithoutPrefix.substr(0, nSlashPos);
osObjectKey = osDirnameWithoutPrefix.substr(nSlashPos + 1);
}
auto poHandleHelper = std::unique_ptr<IVSIS3LikeHandleHelper>(
CreateHandleHelper(osBucket, true));
if (poHandleHelper == nullptr)
{
return false;
}
UpdateHandleFromMap(poHandleHelper.get());
// For debugging purposes
const int nMaxUploads = std::min(
1000, atoi(CPLGetConfigOption("CPL_VSIS3_LIST_UPLOADS_MAX", "1000")));
std::string osKeyMarker;
std::string osUploadIdMarker;
std::vector<std::pair<std::string, std::string>> aosUploads;
const CPLStringList aosHTTPOptions(CPLHTTPGetOptionsFromEnv(pszFilename));
// First pass: collect (key, uploadId)
while (true)
{
int nRetryCount = 0;
double dfRetryDelay = dfInitialRetryDelay;
bool bRetry;
std::string osXML;
bool bSuccess = true;
do
{
bRetry = false;
CURL *hCurlHandle = curl_easy_init();
poHandleHelper->AddQueryParameter("uploads", "");
if (!osObjectKey.empty())
{
poHandleHelper->AddQueryParameter("prefix", osObjectKey);
}
if (!osKeyMarker.empty())
{
poHandleHelper->AddQueryParameter("key-marker", osKeyMarker);
}
if (!osUploadIdMarker.empty())
{
poHandleHelper->AddQueryParameter("upload-id-marker",
osUploadIdMarker);
}
poHandleHelper->AddQueryParameter("max-uploads",
CPLSPrintf("%d", nMaxUploads));
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, poHandleHelper->GetURL().c_str(),
aosHTTPOptions.List()));
headers = VSICurlMergeHeaders(
headers, poHandleHelper->GetCurlHeaders("GET", headers));
CurlRequestHelper requestHelper;
const long response_code = requestHelper.perform(
hCurlHandle, headers, this, poHandleHelper.get());
NetworkStatisticsLogger::LogGET(requestHelper.sWriteFuncData.nSize);
if (response_code != 200)
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
poHandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poHandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
UpdateMapFromHandle(poHandleHelper.get());
bRetry = true;
}
else
{
CPLDebug(GetDebugKey(), "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined,
"ListMultipartUpload failed");
bSuccess = false;
}
}
else
{
osXML = requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)";
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
if (!bSuccess)
return false;
#ifdef DEBUG_VERBOSE
CPLDebug(GetDebugKey(), "%s", osXML.c_str());
#endif
CPLXMLTreeCloser oTree(CPLParseXMLString(osXML.c_str()));
if (!oTree)
return false;
const CPLXMLNode *psRoot =
CPLGetXMLNode(oTree.get(), "=ListMultipartUploadsResult");
if (!psRoot)
return false;
for (const CPLXMLNode *psIter = psRoot->psChild; psIter;
psIter = psIter->psNext)
{
if (!(psIter->eType == CXT_Element &&
strcmp(psIter->pszValue, "Upload") == 0))
continue;
const char *pszKey = CPLGetXMLValue(psIter, "Key", nullptr);
const char *pszUploadId =
CPLGetXMLValue(psIter, "UploadId", nullptr);
if (pszKey && pszUploadId)
{
aosUploads.emplace_back(
std::pair<std::string, std::string>(pszKey, pszUploadId));
}
}
const bool bIsTruncated =
CPLTestBool(CPLGetXMLValue(psRoot, "IsTruncated", "false"));
if (!bIsTruncated)
break;
osKeyMarker = CPLGetXMLValue(psRoot, "NextKeyMarker", "");
osUploadIdMarker = CPLGetXMLValue(psRoot, "NextUploadIdMarker", "");
}
// Second pass: actually abort those pending uploads
bool bRet = true;
for (const auto &pair : aosUploads)
{
const auto &osKey = pair.first;
const auto &osUploadId = pair.second;
CPLDebug(GetDebugKey(), "Abort %s/%s", osKey.c_str(),
osUploadId.c_str());
auto poSubHandleHelper = std::unique_ptr<IVSIS3LikeHandleHelper>(
CreateHandleHelper((osBucket + '/' + osKey).c_str(), true));
if (poSubHandleHelper == nullptr)
{
bRet = false;
continue;
}
UpdateHandleFromMap(poSubHandleHelper.get());
if (!AbortMultipart(GetFSPrefix() + osBucket + '/' + osKey, osUploadId,
poSubHandleHelper.get(), nMaxRetry,
dfInitialRetryDelay))
{
bRet = false;
}
}
return bRet;
}
/************************************************************************/
/* Close() */
/************************************************************************/
int VSIS3WriteHandle::Close()
{
int nRet = 0;
if (!m_bClosed)
{
m_bClosed = true;
if (m_bUseChunked && m_hCurlMulti != nullptr)
{
nRet = FinishChunkedTransfer();
}
else if (m_osUploadID.empty())
{
if (!m_bError && !DoSinglePartPUT())
nRet = -1;
}
else
{
if (m_bError)
{
if (!m_poFS->AbortMultipart(m_osFilename, m_osUploadID,
m_poS3HandleHelper, m_nMaxRetry,
m_dfRetryDelay))
nRet = -1;
}
else if (m_nBufferOff > 0 && !UploadPart())
nRet = -1;
else if (m_poFS->CompleteMultipart(
m_osFilename, m_osUploadID, m_aosEtags, m_nCurOffset,
m_poS3HandleHelper, m_nMaxRetry, m_dfRetryDelay))
{
InvalidateParentDirectory();
}
else
nRet = -1;
}
}
return nRet;
}
/************************************************************************/
/* Open() */
/************************************************************************/
VSIVirtualHandle *VSIS3FSHandler::Open(const char *pszFilename,
const char *pszAccess, bool bSetError,
CSLConstList papszOptions)
{
if (!STARTS_WITH_CI(pszFilename, GetFSPrefix()))
return nullptr;
if (strchr(pszAccess, 'w') != nullptr || strchr(pszAccess, 'a') != nullptr)
{
if (strchr(pszAccess, '+') != nullptr &&
!SupportsRandomWrite(pszFilename, true))
{
CPLError(CE_Failure, CPLE_AppDefined,
"w+ not supported for /vsis3, unless "
"CPL_VSIL_USE_TEMP_FILE_FOR_RANDOM_WRITE is set to YES");
errno = EACCES;
return nullptr;
}
VSIS3HandleHelper *poS3HandleHelper = VSIS3HandleHelper::BuildFromURI(
pszFilename + GetFSPrefix().size(), GetFSPrefix().c_str(), false);
if (poS3HandleHelper == nullptr)
return nullptr;
UpdateHandleFromMap(poS3HandleHelper);
VSIS3WriteHandle *poHandle = new VSIS3WriteHandle(
this, pszFilename, poS3HandleHelper, false, papszOptions);
if (!poHandle->IsOK())
{
delete poHandle;
return nullptr;
}
if (strchr(pszAccess, '+') != nullptr)
{
return VSICreateUploadOnCloseFile(poHandle);
}
return poHandle;
}
if (CPLString(pszFilename).back() != '/')
{
// If there's directory content for the directory where this file
// belongs to, use it to detect if the object does not exist
CachedDirList cachedDirList;
const CPLString osDirname(CPLGetDirname(pszFilename));
if (STARTS_WITH_CI(osDirname, GetFSPrefix()) &&
GetCachedDirList(osDirname, cachedDirList) &&
cachedDirList.bGotFileList)
{
const CPLString osFilenameOnly(CPLGetFilename(pszFilename));
bool bFound = false;
for (int i = 0; i < cachedDirList.oFileList.size(); i++)
{
if (cachedDirList.oFileList[i] == osFilenameOnly)
{
bFound = true;
break;
}
}
if (!bFound)
{
return nullptr;
}
}
}
return VSICurlFilesystemHandlerBase::Open(pszFilename, pszAccess, bSetError,
papszOptions);
}
/************************************************************************/
/* SupportsRandomWrite() */
/************************************************************************/
bool VSIS3FSHandler::SupportsRandomWrite(const char *pszPath,
bool bAllowLocalTempFile)
{
return bAllowLocalTempFile &&
CPLTestBool(VSIGetPathSpecificOption(
pszPath, "CPL_VSIL_USE_TEMP_FILE_FOR_RANDOM_WRITE", "NO"));
}
/************************************************************************/
/* ~VSIS3FSHandler() */
/************************************************************************/
VSIS3FSHandler::~VSIS3FSHandler()
{
VSIS3FSHandler::ClearCache();
VSIS3HandleHelper::CleanMutex();
}
/************************************************************************/
/* ClearCache() */
/************************************************************************/
void VSIS3FSHandler::ClearCache()
{
VSICurlFilesystemHandlerBase::ClearCache();
VSIS3UpdateParams::ClearCache();
VSIS3HandleHelper::ClearCache();
}
/************************************************************************/
/* GetOptions() */
/************************************************************************/
const char *VSIS3FSHandler::GetOptions()
{
static CPLString osOptions(
CPLString("<Options>") +
" <Option name='AWS_SECRET_ACCESS_KEY' type='string' "
"description='Secret access key. To use with AWS_ACCESS_KEY_ID'/>"
" <Option name='AWS_ACCESS_KEY_ID' type='string' "
"description='Access key id'/>"
" <Option name='AWS_SESSION_TOKEN' type='string' "
"description='Session token'/>"
" <Option name='AWS_REQUEST_PAYER' type='string' "
"description='Content of the x-amz-request-payer HTTP header. "
"Typically \"requester\" for requester-pays buckets'/>"
" <Option name='AWS_VIRTUAL_HOSTING' type='boolean' "
"description='Whether to use virtual hosting server name when the "
"bucket name is compatible with it' default='YES'/>"
" <Option name='AWS_NO_SIGN_REQUEST' type='boolean' "
"description='Whether to disable signing of requests' default='NO'/>"
" <Option name='AWS_DEFAULT_REGION' type='string' "
"description='AWS S3 default region' default='us-east-1'/>"
" <Option name='CPL_AWS_AUTODETECT_EC2' type='boolean' "
"description='Whether to check Hypervisor and DMI identifiers to "
"determine if current host is an AWS EC2 instance' default='YES'/>"
" <Option name='AWS_DEFAULT_PROFILE' type='string' "
"description='Name of the profile to use for IAM credentials "
"retrieval on EC2 instances' default='default'/>"
" <Option name='AWS_CONFIG_FILE' type='string' "
"description='Filename that contains AWS configuration' "
"default='~/.aws/config'/>"
" <Option name='CPL_AWS_CREDENTIALS_FILE' type='string' "
"description='Filename that contains AWS credentials' "
"default='~/.aws/credentials'/>"
" <Option name='VSIS3_CHUNK_SIZE' type='int' "
"description='Size in MB for chunks of files that are uploaded. The"
"default value of 50 MB allows for files up to 500 GB each' "
"default='50' min='5' max='1000'/>" +
VSICurlFilesystemHandlerBase::GetOptionsStatic() + "</Options>");
return osOptions.c_str();
}
/************************************************************************/
/* GetSignedURL() */
/************************************************************************/
char *VSIS3FSHandler::GetSignedURL(const char *pszFilename,
CSLConstList papszOptions)
{
if (!STARTS_WITH_CI(pszFilename, GetFSPrefix()))
return nullptr;
VSIS3HandleHelper *poS3HandleHelper = VSIS3HandleHelper::BuildFromURI(
pszFilename + GetFSPrefix().size(), GetFSPrefix().c_str(), false,
papszOptions);
if (poS3HandleHelper == nullptr)
{
return nullptr;
}
CPLString osRet(poS3HandleHelper->GetSignedURL(papszOptions));
delete poS3HandleHelper;
return CPLStrdup(osRet);
}
/************************************************************************/
/* UnlinkBatch() */
/************************************************************************/
int *VSIS3FSHandler::UnlinkBatch(CSLConstList papszFiles)
{
// Implemented using
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html
int *panRet =
static_cast<int *>(CPLCalloc(sizeof(int), CSLCount(papszFiles)));
CPLStringList aosList;
CPLString osCurBucket;
int iStartIndex = -1;
// For debug / testing only
const int nBatchSize =
atoi(CPLGetConfigOption("CPL_VSIS3_UNLINK_BATCH_SIZE", "1000"));
for (int i = 0; papszFiles && papszFiles[i]; i++)
{
CPLAssert(STARTS_WITH_CI(papszFiles[i], GetFSPrefix()));
const char *pszFilenameWithoutPrefix =
papszFiles[i] + GetFSPrefix().size();
const char *pszSlash = strchr(pszFilenameWithoutPrefix, '/');
if (!pszSlash)
return panRet;
CPLString osBucket;
osBucket.assign(pszFilenameWithoutPrefix,
pszSlash - pszFilenameWithoutPrefix);
bool bBucketChanged = false;
if ((osCurBucket.empty() || osCurBucket == osBucket))
{
if (osCurBucket.empty())
{
iStartIndex = i;
osCurBucket = osBucket;
}
aosList.AddString(pszSlash + 1);
}
else
{
bBucketChanged = true;
}
while (bBucketChanged || aosList.size() == nBatchSize ||
papszFiles[i + 1] == nullptr)
{
// Compose XML post content
CPLXMLNode *psXML = CPLCreateXMLNode(nullptr, CXT_Element, "?xml");
CPLAddXMLAttributeAndValue(psXML, "version", "1.0");
CPLAddXMLAttributeAndValue(psXML, "encoding", "UTF-8");
CPLXMLNode *psDelete =
CPLCreateXMLNode(nullptr, CXT_Element, "Delete");
psXML->psNext = psDelete;
CPLAddXMLAttributeAndValue(
psDelete, "xmlns", "http://s3.amazonaws.com/doc/2006-03-01/");
CPLXMLNode *psLastChild = psDelete->psChild;
CPLAssert(psLastChild != nullptr);
CPLAssert(psLastChild->psNext == nullptr);
std::map<CPLString, int> mapKeyToIndex;
for (int j = 0; aosList[j]; ++j)
{
CPLXMLNode *psObject =
CPLCreateXMLNode(nullptr, CXT_Element, "Object");
mapKeyToIndex[aosList[j]] = iStartIndex + j;
CPLCreateXMLElementAndValue(psObject, "Key", aosList[j]);
psLastChild->psNext = psObject;
psLastChild = psObject;
}
// Run request
char *pszXML = CPLSerializeXMLTree(psXML);
CPLDestroyXMLNode(psXML);
auto oDeletedKeys = DeleteObjects(osCurBucket.c_str(), pszXML);
CPLFree(pszXML);
// Mark delete file
for (const auto &osDeletedKey : oDeletedKeys)
{
auto mapKeyToIndexIter = mapKeyToIndex.find(osDeletedKey);
if (mapKeyToIndexIter != mapKeyToIndex.end())
{
panRet[mapKeyToIndexIter->second] = true;
}
}
osCurBucket.clear();
aosList.Clear();
if (bBucketChanged)
{
iStartIndex = i;
osCurBucket = osBucket;
aosList.AddString(pszSlash + 1);
bBucketChanged = false;
}
else
{
break;
}
}
}
return panRet;
}
/************************************************************************/
/* RmdirRecursive() */
/************************************************************************/
int VSIS3FSHandler::RmdirRecursive(const char *pszDirname)
{
// Some S3-like APIs do not support DeleteObjects
if (CPLTestBool(VSIGetPathSpecificOption(
pszDirname, "CPL_VSIS3_USE_BASE_RMDIR_RECURSIVE", "NO")))
return VSIFilesystemHandler::RmdirRecursive(pszDirname);
// For debug / testing only
const int nBatchSize =
atoi(CPLGetConfigOption("CPL_VSIS3_UNLINK_BATCH_SIZE", "1000"));
return RmdirRecursiveInternal(pszDirname, nBatchSize);
}
int IVSIS3LikeFSHandler::RmdirRecursiveInternal(const char *pszDirname,
int nBatchSize)
{
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("RmdirRecursive");
CPLString osDirnameWithoutEndSlash(pszDirname);
if (!osDirnameWithoutEndSlash.empty() &&
osDirnameWithoutEndSlash.back() == '/')
osDirnameWithoutEndSlash.resize(osDirnameWithoutEndSlash.size() - 1);
CPLStringList aosOptions;
aosOptions.SetNameValue("CACHE_ENTRIES", "FALSE");
auto poDir = std::unique_ptr<VSIDIR>(
OpenDir(osDirnameWithoutEndSlash, -1, aosOptions.List()));
if (!poDir)
return -1;
CPLStringList aosList;
while (true)
{
auto entry = poDir->NextDirEntry();
if (entry)
{
CPLString osFilename(osDirnameWithoutEndSlash + '/' +
entry->pszName);
if (entry->nMode == S_IFDIR)
osFilename += '/';
aosList.AddString(osFilename);
}
if (entry == nullptr || aosList.size() == nBatchSize)
{
if (entry == nullptr && !osDirnameWithoutEndSlash.empty())
{
aosList.AddString((osDirnameWithoutEndSlash + '/').c_str());
}
int *ret = UnlinkBatch(aosList.List());
if (ret == nullptr)
return -1;
CPLFree(ret);
aosList.Clear();
}
if (entry == nullptr)
break;
}
PartialClearCache(osDirnameWithoutEndSlash);
return 0;
}
/************************************************************************/
/* DeleteObjects() */
/************************************************************************/
std::set<CPLString> VSIS3FSHandler::DeleteObjects(const char *pszBucket,
const char *pszXML)
{
auto poS3HandleHelper =
std::unique_ptr<VSIS3HandleHelper>(VSIS3HandleHelper::BuildFromURI(
pszBucket, GetFSPrefix().c_str(), true));
if (!poS3HandleHelper)
return std::set<CPLString>();
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("DeleteObjects");
std::set<CPLString> oDeletedKeys;
bool bRetry;
const std::string osFilename(GetFSPrefix() + pszBucket);
// coverity[tainted_data]
double dfRetryDelay = CPLAtof(
VSIGetPathSpecificOption(osFilename.c_str(), "GDAL_HTTP_RETRY_DELAY",
CPLSPrintf("%f", CPL_HTTP_RETRY_DELAY)));
const int nMaxRetry =
atoi(VSIGetPathSpecificOption(osFilename.c_str(), "GDAL_HTTP_MAX_RETRY",
CPLSPrintf("%d", CPL_HTTP_MAX_RETRY)));
int nRetryCount = 0;
CPLString osContentMD5;
struct CPLMD5Context context;
CPLMD5Init(&context);
CPLMD5Update(&context, pszXML, strlen(pszXML));
unsigned char hash[16];
CPLMD5Final(hash, &context);
char *pszBase64 = CPLBase64Encode(16, hash);
osContentMD5.Printf("Content-MD5: %s", pszBase64);
CPLFree(pszBase64);
const CPLStringList aosHTTPOptions(
CPLHTTPGetOptionsFromEnv(osFilename.c_str()));
do
{
bRetry = false;
CURL *hCurlHandle = curl_easy_init();
poS3HandleHelper->AddQueryParameter("delete", "");
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_CUSTOMREQUEST, "POST");
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_POSTFIELDS, pszXML);
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, poS3HandleHelper->GetURL().c_str(),
aosHTTPOptions.List()));
headers = curl_slist_append(headers, "Content-Type: application/xml");
headers = curl_slist_append(headers, osContentMD5.c_str());
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders("POST", headers, pszXML,
strlen(pszXML)));
CurlRequestHelper requestHelper;
const long response_code = requestHelper.perform(
hCurlHandle, headers, this, poS3HandleHelper.get());
NetworkStatisticsLogger::LogPOST(strlen(pszXML),
requestHelper.sWriteFuncData.nSize);
if (response_code != 200 ||
requestHelper.sWriteFuncData.pBuffer == nullptr)
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
poS3HandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
UpdateMapFromHandle(poS3HandleHelper.get());
bRetry = true;
}
else
{
CPLDebug(GetDebugKey(), "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined, "DeleteObjects failed");
}
}
else
{
CPLXMLNode *psXML =
CPLParseXMLString(requestHelper.sWriteFuncData.pBuffer);
if (psXML)
{
CPLXMLNode *psDeleteResult =
CPLGetXMLNode(psXML, "=DeleteResult");
if (psDeleteResult)
{
for (CPLXMLNode *psIter = psDeleteResult->psChild; psIter;
psIter = psIter->psNext)
{
if (psIter->eType == CXT_Element &&
strcmp(psIter->pszValue, "Deleted") == 0)
{
CPLString osKey = CPLGetXMLValue(psIter, "Key", "");
oDeletedKeys.insert(osKey);
InvalidateCachedData(
(poS3HandleHelper->GetURL() + osKey).c_str());
InvalidateDirContent(CPLGetDirname(
(GetFSPrefix() + pszBucket + "/" + osKey)
.c_str()));
}
}
}
CPLDestroyXMLNode(psXML);
}
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
return oDeletedKeys;
}
/************************************************************************/
/* GetFileMetadata() */
/************************************************************************/
char **VSIS3FSHandler::GetFileMetadata(const char *pszFilename,
const char *pszDomain,
CSLConstList papszOptions)
{
if (!STARTS_WITH_CI(pszFilename, GetFSPrefix()))
return nullptr;
if (pszDomain == nullptr || !EQUAL(pszDomain, "TAGS"))
{
return VSICurlFilesystemHandlerBase::GetFileMetadata(
pszFilename, pszDomain, papszOptions);
}
auto poS3HandleHelper =
std::unique_ptr<VSIS3HandleHelper>(VSIS3HandleHelper::BuildFromURI(
pszFilename + GetFSPrefix().size(), GetFSPrefix().c_str(), false));
if (!poS3HandleHelper)
return nullptr;
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("GetFileMetadata");
bool bRetry;
// coverity[tainted_data]
double dfRetryDelay = CPLAtof(
VSIGetPathSpecificOption(pszFilename, "GDAL_HTTP_RETRY_DELAY",
CPLSPrintf("%f", CPL_HTTP_RETRY_DELAY)));
const int nMaxRetry =
atoi(VSIGetPathSpecificOption(pszFilename, "GDAL_HTTP_MAX_RETRY",
CPLSPrintf("%d", CPL_HTTP_MAX_RETRY)));
int nRetryCount = 0;
const CPLStringList aosHTTPOptions(CPLHTTPGetOptionsFromEnv(pszFilename));
CPLStringList aosTags;
do
{
bRetry = false;
CURL *hCurlHandle = curl_easy_init();
poS3HandleHelper->AddQueryParameter("tagging", "");
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, poS3HandleHelper->GetURL().c_str(),
aosHTTPOptions.List()));
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders("GET", headers));
CurlRequestHelper requestHelper;
const long response_code = requestHelper.perform(
hCurlHandle, headers, this, poS3HandleHelper.get());
NetworkStatisticsLogger::LogGET(requestHelper.sWriteFuncData.nSize);
if (response_code != 200 ||
requestHelper.sWriteFuncData.pBuffer == nullptr)
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
poS3HandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
UpdateMapFromHandle(poS3HandleHelper.get());
bRetry = true;
}
else
{
CPLDebug(GetDebugKey(), "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined,
"GetObjectTagging failed");
}
}
else
{
CPLXMLNode *psXML =
CPLParseXMLString(requestHelper.sWriteFuncData.pBuffer);
if (psXML)
{
CPLXMLNode *psTagSet = CPLGetXMLNode(psXML, "=Tagging.TagSet");
if (psTagSet)
{
for (CPLXMLNode *psIter = psTagSet->psChild; psIter;
psIter = psIter->psNext)
{
if (psIter->eType == CXT_Element &&
strcmp(psIter->pszValue, "Tag") == 0)
{
CPLString osKey = CPLGetXMLValue(psIter, "Key", "");
CPLString osValue =
CPLGetXMLValue(psIter, "Value", "");
aosTags.SetNameValue(osKey, osValue);
}
}
}
CPLDestroyXMLNode(psXML);
}
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
return CSLDuplicate(aosTags.List());
}
/************************************************************************/
/* SetFileMetadata() */
/************************************************************************/
bool VSIS3FSHandler::SetFileMetadata(const char *pszFilename,
CSLConstList papszMetadata,
const char *pszDomain,
CSLConstList /* papszOptions */)
{
if (!STARTS_WITH_CI(pszFilename, GetFSPrefix()))
return false;
if (pszDomain == nullptr ||
!(EQUAL(pszDomain, "HEADERS") || EQUAL(pszDomain, "TAGS")))
{
CPLError(CE_Failure, CPLE_NotSupported,
"Only HEADERS and TAGS domain are supported");
return false;
}
if (EQUAL(pszDomain, "HEADERS"))
{
return CopyObject(pszFilename, pszFilename, papszMetadata) == 0;
}
auto poS3HandleHelper =
std::unique_ptr<VSIS3HandleHelper>(VSIS3HandleHelper::BuildFromURI(
pszFilename + GetFSPrefix().size(), GetFSPrefix().c_str(), false));
if (!poS3HandleHelper)
return false;
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("SetFileMetadata");
bool bRetry;
// coverity[tainted_data]
double dfRetryDelay = CPLAtof(
VSIGetPathSpecificOption(pszFilename, "GDAL_HTTP_RETRY_DELAY",
CPLSPrintf("%f", CPL_HTTP_RETRY_DELAY)));
const int nMaxRetry =
atoi(VSIGetPathSpecificOption(pszFilename, "GDAL_HTTP_MAX_RETRY",
CPLSPrintf("%d", CPL_HTTP_MAX_RETRY)));
int nRetryCount = 0;
// Compose XML post content
CPLString osXML;
if (papszMetadata != nullptr && papszMetadata[0] != nullptr)
{
CPLXMLNode *psXML = CPLCreateXMLNode(nullptr, CXT_Element, "?xml");
CPLAddXMLAttributeAndValue(psXML, "version", "1.0");
CPLAddXMLAttributeAndValue(psXML, "encoding", "UTF-8");
CPLXMLNode *psTagging =
CPLCreateXMLNode(nullptr, CXT_Element, "Tagging");
psXML->psNext = psTagging;
CPLAddXMLAttributeAndValue(psTagging, "xmlns",
"http://s3.amazonaws.com/doc/2006-03-01/");
CPLXMLNode *psTagSet =
CPLCreateXMLNode(psTagging, CXT_Element, "TagSet");
for (int i = 0; papszMetadata[i]; ++i)
{
char *pszKey = nullptr;
const char *pszValue = CPLParseNameValue(papszMetadata[i], &pszKey);
if (pszKey && pszValue)
{
CPLXMLNode *psTag =
CPLCreateXMLNode(psTagSet, CXT_Element, "Tag");
CPLCreateXMLElementAndValue(psTag, "Key", pszKey);
CPLCreateXMLElementAndValue(psTag, "Value", pszValue);
}
CPLFree(pszKey);
}
char *pszXML = CPLSerializeXMLTree(psXML);
osXML = pszXML;
CPLFree(pszXML);
CPLDestroyXMLNode(psXML);
}
CPLString osContentMD5;
if (!osXML.empty())
{
struct CPLMD5Context context;
CPLMD5Init(&context);
CPLMD5Update(&context, osXML.data(), osXML.size());
unsigned char hash[16];
CPLMD5Final(hash, &context);
char *pszBase64 = CPLBase64Encode(16, hash);
osContentMD5.Printf("Content-MD5: %s", pszBase64);
CPLFree(pszBase64);
}
bool bRet = false;
const CPLStringList aosHTTPOptions(CPLHTTPGetOptionsFromEnv(pszFilename));
do
{
bRetry = false;
CURL *hCurlHandle = curl_easy_init();
poS3HandleHelper->AddQueryParameter("tagging", "");
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_CUSTOMREQUEST,
osXML.empty() ? "DELETE" : "PUT");
if (!osXML.empty())
{
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_POSTFIELDS,
osXML.c_str());
}
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, poS3HandleHelper->GetURL().c_str(),
aosHTTPOptions.List()));
if (!osXML.empty())
{
headers =
curl_slist_append(headers, "Content-Type: application/xml");
headers = curl_slist_append(headers, osContentMD5.c_str());
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders(
"PUT", headers, osXML.c_str(), osXML.size()));
NetworkStatisticsLogger::LogPUT(osXML.size());
}
else
{
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders("DELETE", headers));
NetworkStatisticsLogger::LogDELETE();
}
CurlRequestHelper requestHelper;
const long response_code = requestHelper.perform(
hCurlHandle, headers, this, poS3HandleHelper.get());
if ((!osXML.empty() && response_code != 200) ||
(osXML.empty() && response_code != 204))
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
poS3HandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
UpdateMapFromHandle(poS3HandleHelper.get());
bRetry = true;
}
else
{
CPLDebug(GetDebugKey(), "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined,
"PutObjectTagging failed");
}
}
else
{
bRet = true;
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
return bRet;
}
/************************************************************************/
/* GetStreamingFilename() */
/************************************************************************/
std::string
VSIS3FSHandler::GetStreamingFilename(const std::string &osFilename) const
{
if (STARTS_WITH(osFilename.c_str(), GetFSPrefix().c_str()))
return "/vsis3_streaming/" + osFilename.substr(GetFSPrefix().size());
return osFilename;
}
/************************************************************************/
/* Mkdir() */
/************************************************************************/
int IVSIS3LikeFSHandler::MkdirInternal(const char *pszDirname, long /*nMode*/,
bool bDoStatCheck)
{
if (!STARTS_WITH_CI(pszDirname, GetFSPrefix()))
return -1;
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("Mkdir");
CPLString osDirname(pszDirname);
if (!osDirname.empty() && osDirname.back() != '/')
osDirname += "/";
if (bDoStatCheck)
{
VSIStatBufL sStat;
if (VSIStatL(osDirname, &sStat) == 0 && VSI_ISDIR(sStat.st_mode))
{
CPLDebug(GetDebugKey(), "Directory %s already exists",
osDirname.c_str());
errno = EEXIST;
return -1;
}
}
int ret = 0;
if (CPLTestBool(CPLGetConfigOption("CPL_VSIS3_CREATE_DIR_OBJECT", "YES")))
{
VSILFILE *fp = VSIFOpenL(osDirname, "wb");
if (fp != nullptr)
{
CPLErrorReset();
VSIFCloseL(fp);
ret = CPLGetLastErrorType() == CPLE_None ? 0 : -1;
}
else
{
ret = -1;
}
}
if (ret == 0)
{
CPLString osDirnameWithoutEndSlash(osDirname);
osDirnameWithoutEndSlash.resize(osDirnameWithoutEndSlash.size() - 1);
InvalidateDirContent(CPLGetDirname(osDirnameWithoutEndSlash));
FileProp cachedFileProp;
GetCachedFileProp(GetURLFromFilename(osDirname), cachedFileProp);
cachedFileProp.eExists = EXIST_YES;
cachedFileProp.bIsDirectory = true;
cachedFileProp.bHasComputedFileSize = true;
SetCachedFileProp(GetURLFromFilename(osDirname), cachedFileProp);
RegisterEmptyDir(osDirnameWithoutEndSlash);
RegisterEmptyDir(osDirname);
}
return ret;
}
int IVSIS3LikeFSHandler::Mkdir(const char *pszDirname, long nMode)
{
return MkdirInternal(pszDirname, nMode, true);
}
/************************************************************************/
/* Rmdir() */
/************************************************************************/
int IVSIS3LikeFSHandler::Rmdir(const char *pszDirname)
{
if (!STARTS_WITH_CI(pszDirname, GetFSPrefix()))
return -1;
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("Rmdir");
CPLString osDirname(pszDirname);
if (!osDirname.empty() && osDirname.back() != '/')
osDirname += "/";
VSIStatBufL sStat;
if (VSIStatL(osDirname, &sStat) != 0)
{
CPLDebug(GetDebugKey(), "%s is not a object", pszDirname);
errno = ENOENT;
return -1;
}
else if (!VSI_ISDIR(sStat.st_mode))
{
CPLDebug(GetDebugKey(), "%s is not a directory", pszDirname);
errno = ENOTDIR;
return -1;
}
char **papszFileList = ReadDirEx(osDirname, 100);
bool bEmptyDir =
papszFileList == nullptr ||
(EQUAL(papszFileList[0], ".") && papszFileList[1] == nullptr);
CSLDestroy(papszFileList);
if (!bEmptyDir)
{
CPLDebug(GetDebugKey(), "%s is not empty", pszDirname);
errno = ENOTEMPTY;
return -1;
}
CPLString osDirnameWithoutEndSlash(osDirname);
osDirnameWithoutEndSlash.resize(osDirnameWithoutEndSlash.size() - 1);
if (osDirnameWithoutEndSlash.find('/', GetFSPrefix().size()) ==
std::string::npos)
{
CPLDebug(GetDebugKey(), "%s is a bucket", pszDirname);
errno = ENOTDIR;
return -1;
}
int ret = DeleteObject(osDirname);
if (ret == 0)
{
InvalidateDirContent(osDirnameWithoutEndSlash);
}
return ret;
}
/************************************************************************/
/* Stat() */
/************************************************************************/
int IVSIS3LikeFSHandler::Stat(const char *pszFilename, VSIStatBufL *pStatBuf,
int nFlags)
{
if (!STARTS_WITH_CI(pszFilename, GetFSPrefix()))
return -1;
if ((nFlags & VSI_STAT_CACHE_ONLY) != 0)
return VSICurlFilesystemHandlerBase::Stat(pszFilename, pStatBuf,
nFlags);
memset(pStatBuf, 0, sizeof(VSIStatBufL));
if (!IsAllowedFilename(pszFilename))
return -1;
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("Stat");
CPLString osFilename(pszFilename);
if (osFilename.find('/', GetFSPrefix().size()) == std::string::npos)
osFilename += "/";
CPLString osFilenameWithoutSlash(osFilename);
if (osFilenameWithoutSlash.back() == '/')
osFilenameWithoutSlash.resize(osFilenameWithoutSlash.size() - 1);
// If there's directory content for the directory where this file belongs
// to, use it to detect if the object does not exist
CachedDirList cachedDirList;
const CPLString osDirname(CPLGetDirname(osFilenameWithoutSlash));
if (STARTS_WITH_CI(osDirname, GetFSPrefix()) &&
GetCachedDirList(osDirname, cachedDirList) &&
cachedDirList.bGotFileList)
{
const CPLString osFilenameOnly(CPLGetFilename(osFilenameWithoutSlash));
bool bFound = false;
for (int i = 0; i < cachedDirList.oFileList.size(); i++)
{
if (cachedDirList.oFileList[i] == osFilenameOnly)
{
bFound = true;
break;
}
}
if (!bFound)
{
return -1;
}
}
if (VSICurlFilesystemHandlerBase::Stat(osFilename, pStatBuf, nFlags) == 0)
{
return 0;
}
char **papszRet = ReadDirInternal(osFilename, 100, nullptr);
int nRet = papszRet ? 0 : -1;
if (nRet == 0)
{
pStatBuf->st_mtime = 0;
pStatBuf->st_size = 0;
pStatBuf->st_mode = S_IFDIR;
FileProp cachedFileProp;
GetCachedFileProp(GetURLFromFilename(osFilename), cachedFileProp);
cachedFileProp.eExists = EXIST_YES;
cachedFileProp.bIsDirectory = true;
cachedFileProp.bHasComputedFileSize = true;
SetCachedFileProp(GetURLFromFilename(osFilename), cachedFileProp);
}
CSLDestroy(papszRet);
return nRet;
}
/************************************************************************/
/* CreateFileHandle() */
/************************************************************************/
VSICurlHandle *VSIS3FSHandler::CreateFileHandle(const char *pszFilename)
{
VSIS3HandleHelper *poS3HandleHelper = VSIS3HandleHelper::BuildFromURI(
pszFilename + GetFSPrefix().size(), GetFSPrefix().c_str(), false);
if (poS3HandleHelper)
{
UpdateHandleFromMap(poS3HandleHelper);
return new VSIS3Handle(this, pszFilename, poS3HandleHelper);
}
return nullptr;
}
/************************************************************************/
/* GetURLFromFilename() */
/************************************************************************/
CPLString VSIS3FSHandler::GetURLFromFilename(const CPLString &osFilename)
{
CPLString osFilenameWithoutPrefix = osFilename.substr(GetFSPrefix().size());
VSIS3HandleHelper *poS3HandleHelper = VSIS3HandleHelper::BuildFromURI(
osFilenameWithoutPrefix, GetFSPrefix().c_str(), true);
if (poS3HandleHelper == nullptr)
{
return "";
}
UpdateHandleFromMap(poS3HandleHelper);
CPLString osBaseURL(poS3HandleHelper->GetURL());
if (!osBaseURL.empty() && osBaseURL.back() == '/')
osBaseURL.resize(osBaseURL.size() - 1);
delete poS3HandleHelper;
return osBaseURL;
}
/************************************************************************/
/* CreateHandleHelper() */
/************************************************************************/
IVSIS3LikeHandleHelper *VSIS3FSHandler::CreateHandleHelper(const char *pszURI,
bool bAllowNoObject)
{
return VSIS3HandleHelper::BuildFromURI(pszURI, GetFSPrefix().c_str(),
bAllowNoObject);
}
/************************************************************************/
/* Unlink() */
/************************************************************************/
int IVSIS3LikeFSHandler::Unlink(const char *pszFilename)
{
if (!STARTS_WITH_CI(pszFilename, GetFSPrefix()))
return -1;
CPLString osNameWithoutPrefix = pszFilename + GetFSPrefix().size();
if (osNameWithoutPrefix.find('/') == std::string::npos)
{
CPLDebug(GetDebugKey(), "%s is not a file", pszFilename);
errno = EISDIR;
return -1;
}
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("Unlink");
VSIStatBufL sStat;
if (VSIStatL(pszFilename, &sStat) != 0)
{
CPLDebug(GetDebugKey(), "%s is not a object", pszFilename);
errno = ENOENT;
return -1;
}
else if (!VSI_ISREG(sStat.st_mode))
{
CPLDebug(GetDebugKey(), "%s is not a file", pszFilename);
errno = EISDIR;
return -1;
}
return DeleteObject(pszFilename);
}
/************************************************************************/
/* Rename() */
/************************************************************************/
int IVSIS3LikeFSHandler::Rename(const char *oldpath, const char *newpath)
{
if (!STARTS_WITH_CI(oldpath, GetFSPrefix()))
return -1;
if (!STARTS_WITH_CI(newpath, GetFSPrefix()))
return -1;
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("Rename");
VSIStatBufL sStat;
if (VSIStatL(oldpath, &sStat) != 0)
{
CPLDebug(GetDebugKey(), "%s is not a object", oldpath);
errno = ENOENT;
return -1;
}
// AWS doesn't like renaming to the same name, and errors out
// But GCS does like it, and so we might end up killing ourselves !
// POSIX says renaming on the same file is OK
if (strcmp(oldpath, newpath) == 0)
return 0;
if (VSI_ISDIR(sStat.st_mode))
{
CPLStringList aosList(VSIReadDir(oldpath));
Mkdir(newpath, 0755);
for (int i = 0; i < aosList.size(); i++)
{
CPLString osSrc = CPLFormFilename(oldpath, aosList[i], nullptr);
CPLString osTarget = CPLFormFilename(newpath, aosList[i], nullptr);
if (Rename(osSrc, osTarget) != 0)
{
return -1;
}
}
Rmdir(oldpath);
return 0;
}
else
{
if (VSIStatL(newpath, &sStat) == 0 && VSI_ISDIR(sStat.st_mode))
{
CPLDebug(GetDebugKey(), "%s already exists and is a directory",
newpath);
errno = ENOTEMPTY;
return -1;
}
if (CopyObject(oldpath, newpath, nullptr) != 0)
{
return -1;
}
return DeleteObject(oldpath);
}
}
/************************************************************************/
/* CopyObject() */
/************************************************************************/
int IVSIS3LikeFSHandler::CopyObject(const char *oldpath, const char *newpath,
CSLConstList papszMetadata)
{
CPLString osTargetNameWithoutPrefix = newpath + GetFSPrefix().size();
std::unique_ptr<IVSIS3LikeHandleHelper> poS3HandleHelper(
CreateHandleHelper(osTargetNameWithoutPrefix, false));
if (poS3HandleHelper == nullptr)
{
return -1;
}
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("CopyObject");
std::string osSourceHeader(poS3HandleHelper->GetCopySourceHeader());
if (osSourceHeader.empty())
{
CPLError(CE_Failure, CPLE_NotSupported,
"Object copy not supported by this file system");
return -1;
}
osSourceHeader += ": /";
if (STARTS_WITH(oldpath, "/vsis3/"))
osSourceHeader +=
CPLAWSURLEncode(oldpath + GetFSPrefix().size(), false);
else
osSourceHeader += (oldpath + GetFSPrefix().size());
UpdateHandleFromMap(poS3HandleHelper.get());
int nRet = 0;
bool bRetry;
// coverity[tainted_data]
double dfRetryDelay = CPLAtof(
VSIGetPathSpecificOption(oldpath, "GDAL_HTTP_RETRY_DELAY",
CPLSPrintf("%f", CPL_HTTP_RETRY_DELAY)));
const int nMaxRetry = atoi(VSIGetPathSpecificOption(
oldpath, "GDAL_HTTP_MAX_RETRY", CPLSPrintf("%d", CPL_HTTP_MAX_RETRY)));
int nRetryCount = 0;
const CPLStringList aosHTTPOptions(CPLHTTPGetOptionsFromEnv(oldpath));
do
{
bRetry = false;
CURL *hCurlHandle = curl_easy_init();
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_CUSTOMREQUEST, "PUT");
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, poS3HandleHelper->GetURL().c_str(),
aosHTTPOptions.List()));
headers = curl_slist_append(headers, osSourceHeader.c_str());
headers = curl_slist_append(
headers, "Content-Length: 0"); // Required by GCS, but not by S3
if (papszMetadata && papszMetadata[0])
{
const char *pszReplaceDirective =
poS3HandleHelper->GetMetadataDirectiveREPLACE();
if (pszReplaceDirective[0])
headers = curl_slist_append(headers, pszReplaceDirective);
for (int i = 0; papszMetadata[i]; i++)
{
char *pszKey = nullptr;
const char *pszValue =
CPLParseNameValue(papszMetadata[i], &pszKey);
if (pszKey && pszValue)
{
headers = curl_slist_append(
headers, CPLSPrintf("%s: %s", pszKey, pszValue));
}
CPLFree(pszKey);
}
}
headers = VSICurlSetContentTypeFromExt(headers, newpath);
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders("PUT", headers));
CurlRequestHelper requestHelper;
const long response_code = requestHelper.perform(
hCurlHandle, headers, this, poS3HandleHelper.get());
NetworkStatisticsLogger::LogPUT(0);
if (response_code != 200)
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
poS3HandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
UpdateMapFromHandle(poS3HandleHelper.get());
bRetry = true;
}
else
{
CPLDebug(GetDebugKey(), "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined, "Copy of %s to %s failed",
oldpath, newpath);
nRet = -1;
}
}
else
{
InvalidateCachedData(poS3HandleHelper->GetURL().c_str());
CPLString osFilenameWithoutSlash(newpath);
if (!osFilenameWithoutSlash.empty() &&
osFilenameWithoutSlash.back() == '/')
osFilenameWithoutSlash.resize(osFilenameWithoutSlash.size() -
1);
InvalidateDirContent(CPLGetDirname(osFilenameWithoutSlash));
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
return nRet;
}
/************************************************************************/
/* DeleteObject() */
/************************************************************************/
int IVSIS3LikeFSHandler::DeleteObject(const char *pszFilename)
{
CPLString osNameWithoutPrefix = pszFilename + GetFSPrefix().size();
IVSIS3LikeHandleHelper *poS3HandleHelper =
CreateHandleHelper(osNameWithoutPrefix, false);
if (poS3HandleHelper == nullptr)
{
return -1;
}
UpdateHandleFromMap(poS3HandleHelper);
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("DeleteObject");
int nRet = 0;
bool bRetry;
// coverity[tainted_data]
double dfRetryDelay = CPLAtof(
VSIGetPathSpecificOption(pszFilename, "GDAL_HTTP_RETRY_DELAY",
CPLSPrintf("%f", CPL_HTTP_RETRY_DELAY)));
const int nMaxRetry =
atoi(VSIGetPathSpecificOption(pszFilename, "GDAL_HTTP_MAX_RETRY",
CPLSPrintf("%d", CPL_HTTP_MAX_RETRY)));
int nRetryCount = 0;
const CPLStringList aosHTTPOptions(CPLHTTPGetOptionsFromEnv(pszFilename));
do
{
bRetry = false;
CURL *hCurlHandle = curl_easy_init();
unchecked_curl_easy_setopt(hCurlHandle, CURLOPT_CUSTOMREQUEST,
"DELETE");
struct curl_slist *headers = static_cast<struct curl_slist *>(
CPLHTTPSetOptions(hCurlHandle, poS3HandleHelper->GetURL().c_str(),
aosHTTPOptions.List()));
headers = VSICurlMergeHeaders(
headers, poS3HandleHelper->GetCurlHeaders("DELETE", headers));
CurlRequestHelper requestHelper;
const long response_code =
requestHelper.perform(hCurlHandle, headers, this, poS3HandleHelper);
NetworkStatisticsLogger::LogDELETE();
// S3 and GS respond with 204. Azure with 202. ADLS with 200.
if (response_code != 204 && response_code != 202 &&
response_code != 200)
{
// Look if we should attempt a retry
const double dfNewRetryDelay = CPLHTTPGetNewRetryDelay(
static_cast<int>(response_code), dfRetryDelay,
requestHelper.sWriteFuncHeaderData.pBuffer,
requestHelper.szCurlErrBuf);
if (dfNewRetryDelay > 0 && nRetryCount < nMaxRetry)
{
CPLError(CE_Warning, CPLE_AppDefined,
"HTTP error code: %d - %s. "
"Retrying again in %.1f secs",
static_cast<int>(response_code),
poS3HandleHelper->GetURL().c_str(), dfRetryDelay);
CPLSleep(dfRetryDelay);
dfRetryDelay = dfNewRetryDelay;
nRetryCount++;
bRetry = true;
}
else if (requestHelper.sWriteFuncData.pBuffer != nullptr &&
poS3HandleHelper->CanRestartOnError(
requestHelper.sWriteFuncData.pBuffer,
requestHelper.sWriteFuncHeaderData.pBuffer, false))
{
UpdateMapFromHandle(poS3HandleHelper);
bRetry = true;
}
else
{
CPLDebug(GetDebugKey(), "%s",
requestHelper.sWriteFuncData.pBuffer
? requestHelper.sWriteFuncData.pBuffer
: "(null)");
CPLError(CE_Failure, CPLE_AppDefined, "Delete of %s failed",
pszFilename);
nRet = -1;
}
}
else
{
InvalidateCachedData(poS3HandleHelper->GetURL().c_str());
CPLString osFilenameWithoutSlash(pszFilename);
if (!osFilenameWithoutSlash.empty() &&
osFilenameWithoutSlash.back() == '/')
osFilenameWithoutSlash.resize(osFilenameWithoutSlash.size() -
1);
InvalidateDirContent(CPLGetDirname(osFilenameWithoutSlash));
}
curl_easy_cleanup(hCurlHandle);
} while (bRetry);
delete poS3HandleHelper;
return nRet;
}
/************************************************************************/
/* GetFileList() */
/************************************************************************/
char **IVSIS3LikeFSHandler::GetFileList(const char *pszDirname, int nMaxFiles,
bool *pbGotFileList)
{
if (ENABLE_DEBUG)
CPLDebug(GetDebugKey(), "GetFileList(%s)", pszDirname);
*pbGotFileList = false;
char **papszOptions =
CSLSetNameValue(nullptr, "MAXFILES", CPLSPrintf("%d", nMaxFiles));
auto dir = OpenDir(pszDirname, 0, papszOptions);
CSLDestroy(papszOptions);
if (!dir)
{
return nullptr;
}
CPLStringList aosFileList;
while (true)
{
auto entry = dir->NextDirEntry();
if (!entry)
{
break;
}
aosFileList.AddString(entry->pszName);
if (nMaxFiles > 0 && aosFileList.size() >= nMaxFiles)
break;
}
delete dir;
*pbGotFileList = true;
return aosFileList.StealList();
}
/************************************************************************/
/* OpenDir() */
/************************************************************************/
VSIDIR *IVSIS3LikeFSHandler::OpenDir(const char *pszPath, int nRecurseDepth,
const char *const *papszOptions)
{
if (nRecurseDepth > 0)
{
return VSIFilesystemHandler::OpenDir(pszPath, nRecurseDepth,
papszOptions);
}
if (!STARTS_WITH_CI(pszPath, GetFSPrefix()))
return nullptr;
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("OpenDir");
CPLString osDirnameWithoutPrefix = pszPath + GetFSPrefix().size();
if (!osDirnameWithoutPrefix.empty() && osDirnameWithoutPrefix.back() == '/')
{
osDirnameWithoutPrefix.resize(osDirnameWithoutPrefix.size() - 1);
}
CPLString osBucket(osDirnameWithoutPrefix);
CPLString osObjectKey;
size_t nSlashPos = osDirnameWithoutPrefix.find('/');
if (nSlashPos != std::string::npos)
{
osBucket = osDirnameWithoutPrefix.substr(0, nSlashPos);
osObjectKey = osDirnameWithoutPrefix.substr(nSlashPos + 1);
}
IVSIS3LikeHandleHelper *poS3HandleHelper =
CreateHandleHelper(osBucket, true);
if (poS3HandleHelper == nullptr)
{
return nullptr;
}
UpdateHandleFromMap(poS3HandleHelper);
VSIDIRS3 *dir = new VSIDIRS3(this);
dir->nRecurseDepth = nRecurseDepth;
dir->poFS = this;
dir->poS3HandleHelper = poS3HandleHelper;
dir->osBucket = osBucket;
dir->osObjectKey = osObjectKey;
dir->nMaxFiles = atoi(CSLFetchNameValueDef(papszOptions, "MAXFILES", "0"));
dir->bCacheEntries = CPLTestBool(
CSLFetchNameValueDef(papszOptions, "CACHE_ENTRIES", "TRUE"));
dir->m_osFilterPrefix = CSLFetchNameValueDef(papszOptions, "PREFIX", "");
dir->m_bSynthetizeMissingDirectories = CPLTestBool(CSLFetchNameValueDef(
papszOptions, "SYNTHETIZE_MISSING_DIRECTORIES", "NO"));
if (!dir->IssueListDir())
{
delete dir;
return nullptr;
}
return dir;
}
/************************************************************************/
/* ComputeMD5OfLocalFile() */
/************************************************************************/
static CPLString ComputeMD5OfLocalFile(VSILFILE *fp)
{
constexpr size_t nBufferSize = 10 * 4096;
std::vector<GByte> abyBuffer(nBufferSize, 0);
struct CPLMD5Context context;
CPLMD5Init(&context);
while (true)
{
size_t nRead = VSIFReadL(&abyBuffer[0], 1, nBufferSize, fp);
CPLMD5Update(&context, &abyBuffer[0], nRead);
if (nRead < nBufferSize)
{
break;
}
}
unsigned char hash[16];
CPLMD5Final(hash, &context);
constexpr char tohex[] = "0123456789abcdef";
char hhash[33];
for (int i = 0; i < 16; ++i)
{
hhash[i * 2] = tohex[(hash[i] >> 4) & 0xf];
hhash[i * 2 + 1] = tohex[hash[i] & 0xf];
}
hhash[32] = '\0';
VSIFSeekL(fp, 0, SEEK_SET);
return hhash;
}
/************************************************************************/
/* CopyFile() */
/************************************************************************/
int IVSIS3LikeFSHandler::CopyFile(const char *pszSource, const char *pszTarget,
VSILFILE *fpSource, vsi_l_offset nSourceSize,
CSLConstList papszOptions,
GDALProgressFunc pProgressFunc,
void *pProgressData)
{
CPLString osMsg;
osMsg.Printf("Copying of %s", pszSource);
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("CopyFile");
const CPLString osPrefix(GetFSPrefix());
if (STARTS_WITH(pszSource, osPrefix) && STARTS_WITH(pszTarget, osPrefix))
{
bool bRet = CopyObject(pszSource, pszTarget, papszOptions) == 0;
if (bRet && pProgressFunc)
{
bRet = pProgressFunc(1.0, osMsg.c_str(), pProgressData) != 0;
}
return bRet ? 0 : -1;
}
VSIVirtualHandleUniquePtr poFileHandleAutoClose;
if (!fpSource)
{
if (STARTS_WITH(pszSource, osPrefix))
{
// Try to get a streaming path from the source path
auto poSourceFSHandler = dynamic_cast<IVSIS3LikeFSHandler *>(
VSIFileManager::GetHandler(pszSource));
if (poSourceFSHandler)
{
const CPLString osStreamingPath =
poSourceFSHandler->GetStreamingFilename(pszSource);
if (!osStreamingPath.empty())
{
fpSource = VSIFOpenExL(osStreamingPath, "rb", TRUE);
}
}
}
if (!fpSource)
{
fpSource = VSIFOpenExL(pszSource, "rb", TRUE);
}
if (!fpSource)
{
CPLError(CE_Failure, CPLE_FileIO, "Cannot open %s", pszSource);
return false;
}
poFileHandleAutoClose.reset(fpSource);
}
return VSIFilesystemHandler::CopyFile(pszSource, pszTarget, fpSource,
nSourceSize, papszOptions,
pProgressFunc, pProgressData);
}
/************************************************************************/
/* CopyChunk() */
/************************************************************************/
static bool CopyChunk(const char *pszSource, const char *pszTarget,
vsi_l_offset nStartOffset, size_t nChunkSize)
{
VSILFILE *fpIn = VSIFOpenExL(pszSource, "rb", TRUE);
if (fpIn == nullptr)
{
CPLError(CE_Failure, CPLE_FileIO, "Cannot open %s", pszSource);
return false;
}
VSILFILE *fpOut = VSIFOpenExL(pszTarget, "wb+", TRUE);
if (fpOut == nullptr)
{
CPLError(CE_Failure, CPLE_FileIO, "Cannot create %s", pszTarget);
VSIFCloseL(fpIn);
return false;
}
bool ret = true;
if (VSIFSeekL(fpIn, nStartOffset, SEEK_SET) < 0 ||
VSIFSeekL(fpOut, nStartOffset, SEEK_SET) < 0)
{
ret = false;
}
else
{
void *pBuffer = VSI_MALLOC_VERBOSE(nChunkSize);
if (pBuffer == nullptr)
{
ret = false;
}
else
{
if (VSIFReadL(pBuffer, 1, nChunkSize, fpIn) != nChunkSize ||
VSIFWriteL(pBuffer, 1, nChunkSize, fpOut) != nChunkSize)
{
ret = false;
}
}
VSIFree(pBuffer);
}
VSIFCloseL(fpIn);
if (VSIFCloseL(fpOut) != 0)
{
ret = false;
}
if (!ret)
{
CPLError(CE_Failure, CPLE_FileIO, "Copying of %s to %s failed",
pszSource, pszTarget);
}
return ret;
}
/************************************************************************/
/* Sync() */
/************************************************************************/
bool IVSIS3LikeFSHandler::Sync(const char *pszSource, const char *pszTarget,
const char *const *papszOptions,
GDALProgressFunc pProgressFunc,
void *pProgressData, char ***ppapszOutputs)
{
if (ppapszOutputs)
{
*ppapszOutputs = nullptr;
}
NetworkStatisticsFileSystem oContextFS(GetFSPrefix());
NetworkStatisticsAction oContextAction("Sync");
CPLString osSource(pszSource);
CPLString osSourceWithoutSlash(pszSource);
if (osSourceWithoutSlash.back() == '/')
{
osSourceWithoutSlash.resize(osSourceWithoutSlash.size() - 1);
}
// coverity[tainted_data]
double dfRetryDelay = CPLAtof(
VSIGetPathSpecificOption(pszSource, "GDAL_HTTP_RETRY_DELAY",
CPLSPrintf("%f", CPL_HTTP_RETRY_DELAY)));
const int nMaxRetry =
atoi(VSIGetPathSpecificOption(pszSource, "GDAL_HTTP_MAX_RETRY",
CPLSPrintf("%d", CPL_HTTP_MAX_RETRY)));
const bool bRecursive = CPLFetchBool(papszOptions, "RECURSIVE", true);
enum class SyncStrategy
{
TIMESTAMP,
ETAG,
OVERWRITE
};
SyncStrategy eSyncStrategy = SyncStrategy::TIMESTAMP;
const char *pszSyncStrategy =
CSLFetchNameValueDef(papszOptions, "SYNC_STRATEGY", "TIMESTAMP");
if (EQUAL(pszSyncStrategy, "TIMESTAMP"))
eSyncStrategy = SyncStrategy::TIMESTAMP;
else if (EQUAL(pszSyncStrategy, "ETAG"))
eSyncStrategy = SyncStrategy::ETAG;
else if (EQUAL(pszSyncStrategy, "OVERWRITE"))
eSyncStrategy = SyncStrategy::OVERWRITE;
else
{
CPLError(CE_Warning, CPLE_NotSupported,
"Unsupported value for SYNC_STRATEGY: %s", pszSyncStrategy);
}
const bool bDownloadFromNetworkToLocal =
(!STARTS_WITH(pszTarget, "/vsi") ||
STARTS_WITH(pszTarget, "/vsimem/")) &&
STARTS_WITH(pszSource, GetFSPrefix());
const bool bTargetIsThisFS = STARTS_WITH(pszTarget, GetFSPrefix());
const bool bUploadFromLocalToNetwork =
(!STARTS_WITH(pszSource, "/vsi") ||
STARTS_WITH(pszSource, "/vsimem/")) &&
bTargetIsThisFS;
// If the source is likely to be a directory, try to issue a ReadDir()
// if we haven't stat'ed it yet
std::unique_ptr<VSIDIR> poSourceDir;
if (STARTS_WITH(pszSource, GetFSPrefix()) && osSource.back() == '/')
{
const char *const apszOptions[] = {"SYNTHETIZE_MISSING_DIRECTORIES=YES",
nullptr};
poSourceDir.reset(
VSIOpenDir(osSourceWithoutSlash, bRecursive ? -1 : 0, apszOptions));
}
VSIStatBufL sSource;
if (VSIStatL(osSourceWithoutSlash, &sSource) < 0)
{
CPLError(CE_Failure, CPLE_FileIO, "%s does not exist", pszSource);
return false;
}
const auto CanSkipDownloadFromNetworkToLocal =
[this, eSyncStrategy](
const char *l_pszSource, const char *l_pszTarget,
GIntBig sourceTime, GIntBig targetTime,
const std::function<CPLString(const char *)> &getETAGSourceFile)
{
switch (eSyncStrategy)
{
case SyncStrategy::ETAG:
{
VSILFILE *fpOutAsIn = VSIFOpenExL(l_pszTarget, "rb", TRUE);
if (fpOutAsIn)
{
CPLString md5 = ComputeMD5OfLocalFile(fpOutAsIn);
VSIFCloseL(fpOutAsIn);
if (getETAGSourceFile(l_pszSource) == md5)
{
CPLDebug(GetDebugKey(),
"%s has already same content as %s",
l_pszTarget, l_pszSource);
return true;
}
}
return false;
}
case SyncStrategy::TIMESTAMP:
{
if (targetTime <= sourceTime)
{
// Our local copy is older than the source, so
// presumably the source was uploaded from it. Nothing to do
CPLDebug(GetDebugKey(),
"%s is older than %s. "
"Do not replace %s assuming it was used to "
"upload %s",
l_pszTarget, l_pszSource, l_pszTarget,
l_pszSource);
return true;
}
return false;
}
case SyncStrategy::OVERWRITE:
{
break;
}
}
return false;
};
const auto CanSkipUploadFromLocalToNetwork =
[this, eSyncStrategy](
VSILFILE *&l_fpIn, const char *l_pszSource, const char *l_pszTarget,
GIntBig sourceTime, GIntBig targetTime,
const std::function<CPLString(const char *)> &getETAGTargetFile)
{
switch (eSyncStrategy)
{
case SyncStrategy::ETAG:
{
l_fpIn = VSIFOpenExL(l_pszSource, "rb", TRUE);
if (l_fpIn && getETAGTargetFile(l_pszTarget) ==
ComputeMD5OfLocalFile(l_fpIn))
{
CPLDebug(GetDebugKey(), "%s has already same content as %s",
l_pszTarget, l_pszSource);
VSIFCloseL(l_fpIn);
l_fpIn = nullptr;
return true;
}
return false;
}
case SyncStrategy::TIMESTAMP:
{
if (targetTime >= sourceTime)
{
// The remote copy is more recent than the source, so
// presumably it was uploaded from the source. Nothing to do
CPLDebug(GetDebugKey(),
"%s is more recent than %s. "
"Do not replace %s assuming it was uploaded from "
"%s",
l_pszTarget, l_pszSource, l_pszTarget,
l_pszSource);
return true;
}
return false;
}
case SyncStrategy::OVERWRITE:
{
break;
}
}
return false;
};
struct ChunkToCopy
{
CPLString osFilename{};
GIntBig nMTime = 0;
CPLString osETag{};
vsi_l_offset nTotalSize = 0;
vsi_l_offset nStartOffset = 0;
vsi_l_offset nSize = 0;
};
std::vector<ChunkToCopy> aoChunksToCopy;
std::set<CPLString> aoSetDirsToCreate;
const char *pszChunkSize = CSLFetchNameValue(papszOptions, "CHUNK_SIZE");
#if !defined(CPL_MULTIPROC_STUB)
// 10 threads used by default by the Python s3transfer library
const int nRequestedThreads =
atoi(CSLFetchNameValueDef(papszOptions, "NUM_THREADS", "10"));
#else
const int nRequestedThreads =
atoi(CSLFetchNameValueDef(papszOptions, "NUM_THREADS", "1"));
#endif
auto poTargetFSHandler = dynamic_cast<IVSIS3LikeFSHandler *>(
VSIFileManager::GetHandler(pszTarget));
const bool bSupportsParallelMultipartUpload =
bUploadFromLocalToNetwork && poTargetFSHandler != nullptr &&
poTargetFSHandler->SupportsParallelMultipartUpload();
const bool bSimulateThreading =
CPLTestBool(CPLGetConfigOption("VSIS3_SIMULATE_THREADING", "NO"));
const int nMinSizeChunk =
bSupportsParallelMultipartUpload && !bSimulateThreading
? 8 * 1024 * 1024
: 1; // 5242880 defined by S3 API as the minimum, but 8 MB used by
// default by the Python s3transfer library
const int nMinThreads = bSimulateThreading ? 0 : 1;
const size_t nMaxChunkSize =
pszChunkSize && nRequestedThreads > nMinThreads &&
(bDownloadFromNetworkToLocal ||
bSupportsParallelMultipartUpload)
? static_cast<size_t>(
std::min(1024 * 1024 * 1024,
std::max(nMinSizeChunk, atoi(pszChunkSize))))
: 0;
// Filter x-amz- options when outputting to /vsis3/
CPLStringList aosObjectCreationOptions;
if (poTargetFSHandler != nullptr && papszOptions != nullptr)
{
for (auto papszIter = papszOptions; *papszIter != nullptr; ++papszIter)
{
char *pszKey = nullptr;
const char *pszValue = CPLParseNameValue(*papszIter, &pszKey);
if (pszKey && pszValue &&
poTargetFSHandler->IsAllowedHeaderForObjectCreation(pszKey))
{
aosObjectCreationOptions.SetNameValue(pszKey, pszValue);
}
CPLFree(pszKey);
}
}
uint64_t nTotalSize = 0;
std::vector<size_t> anIndexToCopy; // points to aoChunksToCopy
struct MultiPartDef
{
CPLString osUploadID{};
int nCountValidETags = 0;
int nExpectedCount = 0;
// cppcheck-suppress unusedStructMember
std::vector<CPLString> aosEtags{};
vsi_l_offset nTotalSize = 0;
};
std::map<CPLString, MultiPartDef> oMapMultiPartDefs;
// Cleanup pending uploads in case of early exit
struct CleanupPendingUploads
{
IVSIS3LikeFSHandler *m_poFS;
std::map<CPLString, MultiPartDef> &m_oMapMultiPartDefs;
int m_nMaxRetry;
double m_dfRetryDelay;
CleanupPendingUploads(
IVSIS3LikeFSHandler *poFSIn,
std::map<CPLString, MultiPartDef> &oMapMultiPartDefsIn,
int nMaxRetryIn, double dfRetryDelayIn)
: m_poFS(poFSIn), m_oMapMultiPartDefs(oMapMultiPartDefsIn),
m_nMaxRetry(nMaxRetryIn), m_dfRetryDelay(dfRetryDelayIn)
{
}
~CleanupPendingUploads()
{
for (const auto &kv : m_oMapMultiPartDefs)
{
auto poS3HandleHelper = std::unique_ptr<IVSIS3LikeHandleHelper>(
m_poFS->CreateHandleHelper(kv.first.c_str() +
m_poFS->GetFSPrefix().size(),
false));
if (poS3HandleHelper)
{
m_poFS->UpdateHandleFromMap(poS3HandleHelper.get());
m_poFS->AbortMultipart(kv.first, kv.second.osUploadID,
poS3HandleHelper.get(), m_nMaxRetry,
m_dfRetryDelay);
}
}
}
CleanupPendingUploads(const CleanupPendingUploads &) = delete;
CleanupPendingUploads &
operator=(const CleanupPendingUploads &) = delete;
};
const CleanupPendingUploads cleanupPendingUploads(this, oMapMultiPartDefs,
nMaxRetry, dfRetryDelay);
CPLString osTargetDir; // set in the VSI_ISDIR(sSource.st_mode) case
CPLString osTarget; // set in the !(VSI_ISDIR(sSource.st_mode)) case
if (VSI_ISDIR(sSource.st_mode))
{
osTargetDir = pszTarget;
if (osSource.back() != '/')
{
osTargetDir = CPLFormFilename(osTargetDir,
CPLGetFilename(pszSource), nullptr);
}
if (!poSourceDir)
{
const char *const apszOptions[] = {
"SYNTHETIZE_MISSING_DIRECTORIES=YES", nullptr};
poSourceDir.reset(VSIOpenDir(osSourceWithoutSlash,
bRecursive ? -1 : 0, apszOptions));
if (!poSourceDir)
return false;
}
auto poTargetDir = std::unique_ptr<VSIDIR>(
VSIOpenDir(osTargetDir, bRecursive ? -1 : 0, nullptr));
std::set<CPLString> oSetTargetSubdirs;
std::map<CPLString, VSIDIREntry> oMapExistingTargetFiles;
// Enumerate existing target files and directories
if (poTargetDir)
{
while (true)
{
const auto entry = VSIGetNextDirEntry(poTargetDir.get());
if (!entry)
break;
if (VSI_ISDIR(entry->nMode))
{
oSetTargetSubdirs.insert(entry->pszName);
}
else
{
oMapExistingTargetFiles.insert(
std::pair<CPLString, VSIDIREntry>(entry->pszName,
*entry));
}
}
poTargetDir.reset();
}
else
{
VSIStatBufL sTarget;
if (VSIStatL(osTargetDir, &sTarget) < 0 &&
VSIMkdirRecursive(osTargetDir, 0755) < 0)
{
CPLError(CE_Failure, CPLE_FileIO, "Cannot create directory %s",
osTargetDir.c_str());
return false;
}
}
// Enumerate source files and directories
while (true)
{
const auto entry = VSIGetNextDirEntry(poSourceDir.get());
if (!entry)
break;
if (VSI_ISDIR(entry->nMode))
{
if (oSetTargetSubdirs.find(entry->pszName) ==
oSetTargetSubdirs.end())
{
const CPLString osTargetSubdir(
CPLFormFilename(osTargetDir, entry->pszName, nullptr));
aoSetDirsToCreate.insert(osTargetSubdir);
}
}
else
{
// Split file in possibly multiple chunks
const vsi_l_offset nChunksLarge =
nMaxChunkSize == 0
? 1
: (entry->nSize + nMaxChunkSize - 1) / nMaxChunkSize;
if (nChunksLarge >
1000) // must also be below knMAX_PART_NUMBER for upload
{
CPLError(CE_Failure, CPLE_AppDefined,
"Too small CHUNK_SIZE w.r.t file size");
return false;
}
ChunkToCopy chunk;
chunk.osFilename = entry->pszName;
chunk.nMTime = entry->nMTime;
chunk.nTotalSize = entry->nSize;
chunk.osETag =
CSLFetchNameValueDef(entry->papszExtra, "ETag", "");
const size_t nChunks = static_cast<size_t>(nChunksLarge);
for (size_t iChunk = 0; iChunk < nChunks; iChunk++)
{
chunk.nStartOffset = iChunk * nMaxChunkSize;
chunk.nSize =
nChunks == 1
? entry->nSize
: std::min(
entry->nSize - chunk.nStartOffset,
static_cast<vsi_l_offset>(nMaxChunkSize));
aoChunksToCopy.push_back(chunk);
chunk.osETag.clear();
}
}
}
poSourceDir.reset();
// Create missing target directories, sorted in lexicographic order
// so that upper-level directories are listed before subdirectories.
for (const auto &osTargetSubdir : aoSetDirsToCreate)
{
const bool ok =
(bTargetIsThisFS ? MkdirInternal(osTargetSubdir, 0755, false)
: VSIMkdir(osTargetSubdir, 0755)) == 0;
if (!ok)
{
CPLError(CE_Failure, CPLE_FileIO, "Cannot create directory %s",
osTargetSubdir.c_str());
return false;
}
}
// Collect source files to copy
const size_t nChunkCount = aoChunksToCopy.size();
for (size_t iChunk = 0; iChunk < nChunkCount; ++iChunk)
{
const auto &chunk = aoChunksToCopy[iChunk];
if (chunk.nStartOffset != 0)
continue;
const CPLString osSubSource(CPLFormFilename(
osSourceWithoutSlash, chunk.osFilename, nullptr));
const CPLString osSubTarget(
CPLFormFilename(osTargetDir, chunk.osFilename, nullptr));
bool bSkip = false;
const auto oIterExistingTarget =
oMapExistingTargetFiles.find(chunk.osFilename);
if (oIterExistingTarget != oMapExistingTargetFiles.end() &&
oIterExistingTarget->second.nSize == chunk.nTotalSize)
{
if (bDownloadFromNetworkToLocal)
{
if (CanSkipDownloadFromNetworkToLocal(
osSubSource, osSubTarget, chunk.nMTime,
oIterExistingTarget->second.nMTime,
[&chunk](const char *) { return chunk.osETag; }))
{
bSkip = true;
}
}
else if (bUploadFromLocalToNetwork)
{
VSILFILE *fpIn = nullptr;
if (CanSkipUploadFromLocalToNetwork(
fpIn, osSubSource, osSubTarget, chunk.nMTime,
oIterExistingTarget->second.nMTime,
[&oIterExistingTarget](const char *)
{
return CPLString(CSLFetchNameValueDef(
oIterExistingTarget->second.papszExtra,
"ETag", ""));
}))
{
bSkip = true;
}
if (fpIn)
VSIFCloseL(fpIn);
}
}
if (!bSkip)
{
anIndexToCopy.push_back(iChunk);
nTotalSize += chunk.nTotalSize;
if (chunk.nSize < chunk.nTotalSize)
{
if (bDownloadFromNetworkToLocal)
{
// Suppress target file as we're going to open in wb+
// mode for parallelized writing
VSIUnlink(osSubTarget);
}
else if (bSupportsParallelMultipartUpload)
{
auto poS3HandleHelper =
std::unique_ptr<IVSIS3LikeHandleHelper>(
CreateHandleHelper(osSubTarget.c_str() +
GetFSPrefix().size(),
false));
if (poS3HandleHelper == nullptr)
return false;
UpdateHandleFromMap(poS3HandleHelper.get());
const auto osUploadID = InitiateMultipartUpload(
osSubTarget, poS3HandleHelper.get(), nMaxRetry,
dfRetryDelay, aosObjectCreationOptions.List());
if (osUploadID.empty())
{
return false;
}
MultiPartDef def;
def.osUploadID = osUploadID;
def.nExpectedCount = static_cast<int>(
(chunk.nTotalSize + chunk.nSize - 1) / chunk.nSize);
def.nTotalSize = chunk.nTotalSize;
oMapMultiPartDefs[osSubTarget] = def;
}
else
{
CPLAssert(false);
}
// Include all remaining chunks of the same file
while (iChunk + 1 < nChunkCount &&
aoChunksToCopy[iChunk + 1].nStartOffset > 0)
{
++iChunk;
anIndexToCopy.push_back(iChunk);
}
}
}
}
const int nThreads = std::min(std::max(1, nRequestedThreads),
static_cast<int>(anIndexToCopy.size()));
if (nThreads <= nMinThreads)
{
// Proceed to file copy
bool ret = true;
uint64_t nAccSize = 0;
for (const size_t iChunk : anIndexToCopy)
{
const auto &chunk = aoChunksToCopy[iChunk];
CPLAssert(chunk.nStartOffset == 0);
const CPLString osSubSource(CPLFormFilename(
osSourceWithoutSlash, chunk.osFilename, nullptr));
const CPLString osSubTarget(
CPLFormFilename(osTargetDir, chunk.osFilename, nullptr));
// coverity[divide_by_zero]
void *pScaledProgress = GDALCreateScaledProgress(
double(nAccSize) / nTotalSize,
double(nAccSize + chunk.nSize) / nTotalSize, pProgressFunc,
pProgressData);
ret = CopyFile(osSubSource, osSubTarget, nullptr, chunk.nSize,
aosObjectCreationOptions.List(),
GDALScaledProgress, pScaledProgress) == 0;
GDALDestroyScaledProgress(pScaledProgress);
if (!ret)
{
break;
}
nAccSize += chunk.nSize;
}
return ret;
}
}
else
{
CPLString osMsg;
osMsg.Printf("Copying of %s", osSourceWithoutSlash.c_str());
VSIStatBufL sTarget;
osTarget = pszTarget;
bool bTargetIsFile = false;
sTarget.st_size = 0;
if (VSIStatL(osTarget, &sTarget) == 0)
{
bTargetIsFile = true;
if (VSI_ISDIR(sTarget.st_mode))
{
osTarget = CPLFormFilename(osTarget, CPLGetFilename(pszSource),
nullptr);
bTargetIsFile = VSIStatL(osTarget, &sTarget) == 0 &&
!CPL_TO_BOOL(VSI_ISDIR(sTarget.st_mode));
}
}
// Download from network to local file system ?
if (bTargetIsFile && bDownloadFromNetworkToLocal &&
sSource.st_size == sTarget.st_size)
{
if (CanSkipDownloadFromNetworkToLocal(
osSourceWithoutSlash, osTarget, sSource.st_mtime,
sTarget.st_mtime,
[this](const char *pszFilename)
{
FileProp cachedFileProp;
if (GetCachedFileProp(GetURLFromFilename(pszFilename),
cachedFileProp))
{
return cachedFileProp.ETag;
}
return CPLString();
}))
{
if (pProgressFunc)
{
pProgressFunc(1.0, osMsg.c_str(), pProgressData);
}
return true;
}
}
VSILFILE *fpIn = nullptr;
// Upload from local file system to network ?
if (bUploadFromLocalToNetwork && sSource.st_size == sTarget.st_size)
{
if (CanSkipUploadFromLocalToNetwork(
fpIn, osSourceWithoutSlash, osTarget, sSource.st_mtime,
sTarget.st_mtime,
[this](const char *pszFilename)
{
FileProp cachedFileProp;
if (GetCachedFileProp(GetURLFromFilename(pszFilename),
cachedFileProp))
{
return cachedFileProp.ETag;
}
return CPLString();
}))
{
if (pProgressFunc)
{
pProgressFunc(1.0, osMsg.c_str(), pProgressData);
}
return true;
}
}
// Split file in possibly multiple chunks
const vsi_l_offset nChunksLarge =
nMaxChunkSize == 0
? 1
: (sSource.st_size + nMaxChunkSize - 1) / nMaxChunkSize;
if (nChunksLarge >
1000) // must also be below knMAX_PART_NUMBER for upload
{
CPLError(CE_Failure, CPLE_AppDefined,
"Too small CHUNK_SIZE w.r.t file size");
return false;
}
ChunkToCopy chunk;
chunk.nMTime = sSource.st_mtime;
chunk.nTotalSize = sSource.st_size;
nTotalSize = chunk.nTotalSize;
const size_t nChunks = static_cast<size_t>(nChunksLarge);
for (size_t iChunk = 0; iChunk < nChunks; iChunk++)
{
chunk.nStartOffset = iChunk * nMaxChunkSize;
chunk.nSize =
nChunks == 1
? sSource.st_size
: std::min(sSource.st_size - chunk.nStartOffset,
static_cast<vsi_l_offset>(nMaxChunkSize));
aoChunksToCopy.push_back(chunk);
anIndexToCopy.push_back(iChunk);
if (nChunks > 1)
{
if (iChunk == 0)
{
if (bDownloadFromNetworkToLocal)
{
// Suppress target file as we're going to open in wb+
// mode for parallelized writing
VSIUnlink(osTarget);
}
else if (bSupportsParallelMultipartUpload)
{
auto poS3HandleHelper =
std::unique_ptr<IVSIS3LikeHandleHelper>(
CreateHandleHelper(osTarget.c_str() +
GetFSPrefix().size(),
false));
if (poS3HandleHelper == nullptr)
return false;
UpdateHandleFromMap(poS3HandleHelper.get());
const auto osUploadID = InitiateMultipartUpload(
osTarget, poS3HandleHelper.get(), nMaxRetry,
dfRetryDelay, aosObjectCreationOptions.List());
if (osUploadID.empty())
{
return false;
}
MultiPartDef def;
def.osUploadID = osUploadID;
def.nExpectedCount = static_cast<int>(
(chunk.nTotalSize + chunk.nSize - 1) / chunk.nSize);
def.nTotalSize = chunk.nTotalSize;
oMapMultiPartDefs[osTarget] = def;
}
else
{
CPLAssert(false);
}
}
}
}
const int nThreads = std::min(std::max(1, nRequestedThreads),
static_cast<int>(anIndexToCopy.size()));
if (nThreads <= nMinThreads)
{
bool bRet =
CopyFile(osSourceWithoutSlash, osTarget, fpIn, sSource.st_size,
aosObjectCreationOptions.List(), pProgressFunc,
pProgressData) == 0;
if (fpIn)
{
VSIFCloseL(fpIn);
}
return bRet;
}
if (fpIn)
{
VSIFCloseL(fpIn);
}
}
const int nThreads = std::min(std::max(1, nRequestedThreads),
static_cast<int>(anIndexToCopy.size()));
struct JobQueue
{
IVSIS3LikeFSHandler *poFS;
const std::vector<ChunkToCopy> &aoChunksToCopy;
const std::vector<size_t> &anIndexToCopy;
std::map<CPLString, MultiPartDef> &oMapMultiPartDefs;
volatile int iCurIdx = 0;
volatile bool ret = true;
volatile bool stop = false;
CPLString osSourceDir{};
CPLString osTargetDir{};
CPLString osSource{};
CPLString osTarget{};
std::mutex sMutex{};
uint64_t nTotalCopied = 0;
bool bSupportsParallelMultipartUpload = false;
size_t nMaxChunkSize = 0;
int nMaxRetry = 0;
double dfRetryDelay = 0.0;
const CPLStringList &aosObjectCreationOptions;
JobQueue(IVSIS3LikeFSHandler *poFSIn,
const std::vector<ChunkToCopy> &aoChunksToCopyIn,
const std::vector<size_t> &anIndexToCopyIn,
std::map<CPLString, MultiPartDef> &oMapMultiPartDefsIn,
const CPLString &osSourceDirIn, const CPLString &osTargetDirIn,
const CPLString &osSourceIn, const CPLString &osTargetIn,
bool bSupportsParallelMultipartUploadIn,
size_t nMaxChunkSizeIn, int nMaxRetryIn, double dfRetryDelayIn,
const CPLStringList &aosObjectCreationOptionsIn)
: poFS(poFSIn), aoChunksToCopy(aoChunksToCopyIn),
anIndexToCopy(anIndexToCopyIn),
oMapMultiPartDefs(oMapMultiPartDefsIn),
osSourceDir(osSourceDirIn), osTargetDir(osTargetDirIn),
osSource(osSourceIn), osTarget(osTargetIn),
bSupportsParallelMultipartUpload(
bSupportsParallelMultipartUploadIn),
nMaxChunkSize(nMaxChunkSizeIn), nMaxRetry(nMaxRetryIn),
dfRetryDelay(dfRetryDelayIn),
aosObjectCreationOptions(aosObjectCreationOptionsIn)
{
}
JobQueue(const JobQueue &) = delete;
JobQueue &operator=(const JobQueue &) = delete;
};
const auto threadFunc = [](void *pDataIn)
{
struct ProgressData
{
uint64_t nFileSize;
double dfLastPct;
JobQueue *queue;
static int CPL_STDCALL progressFunc(double pct, const char *,
void *pProgressDataIn)
{
ProgressData *pProgress =
static_cast<ProgressData *>(pProgressDataIn);
const auto nInc = static_cast<uint64_t>(
(pct - pProgress->dfLastPct) * pProgress->nFileSize + 0.5);
pProgress->queue->sMutex.lock();
pProgress->queue->nTotalCopied += nInc;
pProgress->queue->sMutex.unlock();
pProgress->dfLastPct = pct;
return TRUE;
}
};
JobQueue *queue = static_cast<JobQueue *>(pDataIn);
while (!queue->stop)
{
const int idx = CPLAtomicInc(&(queue->iCurIdx)) - 1;
if (static_cast<size_t>(idx) >= queue->anIndexToCopy.size())
{
queue->stop = true;
break;
}
const auto &chunk =
queue->aoChunksToCopy[queue->anIndexToCopy[idx]];
const CPLString osSubSource(
queue->osTargetDir.empty()
? queue->osSource.c_str()
: CPLFormFilename(queue->osSourceDir, chunk.osFilename,
nullptr));
const CPLString osSubTarget(
queue->osTargetDir.empty()
? queue->osTarget.c_str()
: CPLFormFilename(queue->osTargetDir, chunk.osFilename,
nullptr));
ProgressData progressData;
progressData.nFileSize = chunk.nSize;
progressData.dfLastPct = 0;
progressData.queue = queue;
if (chunk.nSize < chunk.nTotalSize)
{
const size_t nSizeToRead = static_cast<size_t>(chunk.nSize);
bool bSuccess = false;
if (queue->bSupportsParallelMultipartUpload)
{
const auto iter =
queue->oMapMultiPartDefs.find(osSubTarget);
CPLAssert(iter != queue->oMapMultiPartDefs.end());
VSILFILE *fpIn = VSIFOpenL(osSubSource, "rb");
void *pBuffer = VSI_MALLOC_VERBOSE(nSizeToRead);
auto poS3HandleHelper =
std::unique_ptr<IVSIS3LikeHandleHelper>(
queue->poFS->CreateHandleHelper(
osSubTarget.c_str() +
queue->poFS->GetFSPrefix().size(),
false));
if (fpIn && pBuffer && poS3HandleHelper &&
VSIFSeekL(fpIn, chunk.nStartOffset, SEEK_SET) == 0 &&
VSIFReadL(pBuffer, 1, nSizeToRead, fpIn) == nSizeToRead)
{
queue->poFS->UpdateHandleFromMap(
poS3HandleHelper.get());
const int nPartNumber =
1 + (queue->nMaxChunkSize == 0
? 0 /* shouldn't happen */
: static_cast<int>(chunk.nStartOffset /
queue->nMaxChunkSize));
const CPLString osEtag = queue->poFS->UploadPart(
osSubTarget, nPartNumber, iter->second.osUploadID,
chunk.nStartOffset, pBuffer, nSizeToRead,
poS3HandleHelper.get(), queue->nMaxRetry,
queue->dfRetryDelay,
queue->aosObjectCreationOptions.List());
if (!osEtag.empty())
{
std::lock_guard<std::mutex> lock(queue->sMutex);
iter->second.nCountValidETags++;
iter->second.aosEtags.resize(
std::max(nPartNumber,
static_cast<int>(
iter->second.aosEtags.size())));
iter->second.aosEtags[nPartNumber - 1] = osEtag;
bSuccess = true;
}
}
if (fpIn)
VSIFCloseL(fpIn);
VSIFree(pBuffer);
}
else
{
bSuccess = CopyChunk(osSubSource, osSubTarget,
chunk.nStartOffset, nSizeToRead);
}
if (bSuccess)
{
ProgressData::progressFunc(1.0, "", &progressData);
}
else
{
queue->ret = false;
queue->stop = true;
}
}
else
{
CPLAssert(chunk.nStartOffset == 0);
if (queue->poFS->CopyFile(
osSubSource, osSubTarget, nullptr, chunk.nTotalSize,
queue->aosObjectCreationOptions.List(),
ProgressData::progressFunc, &progressData) != 0)
{
queue->ret = false;
queue->stop = true;
}
}
}
};
JobQueue sJobQueue(this, aoChunksToCopy, anIndexToCopy, oMapMultiPartDefs,
osSourceWithoutSlash, osTargetDir, osSourceWithoutSlash,
osTarget, bSupportsParallelMultipartUpload,
nMaxChunkSize, nMaxRetry, dfRetryDelay,
aosObjectCreationOptions);
if (CPLTestBool(CPLGetConfigOption("VSIS3_SYNC_MULTITHREADING", "YES")))
{
std::vector<CPLJoinableThread *> ahThreads;
for (int i = 0; i < nThreads; i++)
{
auto hThread = CPLCreateJoinableThread(threadFunc, &sJobQueue);
if (!hThread)
{
sJobQueue.ret = false;
sJobQueue.stop = true;
break;
}
ahThreads.push_back(hThread);
}
if (pProgressFunc)
{
while (!sJobQueue.stop)
{
CPLSleep(0.1);
sJobQueue.sMutex.lock();
const auto nTotalCopied = sJobQueue.nTotalCopied;
sJobQueue.sMutex.unlock();
// coverity[divide_by_zero]
if (!pProgressFunc(double(nTotalCopied) / nTotalSize, "",
pProgressData))
{
sJobQueue.ret = false;
sJobQueue.stop = true;
}
}
if (sJobQueue.ret)
{
pProgressFunc(1.0, "", pProgressData);
}
}
for (auto hThread : ahThreads)
{
CPLJoinThread(hThread);
}
}
else
{
// Only for simulation case
threadFunc(&sJobQueue);
}
// Finalize multipart uploads
if (sJobQueue.ret && bSupportsParallelMultipartUpload)
{
std::set<CPLString> oSetKeysToRemove;
for (const auto &kv : oMapMultiPartDefs)
{
auto poS3HandleHelper =
std::unique_ptr<IVSIS3LikeHandleHelper>(CreateHandleHelper(
kv.first.c_str() + GetFSPrefix().size(), false));
sJobQueue.ret = false;
if (poS3HandleHelper)
{
CPLAssert(kv.second.nCountValidETags ==
kv.second.nExpectedCount);
UpdateHandleFromMap(poS3HandleHelper.get());
if (CompleteMultipart(kv.first, kv.second.osUploadID,
kv.second.aosEtags, kv.second.nTotalSize,
poS3HandleHelper.get(), nMaxRetry,
dfRetryDelay))
{
sJobQueue.ret = true;
oSetKeysToRemove.insert(kv.first);
InvalidateCachedData(poS3HandleHelper->GetURL().c_str());
InvalidateDirContent(CPLGetDirname(kv.first));
}
}
}
for (const auto &key : oSetKeysToRemove)
{
oMapMultiPartDefs.erase(key);
}
}
return sJobQueue.ret;
}
/************************************************************************/
/* UpdateMapFromHandle() */
/************************************************************************/
void VSIS3FSHandler::UpdateMapFromHandle(IVSIS3LikeHandleHelper *poHandleHelper)
{
VSIS3UpdateParams::UpdateMapFromHandle(poHandleHelper);
}
/************************************************************************/
/* UpdateHandleFromMap() */
/************************************************************************/
void VSIS3FSHandler::UpdateHandleFromMap(IVSIS3LikeHandleHelper *poHandleHelper)
{
VSIS3UpdateParams::UpdateHandleFromMap(poHandleHelper);
}
/************************************************************************/
/* VSIS3Handle() */
/************************************************************************/
VSIS3Handle::VSIS3Handle(VSIS3FSHandler *poFSIn, const char *pszFilename,
VSIS3HandleHelper *poS3HandleHelper)
: IVSIS3LikeHandle(poFSIn, pszFilename, poS3HandleHelper->GetURLNoKVP()),
m_poS3HandleHelper(poS3HandleHelper)
{
}
/************************************************************************/
/* ~VSIS3Handle() */
/************************************************************************/
VSIS3Handle::~VSIS3Handle()
{
delete m_poS3HandleHelper;
}
/************************************************************************/
/* GetCurlHeaders() */
/************************************************************************/
struct curl_slist *
VSIS3Handle::GetCurlHeaders(const CPLString &osVerb,
const struct curl_slist *psExistingHeaders)
{
return m_poS3HandleHelper->GetCurlHeaders(osVerb, psExistingHeaders);
}
/************************************************************************/
/* CanRestartOnError() */
/************************************************************************/
bool VSIS3Handle::CanRestartOnError(const char *pszErrorMsg,
const char *pszHeaders, bool bSetError)
{
bool bUpdateMap = false;
if (m_poS3HandleHelper->CanRestartOnError(pszErrorMsg, pszHeaders,
bSetError, &bUpdateMap))
{
if (bUpdateMap)
{
static_cast<VSIS3FSHandler *>(poFS)->UpdateMapFromHandle(
m_poS3HandleHelper);
}
SetURL(m_poS3HandleHelper->GetURL());
return true;
}
return false;
}
} /* end of namespace cpl */
#endif // DOXYGEN_SKIP
//! @endcond
/************************************************************************/
/* VSIInstallS3FileHandler() */
/************************************************************************/
/*!
\brief Install /vsis3/ Amazon S3 file system handler (requires libcurl)
\verbatim embed:rst
See :ref:`/vsis3/ documentation <vsis3>`
\endverbatim
@since GDAL 2.1
*/
void VSIInstallS3FileHandler(void)
{
VSIFileManager::InstallHandler("/vsis3/",
new cpl::VSIS3FSHandler("/vsis3/"));
}
#endif /* HAVE_CURL */
|
298f995fb45a9a0df3a5dfb2607f59e5d931c976 | 59067dd90aad0beac00a2b1d6042be9655126e13 | /Classes/StartMenuScene.h | 4562b7480c032442be34da5ef9f8ce74faac256b | [] | no_license | TeamNA/Trench-Defence | 9dc6814b45117c440699d3122f71b7d768840307 | 891f659ff65b06cab4f8a6bcf789a1a7515cbae8 | refs/heads/master | 2020-02-26T17:10:37.722191 | 2016-03-08T10:30:57 | 2016-03-08T10:30:57 | 51,311,969 | 0 | 0 | null | 2016-02-08T17:02:43 | 2016-02-08T17:02:43 | null | UTF-8 | C++ | false | false | 639 | h | StartMenuScene.h | #ifndef __STARTMENU_SCENE_H__
#define __STARTMENU_SCENE_H__
#include "cocos2d.h"
#include <string>
class StartMenu : public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
// implement the "static create()" method manually
CREATE_FUNC(StartMenu);
void startButtonPressed();
void rankButtonPressed();
void BackButtonPressed();
void settingsButtonPressed();
void update(float dt);
void updateFactTimer(float dt);
void onEnter();
void menuCloseCallback(cocos2d::Ref* pSender);
private:
cocos2d::Label* didYouKnowLabel;
};
#endif // __STARTMENU_SCENE_H__ |
5397ddecead876620c87973a05367ba2aeccb91c | 59dd6c40f372f61da3e088754eddff8fbd529026 | /Hacker Earth/Altizon Coding test/Share the fare.cpp | 519ad7e3662f99e17bebc516f2efce4838652679 | [] | no_license | skystone1000/Coding-Problems | a5dc6332352f496f169fad5d17c18bbf21911b87 | a8f219408dd9afd9a119175156e3c4dde89f54cb | refs/heads/master | 2022-12-04T12:51:40.913901 | 2022-11-30T13:31:58 | 2022-11-30T13:31:58 | 250,971,303 | 8 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 1,751 | cpp | Share the fare.cpp | // Problem - Share the fare
// https://www.hackerearth.com/problem/algorithm/sharethefare-1/
#include <bits/stdc++.h>
using namespace std;
map < string , int > paid;
map < string , int > correct;
map < int , string > order;
int main()
{
int t , n , m , q, amount, money;
string s , c;
cin >> t;
while(t--){
cin >> n >> q;
correct.clear(); // reset for each case
paid.clear();
order.clear();
for(int i = 0; i < n; i++){
cin >> s;
order[i] = s; // memorize the order of the input
}
for(int i = 0; i < q; i++){
cin >> s;
cin >> amount >> m;
money = amount / (m + 1) + amount % (m + 1); // the extra amount of money added to the first
paid[s] += amount; // actual paid money
correct[s] += money; // oney supposed to pay
money = amount / (m + 1);
for(int j = 0; j < m; j++){
cin >> s;
correct[s] += money; // amount of money that other memebers in the transaction should pay
}
}
for(int i = 0; i < n; i++){ // output the names in the order given in the Question
s = order[i];
amount = correct[s] - paid[s]; // supposed paid money - actual paid money
if(amount == 0) cout << s << " neither owes nor is owed\n";
else if (amount > 0) cout << s << " owes " << amount << "\n";
else cout << s << " is owed " << -amount << "\n";
}
}
return 0;
} |
6431172f03776158095851ac4ce5473a98231adc | 3e8bdb01c0f0d9696fa857d3afb0ae9ba7c0913a | /controllers/obstacle_avoidance_path_finding/obstacle_avoidance_path_finding.cpp | 4fec105dfeea4fbe25b5781994be2a2b821d0699 | [
"MIT"
] | permissive | jezuina/reinforcement_learning | 538b0a17011d0109d52d95572db9b1d5bbbc28d2 | ef1d780fd9404390a54c3a2594fffc09fde2c79c | refs/heads/master | 2020-04-09T20:29:39.999934 | 2019-05-05T20:29:03 | 2019-05-05T20:29:03 | 160,575,242 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 16,005 | cpp | obstacle_avoidance_path_finding.cpp | /*python*/
#include </usr/include/python2.7/Python.h>
/* Include the controller definition */
#include "obstacle_avoidance_path_finding.h"
/* Function definitions for XML parsing */
#include <argos3/core/utility/configuration/argos_configuration.h>
/* 2D vector definition */
#include <argos3/core/utility/math/vector2.h>
/****************************************/
/****************************************/
CObstacleAvoidance::CObstacleAvoidance() :
m_pcLEDs(NULL),
m_pcCamera(NULL),
m_pcWheels(NULL),
m_pcProximity(NULL),
m_pcLight(NULL),
m_cAlpha(10.0f),
m_fDelta(0.5f),
m_fWheelVelocity(2.5f),
m_cGoStraightAngleRange(-ToRadians(m_cAlpha),
ToRadians(m_cAlpha)) {
numberOfSteps = 0;
otnn = new ObjectTrackingNeuralNetwork;
previous_state[0] = 0;
previous_state[1] = 0;
previous_current[0] = 0;
previous_current[1] = 0;
turn = 1;
hasTurn = false;
}
/****************************************/
/****************************************/
void CObstacleAvoidance::Init(TConfigurationNode& t_node) {
/*
* Get sensor/actuator handles
*
* The passed string (ex. "differential_steering") corresponds to the
* XML tag of the device whose handle we want to have. For a list of
* allowed values, type at the command prompt:
*
* $ argos3 -q actuators
*
* to have a list of all the possible actuators, or
*
* $ argos3 -q sensors
*
* to have a list of all the possible sensors.
*
* NOTE: ARGoS creates and initializes actuators and sensors
* internally, on the basis of the lists provided the configuration
* file at the <controllers><footbot_diffusion><actuators> and
* <controllers><footbot_diffusion><sensors> sections. If you forgot to
* list a device in the XML and then you request it here, an error
* occurs.
*/
m_pcLEDs = GetActuator<CCI_LEDsActuator >("leds");
m_pcCamera = GetSensor <CCI_ColoredBlobOmnidirectionalCameraSensor>("colored_blob_omnidirectional_camera");
m_pcWheels = GetActuator<CCI_DifferentialSteeringActuator >("differential_steering");
m_pcProximity = GetSensor <CCI_FootBotProximitySensor >("footbot_proximity" );
m_pcPosSens = GetSensor <CCI_PositioningSensor >("positioning" );
m_pcLight = GetSensor <CCI_FootBotLightSensor >("footbot_light");
/*
* Parse the configuration file
*
* The user defines this part. Here, the algorithm accepts three
* parameters and it's nice to put them in the config file so we don't
* have to recompile if we want to try other settings.
*/
GetNodeAttributeOrDefault(t_node, "alpha", m_cAlpha, m_cAlpha);
m_cGoStraightAngleRange.Set(-ToRadians(m_cAlpha), ToRadians(m_cAlpha));
GetNodeAttributeOrDefault(t_node, "delta", m_fDelta, m_fDelta);
GetNodeAttributeOrDefault(t_node, "velocity", m_fWheelVelocity, m_fWheelVelocity);
/* Switch the camera on */
m_pcCamera->Enable();
//python
/*Py_Initialize();
char *args[1] = {"/home/jkoroveshi/eclipse-workspace/PythonEmbedding/Debug/PythonEmbedding"};
PySys_SetArgv(1,args); // must call this to get sys.argv and relative imports
PyRun_SimpleString("import os, sys\n"
"print sys.argv\n"
"print sys.argv, \"\\n\".join(sys.path)\n"
"print os.getcwd()\n"
"import numpy\n" // import a relative module
);*/
//pName = PyString_FromString("clasifyNumbers");
//pModuleTensorFlow = PyImport_Import(pName);
//Py_DECREF(pName);
}
/****************************************/
/****************************************/
void CObstacleAvoidance::setTurn(int t)
{
turn = t;
}
void CObstacleAvoidance::setHasTurn(bool t)
{
hasTurn = t;
}
int CObstacleAvoidance::getTurn()
{
return turn;
}
void CObstacleAvoidance::ControlStep() {
//lexohen te dhenat e sensorit te drites
/* Get light readings */
//const CCI_FootBotLightSensor::TReadings& tReadings = m_pcLight->GetReadings();
/* Calculate a normalized vector that points to the closest light */
//CVector2 cAccum;
//for(size_t i = 0; i < tReadings.size(); ++i) {
// cAccum += CVector2(tReadings[i].Value, tReadings[i].Angle);
//}
//CRadians cAngle = cAccum.Angle();
//Real cValue = cAccum.Length();
//std::cout << "gjetesia rezultat "<<cValue<<std::endl;
//std::cout << "kendi rezultat "<<cAngle<<std::endl;
//lexojme nga sensoret gjendjen aktuale
double current_state[2];
GetCurrentState(current_state);
//std::cout<<"current ne controller"<<current_state[0]<<" "<<current_state[1]<<std::endl;
if(hasTurn == false)//hera e pare e episodit
{
previous_state[0] = 0;
previous_state[1] = 0;
previous_current[0] = current_state[0];
previous_current[1] = current_state[1];
hasTurn = true;
std::cout<<"fillim episodi previous state"<<previous_state[0]<<" "<<previous_state[1]<<std::endl;
std::cout<<"fillim episodi previous current state"<<previous_current[0]<<" "<<previous_current[1]<<std::endl;
return;
}
else//fillon nga hera e dyte
{
if((turn % 2) == 1)//nqs nuk eshte radha e tij, resetojme vlerat
{
previous_state[0] = previous_current[0];
previous_state[1] = previous_current[1];
previous_current[0] = current_state[0];
previous_current[1] = current_state[1];
std::cout<<"nuk eshte radha previous state"<<previous_state[0]<<" "<<previous_state[1]<<std::endl;
std::cout<<"nuk eshte previous current state"<<previous_current[0]<<" "<<previous_current[1]<<std::endl;
}
else//radha e tij, do zgjedhe veprimin
{
double previous_state1[2];
GetPreviousState(previous_state1);
//std::cout<<"previous ne controller"<<previous_state1[0]<<" "<<previous_state1[1]<<std::endl;
//double state[4];
//state[0] = previous_state1[0];
//state[1] = previous_state1[1];
//state[2] = previous_current[0];
//state[3] = previous_current[1];
double state[2];
state[0] = current_state[0];
state[1] = current_state[1];
std::cout<<"eshte radha current state"<<state[0]<<" "<<state[1]<<std::endl;
//std::cout<<"exec f2"<<std::endl;
int action = otnn->callMethodAct(state,2);
last_action = action;
//0 majtas
//1 djathtas
//2 drejt
//4 no action
if(action == 0)
m_pcWheels->SetLinearVelocity(0, m_fWheelVelocity);
else if(action == 1)
m_pcWheels->SetLinearVelocity(m_fWheelVelocity, 0);
else if(action == 2)
m_pcWheels->SetLinearVelocity(m_fWheelVelocity, m_fWheelVelocity);
else m_pcWheels->SetLinearVelocity(0, 0);
numberOfSteps ++;
}
}
}
void CObstacleAvoidance::Reset() {
//std::cout<<"reseting"<<std::endl;
}
bool CObstacleAvoidance::IsEpisodeFinished()
{
//std::cout<<"controlling is episode finished numberOfSteps "<<numberOfSteps<<std::endl;
if(numberOfSteps == 0)
return false;
//proximity sensor
const CCI_FootBotProximitySensor::TReadings& tProxReads = m_pcProximity->GetReadings();
/* Sum them together */
CVector2 cAccumulator;
for(size_t i = 0; i < tProxReads.size(); ++i)
{
cAccumulator += CVector2(tProxReads[i].Value, tProxReads[i].Angle);
}
cAccumulator /= tProxReads.size();
double cAngle = cAccumulator.Angle().GetValue();
Real cValue = cAccumulator.Length();
//camera sensor
/* Get led color of nearby robots */
const CCI_ColoredBlobOmnidirectionalCameraSensor::SReadings& sBlobs = m_pcCamera->GetReadings();
/*
* Check whether someone sent a 1, which means 'flash'
*/
double distanca =0;
bool bSomeoneFlashed = false;
CVector2 cAccum;
for(size_t i = 0; i < sBlobs.BlobList.size(); ++i) {
bSomeoneFlashed = (sBlobs.BlobList[i]->Color == CColor::RED);
cAccum += CVector2(sBlobs.BlobList[i]->Distance,sBlobs.BlobList[i]->Angle);
}
cAccum /= sBlobs.BlobList.size();
if(bSomeoneFlashed == false)
return false;
distanca = cAccum.Length();
double distanca_previous = previous_current[0];
//std::cout << "distanca "<<distanca<<std::endl;
//std::cout << "distanca previous "<<distanca_previous<<std::endl;
double kendi = cAccum.Angle().GetValue();
double previous_angle = previous_current[1];
//std::cout << "kendi "<<kendi<<std::endl;
//std::cout << "kendi previous "<<previous_angle<<std::endl;
//if(cAccum.Length() > 35 || cAccum.Length() < 18)
//return true;
//else return false;
//double dif_distanca = distanca - distanca_previous;
//if(dif_distanca < 0) dif_distanca = (-1)* dif_distanca;
//double dif_kendi = kendi - previous_angle;
//if(dif_kendi < 0) dif_kendi = (-1) * dif_kendi;
//std::cout << "kendi "<<dif_kendi<<std::endl;
//std::cout << "distanca "<<dif_distanca<<std::endl;
if(cValue > distanca_previous || cAngle > previous_angle)
return true;
else return false;
if(distanca >= 2* distanca_previous && kendi >= 2*previous_angle)
return true;
else return false;
if(cAccum.Length() > 35 || cAccum.Length() < 18)
return true;
else return false;
if(kendi < 0 && previous_angle < 0 )
{
kendi = kendi * -1;
previous_angle = previous_angle * -1;
//std::cout << "kendi negativ "<<kendi<<std::endl;
//std::cout << "kendi previous negativ "<<previous_angle<<std::endl;
if(kendi > 2 * previous_angle)
{
std::cout << "mbaron eisodiiiidd "<<std::endl;
return true;
}
else
{
return false;
}
}
else if(kendi < 0 && previous_angle > 0)
{
std::cout << "2 "<<std::endl;
return false;
}
else if(kendi > 0 && previous_angle < 0)
{
std::cout << "3 "<<std::endl;
return false;
}
else if (kendi > 0 && previous_angle > 0)
{
std::cout << "3 "<<std::endl;
if(kendi > 2 * previous_angle)
return true;
else return false;
}
else return false;
std::cout << "4 "<<std::endl;
if(cAccum.Length() < 35 && cAccum.Length() > 18 && bSomeoneFlashed)
return false;
else return true;
}
int CObstacleAvoidance::GetReward()
{
//lexojme nga proximity sensor
/* Get readings from proximity sensor */
const CCI_FootBotProximitySensor::TReadings& tProxReads = m_pcProximity->GetReadings();
/* Sum them together */
CVector2 cAccumulator;
for(size_t i = 0; i < tProxReads.size(); ++i) {
cAccumulator += CVector2(tProxReads[i].Value, tProxReads[i].Angle);
}
cAccumulator /= tProxReads.size();
//lexohen te dhenat nga sensori i kameras
/* Get led color of nearby robots */
const CCI_ColoredBlobOmnidirectionalCameraSensor::SReadings& sBlobs = m_pcCamera->GetReadings();
/*
* Check whether someone sent a 1, which means 'flash'
*/
Real distanca =0;
bool bSomeoneFlashed = false;
CVector2 cAccum;
for(size_t i = 0; i < sBlobs.BlobList.size(); ++i) {
bSomeoneFlashed = (sBlobs.BlobList[i]->Color == CColor::RED);
//std::cout << "distanca "<<sBlobs.BlobList[i]->Distance<<std::endl;
//std::cout << "kendi "<<sBlobs.BlobList[i]->Angle<<std::endl;
//distanca = sBlobs.BlobList[i]->Distance;
cAccum += CVector2(sBlobs.BlobList[i]->Distance,sBlobs.BlobList[i]->Angle);
}
cAccum /= sBlobs.BlobList.size();
distanca = cAccumulator.Length();//gjatesia cm
double kendi = cAccumulator.Angle().GetValue();
//distanca paraardhese
double previous_distance = previous_current[0];
double previous_angle = previous_current[1];
//std::cout << "get reward gjatesia "<<distanca<<std::endl;
//if(distanca > 35 || distanca < 18)
//return -100;
//double dif_distanca = distanca - previous_distance;
//if(dif_distanca < 0) dif_distanca = (-1)* dif_distanca;
//double dif_kendi = kendi - previous_angle;
//if(dif_kendi < 0) dif_kendi = (-1) * dif_kendi;
if(distanca > previous_distance || kendi > previous_angle)
return -10;
else return 1;
//std::cout << "get reward gjatesia "<<distanca<<std::endl;
if(distanca > 35 || distanca < 18)
return -100;
if(kendi < 0 && previous_angle < 0 )
{
kendi = kendi * -1;
previous_angle = previous_angle * -1;
if(kendi >2 * previous_angle) return -10;
else return 1;
}
else if(kendi < 0 && previous_angle > 0)
{
return -10;
}
else if(kendi > 0 && previous_angle < 0)
{
return -10;
}
else if (kendi > 0 && previous_angle > 0)
{
if(kendi > 2* previous_angle)
return -10;
else return 1;
}
else return 1;
if(kendi <= previous_angle) return 1;
else return -10;
}
void CObstacleAvoidance::Remember(double current_state[], int action, double new_state[], int reward, bool done)
{
otnn->callMethodRemember(current_state,action,reward,new_state,done,2);
}
void CObstacleAvoidance::WriteToFile(int episodeLength[], int dimension)
{
otnn->callMethodSaveTeFile(episodeLength, dimension);
}
void CObstacleAvoidance::SaveModel()
{
otnn->callMethodSaveModel("file");
}
void CObstacleAvoidance::GetCurrentState(double state[])
{
//lexojme nga proximity sensor
/* Get readings from proximity sensor */
//const CCI_FootBotProximitySensor::TReadings& tProxReads = m_pcProximity->GetReadings();
/* Sum them together */
CVector2 cAccumulator;
//for(size_t i = 0; i < tProxReads.size(); ++i) {
// cAccumulator += CVector2(tProxReads[i].Value, tProxReads[i].Angle);
//}
//cAccumulator /= tProxReads.size();
//state[0] = cAccumulator.Length();//gjatesia cm
//state[1] = cAccumulator.Angle().GetValue();//kendi radian
//camera sensor
/* Get led color of nearby robots */
//sBlobs ka 11 lexime, te perbera nga gjatesia dhe kendi
//qe tregojne pozicionin ku eshte pare drita
const CCI_ColoredBlobOmnidirectionalCameraSensor::SReadings& sBlobs = m_pcCamera->GetReadings();
/*
* Check whether someone sent a 1, which means 'flash'
*/
Real distanca =0;
bool bSomeoneFlashed = false;
CVector2 cAccum;
//std::cout << "getting current state "<<std::endl;
//std::cout << "bloblist size "<<sBlobs.BlobList.size()<<std::endl;
for(size_t i = 0; i < sBlobs.BlobList.size(); ++i) {
bSomeoneFlashed = (sBlobs.BlobList[i]->Color == CColor::RED);
//std::cout << "ngjyra "<<sBlobs.BlobList[i]->Color<<std::endl;
//std::cout << "flashed "<<bSomeoneFlashed<<std::endl;
//std::cout << "distanca "<<sBlobs.BlobList[i]->Distance<<std::endl;
//std::cout << "kendi "<<sBlobs.BlobList[i]->Angle<<std::endl;
cAccum += CVector2(sBlobs.BlobList[i]->Distance,sBlobs.BlobList[i]->Angle);
}
//std::cout << "pas forit "<<std::endl;
//std::cout << "pas forit gjatesia "<<cAccum.Length()<<std::endl;
//std::cout << "pas forit kendi "<<cAccum.Angle().GetValue()<<std::endl;
cAccum /= sBlobs.BlobList.size();
//std::cout << "pas pjesetimi "<<std::endl;
//std::cout << "pas pjesetimit gjatesia "<<cAccum.Length()<<std::endl;
//std::cout << "pas pjesetimit kendi "<<cAccum.Angle().GetValue()<<std::endl;
state[0] = cAccum.Length();//gjatesia cm
state[1] = cAccum.Angle().GetValue();//kendi radian
}
void CObstacleAvoidance::GetPreviousState(double state[])
{
state[0] = previous_state[0];//gjatesia
state[1] = previous_state[1];//kendi
}
void CObstacleAvoidance::GetPreviousCurrent(double state[])
{
state[0] = previous_current[0];//gjatesia
state[1] = previous_current[1];//kendi
}
void CObstacleAvoidance::SetPreviousState(double state[])
{
previous_state[0] = state[0];//gjatesia
previous_state[1] = state[1];//kendi
}
void CObstacleAvoidance::Replay()
{
otnn->callMethodReplay();
}
void CObstacleAvoidance::TargetTrain()
{
otnn->callMethodTargetTrain();
}
int CObstacleAvoidance::GetLastAction()
{
return last_action;
}
/****************************************/
/****************************************/
/*
* This statement notifies ARGoS of the existence of the controller.
* It binds the class passed as first argument to the string passed as
* second argument.
* The string is then usable in the configuration file to refer to this
* controller.
* When ARGoS reads that string in the configuration file, it knows which
* controller class to instantiate.
* See also the configuration files for an example of how this is used.
*/
REGISTER_CONTROLLER(CObstacleAvoidance, "obstacle_avoidance_controller")
|
759b952f4afa341f3dd4ac45c90a88780e8c7b7c | d248bd05aa8c8fc2dacba3c1690073a839ac8945 | /AnnihilationCharacter_Siv3D/AnnihilationCharacter_Siv3D/Game/inc/BarrageBase.hpp | fdee223ece59375567b6b4f918bf1c344e705037 | [] | no_license | elipmoc/AnnihilationCharacter_Siv3D | bff5e1be6e6082665a1fd4bf7288a1296d434d2e | 7662b37945ec0cdd62132a63028df0d0c1edfe9e | refs/heads/master | 2021-01-01T05:55:41.518750 | 2019-03-02T21:40:47 | 2019-03-02T21:40:47 | 97,309,105 | 3 | 1 | null | null | null | null | SHIFT_JIS | C++ | false | false | 1,626 | hpp | BarrageBase.hpp | #pragma once
#include <memory>
#include "SceneBase.hpp"
namespace game {
class BulletListCreator;
//弾幕クラス
class BarrageBase {
//弾リスト
std::unique_ptr<BulletListCreator> m_bulletListCreator;
//主人公の参照座標
const siv::Vec2& m_playerBindPos;
//弾打つ人の座標
const siv::Vec2& m_bindPos;
//弾打つ人の座標修正用
const siv::Vec2 m_fixPos;
const Level m_level;
protected:
BulletListCreator& GetBulletListCreator();
siv::Vec2 GetPlayerPos() {
return m_playerBindPos;
}
siv::Vec2 GetPos()const noexcept {
return m_bindPos + m_fixPos;
}
public:
BarrageBase(BulletListCreator&,const Level level, const siv::Vec2& bindPos,const siv::Vec2&playerBindPos, const siv::Vec2& fixPos);
~BarrageBase();
void Update();
virtual void YawarakaUpdate() = 0;
virtual void NormalUpdate()=0;
virtual void RengokuUpdate()=0;
//void Draw()const;
};
//BarrageBaseを生成するビルダークラス用のinterface
class BarrageGenerator {
public:
virtual std::unique_ptr<BarrageBase> GenerateBarrage(BulletListCreator& ,const Level level,const siv::Vec2& bindPos, const siv::Vec2&playerBindPos, const siv::Vec2& fixPos = {0,0})const = 0;
};
template<class BarrageT>
class MakeBarrageGenerator :public BarrageGenerator {
virtual std::unique_ptr<BarrageBase> GenerateBarrage(BulletListCreator& bulletListCreator,const Level level, const siv::Vec2& bindPos, const siv::Vec2&playerBindPos, const siv::Vec2& fixPos)const override final {
return std::make_unique<BarrageT>(bulletListCreator,level,bindPos,playerBindPos, fixPos);
}
};
} |
c73eb2649a79f69dfe8d4c30f997d1cf4f709fcb | ec0453708237e7d772721095edd9e6928e283854 | /WS06/Autoshop.h | f03d2e069a90acb5cd6bb0a7d1485eb6e49af7fa | [] | no_license | mayankantil/OOP345-Language_CPP | 43bff39ad7f58169e2a168fd769832d48718f8c6 | 398b41f58d787f89ea933ba930dd03abd0132a4c | refs/heads/main | 2023-07-04T22:16:52.944290 | 2021-08-16T14:57:07 | 2021-08-16T14:57:07 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,035 | h | Autoshop.h | //==============================================
// Name: Jungjoo Kim
// Student Number: 162 641 195
// Email: jkim594@myseneca.ca
// Section: NAA
// Date: July 9, 2021
// Workshop: Workshop6
// Ownership:
// I have completed all the coding by myself and
// copied only the code provided by the professor to submit my assignment.
//==============================================
// Autoshop.h
#ifndef SDDS_AUTOSHOP_H
#define SDDS_AUTOSHOP_H
#include <iostream>
#include <vector>
#include <list>
#include "Vehicle.h"
namespace sdds
{
class Autoshop
{
std::vector<Vehicle*> m_vehicles;
public:
Autoshop& operator +=(Vehicle* theVechicle);
void display(std::ostream& out) const;
~Autoshop();
template <typename T>
void select(T test, std::list<const Vehicle *>& vehicles) {
for (auto temp : m_vehicles) {
if (test(temp))
vehicles.push_back(temp);
}
}
};
}
#endif // !SDDS_AUTOSHOP_H
|
c304f574aeb65bf904dd1773ad0873c37207310b | 756816ca0070c5f8d8dd56bbb8a3aa5bfe8e1cb7 | /src/Vel-Stereo-Calib.cpp | c150ecf30a736b30277db55a46f39279444dfcdd | [] | no_license | xiaohedu/Vel-Stereo-Calib | 6f6f5274541488c0fd10be66b51c13d9bd82c466 | 1745a80cace3d73f3e6ce3cc2e6301771d684a0e | refs/heads/master | 2020-04-10T06:01:50.906893 | 2016-06-11T06:40:52 | 2016-06-11T06:40:52 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 939 | cpp | Vel-Stereo-Calib.cpp | //============================================================================
// Name : Vel-Stereo-Calib.cpp
// Author : Zachary Taylor
// Version :
// Copyright :
// Description : Hello World in C++, Ansi-style
//============================================================================
#include "VelStereoMatcher.h"
int main(int argc, char* argv[])
{
VelStereoMatcher matcher;
matcher.addFrame(argv[1], argv[2], argv[3]);
Eigen::Affine3f tform = Eigen::Affine3f::Identity();
tform.rotate(Eigen::AngleAxisf(M_PI / 2, Eigen::Vector3f::UnitZ()));
tform.rotate(Eigen::AngleAxisf(-M_PI / 2, Eigen::Vector3f::UnitY()));
tform.rotate(Eigen::AngleAxisf(-0.785, Eigen::Vector3f::UnitZ()));
tform.translation() << 0.21, -0.41, 0.06;
//StereoOptVec vec(450,450,512,384,tform);
//auto v = matcher.findOptimalStereo(vec);
//auto v = matcher.evalTform(tform, true);
//std::cout << v << std::endl;
}
|
55c28ab681770cd292357eedf6b0a9eba9ff51f6 | 7da3fca158ea3fb03a578aaff783739a91194bab | /Code/CF/914/d/code.cpp | d9a12597cec6ff1d9a5f5f7f6a3886649c9ccd6e | [] | no_license | powerLEO101/Work | f1b16d410a55a9136470e0d04ccc4abcfd95e18b | 6ae5de17360a7a06e1b65d439158ff5c2d506c2a | refs/heads/master | 2021-06-18T01:33:07.380867 | 2021-02-16T10:16:47 | 2021-02-16T10:16:47 | 105,882,852 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,125 | cpp | code.cpp | /**************************
* Author : Leo101
* Problem :
* Tags :
**************************/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define _FILE(s) freopen(#s".in", "r", stdin); freopen(#s".out", "w", stdout)
#define gi get_int()
const int MAXN = 3e6;
int get_int()
{
int x = 0, y = 1; char ch = getchar();
while (!isdigit(ch) && ch != '-')
ch = getchar();
if (ch == '-') y = -1,ch = getchar();
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * y;
}
int n;
int gcd(int x, int y)
{
return y == 0 ? x : gcd(y, x % y);
}
int tree[MAXN];
void buildTree(int now = 1, int lRange = 0, int rRange = n)
{
if (lRange == rRange - 1) {
tree[now] = gi;
return ;
}
int mid = (lRange + rRange) / 2;
buildTree(now << 1, lRange, mid);
buildTree(now << 1 | 1, mid, rRange);
tree[now] = gcd(tree[now << 1], tree[now << 1 | 1]);
}
void modify(int index, int value, int now = 1, int lRange = 0, int rRange = n)
{
if (index < lRange || index >= rRange) return ;
if (lRange == rRange - 1) {
tree[now] = value;
return ;
}
int mid = (lRange + rRange) / 2;
modify(index, value, now << 1, lRange, mid);
modify(index, value, now << 1 | 1, mid, rRange);
tree[now] = gcd(tree[now << 1], tree[now << 1 | 1]);
}
int query(int l, int r, int x, int now = 1, int lRange = 0, int rRange = n)
{
if (r <= lRange || rRange <= l) return 0;
if (lRange == rRange - 1) return 1;
int mid = (lRange + rRange) / 2;
int ans = 0;
if (tree[now << 1] % x != 0)
ans += query(l, r, x, now << 1, lRange, mid);
if (ans >= 2) return ans;
if (tree[now << 1 | 1] % x != 0)
ans += query(l, r, x, now << 1 | 1, mid, rRange);
return ans;
}
int main()
{
_FILE(code);
n = gi;
buildTree();
int m = gi;
while (m--) {
int mode = gi;
if (mode == 1) {
int l = gi - 1, r = gi, x = gi;
int tmp = query(l, r, x);
if (tmp <= 1) printf("YES\n");
else printf("NO\n");
}
if (mode == 2) {
int index = gi - 1, value = gi;
modify(index, value);
}
}
return 0;
}
|
f3532ee3a943b9ec9a5b99c17e636773a697c484 | a3de8a7ce701185a31f6b39131d9c22439cac539 | /include/example/example_parser.h | 1a298afc5530707242d5bd335eb3e51df3cd1b35 | [
"Apache-2.0"
] | permissive | karmaresearch/laser-plus-plus | c2c9cd46f0d0ad0a12d51be089c8c34562a87377 | b37839c9c3674515ed6e64432c3bee43b3882963 | refs/heads/master | 2020-04-28T09:56:45.135481 | 2020-02-20T11:59:34 | 2020-02-20T11:59:34 | 175,185,549 | 2 | 1 | null | 2019-03-12T10:15:54 | 2019-03-12T10:15:54 | null | UTF-8 | C++ | false | false | 1,759 | h | example_parser.h | //
// Created by mike on 6/21/18.
//
#ifndef LASER_EXAMPLE_EXAMPLE_PARSER_H
#define LASER_EXAMPLE_EXAMPLE_PARSER_H
#include <algorithm>
#include <memory>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <util/format_exception.h>
#include <util/grounding.h>
#include <util/timeline.h>
namespace laser {
namespace example {
enum class TokenType {
OPERATOR,
OPEN_PARENTHESES,
CLOSED_PARENTHESES,
IDENTIFIER
};
struct Token {
TokenType type;
std::string value;
};
// Helper functions:
static inline void rtrim(std::string *s);
static inline void ltrim(std::string *s);
static inline void trim(std::string *s);
static inline void syntax_error(std::string error_message);
class ExampleParser {
private:
uint64_t current_tuple_counter = 0;
std::vector<std::shared_ptr<laser::util::Grounding>> argument_stack;
Token recognize(std::string token_string) const;
std::vector<Token> tokenize(std::string &rule_string) const;
void add_token_attempt(std::vector<Token> &token_vector,
std::ostringstream &token_stream) const;
void add_new_token(std::vector<Token> &token_vector, TokenType type,
char value_char) const;
std::vector<std::shared_ptr<laser::util::Grounding>>
parse_token_vector(laser::util::Timeline const &timeline,
std::vector<Token> const &input_token_vector);
public:
~ExampleParser() = default;
std::vector<std::shared_ptr<laser::util::Grounding>>
parse_data(laser::util::Timeline &timeline,
std::vector<std::string> &raw_data_vector);
};
} // namespace example
} // namespace laser
#endif // LASER_EXAMPLE_EXAMPLE_PARSER_H
|
cf107eaa08f7f693f4f7d868ddb2d4ffeb78bd70 | 8b4c7e6ac17df1b13642b2a5a0e2744b484c579b | /HALCON-12.0/include/cpp/HCondition.h | 51f07be96959c211b7cf39479c8219f2d85b3ecf | [
"MIT"
] | permissive | liuwake/HalconPractise | b7608602d3da6bddcc39ad73645680bebeaa88fb | d7615f09fd7c91cef9759a1e7eafcc2fec049b26 | refs/heads/master | 2021-07-03T15:20:22.780521 | 2020-10-15T09:54:58 | 2020-10-15T09:54:58 | 186,081,245 | 14 | 10 | null | null | null | null | UTF-8 | C++ | false | false | 1,748 | h | HCondition.h | /*****************************************************************************
* HCondition.h
*****************************************************************************
*
* Project: HALCON/C++
* Description: Class HCondition
*
* (c) 2009-2014 by MVTec Software GmbH
* www.mvtec.com
*
*****************************************************************************
*
*
*/
#ifndef H_CONDITION_H
#define H_CONDITION_H
#include "HCPPToolRef.h"
namespace Halcon {
class LIntExport HCondition: public HToolBase
{
public:
// Tool-specific functional class constructors
HCondition(const HTuple &AttrName,const HTuple &AttrValue);
//HCondition(const char *AttrName,const char *AttrValue);
// Common tool class management functionality
HCondition();
HCondition(Hlong ID);
const char *ClassName(void) const;
void SetHandle(Hlong ID);
// Tool-specific member functions
// Signal a condition synchronization object.
virtual void BroadcastCondition() const;
// Signal a condition synchronization object.
virtual void SignalCondition() const;
// Bounded wait on the signal of a condition synchronization object.
virtual void TimedWaitCondition(const Halcon::HMutex &MutexHandle, const Halcon::HTuple &Timeout) const;
// Bounded wait on the signal of a condition synchronization object.
virtual void TimedWaitCondition(const Halcon::HMutex &MutexHandle, Hlong Timeout) const;
// wait on the signal of a condition synchronization object.
virtual void WaitCondition(const Halcon::HMutex &MutexHandle) const;
// Create a condition variable synchronization object.
virtual void CreateCondition(const Halcon::HTuple &AttribName, const Halcon::HTuple &AttribValue);
};
}
#endif
|
61094049391fcfe8d36e55874dcbb7315ae45d21 | 5c01feb74b1a9d9450c0d468e7ec16563894d168 | /source/EngineModes/BananaToss/State.h | 6cb4fb67ea6580b746205fee292f74d52b19c787 | [] | no_license | jrbeck/monkey-business | e57ce7198d1524091fdbfe41cc759a961617d32c | cda97d6300685fbd2a9d7a71c2b958bfad8f994e | refs/heads/master | 2021-05-10T13:49:14.376547 | 2018-01-22T17:34:07 | 2018-01-22T17:34:07 | 118,491,306 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 736 | h | State.h | #pragma once
#include <SDL2/SDL.h>
#include "../../engine/Vec2.h"
#include "../../engine/PseudoRandom.h"
#define NUM_PROJECTILES (1)
#define NUM_TARGETS (1)
namespace BananaToss {
enum SimulationResults {
SIMULATION_RESULT_NONE,
SIMULATION_RESULT_HIT,
SIMULATION_RESULT_MISS
};
struct Projectile {
bool active;
v2d_t pos;
v2d_t vel;
};
struct Target {
bool active;
v2d_t pos;
v2d_t dimensions;
};
class State {
public:
State();
~State();
void reset();
Projectile* mProjectiles;
Target* mTargets;
PseudoRandom* mPseudoRandom;
Uint32 mLastTicks;
int mNumHits;
int mTotalShots;
v2d_t mLastShotInfo;
int mLastSimulationResult;
};
}
|
238985129b84b28ee079a48153ed67dae1cbf59f | 22212b6400346c5ec3f5927703ad912566d3474f | /src/Plugins/SDLFileGroupPlugin/SDLFileHelper.cpp | aac6ed2545db5d277b02bb608eae7deba4c1e77a | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | irov/Mengine | 673a9f35ab10ac93d42301bc34514a852c0f150d | 8118e4a4a066ffba82bda1f668c1e7a528b6b717 | refs/heads/master | 2023-09-04T03:19:23.686213 | 2023-09-03T16:05:24 | 2023-09-03T16:05:24 | 41,422,567 | 46 | 17 | MIT | 2022-09-26T18:41:33 | 2015-08-26T11:44:35 | C++ | UTF-8 | C++ | false | false | 2,758 | cpp | SDLFileHelper.cpp | #include "SDLFileHelper.h"
#include "Kernel/Logger.h"
#include "Config/StdString.h"
namespace Mengine
{
namespace Helper
{
//////////////////////////////////////////////////////////////////////////
bool concatenateFilePath( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, Char * const _concatenatePath, size_t _capacity )
{
FilePath::size_type relationSize = _relationPath.size();
FilePath::size_type folderSize = _folderPath.size();
FilePath::size_type fileSize = _filePath.size();
FilePath::size_type filePathSize = relationSize + folderSize + fileSize;
if( filePathSize > _capacity )
{
LOGGER_ERROR( "invalid full path max size:\nrelation: %s\nfolder: %s\nfile: %s\ntotal size %u [max size: %zu]"
, _relationPath.c_str()
, _folderPath.c_str()
, _filePath.c_str()
, filePathSize
, _capacity
);
return false;
}
MENGINE_STRCPY( _concatenatePath, _relationPath.c_str() );
MENGINE_STRCAT( _concatenatePath, _folderPath.c_str() );
MENGINE_STRCAT( _concatenatePath, _filePath.c_str() );
return true;
}
//////////////////////////////////////////////////////////////////////////
bool concatenateFilePathTemp( const FilePath & _relationPath, const FilePath & _folderPath, const FilePath & _filePath, Char * const _concatenatePath, size_t _capacity )
{
FilePath::size_type relationSize = _relationPath.size();
FilePath::size_type folderSize = _folderPath.size();
FilePath::size_type fileSize = _filePath.size();
FilePath::size_type filePathSize = relationSize + folderSize + fileSize + 5;
if( filePathSize > _capacity )
{
LOGGER_ERROR( "invalid full path max size:\nrelation: %s\nfolder: %s\nfile: %s\ntotal size %u [max size: %zu]"
, _relationPath.c_str()
, _folderPath.c_str()
, _filePath.c_str()
, filePathSize
, _capacity
);
return false;
}
MENGINE_STRCPY( _concatenatePath, _relationPath.c_str() );
MENGINE_STRCAT( _concatenatePath, _folderPath.c_str() );
MENGINE_STRCAT( _concatenatePath, _filePath.c_str() );
MENGINE_STRCAT( _concatenatePath, ".~tmp" );
return true;
}
//////////////////////////////////////////////////////////////////////////
}
}
|
a2a0280d9877c3f692d544cab821ecb2ccde7228 | 8d886c7b3ecbc475c4ca8958233cc2be965b3a6b | /Projects/RendererDX12/Headers/Level 1/BaseCommandList.h | 968d58ef0ecca0776af4c15192501698f75440e2 | [] | no_license | XeroKimo/DX12-Attempt2 | a29d4e08a004fb1a09579825996cbe85d5df77b2 | 896e47adec29f39d38e2d1925ba5983c38029766 | refs/heads/master | 2020-07-23T10:57:17.587825 | 2019-11-12T22:07:31 | 2019-11-12T22:07:31 | 207,533,506 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 775 | h | BaseCommandList.h | #pragma once
#include "DX12Header.h"
#include "Level 0/!Header.h"
namespace RendererDX12
{
class BaseCommandList
{
public:
inline BaseCommandList(const BaseDevice* const device, const BaseCommandAllocator* const allocator)
{
device->GetInterface()->CreateCommandList(device->GetNodeMask(), allocator->GetType(), allocator->GetInterface(), nullptr, IID_PPV_ARGS(m_commandList.GetAddressOf()));
m_device = device;
}
inline ID3D12GraphicsCommandList* GetInterface() const noexcept { return m_commandList.Get(); }
inline const BaseDevice* GetDevice() const noexcept { return m_device; }
private:
ComPtr<ID3D12GraphicsCommandList> m_commandList;
const BaseDevice* m_device;
};
} |
d8b7eb3de56f0e6ab221ff7f5b56df03432dfab1 | dbdf36645adcbaa6a9fd4b655ae5e0c78cfd5f7d | /src/nim/engine/components/Transform.hpp | a7e5d3c8bcf061af177e981466f9d3d64d97b6d2 | [] | no_license | JulianThijssen/NimEngine | dd9223229c8cbb01c97a684302f34d2cf9f6f5fe | 1e4ad54170a6de6d5167b410f5ae28ac62a9a3a5 | refs/heads/master | 2021-01-20T12:04:18.589078 | 2014-12-14T17:25:38 | 2014-12-14T17:25:38 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 404 | hpp | Transform.hpp | #ifndef TRANSFORM_HPP
#define TRANSFORM_HPP
#include <nim/engine/core/math/Vector3f.hpp>
class Transform : public Component {
public:
Vector3f position;
Vector3f rotation;
Vector3f scale;
Transform() :
position(0, 0, 0),
rotation(0, 0, 0),
scale(1, 1, 1) {}
Transform(float x, float y, float z) :
position(x, y, z),
rotation(0, 0, 0),
scale(1, 1, 1) {}
};
#endif /* TRANSFORM_HPP */
|
f14b8cce418dc120430b0b61998594d9f207ae4a | 603850e29d0e57714e09570aac3f66031acfb43c | /C++/Game/v1/game/client.h | b6e1d50a629d81bc5cfe3c759147c8f4be94d13c | [] | no_license | golgirihm/code | 0d5437af61499ce855171cd94499817966f02032 | 9eb1ed0f58dc305a428b3b81218047abcdbdf75b | refs/heads/master | 2021-01-10T10:51:48.760350 | 2016-02-01T05:04:08 | 2016-02-01T05:04:08 | 48,399,203 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,103 | h | client.h | #ifndef CLIENT_H
#define CLIENT_H
#include <QtNetwork>
#include <QWidget>
#include <QMainWindow>
#include <QUdpSocket>
namespace Ui
{
class client;
}
QT_BEGIN_NAMESPACE
class QLabel;
class QPushButton;
class QUdpSocket;
class QTcpSocket;
class QAction;
class QTimer;
QT_END_NAMESPACE
class client : public QWidget
{
Q_OBJECT
public:
explicit client(QWidget *parent = 0);
~client();
const unsigned char MSGTOALL = 'A', REQUEST = 'R', MSGTOCLIENT = 'C', MSGTOSERVER = 'S';
public slots:
QHostAddress getHostIP();
quint16 getHostPort();
void setHostInfo(const QHostAddress& host_IP, const quint16& host_port);
void attemptToConnect();
bool isConnected();
void Request(unsigned char request);
void SendToAll(QByteArray message);
void SendToServer(QByteArray message);
QByteArray ReceiveExternalData();
private:
QHostAddress serverIP;
quint16 port;
QTcpSocket* TcpSocket;
QTimer* attempt_timer;
QTimer* status_timer;
private slots:
signals:
void ConnectedToSocket();
void ExternalDataReady();
};
#endif // CLIENT_H
|
c66368cfc67ed753cf426dccb6a58a20f2ea048f | 11372f47584ed7154697ac3b139bf298cdc10675 | /刷题比赛/LUOGU/P2590 [ZJOI2008]树的统计.cpp | 4fad86e563246cd2d182a6aafa23273a30f1271a | [] | no_license | strategist614/ACM-Code | b5d893103e4d2ea0134fbaeb0cbd18c0fec06d12 | d1e0f36dab47f649e2fade5e7ff23cfd0e8c8e56 | refs/heads/master | 2020-12-20T04:21:50.750182 | 2020-01-24T07:43:50 | 2020-01-24T07:45:08 | 235,958,679 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,146 | cpp | P2590 [ZJOI2008]树的统计.cpp | /*
独立思考
一个题不会做,收获5%,写了代码10%,提交对了30%,总结吃透了这个题才是100%.
*/
#include<bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x)
{
x = 0;
char c = getchar();
int sgn = 1;
while (c < '0' || c > '9') {if (c == '-')sgn = -1; c = getchar();}
while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
x *= sgn;
}
template <typename T>
void out(T x)
{
if (x < 0) {putchar('-'); x = -x;}
if (x >= 10)out(x / 10);
putchar(x % 10 + '0');
}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
const int N = 1e5 + 5;
int head[N], ver[N << 1], Next[N << 1];
int size[N], d[N], son[N], fa[N], cnt, top[N], rk[N], id[N];
int tot, n, m;
int a[N];
int in[N];
void add(int x, int y) {
ver[++tot] = y; Next[tot] = head[x]; head[x] = tot;
}
struct stree
{
int l;
int r;
ll sum;
ll add;
ll maxn;
} tree[N << 2];
inline void pushup(int rt)
{
tree[rt].sum = tree[rt << 1].sum + tree[rt << 1 | 1].sum;
tree[rt].maxn = max(tree[rt << 1].maxn, tree[rt << 1 | 1].maxn);
}
inline void pushdown(int rt)
{
if (tree[rt].add)
{
tree[rt << 1].sum += tree[rt].add * (tree[rt << 1].r - tree[rt << 1].l + 1);
tree[rt << 1 | 1].sum += tree[rt].add * (tree[rt << 1 | 1].r - tree[rt << 1 | 1].l + 1);
tree[rt << 1].add += tree[rt].add;
tree[rt << 1 | 1].add += tree[rt].add;
tree[rt].add = 0;
}
}
inline void build(int rt, int l, int r)
{
tree[rt].l = l;
tree[rt].r = r;
if (l == r)
{
tree[rt].sum = a[rk[l]];
tree[rt].maxn = a[rk[l]];
tree[rt].add = 0;
return;
}
int mid = (l + r) >> 1;
build(rt << 1, l, mid);
build(rt << 1 | 1, mid + 1, r);
pushup(rt);
}
inline void update(int rt, int x, int val)
{
int l = tree[rt].l;
int r = tree[rt].r;
if (l == r) {
tree[rt].sum = val;
tree[rt].add = val;
tree[rt].maxn = val;
return ;
}
int mid = (l + r) >> 1;
pushdown(rt);
if (x <= mid) update(rt << 1, x, val);
else update(rt << 1 | 1, x, val);
pushup(rt);
}
// inline void update(int rt, int L, int R, int val)
// {
// int l = tree[rt].l;
// int r = tree[rt].r;
// if (L <= l && r <= R)
// {
// tree[rt].sum += (ll)val * (tree[rt].r - tree[rt].l + 1);
// tree[rt].add += val;
// return ;
// }
// int mid = (l + r) >> 1;
// pushdown(rt);
// if (L <= mid) update(rt << 1, L, R, val);
// if (R > mid) update(rt << 1 | 1, L, R, val);
// pushup(rt);
// }
inline ll query(int rt, int L, int R)
{
int l = tree[rt].l;
int r = tree[rt].r;
if (L <= l && r <= R) return tree[rt].sum;
int mid = (l + r) >> 1;
pushdown(rt);
ll ans = 0;
if (L <= mid) ans = ans + query(rt << 1, L, R);
if (R > mid) ans = ans + query(rt << 1 | 1, L, R);
return ans;
}
inline ll querymax(int rt, int L, int R)
{
int l = tree[rt].l;
int r = tree[rt].r;
if (L <= l && r <= R) return tree[rt].maxn;
ll ans = -1e9;
int mid = (l + r) >> 1;
pushdown(rt);
if (L <= mid) ans = max(ans, querymax(rt << 1, L, R));
if (R > mid) ans = max(ans, querymax(rt << 1 | 1, L, R));
return ans;
}
inline void dfs1(int x)
{
size[x] = 1, d[x] = d[fa[x]] + 1;
for (int v, i = head[x]; i; i = Next[i])
if ((v = ver[i]) != fa[x])
{
fa[v] = x, dfs1(v), size[x] += size[v];
if (size[son[x]] < size[v])
son[x] = v;
}
}
inline void dfs2(int u, int t)
{
top[u] = t;
id[u] = ++cnt;
rk[cnt] = u;
if (!son[u])
return;
dfs2(son[u], t);
for (int i = head[u]; i; i = Next[i])
{
int v = ver[i];
if (v != son[u] && v != fa[u])
dfs2(v, v);
}
}
inline ll sum(int x, int y)
{
ll ret = 0;
while (top[x] != top[y])
{
if (d[top[x]] < d[top[y]])
swap(x, y);
ret += query(1, id[top[x]], id[x]);
x = fa[top[x]];
}
if (id[x] > id[y])
swap(x, y);
return ret + query(1, id[x], id[y]);
}
// inline void change(int x, int y, int c)
// {
// while (top[x] != top[y])
// {
// if (d[top[x]] < d[top[y]])
// swap(x, y);
// update(1, id[top[x]], id[x], c);
// x = fa[top[x]];
// }
// if (id[x] > id[y])
// swap(x, y);
// update(1, id[x], id[y], c);
// }
inline void change(int x, int c)
{
update(1, id[x], c);
}
inline ll qmax(int x, int y)
{
ll ans = -1e9;
while (top[x] != top[y])
{
if (d[top[x]] < d[top[y]]) swap(x, y);
ans = max(ans, querymax(1, id[top[x]], id[x]));
x = fa[top[x]];
}
if (id[x] > id[y])
swap(x, y);
ans = max(ans, querymax(1, id[x], id[y]));
return ans;
}
int main ()
{
//freopen("input.in", "r", stdin);
//freopen("test.out", "w", stdout);
read(n);
for (int i = 1; i < n; i++)
{
int u, v;
read(u);
read(v);
add(u, v);
add(v, u);
in[v]++;
}
for (int i = 1; i <= n; i++) read(a[i]);
int root = 0;
for (int i = 1; i <= n; i++) if (!in[i]) {root = i; break;}
dfs1(root);
dfs2(root, root);
build(1,1,n);
int q;
read(q);
for (int i = 1; i <= q; i++)
{
string s;
cin >> s;
if (s == "QMAX")
{
int x, y;
read(x);
read(y);
printf("%lld\n", qmax(x, y));
}
else if (s == "QSUM")
{
int x, y;
read(x);
read(y);
printf("%lld\n", sum(x, y));
}
else
{
int x;
int y;
read(x);
read(y);
change(x, y);
}
}
return 0 ;
} |
ed768b3b7e19c6240240dbb7fc3de47f70714cf6 | afe656a7012158da0b44829fd71355006918b4be | /ParsingAssistant/MainMenu.h | 7083ce5c68c48171e52ee05411c237af5003c610 | [] | no_license | Owlfeather/ParsingAssistant | c08e31bcb8eac5443d19065247376825ce296bec | b003ac6c8fb533bbf21f7fae4f03ac9924dd9f1a | refs/heads/master | 2021-06-16T06:12:26.148128 | 2019-09-14T15:06:35 | 2019-09-14T15:06:35 | 206,980,485 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 364 | h | MainMenu.h | #pragma once
#include <QtWidgets/QMainWindow>
//#include "ui_ParsingAssistant.h"
#include "ui_MainMenu.h"
#include"CWindow.h"
class MainMenu : public QMainWindow
{
Q_OBJECT
public:
MainMenu(QWidget *parent = Q_NULLPTR);
private:
Ui::MainWindow ui;
CWindow * c_win;
private slots:
void onExitClicked();
void onLtoRClicked();
void onTtoDClicked();
};
|
cd5a6e25b689854a3acc220af59ea504152da515 | 828ad55c981db843668901fd344080bcd9fab83e | /src/system/remote_node.cc | 4cffaf41a512c230f5656fa6dce162414474414f | [
"Apache-2.0"
] | permissive | dario-DI/parameter_server | c6422d37dbd49ea9d646af8fcdcd15e6057e300d | 404d748fb1bdb43ffb925f363576c436b86893f1 | refs/heads/master | 2020-04-06T04:40:38.092456 | 2014-09-11T21:27:10 | 2014-09-11T21:27:10 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,863 | cc | remote_node.cc | #include "system/remote_node.h"
#include "system/customer.h"
#include "util/crc32c.h"
#include "base/shared_array_inl.h"
namespace PS {
DEFINE_bool(key_cache, true, "enable caching keys during communication");
// , Callback received, Callback finished, bool no_wait) {
int RNode::submit(const MessagePtr& msg) {
auto& task = msg->task; CHECK(task.has_type());
task.set_request(true);
task.set_customer(exec_.obj().name());
// set the message timestamp, store the finished_callback
msg->original_recver = id();
{
Lock l(mu_);
if (task.has_time()) {
time_ = std::max(task.time(), time_);
} else {
// choose a timestamp
if (role() == Node::GROUP) {
for (auto w : exec_.group(id())) {
// Lock l(w->time_mu_);
time_ = std::max(w->time_, time_);
}
}
task.set_time(++time_);
}
if (msg->fin_handle) msg_finish_handle_[task.time()] = msg->fin_handle;
}
int t = task.time();
outgoing_task_.start(t);
// partition the message according the receiver node's key range
const auto& key_partition = exec_.partition(id());
auto msgs = exec_.obj().slice(msg, key_partition);
CHECK_EQ(msgs.size(), key_partition.size()-1);
// sent partitioned messages one-by-one
int i = 0;
for (auto w : exec_.group(id())) {
msgs[i]->sender = exec_.myNode().id();
{
Lock l(w->mu_);
msgs[i]->recver = w->id();
w->time_ = std::max(t, w->time_);
// a terminate confirm message will not get replied
// if (task.type() != Task::TERMINATE_CONFIRM)
w->pending_msgs_[t] = msgs[i];
if (msg->recv_handle) w->msg_receive_handle_[t] = msg->recv_handle;
}
sys_.queue(w->cacheKeySender(msgs[i]));
++ i;
}
CHECK_EQ(i, msgs.size());
if (msg->wait) waitOutgoingTask(t);
return t;
}
void RNode::waitOutgoingTask(int time) {
for (auto& w : exec_.group(id())) w->outgoing_task_.wait(time);
}
bool RNode::tryWaitOutgoingTask(int time) {
for (auto& w : exec_.group(id()))
if (!w->outgoing_task_.tryWait(time)) return false;
return true;
}
void RNode::finishOutgoingTask(int time) {
for (auto& w : exec_.group(id())) w->outgoing_task_.finish(time);
}
void RNode::waitIncomingTask(int time) {
for (auto& w : exec_.group(id())) w->incoming_task_.wait(time);
}
bool RNode::tryWaitIncomingTask(int time) {
for (auto& w : exec_.group(id()))
if (!w->incoming_task_.tryWait(time)) return false;
return true;
}
void RNode::finishIncomingTask(int time) {
for (auto& w : exec_.group(id())) w->incoming_task_.finish(time);
exec_.notify();
}
MessagePtr RNode::cacheKeySender(const MessagePtr& msg) {
if (!FLAGS_key_cache || !msg->task.has_key_range() || msg->key.size() == 0)
return msg;
MessagePtr ret(new Message(*msg));
Range<Key> range(ret->task.key_range());
auto sig = crc32c::Value(ret->key.data(), ret->key.size());
Lock l(key_cache_mu_);
auto& cache = key_cache_[range];
bool hit_cache = cache.first == sig && cache.second.size() == ret->key.size();
if (hit_cache) {
ret->key.reset(nullptr, 0);
ret->task.set_has_key(false);
} else {
cache.first = sig;
cache.second = ret->key;
ret->task.set_has_key(true);
}
ret->task.set_key_signature(sig);
return ret;
}
MessagePtr RNode::cacheKeyRecver(const MessagePtr& msg) {
if (!FLAGS_key_cache || !msg->task.has_key_range()) return msg;
MessagePtr ret(new Message(*msg));
Range<Key> range(ret->task.key_range());
auto sig = ret->task.key_signature();
Lock l(key_cache_mu_);
auto& cache = key_cache_[range];
if (ret->task.has_key()) {
CHECK_EQ(crc32c::Value(ret->key.data(), ret->key.size()), sig);
cache.first = sig;
cache.second = ret->key;
} else {
CHECK_EQ(sig, cache.first) << msg->debugString();
ret->key = cache.second;
}
return ret;
}
} // namespace PS
|
b379857ddbe1fba5ae54d2ef770bf72a4d6ed4f7 | 492730fe899fbacc28686fb94ddd1b1cf96576d0 | /maneuvers/include/maneuvers/eth_trajectory.h | feb64ea91ca7c4ed886731fc101a89e4c7c8b038 | [] | no_license | BiuBiuSun/agile_quadrotor | 778384e7151562e9e648b73c238f2279c6ca3a49 | d12c8fbea188fb5a9881ea4fe368ab4a49826ebe | refs/heads/master | 2023-01-02T11:24:40.764852 | 2020-10-30T05:00:40 | 2020-10-30T05:00:40 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 661 | h | eth_trajectory.h |
#ifndef ETH_TRAJECTORY_H
#define ETH_TRAJECTORY_H
#include <mav_trajectory_generation/polynomial_optimization_linear.h>
#include <mav_trajectory_generation/trajectory.h>
#include <mav_trajectory_generation/polynomial_optimization_nonlinear.h>
#include <geometry_msgs/TwistStamped.h>
#include <geometry_msgs/PoseStamped.h>
#include <std_srvs/SetBool.h>
void eth_trajectory_init(mav_trajectory_generation::Vertex::Vector, std::vector<double>, int);
Eigen::Vector3d eth_trajectory_pos(double time);
Eigen::Vector3d eth_trajectory_vel(double time);
Eigen::Vector3d eth_trajectory_acc(double time);
Eigen::Vector3d eth_trajectory_jerk(double time);
#endif |
7070fb48e12d77ac76074d3315b54511f44b0826 | 9bdaee4be6980ba4fa3e7ef228ed5a44eea1f8d4 | /Classes/GameScene.cpp | a2e7a14a211c1b25c7100bd4875d9b4e3f6cf17c | [] | no_license | SimonHPedersen/MagneticGame | 0d8385b64d0348438f5a385920a4eb585a73501d | fd19145b2b96f7eef36d0ef9ce69162ac3793132 | refs/heads/master | 2021-03-12T20:07:43.856707 | 2015-05-26T11:46:11 | 2015-05-26T11:46:11 | 35,866,974 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 9,504 | cpp | GameScene.cpp | #include "GameScene.h"
#include "Magnet.h"
#include "HorizontalWall.h"
#include "VerticalWall.h"
#include "FinishTile.h"
#include "TimerLabel.h"
USING_NS_CC;
Scene* MagneticWorld::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::createWithPhysics();
// 'layer' is an autorelease object
auto layer = MagneticWorld::create();
// add layer as a child to scene
scene->addChild(layer);
layer->setPhyWorld(scene->getPhysicsWorld());
// return the scene
return scene;
}
void MagneticWorld::setPhyWorld(cocos2d::PhysicsWorld *world) {
m_world = world;
}
// on "init" you need to initialize your instance
bool MagneticWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(MagneticWorld::menuCloseCallback, this));
closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2));
// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
// Tilføj et mål felt:
auto finishTile = FinishTile::create();
finishTile->setAnchorPoint(Vec2(0,0));
finishTile->setPosition(Vec2(800, 200));
this->addChild(finishTile);
/////////////////////////////
// 3. add your codes below...
auto magnet1 = new Magnet(400, 400, 100000, 200);
auto magnetSprite1 = magnet1->getSprite();
this->addChild(magnetSprite1);
auto magnet2 = new Magnet(600, 600, -150000, 200);
auto magnetSprite2 = magnet2->getSprite();
this->addChild(magnetSprite2);
auto magnet3 = new Magnet(200, 400, -150000, 200);
auto magnetSprite3 = magnet3->getSprite();
this->addChild(magnetSprite3);
auto magnet4 = new Magnet(400, 200, 150000, 200);
auto magnetSprite4 = magnet4->getSprite();
this->addChild(magnetSprite4);
auto magnet5 = new Magnet(800, 100, -100000, 200);
auto magnetSprite5 = magnet5->getSprite();
this->addChild(magnetSprite5);
magnetList.push_back(magnet1);
magnetList.push_back(magnet2);
magnetList.push_back(magnet3);
magnetList.push_back(magnet4);
magnetList.push_back(magnet5);
// wall setup
new HorizontalWall(0, visibleSize.height - 8, 300, this);
new HorizontalWall(0, 8, 300, this);
new HorizontalWall(300, 300, 20, this);
new HorizontalWall(800, 800, 20, this);
new HorizontalWall(500, 500, 20, this);
new HorizontalWall(100, 50, 20, this);
new HorizontalWall(200, 150, 20, this);
//new VerticalWall(10, 50, 20, this);
new VerticalWall(8, 0, 300, this);
new VerticalWall(visibleSize.width - 8, 0, 300, this);
new VerticalWall(500, 700, 20, this);
new VerticalWall(800, 600, 20, this);
new VerticalWall(700, 100, 20, this);
new VerticalWall(600, 450, 4, this);
//setup touch for dragging magnets
// listen for touch events
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = CC_CALLBACK_2(MagneticWorld::onTouchesBegan, this);
listener->onTouchesMoved = CC_CALLBACK_2(MagneticWorld::onTouchesMoved, this);
listener->onTouchesEnded = CC_CALLBACK_2(MagneticWorld::onTouchesEnded, this);
listener->onTouchesCancelled = CC_CALLBACK_2(MagneticWorld::onTouchesEnded, this);
this->getEventDispatcher()->
addEventListenerWithSceneGraphPriority(listener, this);
auto body = PhysicsBody::createEdgeBox(visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 3);
auto edgeNode = Node::create();
edgeNode->setPosition(Point(visibleSize.width/2,visibleSize.height/2));
edgeNode->setPhysicsBody(body);
this->addChild(edgeNode);
this->physicsBody = PhysicsBody::createCircle(30.0f,
PhysicsMaterial(0.1f, 0.3f, 0.0f));
//set the body isn't affected by the physics world's gravitational force
this->physicsBody->setGravityEnable(false);
//set initial velocity of physicsBody
this->physicsBody->setVelocity(Vec2(1,
1));
//physicsBody->setTag("Dynamic");
// add "MagneticWorld" splash screen"
ballSprite = Sprite::create("ball.png");
// position the sprite on the center of the screen
ballSprite->setPosition(Vec2(visibleSize.width/2 + origin.x - 200, visibleSize.height/2 + origin.y + 200));
ballSprite->setAnchorPoint(Vec2(0.5f, 0.5f));
ballSprite->setPhysicsBody(this->physicsBody);
// add the sprite as a child to this layer
this->addChild(ballSprite, 0);
finishTile->setBall(ballSprite);
finishTile->setGameEndedCallback(CC_CALLBACK_0(MagneticWorld::gameEnded, this));
//timer
timerLabel = TimerLabel::create();
timerLabel->initialize(visibleSize.width - 40, visibleSize.height - 30, 30, this);
finishTile->setTimer(timerLabel);
scheduleUpdate();
return true;
}
void MagneticWorld::gameEnded() {
timerLabel->pause();
this->paused = true;
auto staticBody = PhysicsBody::createCircle(30.0f,
PhysicsMaterial(0.1f, 1.0f, 0.0f));
staticBody->setDynamic(false);
ballSprite->setPhysicsBody(staticBody);
}
bool MagneticWorld::isTouchingSprite(Sprite* sprite, Touch* touch) {
float distance = sprite->getPosition().getDistance(this->
touchToPoint(touch));
return (distance < 60.0f);
}
Point MagneticWorld::touchToPoint(Touch* touch)
{
// convert the touch object to a position in our cocos2d space
return CCDirector::getInstance()->convertToGL(touch->getLocationInView());
}
void MagneticWorld::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
{
// reset touch offset
this->touchOffset = Point::ZERO;
for( auto touch : touches )
{
// if this touch is within our sprite's boundary
for ( auto magnet : magnetList) {
if (touch && this->isTouchingSprite(magnet->getSprite(), touch)) {
// calculate offset from sprite to touch point
this->touchOffset = magnet->getSprite()->getPosition() - this->touchToPoint(touch);
}
}
}
}
void MagneticWorld::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
{
for( auto touch : touches )
{
// set the new sprite position
if( touch && touchOffset.x && touchOffset.y )
for ( auto magnet : magnetList) {
if (this->isTouchingSprite(magnet->getSprite(), touch)) {
magnet->getSprite()->setPosition(this->touchToPoint(touch) + this->touchOffset);
}
}
}
}
void MagneticWorld::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
for( auto touch : touches )
{
if( touch && touchOffset.x && touchOffset.y )
{
// set the new sprite position
for ( auto magnet : magnetList) {
if (this->isTouchingSprite(magnet->getSprite(), touch)) {
magnet->getSprite()->setPosition(this->touchToPoint(touch) + this->touchOffset);
// stop any existing actions and reset the scale
magnet->getSprite()->stopAllActions();
//magnet->getSprite()->setScale(1.0f);
// animate letting go of the sprite
magnet->getSprite()->runAction(Sequence::create(
ScaleBy::create(0.125f, 1.111f),
ScaleBy::create(0.125f, 0.9f),
nullptr
));
}
}
}
}
}
void MagneticWorld::update(float delta) {
if (!paused) {
for (std::list<Magnet*>::const_iterator iterator = magnetList.begin(); iterator != magnetList.end(); ++iterator) {
auto magnet = (*iterator);
auto xDiff = magnet->getSprite()->getPositionX() - ballSprite->getPositionX();
auto yDiff = magnet->getSprite()->getPositionY() - ballSprite->getPositionY();
auto rad2 = xDiff*xDiff + yDiff*yDiff;
auto distance = sqrt(rad2);
if (distance <= magnet->radius) {
physicsBody->applyImpulse(Vec2((magnet->strength*xDiff)/rad2, (magnet->strength*yDiff)/rad2)), Vec2(ballSprite->getPositionX(), ballSprite->getPositionY());
}
}
}
}
void MagneticWorld::menuCloseCallback(Ref* pSender)
{
Director::getInstance()->popScene();
}
|
84d50e68d0d7757b4e211b0ca2cfd532c176ce5e | 5f21f553666ec9b6916e3b68b2b123b4db374393 | /pitzDaily_Reynolds_stress_R_manual/500/nut | 6f75ac99d4a772a13ec2660f7e00f0e6f9229603 | [] | no_license | giacomodelbianco/software | 9a4f732635adc5ca954eb1dbc3327e7e61a549c3 | ca2f61c9833650b3d165260b3a445b4a6e29c409 | refs/heads/master | 2022-11-15T22:45:43.272727 | 2020-07-08T19:59:52 | 2020-07-08T19:59:52 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 137,976 | nut | /*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1906 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "500";
object nut;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -1 0 0 0 0];
internalField nonuniform List<scalar>
12225
(
5.38048e-05
5.34215e-05
5.26392e-05
5.17768e-05
5.09442e-05
5.01776e-05
4.94826e-05
4.88638e-05
4.82991e-05
4.78076e-05
4.73396e-05
4.69585e-05
4.66484e-05
4.63956e-05
4.61621e-05
4.59947e-05
4.57919e-05
4.57202e-05
0.000743658
0.000274823
0.000208909
0.000186803
0.000173786
0.000168865
0.000164668
0.000161018
0.000158093
0.000155524
0.000153587
0.000151625
0.000150356
0.000148547
0.000148025
0.000146234
0.000146777
0.00014487
0.00337131
0.000965676
0.000668408
0.000562221
0.000503838
0.000471975
0.000448834
0.000431552
0.000418655
0.000408187
0.000399524
0.000392103
0.00038605
0.000380274
0.000376158
0.000371112
0.00036938
0.000364466
0.00784747
0.00229236
0.00147323
0.00117571
0.00101856
0.000926422
0.000864544
0.000819759
0.000786874
0.000761042
0.000739944
0.000723147
0.000709401
0.000697506
0.000687953
0.000678605
0.000673333
0.000663163
0.0127627
0.00432668
0.00270971
0.00210431
0.00178852
0.00159942
0.00147336
0.00138292
0.00131558
0.00126339
0.00122142
0.00118724
0.00115945
0.00113556
0.00111537
0.00109757
0.00108479
0.00106665
0.0171138
0.00693191
0.00436911
0.00334584
0.00280523
0.00247632
0.00225599
0.00209799
0.0019797
0.00188802
0.00181469
0.00175482
0.00170549
0.00166385
0.00162844
0.00159776
0.00157218
0.00154419
0.0205945
0.00988381
0.00641789
0.00491179
0.0040942
0.00358845
0.00324676
0.00300085
0.00281592
0.0026721
0.00255704
0.00246298
0.00238498
0.00231923
0.00226319
0.0022148
0.00217368
0.00213138
0.0232405
0.0129303
0.00876051
0.00676547
0.00563795
0.00492463
0.00443619
0.00408182
0.00381363
0.00360401
0.00343578
0.00329791
0.0031831
0.00308613
0.00300327
0.00293169
0.00286966
0.00280878
0.0252061
0.0158683
0.0112822
0.00885725
0.00741803
0.00648203
0.00583015
0.00535204
0.00498736
0.00470057
0.0044694
0.00427928
0.00412041
0.00398584
0.00387055
0.00377076
0.00368349
0.003601
0.0266539
0.0185545
0.0138524
0.011107
0.00938558
0.00822867
0.0074058
0.00679365
0.0063219
0.00594797
0.00564473
0.00539414
0.00518385
0.00500508
0.0048514
0.00471797
0.00460052
0.00449225
0.0277219
0.0209142
0.0163554
0.0134288
0.0114838
0.0101278
0.00913959
0.0083919
0.00780858
0.00734188
0.00696065
0.00664379
0.00637661
0.00614856
0.00595182
0.00578043
0.0056292
0.00549173
0.0284465
0.022741
0.0184771
0.0155114
0.0134323
0.0119301
0.0108079
0.00994379
0.00926072
0.0087087
0.00825421
0.00787407
0.00755185
0.00727561
0.00703639
0.0068273
0.00664236
0.00647561
0.0290073
0.0243024
0.0204367
0.0175378
0.0153936
0.0137846
0.0125499
0.0115802
0.0108023
0.0101665
0.00963824
0.00919325
0.00881386
0.00848702
0.00820283
0.00795357
0.00773277
0.00753438
0.0294887
0.025755
0.0223972
0.0196759
0.0175403
0.0158662
0.0145392
0.0134716
0.0125991
0.0118756
0.0112676
0.0107508
0.0103069
0.00992203
0.00958571
0.00928951
0.00902649
0.00879068
0.0298836
0.027028
0.0242385
0.0217971
0.0197573
0.0180787
0.0166978
0.0155544
0.014599
0.0137928
0.0131059
0.0125154
0.0120036
0.0115566
0.0111636
0.0108157
0.0105059
0.010228
0.0301875
0.02806
0.0258263
0.0237249
0.0218561
0.0202381
0.0188523
0.0176678
0.0166529
0.0157794
0.0150233
0.0143649
0.0137882
0.0132803
0.0128306
0.0124305
0.0120728
0.0117515
0.0303977
0.0288003
0.0270239
0.0252471
0.0235764
0.0220603
0.0207111
0.0195218
0.0184775
0.0175607
0.0167545
0.0160435
0.0154143
0.0148554
0.014357
0.0139112
0.013511
0.013151
0.0305044
0.0291848
0.027668
0.0260934
0.0245605
0.023127
0.0218189
0.0206422
0.0195919
0.0186575
0.017827
0.0170882
0.0164297
0.0158414
0.0153144
0.014841
0.0144146
0.0140292
0.0304716
0.0290673
0.0274723
0.0258376
0.0242643
0.0228068
0.0214868
0.0203063
0.0192572
0.0183273
0.0175029
0.0167711
0.0161199
0.0155388
0.015019
0.0145527
0.0141336
0.0137565
0.0302312
0.0282144
0.0260768
0.0240432
0.0222149
0.0206166
0.0192363
0.0180483
0.0170245
0.0161389
0.0153691
0.0146963
0.0141052
0.0135832
0.01312
0.0127074
0.0123388
0.0120089
0.0298208
0.0268286
0.0239505
0.021464
0.0194066
0.0177251
0.0163485
0.0152125
0.0142653
0.0134672
0.0127878
0.0122038
0.0116975
0.0112552
0.0108662
0.0105222
0.0102169
0.00994644
0.0291398
0.0247094
0.0209857
0.0181333
0.0159872
0.0143556
0.0130907
0.0120893
0.0112806
0.010616
0.0100614
0.00959213
0.00919054
0.00884332
0.00854044
0.00827433
0.00803934
0.00783197
0.0280362
0.0217168
0.0172859
0.0143388
0.0123321
0.0109087
0.00985786
0.00905499
0.00842371
0.00791535
0.00749777
0.00714896
0.00685343
0.00659996
0.00638018
0.00618789
0.00601841
0.00587065
0.0262546
0.0178172
0.0131464
0.0104901
0.00884801
0.00775203
0.00697472
0.00639747
0.00595298
0.00560067
0.00531483
0.00507845
0.00487981
0.00471064
0.0045648
0.0044378
0.00432603
0.00422866
0.0233816
0.0132062
0.00902291
0.00699389
0.00583866
0.00510195
0.00459355
0.00422336
0.00394225
0.00372169
0.00354419
0.00339834
0.00327644
0.00317312
0.00308423
0.00300697
0.00293811
0.00287877
0.0189047
0.00845576
0.00545027
0.00418511
0.00350662
0.00308646
0.00280124
0.00259689
0.00244317
0.00232327
0.00222728
0.00214872
0.0020833
0.0020281
0.00198056
0.00193959
0.00190309
0.00187211
0.0125845
0.00438903
0.00278868
0.00217258
0.0018505
0.00165244
0.00151853
0.00142456
0.00135384
0.00129865
0.00125469
0.00121876
0.001189
0.00116402
0.00114203
0.0011235
0.00110611
0.00109144
0.00562613
0.00171152
0.00115556
0.000946041
0.000837053
0.000769117
0.000723431
0.000693304
0.000668944
0.000649534
0.000634052
0.000621075
0.000609875
0.000600378
0.000591754
0.00058459
0.000577418
0.000572507
0.00117126
0.000435655
0.000327305
0.00028483
0.000262935
0.000248791
0.00024145
0.000237251
0.000233297
0.000229706
0.000226492
0.0002237
0.00022116
0.000219014
0.000216957
0.000215309
0.000213539
0.000211915
7.08579e-05
7.01307e-05
6.9115e-05
6.81145e-05
6.717e-05
6.63015e-05
6.55064e-05
6.47827e-05
6.41259e-05
6.35292e-05
6.2986e-05
6.24896e-05
6.20358e-05
6.16179e-05
6.12357e-05
6.08797e-05
6.05555e-05
6.02474e-05
1.29936e-05
3.54588e-05
4.33573e-05
4.79365e-05
5.11952e-05
5.34532e-05
5.50393e-05
5.60549e-05
5.66224e-05
5.67728e-05
5.66693e-05
5.6354e-05
5.56924e-05
5.46825e-05
5.32652e-05
5.15131e-05
4.93016e-05
4.65978e-05
4.35346e-05
3.96272e-05
3.63218e-05
3.44754e-05
3.43108e-05
3.47363e-05
3.52959e-05
3.52371e-05
3.46402e-05
3.42507e-05
3.56931e-05
3.86414e-05
4.3041e-05
4.918e-05
5.48884e-05
5.9772e-05
6.40785e-05
6.7955e-05
7.14411e-05
7.45969e-05
7.74887e-05
8.0169e-05
8.26782e-05
8.50492e-05
8.73068e-05
8.94699e-05
9.15526e-05
9.35649e-05
9.55136e-05
9.74034e-05
9.92367e-05
0.000101015
0.000102739
0.000104407
0.00010602
0.000107579
0.000109085
0.000110544
0.000111959
0.000113324
0.000114639
0.000115912
0.000117157
0.000118373
0.000119554
0.000120691
0.000121768
0.000122769
0.00012367
0.000124441
0.000125125
0.000125479
0.000125614
0.000125668
0.000125366
0.000124847
0.000124036
0.000122872
0.000121313
0.000119333
0.000117421
0.000115499
0.000113618
0.000111805
0.000110084
0.000108472
0.00010698
0.000105615
0.000104379
0.000103279
0.000102123
0.000101252
0.000100611
0.000100036
9.95016e-05
9.90141e-05
9.8573e-05
9.81774e-05
9.78247e-05
9.75099e-05
9.72267e-05
9.69685e-05
9.67292e-05
9.65036e-05
9.62871e-05
9.60762e-05
9.58681e-05
9.56607e-05
9.54523e-05
9.52419e-05
9.50288e-05
9.48127e-05
9.45934e-05
9.4371e-05
9.41457e-05
9.3918e-05
9.36881e-05
9.34565e-05
9.32236e-05
9.29898e-05
9.27555e-05
9.25211e-05
9.22869e-05
9.20533e-05
9.18206e-05
9.1589e-05
9.13587e-05
9.11299e-05
9.09029e-05
9.06776e-05
9.04542e-05
9.02328e-05
9.00135e-05
8.97963e-05
8.95812e-05
8.93684e-05
8.91578e-05
8.89494e-05
8.87433e-05
8.85393e-05
8.83376e-05
8.8138e-05
8.79406e-05
8.77453e-05
8.7552e-05
8.73607e-05
8.71712e-05
8.69834e-05
8.67974e-05
8.66134e-05
8.64311e-05
8.62506e-05
8.60716e-05
8.58938e-05
8.57192e-05
8.55436e-05
8.53736e-05
8.51985e-05
8.50314e-05
8.48579e-05
8.4693e-05
8.45245e-05
8.43607e-05
8.41961e-05
8.40269e-05
8.38731e-05
8.37238e-05
8.35637e-05
8.34153e-05
8.32418e-05
8.30788e-05
8.29195e-05
8.27626e-05
8.25996e-05
8.24395e-05
8.22616e-05
8.20889e-05
8.18734e-05
8.16528e-05
8.13029e-05
8.06844e-05
7.79981e-05
1.96179e-05
6.15404e-05
0.000146459
0.000214222
0.000261834
0.000290575
0.000307138
0.000314393
0.000317015
0.000317559
0.000317462
0.000316424
0.00031412
0.00031234
0.000314968
0.000317478
0.000326472
0.000349341
0.000380442
0.000406833
0.000421862
0.000427692
0.000429067
0.000430514
0.000434547
0.000441247
0.000449112
0.000456567
0.000462843
0.000467743
0.000471103
0.000472359
0.000475694
0.000482318
0.000491795
0.00050318
0.000516921
0.000531077
0.000544912
0.000558023
0.000570239
0.000581687
0.000592419
0.000602529
0.000612128
0.000621329
0.000630221
0.000638864
0.000647274
0.000655416
0.000663188
0.000670404
0.000676744
0.000681719
0.000684552
0.000686171
0.000687831
0.000689216
0.000689423
0.000688844
0.000689709
0.000692368
0.000697059
0.000703796
0.000712471
0.000722911
0.000734943
0.000748126
0.000762936
0.000778092
0.000793313
0.000806579
0.000819244
0.000832417
0.000845468
0.000857918
0.000869308
0.000877518
0.000882984
0.000885877
0.000886615
0.000885624
0.000883347
0.000880138
0.000876299
0.000872076
0.000867833
0.000864268
0.000862617
0.000864801
0.000869057
0.000872757
0.000875703
0.000878158
0.000880241
0.000882077
0.000883748
0.00088528
0.000886677
0.00088793
0.000889031
0.000889975
0.00089076
0.000891392
0.000891878
0.000892229
0.000892455
0.000892569
0.000892582
0.000892507
0.000892356
0.000892139
0.000891866
0.000891546
0.000891186
0.000890792
0.000890369
0.000889921
0.00088945
0.000888958
0.000888446
0.000887913
0.00088736
0.000886787
0.000886193
0.000885576
0.000884932
0.00088426
0.000883559
0.000882824
0.000882055
0.000881248
0.000880402
0.000879514
0.000878582
0.000877604
0.000876577
0.000875501
0.000874374
0.000873194
0.000871961
0.000870674
0.000869325
0.00086791
0.000866432
0.000864893
0.000863292
0.000861631
0.000859908
0.000858125
0.000856279
0.000854386
0.00085251
0.00085042
0.00084844
0.000846069
0.000844007
0.000841497
0.000839368
0.000836815
0.000834383
0.000831692
0.000829062
0.000826405
0.000823694
0.000821019
0.000818298
0.000815595
0.000812878
0.000810154
0.000807458
0.000804764
0.000802197
0.000799639
0.000797428
0.000795082
0.00079287
0.000784427
0.000764623
0.000725174
2.49812e-05
9.41819e-05
0.000217325
0.000311148
0.000387988
0.000443562
0.000487367
0.000519422
0.00054825
0.000575079
0.00060151
0.000626769
0.000650704
0.000671751
0.000685993
0.000692878
0.000692602
0.000686022
0.00067916
0.000677821
0.000682383
0.000692865
0.000709525
0.000733159
0.000759057
0.000785538
0.000811988
0.000836924
0.000863088
0.000889727
0.00091662
0.000944634
0.000974176
0.00100498
0.00103636
0.00106756
0.00109678
0.00112411
0.00114949
0.00117318
0.00119477
0.00121422
0.00123179
0.00124775
0.00126235
0.0012758
0.00128828
0.00129989
0.00131072
0.00132079
0.00133007
0.00133855
0.00134622
0.00135317
0.00135977
0.00136674
0.00137477
0.00138422
0.00139559
0.00140958
0.00142678
0.00144731
0.00147144
0.00149899
0.0015298
0.00156362
0.00160121
0.00164126
0.00168222
0.0017235
0.00176654
0.00180977
0.00185257
0.00189803
0.0019439
0.00198822
0.00202891
0.00206395
0.00209317
0.00211623
0.00213333
0.002145
0.00215201
0.00215521
0.00215548
0.0021536
0.00215031
0.00214607
0.00214126
0.00213661
0.00213201
0.00212739
0.00212306
0.00211924
0.00211602
0.0021134
0.00211132
0.00210966
0.00210831
0.00210717
0.00210616
0.00210521
0.00210425
0.00210325
0.00210218
0.00210101
0.00209975
0.00209837
0.0020969
0.00209532
0.00209365
0.0020919
0.00209007
0.00208817
0.00208621
0.00208421
0.00208216
0.00208007
0.00207794
0.00207578
0.00207359
0.00207136
0.00206911
0.00206681
0.00206448
0.00206211
0.0020597
0.00205724
0.00205472
0.00205215
0.00204951
0.00204681
0.00204404
0.00204119
0.00203826
0.00203525
0.00203214
0.00202895
0.00202566
0.00202227
0.00201879
0.0020152
0.0020115
0.00200769
0.00200376
0.00199972
0.00199556
0.00199129
0.0019869
0.00198239
0.00197778
0.00197306
0.00196825
0.00196328
0.00195818
0.00195291
0.00194758
0.0019421
0.00193657
0.00193086
0.00192502
0.00191905
0.00191303
0.00190694
0.00190078
0.00189459
0.00188834
0.00188206
0.00187574
0.0018694
0.00186305
0.00185669
0.0018504
0.00184406
0.0018378
0.00183033
0.00182168
0.00180682
0.00177834
0.00171185
2.81876e-05
0.000132608
0.000287355
0.000397191
0.000505101
0.000582643
0.000656723
0.000715326
0.000771176
0.000818618
0.000861413
0.000895993
0.000917932
0.000930314
0.000935513
0.000935732
0.000933548
0.000932242
0.000935163
0.000944863
0.000962831
0.00098827
0.00102041
0.0010561
0.00109753
0.00114206
0.0011886
0.00123603
0.00128271
0.00132733
0.0013703
0.00141242
0.0014539
0.00149456
0.00153399
0.00157173
0.00160742
0.00164085
0.00167194
0.00170053
0.00172702
0.00175139
0.00177388
0.0017947
0.00181408
0.00183223
0.00184931
0.00186545
0.00188074
0.00189524
0.001909
0.00192201
0.00193426
0.00194563
0.00195585
0.00196563
0.00197811
0.00199436
0.00201511
0.00204077
0.0020718
0.00210854
0.00215196
0.00220134
0.00225638
0.00231722
0.0023833
0.00245296
0.00252391
0.00259198
0.00266233
0.00273625
0.00281092
0.00288977
0.00296974
0.00304773
0.00312083
0.00318652
0.00324319
0.00328973
0.00332591
0.00335219
0.00336961
0.00337951
0.00338333
0.0033823
0.00337727
0.00336816
0.00335522
0.0033415
0.00332831
0.00331634
0.00330583
0.00329682
0.0032893
0.00328312
0.00327807
0.00327391
0.00327042
0.00326741
0.00326474
0.00326226
0.00325986
0.00325748
0.00325503
0.00325249
0.00324982
0.00324702
0.00324407
0.00324097
0.00323774
0.00323439
0.00323092
0.00322735
0.0032237
0.00321997
0.00321618
0.00321233
0.00320843
0.00320449
0.0032005
0.00319647
0.00319239
0.00318827
0.0031841
0.00317988
0.00317561
0.00317127
0.00316687
0.0031624
0.00315784
0.0031532
0.00314847
0.00314364
0.0031387
0.00313365
0.00312849
0.0031232
0.00311779
0.00311226
0.00310659
0.00310079
0.00309485
0.00308876
0.00308252
0.00307613
0.00306958
0.00306289
0.00305605
0.00304905
0.00304191
0.00303462
0.00302718
0.00301957
0.00301179
0.00300386
0.00299578
0.00298757
0.00297922
0.00297071
0.00296204
0.00295326
0.00294439
0.00293545
0.00292642
0.00291735
0.00290822
0.00289905
0.00288986
0.00288066
0.0028715
0.00286234
0.00285333
0.00284421
0.00283499
0.00282372
0.00281158
0.00279308
0.00276101
0.00268586
3.13623e-05
0.000172008
0.00036678
0.000516487
0.000653067
0.000764558
0.000861159
0.000941558
0.00100854
0.00106372
0.00110737
0.00114049
0.00116444
0.00118121
0.00119284
0.00120148
0.00120954
0.00121961
0.00123408
0.0012547
0.00128233
0.00131813
0.00136194
0.00141278
0.00146612
0.00152138
0.00157867
0.00163556
0.00169068
0.00174218
0.00179113
0.00183843
0.00188436
0.00192887
0.00197178
0.00201283
0.00205184
0.00208868
0.00212331
0.00215578
0.00218617
0.00221486
0.00224188
0.00226737
0.00229155
0.00231463
0.0023368
0.00235822
0.00237904
0.00239941
0.00241946
0.00243936
0.0024593
0.00247957
0.0025007
0.00252344
0.00254855
0.00257695
0.00261038
0.00264865
0.00269233
0.00274191
0.00279763
0.00285951
0.00292791
0.00300288
0.00308383
0.00316949
0.00325823
0.00334833
0.00344304
0.00354386
0.00364881
0.00375875
0.00387221
0.00398523
0.00409413
0.0041952
0.00428512
0.0043613
0.00442241
0.00446837
0.00450026
0.00451987
0.00452935
0.00453074
0.00452582
0.0045163
0.00450422
0.00449162
0.00447961
0.00446874
0.00445925
0.00445117
0.00444444
0.00443889
0.00443432
0.00443052
0.00442729
0.00442447
0.00442192
0.00441951
0.00441713
0.00441473
0.00441224
0.00440961
0.00440683
0.00440388
0.00440075
0.00439744
0.00439396
0.00439031
0.0043865
0.00438254
0.00437843
0.00437419
0.00436982
0.00436532
0.0043607
0.00435595
0.00435108
0.00434609
0.00434097
0.00433572
0.00433033
0.0043248
0.00431913
0.00431332
0.00430734
0.00430121
0.00429492
0.00428846
0.00428182
0.00427501
0.00426801
0.00426082
0.00425344
0.00424586
0.0042381
0.00423014
0.00422199
0.00421363
0.00420508
0.00419632
0.00418736
0.00417819
0.00416883
0.00415926
0.0041495
0.00413955
0.0041294
0.00411906
0.00410853
0.00409781
0.00408689
0.00407579
0.00406453
0.00405311
0.00404152
0.00402977
0.00401786
0.00400584
0.00399371
0.0039815
0.00396919
0.00395682
0.00394437
0.00393187
0.00391932
0.00390673
0.0038941
0.00388141
0.00386863
0.00385543
0.00384076
0.00382389
0.00380523
0.00377844
0.00373451
0.00364871
3.39628e-05
0.000198359
0.000433145
0.000619806
0.000777795
0.000910062
0.00102131
0.00111584
0.0011957
0.00126285
0.00131873
0.00136522
0.00140297
0.0014338
0.0014596
0.00148228
0.00150374
0.00152573
0.00154964
0.00157789
0.00161185
0.00165075
0.00169845
0.00175444
0.00181597
0.00188083
0.00194572
0.00200884
0.0020658
0.00211901
0.0021699
0.00221915
0.00226699
0.0023134
0.00235825
0.00240138
0.00244265
0.00248199
0.00251933
0.00255471
0.00258841
0.00262054
0.00265137
0.00268098
0.0027095
0.00273713
0.00276405
0.00279047
0.00281658
0.00284257
0.00286863
0.00289494
0.00292173
0.00294915
0.00297718
0.00300569
0.0030345
0.00306572
0.00310166
0.00314331
0.00319147
0.00324674
0.0033094
0.00337973
0.0034591
0.00354822
0.00364682
0.0037538
0.00386663
0.00397753
0.00409319
0.00421693
0.00434898
0.00448796
0.00463526
0.00478656
0.00493746
0.00508261
0.00521613
0.00533281
0.00542912
0.0055037
0.0055573
0.00559222
0.00561166
0.00561907
0.00561778
0.00561086
0.00560098
0.00559009
0.00557936
0.00556943
0.00556062
0.00555299
0.00554649
0.00554099
0.0055363
0.00553223
0.00552863
0.00552533
0.0055222
0.00551914
0.00551606
0.0055129
0.00550959
0.00550612
0.00550245
0.00549858
0.0054945
0.00549021
0.00548571
0.00548101
0.0054761
0.00547101
0.00546573
0.00546027
0.00545463
0.00544881
0.0054428
0.00543662
0.00543026
0.00542371
0.00541696
0.00541003
0.00540289
0.00539554
0.00538799
0.00538022
0.00537224
0.00536404
0.00535561
0.00534695
0.00533806
0.00532892
0.00531954
0.00530992
0.00530006
0.00528995
0.00527961
0.00526903
0.0052582
0.00524714
0.00523584
0.00522429
0.00521251
0.0052005
0.00518825
0.00517578
0.00516308
0.00515016
0.00513702
0.00512368
0.00511012
0.00509636
0.0050824
0.00506826
0.00505395
0.00503947
0.00502483
0.00501004
0.00499511
0.00498007
0.00496493
0.0049497
0.00493439
0.00491901
0.00490357
0.00488806
0.0048725
0.00485687
0.00484114
0.00482526
0.00480906
0.00479203
0.00477266
0.00475122
0.00472672
0.00469229
0.00463849
0.00454712
3.60529e-05
0.00021831
0.000484951
0.000698965
0.000876798
0.00102715
0.00115494
0.00126497
0.00135972
0.00144161
0.00151236
0.00157354
0.00162662
0.00167405
0.00171633
0.00175477
0.0017907
0.00182525
0.00185929
0.0018939
0.00193361
0.00198093
0.00203627
0.00209877
0.00216592
0.00223292
0.00229489
0.00235216
0.00240641
0.00245876
0.00250978
0.00255968
0.00260845
0.00265601
0.00270221
0.00274693
0.00279008
0.0028316
0.00287149
0.00290979
0.00294636
0.00298117
0.00301437
0.0030462
0.00307689
0.00310666
0.00313572
0.00316429
0.00319257
0.0032208
0.00324921
0.00327805
0.00330788
0.00333895
0.00337103
0.00340518
0.00344227
0.00348329
0.00352902
0.00357966
0.00363522
0.00369558
0.00376047
0.00382933
0.0039066
0.00399462
0.00409378
0.00420322
0.00432331
0.00445083
0.00458696
0.00473168
0.00488738
0.00505532
0.00523771
0.00543257
0.00563469
0.00583713
0.00603007
0.00620396
0.00635136
0.00646834
0.00655474
0.00661343
0.0066491
0.0066671
0.00667258
0.00666999
0.0066628
0.00665344
0.00664344
0.0066337
0.00662468
0.00661655
0.00660932
0.00660287
0.00659706
0.00659173
0.00658674
0.00658194
0.00657722
0.00657249
0.00656767
0.00656271
0.00655756
0.0065522
0.00654662
0.0065408
0.00653474
0.00652845
0.00652193
0.00651519
0.00650822
0.00650104
0.00649365
0.00648604
0.00647822
0.0064702
0.00646196
0.00645351
0.00644484
0.00643594
0.00642682
0.00641747
0.00640787
0.00639804
0.00638796
0.00637763
0.00636706
0.00635623
0.00634515
0.0063338
0.00632218
0.00631029
0.00629812
0.00628568
0.00627299
0.00626003
0.00624681
0.00623333
0.0062196
0.00620561
0.00619137
0.00617688
0.00616213
0.00614715
0.00613191
0.00611645
0.00610075
0.00608483
0.0060687
0.00605235
0.00603581
0.00601907
0.00600215
0.00598506
0.00596781
0.00595042
0.00593289
0.00591524
0.00589748
0.00587963
0.00586171
0.00584373
0.00582568
0.00580759
0.00578945
0.00577126
0.00575301
0.00573467
0.00571619
0.00569744
0.00567815
0.00565764
0.00563434
0.00560885
0.00557904
0.00553782
0.00547619
0.00538222
3.70238e-05
0.000229907
0.000523516
0.000760072
0.000956833
0.00112377
0.00126662
0.00139083
0.00149948
0.00159542
0.00168051
0.00175646
0.0018249
0.00188795
0.00194569
0.00199926
0.00204967
0.00209789
0.00214474
0.00219233
0.00224424
0.00230135
0.00236254
0.00242517
0.00248564
0.00254336
0.00259893
0.00265297
0.0027059
0.00275793
0.00280911
0.00285938
0.00290861
0.00295668
0.00300341
0.00304869
0.00309239
0.00313438
0.0031746
0.00321298
0.0032495
0.00328422
0.00331718
0.00334851
0.00337841
0.00340711
0.00343488
0.00346201
0.00348883
0.00351565
0.00354286
0.00357082
0.00360049
0.00363144
0.00366387
0.00369907
0.00373744
0.00377909
0.00382432
0.00387416
0.00392863
0.00398834
0.00405401
0.00412644
0.00420679
0.00429528
0.00439071
0.00449199
0.00460599
0.00473946
0.00489384
0.00505979
0.00523845
0.0054367
0.00565718
0.00590359
0.00617052
0.00644712
0.00672055
0.00697443
0.00719482
0.00737322
0.00750757
0.0076012
0.00766081
0.00769435
0.00770939
0.00771231
0.00770796
0.00769968
0.00768964
0.00767914
0.00766886
0.00765913
0.00765003
0.0076415
0.00763343
0.0076257
0.00761818
0.00761074
0.00760329
0.00759574
0.00758803
0.00758014
0.00757201
0.00756364
0.00755502
0.00754614
0.00753701
0.00752763
0.00751801
0.00750816
0.00749809
0.00748779
0.00747727
0.00746653
0.00745557
0.0074444
0.007433
0.00742138
0.00740953
0.00739745
0.00738513
0.00737258
0.00735978
0.00734673
0.00733343
0.00731989
0.0073061
0.00729207
0.00727777
0.0072632
0.00724834
0.00723322
0.00721783
0.00720218
0.00718627
0.00717011
0.00715371
0.00713705
0.00712015
0.00710301
0.00708561
0.00706798
0.00705011
0.007032
0.00701366
0.00699511
0.00697634
0.00695737
0.0069382
0.00691885
0.00689933
0.00687965
0.00685982
0.00683986
0.00681977
0.00679958
0.0067793
0.00675894
0.00673852
0.00671805
0.00669755
0.00667703
0.00665648
0.00663592
0.00661534
0.00659473
0.00657407
0.0065533
0.00653233
0.00651099
0.00648889
0.00646528
0.0064387
0.00640952
0.00637494
0.00632784
0.00626069
0.00616587
3.772e-05
0.000240536
0.000552083
0.000805529
0.00101792
0.00119943
0.00135604
0.00149341
0.00161481
0.00172327
0.00182074
0.00190961
0.00199156
0.00206729
0.00213792
0.00220453
0.00226804
0.00232935
0.00238934
0.00244892
0.0025086
0.00256827
0.00262749
0.00268575
0.00274279
0.00279871
0.00285364
0.00290768
0.00296087
0.00301316
0.00306448
0.00311469
0.00316365
0.00321122
0.00325723
0.0033015
0.00334384
0.00338409
0.00342208
0.0034577
0.0034909
0.00352172
0.00355028
0.00357679
0.00360155
0.00362491
0.00364726
0.00366898
0.00369049
0.00371219
0.00373445
0.00375773
0.00378285
0.00380896
0.00383676
0.00386714
0.00390033
0.00393716
0.00397759
0.00402213
0.00407131
0.00412572
0.00418611
0.00425336
0.00432832
0.0044118
0.00450489
0.00460971
0.00472948
0.00486642
0.00502119
0.00519155
0.00538436
0.00560718
0.00586545
0.00616653
0.00651262
0.00688947
0.0072698
0.00763237
0.00795382
0.00821811
0.0084196
0.00856189
0.00865442
0.00870879
0.0087361
0.00874557
0.00874408
0.00873635
0.00872544
0.00871318
0.00870058
0.00868813
0.00867603
0.00866429
0.00865283
0.00864156
0.00863037
0.00861917
0.00860786
0.00859638
0.00858469
0.00857275
0.00856056
0.0085481
0.00853536
0.00852235
0.00850908
0.00849556
0.00848182
0.00846785
0.00845366
0.00843925
0.00842463
0.0084098
0.00839476
0.00837952
0.00836406
0.0083484
0.00833251
0.00831642
0.0083001
0.00828356
0.0082668
0.00824982
0.00823263
0.00821522
0.00819761
0.00817977
0.00816169
0.00814335
0.00812476
0.00810593
0.00808687
0.00806759
0.0080481
0.00802839
0.00800848
0.00798835
0.007968
0.00794744
0.00792666
0.00790568
0.00788448
0.00786308
0.00784148
0.00781971
0.00779775
0.00777564
0.00775338
0.00773098
0.00770845
0.00768582
0.00766309
0.00764028
0.00761741
0.00759449
0.00757154
0.00754858
0.00752561
0.00750265
0.00747971
0.00745679
0.00743391
0.00741105
0.00738821
0.00736536
0.00734246
0.00731944
0.00729616
0.0072724
0.0072477
0.00722129
0.00719185
0.0071593
0.00712049
0.0070686
0.00699788
0.00690382
3.80526e-05
0.000249956
0.000571543
0.000837404
0.00106271
0.00125699
0.00142592
0.00157516
0.00170782
0.00182706
0.00193568
0.00203513
0.00212689
0.00221227
0.00229241
0.0023683
0.00244077
0.00251048
0.00257798
0.00264362
0.00270758
0.00277001
0.002831
0.0028906
0.0029489
0.00300596
0.00306183
0.00311651
0.00316996
0.00322213
0.0032729
0.00332218
0.00336981
0.00341562
0.00345938
0.00350087
0.00353983
0.00357602
0.00360927
0.00363948
0.00366667
0.00369098
0.0037127
0.0037322
0.00374992
0.00376634
0.0037819
0.00379705
0.00381219
0.00382772
0.00384382
0.00386147
0.00387959
0.00389853
0.00391979
0.00394331
0.00396905
0.0039974
0.00402868
0.00406328
0.00410163
0.00414429
0.00419194
0.00424522
0.00430492
0.0043728
0.00445155
0.00454421
0.00465345
0.00478202
0.00493301
0.00511111
0.00531906
0.00556478
0.00585817
0.00621413
0.0066457
0.00713587
0.00765907
0.00816379
0.00861996
0.00899977
0.00929137
0.00949827
0.00963367
0.00971445
0.00975673
0.00977371
0.00977506
0.00976737
0.0097548
0.00973986
0.00972394
0.00970776
0.00969163
0.00967564
0.00965977
0.00964394
0.00962808
0.00961212
0.00959596
0.00957957
0.00956292
0.00954599
0.00952879
0.0095113
0.00949354
0.00947548
0.00945715
0.0094386
0.00941984
0.00940088
0.00938172
0.00936237
0.00934282
0.00932309
0.00930317
0.00928307
0.00926278
0.00924232
0.00922167
0.00920083
0.00917982
0.00915863
0.00913727
0.00911574
0.00909406
0.00907223
0.00905028
0.00902815
0.0090058
0.00898323
0.00896046
0.00893753
0.00891445
0.00889123
0.00886785
0.00884431
0.00882062
0.00879677
0.00877276
0.00874858
0.00872422
0.0086997
0.00867501
0.00865017
0.00862519
0.00860008
0.00857485
0.00854952
0.00852411
0.00849862
0.00847307
0.00844748
0.00842187
0.00839624
0.00837063
0.00834504
0.00831949
0.00829399
0.00826855
0.00824319
0.00821791
0.00819272
0.0081676
0.00814256
0.00811756
0.00809259
0.00806756
0.00804239
0.00801691
0.00799084
0.0079637
0.00793473
0.00790277
0.00786717
0.00782476
0.00776924
0.00769658
0.00760465
3.80113e-05
0.000254228
0.000580612
0.000853592
0.00109224
0.00129918
0.00147969
0.00163898
0.00178121
0.00191009
0.00202737
0.00213481
0.00223416
0.00232679
0.00241383
0.00249627
0.00257486
0.0026502
0.00272273
0.00279273
0.00286035
0.00292576
0.00298915
0.00305066
0.00311039
0.00316839
0.0032247
0.00327933
0.00333225
0.00338342
0.00343275
0.00348012
0.00352535
0.00356821
0.00360844
0.00364574
0.00367983
0.00371049
0.00373761
0.0037612
0.00378145
0.00379868
0.00381331
0.00382585
0.00383677
0.00384657
0.00385564
0.00386438
0.00387309
0.00388244
0.00389149
0.00390126
0.00391171
0.00392303
0.00393549
0.00394918
0.00396435
0.00398124
0.00400003
0.00402089
0.00404413
0.00407019
0.00409971
0.00413342
0.00417238
0.0042184
0.00427386
0.00434183
0.00442619
0.004532
0.00466566
0.00483415
0.00504359
0.00530167
0.00562132
0.00602855
0.0065495
0.00717603
0.00786648
0.00855298
0.0091821
0.00971099
0.0101183
0.0104069
0.0105953
0.0107077
0.0107672
0.0107924
0.0107963
0.010788
0.0107729
0.0107544
0.0107342
0.0107133
0.0106923
0.0106711
0.0106499
0.0106286
0.0106072
0.0105857
0.0105639
0.0105418
0.0105194
0.0104967
0.0104737
0.0104505
0.010427
0.0104032
0.010379
0.0103548
0.0103303
0.0103057
0.0102809
0.010256
0.0102308
0.0102056
0.0101802
0.0101546
0.0101289
0.010103
0.010077
0.0100509
0.0100246
0.00999822
0.00997174
0.00994517
0.00991854
0.00989186
0.00986518
0.00983838
0.00981134
0.00978417
0.00975689
0.0097296
0.00970228
0.00967488
0.00964739
0.00961983
0.00959218
0.00956444
0.00953659
0.00950863
0.00948054
0.00945234
0.00942404
0.00939565
0.00936718
0.00933866
0.00931009
0.00928149
0.00925288
0.00922428
0.0091957
0.00916715
0.00913866
0.00911025
0.00908191
0.00905369
0.00902557
0.00899759
0.00896974
0.00894203
0.00891446
0.00888704
0.00885976
0.00883259
0.0088055
0.00877844
0.00875134
0.00872408
0.00869646
0.00866816
0.0086387
0.00860735
0.00857315
0.00853483
0.00848951
0.0084315
0.00835821
0.00826912
3.77777e-05
0.00025653
0.00058469
0.000860652
0.00111189
0.00132967
0.00151978
0.0016881
0.00183905
0.00197518
0.00209877
0.00221235
0.00231732
0.00241518
0.00250709
0.002594
0.00267665
0.00275562
0.0028313
0.00290398
0.00297385
0.00304109
0.00310582
0.00316814
0.00322817
0.003286
0.00334168
0.00339526
0.00344674
0.00349608
0.00354318
0.00358788
0.00362996
0.00366915
0.00370513
0.00373759
0.00376628
0.00379105
0.00381188
0.00382892
0.00384247
0.00385294
0.00386078
0.00386646
0.00387043
0.00387308
0.00387467
0.00387567
0.00387625
0.00387657
0.00387696
0.00387704
0.00387679
0.00387652
0.00387639
0.00387652
0.00387698
0.00387796
0.00387969
0.00388252
0.00388677
0.00389278
0.00390102
0.00391234
0.00392774
0.00394866
0.003977
0.00401547
0.00406813
0.00414094
0.00424216
0.00438231
0.0045727
0.00482597
0.00515498
0.00561102
0.00623013
0.00700722
0.00789099
0.00879637
0.00963623
0.0103486
0.0108974
0.011284
0.0115343
0.0116825
0.0117606
0.0117938
0.0117998
0.0117899
0.0117714
0.0117484
0.011723
0.0116966
0.0116697
0.0116426
0.0116153
0.0115879
0.0115603
0.0115325
0.0115044
0.011476
0.0114472
0.0114182
0.0113889
0.0113595
0.0113299
0.0112999
0.0112694
0.0112389
0.0112083
0.0111776
0.0111468
0.0111159
0.0110848
0.0110536
0.0110223
0.0109909
0.0109594
0.0109278
0.0108961
0.0108643
0.0108324
0.0108005
0.0107686
0.0107367
0.0107048
0.010673
0.0106415
0.0106098
0.0105777
0.0105457
0.0105138
0.0104821
0.0104505
0.0104188
0.0103871
0.0103555
0.0103238
0.0102921
0.0102603
0.0102285
0.0101966
0.0101647
0.0101327
0.0101007
0.0100688
0.0100368
0.0100049
0.00997303
0.00994124
0.00990954
0.00987795
0.00984648
0.00981515
0.00978398
0.00975297
0.00972215
0.00969152
0.00966109
0.00963087
0.00960087
0.00957107
0.00954147
0.00951205
0.00948279
0.00945365
0.00942456
0.00939543
0.00936612
0.0093364
0.00930597
0.0092743
0.00924075
0.00920455
0.00916388
0.00911638
0.00905692
0.00898384
0.00889753
3.7287e-05
0.000258353
0.000586598
0.000863346
0.00112372
0.00134927
0.00154805
0.00172432
0.00188159
0.00202336
0.00215181
0.00226938
0.002378
0.00247911
0.00257381
0.00266309
0.00274765
0.00282806
0.00290472
0.00297793
0.00304794
0.00311495
0.00317913
0.00324059
0.00329944
0.00335576
0.00340966
0.00346122
0.00351041
0.00355719
0.00360143
0.00364292
0.0036814
0.00371655
0.00374802
0.00377551
0.00379876
0.00381768
0.0038323
0.00384283
0.00384959
0.00385295
0.00385329
0.00385111
0.00384683
0.00384085
0.00383354
0.00382478
0.00381463
0.00380317
0.00379047
0.0037767
0.00376222
0.003747
0.00373105
0.00371439
0.00369711
0.00367933
0.00366122
0.00364311
0.00362532
0.00360834
0.00359273
0.003579
0.00356798
0.00356095
0.00355972
0.00356692
0.00358648
0.00362409
0.00368785
0.00378997
0.00394469
0.00416879
0.00447449
0.00497927
0.00570946
0.00665115
0.00774944
0.00890287
0.00998916
0.0109166
0.0116291
0.0121265
0.0124442
0.0126295
0.0127257
0.0127657
0.0127723
0.0127597
0.0127367
0.0127081
0.0126767
0.0126438
0.0126104
0.0125767
0.0125426
0.0125083
0.012474
0.0124395
0.0124049
0.0123698
0.012334
0.0122982
0.0122623
0.0122262
0.0121899
0.0121534
0.0121167
0.01208
0.0120431
0.0120062
0.0119692
0.0119321
0.0118949
0.0118577
0.0118204
0.011783
0.0117456
0.0117081
0.0116705
0.0116329
0.0115953
0.0115577
0.0115202
0.0114828
0.0114455
0.0114085
0.0113716
0.0113348
0.0112979
0.0112613
0.0112248
0.0111889
0.0111531
0.0111171
0.0110814
0.0110457
0.0110101
0.0109744
0.0109388
0.0109031
0.0108674
0.0108318
0.0107962
0.0107607
0.0107253
0.01069
0.0106548
0.0106198
0.0105849
0.0105502
0.0105157
0.0104814
0.0104474
0.0104136
0.01038
0.0103467
0.0103136
0.0102809
0.0102484
0.0102162
0.0101842
0.0101525
0.0101211
0.0100898
0.0100587
0.0100276
0.00999657
0.00996529
0.00993358
0.00990112
0.0098674
0.00983183
0.00979375
0.00975116
0.00970219
0.00964218
0.00956989
0.00948613
3.66871e-05
0.000259874
0.00058722
0.000863225
0.00112883
0.00135774
0.00156458
0.00174747
0.00190962
0.00205473
0.00218567
0.00230506
0.00241467
0.00251655
0.00261148
0.00270047
0.00278423
0.0028634
0.00293838
0.00300956
0.00307723
0.00314166
0.00320308
0.00326167
0.00331757
0.00337093
0.00342183
0.0034703
0.00351633
0.00355982
0.0036006
0.00363845
0.00367302
0.00370396
0.00373085
0.00375335
0.0037712
0.00378429
0.00379265
0.00379653
0.00379624
0.00379219
0.00378489
0.00377442
0.00376099
0.00374491
0.00372661
0.00370647
0.0036846
0.0036609
0.00363538
0.0036082
0.00357948
0.00354929
0.00351775
0.00348496
0.00345105
0.00341615
0.00338039
0.00334379
0.00330639
0.00326829
0.00322964
0.00319073
0.0031521
0.00311487
0.00308074
0.00305248
0.00303429
0.00303183
0.00305335
0.0031103
0.00322004
0.00340132
0.00366676
0.00417238
0.0050386
0.00616213
0.00749174
0.00891211
0.0102699
0.0114336
0.0123229
0.0129355
0.0133198
0.0135392
0.0136501
0.0136942
0.0136991
0.0136821
0.0136533
0.0136181
0.0135798
0.0135398
0.0134992
0.0134584
0.0134171
0.0133753
0.0133338
0.0132921
0.0132502
0.013208
0.0131656
0.0131231
0.0130805
0.0130378
0.0129949
0.0129519
0.0129088
0.0128657
0.0128226
0.0127794
0.0127362
0.0126931
0.0126499
0.0126067
0.0125635
0.0125203
0.012477
0.0124338
0.0123905
0.0123473
0.012304
0.0122608
0.0122177
0.0121748
0.0121323
0.01209
0.012048
0.0120062
0.0119646
0.0119233
0.0118824
0.011842
0.0118019
0.0117625
0.0117235
0.0116841
0.0116446
0.0116052
0.0115658
0.0115264
0.011487
0.0114478
0.0114088
0.01137
0.0113313
0.0112929
0.0112547
0.0112168
0.011179
0.0111416
0.0111044
0.0110675
0.0110309
0.0109947
0.0109587
0.0109231
0.0108879
0.010853
0.0108184
0.0107842
0.0107503
0.0107167
0.0106833
0.0106502
0.0106173
0.0105845
0.0105516
0.0105185
0.010485
0.0104507
0.0104151
0.0103778
0.0103378
0.0102938
0.010244
0.0101844
0.0101134
0.0100325
3.60271e-05
0.000261618
0.000587466
0.000862055
0.00112994
0.00135993
0.00157132
0.00175664
0.00192046
0.00206614
0.00219634
0.00231399
0.00242159
0.00252077
0.00261246
0.0026977
0.00277728
0.00285193
0.00292216
0.00298842
0.00305108
0.00311049
0.00316692
0.0032206
0.00327175
0.00332052
0.003367
0.00341123
0.00345312
0.00349258
0.00352937
0.0035632
0.00359368
0.00362037
0.00364278
0.00366049
0.00367328
0.00368106
0.00368393
0.00368183
0.00367485
0.00366322
0.00364727
0.00362764
0.00360496
0.00357977
0.00355212
0.00352215
0.00349003
0.00345587
0.00341983
0.00338185
0.00334229
0.00330106
0.00325822
0.0032138
0.00316783
0.0031203
0.00307117
0.00302038
0.00296783
0.0029134
0.00285705
0.00279874
0.00273855
0.00267749
0.00261591
0.00255617
0.00250209
0.00245938
0.00243622
0.00244348
0.00249866
0.00262935
0.00284544
0.00332808
0.00432659
0.00563214
0.00719762
0.00889266
0.0105278
0.0119347
0.0129985
0.0137171
0.0141569
0.0144008
0.0145193
0.0145625
0.0145628
0.0145393
0.0145032
0.0144607
0.0144147
0.0143668
0.0143181
0.0142695
0.0142208
0.014172
0.0141232
0.0140744
0.0140254
0.0139763
0.0139271
0.0138779
0.0138286
0.0137793
0.01373
0.0136807
0.0136314
0.0135821
0.0135329
0.0134837
0.0134346
0.0133855
0.0133365
0.0132876
0.0132388
0.0131901
0.0131414
0.0130927
0.0130441
0.0129955
0.012947
0.0128984
0.01285
0.0128018
0.012754
0.0127067
0.0126598
0.0126133
0.0125672
0.0125216
0.0124764
0.0124319
0.0123879
0.0123447
0.0123026
0.0122605
0.0122177
0.0121749
0.0121317
0.0120888
0.0120461
0.0120037
0.0119616
0.0119198
0.0118783
0.0118371
0.0117962
0.0117557
0.0117155
0.0116756
0.0116361
0.011597
0.0115582
0.0115199
0.0114819
0.0114443
0.0114072
0.0113704
0.0113341
0.0112982
0.0112626
0.0112274
0.0111924
0.0111578
0.0111233
0.011089
0.0110546
0.01102
0.0109849
0.010949
0.010912
0.0108731
0.0108316
0.0107867
0.0107364
0.0106778
0.0106087
0.0105309
3.52052e-05
0.000261629
0.000585695
0.000857902
0.00112544
0.00135352
0.00156474
0.00174709
0.00190827
0.00204948
0.0021742
0.00228614
0.00238687
0.00247838
0.00256194
0.0026389
0.00271007
0.00277639
0.00283837
0.0028966
0.00295144
0.0030033
0.00305247
0.00309922
0.00314377
0.00318629
0.00322688
0.00326555
0.00330226
0.00333688
0.00336913
0.00339869
0.00342512
0.00344782
0.00346627
0.00348013
0.0034888
0.00349189
0.00348933
0.00348138
0.00346841
0.00345083
0.00342908
0.00340369
0.00337532
0.00334403
0.0033101
0.0032738
0.00323531
0.00319475
0.00315223
0.00310781
0.00306149
0.00301321
0.00296317
0.00291128
0.00285751
0.00280182
0.0027441
0.00268422
0.00262198
0.00255714
0.00248998
0.00242005
0.00234755
0.00227298
0.0021969
0.00212035
0.00204519
0.00197523
0.00191715
0.00188229
0.00188625
0.00196504
0.00213251
0.00260042
0.00369965
0.00517607
0.00698396
0.00893076
0.0108524
0.0124926
0.0137063
0.0145021
0.0149727
0.015223
0.0153373
0.0153723
0.0153633
0.0153307
0.0152858
0.0152342
0.0151789
0.0151228
0.0150666
0.0150104
0.0149542
0.0148981
0.014842
0.014786
0.01473
0.014674
0.0146181
0.0145623
0.0145065
0.0144509
0.0143953
0.0143398
0.0142845
0.0142293
0.0141741
0.0141191
0.0140643
0.0140095
0.0139549
0.0139006
0.0138464
0.0137924
0.0137385
0.0136849
0.0136313
0.0135778
0.0135244
0.0134708
0.0134175
0.0133645
0.013312
0.0132601
0.0132085
0.0131575
0.013107
0.0130571
0.0130077
0.0129591
0.0129111
0.0128642
0.0128186
0.0127735
0.0127276
0.0126813
0.0126347
0.0125882
0.0125424
0.0124971
0.0124522
0.0124078
0.0123638
0.0123201
0.0122769
0.0122341
0.0121918
0.0121498
0.0121083
0.0120672
0.0120266
0.0119864
0.0119467
0.0119075
0.0118687
0.0118304
0.0117926
0.0117552
0.0117182
0.0116816
0.0116453
0.0116093
0.0115736
0.0115379
0.0115022
0.0114662
0.0114298
0.0113926
0.0113542
0.0113141
0.0112715
0.0112256
0.0111751
0.0111178
0.0110514
0.0109768
3.4254e-05
0.000257916
0.000579434
0.00084831
0.00111212
0.00133411
0.00153767
0.00170969
0.00186043
0.00199063
0.00210338
0.00220216
0.00228916
0.00236684
0.00243666
0.00250053
0.00255923
0.00261372
0.00266455
0.00271224
0.00275716
0.00279967
0.00284005
0.00287856
0.00291538
0.00295067
0.00298454
0.003017
0.00304804
0.00307752
0.00310524
0.00313086
0.00315386
0.00317338
0.00318846
0.00319883
0.00320429
0.0032046
0.00319976
0.00318992
0.00317529
0.00315622
0.00313321
0.00310679
0.00307705
0.00304437
0.00300906
0.00297138
0.00293149
0.00288949
0.00284548
0.0027995
0.00275156
0.00270172
0.00264997
0.0025963
0.0025407
0.00248313
0.00242357
0.00236194
0.00229821
0.00223238
0.00216436
0.00209399
0.00202092
0.00194521
0.00186723
0.00178782
0.0017085
0.00163265
0.00156664
0.00151743
0.00149062
0.00153518
0.00166284
0.00212545
0.00332014
0.00497582
0.00697173
0.00918772
0.0113724
0.0131832
0.0144691
0.015275
0.0157288
0.0159562
0.0160491
0.0160667
0.0160437
0.0159995
0.015944
0.0158825
0.0158195
0.0157562
0.0156929
0.0156299
0.0155671
0.0155046
0.0154422
0.01538
0.015318
0.0152562
0.0151946
0.0151332
0.015072
0.015011
0.0149502
0.0148897
0.0148294
0.0147692
0.0147093
0.0146495
0.0145898
0.0145303
0.014471
0.014412
0.0143534
0.014295
0.014237
0.0141792
0.0141218
0.0140646
0.0140077
0.013951
0.0138948
0.0138391
0.0137839
0.0137292
0.013675
0.0136211
0.0135677
0.013515
0.013463
0.0134117
0.0133612
0.0133117
0.0132638
0.0132157
0.0131671
0.0131185
0.0130695
0.0130211
0.0129733
0.0129261
0.0128794
0.0128332
0.0127875
0.0127422
0.0126974
0.0126531
0.0126093
0.0125659
0.012523
0.0124806
0.0124388
0.0123974
0.0123565
0.0123162
0.0122763
0.012237
0.0121982
0.0121598
0.0121219
0.0120844
0.0120473
0.0120105
0.0119738
0.0119373
0.0119007
0.0118638
0.0118264
0.0117882
0.0117488
0.0117076
0.0116641
0.0116173
0.0115666
0.01151
0.0114461
0.0113744
3.31004e-05
0.00025007
0.00056881
0.000833965
0.00108879
0.00129831
0.00148579
0.00164057
0.00177375
0.00188466
0.00197754
0.00205692
0.00212543
0.00218589
0.00224008
0.0022893
0.00233444
0.00237638
0.00241562
0.0024526
0.00248764
0.00252101
0.00255292
0.00258357
0.00261309
0.00264163
0.00266925
0.002696
0.00272187
0.00274676
0.00277044
0.00279254
0.00281243
0.00282894
0.00284191
0.00285112
0.00285627
0.00285721
0.00285365
0.00284554
0.00283311
0.00281676
0.00279666
0.00277296
0.00274599
0.00271613
0.00268369
0.00264889
0.00261188
0.00257276
0.00253162
0.00248852
0.00244351
0.00239663
0.00234788
0.00229728
0.00224491
0.0021908
0.002135
0.00207754
0.00201839
0.0019575
0.00189479
0.00183022
0.00176362
0.00169491
0.00162425
0.001552
0.00147861
0.00140602
0.00134031
0.00128806
0.00125746
0.00128825
0.00140547
0.00195291
0.00326245
0.0050129
0.00720668
0.00969713
0.0120733
0.0139479
0.015209
0.0159579
0.0163554
0.0165374
0.016598
0.0165931
0.016554
0.0164971
0.016431
0.0163622
0.016293
0.0162239
0.0161551
0.0160869
0.0160191
0.0159518
0.0158849
0.0158183
0.0157521
0.0156863
0.0156208
0.0155557
0.0154909
0.0154265
0.0153624
0.0152987
0.0152353
0.0151721
0.0151092
0.0150465
0.0149838
0.0149213
0.0148589
0.0147968
0.0147352
0.014674
0.0146132
0.0145529
0.0144931
0.0144337
0.0143747
0.0143163
0.0142584
0.014201
0.0141443
0.0140881
0.0140325
0.0139775
0.0139232
0.0138696
0.0138166
0.0137645
0.0137133
0.0136631
0.0136136
0.0135635
0.0135141
0.0134647
0.0134156
0.0133669
0.0133187
0.013271
0.0132239
0.0131774
0.0131313
0.0130858
0.0130409
0.0129964
0.0129525
0.0129091
0.0128662
0.0128238
0.0127819
0.0127406
0.0126998
0.0126596
0.0126199
0.0125807
0.012542
0.0125039
0.0124662
0.012429
0.0123921
0.0123555
0.0123191
0.0122827
0.0122463
0.0122096
0.0121723
0.0121341
0.0120947
0.0120535
0.01201
0.0119634
0.0119131
0.011858
0.0117966
0.011729
3.19132e-05
0.000244194
0.000556841
0.000814999
0.00105105
0.00124012
0.0014034
0.00153354
0.00163874
0.00172328
0.00179197
0.00184925
0.00189814
0.00194109
0.00197957
0.00201465
0.00204699
0.00207733
0.00210608
0.00213358
0.00216003
0.00218562
0.00221044
0.00223458
0.00225812
0.00228113
0.00230366
0.00232573
0.0023473
0.00236827
0.00238855
0.00240803
0.00242571
0.00244036
0.00245264
0.00246224
0.00246905
0.00247287
0.00247313
0.00246969
0.00246223
0.00245117
0.00243655
0.00241839
0.00239709
0.00237302
0.00234647
0.00231758
0.00228643
0.00225317
0.00221795
0.00218085
0.00214192
0.00210121
0.00205875
0.0020146
0.00196892
0.00192182
0.00187342
0.0018237
0.00177273
0.00172056
0.00166723
0.00161272
0.0015569
0.00149951
0.00144044
0.00137986
0.00131801
0.00125627
0.00119969
0.0011548
0.00113714
0.00117045
0.00132696
0.00203151
0.00340899
0.00529605
0.00775753
0.0104709
0.0129191
0.0147307
0.0158771
0.0165168
0.0168322
0.0169607
0.0169873
0.0169606
0.0169062
0.0168378
0.0167648
0.0166905
0.0166163
0.0165428
0.01647
0.016398
0.0163267
0.0162561
0.016186
0.0161164
0.0160474
0.0159789
0.015911
0.0158435
0.0157764
0.0157099
0.015644
0.0155785
0.0155134
0.0154487
0.0153843
0.0153202
0.0152561
0.0151921
0.0151283
0.015065
0.0150022
0.0149399
0.0148782
0.014817
0.0147564
0.0146964
0.0146369
0.014578
0.0145198
0.0144622
0.0144052
0.0143489
0.0142932
0.0142383
0.0141843
0.0141308
0.0140779
0.0140265
0.0139754
0.0139243
0.0138742
0.0138245
0.0137754
0.0137267
0.0136784
0.0136304
0.013583
0.0135362
0.0134899
0.0134442
0.013399
0.0133544
0.0133104
0.0132669
0.013224
0.0131817
0.0131399
0.0130987
0.0130581
0.013018
0.0129785
0.0129395
0.0129011
0.0128631
0.0128258
0.0127889
0.0127525
0.0127166
0.0126811
0.0126458
0.0126108
0.0125758
0.0125407
0.0125052
0.0124692
0.0124323
0.0123942
0.0123543
0.0123121
0.012267
0.0122184
0.0121656
0.0121076
0.0120446
3.05806e-05
0.000239441
0.000541051
0.000781768
0.000990012
0.00115041
0.00127949
0.00137628
0.00144965
0.00150621
0.00155085
0.00158753
0.00161867
0.0016461
0.00167096
0.00169399
0.00171588
0.00173705
0.00175777
0.00177818
0.00179839
0.00181842
0.00183828
0.00185792
0.00187735
0.00189657
0.00191558
0.00193439
0.00195296
0.00197129
0.00198945
0.0020073
0.00202302
0.00203641
0.00204834
0.00205909
0.00206863
0.00207613
0.00208106
0.00208316
0.00208228
0.00207818
0.00207077
0.00205963
0.00204579
0.00202944
0.00201073
0.00198959
0.00196603
0.00194045
0.00191309
0.00188399
0.00185315
0.00182071
0.00178677
0.00175144
0.00171485
0.00167709
0.00163818
0.00159823
0.00155743
0.00151594
0.00147384
0.00143118
0.00138778
0.00134296
0.00129657
0.00124873
0.00119991
0.00115121
0.00110691
0.00107582
0.00107505
0.0011387
0.00139983
0.00229168
0.00379585
0.00593238
0.00863642
0.0114633
0.0138297
0.0154595
0.0164252
0.0169303
0.017159
0.0172338
0.0172279
0.01718
0.0171112
0.0170345
0.0169559
0.0168775
0.0167998
0.0167233
0.0166478
0.0165733
0.0164997
0.016427
0.0163549
0.0162836
0.0162129
0.0161428
0.0160734
0.0160047
0.0159367
0.0158694
0.0158027
0.0157367
0.0156713
0.0156065
0.0155421
0.0154782
0.0154147
0.0153515
0.0152888
0.0152264
0.0151642
0.0151026
0.0150416
0.0149812
0.0149214
0.0148622
0.0148035
0.0147455
0.0146882
0.0146315
0.0145753
0.0145198
0.014465
0.0144113
0.0143587
0.0143059
0.0142537
0.0142026
0.014152
0.0141021
0.014053
0.0140044
0.0139564
0.0139089
0.0138619
0.0138154
0.0137694
0.013724
0.0136791
0.0136349
0.0135913
0.0135482
0.0135058
0.013464
0.0134228
0.0133822
0.0133422
0.0133028
0.013264
0.0132258
0.0131883
0.0131513
0.013115
0.0130792
0.0130439
0.0130092
0.012975
0.0129413
0.012908
0.012875
0.0128422
0.0128095
0.0127767
0.0127436
0.0127099
0.0126752
0.0126393
0.0126017
0.012562
0.0125195
0.0124738
0.0124242
0.0123705
0.0123127
2.93895e-05
0.000240777
0.000518885
0.000729428
0.000900069
0.00102038
0.0011072
0.00116807
0.00121152
0.0012435
0.00126825
0.00128852
0.00130597
0.00132191
0.00133719
0.00135229
0.00136751
0.00138306
0.00139903
0.00141546
0.00143234
0.00144956
0.00146702
0.00148458
0.00150216
0.00151976
0.00153731
0.00155476
0.00157213
0.00158949
0.0016069
0.00162372
0.00163793
0.00165077
0.00166302
0.00167543
0.00168731
0.00169793
0.00170692
0.00171398
0.00171878
0.001721
0.00172051
0.00171731
0.00171167
0.00170399
0.00169402
0.00168133
0.00166605
0.00164938
0.00163121
0.0016113
0.00158965
0.00156663
0.00154229
0.00151669
0.00148995
0.00146217
0.00143341
0.00140381
0.0013737
0.00134332
0.00131278
0.00128195
0.00125084
0.00121765
0.00118277
0.00114685
0.00111157
0.00107621
0.00104513
0.00103066
0.00106645
0.00119773
0.00163095
0.00274223
0.00446857
0.00689042
0.00977292
0.0125553
0.0146938
0.0160616
0.0168215
0.0171919
0.0173391
0.0173667
0.0173318
0.0172656
0.0171862
0.0171036
0.017021
0.0169396
0.0168597
0.0167813
0.0167042
0.0166283
0.0165535
0.0164797
0.0164068
0.0163346
0.0162631
0.0161923
0.0161224
0.0160534
0.0159851
0.0159177
0.0158512
0.0157855
0.0157206
0.0156565
0.0155931
0.0155304
0.0154682
0.0154066
0.0153457
0.0152853
0.0152255
0.0151663
0.0151077
0.0150497
0.0149923
0.0149355
0.0148792
0.0148235
0.0147687
0.0147141
0.0146594
0.0146056
0.0145526
0.0145005
0.0144493
0.0143985
0.0143483
0.0142989
0.0142502
0.0142021
0.0141547
0.0141079
0.0140617
0.014016
0.0139709
0.0139263
0.0138823
0.013839
0.0137962
0.0137541
0.0137126
0.0136717
0.0136315
0.0135919
0.0135529
0.0135146
0.013477
0.01344
0.0134037
0.013368
0.013333
0.0132986
0.0132649
0.0132317
0.013199
0.013167
0.0131355
0.0131046
0.0130741
0.0130439
0.013014
0.0129842
0.0129543
0.0129242
0.0128936
0.0128621
0.0128295
0.0127953
0.012759
0.0127203
0.0126786
0.0126336
0.0125849
0.0125332
2.79337e-05
0.000235886
0.000478195
0.000645076
0.0007666
0.00084095
0.000889646
0.000920414
0.000941126
0.00095575
0.000967514
0.000977972
0.000988225
0.000998769
0.00100998
0.00102202
0.001035
0.00104892
0.00106375
0.00107947
0.00109595
0.00111301
0.00113046
0.00114807
0.00116586
0.00118378
0.00120167
0.0012195
0.00123727
0.00125502
0.0012726
0.00128837
0.00130203
0.00131518
0.00132848
0.00134255
0.00135613
0.00136886
0.00138071
0.00139134
0.00140043
0.00140775
0.00141313
0.00141651
0.00141792
0.00141744
0.00141495
0.00141046
0.00140421
0.00139673
0.00138772
0.00137666
0.00136384
0.00135015
0.00133519
0.001319
0.00130184
0.00128376
0.0012647
0.0012447
0.00122492
0.00120571
0.00118628
0.00116581
0.00114405
0.00112044
0.00109713
0.00107206
0.00104988
0.00102587
0.00101558
0.00103409
0.00111507
0.00133973
0.0020385
0.00338951
0.00540015
0.00808142
0.0110243
0.0135976
0.0154104
0.0164912
0.0170548
0.0173064
0.0173851
0.017373
0.017315
0.017235
0.0171491
0.0170625
0.0169774
0.0168944
0.0168134
0.0167342
0.0166564
0.01658
0.0165049
0.016431
0.0163579
0.0162855
0.0162136
0.0161424
0.0160727
0.016004
0.0159357
0.0158684
0.0158023
0.0157374
0.0156735
0.0156106
0.0155486
0.0154875
0.015427
0.0153674
0.0153086
0.0152505
0.0151931
0.0151364
0.0150804
0.015025
0.0149702
0.014916
0.0148623
0.0148093
0.014757
0.0147052
0.0146539
0.0146033
0.0145533
0.014504
0.0144555
0.0144075
0.0143602
0.0143135
0.0142675
0.0142221
0.0141772
0.014133
0.0140893
0.014046
0.0140034
0.0139614
0.0139199
0.0138791
0.013839
0.0137995
0.0137606
0.0137224
0.0136848
0.0136479
0.0136117
0.0135762
0.0135413
0.0135072
0.0134737
0.0134409
0.0134088
0.0133774
0.0133467
0.0133166
0.0132871
0.0132582
0.01323
0.0132023
0.0131751
0.0131484
0.0131219
0.0130956
0.0130693
0.0130429
0.013016
0.0129884
0.0129596
0.0129294
0.0128973
0.0128629
0.0128259
0.0127859
0.0127432
0.0126981
2.6853e-05
0.00022215
0.000415351
0.00052441
0.000590586
0.000625893
0.000646302
0.000658538
0.000667673
0.000675702
0.000683946
0.000692857
0.000702847
0.000713969
0.00072626
0.000739665
0.000754119
0.000769537
0.000785872
0.000803085
0.000821002
0.000839371
0.000858053
0.000876889
0.000896014
0.000915316
0.000934433
0.000953527
0.000972498
0.000991067
0.00100826
0.00102349
0.00103804
0.00105207
0.00106679
0.00108213
0.00109687
0.0011109
0.00112437
0.00113706
0.00114879
0.0011594
0.00116875
0.00117674
0.00118331
0.0011884
0.00119199
0.00119407
0.00119474
0.00119412
0.00119212
0.00118886
0.00118453
0.00117928
0.00117239
0.00116429
0.00115549
0.00114577
0.00113482
0.00112376
0.00111321
0.00110266
0.00109043
0.00107724
0.00106337
0.00104943
0.00103618
0.00102053
0.00100936
0.00100689
0.00101488
0.00105911
0.00120733
0.00160841
0.00259045
0.00421719
0.00655223
0.009396
0.0122277
0.014465
0.015919
0.016734
0.0171319
0.0172882
0.0173139
0.0172719
0.0171958
0.0171082
0.0170181
0.0169293
0.0168433
0.0167601
0.0166791
0.0166
0.0165223
0.0164462
0.0163716
0.0162983
0.016226
0.0161535
0.0160805
0.0160088
0.0159387
0.0158699
0.0158023
0.0157358
0.0156706
0.0156066
0.0155437
0.015482
0.0154214
0.0153618
0.0153031
0.0152454
0.0151886
0.0151328
0.0150777
0.0150233
0.0149697
0.0149168
0.0148646
0.014813
0.0147621
0.0147118
0.0146622
0.0146132
0.0145649
0.0145173
0.0144702
0.0144238
0.0143782
0.0143331
0.0142887
0.0142449
0.0142017
0.0141592
0.0141172
0.0140759
0.0140352
0.0139951
0.0139556
0.0139167
0.0138784
0.0138408
0.0138038
0.0137675
0.0137318
0.0136968
0.0136624
0.0136288
0.0135958
0.0135635
0.013532
0.0135011
0.013471
0.0134415
0.0134128
0.0133849
0.0133576
0.0133311
0.0133052
0.0132801
0.0132556
0.0132317
0.0132084
0.0131855
0.0131631
0.0131409
0.0131188
0.0130966
0.0130741
0.013051
0.013027
0.0130017
0.0129746
0.0129455
0.012914
0.0128801
0.0128438
0.0128058
2.47224e-05
0.000186653
0.000312196
0.000358956
0.00039009
0.000404551
0.000415165
0.000424321
0.000434172
0.00044497
0.000456991
0.000470114
0.000484385
0.000499635
0.000515735
0.00053257
0.000550038
0.0005681
0.000586761
0.000606043
0.000625667
0.000645374
0.000665188
0.000685176
0.000705531
0.00072597
0.000745926
0.000766056
0.000785634
0.000803349
0.000820375
0.000836417
0.000851546
0.000866812
0.000882919
0.00089876
0.00091401
0.000928713
0.000942861
0.000956489
0.000969507
0.000981837
0.000993395
0.00100409
0.00101382
0.00102252
0.00103015
0.00103669
0.00104214
0.00104651
0.00104981
0.00105211
0.00105349
0.00105394
0.00105339
0.00105189
0.00104951
0.00104612
0.00104201
0.00103765
0.00103317
0.00102793
0.00102143
0.00101373
0.00100652
0.00100196
0.00100059
0.000998091
0.000996872
0.00100537
0.00103944
0.00113697
0.00139031
0.00203484
0.00330264
0.00523413
0.00782339
0.0106804
0.0132371
0.0150812
0.0162044
0.0168005
0.0170705
0.0171572
0.0171446
0.0170812
0.0169956
0.016904
0.016812
0.0167223
0.0166367
0.0165548
0.0164749
0.0163967
0.0163198
0.0162447
0.0161714
0.0160995
0.0160263
0.015952
0.0158792
0.0158076
0.0157375
0.0156689
0.0156017
0.0155357
0.0154711
0.0154078
0.0153457
0.015285
0.0152255
0.0151671
0.0151099
0.0150538
0.0149987
0.0149447
0.0148915
0.0148392
0.0147877
0.014737
0.0146871
0.0146379
0.0145894
0.0145416
0.0144946
0.0144482
0.0144026
0.0143576
0.0143133
0.0142697
0.0142267
0.0141844
0.0141428
0.0141018
0.0140615
0.0140218
0.0139827
0.0139443
0.0139066
0.0138695
0.013833
0.0137972
0.013762
0.0137275
0.0136937
0.0136605
0.013628
0.0135961
0.013565
0.0135346
0.0135048
0.0134759
0.0134476
0.0134201
0.0133934
0.0133674
0.0133421
0.0133177
0.013294
0.0132711
0.013249
0.0132276
0.0132069
0.0131869
0.0131676
0.0131488
0.0131305
0.0131126
0.0130948
0.0130771
0.0130593
0.013041
0.0130219
0.0130019
0.0129805
0.0129574
0.0129323
0.0129051
0.012876
0.012846
2.4458e-05
0.000139501
0.000187425
0.00020664
0.000223351
0.000236865
0.000250951
0.000265491
0.000281151
0.000297614
0.000314757
0.000332418
0.000350623
0.000369135
0.00038785
0.00040675
0.000425771
0.000444964
0.000464441
0.000484446
0.000504507
0.00052454
0.000544663
0.000564912
0.000585742
0.00060634
0.000625886
0.000645444
0.000664478
0.000682476
0.000699607
0.00071578
0.000731959
0.000748513
0.000764752
0.000780559
0.000795927
0.000810854
0.000825286
0.000839252
0.000852766
0.00086582
0.000878381
0.000890368
0.000901702
0.000912319
0.0009222
0.000931292
0.000939552
0.000946957
0.000953513
0.000959271
0.000964307
0.000968613
0.000972086
0.000974517
0.000976003
0.000976576
0.000976483
0.000975795
0.000975296
0.000975111
0.000975722
0.000978153
0.000979021
0.000979958
0.000982169
0.000985675
0.000998887
0.001035
0.00111621
0.00128864
0.00169403
0.00260937
0.00416477
0.00637981
0.00907455
0.0117715
0.0139599
0.0154308
0.0162833
0.0167147
0.0168941
0.0169327
0.0168961
0.0168201
0.0167311
0.0166387
0.0165475
0.0164592
0.0163753
0.0162957
0.0162181
0.0161414
0.016066
0.0159927
0.0159214
0.0158486
0.0157735
0.0156994
0.0156263
0.0155548
0.0154847
0.0154162
0.0153491
0.0152833
0.0152189
0.0151559
0.0150942
0.015034
0.0149752
0.0149177
0.0148614
0.0148064
0.0147525
0.0146998
0.014648
0.0145973
0.0145474
0.0144985
0.0144503
0.0144031
0.0143566
0.0143109
0.014266
0.0142218
0.0141784
0.0141357
0.0140937
0.0140525
0.0140119
0.0139721
0.013933
0.0138946
0.0138568
0.0138197
0.0137833
0.0137476
0.0137125
0.0136781
0.0136444
0.0136114
0.0135791
0.0135474
0.0135164
0.0134862
0.0134566
0.0134278
0.0133997
0.0133723
0.0133457
0.0133198
0.0132947
0.0132704
0.0132469
0.0132242
0.0132023
0.0131813
0.013161
0.0131416
0.0131231
0.0131053
0.0130884
0.0130722
0.0130568
0.0130419
0.0130277
0.013014
0.0130006
0.0129873
0.0129741
0.0129606
0.0129466
0.0129318
0.012916
0.0128988
0.01288
0.0128594
0.0128374
0.012815
2.32147e-05
7.559e-05
0.000104017
0.00012224
0.000140231
0.000157833
0.000175716
0.000193593
0.000211907
0.000230307
0.000248651
0.000266948
0.000285149
0.000303247
0.000321354
0.000339565
0.000357975
0.000376563
0.000395535
0.000415146
0.000434206
0.000453292
0.000472709
0.000492294
0.000512096
0.000531842
0.000551362
0.000570637
0.000589212
0.000606726
0.000623757
0.000641208
0.000658309
0.000674919
0.000691139
0.000706969
0.000722412
0.00073744
0.000752032
0.000766173
0.000779889
0.000793251
0.00080622
0.000818729
0.000830727
0.000842172
0.000853027
0.00086325
0.000872809
0.000881676
0.000889861
0.000897353
0.000904245
0.000910439
0.000915909
0.000920879
0.000925349
0.000929873
0.000934921
0.00093992
0.000943606
0.000946873
0.000950832
0.000954601
0.000959275
0.000967025
0.000979162
0.000999271
0.00103795
0.00111433
0.00125674
0.00151935
0.00213466
0.00331155
0.00511863
0.0075102
0.0101485
0.0125601
0.0143758
0.0155375
0.0161883
0.0165058
0.0166269
0.0166367
0.0165864
0.0165065
0.0164183
0.0163286
0.0162408
0.0161559
0.0160752
0.0159993
0.0159247
0.0158503
0.0157766
0.0157059
0.0156347
0.0155599
0.0154854
0.0154105
0.0153371
0.0152653
0.015195
0.0151262
0.015059
0.014993
0.0149283
0.014865
0.0148032
0.014743
0.0146844
0.0146272
0.0145713
0.0145167
0.0144635
0.0144115
0.0143605
0.0143107
0.0142619
0.0142141
0.0141673
0.0141213
0.0140763
0.0140321
0.0139887
0.0139462
0.0139045
0.0138636
0.0138234
0.0137841
0.0137455
0.0137077
0.0136707
0.0136343
0.0135987
0.0135638
0.0135296
0.0134961
0.0134633
0.0134312
0.0133998
0.0133691
0.0133392
0.01331
0.0132815
0.0132538
0.0132268
0.0132006
0.0131751
0.0131505
0.0131266
0.0131035
0.0130812
0.0130598
0.0130392
0.0130194
0.0130006
0.0129826
0.0129655
0.0129493
0.012934
0.0129195
0.012906
0.0128933
0.0128814
0.0128703
0.0128598
0.01285
0.0128406
0.0128315
0.0128227
0.0128137
0.0128045
0.0127948
0.0127842
0.0127726
0.0127597
0.0127454
0.0127301
0.0127148
4.50043e-05
9.54043e-05
0.000111309
0.000124742
0.000137634
0.000150792
0.000164521
0.000178673
0.000193566
0.000208317
0.000223165
0.000238364
0.000253757
0.000269452
0.000285458
0.000301743
0.000318336
0.000335254
0.000352572
0.000370332
0.000388342
0.000406602
0.000425142
0.00044393
0.000462924
0.000482005
0.000501073
0.000519903
0.000537811
0.000555645
0.000573608
0.000591178
0.000608211
0.000624982
0.000641441
0.000657496
0.000673145
0.000688309
0.000703043
0.000717382
0.000731359
0.00074499
0.000758214
0.000771026
0.000783417
0.000795368
0.000806869
0.000817916
0.000828511
0.00083866
0.000848417
0.000857791
0.000866444
0.000874426
0.000881787
0.000888646
0.000895126
0.000901605
0.000907965
0.000913854
0.000920233
0.000927425
0.00093608
0.000946655
0.000960633
0.000980106
0.0010082
0.00105162
0.0011255
0.00125393
0.00145626
0.00185292
0.002676
0.00407228
0.00605352
0.00847529
0.0109309
0.0130185
0.0145142
0.0154443
0.0159571
0.0162024
0.0162896
0.0162866
0.016232
0.0161553
0.0160723
0.0159887
0.015907
0.0158281
0.0157524
0.015681
0.0156101
0.0155382
0.0154662
0.0153964
0.0153247
0.0152496
0.0151748
0.0150993
0.0150252
0.0149526
0.0148819
0.0148128
0.0147449
0.0146782
0.0146126
0.0145483
0.0144857
0.0144251
0.0143661
0.0143085
0.0142523
0.0141975
0.0141442
0.0140923
0.0140416
0.013992
0.0139436
0.0138963
0.01385
0.0138048
0.0137605
0.0137172
0.0136748
0.0136332
0.0135926
0.0135528
0.0135139
0.0134759
0.0134387
0.0134023
0.0133667
0.0133319
0.0132978
0.0132645
0.0132319
0.0132001
0.013169
0.0131386
0.013109
0.0130801
0.0130521
0.0130247
0.0129982
0.0129725
0.0129475
0.0129234
0.0129001
0.0128775
0.0128559
0.012835
0.0128151
0.012796
0.0127778
0.0127605
0.0127441
0.0127287
0.0127142
0.0127006
0.0126881
0.0126764
0.0126658
0.012656
0.0126472
0.0126392
0.012632
0.0126256
0.0126197
0.0126143
0.0126093
0.0126044
0.0125994
0.0125942
0.0125884
0.0125818
0.0125743
0.0125657
0.0125564
0.0125474
5.08274e-05
5.82776e-05
7.00486e-05
8.48202e-05
0.000100324
0.00011625
0.000132281
0.000147991
0.000163489
0.000179154
0.000193892
0.000208231
0.000223153
0.000238275
0.000253542
0.000269047
0.000284951
0.000301272
0.000318041
0.000335247
0.000352868
0.000370804
0.000389083
0.000407653
0.000426401
0.000445272
0.000464213
0.00048304
0.000501488
0.000519768
0.000537927
0.000555405
0.00057254
0.000589801
0.000606638
0.000622939
0.000638816
0.00065404
0.000668944
0.000683541
0.000697882
0.000711809
0.000725298
0.000738411
0.000751139
0.000763468
0.000775397
0.000786927
0.000798059
0.000808793
0.000819168
0.000829117
0.000838651
0.000847883
0.000856838
0.000865617
0.000874395
0.000883453
0.000892964
0.000903146
0.000914626
0.000928126
0.00094467
0.000965567
0.000992834
0.00102942
0.00108027
0.00115553
0.00127409
0.0014522
0.00173337
0.0022858
0.00328964
0.00485121
0.00690279
0.00922664
0.0114242
0.0131984
0.0144333
0.0151938
0.0156134
0.015815
0.015886
0.0158821
0.0158312
0.0157634
0.0156904
0.0156167
0.0155444
0.0154736
0.0154049
0.0153394
0.0152727
0.0152033
0.0151323
0.0150614
0.0149888
0.0149144
0.0148389
0.0147617
0.014686
0.0146126
0.0145413
0.0144711
0.014402
0.0143335
0.0142658
0.0141995
0.0141353
0.0140735
0.0140134
0.0139545
0.0138969
0.013841
0.0137868
0.0137341
0.0136826
0.0136323
0.0135834
0.0135357
0.0134891
0.0134436
0.0133992
0.0133559
0.0133135
0.0132721
0.0132317
0.0131922
0.0131537
0.0131161
0.0130794
0.0130436
0.0130087
0.0129746
0.0129413
0.0129089
0.0128771
0.0128462
0.012816
0.0127865
0.0127579
0.0127301
0.0127031
0.0126769
0.0126515
0.012627
0.0126034
0.0125806
0.0125587
0.0125376
0.0125175
0.0124982
0.0124798
0.0124624
0.0124459
0.0124304
0.0124158
0.0124022
0.0123897
0.0123782
0.0123676
0.0123582
0.0123497
0.0123423
0.0123359
0.0123304
0.0123259
0.0123222
0.0123193
0.012317
0.0123153
0.0123138
0.0123126
0.0123112
0.0123097
0.0123076
0.012305
0.0123017
0.012298
0.0122946
0.000149664
0.000151129
0.000153369
0.000157385
0.000163039
0.00016864
0.000175466
0.00018344
0.000192398
0.00020246
0.000213247
0.000224463
0.000236349
0.000248715
0.000261682
0.000275149
0.000288998
0.000303235
0.000317916
0.000332998
0.0003486
0.00036445
0.000381074
0.000397804
0.000414631
0.000431903
0.000449472
0.000467133
0.000484725
0.00050226
0.000519681
0.000536731
0.000553558
0.000570189
0.000586616
0.000602723
0.000618324
0.000632927
0.000648031
0.000662757
0.000677192
0.000691058
0.000704592
0.000717918
0.0007309
0.000743546
0.000755889
0.000767954
0.000779767
0.00079136
0.000802786
0.000814067
0.000825284
0.000836543
0.00084798
0.000859792
0.000872257
0.000885749
0.000900712
0.000917713
0.000937581
0.000961407
0.000990683
0.00102741
0.00107405
0.00113485
0.00121677
0.00133284
0.00149978
0.00173333
0.0021254
0.00282602
0.00398013
0.00563997
0.00766304
0.00979616
0.0117009
0.0131824
0.014198
0.0148251
0.0151766
0.0153514
0.0154175
0.0154215
0.0153822
0.0153302
0.0152734
0.0152151
0.0151564
0.0150972
0.0150387
0.014981
0.0149188
0.0148517
0.014781
0.0147082
0.0146332
0.0145566
0.014479
0.0144013
0.0143248
0.0142518
0.0141801
0.0141077
0.0140371
0.0139657
0.0138946
0.013825
0.0137585
0.0136953
0.0136333
0.0135722
0.013512
0.0134541
0.0133982
0.0133439
0.0132907
0.0132389
0.0131886
0.0131397
0.0130919
0.0130452
0.0129997
0.0129554
0.0129122
0.01287
0.0128289
0.0127888
0.0127497
0.0127116
0.0126745
0.0126384
0.0126033
0.0125691
0.0125357
0.0125031
0.0124714
0.0124404
0.0124102
0.0123808
0.0123523
0.0123245
0.0122977
0.0122717
0.0122467
0.0122225
0.0121993
0.0121769
0.0121555
0.012135
0.0121155
0.0120969
0.0120792
0.0120626
0.0120469
0.0120323
0.0120186
0.0120061
0.0119945
0.0119841
0.0119748
0.0119666
0.0119594
0.0119534
0.0119485
0.0119447
0.0119419
0.0119401
0.0119391
0.011939
0.0119396
0.0119407
0.0119421
0.0119438
0.0119455
0.011947
0.0119482
0.0119491
0.01195
0.0119508
0.000366857
0.000368386
0.000369543
0.000369616
0.000369149
0.000368426
0.000367673
0.000365716
0.000363907
0.000362583
0.000361804
0.000361726
0.000362651
0.000364636
0.000367786
0.000372123
0.000377558
0.000384009
0.00039145
0.000399783
0.000409051
0.000419047
0.000429971
0.00044162
0.000453765
0.000466461
0.000479673
0.000493303
0.000507233
0.00052141
0.000535752
0.000550121
0.000564602
0.000578886
0.000593783
0.000608102
0.000621901
0.000635792
0.00064971
0.000663543
0.000677498
0.000690472
0.000703906
0.000717463
0.000730597
0.000743674
0.000756712
0.000769745
0.000782836
0.000796059
0.00080951
0.0008233
0.00083758
0.000852544
0.000868445
0.000885619
0.000904496
0.00092564
0.000949769
0.000977752
0.00101069
0.00105002
0.00109754
0.00115596
0.00122743
0.0013192
0.00143988
0.00160063
0.00181201
0.00212262
0.00262837
0.00345663
0.00471592
0.0063954
0.00830385
0.0101922
0.0118031
0.0130223
0.013853
0.0143719
0.0146716
0.0148313
0.0149028
0.0149218
0.0149036
0.0148754
0.014842
0.0148045
0.0147638
0.0147204
0.0146751
0.0146253
0.0145679
0.0145031
0.0144322
0.0143572
0.0142798
0.0142011
0.0141218
0.0140426
0.0139645
0.0138883
0.013813
0.0137383
0.0136644
0.0135912
0.0135191
0.0134492
0.0133838
0.0133197
0.013255
0.0131915
0.013128
0.013068
0.0130103
0.012954
0.0128987
0.0128449
0.012793
0.0127425
0.012693
0.0126447
0.0125977
0.012552
0.0125075
0.012464
0.0124216
0.0123802
0.01234
0.0123009
0.0122628
0.0122259
0.0121899
0.0121549
0.0121208
0.0120876
0.0120552
0.0120235
0.0119927
0.0119626
0.0119334
0.011905
0.0118776
0.0118511
0.0118255
0.0118009
0.0117773
0.0117546
0.0117329
0.0117122
0.0116925
0.0116737
0.011656
0.0116393
0.0116236
0.0116089
0.0115953
0.0115828
0.0115715
0.0115612
0.0115521
0.0115442
0.0115374
0.0115317
0.0115273
0.011524
0.0115218
0.0115207
0.0115206
0.0115214
0.0115231
0.0115254
0.0115282
0.0115314
0.0115349
0.0115384
0.011542
0.0115453
0.0115488
0.0115518
0.000665773
0.000668905
0.000671508
0.000673489
0.000675176
0.000675452
0.000674778
0.00067302
0.000669661
0.000663812
0.000656767
0.000648819
0.000640577
0.000632372
0.000624518
0.000617164
0.000610592
0.00060496
0.000600373
0.000596903
0.000594611
0.000593418
0.000593394
0.000594488
0.000596597
0.000599699
0.000603757
0.000608713
0.000614475
0.000621027
0.00062826
0.000636059
0.000644441
0.000653237
0.00066273
0.000672598
0.000682593
0.000693109
0.000703819
0.000715056
0.000726761
0.000738084
0.000750287
0.000763228
0.000775583
0.000789004
0.000802768
0.00081704
0.000831955
0.00084763
0.00086423
0.000881947
0.000901023
0.000921757
0.000944534
0.000969838
0.000998257
0.00103055
0.00106766
0.00111062
0.00116065
0.00121943
0.00128884
0.00137287
0.00147437
0.00160252
0.00175953
0.00195817
0.00222672
0.00262048
0.00322727
0.00414823
0.00545111
0.00706988
0.00879993
0.0104228
0.0117578
0.0127464
0.0134192
0.0138479
0.0141083
0.0142611
0.0143457
0.014388
0.0143999
0.0144039
0.0144012
0.0143902
0.014373
0.0143509
0.0143215
0.014281
0.0142293
0.0141665
0.0140936
0.0140151
0.0139343
0.0138525
0.0137707
0.0136894
0.0136091
0.0135301
0.0134523
0.0133754
0.0132993
0.0132243
0.0131508
0.0130793
0.0130104
0.0129425
0.0128758
0.0128103
0.0127472
0.0126883
0.0126307
0.0125722
0.0125149
0.0124588
0.0124057
0.0123537
0.0123025
0.0122524
0.0122039
0.0121567
0.0121106
0.0120656
0.0120217
0.0119789
0.0119372
0.0118967
0.0118573
0.011819
0.0117818
0.0117455
0.0117102
0.0116758
0.0116421
0.0116092
0.0115771
0.0115457
0.0115151
0.0114854
0.0114567
0.0114289
0.0114021
0.0113763
0.0113515
0.0113277
0.0113049
0.0112831
0.0112624
0.0112426
0.0112239
0.0112062
0.0111896
0.011174
0.0111596
0.0111462
0.011134
0.0111229
0.011113
0.0111043
0.0110967
0.0110903
0.0110851
0.0110812
0.0110784
0.0110767
0.0110761
0.0110764
0.0110776
0.0110796
0.0110823
0.0110854
0.011089
0.0110928
0.0110971
0.0111013
0.0111056
0.011109
0.00106725
0.00106825
0.00106885
0.00106892
0.00106879
0.00106764
0.00106618
0.00106325
0.00105924
0.00105494
0.00104778
0.00103837
0.00102787
0.00101592
0.00100291
0.000989327
0.000975473
0.000961575
0.000947839
0.000934385
0.000921388
0.000909008
0.0008974
0.000886667
0.000876896
0.000868119
0.00086036
0.000853644
0.000847969
0.000843381
0.000839861
0.000837387
0.000835983
0.000835594
0.000836359
0.000838151
0.000840829
0.000844626
0.000849292
0.000855162
0.000862457
0.000869212
0.000879375
0.000889621
0.000900942
0.000913922
0.000927385
0.00094273
0.000959573
0.000978148
0.000998682
0.0010214
0.00104662
0.00107472
0.00110618
0.00114158
0.00118164
0.0012272
0.0012794
0.00133917
0.00140845
0.00148899
0.00158256
0.00169406
0.00182455
0.00198016
0.00217136
0.00241356
0.00274167
0.00320828
0.0038895
0.00485723
0.00613503
0.00762457
0.0091367
0.0104965
0.0115791
0.012365
0.0129009
0.0132536
0.0134853
0.0136389
0.0137461
0.0138226
0.013878
0.0139254
0.0139613
0.0139821
0.013995
0.0139957
0.0139802
0.0139478
0.0139
0.0138368
0.0137585
0.0136746
0.0135897
0.0135047
0.0134205
0.0133375
0.0132559
0.0131757
0.0130968
0.0130189
0.0129421
0.0128662
0.0127917
0.0127186
0.0126472
0.0125771
0.0125086
0.0124419
0.0123774
0.0123154
0.0122545
0.0121947
0.0121371
0.0120833
0.0120308
0.011977
0.0119241
0.0118722
0.0118222
0.0117735
0.0117258
0.0116791
0.0116336
0.0115892
0.0115459
0.0115037
0.0114627
0.0114228
0.0113839
0.0113461
0.0113092
0.0112732
0.011238
0.0112034
0.0111695
0.0111362
0.0111037
0.0110721
0.0110414
0.0110117
0.0109829
0.0109553
0.0109286
0.0109029
0.0108783
0.0108547
0.0108321
0.0108106
0.0107901
0.0107707
0.0107522
0.0107349
0.0107187
0.0107036
0.0106896
0.0106767
0.010665
0.0106544
0.010645
0.0106369
0.0106299
0.0106242
0.0106196
0.0106161
0.0106137
0.0106124
0.010612
0.0106123
0.0106134
0.0106151
0.0106173
0.0106199
0.0106229
0.0106256
0.0106285
0.0106297
0.00153946
0.00153853
0.00153679
0.00153453
0.00153208
0.00152924
0.00152617
0.00152252
0.00151806
0.00151236
0.001506
0.00149847
0.00148897
0.00147737
0.00146402
0.00144948
0.00143384
0.00141714
0.00139923
0.0013806
0.00136153
0.00134221
0.00132285
0.00130368
0.0012848
0.00126632
0.00124842
0.00123122
0.00121484
0.00119942
0.00118504
0.00117176
0.00115968
0.00114887
0.00113947
0.00113153
0.001125
0.00112007
0.00111678
0.00111539
0.00111593
0.00111811
0.00112282
0.00112845
0.00113799
0.00114878
0.00116176
0.00117732
0.00119501
0.00121623
0.00124055
0.00126823
0.00129969
0.00133543
0.00137594
0.00142185
0.00147393
0.00153312
0.00160065
0.00167744
0.00176521
0.00186521
0.00197978
0.00211314
0.00226708
0.0024496
0.00267457
0.0029606
0.00333839
0.00385779
0.00457598
0.00553761
0.00672699
0.00803797
0.00931308
0.0104224
0.0112678
0.0118656
0.0122798
0.0125725
0.012785
0.0129497
0.0130898
0.0132143
0.0133262
0.0134243
0.0135037
0.0135646
0.0136078
0.0136282
0.0136237
0.0135954
0.0135459
0.0134769
0.0133914
0.0133016
0.0132123
0.0131246
0.0130391
0.0129561
0.0128753
0.0127964
0.0127191
0.012643
0.0125679
0.0124936
0.0124201
0.0123473
0.0122755
0.0122051
0.0121362
0.0120691
0.0120039
0.0119406
0.0118788
0.0118188
0.0117611
0.0117056
0.0116511
0.0115977
0.0115472
0.0114985
0.0114489
0.0113992
0.0113503
0.0113028
0.0112563
0.011211
0.0111666
0.0111232
0.0110808
0.0110393
0.010999
0.0109597
0.0109212
0.0108836
0.0108467
0.0108103
0.0107743
0.0107388
0.0107039
0.0106698
0.0106367
0.0106045
0.0105733
0.0105431
0.0105139
0.0104858
0.0104586
0.0104325
0.0104074
0.0103833
0.0103602
0.0103381
0.0103171
0.0102971
0.0102782
0.0102603
0.0102436
0.0102279
0.0102134
0.0102
0.0101877
0.0101766
0.0101667
0.010158
0.0101504
0.010144
0.0101386
0.0101342
0.0101307
0.010128
0.0101261
0.0101247
0.0101239
0.0101233
0.010123
0.0101226
0.010122
0.0101189
0.00211777
0.00211249
0.00210594
0.00209911
0.00209204
0.00208474
0.00207731
0.00206967
0.00206167
0.00205312
0.00204362
0.00203364
0.00202308
0.00201087
0.00199688
0.0019814
0.00196478
0.00194652
0.00192682
0.00190612
0.0018844
0.00186167
0.00183822
0.00181431
0.00179013
0.00176581
0.00174151
0.00171742
0.00169369
0.00167041
0.00164775
0.0016259
0.00160504
0.00158532
0.00156692
0.00154999
0.00153475
0.00152153
0.00151044
0.00150171
0.00149546
0.00149178
0.0014909
0.0014929
0.00149739
0.00150692
0.0015184
0.00153345
0.00155203
0.00157478
0.00160188
0.00163362
0.0016704
0.0017127
0.00176104
0.00181599
0.00187837
0.00194922
0.00202961
0.00212064
0.00222315
0.00233823
0.0024694
0.00262005
0.0027961
0.00300567
0.00326021
0.00357783
0.0039877
0.00453091
0.00524616
0.00615078
0.00720455
0.00830919
0.0093418
0.0102078
0.0108105
0.0112133
0.0115153
0.0117623
0.0119707
0.0121648
0.0123604
0.0125546
0.0127374
0.0128962
0.0130255
0.013125
0.0131961
0.0132335
0.0132356
0.0132059
0.0131471
0.0130617
0.0129618
0.012863
0.0127679
0.0126778
0.0125925
0.0125116
0.0124343
0.01236
0.0122878
0.0122172
0.0121475
0.0120783
0.0120093
0.0119397
0.0118696
0.0118006
0.0117331
0.0116672
0.0116029
0.0115403
0.0114794
0.0114204
0.0113634
0.0113082
0.0112545
0.0112027
0.011153
0.0111053
0.0110593
0.0110129
0.0109653
0.0109185
0.0108724
0.0108275
0.0107834
0.0107398
0.0106966
0.0106543
0.010613
0.0105726
0.010533
0.0104942
0.0104559
0.0104177
0.0103797
0.0103419
0.0103045
0.0102679
0.0102321
0.0101972
0.0101633
0.0101304
0.0100984
0.0100675
0.0100375
0.0100084
0.00998033
0.00995323
0.00992709
0.00990193
0.00987775
0.00985457
0.00983239
0.00981124
0.00979112
0.00977206
0.00975406
0.00973715
0.00972135
0.00970667
0.00969313
0.00968071
0.00966939
0.00965915
0.00964993
0.00964167
0.00963428
0.00962766
0.00962171
0.00961628
0.00961126
0.00960644
0.00960174
0.00959671
0.00959125
0.00958222
0.00278522
0.00277209
0.00275958
0.00274651
0.00273321
0.00271989
0.00270666
0.00269353
0.00268044
0.00266725
0.00265355
0.00263969
0.00262578
0.0026111
0.00259509
0.00257794
0.0025596
0.00254008
0.00251921
0.00249718
0.00247415
0.00244955
0.00242397
0.00239771
0.00237076
0.00234315
0.00231517
0.00228699
0.00225873
0.00223059
0.00220267
0.00217519
0.00214834
0.00212234
0.00209739
0.0020738
0.00205204
0.00203237
0.00201502
0.00200025
0.00198828
0.00197935
0.00197369
0.00197149
0.00197307
0.00197885
0.00198985
0.00200406
0.00202279
0.0020465
0.00207552
0.00211021
0.00215099
0.00219833
0.00225273
0.00231476
0.00238494
0.00246416
0.0025536
0.00265446
0.00276758
0.00289552
0.00304159
0.00320893
0.00340254
0.00362984
0.0039019
0.00423579
0.00465663
0.00519214
0.00586646
0.0066744
0.00756649
0.00845884
0.00925834
0.00989795
0.0102829
0.0104908
0.0106405
0.0107996
0.0109957
0.0112427
0.0115269
0.0118237
0.0121037
0.012338
0.0125237
0.0126649
0.0127604
0.0128099
0.0128091
0.0127645
0.0126887
0.0125938
0.0124933
0.0123941
0.0122989
0.0122087
0.0121235
0.0120428
0.0119656
0.0118913
0.011819
0.0117482
0.0116783
0.0116093
0.0115408
0.011473
0.011406
0.0113402
0.0112757
0.0112125
0.0111509
0.0110908
0.0110325
0.0109759
0.0109212
0.0108684
0.0108174
0.0107684
0.0107217
0.0106778
0.0106348
0.0105908
0.0105472
0.0105037
0.0104611
0.0104191
0.0103773
0.0103354
0.0102927
0.0102503
0.0102088
0.0101682
0.0101284
0.0100891
0.0100502
0.0100108
0.00997097
0.00993106
0.0098915
0.00985256
0.0098144
0.0097771
0.00974069
0.0097052
0.00967062
0.00963695
0.00960419
0.00957233
0.00954138
0.00951133
0.00948218
0.00945395
0.00942663
0.00940025
0.00937481
0.00935033
0.00932683
0.00930431
0.00928281
0.00926233
0.0092429
0.00922453
0.00920722
0.00919098
0.00917578
0.00916158
0.00914834
0.00913598
0.00912442
0.00911354
0.00910322
0.0090933
0.00908362
0.00907395
0.00906416
0.00905375
0.00904244
0.00902635
0.00356173
0.00354011
0.00351871
0.00349676
0.00347495
0.00345337
0.00343208
0.00341112
0.00339047
0.00337006
0.00334975
0.00332954
0.00330943
0.00328914
0.00326838
0.003247
0.00322487
0.00320196
0.0031781
0.00315326
0.00312755
0.00310077
0.00307297
0.00304448
0.00301525
0.00298497
0.00295429
0.00292331
0.00289198
0.0028605
0.00282905
0.00279779
0.00276688
0.00273656
0.00270726
0.00267945
0.00265341
0.00262944
0.00260783
0.00258885
0.0025728
0.00256002
0.00255082
0.0025455
0.00254439
0.00254809
0.00255749
0.00257219
0.00259086
0.00261501
0.00264513
0.00268159
0.00272482
0.0027753
0.00283354
0.00290011
0.00297552
0.0030611
0.00315788
0.00326683
0.00338907
0.00352646
0.00368163
0.00385783
0.00405968
0.00429383
0.0045703
0.00490372
0.0053121
0.00581281
0.00641574
0.00710408
0.00783046
0.00852789
0.00912961
0.00959834
0.00989057
0.0100046
0.0100558
0.0101294
0.0102724
0.010502
0.0108002
0.0111321
0.0114619
0.0117589
0.0120057
0.0121922
0.0123152
0.012375
0.0123793
0.0123432
0.0122751
0.012193
0.012105
0.012016
0.0119286
0.0118441
0.0117626
0.011684
0.0116078
0.0115333
0.0114601
0.011388
0.0113165
0.0112458
0.0111756
0.0111062
0.0110375
0.0109697
0.010903
0.0108374
0.0107731
0.0107101
0.0106485
0.0105886
0.0105303
0.0104737
0.0104189
0.0103661
0.0103154
0.0102667
0.0102193
0.0101731
0.010127
0.0100805
0.010035
0.00999008
0.00994585
0.0099023
0.00985951
0.00981768
0.00977685
0.00973693
0.00969775
0.00965906
0.00962032
0.00958008
0.00953865
0.00949703
0.00945574
0.00941505
0.0093751
0.00933596
0.00929764
0.00926018
0.00922356
0.00918777
0.00915283
0.00911872
0.00908544
0.009053
0.00902139
0.00899063
0.00896072
0.00893167
0.00890349
0.0088762
0.00884981
0.00882434
0.00879981
0.00877622
0.0087536
0.00873196
0.0087113
0.00869161
0.00867286
0.00865502
0.00863803
0.00862181
0.00860626
0.00859125
0.00857662
0.00856219
0.00854775
0.00853305
0.00851786
0.00850162
0.00848376
0.0084598
0.00443473
0.00440149
0.0043688
0.00433603
0.0043035
0.00427158
0.00424024
0.00420952
0.00417942
0.00414992
0.00412096
0.00409249
0.00406445
0.0040367
0.00400906
0.00398137
0.00395347
0.00392527
0.00389663
0.00386746
0.00383772
0.00380734
0.00377627
0.00374456
0.00371232
0.00367948
0.00364636
0.00361299
0.00357892
0.00354473
0.00351061
0.00347654
0.00344274
0.00340961
0.00337758
0.00334695
0.00331806
0.00329122
0.00326677
0.00324504
0.00322638
0.00321113
0.00319967
0.00319235
0.00318955
0.00319177
0.00319977
0.00321443
0.00323467
0.00325906
0.00328987
0.00332749
0.00337244
0.00342518
0.00348619
0.00355599
0.00363519
0.0037246
0.00382513
0.00393772
0.00406346
0.00420391
0.0043612
0.0045382
0.00473892
0.00496911
0.00523698
0.00555352
0.00592934
0.00637452
0.00688793
0.00745033
0.00802393
0.00856019
0.00901454
0.00936637
0.00960757
0.0097582
0.00985028
0.00991383
0.0100267
0.0102122
0.0104652
0.0107587
0.0110633
0.0113502
0.0115953
0.0117822
0.0119049
0.0119598
0.0119657
0.0119331
0.0118798
0.0118148
0.0117429
0.0116679
0.0115917
0.0115154
0.0114396
0.0113642
0.0112893
0.0112148
0.0111405
0.0110666
0.0109928
0.0109194
0.0108464
0.0107739
0.0107021
0.0106311
0.010561
0.010492
0.0104241
0.0103576
0.0102925
0.0102289
0.0101669
0.0101065
0.0100479
0.00999106
0.00993601
0.00988265
0.00983067
0.00977982
0.00972993
0.0096802
0.00963029
0.0095811
0.00953275
0.0094853
0.00943878
0.0093932
0.00934851
0.00930461
0.00926135
0.00921849
0.00917564
0.00913241
0.00908905
0.00904592
0.0090033
0.00896133
0.00892009
0.00887962
0.00883995
0.00880108
0.00876299
0.00872569
0.00868917
0.00865342
0.00861844
0.00858423
0.00855079
0.00851812
0.00848624
0.00845514
0.00842484
0.00839534
0.00836666
0.00833881
0.0083118
0.00828564
0.00826034
0.0082359
0.00821233
0.00818959
0.00816767
0.00814651
0.00812604
0.00810618
0.00808681
0.00806776
0.00804887
0.0080299
0.00801058
0.0079906
0.00796963
0.00794703
0.00792174
0.00788876
0.00541234
0.00536419
0.00531742
0.00527143
0.00522598
0.00518137
0.00513764
0.00509485
0.00505303
0.00501215
0.00497219
0.0049331
0.00489481
0.00485725
0.00482029
0.0047838
0.00474764
0.00471172
0.00467589
0.00464006
0.00460416
0.0045681
0.00453182
0.0044953
0.00445857
0.00442165
0.00438462
0.00434758
0.0043105
0.00427371
0.00423683
0.00419989
0.00416351
0.00412802
0.00409369
0.00406084
0.0040298
0.00400093
0.00397456
0.00395104
0.00393074
0.00391403
0.00390128
0.00389284
0.0038891
0.00389052
0.00389763
0.00391105
0.00393037
0.00395634
0.00398836
0.00402597
0.0040714
0.00412481
0.00418646
0.00425688
0.00433662
0.00442627
0.00452649
0.00463806
0.0047619
0.00489925
0.00505182
0.00522195
0.00541293
0.00562938
0.00587676
0.00616134
0.00649136
0.00686913
0.00728821
0.0077315
0.008173
0.00858219
0.00893158
0.00920721
0.00941569
0.00957699
0.00971276
0.00985107
0.0100144
0.010209
0.0104213
0.0106541
0.0108933
0.0111179
0.0113062
0.01144
0.0115208
0.0115569
0.011554
0.0115261
0.0114812
0.011425
0.0113626
0.0112959
0.0112264
0.0111552
0.0110829
0.0110099
0.0109364
0.0108624
0.0107882
0.0107137
0.0106392
0.0105648
0.0104906
0.0104167
0.0103433
0.0102706
0.0101986
0.0101276
0.0100576
0.00998879
0.00992123
0.00985502
0.00979024
0.00972696
0.00966521
0.00960504
0.00954644
0.00948932
0.00943351
0.00937882
0.00932507
0.00927192
0.00921926
0.00916664
0.00911469
0.00906375
0.00901376
0.00896466
0.00891643
0.008869
0.00882229
0.00877613
0.00873033
0.00868481
0.00863967
0.00859506
0.00855108
0.00850781
0.00846529
0.00842353
0.00838254
0.00834231
0.00830283
0.00826409
0.00822608
0.0081888
0.00815223
0.00811638
0.00808123
0.00804679
0.00801305
0.00798002
0.0079477
0.00791609
0.00788521
0.00785504
0.0078256
0.0077969
0.00776892
0.00774167
0.00771513
0.00768927
0.00766407
0.00763945
0.00761534
0.00759163
0.00756818
0.00754482
0.00752133
0.00749742
0.00747276
0.00744697
0.00741954
0.00738975
0.00735591
0.0073118
0.00637443
0.00631115
0.00624985
0.00619001
0.0061313
0.00607357
0.00601712
0.00596198
0.00590815
0.00585561
0.00580434
0.00575429
0.0057054
0.00565761
0.00561082
0.00556493
0.00551983
0.00547541
0.00543156
0.00538819
0.00534521
0.00530254
0.0052601
0.00521786
0.00517581
0.00513398
0.00509241
0.00505118
0.00501035
0.00497005
0.00493055
0.0048917
0.00485317
0.00481545
0.00477908
0.00474438
0.00471168
0.00468134
0.00465369
0.00462909
0.00460787
0.0045904
0.00457702
0.00456799
0.0045637
0.00456453
0.00457088
0.00458317
0.00460157
0.00462649
0.00465779
0.00469566
0.00474129
0.00479418
0.0048544
0.00492322
0.00500091
0.00508785
0.0051845
0.00529138
0.00540922
0.00553894
0.00568182
0.00583969
0.00601503
0.00621067
0.00642953
0.00667705
0.00695675
0.0072679
0.00760312
0.00794846
0.00828641
0.008599
0.00886958
0.0090847
0.00926489
0.00943029
0.00958127
0.00973727
0.00991116
0.0101036
0.0103057
0.0105081
0.0106999
0.0108687
0.0110041
0.0110986
0.0111559
0.0111767
0.0111708
0.0111449
0.0111045
0.0110536
0.0109955
0.010933
0.0108671
0.0107986
0.0107282
0.0106565
0.0105838
0.0105103
0.0104362
0.0103617
0.010287
0.0102123
0.0101377
0.0100633
0.00998939
0.00991598
0.00984323
0.00977126
0.00970017
0.00963008
0.00956107
0.00949322
0.00942661
0.00936129
0.0092973
0.00923465
0.00917335
0.00911333
0.00905449
0.00899669
0.00893974
0.00888345
0.00882753
0.00877174
0.00871625
0.00866187
0.00860853
0.00855598
0.00850433
0.00845359
0.0084037
0.00835455
0.00830605
0.00825816
0.00821089
0.00816429
0.0081184
0.00807323
0.0080288
0.00798511
0.00794215
0.0078999
0.00785836
0.00781752
0.00777736
0.00773786
0.00769902
0.00766082
0.00762326
0.00758634
0.00755004
0.00751436
0.0074793
0.00744485
0.00741102
0.0073778
0.00734518
0.00731316
0.00728173
0.00725089
0.0072206
0.00719083
0.00716154
0.00713266
0.00710409
0.00707572
0.00704739
0.0070189
0.00698998
0.00696031
0.00692949
0.00689704
0.00686226
0.00682425
0.00678059
0.00672169
0.0074087
0.00732783
0.00724966
0.00717368
0.00709946
0.00702671
0.00695557
0.00688614
0.00681838
0.00675227
0.00668776
0.00662484
0.00656344
0.00650351
0.00644498
0.00638776
0.00633176
0.0062769
0.00622309
0.00617025
0.00611829
0.00606713
0.00601665
0.00596684
0.00591772
0.00586929
0.00582162
0.00577478
0.00572882
0.00568395
0.00564032
0.00559818
0.00555712
0.0055166
0.00547716
0.00543965
0.00540444
0.00537184
0.00534217
0.00531574
0.00529287
0.0052739
0.00525914
0.00524888
0.00524344
0.00524309
0.00524794
0.00525836
0.0052747
0.00529727
0.00532624
0.00536181
0.00540443
0.00545413
0.00551112
0.00557578
0.00564841
0.00572929
0.0058187
0.00591697
0.00602454
0.0061421
0.00627041
0.00641054
0.00656369
0.00673269
0.00691842
0.00712276
0.0073491
0.00759481
0.0078542
0.00811736
0.00837251
0.00860916
0.00881982
0.00900084
0.00914447
0.00926806
0.00939886
0.00955215
0.00972992
0.00992348
0.0101162
0.0102927
0.0104519
0.0105865
0.0106901
0.0107622
0.0108016
0.0108147
0.0108064
0.0107812
0.0107431
0.0106952
0.01064
0.0105795
0.0105151
0.0104482
0.0103787
0.0103075
0.010235
0.0101615
0.0100873
0.0100125
0.00993755
0.00986248
0.0097875
0.00971274
0.00963836
0.00956445
0.00949114
0.00941852
0.00934669
0.00927573
0.00920571
0.0091367
0.00906875
0.00900192
0.00893623
0.00887169
0.0088083
0.00874602
0.00868476
0.00862442
0.00856485
0.00850586
0.00844717
0.00838837
0.00832943
0.00827104
0.00821443
0.00815865
0.00810386
0.00805014
0.00799741
0.00794556
0.00789451
0.00784419
0.00779458
0.00774567
0.00769746
0.00764995
0.00760312
0.00755698
0.0075115
0.00746668
0.00742249
0.00737893
0.00733598
0.00729362
0.00725184
0.00721064
0.00716999
0.00712989
0.00709033
0.00705129
0.00701278
0.00697478
0.00693729
0.00690029
0.00686378
0.00682774
0.00679217
0.00675703
0.00672231
0.00668795
0.00665392
0.00662012
0.00658647
0.00655283
0.00651904
0.00648486
0.00645001
0.00641413
0.00637673
0.00633724
0.0062948
0.00624827
0.00619509
0.00612618
0.00863514
0.00853175
0.00843171
0.0083346
0.00824005
0.00814772
0.00805747
0.00796933
0.00788334
0.00779944
0.00771762
0.00763783
0.00756002
0.00748412
0.00741007
0.0073378
0.00726724
0.00719833
0.00713099
0.00706516
0.00700077
0.00693777
0.00687608
0.0068157
0.00675661
0.00669883
0.00664244
0.00658751
0.00653415
0.00648246
0.0064325
0.00638437
0.00633819
0.00629323
0.00624915
0.00620681
0.006167
0.00613014
0.0060965
0.00606632
0.00603988
0.00601745
0.00599928
0.00598565
0.00597677
0.00597282
0.00597398
0.00598049
0.00599263
0.00601064
0.00603474
0.00606509
0.0061019
0.00614527
0.0061953
0.00625211
0.00631582
0.00638659
0.00646447
0.00654955
0.00664194
0.00674169
0.00684904
0.00696478
0.0070899
0.0072256
0.00737291
0.00753315
0.00770241
0.00788344
0.00807209
0.00826289
0.00844936
0.00862528
0.00878672
0.0089328
0.00906571
0.00919185
0.00931417
0.00943004
0.00955773
0.00970125
0.00985484
0.0100081
0.0101501
0.0102661
0.0103512
0.010404
0.0104317
0.0104383
0.0104274
0.0104022
0.0103655
0.0103198
0.0102671
0.0102088
0.0101464
0.0100805
0.0100125
0.00994219
0.00987021
0.009797
0.0097229
0.00964817
0.00957307
0.00949779
0.00942252
0.00934741
0.00927261
0.00919824
0.0091244
0.00905118
0.00897866
0.00890691
0.00883599
0.00876597
0.00869687
0.00862874
0.0085616
0.00849546
0.0084303
0.0083661
0.0083028
0.0082403
0.00817849
0.00811718
0.00805609
0.00799482
0.00793254
0.00787009
0.00780928
0.00775065
0.00769327
0.0076372
0.00758222
0.00752817
0.00747494
0.00742245
0.00737066
0.00731955
0.00726908
0.00721925
0.00717004
0.00712143
0.00707342
0.00702598
0.0069791
0.00693276
0.00688696
0.00684167
0.00679688
0.00675258
0.00670876
0.0066654
0.00662248
0.00658001
0.00653796
0.00649632
0.00645509
0.00641425
0.00637378
0.00633368
0.00629391
0.00625446
0.00621529
0.00617635
0.0061376
0.00609894
0.00606027
0.00602147
0.00598234
0.00594265
0.00590209
0.00586026
0.0058166
0.00577046
0.00572077
0.00566629
0.00560411
0.00552357
0.010037
0.00990553
0.00977831
0.0096549
0.00953493
0.00941804
0.00930395
0.00919252
0.00908373
0.00897757
0.00887404
0.00877306
0.00867456
0.00857849
0.00848479
0.00839339
0.00830425
0.0082173
0.00813252
0.00804986
0.00796928
0.00789073
0.00781419
0.00773968
0.0076672
0.00759681
0.00752852
0.00746238
0.00739846
0.00733679
0.00727741
0.00722041
0.0071659
0.00711363
0.00706268
0.00701311
0.00696611
0.00692251
0.00688254
0.00684639
0.00681424
0.00678631
0.00676281
0.00674391
0.00672973
0.00672019
0.00671536
0.00671553
0.00672093
0.00673176
0.00674819
0.00677032
0.00679825
0.006832
0.00687155
0.00691676
0.00696759
0.00702395
0.00708575
0.00715288
0.00722519
0.00730258
0.00738545
0.00747374
0.0075674
0.00766714
0.00777326
0.00788597
0.00800507
0.00812846
0.00825383
0.00838243
0.00851014
0.00863498
0.00875525
0.00887046
0.00898131
0.00908913
0.00919628
0.0093053
0.00941808
0.00953342
0.00964734
0.00975342
0.00984816
0.00992496
0.00998038
0.0100156
0.0100324
0.0100329
0.0100194
0.00999395
0.00995862
0.00991518
0.00986516
0.00980985
0.00975032
0.00968743
0.00962184
0.00955415
0.0094842
0.00941262
0.00933994
0.00926643
0.00919233
0.00911785
0.0090432
0.00896853
0.008894
0.00881974
0.00874585
0.00867243
0.00859956
0.00852732
0.00845576
0.00838493
0.00831487
0.00824562
0.0081772
0.00810962
0.00804286
0.00797691
0.00791173
0.00784724
0.00778332
0.00771979
0.00765636
0.00759255
0.00752773
0.0074611
0.00739494
0.00733214
0.00727329
0.0072155
0.00715868
0.00710269
0.00704745
0.00699289
0.00693896
0.00688564
0.0068329
0.00678072
0.00672909
0.006678
0.00662742
0.00657735
0.00652776
0.00647865
0.00642999
0.00638177
0.00633397
0.00628658
0.00623959
0.00619297
0.00614672
0.00610082
0.00605526
0.00601002
0.00596508
0.00592044
0.00587608
0.00583197
0.00578809
0.00574442
0.00570092
0.00565753
0.0056142
0.00557084
0.00552736
0.0054836
0.00543938
0.00539446
0.0053485
0.00530109
0.00525158
0.00519927
0.00514285
0.00508102
0.00501001
0.00491681
0.0115226
0.011359
0.0112004
0.0110464
0.0108967
0.010751
0.010609
0.0104706
0.0103355
0.0102037
0.0100751
0.00994961
0.00982725
0.00970792
0.00959158
0.00947816
0.00936762
0.00925992
0.00915507
0.00905304
0.0089538
0.00885732
0.00876362
0.0086727
0.00858453
0.00849912
0.00841646
0.00833653
0.00825938
0.00818504
0.00811356
0.00804499
0.00797941
0.00791691
0.00785634
0.00779729
0.00774079
0.00768772
0.00763858
0.00759349
0.00755259
0.007516
0.00748382
0.00745611
0.00743296
0.00741438
0.00740042
0.00739119
0.00738681
0.00738739
0.00739298
0.00740362
0.00741931
0.00743998
0.00746551
0.00749574
0.00753066
0.00757001
0.00761349
0.00766077
0.00771149
0.00776519
0.00782185
0.00788132
0.00794347
0.00800832
0.00807584
0.00814603
0.00821882
0.0082939
0.00837077
0.0084498
0.00852757
0.00860711
0.00868712
0.00876766
0.00884936
0.00893302
0.00901768
0.0091033
0.00918806
0.00927064
0.00935097
0.00942309
0.00948473
0.00953374
0.00956892
0.00959012
0.00959789
0.00959327
0.00957755
0.0095521
0.00951829
0.0094774
0.00943056
0.0093788
0.00932299
0.0092639
0.00920221
0.00913813
0.00907204
0.00900343
0.00893349
0.00886251
0.00879073
0.00871838
0.00864564
0.00857269
0.00849965
0.00842667
0.00835383
0.00828124
0.00820898
0.00813713
0.00806573
0.00799486
0.00792454
0.00785483
0.00778574
0.00771729
0.00764949
0.00758232
0.00751575
0.00744971
0.00738407
0.00731861
0.0072529
0.00718624
0.00711802
0.00704737
0.00697726
0.00691131
0.00685115
0.00679212
0.00673373
0.00667599
0.00661885
0.00656227
0.00650623
0.00645071
0.00639569
0.00634116
0.00628712
0.00623354
0.00618042
0.00612773
0.00607548
0.00602363
0.00597218
0.0059211
0.00587038
0.00582001
0.00576997
0.00572024
0.0056708
0.00562165
0.00557277
0.00552413
0.00547574
0.00542756
0.00537958
0.00533178
0.00528413
0.0052366
0.00518917
0.00514177
0.00509434
0.00504681
0.00499906
0.00495096
0.00490232
0.0048529
0.00480235
0.00475024
0.00469587
0.00463851
0.00457662
0.00450885
0.00443046
0.00432476
0.0128853
0.0126883
0.0124967
0.0123105
0.0121295
0.0119533
0.0117818
0.0116148
0.0114521
0.0112935
0.0111389
0.0109882
0.0108413
0.0106981
0.0105586
0.0104227
0.0102904
0.0101616
0.0100364
0.00991476
0.00979649
0.00968164
0.00957016
0.00946202
0.0093572
0.00925566
0.00915741
0.00906245
0.0089708
0.00888247
0.0087975
0.00871595
0.00863791
0.00856348
0.00849234
0.0084233
0.00835614
0.008292
0.00823196
0.00817627
0.00812498
0.00807814
0.00803579
0.00799794
0.00796458
0.00793539
0.00791044
0.00788986
0.00787372
0.0078621
0.00785499
0.00785238
0.0078542
0.00786031
0.0078705
0.00788447
0.00790214
0.00792321
0.00794733
0.00797411
0.00800312
0.00803396
0.00806626
0.00809969
0.008134
0.00816901
0.00820463
0.00824087
0.00827776
0.00831541
0.00835405
0.00839405
0.00843568
0.00847958
0.00852633
0.00857596
0.00862815
0.00868227
0.00873843
0.00879638
0.00885424
0.00891018
0.00896242
0.0090089
0.00904794
0.00907831
0.00909926
0.00911051
0.00911219
0.0091047
0.00908868
0.00906485
0.00903404
0.00899704
0.00895466
0.00890765
0.00885671
0.00880248
0.00874552
0.00868631
0.00862528
0.00856213
0.00849617
0.00842858
0.00836004
0.00829073
0.00822084
0.00815052
0.00807991
0.00800913
0.00793828
0.00786745
0.00779671
0.00772614
0.00765579
0.00758572
0.00751598
0.00744661
0.00737763
0.00730909
0.00724098
0.0071733
0.00710602
0.00703906
0.00697223
0.00690517
0.00683727
0.00676798
0.00669705
0.00662347
0.00655099
0.00648391
0.00642292
0.00636255
0.00630278
0.00624355
0.00618478
0.00612648
0.00606862
0.00601119
0.0059542
0.00589763
0.00584149
0.00578577
0.00573046
0.00567554
0.00562101
0.00556684
0.00551304
0.00545957
0.00540642
0.00535359
0.00530105
0.00524879
0.00519679
0.00514505
0.00509354
0.00504225
0.00499117
0.00494028
0.00488955
0.00483898
0.00478854
0.0047382
0.00468791
0.00463764
0.00458733
0.00453689
0.00448622
0.00443519
0.00438362
0.00433127
0.00427779
0.00422277
0.00416546
0.00410515
0.00404016
0.00396904
0.00388605
0.0037708
0.0137329
0.0135068
0.0132875
0.0130747
0.0128682
0.0126676
0.0124727
0.0122833
0.0120992
0.0119201
0.0117458
0.0115763
0.0114113
0.0112507
0.0110945
0.0109425
0.0107947
0.010651
0.0105113
0.0103755
0.0102437
0.0101156
0.00999135
0.0098708
0.00975393
0.0096407
0.0095311
0.0094251
0.0093227
0.00922391
0.00912874
0.00903721
0.00894938
0.00886531
0.00878502
0.00870847
0.00863431
0.00856201
0.00849266
0.00842713
0.00836586
0.00830886
0.00825612
0.00820761
0.00816333
0.00812322
0.00808727
0.00805544
0.00802775
0.00800417
0.00798466
0.00796915
0.00795754
0.0079497
0.00794542
0.00794449
0.00794662
0.00795151
0.00795881
0.00796814
0.0079791
0.00799127
0.00800428
0.00801778
0.00803151
0.00804527
0.00805897
0.00807264
0.00808642
0.00810055
0.00811534
0.00813116
0.00814846
0.00816768
0.00818915
0.00821303
0.00823948
0.00826834
0.00829922
0.00833145
0.00836409
0.00839608
0.00842626
0.00845344
0.00847653
0.0084946
0.00850693
0.00851302
0.00851263
0.00850571
0.00849242
0.00847303
0.00844791
0.00841753
0.00838237
0.00834292
0.0082997
0.00825319
0.00820385
0.00815212
0.00809845
0.00804346
0.00798584
0.00792494
0.00786169
0.0077974
0.00773217
0.00766618
0.00759956
0.00753244
0.00746493
0.00739713
0.00732913
0.00726101
0.00719283
0.00712467
0.00705657
0.00698859
0.00692076
0.00685311
0.00678567
0.00671843
0.00665135
0.00658429
0.006517
0.00644902
0.00637961
0.0063085
0.00623581
0.00616094
0.00608783
0.00602094
0.00595984
0.00589883
0.00583822
0.005778
0.00571818
0.00565874
0.00559968
0.005541
0.0054827
0.0054248
0.0053673
0.00531019
0.00525347
0.00519714
0.00514117
0.00508558
0.00503033
0.00497543
0.00492084
0.00486658
0.00481261
0.00475894
0.00470555
0.00465242
0.00459955
0.00454692
0.00449453
0.00444235
0.00439038
0.0043386
0.00428697
0.00423549
0.00418411
0.00413279
0.00408147
0.00403007
0.00397851
0.00392665
0.00387433
0.00382131
0.00376726
0.0037118
0.00365413
0.00359357
0.00352841
0.00345677
0.0033717
0.0032538
0.0134609
0.0132287
0.0130033
0.0127846
0.0125723
0.0123663
0.0121663
0.0119722
0.0117838
0.0116008
0.0114232
0.0112507
0.0110832
0.0109205
0.0107624
0.0106089
0.0104597
0.0103149
0.0101742
0.0100377
0.00990509
0.00977642
0.0096516
0.00953054
0.00941319
0.0092995
0.00918942
0.00908292
0.00897997
0.00888056
0.00878469
0.00869235
0.00860357
0.00851837
0.00843677
0.00835882
0.00828456
0.00821419
0.0081474
0.00808274
0.00801961
0.00795907
0.00790241
0.00784988
0.00780102
0.0077557
0.00771396
0.00767584
0.00764133
0.0076104
0.00758301
0.00755912
0.00753863
0.00752144
0.0075074
0.00749635
0.00748805
0.00748227
0.00747872
0.00747709
0.00747703
0.00747821
0.00748027
0.00748289
0.00748579
0.00748874
0.00749157
0.00749423
0.00749672
0.00749916
0.00750178
0.00750486
0.00750874
0.00751374
0.00752018
0.00752831
0.00753832
0.00755028
0.00756412
0.00757957
0.00759621
0.00761345
0.00763056
0.00764678
0.00766133
0.00767347
0.00768255
0.00768807
0.0076896
0.0076869
0.00767982
0.00766834
0.0076525
0.00763246
0.00760841
0.0075806
0.00754929
0.00751478
0.00747739
0.00743742
0.00739522
0.00735115
0.00730546
0.00725813
0.00720753
0.00715228
0.00709558
0.00703764
0.00697855
0.00691848
0.00685754
0.00679586
0.00673354
0.00667069
0.00660738
0.00654371
0.00647974
0.00641555
0.00635118
0.00628668
0.00622208
0.00615739
0.00609252
0.00602726
0.00596125
0.00589398
0.00582502
0.00575401
0.00567937
0.0056059
0.005538
0.00547637
0.00541504
0.00535426
0.00529402
0.00523421
0.00517477
0.00511567
0.00505691
0.00499851
0.00494048
0.00488284
0.0048256
0.00476876
0.00471233
0.0046563
0.00460067
0.00454543
0.00449057
0.00443609
0.00438198
0.00432823
0.00427485
0.00422182
0.00416913
0.00411678
0.00406475
0.00401306
0.00396168
0.00391062
0.00385987
0.00380938
0.00375916
0.00370919
0.00365944
0.00360986
0.00356039
0.00351095
0.00346146
0.00341178
0.00336176
0.00331118
0.00325972
0.00320705
0.00315231
0.00309481
0.00303327
0.00296396
0.00288591
0.00276473
0.0117468
0.0115387
0.0113374
0.0111427
0.0109543
0.010772
0.0105955
0.0104245
0.010259
0.0100986
0.00994329
0.00979277
0.00964689
0.0095055
0.00936843
0.00923555
0.00910671
0.00898178
0.00886064
0.00874317
0.00862927
0.00851884
0.00841178
0.00830802
0.00820748
0.00811009
0.00801578
0.00792451
0.00783621
0.00775087
0.00766844
0.0075889
0.00751223
0.00743843
0.00736749
0.00729941
0.00723419
0.00717186
0.00711241
0.00705578
0.00700215
0.00695191
0.00690482
0.00685925
0.00681455
0.00677184
0.00673241
0.00669633
0.00666325
0.0066331
0.00660584
0.00658143
0.0065598
0.00654089
0.00652464
0.00651096
0.00649973
0.00649081
0.00648404
0.00647921
0.00647611
0.00647451
0.00647416
0.00647483
0.00647626
0.00647825
0.00648061
0.00648321
0.00648595
0.00648882
0.00649185
0.00649514
0.00649883
0.00650312
0.00650822
0.00651431
0.00652156
0.00653009
0.00653991
0.00655095
0.00656305
0.00657594
0.00658927
0.00660264
0.00661559
0.00662766
0.0066384
0.00664736
0.00665417
0.0066585
0.00666007
0.0066587
0.00665424
0.00664663
0.00663585
0.00662193
0.00660495
0.00658502
0.00656229
0.00653692
0.00650912
0.0064791
0.00644711
0.0064134
0.0063782
0.00634147
0.00630101
0.00625505
0.00620731
0.00615814
0.00610758
0.0060558
0.00600289
0.00594896
0.00589413
0.00583848
0.00578211
0.0057251
0.00566753
0.00560946
0.00555095
0.00549202
0.00543262
0.00537259
0.00531167
0.00524955
0.00518598
0.00512053
0.00505276
0.00498395
0.00491788
0.00485832
0.00480029
0.00474265
0.00468542
0.0046285
0.00457181
0.00451537
0.0044592
0.00440335
0.00434785
0.00429271
0.00423795
0.00418358
0.00412961
0.00407605
0.00402289
0.00397012
0.00391774
0.00386576
0.00381419
0.00376304
0.00371231
0.00366197
0.00361201
0.00356246
0.00351332
0.0034646
0.00341629
0.00336839
0.00332087
0.00327373
0.00322694
0.00318047
0.00313428
0.00308832
0.00304253
0.00299684
0.00295117
0.0029054
0.00285939
0.00281294
0.00276576
0.00271756
0.00266731
0.00261429
0.00255871
0.0024974
0.00242662
0.00230289
0.00973134
0.00955963
0.00939358
0.00923314
0.00907816
0.00892841
0.00878369
0.00864381
0.00850858
0.00837782
0.00825135
0.00812901
0.00801064
0.00789607
0.00778518
0.00767781
0.00757385
0.00747317
0.00737566
0.0072812
0.0071897
0.00710106
0.00701519
0.00693202
0.00685146
0.00677346
0.00669794
0.00662485
0.00655414
0.00648578
0.00641972
0.00635593
0.00629438
0.00623507
0.00617797
0.00612308
0.00607041
0.00601995
0.00597172
0.00592573
0.00588202
0.00584063
0.00580156
0.00576469
0.00573012
0.00569824
0.0056694
0.00564172
0.00561451
0.00558866
0.00556461
0.0055428
0.00552313
0.00550547
0.00548986
0.00547632
0.00546479
0.0054552
0.00544747
0.00544152
0.00543722
0.00543445
0.00543306
0.00543291
0.00543385
0.00543572
0.0054384
0.00544173
0.00544561
0.00544997
0.00545473
0.00545991
0.0054655
0.00547157
0.00547818
0.00548543
0.00549339
0.00550215
0.00551174
0.00552218
0.0055334
0.00554532
0.00555777
0.00557053
0.00558336
0.00559598
0.00560807
0.00561935
0.00562951
0.00563828
0.00564541
0.00565068
0.00565391
0.00565496
0.0056537
0.00565007
0.00564402
0.00563554
0.00562466
0.00561141
0.00559587
0.00557814
0.00555834
0.00553663
0.00551319
0.00548823
0.00546194
0.00543427
0.00540271
0.00536523
0.00532595
0.00528513
0.00524278
0.00519905
0.00515405
0.00510787
0.00506062
0.00501239
0.00496326
0.00491331
0.00486262
0.00481125
0.00475923
0.00470653
0.00465308
0.00459866
0.00454286
0.00448531
0.00442579
0.00436383
0.00430266
0.0042448
0.004191
0.00413837
0.00408582
0.00403337
0.00398096
0.00392863
0.00387645
0.00382451
0.00377284
0.00372147
0.00367042
0.00361971
0.00356934
0.00351935
0.00346965
0.00342029
0.00337131
0.00332273
0.00327457
0.00322684
0.00317955
0.00313271
0.00308629
0.0030403
0.00299473
0.00294957
0.00290481
0.00286046
0.00281648
0.00277288
0.00272963
0.0026867
0.00264403
0.00260158
0.00255929
0.00251713
0.00247499
0.00243281
0.00239047
0.00234774
0.00230443
0.00226012
0.00221348
0.002166
0.00211644
0.00206129
0.00199827
0.00187552
0.00766557
0.00753276
0.00740513
0.00728232
0.00716405
0.00705008
0.0069402
0.0068342
0.00673191
0.00663316
0.00653781
0.00644569
0.00635667
0.00627063
0.00618743
0.00610698
0.00602914
0.00595382
0.00588093
0.00581037
0.00574206
0.00567591
0.00561185
0.00554981
0.00548972
0.00543153
0.00537518
0.00532061
0.00526779
0.00521666
0.0051672
0.00511938
0.00507316
0.00502852
0.00498544
0.00494392
0.00490393
0.00486549
0.00482858
0.00479321
0.0047594
0.00472715
0.00469647
0.00466737
0.00463989
0.00461408
0.00459002
0.00456752
0.00454653
0.00452732
0.0045108
0.00449543
0.00447997
0.00446497
0.0044508
0.00443837
0.00442768
0.00441832
0.0044104
0.00440389
0.00439873
0.00439482
0.00439214
0.00439061
0.0043902
0.00439085
0.00439248
0.00439501
0.00439837
0.00440247
0.00440724
0.00441263
0.00441861
0.00442514
0.00443221
0.00443983
0.004448
0.00445674
0.00446606
0.00447594
0.00448636
0.00449727
0.00450859
0.00452022
0.00453202
0.00454385
0.00455554
0.00456691
0.00457778
0.00458797
0.00459729
0.00460558
0.00461267
0.00461842
0.00462269
0.00462539
0.00462641
0.00462568
0.00462316
0.00461881
0.00461261
0.00460458
0.00459475
0.00458317
0.00456992
0.00455512
0.0045389
0.0045214
0.0045027
0.00448346
0.00446077
0.00443232
0.00440138
0.00436915
0.00433539
0.00430028
0.00426389
0.00422631
0.00418761
0.00414788
0.00410717
0.00406557
0.00402316
0.00397998
0.00393606
0.00389139
0.00384586
0.00379923
0.00375123
0.00370147
0.00364971
0.00359832
0.00354837
0.00350022
0.00345436
0.00340873
0.00336298
0.00331707
0.00327107
0.00322516
0.00317943
0.00313392
0.00308863
0.00304361
0.00299886
0.0029544
0.00291025
0.0028664
0.00282288
0.0027797
0.00273687
0.00269441
0.00265231
0.00261058
0.00256921
0.00252818
0.00248749
0.00244714
0.00240713
0.00236745
0.0023281
0.00228907
0.00225034
0.00221191
0.00217364
0.00213554
0.00209759
0.00205977
0.00202198
0.00198421
0.00194639
0.00190808
0.00186953
0.00182942
0.00178994
0.00174814
0.00170347
0.00165596
0.00160308
0.00148873
0.00575308
0.00565959
0.00556936
0.00548234
0.00539858
0.00531793
0.00524025
0.00516542
0.00509329
0.00502375
0.00495667
0.00489194
0.00482946
0.00476911
0.0047108
0.00465445
0.00459997
0.00454728
0.0044963
0.00444697
0.00439922
0.004353
0.00430823
0.00426487
0.00422287
0.00418218
0.00414277
0.00410459
0.00406762
0.00403181
0.00399715
0.0039636
0.00393115
0.00389977
0.00386946
0.00384019
0.00381197
0.00378478
0.00375863
0.00373352
0.00370944
0.00368641
0.00366442
0.0036435
0.00362364
0.0036049
0.00358727
0.00357076
0.00355537
0.00354116
0.00352823
0.00351653
0.00350566
0.00349525
0.00348578
0.00347764
0.00346982
0.00346145
0.00345397
0.00344725
0.00344133
0.00343622
0.003432
0.00342853
0.00342593
0.00342426
0.0034235
0.00342364
0.00342466
0.00342648
0.00342908
0.00343242
0.00343646
0.00344115
0.00344646
0.00345234
0.00345877
0.00346572
0.00347315
0.00348104
0.00348933
0.00349797
0.00350691
0.00351608
0.00352538
0.00353475
0.00354407
0.00355326
0.00356222
0.00357083
0.003579
0.00358662
0.0035936
0.00359984
0.00360524
0.00360972
0.00361322
0.00361564
0.00361695
0.00361707
0.00361596
0.0036136
0.00360996
0.00360504
0.00359884
0.00359139
0.00358274
0.00357295
0.00356211
0.00355034
0.00353773
0.00352569
0.00351099
0.00349146
0.00346826
0.0034444
0.00341929
0.00339293
0.00336545
0.00333687
0.00330723
0.00327662
0.00324514
0.00321284
0.00317981
0.00314607
0.00311165
0.00307644
0.00304038
0.00300341
0.00296552
0.0029268
0.00288724
0.00284659
0.00280586
0.00276705
0.00273021
0.00269278
0.00265516
0.00261755
0.00258
0.00254252
0.00250513
0.00246784
0.00243065
0.0023936
0.0023567
0.00231997
0.00228343
0.00224708
0.00221095
0.00217505
0.00213938
0.00210396
0.00206875
0.00203372
0.00199891
0.00196432
0.00192997
0.00189587
0.00186201
0.00182841
0.00179506
0.00176195
0.00172904
0.00169633
0.00166376
0.00163134
0.00159891
0.00156663
0.00153439
0.00150123
0.00146879
0.0014359
0.00140175
0.0013673
0.00132944
0.00128981
0.00124709
0.00114525
0.00414909
0.00408603
0.00402589
0.00396833
0.00391312
0.00386012
0.00380919
0.00376019
0.00371303
0.0036676
0.00362381
0.00358158
0.00354082
0.00350148
0.00346347
0.00342673
0.00339121
0.00335685
0.00332359
0.00329139
0.00326021
0.00323001
0.00320071
0.0031723
0.00314474
0.00311802
0.0030921
0.00306695
0.00304255
0.00301888
0.00299591
0.00297362
0.00295201
0.00293104
0.00291072
0.00289102
0.00287195
0.00285349
0.00283564
0.00281839
0.00280174
0.00278569
0.00277022
0.00275534
0.00274106
0.00272736
0.00271427
0.00270178
0.00268991
0.00267866
0.00266808
0.00265818
0.00264888
0.00264002
0.00263158
0.0026238
0.00261639
0.00260943
0.00260309
0.0025985
0.00259445
0.00258919
0.00258397
0.00257899
0.00257413
0.00257
0.00256649
0.00256382
0.00256203
0.00256083
0.00256035
0.00256059
0.00256141
0.00256289
0.00256499
0.00256767
0.00257089
0.00257462
0.00257884
0.00258348
0.0025885
0.00259381
0.00259935
0.00260505
0.00261084
0.00261666
0.00262245
0.00262815
0.0026337
0.00263905
0.00264415
0.00264896
0.00265344
0.00265753
0.00266119
0.0026644
0.00266709
0.00266925
0.00267083
0.00267179
0.0026721
0.00267172
0.00267063
0.0026688
0.00266622
0.00266287
0.00265875
0.00265388
0.00264828
0.00264198
0.00263503
0.00262757
0.00261953
0.00261076
0.00260278
0.00259275
0.00257834
0.00256178
0.00254484
0.00252685
0.00250778
0.00248786
0.00246717
0.00244579
0.00242377
0.00240115
0.00237795
0.00235414
0.00232978
0.0023047
0.00227895
0.00225194
0.00222448
0.00219631
0.00216763
0.00213907
0.00211123
0.00208315
0.00205487
0.00202648
0.00199802
0.00196948
0.00194086
0.00191216
0.00188339
0.00185458
0.00182573
0.00179689
0.00176806
0.00173927
0.00171053
0.00168187
0.0016533
0.00162485
0.00159652
0.0015683
0.00154021
0.00151226
0.00148446
0.00145683
0.00142937
0.0014021
0.00137501
0.00134812
0.0013214
0.00129489
0.00126849
0.00124222
0.00121591
0.00119004
0.00116388
0.00113808
0.0011118
0.00108585
0.00105845
0.00103175
0.00100183
0.000971029
0.000938509
0.000852288
0.00283117
0.00279431
0.00275885
0.00272455
0.00269155
0.00265987
0.00262944
0.00260017
0.00257198
0.00254482
0.00251864
0.00249339
0.00246901
0.00244547
0.00242271
0.00240069
0.00237937
0.00235872
0.00233871
0.00231931
0.00230057
0.00228235
0.00226456
0.00224724
0.00223047
0.00221424
0.00219845
0.00218311
0.00216819
0.00215368
0.00213957
0.00212585
0.00211251
0.00209954
0.00208695
0.00207471
0.00206283
0.00205131
0.00204013
0.00202927
0.00201874
0.00200851
0.00199858
0.00198893
0.00197958
0.00197051
0.00196174
0.00195326
0.00194507
0.00193719
0.00192967
0.00192241
0.0019155
0.0019084
0.00190121
0.00189419
0.0018873
0.00188052
0.00187385
0.00186758
0.0018618
0.00185625
0.00185071
0.00184536
0.00184136
0.00183803
0.0018339
0.00182948
0.00182597
0.00182223
0.00181965
0.00181719
0.00181468
0.00181296
0.00181187
0.00181123
0.00181105
0.00181139
0.00181218
0.00181337
0.00181491
0.00181673
0.00181876
0.00182092
0.00182316
0.00182541
0.00182764
0.00182979
0.00183184
0.00183376
0.00183553
0.00183714
0.00183859
0.00183985
0.00184094
0.00184184
0.00184254
0.00184306
0.00184337
0.00184348
0.00184337
0.00184302
0.00184242
0.00184156
0.00184042
0.00183898
0.00183724
0.00183518
0.00183279
0.00183006
0.001827
0.00182362
0.00181993
0.00181589
0.00181177
0.00180741
0.00180301
0.00179898
0.00179352
0.00178491
0.00177397
0.00176297
0.00175155
0.00173969
0.0017275
0.00171483
0.00170172
0.001688
0.00167405
0.00165889
0.00164384
0.00162735
0.00161054
0.00159324
0.00157565
0.00155744
0.00153913
0.00151956
0.00150021
0.00148062
0.00146083
0.00144084
0.00142066
0.00140027
0.00137971
0.00135899
0.00133812
0.00131714
0.00129606
0.00127491
0.00125371
0.00123248
0.00121124
0.00119001
0.00116881
0.00114765
0.00112656
0.00110554
0.0010846
0.00106377
0.00104305
0.00102247
0.00100202
0.00098174
0.000961567
0.000941605
0.000921739
0.000901716
0.000882008
0.000863005
0.00084378
0.0008247
0.000805183
0.000786324
0.000766096
0.000747025
0.00072496
0.000703815
0.000680597
0.000612503
0.00184478
0.00182341
0.0018033
0.00178422
0.00176602
0.00174859
0.00173202
0.001716
0.00170043
0.0016854
0.00167102
0.00165712
0.00164366
0.00163063
0.001618
0.00160574
0.00159384
0.00158228
0.00157104
0.0015601
0.00154946
0.0015391
0.001529
0.00151914
0.00150951
0.00150012
0.00149096
0.001482
0.00147325
0.00146469
0.00145632
0.00144813
0.00144012
0.00143228
0.00142461
0.0014171
0.00140974
0.00140255
0.00139547
0.00138847
0.00138152
0.00137462
0.00136776
0.00136093
0.00135413
0.00134735
0.00134066
0.00133394
0.00132729
0.00132062
0.00131427
0.00130751
0.00130105
0.00129468
0.00128832
0.00128199
0.0012757
0.00126945
0.00126323
0.00125709
0.00125112
0.00124532
0.00123967
0.00123416
0.00122876
0.00122393
0.00121943
0.001215
0.00121081
0.00120692
0.00120355
0.00120051
0.00119833
0.00119588
0.00119366
0.0011913
0.00118896
0.00118755
0.00118619
0.0011852
0.00118454
0.00118415
0.00118397
0.00118393
0.00118399
0.0011841
0.00118422
0.00118432
0.00118438
0.0011844
0.00118435
0.00118425
0.0011841
0.00118392
0.0011837
0.00118346
0.00118321
0.00118295
0.0011827
0.00118246
0.00118222
0.00118199
0.00118175
0.00118151
0.00118126
0.00118099
0.0011807
0.00118035
0.00117994
0.00117943
0.0011788
0.00117802
0.00117714
0.00117601
0.00117474
0.00117346
0.00117204
0.00117063
0.00116948
0.00116676
0.00116459
0.00116133
0.00115645
0.00115127
0.00114612
0.0011402
0.00113429
0.00112741
0.0011202
0.00111247
0.00110428
0.00109535
0.00108645
0.00107674
0.00106663
0.001056
0.00104489
0.00103306
0.00102122
0.00100905
0.000996591
0.000983877
0.000970909
0.00095771
0.00094429
0.000930673
0.000916873
0.000902918
0.000888828
0.000874625
0.000860329
0.00084596
0.000831536
0.000817079
0.000802605
0.000788133
0.000773679
0.000759258
0.000744883
0.000730564
0.000716323
0.00070219
0.000688152
0.000674248
0.000660416
0.000646667
0.000633148
0.000619334
0.000606552
0.000593585
0.000580507
0.000567802
0.000554756
0.000542341
0.000528894
0.000516604
0.000501769
0.000489055
0.000474315
0.000424151
0.00107867
0.00106958
0.00106105
0.00105271
0.00104456
0.00103664
0.00102897
0.00102151
0.00101426
0.0010072
0.00100033
0.00099365
0.000987144
0.000980808
0.000974631
0.00096861
0.000962735
0.000957002
0.000951403
0.000945934
0.000940589
0.000935361
0.000930244
0.000925233
0.000920322
0.000915508
0.000910788
0.000906159
0.000901617
0.00089716
0.000892783
0.000888484
0.000884262
0.000880111
0.000876035
0.000872022
0.000868081
0.000864237
0.000860243
0.000856104
0.000851827
0.000847455
0.000842986
0.000838446
0.000833828
0.000829141
0.000824583
0.000819598
0.000814766
0.000809859
0.000804924
0.000799932
0.000794911
0.000789876
0.00078483
0.00077978
0.000774741
0.000769719
0.000764713
0.000759738
0.000754811
0.000749958
0.000745263
0.000740681
0.000736193
0.000731944
0.000727895
0.000724091
0.000720408
0.00071701
0.00071367
0.00071079
0.000708047
0.000706279
0.000704365
0.000702766
0.000701043
0.000699559
0.000698257
0.000697118
0.000696157
0.000695352
0.000694687
0.00069413
0.000693657
0.00069324
0.000692859
0.000692495
0.000692142
0.000691792
0.000691444
0.00069114
0.000690865
0.000690644
0.000690471
0.000690373
0.000690328
0.000690359
0.000690478
0.000690679
0.000690937
0.000691281
0.000691703
0.000692191
0.000692783
0.000693446
0.000694152
0.000694916
0.000695686
0.000696357
0.000697004
0.000697453
0.000698059
0.0006982
0.000698219
0.000698551
0.00069898
0.000698619
0.000699163
0.000698401
0.000698804
0.000698811
0.000697488
0.000696066
0.000694328
0.000692146
0.000690006
0.000687122
0.000684291
0.000680607
0.000676948
0.000672493
0.00066802
0.000662894
0.00065763
0.000652012
0.000646039
0.000639704
0.000633188
0.000626428
0.000619394
0.000612165
0.000604702
0.000597068
0.000589232
0.000581243
0.000573092
0.000564818
0.000556431
0.000547954
0.000539401
0.000530785
0.000522119
0.000513414
0.000504686
0.000495945
0.000487206
0.000478477
0.00046977
0.000461085
0.000452483
0.000443971
0.000435523
0.000427176
0.000418935
0.000410798
0.000403038
0.000394715
0.000387184
0.000379674
0.000371946
0.000364572
0.000357059
0.000349846
0.000342235
0.000335116
0.00032678
0.000319571
0.000311514
0.000278405
0.000566301
0.000561306
0.000556466
0.000551838
0.000547382
0.000543107
0.000538957
0.000534961
0.000531069
0.000527312
0.000523644
0.000520097
0.000516628
0.000513268
0.000509974
0.000506779
0.000503642
0.000500589
0.000497587
0.000494657
0.000491771
0.000488929
0.000486127
0.000483364
0.000480639
0.000477949
0.000475291
0.000472665
0.000470065
0.000467492
0.000464938
0.000462404
0.00045989
0.000457388
0.000454908
0.000452417
0.000449985
0.000447554
0.00044527
0.000442826
0.000440309
0.000437871
0.000435376
0.000432861
0.0004303
0.000427692
0.00042509
0.000422448
0.000419768
0.000417084
0.0004144
0.00041172
0.000409045
0.000406382
0.000403737
0.000401113
0.000398528
0.000395979
0.000393482
0.000391029
0.00038863
0.000386282
0.000383994
0.00038179
0.000379645
0.000377567
0.000375302
0.000373702
0.000372108
0.000370717
0.000369326
0.000368072
0.000367094
0.000366357
0.000365804
0.000365354
0.000365033
0.000364813
0.000364676
0.000364584
0.00036453
0.000364534
0.000364564
0.000364636
0.000364712
0.000364812
0.000364912
0.000365012
0.000365128
0.000365233
0.000365368
0.000365471
0.000365615
0.000365697
0.000365881
0.000366092
0.000366452
0.000366959
0.000367482
0.00036806
0.000368676
0.000369413
0.000370223
0.000371078
0.000372055
0.000373063
0.000373985
0.000375039
0.000376011
0.000376472
0.000377333
0.000377408
0.000378258
0.000379046
0.000379429
0.000379357
0.000380258
0.000380397
0.000380527
0.000380633
0.000380801
0.00038083
0.000380635
0.000380296
0.000379748
0.000379024
0.000378062
0.000376934
0.000375563
0.000374041
0.000372246
0.00037032
0.000368095
0.00036579
0.000363159
0.000360524
0.000357522
0.000354564
0.000351258
0.000348007
0.000344435
0.000340921
0.000337123
0.000333369
0.00032938
0.00032539
0.000321255
0.000317084
0.000312844
0.000308563
0.000304245
0.000299897
0.000295523
0.000291129
0.000286726
0.000282317
0.000277913
0.000273516
0.000269139
0.000264779
0.000260454
0.00025616
0.000251911
0.000247703
0.00024356
0.000239459
0.000235458
0.000231468
0.000227552
0.0002239
0.000219945
0.000216365
0.000212737
0.000209065
0.000205595
0.000201804
0.000198348
0.000194206
0.000190686
0.000169829
0.000210308
0.000208867
0.000207406
0.000206091
0.00020464
0.000203418
0.00020206
0.000200954
0.000199718
0.000198736
0.000197624
0.000196757
0.000195758
0.000194993
0.000194093
0.000193414
0.000192597
0.000191979
0.000191235
0.000190651
0.000189979
0.000189341
0.000188715
0.000188111
0.000187527
0.000186959
0.000186405
0.000185865
0.000185333
0.000184811
0.000184284
0.000183773
0.000183269
0.000182768
0.000182267
0.000181767
0.000181264
0.000180755
0.000180242
0.000179727
0.00017921
0.000178685
0.000178176
0.000177669
0.000177174
0.000176705
0.000176188
0.000175682
0.000175228
0.000174782
0.00017435
0.000173946
0.00017356
0.000173205
0.000172879
0.000172584
0.000172333
0.000172113
0.000171947
0.0001718
0.000171685
0.000171604
0.00017152
0.00017149
0.000171508
0.000171541
0.000171592
0.000171718
0.000171943
0.000172182
0.000172528
0.000172788
0.000173205
0.000173539
0.000173961
0.000174363
0.000174721
0.00017523
0.000175494
0.000175784
0.00017592
0.00017619
0.000176311
0.000176428
0.000176444
0.000176453
0.000176419
0.000176339
0.000176307
0.000176168
0.000176165
0.000176056
0.000176153
0.000175923
0.000176
0.000175731
0.000175741
0.000176351
0.000176616
0.000176926
0.000176883
0.000177023
0.000177246
0.000177439
0.000177588
0.000177731
0.000177817
0.000177887
0.000177931
0.000177897
0.000177804
0.000177582
0.000177336
0.000177047
0.000176707
0.000176282
0.00017584
0.000175316
0.000174759
0.000174177
0.000173596
0.000173034
0.000172395
0.000171848
0.000171087
0.000170497
0.000169578
0.000168852
0.000167796
0.000166934
0.000165801
0.000164728
0.000163524
0.000162279
0.000160995
0.000159672
0.000158312
0.000156916
0.000155483
0.000154017
0.000152517
0.000150987
0.000149426
0.000147838
0.000146224
0.000144586
0.000142926
0.000141247
0.000139553
0.000137847
0.000136131
0.000134407
0.000132678
0.000130944
0.00012921
0.000127476
0.000125746
0.000124019
0.000122303
0.000120592
0.000118897
0.00011721
0.000115543
0.000113885
0.000112255
0.000110635
0.00010905
0.00010748
0.000105937
0.000104423
0.000102968
0.00010145
0.000100125
9.8578e-05
9.74351e-05
9.57458e-05
9.48147e-05
9.27212e-05
9.12776e-05
8.27159e-05
5.99727e-05
5.97191e-05
5.94681e-05
5.92189e-05
5.89711e-05
5.87243e-05
5.84788e-05
5.82345e-05
5.79917e-05
5.77504e-05
5.7511e-05
5.72735e-05
5.70381e-05
5.68049e-05
5.65741e-05
5.63457e-05
5.61198e-05
5.58963e-05
5.56754e-05
5.54571e-05
5.52413e-05
5.50279e-05
5.4817e-05
5.46085e-05
5.44021e-05
5.41979e-05
5.39957e-05
5.37954e-05
5.35969e-05
5.33999e-05
5.32044e-05
5.30101e-05
5.28169e-05
5.26245e-05
5.24327e-05
5.22414e-05
5.205e-05
5.18586e-05
5.16665e-05
5.14734e-05
5.12797e-05
5.10839e-05
5.08872e-05
5.06882e-05
5.04868e-05
5.02838e-05
5.00779e-05
4.98681e-05
4.96559e-05
4.94399e-05
4.92206e-05
4.89975e-05
4.87705e-05
4.85404e-05
4.83044e-05
4.80687e-05
4.7822e-05
4.75841e-05
4.73231e-05
4.70837e-05
4.68604e-05
4.66491e-05
4.64452e-05
4.62463e-05
4.60519e-05
4.58612e-05
4.56727e-05
4.54872e-05
4.53051e-05
4.51274e-05
4.49544e-05
4.47865e-05
4.46224e-05
4.4465e-05
4.43107e-05
4.41644e-05
4.40199e-05
4.38835e-05
4.3748e-05
4.36172e-05
4.34862e-05
4.3358e-05
4.32293e-05
4.30999e-05
4.29687e-05
4.2834e-05
4.26974e-05
4.25553e-05
4.24114e-05
4.22623e-05
4.21114e-05
4.19537e-05
4.17993e-05
4.16384e-05
4.14804e-05
4.13133e-05
4.11422e-05
4.09842e-05
4.0831e-05
4.06794e-05
4.05255e-05
4.03726e-05
4.02219e-05
4.00738e-05
3.99272e-05
3.97825e-05
3.96392e-05
3.94969e-05
3.9356e-05
3.9216e-05
3.9077e-05
3.89369e-05
3.87965e-05
3.86554e-05
3.85141e-05
3.83715e-05
3.82281e-05
3.80831e-05
3.79368e-05
3.77892e-05
3.76407e-05
3.74915e-05
3.73413e-05
3.71906e-05
3.7038e-05
3.68852e-05
3.67297e-05
3.65738e-05
3.64149e-05
3.62551e-05
3.60926e-05
3.59286e-05
3.57623e-05
3.55939e-05
3.54234e-05
3.52508e-05
3.50763e-05
3.48997e-05
3.47212e-05
3.45407e-05
3.43583e-05
3.41738e-05
3.39873e-05
3.37987e-05
3.36081e-05
3.34153e-05
3.32205e-05
3.30234e-05
3.28241e-05
3.26227e-05
3.2419e-05
3.2213e-05
3.20048e-05
3.17941e-05
3.15811e-05
3.13654e-05
3.11472e-05
3.09262e-05
3.07025e-05
3.04757e-05
3.02459e-05
3.00127e-05
2.97761e-05
2.95353e-05
2.92906e-05
2.90408e-05
2.87861e-05
2.85249e-05
2.8257e-05
2.79799e-05
2.76947e-05
2.73936e-05
2.70829e-05
2.67413e-05
2.63934e-05
2.59668e-05
2.55719e-05
2.49119e-05
2.44229e-05
2.24801e-05
7.9659e-05
8.09356e-05
8.19188e-05
8.24924e-05
8.26247e-05
8.24686e-05
8.21334e-05
8.16726e-05
8.11548e-05
8.05595e-05
7.99326e-05
7.9271e-05
7.8594e-05
7.78934e-05
7.71852e-05
7.64491e-05
7.5699e-05
7.4907e-05
7.41174e-05
7.32524e-05
7.24412e-05
7.14734e-05
7.07241e-05
6.9444e-05
6.95997e-05
0.000771782
0.000772189
0.000757379
0.000739142
0.000715678
0.000690932
0.00066842
0.00064723
0.00062744
0.000608403
0.000590131
0.000572261
0.000555052
0.000537448
0.000521169
0.000502623
0.000486533
0.000467869
0.000452309
0.000431578
0.000418358
0.00039338
0.000386044
0.000348951
0.000350721
0.00174994
0.00176054
0.00174104
0.00171094
0.00167104
0.00162573
0.00158028
0.00153767
0.0014954
0.00145396
0.00141354
0.00137381
0.00133497
0.00129571
0.00125821
0.00121668
0.00118048
0.00113721
0.00110123
0.00105429
0.00102178
0.000967102
0.000944324
0.00087574
0.000862347
0.00270573
0.00270735
0.00268495
0.00264962
0.00259983
0.00254099
0.0024804
0.00242042
0.00235969
0.00229932
0.0022398
0.00218091
0.0021229
0.0020644
0.00200746
0.00194599
0.00189058
0.00182469
0.00176961
0.00169647
0.00164605
0.00156119
0.00152415
0.00142392
0.00139647
0.00365198
0.00365845
0.00363822
0.00359816
0.00354154
0.00347479
0.00340317
0.00332973
0.00325443
0.00317855
0.00310285
0.0030274
0.00295242
0.0028768
0.00280191
0.00272284
0.0026484
0.00256267
0.0024875
0.00239095
0.00231911
0.00221066
0.00215091
0.00203053
0.00197525
0.00453747
0.00454194
0.00452168
0.00447911
0.00442009
0.00434893
0.00427095
0.00418901
0.00410399
0.00401727
0.00392985
0.00384204
0.00375395
0.0036648
0.00357534
0.00348179
0.00339087
0.00328794
0.00319401
0.00307627
0.00298376
0.00285299
0.00277138
0.00263072
0.00254812
0.00536324
0.00536337
0.00534241
0.00529873
0.00523871
0.00516605
0.00508495
0.00499813
0.00490704
0.00481322
0.00471775
0.00462106
0.00452321
0.00442357
0.0043224
0.0042168
0.00411159
0.00399461
0.00388395
0.00375067
0.0036376
0.00349154
0.00338462
0.00323365
0.00311739
0.00614073
0.00613615
0.00611277
0.00606921
0.00600918
0.00593637
0.00585402
0.00576467
0.00567009
0.00557188
0.00547115
0.00536829
0.00526333
0.00515562
0.00504504
0.00492923
0.00481151
0.00468199
0.00455588
0.00440844
0.00427605
0.0041158
0.00398432
0.00382309
0.00367301
0.00687481
0.00686542
0.00683918
0.0067958
0.0067365
0.00666427
0.00658178
0.00649145
0.0063952
0.0062946
0.00619067
0.00608373
0.00597366
0.00585975
0.00574152
0.00561691
0.00548805
0.00534705
0.00520654
0.00504581
0.00489535
0.00472139
0.00456634
0.00439436
0.00421074
0.00757203
0.00755796
0.00752971
0.00748527
0.00742714
0.0073556
0.00727338
0.00718293
0.00708619
0.00698459
0.00687898
0.00676953
0.00665586
0.00653719
0.00641264
0.00628031
0.00614139
0.00598975
0.00583575
0.00566242
0.00549516
0.0053076
0.00513018
0.00494682
0.00473
0.00823271
0.00821469
0.00818433
0.00813923
0.00808124
0.00801095
0.00792903
0.00783904
0.00774268
0.00764112
0.00753501
0.00742427
0.00730824
0.00718593
0.0070561
0.00691686
0.00676875
0.00660713
0.00644045
0.00625508
0.00607212
0.00587076
0.00567254
0.00547702
0.00522784
0.00885826
0.00883642
0.00880367
0.00875771
0.00869944
0.00863003
0.00854857
0.00845952
0.00836425
0.00826365
0.00815808
0.00804714
0.00792987
0.00780496
0.00767078
0.00752536
0.00736886
0.0071979
0.0070194
0.00682256
0.0066249
0.00640984
0.00619239
0.00598397
0.00570358
0.00944473
0.0094195
0.00938419
0.0093371
0.00927857
0.00920964
0.00912901
0.00904144
0.008948
0.00884924
0.00874522
0.00863518
0.00851776
0.00839126
0.0082536
0.00810272
0.00793858
0.00775895
0.00756956
0.00736175
0.00715043
0.00692198
0.00668664
0.00646496
0.0061549
0.00998938
0.00996068
0.00992263
0.00987418
0.00981553
0.0097469
0.00966764
0.00958225
0.00949146
0.0093955
0.00929411
0.00918613
0.00906973
0.00894273
0.00880252
0.00864691
0.00847594
0.00828833
0.00808894
0.00787089
0.00764718
0.00740593
0.00715398
0.00691902
0.00658095
0.0104864
0.0104543
0.0104137
0.0103639
0.0103055
0.0102375
0.0101603
0.010078
0.00999087
0.00989882
0.00980128
0.00969664
0.00958255
0.00945624
0.0093145
0.00915496
0.00897801
0.00878313
0.00857487
0.00834747
0.00811239
0.00785923
0.0075919
0.00734398
0.00697982
0.0109311
0.0108953
0.0108526
0.0108019
0.0107441
0.0106775
0.0106035
0.0105253
0.010443
0.0103562
0.010264
0.0101641
0.0100538
0.00992956
0.00978744
0.00962483
0.00944264
0.00924156
0.00902568
0.00879007
0.00854457
0.00828066
0.00799923
0.00773897
0.00735075
0.0113273
0.0112899
0.0112463
0.0111961
0.0111397
0.0110754
0.011005
0.0109311
0.0108538
0.0107722
0.0106852
0.0105901
0.0104836
0.0103614
0.0102189
0.0100539
0.00986772
0.00966157
0.00943913
0.00919653
0.00894174
0.00866825
0.00837408
0.00810235
0.00769228
0.0116813
0.0116433
0.0115996
0.0115504
0.0114957
0.011434
0.011367
0.0112972
0.0112243
0.0111472
0.0110648
0.0109739
0.0108706
0.01075
0.0106073
0.010441
0.010252
0.0100419
0.00981414
0.00956574
0.00930293
0.00902112
0.00871568
0.00843353
0.00800385
0.0119977
0.0119594
0.0119157
0.0118674
0.0118142
0.0117552
0.0116912
0.0116249
0.0115556
0.0114825
0.0114038
0.0113165
0.0112159
0.0110963
0.0109527
0.010785
0.010594
0.0103812
0.0101493
0.00989634
0.00962679
0.00933794
0.00902274
0.00873137
0.00828441
0.0122681
0.01223
0.012187
0.0121398
0.0120886
0.0120328
0.0119722
0.011909
0.0118432
0.0117734
0.011698
0.0116139
0.0115156
0.0113964
0.0112531
0.0110849
0.0108931
0.0106789
0.0104441
0.0101878
0.00991279
0.00961822
0.0092948
0.00899551
0.00853362
0.0124915
0.012454
0.0124122
0.0123667
0.0123179
0.012265
0.0122082
0.0121483
0.0120857
0.012019
0.0119467
0.0118655
0.0117693
0.0116507
0.0115076
0.0113402
0.0111487
0.0109342
0.0106978
0.0104392
0.0101601
0.00986112
0.00953101
0.00922522
0.00875075
0.0126601
0.0126245
0.012585
0.0125422
0.0124962
0.0124469
0.0123943
0.0123384
0.0122792
0.0122158
0.0121464
0.012068
0.0119742
0.0118573
0.0117159
0.0115505
0.0113606
0.011147
0.0109101
0.0106504
0.0103685
0.0100664
0.00973117
0.00942032
0.00893563
0.0127722
0.0127391
0.0127027
0.0126634
0.0126212
0.0125761
0.0125282
0.0124772
0.0124224
0.0123625
0.0122964
0.0122209
0.01213
0.0120161
0.0118778
0.0117156
0.0115285
0.0113169
0.0110808
0.0108211
0.0105376
0.0102336
0.00989474
0.00958029
0.00908776
0.012818
0.0127893
0.0127577
0.0127234
0.0126865
0.0126466
0.012604
0.0125585
0.0125094
0.0124549
0.0123933
0.0123223
0.0122362
0.0121271
0.0119933
0.0118357
0.0116525
0.0114441
0.0112099
0.0109512
0.0106674
0.0103628
0.0100217
0.00970509
0.00920703
0.0127936
0.0127708
0.0127454
0.0127177
0.0126876
0.0126549
0.0126196
0.0125812
0.012539
0.0124916
0.0124367
0.0123719
0.0122925
0.0121903
0.0120626
0.0119107
0.0117328
0.0115286
0.0112974
0.0110407
0.0107577
0.0104536
0.0101117
0.0097944
0.0092931
0.0127007
0.0126851
0.0126674
0.0126477
0.0126259
0.0126018
0.0125751
0.0125456
0.0125122
0.0124733
0.0124275
0.012371
0.0122998
0.0122061
0.0120861
0.0119414
0.0117698
0.0115709
0.0113437
0.0110901
0.0108088
0.0105063
0.0101649
0.00984843
0.00934607
0.0125411
0.0125338
0.0125248
0.0125143
0.0125021
0.0124879
0.0124716
0.0124523
0.0124293
0.012401
0.0123652
0.0123196
0.0122586
0.0121754
0.0120647
0.0119283
0.0117642
0.0115716
0.0113492
0.0110995
0.0108211
0.0105211
0.0101815
0.00986721
0.00936588
0.0122969
0.0122995
0.0123011
0.0123016
0.0123009
0.0122989
0.0122951
0.0122887
0.0122788
0.0122637
0.0122412
0.0122086
0.0121621
0.0120925
0.0119939
0.011868
0.0117132
0.0115283
0.0113121
0.0110675
0.0107931
0.0104968
0.0101604
0.00984985
0.00935188
0.0119621
0.011976
0.0119895
0.0120025
0.0120152
0.0120271
0.0120378
0.0120466
0.0120523
0.0120531
0.0120468
0.0120301
0.0119998
0.011948
0.0118643
0.0117508
0.0116071
0.0114312
0.0112222
0.0109834
0.010714
0.0104225
0.0100906
0.00978511
0.00929322
0.0115711
0.0115959
0.011621
0.0116464
0.011672
0.0116977
0.011723
0.0117472
0.0117689
0.0117865
0.0117974
0.0117982
0.0117842
0.0117512
0.0116848
0.0115846
0.0114526
0.011286
0.0110844
0.0108516
0.0105879
0.0103015
0.0099753
0.00967547
0.00919193
0.0111348
0.0111692
0.0112046
0.011241
0.0112785
0.011317
0.0113562
0.0113953
0.011433
0.0114674
0.011496
0.0115152
0.0115198
0.0115038
0.0114568
0.0113713
0.0112515
0.0110941
0.0109
0.0106732
0.0104156
0.0101345
0.00981507
0.00952143
0.00904832
0.0106598
0.0107022
0.0107463
0.0107922
0.0108402
0.0108902
0.010942
0.010995
0.0110479
0.0110989
0.0111453
0.0111833
0.0112078
0.0112095
0.0111812
0.0111128
0.0110058
0.0108576
0.0106707
0.0104495
0.0101983
0.00992277
0.00961092
0.00932382
0.00886305
0.0101516
0.0102004
0.0102515
0.0103051
0.0103616
0.0104212
0.0104839
0.0105493
0.0106163
0.0106831
0.0107471
0.0108043
0.0108492
0.010871
0.0108589
0.01081
0.0107171
0.0105777
0.0103975
0.0101814
0.00993677
0.00966676
0.00936347
0.00908312
0.0086365
0.0096159
0.00966931
0.00972541
0.00978459
0.00984741
0.0099144
0.00998586
0.0100617
0.010141
0.0102224
0.0103033
0.0103795
0.0104454
0.0104887
0.0104922
0.0104633
0.010387
0.010256
0.0100819
0.00987002
0.00963207
0.00936748
0.00907373
0.00880018
0.00836947
0.00905937
0.00911539
0.00917424
0.0092365
0.00930301
0.00937469
0.00945227
0.00953605
0.00962564
0.00971979
0.00981617
0.00991084
0.00999785
0.0100626
0.0100828
0.0100731
0.0100164
0.00989364
0.00972483
0.00951596
0.00928474
0.00902531
0.00874217
0.0084753
0.00806232
0.00849028
0.00854658
0.00860548
0.00866782
0.00873486
0.00880805
0.00888867
0.00897751
0.00907463
0.00917912
0.00928908
0.00940084
0.00950845
0.00959342
0.00963252
0.00964122
0.00960581
0.00949205
0.00932754
0.00912021
0.00889576
0.00864103
0.00836979
0.00810924
0.00771611
0.00791475
0.00796891
0.00802488
0.00808406
0.00814834
0.00821977
0.00830024
0.00839111
0.00849289
0.00860496
0.00872599
0.00885272
0.00897834
0.00908114
0.00914157
0.00916908
0.00915504
0.00905262
0.00889056
0.00868415
0.00846535
0.00821579
0.00795689
0.00770406
0.0073313
0.00733126
0.00738076
0.00743096
0.00748428
0.00754324
0.00761052
0.00768856
0.00777919
0.00788353
0.00800093
0.00813069
0.00826995
0.0084086
0.00852785
0.00861121
0.0086582
0.00866513
0.00857522
0.00841463
0.00820715
0.00799425
0.00774898
0.00750449
0.00725831
0.00690914
0.00673138
0.00677241
0.0068138
0.00685936
0.00691169
0.00697392
0.00704882
0.00713849
0.00724492
0.00736718
0.00750445
0.00765102
0.00779762
0.00793505
0.00804083
0.00810864
0.00813622
0.00806022
0.00790241
0.00769441
0.00748485
0.00724549
0.00701258
0.00677717
0.00645009
0.00613545
0.00617371
0.00620909
0.00624626
0.0062881
0.00633883
0.00640214
0.00648129
0.00658035
0.00670222
0.00684251
0.00698972
0.00714612
0.00730129
0.00742914
0.00751959
0.00756817
0.0075049
0.00734992
0.00713958
0.00693438
0.00670003
0.00648209
0.00625559
0.00595564
0.00552929
0.00556928
0.0056068
0.00564321
0.00568004
0.00572316
0.00577693
0.00584562
0.00593517
0.00604928
0.00617689
0.00631509
0.00647142
0.00663395
0.00677678
0.00688947
0.00695996
0.00691156
0.00676191
0.00655191
0.00635008
0.00612339
0.00591662
0.00570391
0.00542631
0.00491741
0.0049519
0.00498364
0.00501554
0.00504923
0.00508945
0.00514001
0.00520507
0.00529198
0.00539815
0.00551214
0.00564061
0.00579078
0.00595109
0.006098
0.00622597
0.00631134
0.00627254
0.00612872
0.00591954
0.00572284
0.00550545
0.00531308
0.00511303
0.00486405
0.00432105
0.00434872
0.00437433
0.00440031
0.00442791
0.00446216
0.0045072
0.00456761
0.00465105
0.00474718
0.00485434
0.00498039
0.00512846
0.00528748
0.0054357
0.00557449
0.00566733
0.00562973
0.00548779
0.00528079
0.005089
0.00488584
0.0047044
0.00452301
0.00429504
0.00376507
0.00379292
0.0038166
0.00383862
0.0038604
0.00388739
0.0039238
0.00397533
0.00404654
0.00412751
0.00422366
0.00434316
0.00448748
0.00464481
0.00479478
0.00494146
0.0050387
0.00500208
0.00486474
0.00466135
0.00447787
0.00428861
0.00412171
0.00395522
0.00375339
0.0032473
0.00327232
0.00329438
0.00331406
0.00333334
0.00335582
0.00338535
0.00342805
0.00348604
0.00355384
0.00363741
0.00374567
0.00388132
0.00403262
0.00418417
0.00433663
0.0044382
0.00440271
0.00426747
0.0040685
0.00389632
0.00372131
0.00357103
0.00342314
0.00324461
0.00276225
0.00278481
0.00280424
0.00282047
0.00283565
0.00285301
0.00287609
0.00290997
0.00295593
0.00301208
0.00308313
0.00317826
0.00330263
0.00344387
0.00359326
0.00374786
0.00385442
0.00382457
0.00369683
0.00350615
0.00334811
0.00318795
0.00305594
0.00292393
0.00277092
0.00230885
0.00232974
0.00234774
0.00236123
0.00237255
0.00238502
0.00240203
0.0024278
0.00246271
0.00250792
0.00256601
0.00264555
0.00275511
0.00288279
0.00302475
0.00317842
0.00329117
0.00327317
0.00315745
0.00297895
0.00283383
0.00268973
0.00257602
0.00246045
0.00233188
0.00188809
0.0019105
0.00192799
0.00194017
0.00194899
0.00195766
0.0019694
0.00198767
0.00201308
0.00204695
0.00209238
0.00215413
0.00224478
0.00235409
0.00248231
0.00262912
0.00274606
0.00274344
0.00264552
0.00248415
0.0023547
0.00222726
0.00213265
0.00203175
0.00192829
0.00150853
0.00153118
0.00154926
0.00156148
0.00156926
0.00157556
0.0015832
0.00159483
0.00161154
0.00163395
0.00166633
0.00170966
0.00177678
0.00186316
0.00197146
0.00210415
0.00222111
0.0022364
0.00216363
0.0020273
0.00191507
0.00180618
0.00172767
0.0016428
0.0015601
0.00117576
0.00119726
0.00121617
0.00122903
0.00123658
0.00124146
0.00124603
0.001252
0.00126076
0.00127262
0.00129062
0.00131711
0.00135928
0.00141835
0.00150181
0.00161247
0.00172315
0.00175645
0.001712
0.0016048
0.00151174
0.00142175
0.00135936
0.00128874
0.00122675
0.000891476
0.000912408
0.000931812
0.000945084
0.00095222
0.000955549
0.000957131
0.000957739
0.00095921
0.000961302
0.000966203
0.000977606
0.000997399
0.00102881
0.0010841
0.0011656
0.00126189
0.0013095
0.00129395
0.00121876
0.00114651
0.00107753
0.00102918
0.000973842
0.000928622
0.000655958
0.000676594
0.00069581
0.000708449
0.000714033
0.000714819
0.000712836
0.000707983
0.000702865
0.000696667
0.000691133
0.000690446
0.000693963
0.000704909
0.000731197
0.000781234
0.000855054
0.000908334
0.000917781
0.000874595
0.000824468
0.000774282
0.000739032
0.000697122
0.000666993
0.000467123
0.000486773
0.000504099
0.000514
0.000516155
0.000513127
0.000507025
0.000497126
0.000486998
0.000475372
0.000463626
0.000456977
0.000451559
0.000450077
0.000457493
0.000480221
0.000526288
0.000572444
0.000596437
0.000580015
0.000551307
0.000517008
0.000493088
0.000463185
0.000444857
0.000318019
0.000335228
0.000347853
0.00035183
0.000348376
0.000340893
0.000331272
0.000318623
0.000307002
0.000295296
0.000283854
0.000275738
0.000268839
0.000264263
0.00026433
0.000270597
0.000291854
0.000321172
0.000345203
0.000344683
0.000332508
0.000311419
0.000296334
0.000277216
0.000266883
0.00020577
0.000216391
0.000218653
0.000215733
0.000207947
0.00019909
0.000189772
0.000179994
0.000171516
0.000164443
0.000158354
0.000153348
0.000149414
0.000146816
0.000145946
0.000146629
0.000153572
0.000166602
0.000180554
0.000183591
0.000179575
0.00016861
0.000160269
0.00015013
0.000144489
0.000111244
0.000110042
0.000103166
9.62833e-05
8.95534e-05
8.36342e-05
7.85569e-05
7.45397e-05
7.1531e-05
6.94657e-05
6.79366e-05
6.66362e-05
6.55785e-05
6.4757e-05
6.43788e-05
6.39765e-05
6.55079e-05
6.91056e-05
7.35992e-05
7.50036e-05
7.37935e-05
6.98716e-05
6.6657e-05
6.30651e-05
6.07777e-05
2.34331e-05
2.48872e-05
2.58181e-05
2.61923e-05
2.63424e-05
2.63465e-05
2.6219e-05
2.59809e-05
2.57102e-05
2.54335e-05
2.51666e-05
2.4911e-05
2.46744e-05
2.44555e-05
2.42705e-05
2.40923e-05
2.39771e-05
2.39314e-05
2.40215e-05
2.40621e-05
2.41918e-05
2.40226e-05
2.41488e-05
2.36223e-05
2.42391e-05
)
;
boundaryField
{
inlet
{
type calculated;
value uniform 0.0309749;
}
outlet
{
type calculated;
value nonuniform List<scalar>
57
(
6.95997e-05
0.000350721
0.000862347
0.00139647
0.00197525
0.00254812
0.00311739
0.00367301
0.00421074
0.00473
0.00522784
0.00570358
0.0061549
0.00658095
0.00697982
0.00735075
0.00769228
0.00800385
0.00828441
0.00853362
0.00875075
0.00893563
0.00908776
0.00920703
0.0092931
0.00934607
0.00936588
0.00935188
0.00929322
0.00919193
0.00904832
0.00886305
0.0086365
0.00836947
0.00806232
0.00771611
0.0073313
0.00690914
0.00645009
0.00595564
0.00542631
0.00486405
0.00429504
0.00375339
0.00324461
0.00277092
0.00233188
0.00192829
0.0015601
0.00122675
0.000928622
0.000666993
0.000444857
0.000266883
0.000144489
6.07777e-05
2.42391e-05
)
;
}
upperWall
{
type nutkWallFunction;
Cmu 0.09;
kappa 0.41;
E 9.8;
value nonuniform List<scalar>
223
(
3.80688e-06
3.6927e-06
3.53294e-06
3.37524e-06
3.22604e-06
3.08856e-06
2.96249e-06
2.84753e-06
2.74303e-06
2.64796e-06
2.5613e-06
2.48201e-06
2.40945e-06
2.34256e-06
2.28132e-06
2.22422e-06
2.17219e-06
2.12271e-06
2.07854e-06
2.03775e-06
1.99734e-06
1.95722e-06
1.91727e-06
1.87749e-06
1.83786e-06
1.79842e-06
1.75918e-06
1.72018e-06
1.68144e-06
1.64299e-06
1.60486e-06
1.56706e-06
1.52962e-06
1.49254e-06
1.45584e-06
1.41953e-06
1.3836e-06
1.34806e-06
1.31291e-06
1.27814e-06
1.24373e-06
1.20969e-06
1.17598e-06
1.14259e-06
1.10951e-06
1.07672e-06
1.04418e-06
1.01188e-06
9.7978e-07
9.47863e-07
9.16087e-07
8.84422e-07
8.52831e-07
8.21281e-07
7.89708e-07
7.58081e-07
7.26299e-07
6.94372e-07
6.62238e-07
6.29796e-07
5.97141e-07
5.64052e-07
5.30627e-07
4.96805e-07
4.62481e-07
4.27556e-07
3.92178e-07
3.56116e-07
3.19545e-07
2.82233e-07
2.44361e-07
2.05806e-07
1.66502e-07
1.26891e-07
8.59263e-08
4.57937e-08
2.60481e-09
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
)
;
}
lowerWall
{
type nutkWallFunction;
Cmu 0.09;
kappa 0.41;
E 9.8;
value nonuniform List<scalar>
250
(
1.07834e-06
1.01563e-06
8.87437e-07
7.45768e-07
6.08668e-07
4.82119e-07
3.67127e-07
2.64541e-07
1.70741e-07
8.89485e-08
1.09493e-08
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1.09924e-07
6.48608e-07
1.01746e-06
1.2737e-06
1.43521e-06
1.52314e-06
1.53952e-06
1.51842e-06
1.45908e-06
1.34017e-06
1.15824e-06
9.14548e-07
6.06306e-07
2.14291e-07
0
0
0
0
0
0
0
0
0
0
0
0
0
0
7.12999e-07
1.59749e-06
2.35284e-06
3.01515e-06
3.60776e-06
4.1359e-06
4.61314e-06
5.04961e-06
5.45346e-06
5.83102e-06
6.18719e-06
6.52568e-06
6.84931e-06
7.16012e-06
7.45962e-06
7.74879e-06
8.02833e-06
8.29863e-06
8.55996e-06
8.81239e-06
9.05603e-06
9.29093e-06
9.51733e-06
9.73569e-06
9.94716e-06
1.01515e-05
1.03481e-05
1.05372e-05
1.07209e-05
1.09002e-05
1.10745e-05
1.12428e-05
1.14033e-05
1.15537e-05
1.16915e-05
1.18133e-05
1.19158e-05
1.19951e-05
1.20337e-05
1.20435e-05
1.20275e-05
1.19721e-05
1.18787e-05
1.17409e-05
1.15502e-05
1.12932e-05
1.10135e-05
1.07348e-05
1.04582e-05
1.01883e-05
9.92921e-06
9.68423e-06
9.45505e-06
9.24357e-06
9.0503e-06
8.87399e-06
8.70686e-06
8.5541e-06
8.43998e-06
8.34879e-06
8.26474e-06
8.187e-06
8.11616e-06
8.05215e-06
7.99479e-06
7.94355e-06
7.89764e-06
7.85609e-06
7.81797e-06
7.78241e-06
7.74869e-06
7.71619e-06
7.6844e-06
7.65295e-06
7.62155e-06
7.58999e-06
7.55811e-06
7.52584e-06
7.49312e-06
7.45995e-06
7.42633e-06
7.39231e-06
7.35794e-06
7.32327e-06
7.28836e-06
7.25327e-06
7.21806e-06
7.18279e-06
7.14752e-06
7.11229e-06
7.07714e-06
7.04213e-06
7.00729e-06
6.97265e-06
6.93824e-06
6.90407e-06
6.87017e-06
6.83655e-06
6.80322e-06
6.7702e-06
6.7375e-06
6.70511e-06
6.67305e-06
6.64131e-06
6.6099e-06
6.57882e-06
6.54806e-06
6.51763e-06
6.48751e-06
6.4577e-06
6.4282e-06
6.39901e-06
6.37009e-06
6.34143e-06
6.31304e-06
6.28493e-06
6.25708e-06
6.22949e-06
6.20215e-06
6.17502e-06
6.14813e-06
6.12156e-06
6.09515e-06
6.06898e-06
6.0428e-06
6.01693e-06
5.99107e-06
5.96561e-06
5.94033e-06
5.91501e-06
5.89006e-06
5.86444e-06
5.84115e-06
5.81843e-06
5.79393e-06
5.7711e-06
5.74531e-06
5.7208e-06
5.69634e-06
5.6722e-06
5.64713e-06
5.62247e-06
5.59508e-06
5.56851e-06
5.53537e-06
5.5015e-06
5.44759e-06
5.35236e-06
4.9372e-06
5.19369e-06
5.39043e-06
5.54206e-06
5.6302e-06
5.65077e-06
5.62774e-06
5.57449e-06
5.50562e-06
5.42457e-06
5.33369e-06
5.23656e-06
5.13447e-06
5.02946e-06
4.92074e-06
4.81057e-06
4.69577e-06
4.57871e-06
4.45494e-06
4.33125e-06
4.19561e-06
4.068e-06
3.91584e-06
3.79751e-06
3.59539e-06
3.61855e-06
)
;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
| |
d8914335f8c37fe84a5c470f733659cf9235aefe | 635ef8de70441a98557160d4c78771a1eb335db5 | /http/src/bitmap.cc | d99f0ab8530a93b7a3b4052a4ae667cb1709fca4 | [] | no_license | lineCode/remoteWebGUI | a53d82e2b5691eb467c2fc5bce066e8bacc9198d | 2e301ce74d8ae6b0151b6ca6caa57b7e6d128774 | refs/heads/master | 2020-03-31T15:33:04.398599 | 2018-10-09T15:29:24 | 2018-10-09T15:29:24 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,211 | cc | bitmap.cc | #include "bitmap.h"
#include <stdexcept>
#include <algorithm>
static inline std::size_t __inl_unit_bytes_size(std::size_t bits_size) {
return bits_size / 8 + (bits_size % 8 == 0 ? 0 : 1);
}
static inline std::size_t __inl_outside_nth_unit(std::size_t pos) {
return pos / 8;
}
static inline std::uint8_t __inl_mask_bit(std::size_t pos) {
return 1 << (pos % 8);
}
rwg_http::bitmap::bitmap(std::size_t bits_size)
: _bits(new std::uint8_t[__inl_unit_bytes_size(bits_size)])
, _bits_size(bits_size) {
std::size_t units_size = __inl_unit_bytes_size(bits_size);
std::fill(this->_bits.get(), this->_bits.get() + units_size, 0x00);
}
rwg_http::bitmap::~bitmap() {
}
rwg_http::bit rwg_http::bitmap::operator[](const std::size_t pos) const {
if (pos >= this->_bits_size) {
throw std::out_of_range("rwg_http::bitmap operator[]: out of range");
}
return rwg_http::bit(this->_bits[__inl_outside_nth_unit(pos)], __inl_mask_bit(pos));
}
std::size_t rwg_http::bitmap::size() const {
return this->_bits_size;
}
std::size_t rwg_http::bitmap::units_size() const {
return __inl_unit_bytes_size(this->_bits_size);
}
void rwg_http::bitmap::fill(const std::size_t start_pos, const std::size_t end_pos, const bool bit) {
if (start_pos > end_pos) {
throw std::out_of_range("rwg_http::bitmap fill: start_pos great than end_pos");
}
if (start_pos >= this->_bits_size) {
throw std::out_of_range("rwg_http::bitmap fill: start_pos out of range");
}
if (end_pos > this->_bits_size) {
throw std::out_of_range("rwg_http::bitmap fill: end_pos out of range");
}
if (start_pos == end_pos) {
return;
}
std::size_t startunit = __inl_outside_nth_unit(start_pos);
std::uint8_t startunit_mask = static_cast<std::uint8_t>(0xFF - (__inl_mask_bit(start_pos) - 1));
std::size_t endunit = __inl_outside_nth_unit(end_pos);
std::uint8_t endunit_mask = static_cast<std::uint8_t>(__inl_mask_bit(end_pos) - 1);
if (bit) {
if (startunit == endunit) {
std::uint8_t mask = startunit_mask & endunit_mask;
this->_bits[startunit] |= mask;
return;
}
this->_bits[startunit] |= startunit_mask;
this->_bits[endunit] |= endunit_mask;
for (auto i = startunit + 1; i < endunit; i++) {
this->_bits[i] |= 0xFF;
}
}
else {
if (startunit == endunit) {
std::uint8_t mask = startunit_mask & endunit_mask;
this->_bits[startunit] &= ~mask;
return;
}
this->_bits[startunit] &= ~startunit_mask;
this->_bits[endunit] &= ~endunit_mask;
for (auto i = startunit + 1; i < endunit; i++) {
this->_bits[i] &= 0x00;
}
}
}
bool rwg_http::bitmap::ensure(const std::size_t start_pos, const std::size_t end_pos, const bool bit) const {
if (start_pos > end_pos) {
throw std::out_of_range("rwg_http::bitmap fill: start_pos great than end_pos");
}
if (start_pos >= this->_bits_size) {
throw std::out_of_range("rwg_http::bitmap fill: start_pos out of range");
}
if (end_pos > this->_bits_size) {
throw std::out_of_range("rwg_http::bitmap fill: end_pos out of range");
}
if (start_pos == end_pos) {
return true;
}
std::size_t startunit = __inl_outside_nth_unit(start_pos);
std::uint8_t startunit_mask = static_cast<std::uint8_t>(0xFF - (__inl_mask_bit(start_pos) - 1));
std::size_t endunit = __inl_outside_nth_unit(end_pos);
std::uint8_t endunit_mask = static_cast<std::uint8_t>(__inl_mask_bit(end_pos) - 1);
if (bit) {
if (startunit == endunit) {
std::uint8_t mask = startunit_mask & endunit_mask;
return (this->_bits[startunit] & mask) == mask;
}
if ((this->_bits[startunit] & startunit_mask) != startunit_mask) {
return false;
}
if ((this->_bits[endunit] & endunit_mask) != endunit_mask) {
return false;
}
for (auto i = startunit + 1; i < endunit; i++) {
if (this->_bits[i] != 0xFF) {
return false;
}
}
}
else {
if (startunit == endunit) {
std::uint8_t mask = startunit_mask & endunit_mask;
return (this->_bits[startunit] & mask) == 0x00;
}
if ((this->_bits[startunit] & startunit_mask) != 0x00) {
return false;
}
if ((this->_bits[endunit] & endunit_mask) != 0x00) {
return false;
}
for (auto i = startunit + 1; i < endunit; i++) {
if (this->_bits[i] != 0x00) {
return false;
}
}
}
return true;
}
rwg_http::bit::bit(std::uint8_t& ref_byte, std::uint8_t mask_byte)
: _ref_byte(ref_byte)
, _mask_byte(mask_byte) {}
rwg_http::bit::operator bool() const {
return (this->_ref_byte & this->_mask_byte) != 0;
}
rwg_http::bit& rwg_http::bit::operator=(const bool&& bit) {
if (bit) {
this->_ref_byte |= this->_mask_byte;
}
else {
this->_ref_byte &= ~this->_mask_byte;
}
return *this;
}
|
f6a45c62148d7df4d37724c399a05c43620acdf6 | e26a93af3bb0e13862497e2b9d5c96a3bb02e325 | /include/IJsonSerializable.h | eb3ac2c5c33fe97a2e6d745007b5db5784473689 | [] | no_license | adriangonz/EntityFramework | 0fb486273a01772891da7c442919908a674e48fa | 95463e9fb8adfe4404f28d8dc05c57132013699c | refs/heads/master | 2020-05-17T15:28:25.443930 | 2012-06-08T20:09:42 | 2012-06-08T20:09:48 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 360 | h | IJsonSerializable.h | /*
* IJsonSerializable.h
*
* Created on: 30/05/2012
* Author: kaseyo
*/
#pragma once
#include "json/json.h"
namespace EF {
class IJsonSerializable {
public:
virtual ~IJsonSerializable() {};
virtual Json::Value serialize() const = 0;
virtual void deserialize(const Json::Value& root) = 0;
};
} /* namespace EF */
|
c6b2e4600d59a72633fc326e8513558dc33a93ab | aea4e38e3eeddb7195b813df846fedeeb83f6e50 | /Practica1/Coche.cpp | 39a530ffd98acaaa6ccbe7f1019c5395e8ce6863 | [] | no_license | chanchantal/PECL1-EEDD | 4150a27c1258b7c85e60e4f162b6dac55e106d1b | c9afa073575abc5cf4793f76a5da45c9b13736d8 | refs/heads/master | 2020-08-28T12:01:47.108241 | 2019-11-05T23:21:59 | 2019-11-05T23:21:59 | 217,694,008 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 756 | cpp | Coche.cpp | #include <iostream>
#include "Coche.h"
#include <string>
using namespace std;
Coche::Coche(string matricula,string marca,string modelo,string color){
this -> matricula = matricula;
this -> marca = marca;
this -> modelo = modelo;
this -> color = color;
}
Coche::Coche(){
}
string Coche::getMatricula(){
return matricula;
}
string Coche::getMarca(){
return marca;
}
string Coche::getModelo(){
return modelo;
}
string Coche::getColor(){
return color;
}
void Coche::setMatricula(string strMatricula){
matricula=strMatricula;
}
void Coche::setMarca(string strMarca){
marca=strMarca;
}
void Coche::setModelo(string strModelo){
modelo=strModelo;
}
void Coche::setColor(string strColor){
color=strColor;
}
|
77e2cf36ce0029e2ea4e6782b80ca51f2ea07165 | e488398ef177d0b0d4a4c5cb861e5ebe92a5a2cc | /headers/NetworkModule.hpp | 7e1679446deda09cf5723c1045c5d253a87ca4f5 | [] | no_license | LesikYura/ft_gkrellm | 0ca6d40921766e042c2ced3ea9a77d6759861801 | 84f10c48a89de4b1e668916671ee90244e426af9 | refs/heads/master | 2020-04-05T01:10:54.895337 | 2018-11-06T18:13:09 | 2018-11-06T18:13:09 | 156,426,563 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,420 | hpp | NetworkModule.hpp | // ************************************************************************** //
// //
// ::: :::::::: //
// NetworkModule.hpp :+: :+: :+: //
// +:+ +:+ +:+ //
// By: dpozinen <dpozinen@student.unit.ua> +#+ +:+ +#+ //
// +#+#+#+#+#+ +#+ //
// Created: 2018/10/14 18:08:45 by dpozinen #+# #+# //
// Updated: 2018/10/14 18:08:46 by dpozinen ### ########.fr //
// //
// ************************************************************************** //
#ifndef NETWORKMOD_HPP
# define NETWORKMOD_HPP
#include "IMonitorModule.hpp"
class NetworkModule : public IMonitorModule
{
private:
std::string _inPackets;
std::string _outPackets;
public:
NetworkModule();
NetworkModule(const NetworkModule &other);
NetworkModule &operator=(const NetworkModule &other);
~NetworkModule();
void makeAll(void);
void makeInOut(void);
void update(Ncurses &nc);
void update(SDL &sdl);
std::string getInPackets(void) const;
std::string getOutPackets(void) const;
};
#endif |
515c375e95e610853aafa368d5089c5aabe0a8d9 | fd555d7185ef67d13f6d2993f5683aebbf901f30 | /apps/src/random_bipartite_matching-test/random_bipartite_matching.cc | 4294ef885b299344ad4d65d53b8e902b32cde94e | [] | no_license | gshashidhar125/LightHouse | da719b920e8b40ea8658c8ff03f4623eaba84d5a | 0cb92bcbaab225b4f6e902accdeea57992b322ea | refs/heads/master | 2021-01-20T14:23:52.805409 | 2016-07-10T14:48:45 | 2016-07-10T14:48:45 | 90,603,863 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,522 | cc | random_bipartite_matching.cc | #include "random_bipartite_matching.h"
int32_t random_bipartite_matching(gm_graph& G, bool* G_isLeft,
node_t* G_Match)
{
//Initializations
gm_rt_initialize();
G.freeze();
int32_t count = 0 ;
bool finished = false ;
node_t* G_Suitor = gm_rt_allocate_node_t(G.num_nodes(),gm_rt_thread_id());
count = 0 ;
finished = false ;
#pragma omp parallel for
for (node_t t0 = 0; t0 < G.num_nodes(); t0 ++)
{
G_Match[t0] = gm_graph::NIL_NODE ;
G_Suitor[t0] = gm_graph::NIL_NODE ;
}
while ( !finished)
{
finished = true ;
#pragma omp parallel
{
bool finished_prv = false ;
finished_prv = true ;
#pragma omp for nowait schedule(dynamic,128)
for (node_t n = 0; n < G.num_nodes(); n ++)
{
if (G_isLeft[n] && (G_Match[n] == gm_graph::NIL_NODE))
{
for (edge_t t_idx = G.begin[n];t_idx < G.begin[n+1] ; t_idx ++)
{
node_t t = G.node_idx [t_idx];
if (G_Match[t] == gm_graph::NIL_NODE)
{
G_Suitor[t] = n ;
finished_prv = finished_prv && false ;
}
}
}
}
ATOMIC_AND(&finished, finished_prv);
}
#pragma omp parallel for
for (node_t t2 = 0; t2 < G.num_nodes(); t2 ++)
{
if ( !G_isLeft[t2] && (G_Match[t2] == gm_graph::NIL_NODE))
{
if (G_Suitor[t2] != gm_graph::NIL_NODE)
{
node_t n3;
n3 = G_Suitor[t2] ;
G_Suitor[n3] = t2 ;
G_Suitor[t2] = gm_graph::NIL_NODE ;
}
}
}
#pragma omp parallel
{
int32_t count_prv = 0 ;
count_prv = 0 ;
#pragma omp for nowait
for (node_t n4 = 0; n4 < G.num_nodes(); n4 ++)
{
if (G_isLeft[n4] && (G_Match[n4] == gm_graph::NIL_NODE))
{
if (G_Suitor[n4] != gm_graph::NIL_NODE)
{
node_t t5;
t5 = G_Suitor[n4] ;
G_Match[n4] = t5 ;
G_Match[t5] = n4 ;
count_prv = count_prv + 1 ;
}
}
}
ATOMIC_ADD<int32_t>(&count, count_prv);
}
}
gm_rt_cleanup();
return count;
}
#define GM_DEFINE_USER_MAIN 1
#if GM_DEFINE_USER_MAIN
// random_bipartite_matching -? : for how to run generated main program
int main(int argc, char** argv)
{
gm_default_usermain Main;
Main.declare_property("G_isLeft", GMTYPE_BOOL, true, false, GM_NODEPROP);
Main.declare_property("G_Match", GMTYPE_NODE, true, true, GM_NODEPROP);
Main.declare_return(GMTYPE_INT);
if (!Main.process_arguments(argc, argv)) {
return EXIT_FAILURE;
}
if (!Main.do_preprocess()) {
return EXIT_FAILURE;
}
Main.begin_usermain();
Main.set_return_i(random_bipartite_matching(
Main.get_graph(),
(bool*) Main.get_property("G_isLeft"),
(node_t*) Main.get_property("G_Match")
)
);
Main.end_usermain();
if (!Main.do_postprocess()) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
#endif
|
3cccc566dff27e6190b5e8dd7e74c8636a501212 | e5bda0857d7a51e59b9eacc1cb01af282e96dd53 | /main.cpp | 7f98708467f091a1bfa588c48c71ebf6eb2486a7 | [] | no_license | ChristianPPP/Taller-grupal-3 | 49ea354691c31d964fb6ecb09335cb5a7ac821a6 | e2b65bee29a7cef47887bcffe3ea2e0f987ecbd8 | refs/heads/master | 2023-03-17T18:07:30.768949 | 2021-03-04T15:43:21 | 2021-03-04T15:43:21 | 344,525,206 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 567 | cpp | main.cpp | #include <iostream>
#include <fstream>
#include <ctime>
using namespace std;
int main() {
int opc;
cout<<"***BIENVENIDO***\n";
do
{
cout<<"Menu\n";
cout<<"1.- Ejercicio 1\n";
cout<<"2.- Ejercicio 2\n";
cout<<"3.- Ejercicio 3\n";
cout<<"4.- Salir\n";
cout<<"OPCION: ";
cin>>opc;
switch (opc)
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
cout<<"Saliendo...\n";
break;
default:
cout<<"Opcion no valida.\n";
}
} while (opc!=4);
return 0;
} |
70212b40c2cf80bf4234972ea16878a11551ad6c | 4336088856769e66519a0d8ba22327bc8cbf0d98 | /src/ofApp.cpp | b2e9adc5a973c252e4e628e12eee43555021a500 | [] | no_license | SamuelLouisCampbell/ASCII_TEXT | 4804eb078fc80cc56d4f8d67bbb76d4a25083f14 | 364f4d1fd3f9b310948b2b47beab08e9086492de | refs/heads/master | 2023-03-10T11:07:56.851981 | 2021-03-03T18:28:01 | 2021-03-03T18:28:01 | 344,225,373 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,145 | cpp | ofApp.cpp | #include "ofApp.h"
#include <string>
void ofApp::grayScaleImage(ofImage& image)
{
for (size_t y = 0; y < image.getHeight(); y++)
{
for (size_t x = 0; x < image.getWidth(); x++)
{
ofColor newColor;
ofColor oldColor = image.getColor(x, y);
unsigned char grayColor = (oldColor.r + oldColor.g + oldColor.b) / 3;
newColor.set(grayColor, grayColor, grayColor,255);
image.setColor(x, y, newColor);
}
}
image.update();
}
void ofApp::pixellate(ofImage& image, size_t pixellationSizeX, size_t pixellationSizeY)
{
size_t width = image.getWidth();
size_t height = image.getHeight();
ofPixels pix = image.getPixels();
size_t pixStrideX = image.getWidth() / pixellationSizeX;
size_t pixStrideY = image.getHeight() / pixellationSizeY;
size_t subAreaSize = pixStrideX * pixStrideY;
ofImage img;
//pre allocate vector to recieve color samples.
std::vector<ofColor> sampledColors;
sampledColors.reserve(pixStrideX*pixStrideY);
//loop through large regions
for (size_t y = 0; y < image.getHeight(); y += pixStrideY)
{
for (size_t x = 0; x < image.getWidth(); x += pixStrideX)
{
//loop through small regions gather pixel data
size_t pixelsCounted = 0;
//make sure to clear vector each sub loop
sampledColors.clear();
for (size_t i = y; i < y + pixStrideY; i++)
{
for (size_t j = x; j < x + pixStrideX; j++)
{
//sample each pixel in this sub region;
if (j >= 0 && j < image.getWidth() &&
i >= 0 && i < image.getHeight())
{
pixelsCounted++;
sampledColors.push_back(image.getColor(j, i));
//sampledCols[i + j] = image.getColor(j, i);
}
}
}
//Add up the colors and divide by count to get average.
size_t sumColorR = 0;
size_t sumColorG = 0;
size_t sumColorB = 0;
for (auto& c : sampledColors)
{
sumColorR += c.r;
sumColorG += c.g;
sumColorB += c.b;
}
if (sampledColors.size() != 0)
{
sumColorR /= sampledColors.size();
sumColorG /= sampledColors.size();
sumColorB /= sampledColors.size();
}
ofColor newColor;
newColor.set(sumColorR, sumColorG, sumColorB);
//now set the color of that subregion.
for (size_t i = y; i < y + pixStrideY; i++)
{
for (size_t j = x; j < x + pixStrideX; j++)
{
if (j >= 0 && j < image.getWidth() &&
i >= 0 && i < image.getHeight())
{
image.setColor(j, i, newColor);
}
}
}
}
}
image.update();
}
void ofApp::asciiGlyphTable(const ofTrueTypeFont font,
std::vector<glyphShade>& glyphShades,
const char startRange,
const char endRange)
{
for (char i = startRange; i <= endRange; i++)
{
glyphShade gs;
gs.asciiDec = i;
std::string character;
character.push_back(i);
gs.glyph = font.getStringTexture(character);
ofFbo fb;
fb.allocate(gs.glyph.getWidth(), gs.glyph.getHeight(), GL_RGB);
fb.begin();
ofClear(0, 0, 0);
gs.glyph.draw(0,0);
fb.end();
ofPixels pixels;
fb.readToPixels(pixels);
size_t numpix = pixels.getWidth() * pixels.getHeight();
float sumpix = 0;
for (size_t y = 0; y < pixels.getHeight(); y++)
{
for (size_t x = 0; x < pixels.getWidth(); x++)
{
sumpix += pixels.getColor(x,y).getBrightness();
}
}
float total = float(sumpix / numpix);
//TEST
fb.draw((i-startRange) * 32,0);
gs.shade = total;
glyphShades.push_back(gs);
}
}
void ofApp::remap(std::vector<glyphShade>& glyphShades, float output_start, float output_end)
{
double slope = 1.0 * (output_end - output_start) / (glyphShades.back().shade - glyphShades.front().shade);
auto input_start = glyphShades.front().shade;
for (auto& shade : glyphShades)
{
shade.shade = output_start + slope * (shade.shade - input_start);
}
}
void ofApp::makeAsciiImage(std::vector<glyphShade>& glyphShades,
ofImage& image,
size_t pixellationSizeX,
size_t pixellationSizeY)
{
size_t pixStrideX = image.getWidth() / pixellationSizeX;
size_t pixStrideY = image.getHeight() / pixellationSizeY;
for (size_t y = 0; y < image.getHeight(); y += pixStrideY)
{
for (size_t x = 0; x < image.getWidth(); x += pixStrideX)
{
ofRectangle rect = { float(x), float(y), float(pixStrideX), float(pixStrideY) };
auto it = std::lower_bound(glyphShades.begin(), glyphShades.end(), image.getColor(x,y).getBrightness(), glyphShade());
int index = std::distance(glyphShades.begin(), it);
if (index >= 0 && index < glyphShades.size())
{
if (colorText)
{
ofSetColor(image.getColor(x, y));
}
glyphShades[index].glyph.draw(rect);
}
}
}
}
std::wstring ofApp::ExePath()
{
TCHAR buffer[MAX_PATH] = { 0 };
GetModuleFileName(NULL, buffer, MAX_PATH);
std::wstring::size_type pos = std::wstring(buffer).find_last_of(L"\\/");
return std::wstring(buffer).substr(0, pos);
}
std::string ofApp::ExePathS()
{
CHAR buffer[MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, buffer, MAX_PATH);
std::wstring::size_type pos = std::string(buffer).find_last_of("\\/");
return std::string(buffer).substr(0, pos);
}
//--------------------------------------------------------------
void ofApp::setup(){
//filepath
std::wstring path = ExePath();
std::string pathS = ExePathS();
//GUI
gui.setup();
//Video
player.load(pathS + "\\SanFran.mov");
player.play();
videoTexture.allocate(player.getWidth(), player.getHeight(), OF_PIXELS_RGBA);
//Image
images.push_back(ofImage(path + L"\\/statue.jpg"));
images.push_back(ofImage(path + L"\\/colorFace.jpg"));
images.push_back(ofImage(path + L"\\/face.jpg"));
images.push_back(ofImage(path + L"\\/trees.jpg"));
images.push_back(ofImage(path + L"\\/Cat.jpg"));
images.push_back(ofImage(path + L"\\/daisy.jpg"));
//Fonts
font.load(path + L"\\/consola.ttf", 32);
asciiGlyphTable(font, glyphShades, 32, 126);
std::sort(glyphShades.begin(), glyphShades.end());
//Now Remap to Char vals;
remap(glyphShades, 0.0f, 255.0f);
}
//--------------------------------------------------------------
void ofApp::update(){
if (isVideo)
{
player.update();
if (player.isFrameNew())
{
vidImage.setFromPixels(player.getPixels());
}
}
}
//--------------------------------------------------------------
void ofApp::draw() {
ofClear(0);
ofSetColor(255);
if (isVideo)
{
if (isGrayScale)
grayScaleImage(vidImage);
if (isPrePixellated)
pixellate(vidImage, gridDivisionsX, gridDivisionsY);
if (drawImageUnder)
vidImage.draw(0, 0);
if (drawAscii)
makeAsciiImage(glyphShades, vidImage, gridDivisionsX, gridDivisionsY);
}
else
{
if (images[currImage].isAllocated())
{
if (isGrayScale)
grayScaleImage(images[currImage]);
if (isPrePixellated)
pixellate(images[currImage], gridDivisionsX, gridDivisionsY);
if (drawImageUnder)
images[currImage].draw({ 0.0f, 0.0f, 0.0f });
if (drawAscii)
makeAsciiImage(glyphShades, images[currImage], gridDivisionsX, gridDivisionsY);
}
}
//displayframerate
std::stringstream ss;
ss << "Frame Rate : " << ofGetFrameRate() << "\nCurrent Image No : " << currImage;
font.drawString(ss.str(), 10, 1150);
//Gui stuff
gui.begin();
ImGui::InputInt("gridDivisionsX : ", &gridDivisionsX);
ImGui::InputInt("gridDivisionsY : ", &gridDivisionsY);
if (ImGui::Button("Show Video"))
{
isVideo = true;
}
if (ImGui::Button("Show Image"))
{
isVideo = false;
}
if (ImGui::Button("Next Image"))
{
currImage++;
if (currImage >= images.size())
{
currImage = 0;
}
}
if (ImGui::Button("GrayScale Image"))
{
isGrayScale = true;
}
if (ImGui::Button("Colour Image"))
{
isGrayScale = false;
}
if (ImGui::Button("Pre-Pixellate Image"))
{
isPrePixellated = true;
}
if (ImGui::Button("No Advance Pixellation"))
{
isPrePixellated = false;
}
if (ImGui::Button("Draw Image"))
{
drawImageUnder = true;
}
if (ImGui::Button("Don't Draw Image"))
{
drawImageUnder = false;
}
if (ImGui::Button("Draw ASCII"))
{
drawAscii = true;
}
if (ImGui::Button("Don't Draw ASCII"))
{
drawAscii = false;
}
if (ImGui::Button("Colour the text"))
{
colorText = true;
}
if (ImGui::Button("White Text"))
{
colorText = false;
}
gui.draw();
gui.end();
}
|
cb68c4b38a24f3a5efd1827f810d985883c188de | cbce021d8ea1f70bda0bcd37e3ec3c0aff1c417c | /Cyborg Date Type Sizes/main.cpp | 512f417226573af7278f741eca811fdbe86e6268 | [] | no_license | Shiladitya2002/Computer-Science-1 | 5cc0de2d42315369ff983e23a08d14e1bc04c139 | 2b4e6883f2a12cba45fad1c0b69988f8a4137948 | refs/heads/master | 2020-04-24T13:32:58.845624 | 2019-02-22T04:03:01 | 2019-02-22T04:03:01 | 171,991,466 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 783 | cpp | main.cpp | //********************************************************************************************************************
// Assignment 2: Cyborg Data Type Sizes
// Author: Shiladitya Dutta
// Description:
// Finds the amount of bytes taken up by char, int, float, and double and outputs values to the console.
//Status: Complete
//Date: January 22, 2018
//********************************************************************************************************************
#include <iostream>
using namespace std;
int main()
{
cout << "Char:" << sizeof(char)<< " bytes"<<endl;
cout << "Int: " << sizeof(int)<< " bytes"<<endl;
cout << "Float: " << sizeof(float)<< " bytes"<<endl;
cout << "Double: " << sizeof(double)<< " bytes"<<endl;
return 0;
}
|
ab94faf28fff5eacb5b78df4025e822f876bf47b | 231db5b6d629d456fbf0bc8eaf35dda5336b1e71 | /src/ui/InteractiveManipulator.hpp | 00d3285f33251219c48f5fbed29d044752be6667 | [] | no_license | HolySmoke86/blank | fc555ff0cbbb5b7ba2f77de5af79d5eef36607c6 | 28585b166ce3ad765ab613a375a97265449841e7 | refs/heads/master | 2020-12-24T16:24:00.119868 | 2018-11-17T12:10:22 | 2018-11-17T12:10:33 | 37,578,628 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 505 | hpp | InteractiveManipulator.hpp | #ifndef BLANK_UI_INTERACTIVEMANIPULATOR_HPP_
#define BLANK_UI_INTERACTIVEMANIPULATOR_HPP_
#include "../world/WorldManipulator.hpp"
#include "../audio/Sound.hpp"
namespace blank {
class Audio;
class Entity;
class SoundBank;
class InteractiveManipulator
: public WorldManipulator {
public:
explicit InteractiveManipulator(Audio &, const SoundBank &, Entity &);
void SetBlock(Chunk &, int, const Block &) override;
private:
Entity &player;
Audio &audio;
const SoundBank &sounds;
};
}
#endif
|
54525dd5cc265a69bd9176fcb1d1dbc9bee29e46 | 458e560245a971890d060354633748da9e3b5eed | /Clilindrul/src/Cerc.cpp | 7c412c00454d5fb07c5d3e249021c5d275860a0d | [] | no_license | vladstanoiu/Capitolul-6 | 7baead5e2302cb8f38ec29282754e6fd79ee90d4 | 3d7b035a0fccf87f53280344d234c037577476ec | refs/heads/master | 2020-09-27T02:44:31.644923 | 2019-12-17T17:03:32 | 2019-12-17T17:03:32 | 226,408,381 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 198 | cpp | Cerc.cpp | #include "Cerc.h"
#include "Cilindru.h"
#include <math.h>
Cerc::Cerc(double raza) : _raza(raza)
{
}
double Cerc::Arie()
{
return (3.14* pow(Get_raza(),2)) ;
}
Cerc::~Cerc()
{
//dtor
}
|
5d9283a09e3304cb3cd6de1cf050169235db6900 | ddd70b6df257a2cb3be8b468f355744965bf740e | /src/slg/film/imagepipeline/plugins/gammacorrection.cpp | ec3bc7c58d408754904e08bceae496a697d8d22d | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | MetaRabbit/LuxCore | 2e0e1c4cfc6865dc03d2750c26cca6281cfa541c | ee4d881d7ccf64fb6bb29845d7af0409ef8fd3b9 | refs/heads/master | 2020-05-17T18:44:07.182847 | 2019-04-28T09:10:50 | 2019-04-28T09:10:50 | 183,893,762 | 1 | 0 | Apache-2.0 | 2019-04-28T10:31:30 | 2019-04-28T10:31:29 | null | UTF-8 | C++ | false | false | 5,523 | cpp | gammacorrection.cpp | /***************************************************************************
* Copyright 1998-2018 by authors (see AUTHORS.txt) *
* *
* This file is part of LuxCoreRender. *
* *
* 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 <stdexcept>
#include <boost/foreach.hpp>
#include <boost/regex.hpp>
#include "slg/film/film.h"
#include "slg/kernels/kernels.h"
#include "slg/film/imagepipeline/plugins/gammacorrection.h"
#include "luxrays/kernels/kernels.h"
using namespace std;
using namespace luxrays;
using namespace slg;
//------------------------------------------------------------------------------
// Gamma correction plugin
//------------------------------------------------------------------------------
BOOST_CLASS_EXPORT_IMPLEMENT(slg::GammaCorrectionPlugin)
GammaCorrectionPlugin::GammaCorrectionPlugin(const float g, const u_int tableSize) {
gamma = g;
gammaTable.resize(tableSize, 0.f);
float x = 0.f;
const float dx = 1.f / tableSize;
for (u_int i = 0; i < tableSize; ++i, x += dx)
gammaTable[i] = powf(Clamp(x, 0.f, 1.f), 1.f / g);
#if !defined(LUXRAYS_DISABLE_OPENCL)
oclIntersectionDevice = NULL;
oclGammaTable = NULL;
applyKernel = NULL;
#endif
}
GammaCorrectionPlugin::~GammaCorrectionPlugin() {
#if !defined(LUXRAYS_DISABLE_OPENCL)
delete applyKernel;
if (oclIntersectionDevice)
oclIntersectionDevice->FreeBuffer(&oclGammaTable);
#endif
}
ImagePipelinePlugin *GammaCorrectionPlugin::Copy() const {
return new GammaCorrectionPlugin(gamma, gammaTable.size());
}
float GammaCorrectionPlugin::Radiance2PixelFloat(const float x) const {
// Very slow !
//return powf(Clamp(x, 0.f, 1.f), 1.f / 2.2f);
const u_int tableSize = gammaTable.size();
const int index = Clamp<int>(Floor2UInt(tableSize * Clamp(x, 0.f, 1.f)), 0, tableSize - 1);
return gammaTable[index];
}
//------------------------------------------------------------------------------
// CPU version
//------------------------------------------------------------------------------
void GammaCorrectionPlugin::Apply(Film &film, const u_int index) {
Spectrum *pixels = (Spectrum *)film.channel_IMAGEPIPELINEs[index]->GetPixels();
const u_int pixelCount = film.GetWidth() * film.GetHeight();
const bool hasPN = film.HasChannel(Film::RADIANCE_PER_PIXEL_NORMALIZED);
const bool hasSN = film.HasChannel(Film::RADIANCE_PER_SCREEN_NORMALIZED);
#pragma omp parallel for
for (
// Visual C++ 2013 supports only OpenMP 2.5
#if _OPENMP >= 200805
unsigned
#endif
int i = 0; i < pixelCount; ++i) {
if (film.HasSamples(hasPN, hasSN, i)) {
pixels[i].c[0] = Radiance2PixelFloat(pixels[i].c[0]);
pixels[i].c[1] = Radiance2PixelFloat(pixels[i].c[1]);
pixels[i].c[2] = Radiance2PixelFloat(pixels[i].c[2]);
}
}
}
//------------------------------------------------------------------------------
// OpenCL version
//------------------------------------------------------------------------------
#if !defined(LUXRAYS_DISABLE_OPENCL)
void GammaCorrectionPlugin::ApplyOCL(Film &film, const u_int index) {
if (!applyKernel) {
oclIntersectionDevice = film.oclIntersectionDevice;
film.ctx->SetVerbose(true);
oclIntersectionDevice->AllocBufferRO(&oclGammaTable, &gammaTable[0], gammaTable.size() * sizeof(float), "Gamma table");
film.ctx->SetVerbose(false);
// Compile sources
const double tStart = WallClockTime();
cl::Program *program = ImagePipelinePlugin::CompileProgram(
film,
"-D LUXRAYS_OPENCL_KERNEL -D SLG_OPENCL_KERNEL",
slg::ocl::KernelSource_utils_funcs +
slg::ocl::KernelSource_plugin_gammacorrection_funcs,
"GammaCorrectionPlugin");
SLG_LOG("[GammaCorrectionPlugin] Compiling GammaCorrectionPlugin_Apply Kernel");
applyKernel = new cl::Kernel(*program, "GammaCorrectionPlugin_Apply");
delete program;
// Set kernel arguments
u_int argIndex = 0;
applyKernel->setArg(argIndex++, film.GetWidth());
applyKernel->setArg(argIndex++, film.GetHeight());
applyKernel->setArg(argIndex++, *(film.ocl_IMAGEPIPELINE));
applyKernel->setArg(argIndex++, *oclGammaTable);
applyKernel->setArg(argIndex++, (u_int)gammaTable.size());
const double tEnd = WallClockTime();
SLG_LOG("[GammaCorrectionPlugin] Kernels compilation time: " << int((tEnd - tStart) * 1000.0) << "ms");
}
oclIntersectionDevice->GetOpenCLQueue().enqueueNDRangeKernel(*applyKernel,
cl::NullRange, cl::NDRange(RoundUp(film.GetWidth() * film.GetHeight(), 256u)), cl::NDRange(256));
}
#endif
|
e0d6be2add4a87d4478299bb42299ae0991f931d | b73b4cffebc5499b233e65552bec88fae172550d | /uva496.cpp | f6c16c67caec7a9d61caaf79140b56ddd4e5d7d7 | [] | no_license | yunomeow/UVaPractice | f01bbb20da270b17a27e4e52314683b5860c4532 | 1139ce17195c4bef810a261fee4cc454815d9c01 | refs/heads/master | 2020-03-27T23:54:12.642666 | 2018-09-04T14:58:06 | 2018-09-04T14:58:06 | 147,356,848 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,637 | cpp | uva496.cpp | #include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
#include <set>
using namespace std;
int main (){
string str;
vector<int> A,B;
int tmp;
while(getline(cin,str)){
istringstream iss(str);
A.clear();
B.clear();
while(iss >> tmp){
A.push_back(tmp);
}
getline(cin,str);
istringstream iss2(str);
while(iss2 >> tmp){
B.push_back(tmp);
}
sort(A.begin(),A.end());
sort(B.begin(),B.end());
int flag;
//equals
flag = 1;
if(A.size() != B.size())flag = 0;
else{
for(int i=0;i<A.size();i++){
if(A[i] != B[i])flag = 0;
}
}
if(flag == 1){cout << "A equals B\n";continue;}
//B in A
int now = 0;
if(A.size() > B.size()){
for(int i=0;i<A.size();i++){
if(A[i] == B[now])now++;
}
if(now == B.size()){cout << "B is a proper subset of A\n";continue;}
}
//A in B
now = 0;
if(B.size() > A.size()){
for(int i=0;i<B.size();i++){
if(B[i] == A[now])now++;
}
if(now == A.size()){cout << "A is a proper subset of B\n";continue;}
}
set<int> s;
for(int i=0;i<B.size();i++){
s.insert(B[i]);
}
for(int i=0;i<A.size();i++){
s.insert(A[i]);
}
if(s.size() == A.size() + B.size()){cout << "A and B are disjoint\n";continue;}
cout << "I'm confused!\n";
}
return 0;
}
|
d7e1183e5fe4c25667d9169a2bc0fe9d4e42e349 | d263e9ad5c18c95a44d26af8c9e1a06ed7ba660f | /include/SocketIo/PacketReceiverAsyncMCast.hpp | aa562e32d3eb80a00a36bd398878a3ffd8d04fdc | [
"BSL-1.0"
] | permissive | mlbrock/MlbDev | 3783d148e7934ce84d26643c879d33a3aa1935a2 | d499f66c7f672f8761d81a04f00f87a0808f9ff1 | refs/heads/develop | 2022-10-28T18:09:17.473659 | 2022-10-18T08:28:44 | 2022-10-18T08:28:44 | 15,541,112 | 2 | 2 | null | 2018-04-23T21:50:46 | 2013-12-31T02:18:56 | C++ | UTF-8 | C++ | false | false | 4,015 | hpp | PacketReceiverAsyncMCast.hpp | // ////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////
// SocketIo Include File
// ////////////////////////////////////////////////////////////////////////////
/*
File Name : %M%
File Version : %I%
Last Extracted : %D% %T%
Last Updated : %E% %U%
File Description : Definition of the PacketReceiverAsyncMCast class.
Revision History : 2008-12-20 --- Creation.
Michael L. Brock
Copyright Michael L. Brock 2008 - 2018.
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)
*/
// ////////////////////////////////////////////////////////////////////////////
#ifndef HH__MLB__SocketIo__PacketReceiverAsyncMCast_hpp__HH
#define HH__MLB__SocketIo__PacketReceiverAsyncMCast_hpp__HH 1
// ////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////
// Required include files...
// ////////////////////////////////////////////////////////////////////////////
#include <SocketIo/PacketReceiverMCast.hpp>
#include <SocketIo/SocketBuffer.hpp>
// ////////////////////////////////////////////////////////////////////////////
namespace MLB {
namespace SocketIo {
// ////////////////////////////////////////////////////////////////////////////
class PacketReceiverAsyncMCast : public PacketReceiverMCast {
public:
PacketReceiverAsyncMCast(std::size_t buffer_size,
boost::shared_ptr<char> &buffer_sptr, boost::asio::io_service &io_service,
const std::string &mc_group, IpPortType ip_port,
const std::string &host_interface = "");
PacketReceiverAsyncMCast(std::size_t buffer_size,
boost::shared_ptr<char> &buffer_sptr, boost::asio::io_service &io_service,
const std::string &mc_group, const std::string &ip_port,
const std::string &host_interface = "");
PacketReceiverAsyncMCast(std::size_t buffer_size,
boost::shared_ptr<char> &buffer_sptr, boost::asio::io_service &io_service,
const SocketSpec &socket_spec);
PacketReceiverAsyncMCast(std::size_t buffer_size, char *buffer_ptr,
boost::asio::io_service &io_service, const std::string &mc_group,
IpPortType ip_port, const std::string &host_interface = "");
PacketReceiverAsyncMCast(std::size_t buffer_size, char *buffer_ptr,
boost::asio::io_service &io_service, const std::string &mc_group,
const std::string &ip_port, const std::string &host_interface = "");
PacketReceiverAsyncMCast(std::size_t buffer_size, char *buffer_ptr,
boost::asio::io_service &io_service, const SocketSpec &socket_spec);
PacketReceiverAsyncMCast(std::size_t buffer_size,
boost::asio::io_service &io_service, const std::string &mc_group,
IpPortType ip_port, const std::string &host_interface = "");
PacketReceiverAsyncMCast(std::size_t buffer_size,
boost::asio::io_service &io_service, const std::string &mc_group,
const std::string &ip_port, const std::string &host_interface = "");
PacketReceiverAsyncMCast(std::size_t buffer_size,
boost::asio::io_service &io_service, const SocketSpec &socket_spec);
virtual ~PacketReceiverAsyncMCast();
bool IsRunning() const;
bool Run();
bool RecvFromAsync(const boost::system::error_code& error,
std::size_t bytes_received);
protected:
bool is_running_;
boost::asio::ip::udp::endpoint sender_endpoint_;
SocketBuffer buffer_;
virtual bool RunImpl();
virtual bool RecvFromAsyncImpl(const boost::system::error_code &error,
std::size_t bytes_received);
void Schedule();
private:
PacketReceiverAsyncMCast(const PacketReceiverAsyncMCast &other);
PacketReceiverAsyncMCast & operator = (const PacketReceiverAsyncMCast &other);
};
// ////////////////////////////////////////////////////////////////////////////
} // namespace SocketIo
} // namespace MLB
#endif // #ifndef HH__MLB__SocketIo__PacketReceiverAsyncMCast_hpp__HH
|
fceaed5279e75d4ca455bf194f04e931311979c7 | eba2fadea4972b682edce710300ea280a210eee2 | /design/707.DesignLinkedList.cc | 39d3b27889a6c4fcca814ac800fe102884348e8f | [] | no_license | seesealonely/leetcode | 33b876968f08a0ddd00adc714d03ad6e4c0bfae9 | 1a371f3ad438bb70bf7a685843097535f5fc1c5d | refs/heads/master | 2023-08-30T21:22:07.456531 | 2023-08-30T20:15:49 | 2023-08-30T20:15:49 | 87,525,147 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,868 | cc | 707.DesignLinkedList.cc | /*
Design your implementation of the linked list. You can choose to use a singly or doubly linked list.
A node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer/reference to the next node.
If you want to use the doubly linked list, you will need one more attribute prev to indicate the previous node in the linked list. Assume all nodes in the linked list are 0-indexed.
Implement the MyLinkedList class:
MyLinkedList() Initializes the MyLinkedList object.
int get(int index) Get the value of the indexth node in the linked list. If the index is invalid, return -1.
void addAtHead(int val) Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
void addAtTail(int val) Append a node of value val as the last element of the linked list.
void addAtIndex(int index, int val) Add a node of value val before the indexth node in the linked list. If index equals the length of the linked list, the node will be appended to the end of the linked list. If index is greater than the length, the node will not be inserted.
void deleteAtIndex(int index) Delete the indexth node in the linked list, if the index is valid.
Example 1:
Input
["MyLinkedList", "addAtHead", "addAtTail", "addAtIndex", "get", "deleteAtIndex", "get"]
[[], [1], [3], [1, 2], [1], [1], [1]]
Output
[null, null, null, null, 2, null, 3]
Explanation
MyLinkedList myLinkedList = new MyLinkedList();
myLinkedList.addAtHead(1);
myLinkedList.addAtTail(3);
myLinkedList.addAtIndex(1, 2); // linked list becomes 1->2->3
myLinkedList.get(1); // return 2
myLinkedList.deleteAtIndex(1); // now the linked list is 1->3
myLinkedList.get(1); // return 3
Constraints:
0 <= index, val <= 1000
Please do not use the built-in LinkedList library.
At most 2000 calls will be made to get, addAtHead, addAtTail, addAtIndex and deleteAtIndex.
*/
#include"head.h"
class MyLinkedList {
public:
class LinkedList {
public:
int val;
LinkedList *next;
LinkedList(int val):val(val),next(NULL){}
};
MyLinkedList() {
_head=new LinkedList(0);
_size=0;
}
int get(int index) {
if(index>_size-1||index<0)
return -1;
LinkedList *cur=_head->next;
while(index--)
cur=cur->next;
return cur->val;
}
void addAtHead(int val) {
LinkedList *head=new LinkedList(val);
head->next=_head->next;
_head->next=head;
_size++;
}
void addAtTail(int val) {
LinkedList *tail=new LinkedList(val);
LinkedList *cur=_head;
while(cur->next)
cur=cur->next;
cur->next=tail;
++_size;
}
void addAtIndex(int index, int val) {
if(index>_size)
return;
LinkedList *node=new LinkedList(val);
LinkedList*cur=_head;
while(index--)
cur=cur->next;
node->next=cur->next;
cur->next=node;
_size++;
}
void deleteAtIndex(int index) {
if(index>=_size||index<0)
return ;
LinkedList *cur=_head;
while(index--)
cur=cur->next;
LinkedList *tmp=cur->next;
cur->next=cur->next->next;
delete tmp;
_size--;
}
private:
LinkedList *_head;
int _size;
};
/**
* Your MyLinkedList object will be instantiated and called as such:
* MyLinkedList* obj = new MyLinkedList();
* int param_1 = obj->get(index);
* obj->addAtHead(val);
* obj->addAtTail(val);
* obj->addAtIndex(index,val);
* obj->deleteAtIndex(index);
*/
int main()
{
MyLinkedList myLinkedList = MyLinkedList();
myLinkedList.addAtHead(1);
myLinkedList.addAtTail(3);
myLinkedList.addAtIndex(1, 2); // linked list becomes 1->2->3
myLinkedList.get(1); // return 2
myLinkedList.deleteAtIndex(1); // now the linked list is 1->3
myLinkedList.get(1); // return 3
return 0;
}
|
1b56739d6cb4316a9afddb033e82ddd2c6ad30ad | a446f25d0a16e82224ba9807a1ec5dc7e45155c3 | /tree/inorder.cpp | f6f5ec8b6e922dceee1a827bc515204a8a7f28b5 | [] | no_license | sahil2306/Data-Structures-Algorithms | 28b346add379d1a8ac7fa68201e86ea65a5056ec | d42f61cea65eea6e7b22e9c9b636293aa3e060ef | refs/heads/main | 2023-06-04T22:50:35.843400 | 2021-06-18T18:11:08 | 2021-06-18T18:11:08 | 328,125,553 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,018 | cpp | inorder.cpp | //Recursive
class Solution
{
public:
//Function to return a list containing the inorder traversal of the tree.
vector<int> inOrder(Node* root)
{
// Your code here
vector <int> ans;
if (root == NULL){
return ans;
}
vector <int> x;
x = inOrder(root->left);
ans.insert(ans.end(),x.begin(),x.end());
ans.push_back(root->data);
x = inOrder(root->right);
ans.insert(ans.end(),x.begin(),x.end());
return ans;
}
};
//Iterative
vector<int> inOrder(Node* root)
{
//code here
stack<Node *> st;
Node *curr = root;
vector<int> ans;
while(curr!=NULL || st.empty()==false){
while(curr!=NULL){
st.push(curr);
curr = curr->left;
}
curr = st.top();
st.pop();
ans.push_back(curr->data);
curr=curr->right;
}
return ans;
} |
73043d308b060bdb22c687668d961332b5b0e1ec | 051482d24cf3d5dbc4676ad0ce6ab32e64e968da | /MOGoap/Source/MOGoap/Goap/Core/MOGoapNode.cpp | adf56308277b28e28dd2631734a02c98e958e5bd | [] | no_license | Hengle/GoapSystem | ee449e4b9b7b9f71327ec46381cd4ba56a6d8072 | fd2699f4c98ffec968d31906161693e6a4551c48 | refs/heads/main | 2023-03-16T02:20:11.452675 | 2020-11-08T09:20:36 | 2020-11-08T09:20:36 | null | 0 | 0 | null | null | null | null | GB18030 | C++ | false | false | 4,917 | cpp | MOGoapNode.cpp | #include "MOGoapNode.h"
#include "MOGoapPlanner.h"
#include "MOGoapAgent.h"
#include "MOGoapState.h"
#include "MOGoapAction.h"
std::stack<MOGoapNode*> MOGoapNode::cachedNodes;
MOGoapNode::MOGoapNode()
{
g = 0;
h = 0;
}
MOGoapNode::MOGoapNode(MOGoapAction* a)
{
}
void MOGoapNode::Init(MOGoapPlanner* planner, MOGoapState* newgoal, MOGoapNode* parent, MOGoapAction* action, MOGoapState* settings)
{
ExpandList.clear();
this->Planner = planner;
this->Parent = parent;
this->NodeAction = action;
this->ActionSettings = nullptr;
if (settings != nullptr)
this->ActionSettings = settings->Clone();
g = 0;
h = 0;
if (parent != nullptr)
{
NodeState = parent->GetWorldState()->Clone();
g = parent->GetPathCost();
}
else
{
NodeState = planner->GetCurrentAgent()->GetMemory()->GetWorldState()->Clone();
}
//在当前状态中保存设置
NodeState->AddFromState(settings);
if (action != nullptr)
{
NodeGoalState = MOGoapState::Instantiate(newgoal);
MOGoapActionStackData stackData;
stackData.currentState = NodeState;
stackData.goalState = NodeGoalState;
stackData.next = NodeAction;
stackData.agent = planner->GetCurrentAgent();
stackData.settings = ActionSettings;
Preconditions = NodeAction->GetPreconditions(stackData);
Effects = NodeAction->GetEffects(stackData);
// addding the action's cost to the node's total cost
g += NodeAction->GetCost(stackData);
// adding the action's effects to the current node's state
NodeState->AddFromState(Effects);
// removes from goal all the conditions that are now fullfiled in the action's effects
NodeGoalState->ReplaceWithMissingDifference(Effects);
// add all preconditions of the current action to the goal
NodeGoalState->AddFromState(Preconditions);
}
else
{
NodeGoalState = newgoal;
}
h = NodeGoalState->Count();
cost = g + h * heuristicMultiplier;
MOGoapState* diff = MOGoapState::Instantiate();
MOGoapState* memory = planner->GetCurrentAgent()->GetMemory()->GetWorldState();
NodeGoalState->MissingDifference(memory,diff);
GoalMergeWithWorld = diff;
}
MOGoapNode* MOGoapNode::Instantiate(MOGoapPlanner* planner, MOGoapState* newgoal, MOGoapNode* parent, MOGoapAction* action, MOGoapState* actionSettings)
{
MOGoapNode* node = nullptr;
if (cachedNodes.empty())
{
node = new MOGoapNode();
}
else
{
node = cachedNodes.top();
cachedNodes.pop();
}
node->Init(planner, newgoal, parent, action, actionSettings);
return node;
}
void MOGoapNode::Recycle()
{
NodeState->Recycle();
NodeState = nullptr;
NodeGoalState->Recycle();
NodeGoalState = nullptr;
cachedNodes.push(this);
}
bool MOGoapNode::operator<(const MOGoapNode& n) const
{
return GetF() < n.GetF();
}
bool MOGoapNode::IsGoal(MOGoapState* goal)
{
return GoalMergeWithWorld->Count() <= 0;
}
std::vector<MOGoapNode*> MOGoapNode::Expand()
{
ExpandList.clear();
auto agent = Planner->GetCurrentAgent();
auto actions = agent->GetActionsSet();
MOGoapActionStackData stackData;
stackData.currentState = NodeState;
stackData.goalState = NodeGoalState;
stackData.next = NodeAction;
stackData.agent = agent;
stackData.settings = nullptr;
for (int index = actions.size() - 1; index >= 0; --index)
{
auto possibleAction = actions[index];
possibleAction->Precalculations(stackData);
auto settingsList = possibleAction->GetSettings(stackData);
if (settingsList.size() == 0)
{
auto precond = possibleAction->GetPreconditions(stackData);
auto effects = possibleAction->GetEffects(stackData);
if (effects->HasAny(NodeGoalState) &&
!NodeGoalState->HasAnyConflict(effects, precond) &&
!NodeGoalState->HasAnyConflict(effects) &&
possibleAction->CheckProceduralCondition(stackData))
{
auto newGoal = NodeGoalState;
ExpandList.push_back(Instantiate(Planner, newGoal, this, possibleAction, nullptr));
}
}
else {
for (auto settings : settingsList)
{
stackData.settings = settings;
auto precond = possibleAction->GetPreconditions(stackData);
auto effects = possibleAction->GetEffects(stackData);
if (effects->HasAny(NodeGoalState) &&
!NodeGoalState->HasAnyConflict(effects, precond) &&
!NodeGoalState->HasAnyConflict(effects) &&
possibleAction->CheckProceduralCondition(stackData))
{
auto newGoal = NodeGoalState;
ExpandList.push_back(Instantiate(Planner, newGoal, this, possibleAction, settings));
}
}
}
}
return ExpandList;
}
std::list<MOGoapActionState*> MOGoapNode::CalculatePath()
{
std::list<MOGoapActionState*> result;
auto node = this;
while (node->GetParent() != nullptr)
{
result.push_back(new MOGoapActionState(node->NodeAction, node->ActionSettings));
node = node->GetParent();
}
return result;
}
bool MOGoapNode::operator!=(const MOGoapNode& n) const
{
return !(*this == n);
}
bool MOGoapNode::operator==(const MOGoapNode& n) const
{
return NodeAction == n.GetAction();
}
|
978c3175596d112d0672db8fd6160395dd96c8fe | faeca7997c9bae0ee9c3597e42b27a96f37f5dbe | /Chapter07/Ch7_Exc01/Ch7_Exc01.cpp | 74db4b35ae388d0c6b48174bb540571d1f45b240 | [] | no_license | dimpellos/Cplusplus_Primer_- | c726898c5699a349eb3158c724d2734fe4a3ae2b | 756cb1684ea62d9217f769e8e49984da1db37972 | refs/heads/master | 2020-07-25T21:49:03.229883 | 2019-10-18T12:35:36 | 2019-10-18T12:35:36 | 208,430,960 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 483 | cpp | Ch7_Exc01.cpp | #include <iostream>
using namespace std;
double harmonic_mean(int x, int y);
int main()
{
int x, y;
do {
cout << endl << "\nEnter x:";
cin >> x;
cout << "Enter y:";
cin >> y;
if (!(x && y))
break;
cout << harmonic_mean(x, y);
} while (1);
cout << endl << "You provided a zero. Zero as input terminates the program." << endl;
std::cout << "Chapter 7 Excercise 1" << endl;
}
double harmonic_mean(int x, int y)
{
return 2.0 * (x * y) / (x + y);
}
|
9a50b73155192547afba884c76a48eaa965c7955 | 4b9091d96146b1a664f41dc9a6a217552f172dea | /l.cpp | e0040ccb9cfd35a67ac033759fc73b3c7e22c733 | [] | no_license | AnanyaSingh002/Assignment3 | 8b33a5638526d3eb6ccbfad4b22bd2f48a70f6db | de4b6f55bfb4a30ed1f0ffccec41942a0f527ba9 | refs/heads/main | 2023-01-13T00:16:22.421353 | 2020-11-02T05:38:34 | 2020-11-02T05:38:34 | 292,343,757 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 632 | cpp | l.cpp | *Write a recursive function stringReverse that takes a string and a starting subscript as arguments, prints
the string backward and returns nothing. The function should stop processing and return when the end
of the string is encountered. Note that like an array the square brackets ([]) operator can be used to
iterate through the characters in a string.*/
#include <bits/stdc++.h>
using namespace std;
void reverse(string str)
{
if(str.size() == 0)
{
return;
}
reverse(str.substr(1));
cout << str[0];
}
int main()
{
string a = "I am a good girl";
cout<<a<<endl;
reverse(a);
return 0;
}
|
2bf2458e4ca4d580a9aed0edf7e320c98e9e6f4f | 3851a1ed004ad01f313de7717346320e524e9965 | /include/multicontact-api/scenario/contact-phase.hpp | 00cf03d58059bbca3c10a8a19a12f12b18639576 | [
"BSD-2-Clause"
] | permissive | pFernbach/multicontact-api | d980886eefa569b34326065e342f25277254cb0a | efe4cf25d37aba9184875df6036a864d7aa34b88 | refs/heads/master | 2021-12-14T21:51:24.285591 | 2019-05-20T08:15:02 | 2019-05-20T08:15:02 | 200,243,002 | 1 | 0 | NOASSERTION | 2019-08-02T13:52:06 | 2019-08-02T13:52:05 | null | UTF-8 | C++ | false | false | 6,292 | hpp | contact-phase.hpp | // Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>
#ifndef __multicontact_api_scenario_contact_phase_hpp__
#define __multicontact_api_scenario_contact_phase_hpp__
#include "multicontact-api/scenario/fwd.hpp"
#include "multicontact-api/scenario/contact-patch.hpp"
#include "multicontact-api/serialization/archive.hpp"
#include "multicontact-api/serialization/eigen-matrix.hpp"
#include "multicontact-api/serialization/spatial.hpp"
#include "multicontact-api/geometry/second-order-cone.hpp"
#include "multicontact-api/geometry/linear-cone.hpp"
#include "multicontact-api/container/ref.hpp"
#include <boost/array.hpp>
namespace multicontact_api
{
namespace scenario
{
template<typename _Scalar, int _dim>
struct ContactPhaseTpl : public serialization::Serializable< ContactPhaseTpl<_Scalar,_dim> >
{
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef _Scalar Scalar;
typedef ContactPatchTpl<Scalar> ContactPatch;
typedef boost::array<ContactPatch,_dim> ContactPatchArray;
typedef std::vector< container::comparable_reference_wrapper<ContactPatch> > ContactPatchVector;
typedef std::vector< container::comparable_reference_wrapper<ContactPatch const> > ConstContactPatchVector;
typedef geometry::SecondOrderCone<_Scalar,6> SOC6;
typedef geometry::WrenchConeTpl<_Scalar> WrenchCone;
typedef Eigen::DenseIndex Index;
typedef typename ContactPatch::SE3 SE3;
typedef Eigen::Matrix<double,6,Eigen::Dynamic> Matrix6x;
enum { dim = _dim };
/// \brief Default constructor
ContactPhaseTpl()
: m_sowc_placement(SE3::Identity())
{}
/// \brief Copy constructor
template<typename S2>
ContactPhaseTpl(const ContactPhaseTpl<S2,dim> & other)
: m_contact_patches(other.m_contact_patches)
, m_sowc(other.m_sowc)
, m_sowc_placement(other.m_sowc_placement)
, m_lwc(other.m_lwc)
{}
const ContactPatchArray & contact_patches() const { return m_contact_patches; }
ContactPatchArray & contact_patches() { return m_contact_patches; }
/// \Returns a reference of the second order wrench cone
const SOC6 & sowc() const { return m_sowc; }
SOC6 & sowc() { return m_sowc; }
const SE3 & sowcPlacement() const { return m_sowc_placement; }
SE3 & sowcPlacement() { return m_sowc_placement; }
const Matrix6x & doubleDescription() const { return m_double_description; }
Matrix6x & doubleDescription() { return m_double_description; }
const WrenchCone & lwc() const { return m_lwc; }
WrenchCone & lwc() { return m_lwc; }
/// \returns the number of active patches
Index numActivePatches() const
{
Index num_active = 0;
for(typename ContactPatchArray::const_iterator it = m_contact_patches.begin();
it != m_contact_patches.end(); ++it)
if(it->active()) num_active++;
return num_active;
}
/// \returns the number of inactive patches
Index numInactivePatches() const
{ return dim - numActivePatches(); }
template<typename S2>
bool operator==(const ContactPhaseTpl<S2,dim> & other) const
{
return
m_contact_patches == other.m_contact_patches
&& m_lwc == other.m_lwc
&& m_sowc == other.m_sowc
;
}
template<typename S2>
bool operator!=(const ContactPhaseTpl<S2,dim> & other) const
{ return !(*this == other); }
ContactPatchArray m_contact_patches; // TODO: set protected
///
/// \brief Returns the first active patch.
///
/// \remark This method is useful one looks for the lonely active patch.
///
/// \returns the first active patch.
///
const ContactPatch & getActivePatch() const
{
for(typename ContactPatchArray::const_iterator it = m_contact_patches.begin();
it != m_contact_patches.end(); ++it)
if(it->active()) return *it;
}
ContactPatch & getActivePatch()
{ return const_cast<ContactPatch &>(static_cast<const ContactPhaseTpl*>(this)->getActivePatch()); }
ContactPatchVector getActivePatches()
{
ContactPatchVector res; res.reserve((size_t)dim);
for(typename ContactPatchArray::iterator it = m_contact_patches.begin();
it != m_contact_patches.end(); ++it)
if(it->active()) res.push_back(typename ContactPatchVector::value_type(*it));
return res;
}
protected:
/// \brief Second Order Wrench Cone (SOWC) representing the Minkoski sum of the patch linear wrench cone.
SOC6 m_sowc;
SE3 m_sowc_placement;
Matrix6x m_double_description;
/// \brief Linear Wrench Cone (LWC) representing the Minkoski sum of the patch linear wrench cone.
WrenchCone m_lwc;
private:
// Serialization of the class
friend class boost::serialization::access;
template<class Archive>
void save(Archive & ar, const unsigned int /*version*/) const
{
for(typename ContactPatchArray::const_iterator it = m_contact_patches.begin();
it != m_contact_patches.end(); ++it)
ar & boost::serialization::make_nvp("contact_patch",*it);
ar & boost::serialization::make_nvp("lwc",m_lwc);
ar & boost::serialization::make_nvp("sowc",m_sowc);
ar & boost::serialization::make_nvp("sowc_placement",m_sowc_placement);
ar & boost::serialization::make_nvp("double_description",m_double_description);
}
template<class Archive>
void load(Archive & ar, const unsigned int /*version*/)
{
for(typename ContactPatchArray::iterator it = m_contact_patches.begin();
it != m_contact_patches.end(); ++it)
ar >> boost::serialization::make_nvp("contact_patch",*it);
ar >> boost::serialization::make_nvp("lwc",m_lwc);
ar >> boost::serialization::make_nvp("sowc",m_sowc);
ar >> boost::serialization::make_nvp("sowc_placement",m_sowc_placement);
ar >> boost::serialization::make_nvp("double_description",m_double_description);
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
}
}
#endif // ifndef __multicontact_api_scenario_contact_phase_hpp__
|
51ef3e34fbef3116101f237ca2ba0b50f4682620 | 4749b64b52965942f785b4e592392d3ab4fa3cda | /mojo/application_manager/application_manager.cc | 382cb035bcd005c4d7655479785ef39fa1c4f0f9 | [
"BSD-3-Clause"
] | permissive | crosswalk-project/chromium-crosswalk-efl | 763f6062679727802adeef009f2fe72905ad5622 | ff1451d8c66df23cdce579e4c6f0065c6cae2729 | refs/heads/efl/crosswalk-10/39.0.2171.19 | 2023-03-23T12:34:43.905665 | 2014-12-23T13:44:34 | 2014-12-23T13:44:34 | 27,142,234 | 2 | 8 | null | 2014-12-23T06:02:24 | 2014-11-25T19:27:37 | C++ | UTF-8 | C++ | false | false | 10,819 | cc | application_manager.cc | // 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 "mojo/application_manager/application_manager.h"
#include <stdio.h>
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "mojo/application_manager/application_loader.h"
#include "mojo/common/common_type_converters.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/interfaces/application/application.mojom.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
#include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
namespace mojo {
namespace {
// Used by TestAPI.
bool has_created_instance = false;
class StubServiceProvider : public InterfaceImpl<ServiceProvider> {
public:
ServiceProvider* GetRemoteServiceProvider() { return client(); }
private:
virtual void ConnectToService(const String& service_name,
ScopedMessagePipeHandle client_handle)
MOJO_OVERRIDE {}
};
} // namespace
ApplicationManager::Delegate::~Delegate() {}
class ApplicationManager::LoadCallbacksImpl
: public ApplicationLoader::LoadCallbacks {
public:
LoadCallbacksImpl(base::WeakPtr<ApplicationManager> manager,
const GURL& requested_url,
const GURL& requestor_url,
ServiceProviderPtr service_provider)
: manager_(manager),
requested_url_(requested_url),
requestor_url_(requestor_url),
service_provider_(service_provider.Pass()) {}
private:
virtual ~LoadCallbacksImpl() {}
// LoadCallbacks implementation
virtual ScopedMessagePipeHandle RegisterApplication() OVERRIDE {
ScopedMessagePipeHandle shell_handle;
if (manager_) {
manager_->RegisterLoadedApplication(requested_url_,
requestor_url_,
service_provider_.Pass(),
&shell_handle);
}
return shell_handle.Pass();
}
virtual void LoadWithContentHandler(const GURL& content_handler_url,
URLResponsePtr url_response) OVERRIDE {
if (manager_) {
manager_->LoadWithContentHandler(requested_url_,
requestor_url_,
content_handler_url,
url_response.Pass(),
service_provider_.Pass());
}
}
base::WeakPtr<ApplicationManager> manager_;
GURL requested_url_;
GURL requestor_url_;
ServiceProviderPtr service_provider_;
};
class ApplicationManager::ShellImpl : public InterfaceImpl<Shell> {
public:
ShellImpl(ApplicationManager* manager, const GURL& url)
: manager_(manager), url_(url) {}
virtual ~ShellImpl() {}
void ConnectToClient(const GURL& requestor_url,
ServiceProviderPtr service_provider) {
client()->AcceptConnection(String::From(requestor_url),
service_provider.Pass());
}
// ServiceProvider implementation:
virtual void ConnectToApplication(
const String& app_url,
InterfaceRequest<ServiceProvider> in_service_provider) OVERRIDE {
ServiceProviderPtr out_service_provider;
out_service_provider.Bind(in_service_provider.PassMessagePipe());
manager_->ConnectToApplication(
app_url.To<GURL>(), url_, out_service_provider.Pass());
}
const GURL& url() const { return url_; }
private:
virtual void OnConnectionError() OVERRIDE {
manager_->OnShellImplError(this);
}
ApplicationManager* const manager_;
const GURL url_;
DISALLOW_COPY_AND_ASSIGN(ShellImpl);
};
struct ApplicationManager::ContentHandlerConnection {
ContentHandlerConnection(ApplicationManager* manager,
const GURL& content_handler_url) {
ServiceProviderPtr service_provider;
BindToProxy(&service_provider_impl, &service_provider);
manager->ConnectToApplication(
content_handler_url, GURL(), service_provider.Pass());
mojo::ConnectToService(service_provider_impl.client(), &content_handler);
}
StubServiceProvider service_provider_impl;
ContentHandlerPtr content_handler;
};
// static
ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager)
: manager_(manager) {
}
ApplicationManager::TestAPI::~TestAPI() {
}
bool ApplicationManager::TestAPI::HasCreatedInstance() {
return has_created_instance;
}
bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const {
return manager_->url_to_shell_impl_.find(url) !=
manager_->url_to_shell_impl_.end();
}
ApplicationManager::ApplicationManager()
: delegate_(NULL),
interceptor_(NULL),
weak_ptr_factory_(this) {
}
ApplicationManager::~ApplicationManager() {
STLDeleteValues(&url_to_content_handler_);
TerminateShellConnections();
STLDeleteValues(&url_to_loader_);
STLDeleteValues(&scheme_to_loader_);
}
void ApplicationManager::TerminateShellConnections() {
STLDeleteValues(&url_to_shell_impl_);
}
// static
ApplicationManager* ApplicationManager::GetInstance() {
static base::LazyInstance<ApplicationManager> instance =
LAZY_INSTANCE_INITIALIZER;
has_created_instance = true;
return &instance.Get();
}
void ApplicationManager::ConnectToApplication(
const GURL& url,
const GURL& requestor_url,
ServiceProviderPtr service_provider) {
URLToShellImplMap::const_iterator shell_it = url_to_shell_impl_.find(url);
if (shell_it != url_to_shell_impl_.end()) {
ConnectToClient(
shell_it->second, url, requestor_url, service_provider.Pass());
return;
}
scoped_refptr<LoadCallbacksImpl> callbacks(
new LoadCallbacksImpl(weak_ptr_factory_.GetWeakPtr(),
url,
requestor_url,
service_provider.Pass()));
GetLoaderForURL(url)->Load(this, url, callbacks);
}
void ApplicationManager::ConnectToClient(ShellImpl* shell_impl,
const GURL& url,
const GURL& requestor_url,
ServiceProviderPtr service_provider) {
if (interceptor_) {
shell_impl->ConnectToClient(
requestor_url,
interceptor_->OnConnectToClient(url, service_provider.Pass()));
} else {
shell_impl->ConnectToClient(requestor_url, service_provider.Pass());
}
}
void ApplicationManager::RegisterLoadedApplication(
const GURL& url,
const GURL& requestor_url,
ServiceProviderPtr service_provider,
ScopedMessagePipeHandle* shell_handle) {
ShellImpl* shell_impl = NULL;
URLToShellImplMap::iterator iter = url_to_shell_impl_.find(url);
if (iter != url_to_shell_impl_.end()) {
// This can happen because services are loaded asynchronously. So if we get
// two requests for the same service close to each other, we might get here
// and find that we already have it.
shell_impl = iter->second;
} else {
MessagePipe pipe;
URLToArgsMap::const_iterator args_it = url_to_args_.find(url);
Array<String> args;
if (args_it != url_to_args_.end())
args = Array<String>::From(args_it->second);
shell_impl = WeakBindToPipe(new ShellImpl(this, url), pipe.handle1.Pass());
url_to_shell_impl_[url] = shell_impl;
*shell_handle = pipe.handle0.Pass();
shell_impl->client()->Initialize(args.Pass());
}
ConnectToClient(shell_impl, url, requestor_url, service_provider.Pass());
}
void ApplicationManager::LoadWithContentHandler(
const GURL& content_url,
const GURL& requestor_url,
const GURL& content_handler_url,
URLResponsePtr url_response,
ServiceProviderPtr service_provider) {
ContentHandlerConnection* connection = NULL;
URLToContentHandlerMap::iterator iter =
url_to_content_handler_.find(content_handler_url);
if (iter != url_to_content_handler_.end()) {
connection = iter->second;
} else {
connection = new ContentHandlerConnection(this, content_handler_url);
url_to_content_handler_[content_handler_url] = connection;
}
InterfaceRequest<ServiceProvider> spir;
spir.Bind(service_provider.PassMessagePipe());
connection->content_handler->OnConnect(
content_url.spec(), url_response.Pass(), spir.Pass());
}
void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader,
const GURL& url) {
URLToLoaderMap::iterator it = url_to_loader_.find(url);
if (it != url_to_loader_.end())
delete it->second;
url_to_loader_[url] = loader.release();
}
void ApplicationManager::SetLoaderForScheme(
scoped_ptr<ApplicationLoader> loader,
const std::string& scheme) {
SchemeToLoaderMap::iterator it = scheme_to_loader_.find(scheme);
if (it != scheme_to_loader_.end())
delete it->second;
scheme_to_loader_[scheme] = loader.release();
}
void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args,
const GURL& url) {
url_to_args_[url] = args;
}
void ApplicationManager::SetInterceptor(Interceptor* interceptor) {
interceptor_ = interceptor;
}
ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) {
URLToLoaderMap::const_iterator url_it = url_to_loader_.find(url);
if (url_it != url_to_loader_.end())
return url_it->second;
SchemeToLoaderMap::const_iterator scheme_it =
scheme_to_loader_.find(url.scheme());
if (scheme_it != scheme_to_loader_.end())
return scheme_it->second;
return default_loader_.get();
}
void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) {
// Called from ~ShellImpl, so we do not need to call Destroy here.
const GURL url = shell_impl->url();
URLToShellImplMap::iterator it = url_to_shell_impl_.find(url);
DCHECK(it != url_to_shell_impl_.end());
delete it->second;
url_to_shell_impl_.erase(it);
ApplicationLoader* loader = GetLoaderForURL(url);
if (loader)
loader->OnApplicationError(this, url);
if (delegate_)
delegate_->OnApplicationError(url);
}
ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName(
const GURL& application_url,
const std::string& interface_name) {
StubServiceProvider* stub_sp = new StubServiceProvider;
ServiceProviderPtr spp;
BindToProxy(stub_sp, &spp);
ConnectToApplication(application_url, GURL(), spp.Pass());
MessagePipe pipe;
stub_sp->GetRemoteServiceProvider()->ConnectToService(interface_name,
pipe.handle1.Pass());
return pipe.handle0.Pass();
}
} // namespace mojo
|
5445c189d2ad762b21222b7fd227180962169003 | e36906be9399685b0d03daffec9c33735eda8ba1 | /src/mk/arch/shapes-s.cpp | de607f40ea34638771683d5e8887e91dd3bd2374 | [] | no_license | ybouret/yocto4 | 20deaa21c1ed4f52d5d6a7991450d90103a7fe8e | c02aa079d21cf9828f188153e5d65c1f0d62021c | refs/heads/master | 2020-04-06T03:34:11.834637 | 2016-09-09T14:41:55 | 2016-09-09T14:41:55 | 33,724,799 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 47 | cpp | shapes-s.cpp | #define YOCTO_ZTYPE 's'
#include "shapes.cxx"
|
d5693a026efdc06a5bd62c7955c85dfee32e86ca | c8d4563a44b9a81a997ed45e6a82cd1e079976b7 | /playground/cpp-qt-implementation/mainwindow.cpp | 889954a36bdefb426241c0d0e396f935ad323aa9 | [
"MIT"
] | permissive | filipedeschamps/doom-fire-algorithm | 53ceac63a77497a539d39ad1572ed80521e2dc74 | 36b58ac86dc2c6af9a7ca3706df370ec921a9c01 | refs/heads/master | 2023-08-26T21:36:20.287236 | 2022-07-21T02:47:23 | 2022-07-21T02:47:23 | 164,105,898 | 1,357 | 492 | MIT | 2022-07-21T02:47:24 | 2019-01-04T12:38:54 | JavaScript | UTF-8 | C++ | false | false | 3,294 | cpp | mainwindow.cpp | #include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("Doom Fire Qt");
playPauseButton = new QPushButton(this);
createDestroyButton = new QPushButton(this);
DecreaseWindButton = new QPushButton(this);
DecreaseWindButton->setText("-");
DecreaseWindButton->setMaximumWidth(35);
IncreaseWindButton = new QPushButton(this);
IncreaseWindButton->setText("+");
IncreaseWindButton->setMaximumWidth(35);
DecreaseInvervalButton = new QPushButton(this);
DecreaseInvervalButton->setText("-");
DecreaseInvervalButton->setMaximumWidth(35);
IncreaseInvervalButton = new QPushButton(this);
IncreaseInvervalButton->setText("+");
IncreaseInvervalButton->setMaximumWidth(35);
WindLabel = new QLabel(this);
WindLabel->setText("Wind:");
WindSpeedLabel = new QLabel(this);
//WindSpeedLabel->setStyleSheet("QLabel{color: white;}");
WindSpeedLabel->setMinimumWidth(14);
WindSpeedLabel->setAlignment(Qt::AlignCenter);
updateLabel = new QLabel(this);
updateLabel->setText("Refresh:");
UpdateIntervalLabel = new QLabel(this);
//UpdateIntervalLabel->setStyleSheet("QLabel{color: white;}");
UpdateIntervalLabel->setMinimumWidth(20);
UpdateIntervalLabel->setAlignment(Qt::AlignCenter);
ui->mainToolBar->setStyleSheet("QToolBar{spacing: 2px;}");
ui->mainToolBar->addWidget(playPauseButton);
ui->mainToolBar->addWidget(createDestroyButton);
ui->mainToolBar->addSeparator();
ui->mainToolBar->addWidget(WindLabel);
ui->mainToolBar->addWidget(DecreaseWindButton);
ui->mainToolBar->addWidget(WindSpeedLabel);
ui->mainToolBar->addWidget(IncreaseWindButton);
ui->mainToolBar->addSeparator();
ui->mainToolBar->addWidget(updateLabel);
ui->mainToolBar->addWidget(DecreaseInvervalButton);
ui->mainToolBar->addWidget(UpdateIntervalLabel);
ui->mainToolBar->addWidget(IncreaseInvervalButton);
fireWidget = new FireWidget(centralWidget()->width(), centralWidget()->height());
setCentralWidget(fireWidget);
connect(playPauseButton, &QPushButton::released, fireWidget, &FireWidget::onPlayPausePressed);
connect(createDestroyButton, &QPushButton::released, fireWidget, &FireWidget::onCreateDestroyPressed);
connect(DecreaseWindButton, &QPushButton::released, fireWidget, &FireWidget::onDecreaseWindPressed);
connect(IncreaseWindButton, &QPushButton::released, fireWidget, &FireWidget::onIncreaseWindPressed);
connect(DecreaseInvervalButton, &QPushButton::released, fireWidget, &FireWidget::onDecreaseIntervalPressed);
connect(IncreaseInvervalButton, &QPushButton::released, fireWidget, &FireWidget::onIncreaseIntervalPressed);
connect(fireWidget, &FireWidget::statusUpdated, this, &MainWindow::onStatusUpdated);
onStatusUpdated();
}
MainWindow::~MainWindow()
{
delete fireWidget;
delete ui;
}
void MainWindow::onStatusUpdated()
{
playPauseButton->setText(fireWidget->playPauseString());
createDestroyButton->setText(fireWidget->CreateDestroyString());
WindSpeedLabel->setText(fireWidget->windSpeed());
UpdateIntervalLabel->setText(fireWidget->updateInterval());
}
|
fcdc05614c680b66188d6200622e5c18382f613b | 0f30d43960d46961688497af9004c2f154d71877 | /core/target/cpp/ts/src/thx/fp/CO.cpp | 626b62f5d50c5517ea8efd2a7f4fc703e83bcdc3 | [
"MIT"
] | permissive | mboussaa/haxe-testing | 77d2c44596f92d3b509ad2e450f61d2e640eb9a3 | 930bd6e63c8cb91a4df323d01ae518d048c089ba | refs/heads/master | 2021-01-17T10:20:07.126520 | 2016-06-02T10:00:49 | 2016-06-02T10:00:49 | 59,005,172 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | true | 4,100 | cpp | CO.cpp | // Generated by Haxe 3.3.0
#include <hxcpp.h>
#ifndef INCLUDED_haxe_Utf8
#include <haxe/Utf8.h>
#endif
#ifndef INCLUDED_thx_OrderingImpl
#include <thx/OrderingImpl.h>
#endif
#ifndef INCLUDED_thx__Ord_Ordering_Impl_
#include <thx/_Ord/Ordering_Impl_.h>
#endif
#ifndef INCLUDED_thx_fp_CO
#include <thx/fp/CO.h>
#endif
namespace thx{
namespace fp{
void CO_obj::__construct(::String v){
HX_STACK_FRAME("thx.fp.CO","new",0x370af3d8,"thx.fp.CO.new","thx/fp/TestMap.hx",105,0xd5adc18e)
HX_STACK_THIS(this)
HX_STACK_ARG(v,"v")
HXLINE( 105) this->v = v;
}
Dynamic CO_obj::__CreateEmpty() { return new CO_obj; }
hx::ObjectPtr< CO_obj > CO_obj::__new(::String v)
{
hx::ObjectPtr< CO_obj > _hx_result = new CO_obj();
_hx_result->__construct(v);
return _hx_result;
}
Dynamic CO_obj::__Create(hx::DynamicArray inArgs)
{
hx::ObjectPtr< CO_obj > _hx_result = new CO_obj();
_hx_result->__construct(inArgs[0]);
return _hx_result;
}
::hx::EnumBase CO_obj::compareTo( ::thx::fp::CO that){
HX_STACK_FRAME("thx.fp.CO","compareTo",0x899fa2f8,"thx.fp.CO.compareTo","thx/fp/TestMap.hx",107,0xd5adc18e)
HX_STACK_THIS(this)
HX_STACK_ARG(that,"that")
HXLINE( 107) Int _hx_tmp = ::haxe::Utf8_obj::compare(this->v,that->v);
HXDLIN( 107) return ::thx::_Ord::Ordering_Impl__obj::fromInt(_hx_tmp);
}
HX_DEFINE_DYNAMIC_FUNC1(CO_obj,compareTo,return )
CO_obj::CO_obj()
{
}
void CO_obj::__Mark(HX_MARK_PARAMS)
{
HX_MARK_BEGIN_CLASS(CO);
HX_MARK_MEMBER_NAME(v,"v");
HX_MARK_END_CLASS();
}
void CO_obj::__Visit(HX_VISIT_PARAMS)
{
HX_VISIT_MEMBER_NAME(v,"v");
}
hx::Val CO_obj::__Field(const ::String &inName,hx::PropertyAccess inCallProp)
{
switch(inName.length) {
case 1:
if (HX_FIELD_EQ(inName,"v") ) { return hx::Val( v); }
break;
case 9:
if (HX_FIELD_EQ(inName,"compareTo") ) { return hx::Val( compareTo_dyn()); }
}
return super::__Field(inName,inCallProp);
}
hx::Val CO_obj::__SetField(const ::String &inName,const hx::Val &inValue,hx::PropertyAccess inCallProp)
{
switch(inName.length) {
case 1:
if (HX_FIELD_EQ(inName,"v") ) { v=inValue.Cast< ::String >(); return inValue; }
}
return super::__SetField(inName,inValue,inCallProp);
}
void CO_obj::__GetFields(Array< ::String> &outFields)
{
outFields->push(HX_HCSTRING("v","\x76","\x00","\x00","\x00"));
super::__GetFields(outFields);
};
#if HXCPP_SCRIPTABLE
static hx::StorageInfo CO_obj_sMemberStorageInfo[] = {
{hx::fsString,(int)offsetof(CO_obj,v),HX_HCSTRING("v","\x76","\x00","\x00","\x00")},
{ hx::fsUnknown, 0, null()}
};
static hx::StaticInfo *CO_obj_sStaticStorageInfo = 0;
#endif
static ::String CO_obj_sMemberFields[] = {
HX_HCSTRING("v","\x76","\x00","\x00","\x00"),
HX_HCSTRING("compareTo","\x80","\x95","\x5c","\x02"),
::String(null()) };
static void CO_obj_sMarkStatics(HX_MARK_PARAMS) {
HX_MARK_MEMBER_NAME(CO_obj::__mClass,"__mClass");
};
#ifdef HXCPP_VISIT_ALLOCS
static void CO_obj_sVisitStatics(HX_VISIT_PARAMS) {
HX_VISIT_MEMBER_NAME(CO_obj::__mClass,"__mClass");
};
#endif
hx::Class CO_obj::__mClass;
void CO_obj::__register()
{
hx::Static(__mClass) = new hx::Class_obj();
__mClass->mName = HX_HCSTRING("thx.fp.CO","\xe6","\x67","\x66","\xb9");
__mClass->mSuper = &super::__SGetClass();
__mClass->mConstructEmpty = &__CreateEmpty;
__mClass->mConstructArgs = &__Create;
__mClass->mGetStaticField = &hx::Class_obj::GetNoStaticField;
__mClass->mSetStaticField = &hx::Class_obj::SetNoStaticField;
__mClass->mMarkFunc = CO_obj_sMarkStatics;
__mClass->mStatics = hx::Class_obj::dupFunctions(0 /* sStaticFields */);
__mClass->mMembers = hx::Class_obj::dupFunctions(CO_obj_sMemberFields);
__mClass->mCanCast = hx::TCanCast< CO_obj >;
#ifdef HXCPP_VISIT_ALLOCS
__mClass->mVisitFunc = CO_obj_sVisitStatics;
#endif
#ifdef HXCPP_SCRIPTABLE
__mClass->mMemberStorageInfo = CO_obj_sMemberStorageInfo;
#endif
#ifdef HXCPP_SCRIPTABLE
__mClass->mStaticStorageInfo = CO_obj_sStaticStorageInfo;
#endif
hx::_hx_RegisterClass(__mClass->mName, __mClass);
}
} // end namespace thx
} // end namespace fp
|
d5c011b4e324a2eeacbc81d7b884a7bedd2384dd | 44b289f446877cacce150dca417c1e94e3850c0f | /Unreal_CPP/Components/CPatrolComponent.h | 477772a5e17b2d2d00c481d68f202c14400adf9c | [] | no_license | SeoWon430/Unreal_Cpp | b8e6f1f26bb626fa8d010a366bdf51a16d06f756 | 5c27c80b4757c319d29d6f549f059c030ee41ecb | refs/heads/main | 2023-08-31T02:24:56.387125 | 2021-10-20T09:05:30 | 2021-10-20T09:05:30 | 419,256,795 | 0 | 0 | null | null | null | null | UHC | C++ | false | false | 785 | h | CPatrolComponent.h | #pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "CPatrolComponent.generated.h"
// AI에서 사용될 Patrol기능 (Spline지정시 이를 따라 감)
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class U02_CPP_API UCPatrolComponent : public UActorComponent
{
GENERATED_BODY()
private:
UPROPERTY(EditAnywhere)
class ACPatrolPath* Path;
UPROPERTY(EditAnywhere)
int32 Index;
UPROPERTY(EditAnywhere)
bool bReverse;
UPROPERTY(EditAnywhere)
float AcceptanceRadius = 10.0f;
public:
FORCEINLINE bool IsValid() { return Path != nullptr; }
public:
UCPatrolComponent();
bool GetMoveTo(FVector& OutLocation, float& OutAcceptanceRadius);
void UpdateNextIndex();
protected:
virtual void BeginPlay() override;
};
|
3ee3cf98284294b960cbbb9fa03756c7db7705cd | 2e8a91b18a7322ccac71f3839cb2175e8b8986ab | /inc/gui/FontCreator.h | 7318abc6226060032b28c7970a28cb7c4c9e6215 | [] | no_license | martingleich/LuxEngine | 5ae3df18ef4fb5ecd277a1d3e3b80e0fa4df89cf | d095085c3a2580ea7fe3db633908b84099e2ad4f | refs/heads/master | 2021-01-19T05:13:40.055025 | 2019-03-10T11:10:55 | 2019-03-10T11:10:55 | 87,415,718 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 718 | h | FontCreator.h | #ifndef INCLUDED_LUX_FONTCREATOR_H
#define INCLUDED_LUX_FONTCREATOR_H
#include "gui/Font.h"
namespace lux
{
namespace io
{
class File;
}
namespace gui
{
class FontCreator : public ReferenceCounted
{
public:
virtual StrongRef<Font> CreateFontFromFile(const io::Path& path,
const FontDescription& desc,
const core::Array<u32>& charSet) = 0;
virtual StrongRef<Font> CreateFontFromFile(io::File* file,
const FontDescription& desc,
const core::Array<u32>& charSet) = 0;
virtual StrongRef<Font> CreateFont(const FontDescription& desc,
const core::Array<u32>& charSet) = 0;
virtual const core::Array<u32>& GetDefaultCharset(const core::String& name) const = 0;
};
}
}
#endif // !__INCLUDED_LUX_IFONTCREATOR |
9fffcf271a211a3200111e9f3e24af26eb384feb | 2de460c76ac1b0d3d2b27043d725c2cd51b15695 | /Enigma.cc | 04cdb7dd35329305a35768edef997da040a3a5fb | [] | no_license | abd296/Turing-Machine | efd506ed7b95dfc38e1a09ab5d0c149048a93e0e | 284cde8e227ad20f9193b1b42c13c92d7e05a87f | refs/heads/master | 2020-11-28T08:45:56.634554 | 2019-12-23T13:45:48 | 2019-12-23T13:45:48 | 229,760,331 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 11,712 | cc | Enigma.cc | #include "Enigma.h"
#include <cstdlib>
#include<fstream>
#include<cstring>
#include "Rottor.h"
#include "Rottor.cc"
#include "Plugboard.h"
#include "Plugboard.cc"
#include "Reflector.h"
#include "Reflector.cc"
using namespace std;
Enigma::Enigma()
{
// constructor
}
void Enigma::FileHandling(char * arrq, char * arrp, int p)
{
plug = 0; //variable for checking which setting is used in Encryption
Ref = 0; // 0 for default
Rot1 = 0; // 1 for setting read from file
Rot2 = 0;
Rot3 = 0;
if (p == 3) // if third argument is present
{
ifstream finp;
finp.open(arrp); // opening that file
if (finp.fail()) // if opening fails
{
cout << "Couldn't find the argument for Rottor setting \n Running Enigma with default Rotor Setting ...\n" << endl;
plug = 0;
Ref = 0;
Rot1 = 0;
Rot2 = 0;
Rot3 = 0;
}
else
{
cout<<"Enigma setting invoked"<<endl;
string word;
finp >> word;
//###################################Reading Plugboard setting#######################################
if(word == "Plugboard:")
{
plug = 1;
q = new char [26];
finp.get(ch);
finp.get(ch);
g=0;
t=25;
for(int g=0; g<=13; g++)
{
finp.get(ch);
q[g] =ch;
finp.get(ch);
q[t] = ch;
finp.get(ch);
finp.get(ch);
if(int(ch) != 10)
{
cout<<"Enter in correct pair \n Remember no pair has more two elements\n";
plug = 0;
break;
exit(0);
}
if(g == 13 || t == 13)
break;
t--;
}
}
cout<<"Plugboard Array : "<< q <<endl;
//###################################Reading Rotor 1 setting#######################################
finp >> word;
if(word == "Rotor1:")
{
Rot1 = 1;
RR1 = new char [26];
finp.get(ch);
for (int i=0; i<26; i++)
{
finp.get(ch);
RR1[i] = ch;
}
cout<<"Rotor1 Array : "<<RR1<<endl;
}
//###################################Reading Rotor 2 setting#######################################
finp >> word;
if(word == "Rotor2:")
{
Rot2=1;
RR2 = new char [26];
finp.get(ch);
for (int i=0; i<26; i++)
{
finp.get(ch);
RR2[i] = ch;
}
cout<<"Rotor2 Array : "<<RR2<<endl;
}
//###################################Reading Rotor 3 setting#######################################
finp >> word;
if(word == "Rotor3:")
{
Rot3 = 1;
RR3 = new char [26];
finp.get(ch);
for (int i=0; i<27; i++)
{
finp.get(ch);
RR3[i] = ch;
}
cout<<"Rotor3 Array : "<<RR3<<endl;
}
//###################################Reading Reflector setting#######################################
finp >> word;
if(word == "Reflector:")
{
RF = new char [26];
finp.get(ch);
finp.get(ch);
g=0;
t=25;
Ref= 1;
for(int g=0; g<=13; g++)
{
finp.get(ch);
RF[g] =ch;
finp.get(ch);
RF[t] = ch;
finp.get(ch);
finp.get(ch);
if(int(ch) != 10)
{
cout<<"Enter in correct pair \n Remember no pair has more two elements\n";
Ref = 0;
break;
exit(0);
}
if(g == 13 || t == 13)
break;
t--;
}
cout<<"Reflector Array : "<<RF<<endl<<endl;
}
}
finp.close(); // closing file
}
ifstream fin; // opening Enigma.ini file
fin.open(arrq);
if (fin.fail())
{
cout << "Couldn't find the argument \n opening default ini file ...\n" << endl;
fin.open("enigma.ini");
}
while (!fin.eof())
{
fin.get(ch);
if (ch != 13 || ch != 10 )
{
if(int(ch) == 10)
{
break;
}
else
i++; // counting string length of message
}
}
i--;
ptr = new char [i]; // creating array memory on heap
fin.seekg(0); // pointing cusor back to start in text file
int b= 0;
while (!fin.eof())
{
fin.get(ch);
if (ch != 13 || ch != 10 )
{
if(int(ch) == 10)
{
break;
}
else
{
ptr[b] = ch;
if (int(ch) == 48 || int(ch) == 49 || int(ch) == 50|| int(ch) == 51|| int(ch) == 52|| int(ch) == 53|| int(ch) == 54|| int(ch) == 55|| int(ch) == 56|| int(ch) == 57)
{
cout<<"Number in Message,... but program will handle it."<<endl;
}
b++;
}
}
}
//################################Converting Upper case to Lower case ################################################################//
for(int y=0; y<i; y++)
{
if(ptr[y]>=65 && ptr[y]<=92)
{
ptr[y]=ptr[y]+32;
}
}
//##############################Exception Handling in Key##################################################################//
/* R1 = -1;
R2 = -1;
R3 = -1;
fin >> R1;
try{ if (R1 == -1)
{
throw 1;
}
}
catch(int a)
{
cout<<"Enter correct value of Rotor 1"<<endl;
cout<<"good bye....";
delete ptr;
exit(0);
}
fin.get(ch);
fin >> R2;
try{ if (R2 == -1)
{
throw 1;
}
}
catch(int a)
{
cout<<"Enter correct value of Rotor 2"<<endl;
cout<<"good bye....";
delete ptr;
exit(0);
}
fin.get(ch);
fin >> R3;
try{ if (R1 == -1)
{
throw 1;
}
}
catch(int a)
{
cout<<"Enter correct value of Rotor 3"<<endl;
cout<<"good bye....";
delete ptr;
exit(0);
}
cout<<"Rotor 1 key : "<<R1<<endl<<"Rotor 2 key : "<<R2<<endl<<"Rotor 3 key : "<<R3<<endl<<endl;
*/
}
string Enigma::Cipher()
{
Plugboard A(q, plug); // Making Objects of Classes
Reflector B(RF, Ref);
Rottor C(R1,RR1, 1, Rot1);
Rottor D(R2,RR2, 2, Rot2);
Rottor E(R3,RR3, 3, Rot3);
char a;
output = "";
// cout << "String is "<<ptr<<endl<<"Message length is "<<i<<endl<<endl;
// cout<< "Encrypted message is \" ";
// ofstream fout;
// fout.open("Output.txt");
for(int y=0; y<i; y++)
{
if(ptr[y]>= 'a' && ptr[y] <= 'z' )
{
a = A.swap(ptr[y]);
a = C.Encrypt(a);
a = D.Encrypt(a);
a = E.Encrypt(a);
a = B.swap(a);
a = E.Encrypt(a);
a = D.Encrypt(a);
a = C.Encrypt(a);
a = A.swap(a);
// cout<< a;
// fout<<a;
output = output + a;
}
else
{
// cout<<ptr[y];
// fout<<ptr[y];
output = output + ptr[y];
}
}
// cout<<"\""<<endl;
// fout<<" "<<endl;
// fout<<R1<<endl<<R2<<endl<<R3<<endl;
// fout.close();
return output;
}
Enigma::~Enigma()
{
delete[] ptr;
delete[] q;
delete[] RR1;
delete[] RR2;
delete[] RR3;
delete[] RF; // Destructor
}
|
4bf1ec7d19047e518dcb3e7fa093b62a3cefdb44 | 113854f799ea342b2b2986d40256c9164b5759b4 | /A.数据结构与算法/String-字符串/Medium/3_最长不重复子串/LengthOfLongestSubstring.cpp | f108f3c900c37de6aa69f0a961b8342071691225 | [
"Apache-2.0"
] | permissive | isshe/coding-life | 5710ad135bf91ab9c6caf2f29a91215f03bba120 | f93ecaee587474446d51a0be6bce54176292fd97 | refs/heads/master | 2023-08-31T20:43:23.967162 | 2023-08-30T22:00:02 | 2023-08-30T22:00:02 | 147,092,799 | 8 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,616 | cpp | LengthOfLongestSubstring.cpp | /*=========================================================================\
* Copyright(C)2016 Chudai.
*
* File name : LengthOfLongestSubstring.cpp
* Version : v1.0.0
* Author : 初代
* Date : 2016/08/22
* Description :
* Function list: 1.
* 2.
* 3.
* History :
\*=========================================================================*/
/*-----------------------------------------------------------*
* 头文件 *
*-----------------------------------------------------------*/
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int hashTable[256] = {0};
int i = 0;
int len = s.size();
int sublen = 0;
int curSubStart = -1; //当前子串开始的位置-1(从0开始遍历,所以0-1 == -1. 用结尾减开始得到子串长度)
memset(hashTable, -1, sizeof(hashTable));
for (i = 0; i < len; i++)
{
//如果当前子串中此元素已经出现过了
if (hashTable[s[i]] > curSubStart)
{
curSubStart = hashTable[s[i]];
}
//哈希表对应位置存的是符号出现的位置
//当前位置永远比以前的大,会覆盖以前的,所以保存都是最新的位置
hashTable[s[i]] = i;
//
if (i - curSubStart > sublen)
{
sublen = i - curSubStart;
}
}
return sublen;
}
};
|
b872d2185a15090e8a9fe5c6ecd1a202aa50fa96 | c0cb4ffb337dc5e392d3bbafeb418f7580c05000 | /10400/10487.cpp | 2cca02d7c012a74317fd905ead5333a5061b6901 | [] | no_license | ghj0504520/UVA | b3a7d6b6ba308916681fd8a6e25932a55f7455b3 | 8e49a1424538e907f4bdbe5543cc6966d4ea5a4e | refs/heads/master | 2023-05-01T07:49:18.162394 | 2023-04-24T07:48:11 | 2023-04-24T07:48:11 | 38,348,555 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,020 | cpp | 10487.cpp | #include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#define MAX 1000
using namespace std;
int table[MAX+10];
int main()
{
ios::sync_with_stdio(0);
int num,t=0;
while(cin>>num,num)
{
memset(table,0,sizeof(table));
set<int>table1;
vector<int>table2;
for(int i=0 ; i<num ; i++)cin>>table[i];
for(int i=0 ; i< num ; i++)
{
for(int j=i+1 ; j<num ; j++)
{
if(i!=j)
{
int cur=table[i]+table[j];
if(!table1.count(cur))
{
table1.insert(cur);
table2.push_back(cur);
}
}
}
}
sort(table2.begin(),table2.end());
int qnum;
cin>>qnum;
cout<<"Case "<<++t<<":\n";
while(qnum--)
{
int query;
cin>>query;
vector<int>::iterator it=lower_bound(table2.begin(),table2.end(),query);
int dis=it-table2.begin();
if(dis-1>=0)
dis = abs(table2[dis-1]-query)< abs(table2[dis]-query) ?dis-1:dis;
cout<<"Closest sum to "<<query<<" is "<<table2[dis]<<".\n";
}
}
return 0;
} |
3061de3a59ab679b5f768054635c045468ea8d4a | ced58e19582cb68265fb659e1d7544ba775b433c | /MSCNN_dehazing/matlab/src/vl_nnconv.cu | c9218761084b34643afdd6b1bafca90394c058ae | [] | no_license | feiyungu/Haze-Removal-1 | 2ed37e8ca318215263c023339249330e51cabdcf | bc06da5dcfd96476edf04f191bc862a4e6a13d4f | refs/heads/master | 2020-03-25T15:31:03.806993 | 2018-05-04T07:26:16 | 2018-05-04T07:26:16 | 143,886,804 | 20 | 5 | null | 2018-08-07T14:41:06 | 2018-08-07T14:41:05 | null | UTF-8 | C++ | false | false | 31,844 | cu | vl_nnconv.cu | /** @file vl_nnconv.cu
** @brief Convolution block
** @author Andrea Vedaldi
**/
/*
Copyright (C) 2014 Andrea Vedaldi and Max Jaderberg.
All rights reserved.
This file is part of the VLFeat library and is made available under
the terms of the BSD license (see the COPYING file).
*/
#include "bits/mexutils.h"
#include "bits/nnhelper.h"
#include "bits/im2col.hpp"
#include "bits/subsample.hpp"
#include <assert.h>
#include <blas.h>
#ifdef ENABLE_GPU
#include <cublas_v2.h>
#endif
/* option codes */
enum {
opt_stride = 0,
opt_pad,
opt_verbose,
opt_no_der_data,
opt_no_der_filters,
opt_no_der_biases,
} ;
/* options */
vlmxOption options [] = {
{"Stride", 1, opt_stride },
{"Pad", 1, opt_pad },
{"Verbose", 0, opt_verbose },
{"NoDerData", 0, opt_no_der_data },
{"NoDerFilters", 0, opt_no_der_filters },
{"NoDerBiases", 0, opt_no_der_biases },
{0, 0, 0 }
} ;
/* ---------------------------------------------------------------- */
/* Cache */
/* ---------------------------------------------------------------- */
#ifdef ENABLE_GPU
bool cublasInitialized = false ;
cublasHandle_t thisCublasHandle ;
#endif
bool persistentDataInitialized = false ;
PackedData temp ;
PackedData allOnes ;
void atExit()
{
packed_data_deinit (&temp) ;
packed_data_deinit (&allOnes) ;
#ifdef ENABLE_GPU
if (cublasInitialized) {
cublasDestroy(thisCublasHandle) ;
cublasInitialized = false ;
}
#endif
}
/* ---------------------------------------------------------------- */
/* Dispatcher func */
/* ---------------------------------------------------------------- */
static void
sgemv_dispatch(bool gpuMode,
char op,
ptrdiff_t m, ptrdiff_t n,
float alpha,
float const * a, ptrdiff_t lda,
float const * x, ptrdiff_t incx,
float beta,
float * y, ptrdiff_t incy)
{
if (!gpuMode) {
sgemv(&op,
&m, &n, &alpha,
(float*)a, &lda,
(float*)x, &incx,
&beta,
y, &incy) ;
} else {
#ifdef ENABLE_GPU
cublasSgemv(thisCublasHandle,
(op == 't') ? CUBLAS_OP_T : CUBLAS_OP_N,
(int)m, (int)n,
&alpha,
a, lda,
x, (int)incx,
&beta,
y, (int)incy) ;
#endif
}
}
static void
sgemm_dispatch(bool gpuMode,
char op1, char op2,
ptrdiff_t m, ptrdiff_t n, ptrdiff_t k,
float alpha,
float const * a, ptrdiff_t lda,
float const * b, ptrdiff_t ldb,
float beta,
float * c, ptrdiff_t ldc)
{
if (!gpuMode) {
sgemm(&op1, &op2,
&m, &n, &k,
&alpha,
(float*)a, &lda,
(float*)b, &ldb,
&beta,
c, &ldc) ;
} else {
#ifdef ENABLE_GPU
cublasSgemm(thisCublasHandle,
(op1 == 't') ? CUBLAS_OP_T : CUBLAS_OP_N,
(op2 == 't') ? CUBLAS_OP_T : CUBLAS_OP_N,
(int)m, (int)n, (int)k,
&alpha,
a, (int)lda,
b, (int)ldb,
&beta,
c, (int)ldc);
#endif
}
}
static void
copy_dispatch(bool gpuMode,
float * dest,
float const * src,
size_t numElements)
{
if (!gpuMode) {
memcpy(dest, src, numElements * sizeof(float)) ;
} else {
#ifdef ENABLE_GPU
cudaMemcpy(dest, src, numElements * sizeof(float), cudaMemcpyDeviceToDevice) ;
#endif
}
}
static void
subsample_dispatch(bool gpuMode,
float* subsampled,
float const* data,
size_t width,
size_t height,
size_t depth,
size_t strideX,
size_t strideY,
size_t padLeft,
size_t padRight,
size_t padTop,
size_t padBottom)
{
if (!gpuMode) {
subsample_cpu(subsampled,
data,
width,
height,
depth,
strideX,
strideY,
padLeft,
padRight,
padTop,
padBottom) ;
} else {
#ifdef ENABLE_GPU
subsample_gpu(subsampled,
data,
width,
height,
depth,
strideX,
strideY,
padLeft,
padRight,
padTop,
padBottom) ;
#endif
}
}
static void
subsampleBackward_dispatch(bool gpuMode,
float* dzdx,
float const* dzdy,
size_t width,
size_t height,
size_t depth,
size_t strideX,
size_t strideY,
size_t padLeft,
size_t padRight,
size_t padTop,
size_t padBottom)
{
if (!gpuMode) {
subsampleBackward_cpu(dzdx,
dzdy,
width,
height,
depth,
strideX,
strideY,
padLeft,
padRight,
padTop,
padBottom) ;
} else {
#ifdef ENABLE_GPU
subsampleBackward_gpu(dzdx,
dzdy,
width,
height,
depth,
strideX,
strideY,
padLeft,
padRight,
padTop,
padBottom) ;
#endif
}
}
static void
im2col_dispatch(bool gpuMode,
float* stacked,
float const* data,
size_t width,
size_t height,
size_t depth,
size_t windowWidth,
size_t windowHeight,
size_t strideX,
size_t strideY,
size_t padLeft,
size_t padRight,
size_t padTop,
size_t padBottom)
{
if (!gpuMode) {
im2col_cpu<float>(stacked,
data,
width,
height,
depth,
windowWidth,
windowHeight,
strideX,
strideY,
padLeft,
padRight,
padTop,
padBottom) ;
} else {
#ifdef ENABLE_GPU
im2col_gpu<float>(stacked,
data,
width,
height,
depth,
windowWidth,
windowHeight,
strideX,
strideY,
padLeft,
padRight,
padTop,
padBottom) ;
#endif
}
}
static void
col2im_dispatch(bool gpuMode,
float* data,
float const* stacked,
size_t width,
size_t height,
size_t depth,
size_t windowWidth,
size_t windowHeight,
size_t strideX,
size_t strideY,
size_t padLeft,
size_t padRight,
size_t padTop,
size_t padBottom)
{
if (!gpuMode) {
col2im_cpu<float>(data,
stacked,
width,
height,
depth,
windowWidth,
windowHeight,
strideX,
strideY,
padLeft,
padRight,
padTop,
padBottom) ;
} else {
#ifdef ENABLE_GPU
col2im_gpu<float>(data,
stacked,
width,
height,
depth,
windowWidth,
windowHeight,
strideX,
strideY,
padLeft,
padRight,
padTop,
padBottom) ;
#endif
}
}
/* ---------------------------------------------------------------- */
/* MEX driver */
/* ---------------------------------------------------------------- */
enum {
IN_DATA = 0, IN_FILTERS, IN_BIASES, IN_DEROUTPUT, IN_END
} ;
enum {
OUT_RESULT = 0, OUT_DERFILTERS, OUT_DERBIASES, OUT_END
} ;
void mexFunction(int nout, mxArray *out[],
int nin, mxArray const *in[])
{
/* inputs */
PackedData data ;
PackedData filters ;
PackedData biases ;
PackedData derOutput ;
/* outputs */
PackedData output ;
PackedData derData ;
PackedData derFilters ;
PackedData derBiases ;
PackedDataGeometry outputGeom ;
PackedDataGeometry derDataGeom ;
PackedDataGeometry derFiltersGeom ;
PackedDataGeometry derBiasesGeom ;
PackedDataGeometry tempGeom ;
PackedDataGeometry allOnesGeom ;
int strideX = 1 ;
int strideY = 1 ;
int padLeft = 0 ;
int padRight = 0 ;
int padTop = 0 ;
int padBottom = 0 ;
int numGroups = 1 ;
#if ENABLE_GPU
cublasStatus_t stat;
bool gpuMode = false ;
#else
bool const gpuMode = false ;
#endif
bool backMode = false ;
bool hasFilters = false ;
bool hasBiases = false ;
bool fullyConnectedMode = false ;
bool computeDerData = true ;
bool computeDerFilters = true ;
bool computeDerBiases = true ;
int verbosity = 0 ;
int opt ;
int next = IN_END ;
mxArray const *optarg ;
packed_data_init_empty(&data) ;
packed_data_init_empty(&filters) ;
packed_data_init_empty(&biases) ;
packed_data_init_empty(&derOutput) ;
packed_data_init_empty(&output) ;
packed_data_init_empty(&derData) ;
packed_data_init_empty(&derFilters) ;
packed_data_init_empty(&derBiases) ;
if (!persistentDataInitialized) {
persistentDataInitialized = true ;
packed_data_init_empty(&temp) ;
packed_data_init_empty(&allOnes) ;
}
/* -------------------------------------------------------------- */
/* Check the arguments */
/* -------------------------------------------------------------- */
mexAtExit(atExit) ;
if (nin < 3) {
mexErrMsgTxt("There are less than three arguments.") ;
}
if (nin > 3 && vlmxIsString(in[3],-1)) {
next = 3 ;
backMode = 0 ;
} else {
backMode = (nin >= 4) ;
}
while ((opt = vlmxNextOption (in, nin, options, &next, &optarg)) >= 0) {
switch (opt) {
case opt_verbose :
++ verbosity ;
break ;
case opt_stride :
if (!vlmxIsPlainMatrix(optarg,-1,-1)) {
mexErrMsgTxt("STRIDE is not a plain matrix.") ;
}
switch (mxGetNumberOfElements(optarg)) {
case 1:
strideY = (int)mxGetPr(optarg)[0] ;
strideX = strideY ;
break ;
case 2:
strideY = (int)mxGetPr(optarg)[0] ;
strideX = (int)mxGetPr(optarg)[1] ;
break ;
default:
mexErrMsgTxt("STRIDE has neither one nor two elements.") ;
}
break ;
case opt_pad :
if (!vlmxIsPlainMatrix(optarg,-1,-1)) {
mexErrMsgTxt("PAD is not a plain matrix.") ;
}
switch (mxGetNumberOfElements(optarg)) {
case 1:
padLeft = (int)mxGetPr(optarg)[0] ;
padRight = padLeft ;
padTop = padLeft ;
padBottom = padLeft ;
break ;
case 4:
padTop = (int)mxGetPr(optarg)[0] ;
padBottom = (int)mxGetPr(optarg)[1] ;
padLeft = (int)mxGetPr(optarg)[2] ;
padRight = (int)mxGetPr(optarg)[3] ;
break ;
default:
mexErrMsgTxt("STRIDE has neither one nor two elements.") ;
}
break ;
case opt_no_der_data :
computeDerData = VL_FALSE ;
break ;
case opt_no_der_filters :
computeDerFilters = VL_FALSE ;
break ;
case opt_no_der_biases :
computeDerBiases = VL_FALSE ;
break ;
default: break ;
}
}
packed_data_init_with_array(&data, in[IN_DATA]) ;
packed_data_init_with_array(&filters, in[IN_FILTERS]) ;
packed_data_init_with_array(&biases, in[IN_BIASES]) ;
if (backMode) { packed_data_init_with_array(&derOutput, in[IN_DEROUTPUT]) ; }
#if ENABLE_GPU
gpuMode = (data.mode == matlabGpuArrayWrapper) ;
if (gpuMode) {
mxInitGPU() ;
if (!cublasInitialized) {
stat = cublasCreate(&thisCublasHandle) ;
if (stat != CUBLAS_STATUS_SUCCESS) {
mexErrMsgTxt("Could not initialize cuBLAS.") ;
}
cublasInitialized = true ;
}
}
#endif
hasFilters = filters.geom.numElements > 0 ;
hasBiases = biases.geom.numElements > 0 ;
/* check for GPU/data class consistency */
if (gpuMode && (filters.mode != matlabGpuArrayWrapper & hasFilters)) {
mexErrMsgTxt("DATA is a GPU array but FILTERS is not.") ;
}
if (gpuMode && (biases.mode != matlabGpuArrayWrapper & hasBiases)) {
mexErrMsgTxt("DATA is a GPU array but BIASES is not.") ;
}
if (gpuMode && (derOutput.mode != matlabGpuArrayWrapper & backMode)) {
mexErrMsgTxt("DATA is a GPU array but DEROUTPUT is not.") ;
}
if (data.geom.classID != mxSINGLE_CLASS) {
mexErrMsgTxt("DATA is not of class SINGLE.");
}
if (hasFilters && filters.geom.classID != mxSINGLE_CLASS) {
mexErrMsgTxt("FILTERS is not of class SINGLE.");
}
if (hasBiases && (biases.geom.classID != mxSINGLE_CLASS)) {
mexErrMsgTxt("BIASES is not of class SINGLE.");
}
if (backMode && (derOutput.geom.classID != mxSINGLE_CLASS)) {
mexErrMsgTxt("DEROUTPUT is not of class SINGLE.");
}
if (strideX < 1 || strideY < 1) {
mexErrMsgTxt("At least one element of STRIDE is smaller than one.") ;
}
if (!hasFilters) {
/*
Specifying empty filters assumes that they act as the
identity matrix. Geometrically, emulate this as data.geom.detph
fiilters of size 1x1xdata.geom.depth.
*/
filters.geom.width = 1 ;
filters.geom.height = 1 ;
filters.geom.depth = data.geom.depth ;
filters.geom.size = data.geom.depth ;
}
packed_data_geom_init(&outputGeom,
mxSINGLE_CLASS,
(data.geom.height + (padTop+padBottom) - filters.geom.height)/strideY + 1,
(data.geom.width + (padLeft+padRight) - filters.geom.width)/strideX + 1,
filters.geom.size,
data.geom.size) ;
/* grouped filters */
numGroups = data.geom.depth / filters.geom.depth ;
/* if the output is 1x1 pixels, then there is no need to actually
call im2col as it does not do anything
*/
fullyConnectedMode = (outputGeom.height == 1 &&
outputGeom.width == 1 &&
padTop == 0 &&
padBottom == 0 &&
padLeft == 0 &&
padRight == 0 &&
numGroups == 1) ;
derDataGeom = data.geom ;
derFiltersGeom = filters.geom ;
if (hasBiases) {
if (fullyConnectedMode) {
packed_data_geom_init (&allOnesGeom, mxSINGLE_CLASS,
1, 1,
1, data.geom.size) ;
} else {
packed_data_geom_init (&allOnesGeom, mxSINGLE_CLASS,
outputGeom.height,
outputGeom.width,
1, 1) ;
}
derBiasesGeom = biases.geom ;
} else {
packed_data_geom_init (&allOnesGeom, mxSINGLE_CLASS,
0, 0, 0, 0) ;
}
packed_data_geom_init
(&tempGeom,
mxSINGLE_CLASS,
outputGeom.height,
outputGeom.width,
filters.geom.height*filters.geom.width*filters.geom.depth*numGroups,
1) ;
if (verbosity > 0) {
mexPrintf("vl_nnconv: mode %s; %s\n", gpuMode?"gpu":"cpu", backMode?"backward":"forward") ;
mexPrintf("vl_nnconv: stride: [%d %d], pad: [%d %d %d %d], numGroups: %d, has bias: %d, has filters: %d, fully connected: %d\n",
strideY, strideX,
padTop, padBottom, padLeft, padRight,
numGroups, hasBiases, hasFilters, fullyConnectedMode) ;
packed_data_geom_display(&data.geom, "vl_nnconv: data") ;
if (hasFilters) { packed_data_geom_display(&filters.geom, "vl_nnconv: filters") ; }
if (hasBiases) { packed_data_geom_display(&biases.geom, "vl_nnconv: biases") ; }
if (backMode) {
packed_data_geom_display(&derOutput.geom, "vl_nnconv: derOutput") ;
packed_data_geom_display(&derDataGeom, "vl_nnconv: derData") ;
if (hasFilters) { packed_data_geom_display(&derFiltersGeom, "vl_nnconv: derFilters") ; }
if (hasBiases) { packed_data_geom_display(&derBiasesGeom, "vl_nnconv: derBiases") ; }
} else {
packed_data_geom_display(&outputGeom, "vl_nnconv: output") ;
}
packed_data_geom_display(&tempGeom, "vl_nnconv: temp") ;
packed_data_geom_display(&temp.geom, "vl_nnconv: temp (cached)") ;
packed_data_geom_display(&allOnesGeom, "vl_nnconv: allOnes") ;
packed_data_geom_display(&allOnes.geom, "vl_nnconv: allOnes (cached)") ;
}
if (backMode) {
if (derOutput.geom.height != tempGeom.height ||
derOutput.geom.width != tempGeom.width ||
derOutput.geom.depth != filters.geom.size ||
derOutput.geom.size != data.geom.size)
{
mexErrMsgTxt("DEROUTPUT dimensions are incompatible with X and FILTERS.") ;
}
}
if (numGroups * filters.geom.depth != data.geom.depth) {
mexErrMsgTxt("The filter depth does not divide the image depth.") ;
}
if (filters.geom.size % numGroups != 0) {
mexErrMsgTxt("The number of filter groups does not divide the total number of filters.") ;
}
if (padLeft < 0 ||
padRight < 0 ||
padTop < 0 ||
padBottom < 0) {
mexErrMsgTxt("An element of PAD is negative.") ;
}
if (data.geom.height + (padTop+padBottom) < filters.geom.height ||
data.geom.width + (padLeft+padRight) < filters.geom.width) {
mexErrMsgTxt("FILTERS are larger than the DATA (including padding).") ;
}
if (filters.geom.height == 0 || filters.geom.width == 0 || filters.geom.depth == 0) {
mexErrMsgTxt("A dimension of FILTERS is void.") ;
}
if (hasBiases) {
if (biases.geom.numElements != filters.geom.size) {
mexErrMsgTxt("The number of elements of BIASES is not the same as the number of filters.") ;
}
}
/* -------------------------------------------------------------- */
/* Do the work */
/* -------------------------------------------------------------- */
/* auxiliary buffers */
if (hasBiases) {
if (allOnes.memorySize < allOnesGeom.numElements * sizeof(float) ||
(allOnes.mode == matlabGpuArray || allOnes.mode == matlabGpuArrayWrapper) != gpuMode) {
packed_data_deinit (&allOnes) ;
packed_data_init_with_geom (&allOnes, gpuMode, allOnesGeom, true, true, 1.0f) ;
}
}
if (!fullyConnectedMode) {
if (temp.memorySize < tempGeom.numElements * sizeof(float) ||
(temp.mode == matlabGpuArray || temp.mode == matlabGpuArrayWrapper) != gpuMode) {
packed_data_deinit (&temp) ;
packed_data_init_with_geom (&temp, gpuMode, tempGeom, true, false, 0);
}
}
if (!backMode) {
packed_data_init_with_geom(&output, gpuMode, outputGeom, false, false, 0) ;
} else {
if (computeDerData) {
packed_data_init_with_geom(&derData, gpuMode, derDataGeom, false, false, 0) ;
}
if (computeDerFilters && hasFilters) {
packed_data_init_with_geom(&derFilters, gpuMode, derFiltersGeom, false, false, 0) ;
}
if (computeDerBiases && hasBiases) {
packed_data_init_with_geom(&derBiases, gpuMode, derBiasesGeom, false, false, 0) ;
}
}
if (fullyConnectedMode) {
float alpha = 1 ;
float beta = 0 ;
ptrdiff_t filtersVolume = filters.geom.height*filters.geom.width*filters.geom.depth ;
/* note: fullyConnectedMode also guarantees no padding, num filter groups = 1 */
/* optimise fully-connected mode case */
if (!backMode) {
if (hasFilters) {
if (data.geom.size == 1) {
/* one image in the stack */
sgemv_dispatch(gpuMode, 't',
filtersVolume, filters.geom.size,
alpha,
filters.memory, filtersVolume,
data.memory, 1,
beta,
output.memory, 1) ;
} else {
/* multiple images in the stack */
sgemm_dispatch(gpuMode, 't', 'n',
filters.geom.size, data.geom.size, filtersVolume,
alpha,
filters.memory, filtersVolume,
data.memory, filtersVolume,
beta,
output.memory, filters.geom.size) ;
}
} else {
/* if no filter specified, assume that they act as the
identity */
copy_dispatch(gpuMode,
output.memory, data.memory,
filtersVolume * data.geom.size) ;
}
if (hasBiases) {
float beta = 1 ;
ptrdiff_t q = 1 ;
sgemm_dispatch(gpuMode, 'n', 'n',
filters.geom.size, data.geom.size, q,
alpha,
biases.memory, filters.geom.size,
allOnes.memory, q,
beta,
output.memory, filters.geom.size) ;
}
} else {
/* back mode */
if (computeDerFilters && hasFilters) {
sgemm_dispatch(gpuMode, 'n', 't',
filtersVolume, filters.geom.size, data.geom.size,
alpha,
data.memory, filtersVolume,
derOutput.memory, filters.geom.size,
beta,
derFilters.memory, filtersVolume) ;
}
if (computeDerBiases && hasBiases) {
ptrdiff_t q = 1 ;
sgemm_dispatch(gpuMode, 'n', 't',
q, filters.geom.size, data.geom.size,
alpha,
allOnes.memory, q,
derOutput.memory, filters.geom.size,
beta,
derBiases.memory, q) ;
}
if (computeDerData) {
if (hasFilters) {
sgemm_dispatch(gpuMode, 'n', 'n',
filtersVolume, data.geom.size, filters.geom.size,
alpha,
filters.memory, filtersVolume,
derOutput.memory, filters.geom.size,
beta,
derData.memory, filtersVolume) ;
} else {
/* does not have filters, just act as identity */
copy_dispatch(gpuMode,
derData.memory, derOutput.memory,
filtersVolume * data.geom.size) ;
}
}
}
} else {
/* not fully connected */
for (int image = 0 ; image < data.geom.size ; ++image) {
/*
temp (phi(x)): m x k
filters, derFilters: k x n (for one group of filters)
derOutput (dzdy) : m x n (for one group of filters)
res (y) : m x n (for one group of filters)
*/
ptrdiff_t dataOffset = (data.geom.height*data.geom.width*data.geom.depth) * image ;
ptrdiff_t outputOffset = (output.geom.height*output.geom.width*output.geom.depth) * image ;
ptrdiff_t derDataOffset = (derData.geom.height*derData.geom.width*derData.geom.depth) * image ;
ptrdiff_t derOutputOffset = (derOutput.geom.height*derOutput.geom.width*derOutput.geom.depth) * image ;
ptrdiff_t m = tempGeom.height * tempGeom.width ; /* num output pixels */
ptrdiff_t n = filters.geom.size/numGroups ; /* num filters per group */
ptrdiff_t k = filters.geom.height*filters.geom.width*filters.geom.depth ; /* filter volume */
if (backMode) {
/* ---------------------------------------------------------- */
/* Backward mode */
/* ---------------------------------------------------------- */
/* compute derFilters dz/dF */
if (computeDerFilters & hasFilters) {
im2col_dispatch(gpuMode,
temp.memory,
data.memory + dataOffset,
data.geom.height, data.geom.width, data.geom.depth,
filters.geom.height, filters.geom.width,
strideY, strideX,
padTop, padBottom, padLeft, padRight) ;
for (int g = 0 ; g < numGroups ; ++ g) {
ptrdiff_t filterGrpOffset = k * n * g ;
ptrdiff_t tempGrpOffset = m * k * g ;
ptrdiff_t derOutputGrpOffset = m * n * g ;
float alpha = 1 ;
float beta = (image > 0) ; /* this saves init. the output array with 0 */
sgemm_dispatch(gpuMode, 't', 'n',
k, n, m,
alpha,
(fullyConnectedMode ? data.memory : temp.memory)
+ (fullyConnectedMode?dataOffset:0) + tempGrpOffset, m,
derOutput.memory + derOutputOffset + derOutputGrpOffset, m,
beta,
derFilters.memory + filterGrpOffset, k) ;
}
}
/* compute derData dz/dbias */
if (computeDerBiases & hasBiases) {
sgemv_dispatch(gpuMode, 't',
m, filters.geom.size,
1, /* alpha */
derOutput.memory + derOutputOffset, m,
allOnes.memory, 1,
(float)(image > 0), /* beta */
derBiases.memory, 1) ;
}
/* compute derData dz/dx */
if (computeDerData) {
if (hasFilters) {
for (int g = 0 ; g < numGroups ; ++ g) {
ptrdiff_t filterGrpOffset = k * n * g ;
ptrdiff_t tempGrpOffset = m * k * g ;
ptrdiff_t derOutputGrpOffset = m * n * g ;
float alpha = 1 ;
float beta = fullyConnectedMode ? (g > 0) : 0 ;
sgemm_dispatch(gpuMode, 'n', 't',
m, k, n,
alpha,
derOutput.memory + derOutputOffset + derOutputGrpOffset, m,
filters.memory + filterGrpOffset, k,
beta,
(fullyConnectedMode ? derData.memory : temp.memory)
+ (fullyConnectedMode ? + derDataOffset : 0) + tempGrpOffset,
m) ;
}
col2im_dispatch(gpuMode,
derData.memory + derDataOffset,
temp.memory,
data.geom.height, data.geom.width, data.geom.depth,
filters.geom.height, filters.geom.width,
strideY, strideX,
padTop, padBottom, padLeft, padRight) ;
} else {
/* no filters: identity */
subsampleBackward_dispatch(gpuMode,
derData.memory + derDataOffset,
derOutput.memory + derOutputOffset,
data.geom.height, data.geom.width, data.geom.depth,
strideY, strideX,
padTop, padBottom, padLeft, padRight) ;
}
}
} else {
/* ---------------------------------------------------------- */
/* Forward mode */
/* ---------------------------------------------------------- */
if (hasFilters) {
im2col_dispatch(gpuMode,
temp.memory,
data.memory + dataOffset,
data.geom.height, data.geom.width, data.geom.depth,
filters.geom.height, filters.geom.width,
strideY, strideX,
padTop, padBottom, padLeft, padRight) ;
for (int g = 0 ; g < numGroups ; ++ g) {
ptrdiff_t filterGrpOffset = k * n * g ;
ptrdiff_t tempGrpOffset = m * k * g ;
ptrdiff_t outputGrpOffset = m * n * g ;
float alpha = 1 ;
float beta = 0 ;
sgemm_dispatch(gpuMode, 'n', 'n',
m, n, k,
alpha,
(fullyConnectedMode ? data.memory : temp.memory)
+ (fullyConnectedMode?dataOffset:0) + tempGrpOffset, m,
filters.memory + filterGrpOffset, k,
beta,
output.memory + outputOffset + outputGrpOffset, m) ;
}
} else {
/* no filters: identity */
subsample_dispatch(gpuMode,
output.memory + outputOffset,
data.memory + dataOffset,
data.geom.height, data.geom.width, data.geom.depth,
strideY, strideX,
padTop, padBottom, padLeft, padRight) ;
}
if (hasBiases) {
float alpha = 1 ;
float beta = 1 ;
ptrdiff_t q = 1 ;
sgemm_dispatch(gpuMode, 'n', 'n',
m, biases.geom.numElements, q,
alpha,
allOnes.memory, m,
biases.memory, q,
beta,
output.memory + outputOffset, m) ;
}
}
}
}
/* -------------------------------------------------------------- */
/* Cleanup */
/* -------------------------------------------------------------- */
packed_data_deinit(&data) ;
packed_data_deinit(&filters) ;
packed_data_deinit(&biases) ;
if (backMode) {
packed_data_deinit(&derOutput) ;
out[OUT_RESULT] = (computeDerData) ? packed_data_deinit_extracting_array(&derData) : mxCreateDoubleMatrix(0,0,mxREAL) ;
out[OUT_DERFILTERS] =(computeDerFilters & hasFilters)? packed_data_deinit_extracting_array(&derFilters) : mxCreateDoubleMatrix(0,0,mxREAL) ;
out[OUT_DERBIASES] = (computeDerBiases & hasBiases) ? packed_data_deinit_extracting_array(&derBiases) : mxCreateDoubleMatrix(0,0,mxREAL) ;
} else {
out[OUT_RESULT] = packed_data_deinit_extracting_array(&output) ;
}
}
|
fff2f9c85a7793020bbb464a8fdf9d413648c3db | 1f58a6a9d103b8115c8014aac3e033ff6926ca23 | /Matrices/LowerTriangularMatrix.cpp | 5fa1f4ae80ff60dfec0f744e36051dcbcaad7cca | [] | no_license | UmukoroG/Data-Structures-and-Algorithms | cd15fdbbe4b05347da5f185f69675f0fd0e92dbb | a4ec40d7da92b2a4e83edff7e1cca3aef98e4d3b | refs/heads/master | 2023-08-27T20:35:04.985931 | 2021-11-01T06:45:27 | 2021-11-01T06:45:27 | 415,561,787 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,404 | cpp | LowerTriangularMatrix.cpp | #include <iostream>
#include <cstring>
using namespace std;
//USING ROW-MAJOR MAPPING
class LowerTriangular{
private:
int n;
int *A;
public:
LowerTriangular(){
n=2;
A=new int[2*(2+1)/2];
}
LowerTriangular(int n){
this->n=n;
A=new int[n*(n+1)/2];
}
void Set(int row, int col, int x);
int Get(int i, int j);
void Display();
int GetDimension(){
return n;
}
~LowerTriangular(){
delete []A;
}
};
void LowerTriangular::Set(int i, int j, int x){
if(i>=j){
A[i*(i-1)/2+j-1]=x;
}
}
int LowerTriangular::Get(int i, int j){
if(i==j){
return A[i*(i-1)/2+j-1];
}
else{
return 0;
}
}
void LowerTriangular::Display(){
int i, j;
for(i =1; i<=n;i++){
for(j=1;j<=n;j++){
if(i>=j){
cout<<A[i*(i-1)/2+j-1] <<" ";
}
else{
cout<<0 <<" ";
}
}
cout<<endl;
}
}
int main(){
int n;
cout<<"Enter the dimension:";
cin>>n;
LowerTriangular m(n);
int x;
cout<<"Enter All Elements:\n";
for(int i=1; i<=n; i++){
for(int j=1;j<=n;j++){
cin>>x;
m.Set(i,j,x);
}
}
cout<<endl;
m.Display();
return 0;
} |
4e4429883b74770139645ae4195960c9790b376a | eb2bf2f7b926b0e1807831bf63bdbee432877bad | /predictor.cc | 08881c37c4c8f1fedbfe6489b1ad6ec3a06ce6a5 | [] | no_license | zhangshaolei1998/Branch-Prediction | 07bdb58dc3f31449814b4e001f51158a0de93329 | 1c153731e733f73bb900db295fe39cd3d82b4dc6 | refs/heads/master | 2023-07-09T09:35:59.629178 | 2019-05-01T11:36:47 | 2019-05-01T11:36:47 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 11,523 | cc | predictor.cc | #include "predictor.h"
#include <math.h>
PREDICTOR::PREDICTOR (void)
{
numbranches = 0;
bp.init_bp();
banks.bank_init();
lp.init_lp();
}
bool PREDICTOR::GetPrediction (UINT64 PC)
{
/*
if (lp.get_prediction(PC) == 0){
usedlp = true;
return NOTTAKEN;
}*/
usedlp = false;
//printf("not lp\n");
numbranches++;
bool foundPred = false;
altpredno = predno = 0;
int index = bp.bp_getIndex(PC);
pred = altpred = bp.bp_getPred(index);
for (int i = 0; i < NUMBANKS; i++){
uint16_t entry = get_bank_index(PC, i, ghr.get_ghr());
uint16_t tag = get_tag(PC, ghr.get_ghr(), i);
if (banks.tag_match(i, entry, tag)){
if (foundPred){
altpred = pred;
altpredno = predno;
}
pred = banks.get_pred(i, entry);
predno = i + 1;
foundPred = true;
}
}
return pred;
}
void PREDICTOR::UpdatePredictor (UINT64 PC, OpType OPTYPE, bool resolveDir, bool predDir, UINT64 branchTarget)
{
/*if (branchTarget < PC){
lp.UpdatePredictor(PC, resolveDir, predDir, usedlp);
}*/
if (numbranches % 512000 == 0){
banks.clearLSBs();
}
else if (numbranches % 256000 == 0){
banks.clearMSBs();
}
int entry = get_bank_index(PC, predno - 1, ghr.get_ghr());
if (pred != altpred && predno > 0){
//correct, resolve = actual taken or not, pred = predicted taken or not
if (resolveDir == predDir)
banks.incr_u_ctr(predno - 1, entry);
//incorrect
else
banks.decr_u_ctr(predno - 1, entry);
}
int bp_index = bp.bp_getIndex(PC);
//if overall is correct
if (resolveDir == predDir){
if (predno == 0){
bp.bp_update(bp_index, resolveDir);
}
else{
banks.bank_update(predno - 1, entry, resolveDir);
}
}
//if overall is incorrect
else{
banks.bank_update(predno - 1, entry, resolveDir);
if (predno != NUMBANKS){
init_update_banks();
int prob_val = 1 << (NUMBANKS - 1);
int cuml_prob = 0;
bool no_zeros = true;
for (int i = predno; i < NUMBANKS; i++){
int bank_entry = get_bank_index(PC, i, ghr.get_ghr());
if (banks.get_u_ctr(i, bank_entry) == 0){
update_banks[i] = prob_val;
cuml_prob += prob_val;
prob_val /= 2;
no_zeros = false;
}
}
if (no_zeros){
for (int i = predno; i < NUMBANKS; i++){
int bank_entry = get_bank_index(PC, i, ghr.get_ghr());
banks.decr_u_ctr(i, bank_entry);
}
}
else{
int rand_val = rand() % (cuml_prob + 1);
int running_total = 0;
int selected_bank = -1;
for (int i = 0; i < NUMBANKS; i++){
if (update_banks[i] != 0){
running_total += update_banks[i];
if (rand_val <= running_total){
selected_bank = i;
break;
}
}
}
//allocate
int allocate_entry = get_bank_index(PC, selected_bank, ghr.get_ghr());
int allocate_tag = get_tag(PC, ghr.get_ghr(), selected_bank);
banks.clear_u_ctr(selected_bank, allocate_entry);
banks.set_pred_ctr(selected_bank, allocate_entry);
banks.set_tag(selected_bank, allocate_entry, allocate_tag);
}
}
}
ghr.ghr_update(resolveDir);
}
void PREDICTOR::TrackOtherInst (UINT64 PC, OpType opType, bool taken, UINT64 branchTarget)
{
}
uint16_t PREDICTOR::get_bank_index(UINT64 PC, uint8_t bankno, __uint128_t ghr){
int numHistoryBits = (int) (pow(2.0, bankno) * 8.0 + .5);
__uint128_t tempGHR = ghr;
uint16_t index = PC & ((1 << BANKINDEXBITS) - 1);
//tempGHR >>= BANKINDEXBITS;
//numHistoryBits -= BANKINDEXBITS;
while (numHistoryBits > 0){
if (numHistoryBits >= BANKINDEXBITS){
index ^= tempGHR & ((1 << BANKINDEXBITS) - 1);
tempGHR >>= BANKINDEXBITS;
numHistoryBits -= BANKINDEXBITS;
}
else{
index ^= tempGHR & ((1 << numHistoryBits) - 1);
tempGHR >>= numHistoryBits;
numHistoryBits -= numHistoryBits;
}
}
return (index % BANKSIZE);
}
uint16_t PREDICTOR::get_tag(UINT64 PC, __uint128_t ghr, int bankno){
int numHistoryBits = (int) (pow(13.0/8.0, bankno) * 10.0 + .5);
__uint128_t masked_ghr = ghr & ((1 << numHistoryBits) - 1);
__uint128_t mapped = masked_ghr + PC * 2971215073;
return mapped % (1 << TAGBITS);
/* int tag = mapped & ((1 << TAGBITS) - 1);
mapped >>= TAGBITS;
numHistoryBits -= TAGBITS;
while (numHistoryBits > 0){
if (numHistoryBits >= TAGBITS){
tag ^= mapped & ((1 << TAGBITS) - 1);
mapped >>= BANKINDEXBITS;
numHistoryBits -= BANKINDEXBITS;
}
else{
tag ^= mapped & ((1 << numHistoryBits) - 1);
mapped >>= numHistoryBits;
numHistoryBits -= numHistoryBits;
}
}
return tag % (1 << TAGBITS); */
}
void PREDICTOR::init_update_banks(){
for (int i = 0; i < NUMBANKS; i++){
update_banks[i] = 0;
}
}
//Global History Methods
GHR::GHR(void){
ghr = 0;
}
void GHR::ghr_update(bool resolveDir){
ghr <<= 1;
if (resolveDir == TAKEN)
ghr++;
}
__uint128_t GHR::get_ghr(){
return ghr;
};
//BASE PREDICTOR METHODS
BasePredictor::BasePredictor(void){}
void BasePredictor::init_bp(){
for (int i = 0; i < BPSIZE; i++)
bp_table[i] = 4;
}
void BasePredictor::bp_incr(int index){
if (bp_table[index] < MAXSAT)
bp_table[index]++;
}
void BasePredictor::bp_decr(int index){
if (bp_table[index] > 0)
bp_table[index]--;
}
void BasePredictor::bp_update(int index, bool resolveDir){
if (resolveDir == TAKEN)
bp_incr(index);
else
bp_decr(index);
}
bool BasePredictor::bp_getPred(int index){
return (bp_table[index] & PREDMSB);
}
UINT64 BasePredictor::bp_getIndex(UINT64 PC){
return (PC & ((1<<BPINDEXBITS) - 1));
}
//bank methods
Banks::Banks(void){};
void Banks::bank_init(){
for (int i = 0; i < NUMBANKS; i++){
for (int j = 0; j < BANKSIZE; j++){
bank_array[i][j].pred_ctr = 3;
bank_array[i][j].tag = 0;
bank_array[i][j].useful_ctr = 0;
}
}
}
bool Banks::get_pred(int bank, int entry){
return (bank_array[bank][entry].pred_ctr & PREDMSB);
}
bool Banks::tag_match(int bank, int entry, int tag){
return (bank_array[bank][entry].tag == tag);
}
void Banks::set_tag(int bankno, int entry, int tag){
bank_array[bankno][entry].tag = tag;
}
void Banks::incr_pred_ctr(int bank, int entry){
if (bank_array[bank][entry].pred_ctr < MAXSAT)
bank_array[bank][entry].pred_ctr++;
}
void Banks::decr_pred_ctr(int bank, int entry){
if (bank_array[bank][entry].pred_ctr > 0)
bank_array[bank][entry].pred_ctr--;
}
void Banks::set_pred_ctr(int bank, int entry){
bank_array[bank][entry].pred_ctr = 4;
}
void Banks::incr_u_ctr(int bank, int entry){
if (bank_array[bank][entry].useful_ctr < UMAX)
bank_array[bank][entry].useful_ctr++;
}
void Banks::decr_u_ctr(int bank, int entry){
if (bank_array[bank][entry].useful_ctr > 0)
bank_array[bank][entry].useful_ctr--;
}
void Banks::clear_u_ctr(int bank, int entry){
bank_array[bank][entry].useful_ctr = 0;
}
int Banks::get_u_ctr(int bank, int entry){
return bank_array[bank][entry].useful_ctr;
}
void Banks::bank_update(int bankno, int entry, bool resolveDir){
if (resolveDir == TAKEN)
incr_pred_ctr(bankno, entry);
else
decr_pred_ctr(bankno, entry);
}
void Banks::clearMSBs(){
for (int i = 0; i < NUMBANKS; i++){
for (int j = 0; j < BANKSIZE; j++){
bank_array[i][j].useful_ctr &= 1;
}
}
}
void Banks::clearLSBs(){
for (int i = 0; i < NUMBANKS; i++){
for (int j = 0; j < BANKSIZE; j++){
bank_array[i][j].useful_ctr &= 2;
}
}
}
int Banks::get_tag(int bank, int entry){
return bank_array[bank][entry].tag;
}
int LoopPredictor::get_prediction(UINT64 PC){
int index = get_index(PC);
int tag = get_tag(PC);
/* if (loop_table[index].tag != tag)
return -1;*/
if (loop_table[index].confidence == HIGHCONFIDENCE
&& loop_table[index].loop_count > 0
&& loop_table[index].iter_count == loop_table[index].loop_count
&& loop_table[index].miss_count < 1000
&& loop_table[index].tag == tag)
return NOTTAKEN;
else
return -1;
}
void LoopPredictor::UpdatePredictor(UINT64 PC, bool resolveDir, bool predDir, bool usedlp){
int tag = get_tag(PC);
int index = get_index(PC);
//if (usedlp && predDir != resolveDir)
//printf("Index: %d, Tag: %d, Stored Tag: %d, Loop count: %d, Iter Count: %d, confidence: %d, Age:%d\n", index,
//tag, loop_table[index].tag, loop_table[index].loop_count, loop_table[index].iter_count, loop_table[index].confidence, loop_table[index].age);
if (loop_table[index].tag == tag){
//correct
if (predDir == resolveDir){
//took branch
// loop_table[index].miss_count = 0;
if (resolveDir == TAKEN){
loop_table[index].iter_count++;
if (loop_table[index].iter_count > loop_table[index].loop_count &&
loop_table[index].confidence <= LOWCONFIDENCE)
loop_table[index].loop_count = loop_table[index].iter_count;
}
//did not take
else{
incr_confidence(index);
incr_age(index);
loop_table[index].iter_count = 0;
}
}
//incorrect
else{
loop_table[index].miss_count++;
if (resolveDir == TAKEN){
loop_table[index].iter_count++;
}
else{
if (loop_table[index].confidence <= LOWCONFIDENCE){
loop_table[index].loop_count = loop_table[index].iter_count;
}
loop_table[index].iter_count = 0;
}
decr_age(index);
decr_confidence(index);
}
}
else{
if(loop_table[index].age == 0 && resolveDir == TAKEN){
loop_table[index].tag = tag;
loop_table[index].age = INITAGE;
loop_table[index].iter_count = 1;
loop_table[index].loop_count = 1;
loop_table[index].confidence = 0;
loop_table[index].miss_count = 0;
}
else
decr_age(index);
}
}
uint16_t LoopPredictor::get_index(UINT64 PC){
return (PC & ((1 << LPINDEXBITS) - 1));
}
uint16_t LoopPredictor::get_tag(UINT64 PC){
return (PC >> LPINDEXBITS) & ((1 << LPTAGBITS) - 1);
}
void LoopPredictor::init_lp(){
for (int i = 0; i < LPSIZE; i++){
loop_table[i].iter_count = 0;
loop_table[i].loop_count = 0;
loop_table[i].confidence = 0;
loop_table[i].tag = 0;
loop_table[i].age = 0;
loop_table[i].miss_count = 0;
}
}
void LoopPredictor::incr_confidence(uint16_t index){
if (loop_table[index].confidence < HIGHCONFIDENCE)
loop_table[index].confidence++;
}
void LoopPredictor::decr_confidence(uint16_t index){
if (loop_table[index].confidence > 0)
loop_table[index].confidence--;
}
void LoopPredictor::incr_age(uint16_t index){
if (loop_table[index].age < INITAGE)
loop_table[index].age++;
}
void LoopPredictor::decr_age(uint16_t index){
if (loop_table[index].age > 0)
loop_table[index].age--;
}
LoopPredictor::LoopPredictor(void){}; |
fddb829a8745097fa0fe004bac72781502823e3d | 36597ca6d8b08baaef52cddf46bca3d13f0a97a5 | /Plugins/GStreamer/src/chunked_file_sink.cpp | b3a071ba040c56324bb70493ba9822f9abbd73f8 | [
"BSD-3-Clause"
] | permissive | Essarelle/EagleEye | 169f3ce17d1a6ae298a3b764784f29be7ce49280 | 341132edb21b4899ebbe0b52460c4e72e36e4b6d | refs/heads/master | 2020-02-27T21:55:27.725746 | 2017-10-10T06:28:23 | 2017-10-10T06:28:23 | 101,608,078 | 1 | 1 | null | 2017-09-05T06:46:26 | 2017-08-28T05:47:15 | C++ | UTF-8 | C++ | false | false | 3,861 | cpp | chunked_file_sink.cpp | #include "chunked_file_sink.h"
#include <Aquila/framegrabbers/FrameGrabberInfo.hpp>
#include <gst/base/gstbasesink.h>
using namespace aq;
int chunked_file_sink::canLoad(const std::string& document)
{
return 0; // Currently needs to be manually specified
}
int chunked_file_sink::loadTimeout()
{
return 3000;
}
GstFlowReturn chunked_file_sink::on_pull()
{
GstSample *sample = gst_base_sink_get_last_sample(GST_BASE_SINK(_appsink));
if(sample)
{
GstBuffer *buffer;
GstCaps *caps;
GstStructure *s;
GstMapInfo map;
caps = gst_sample_get_caps (sample);
if (!caps)
{
MO_LOG(debug) << "could not get sample caps";
return GST_FLOW_OK;
}
s = gst_caps_get_structure (caps, 0);
gint width, height;
gboolean res;
res = gst_structure_get_int (s, "width", &width);
res |= gst_structure_get_int (s, "height", &height);
//const gchar* format = gst_structure_get_string(s, "format");
if (!res)
{
MO_LOG(debug) << "could not get snapshot dimension\n";
return GST_FLOW_OK;
}
buffer = gst_sample_get_buffer (sample);
if (gst_buffer_map (buffer, &map, GST_MAP_READ))
{
cv::Mat mapped(height, width, CV_8UC3);
memcpy(mapped.data, map.data, map.size);
}
gst_buffer_unmap(buffer, &map);
gst_sample_unref(sample);
gst_buffer_unref(buffer);
}
return GST_FLOW_OK;
}
bool chunked_file_sink::loadData(const std::string& file_path)
{
if(gstreamer_src_base::create_pipeline(file_path))
{
_filesink = gst_bin_get_by_name(GST_BIN(_pipeline), "filesink0");
if(_filesink)
{
this->start_pipeline();
return true;
}
}
return false;
}
MO_REGISTER_CLASS(chunked_file_sink);
int JpegKeyframer::canLoad(const std::string& doc)
{
if(doc.find("http") != std::string::npos && doc.find("mjpg") != std::string::npos)
{
return 10;
}
return 0;
}
int JpegKeyframer::loadTimeout()
{
return 10000;
}
bool JpegKeyframer::loadData(const std::string& file_path)
{
std::stringstream pipeline;
pipeline << "souphttpsrc location=" << file_path;
pipeline << " ! multipartdemux ! appsink name=mysink";
if(this->create_pipeline(pipeline.str()))
{
if(this->set_caps("image/jpeg"))
{
this->start_pipeline();
return true;
}
}
return false;
}
GstFlowReturn JpegKeyframer::on_pull()
{
GstSample *sample = gst_base_sink_get_last_sample(GST_BASE_SINK(_appsink));
if (sample)
{
GstCaps *caps;
caps = gst_sample_get_caps(sample);
if (!caps)
{
MO_LOG(debug) << "could not get sample caps";
return GST_FLOW_OK;
}
++keyframe_count;
}
return GST_FLOW_OK;
}
MO_REGISTER_CLASS(JpegKeyframer);
using namespace aq::nodes;
bool GstreamerSink::processImpl()
{
if(pipeline_param.modified() && !image->empty())
{
this->cleanup();
if(!this->create_pipeline(pipeline))
{
MO_LOG(warning) << "Unable to create pipeline " << pipeline;
return false;
}
if(!this->set_caps(image->getSize(), image->getChannels(), image->getDepth()))
{
MO_LOG(warning) << "Unable to set caps on pipeline";
return false;
}
if(!this->start_pipeline())
{
MO_LOG(warning) << "Unable to start pipeline " << pipeline;
return false;
}
pipeline_param.modified(false);
}
if(_source && _feed_enabled)
{
PushImage(*image, stream());
return true;
}
return false;
}
MO_REGISTER_CLASS(GstreamerSink)
|
334a307667c5669137eaf5559ab03235bfc3a85e | 95b63f08332bc3542ae8262dd33520dbfc0371d2 | /Amigo/ListItem.cpp | 7d3cfd77faa0895b3031bcce83ded6b4230e76bb | [] | no_license | Landeplage/Amigo | 984746c6907e724c82100b30f71f16dcb235fd1c | a15038f6dd72aa05aad5a2b2d937eedb3ab4ff43 | refs/heads/master | 2021-01-23T07:34:54.995297 | 2015-08-16T19:18:09 | 2015-08-16T19:18:09 | 4,243,973 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,008 | cpp | ListItem.cpp | #include "ListItem.h"
#include "Helper.h" //<- debug
ListItem::ListItem(MenuSystem *menuSystem, std::function<void()> onClick)
{
this->menuSystem = menuSystem;
// Set sprite and font
sprite = menuSystem->GetSpriteUI();
font = menuSystem->GetFontRegular();
// Init button
button = new Button(menuSystem, "", Vec2(0, 0), Vec2(0, 0), Align::CENTER, -1, "", onClick);
children.push_back(button);
// Init selection
isSelected = false;
}
void ListItem::Unload()
{
//Unload button
button->Unload();
}
void ListItem::HandleInput()
{
// Handle input on button
button->HandleInput();
}
void ListItem::Update(GLdouble time)
{
// Update button
button->Update(time);
}
void ListItem::Draw()
{
// Draw item back (debug)
if (button->GetState() > 0)
{
Color color = Color(255, 255, 255);
if (button->GetState() == 1)
color = Color(0, 0, 0);
if (button->GetState() == 2)
color = Color(255, 255, 255);
sprite->Draw(position + drawOffset, 0.0f, size - Vec2(-1, 0), color, 0.05f, 0, 72, 1, 1);
}
if (isSelected)
sprite->Draw(position + drawOffset, 0.0f, Vec2(size.x, 1.0f), 1.0f, 40, 47, 1, 24);
// Draw text
Vec2 pos;
GLint xOff;
MenuItem::Align align;
pos = position + drawOffset + Vec2(10, 4);
for (int u = 0; u < strings.size(); u++)
{
align = MenuItem::Align::LEFT;
// Place the text-items horizontally
if (strings.size() > 1) // if there is more than one textItem in this item
{
if (u == strings.size() - 1) // if this is the last textItem
{
pos.x = size.x - 10;
align = MenuItem::Align::RIGHT;
}
else if (u > 0) // if this is not the first textItem
{
pos.x = 10 + ((size.x - 20) / (strings.size() - 1) * u);
}
}
// Align text correctly, if needed.
xOff = 0;
if (align == MenuItem::Align::RIGHT)
xOff = font->GetWidth(strings[u]);
// Draw text
font->Draw(pos - Vec2(xOff, -1), strings[u], 0.0f, Vec2(1.0f, 1.0f), Color(255, 255, 255), 0.6f); // highlight
font->Draw(pos - Vec2(xOff, 0), strings[u], 0.0f, Vec2(1.0f, 1.0f), Color(139, 98, 38), 1.0f); // text
}
}
void ListItem::SetPosition(Vec2 position)
{
MenuItem::SetPosition(position);
// Update button's position
button->SetPosition(position);
}
void ListItem::SetSize(Vec2 size)
{
MenuItem::SetSize(size);
// Update button's size
button->SetSize(size);
}
void ListItem::SetOrigin(Vec2 origin)
{
MenuItem::SetOrigin(origin);
// Update button's origin
button->SetOrigin(origin);
}
void ListItem::SetDrawOffset(Vec2 drawOffset)
{
MenuItem::SetDrawOffset(drawOffset);
// Update button's drawOffset
button->SetDrawOffset(drawOffset);
}
// Add a string to this list item
void ListItem::AddItem(std::string text)
{
strings.push_back(text);
}
// Set the onClick function of the list-item's button
void ListItem::SetOnClick(std::function<void()> onClick)
{
button->SetOnClick(onClick);
}
// Set whether or not this item is selected (used only for visuals)
void ListItem::SetIsSelected(bool isSelected)
{
this->isSelected = isSelected;
} |
6a186bd2fe4f9820f2062da548430c5dab545284 | f481aeb897c81095bf5bc544f9368aa78457694b | /2165.cpp | f737a3ead1c6cc3de56f56717c2e3611ff943896 | [] | no_license | channyHuang/leetcodeOJ | 78b10f31f9a6c6571124208efe85201a3690f2da | b41e9c3c076074b6ab9349455b0cf40c270df41f | refs/heads/master | 2023-01-28T15:31:29.346320 | 2023-01-18T03:43:10 | 2023-01-18T03:43:10 | 221,703,848 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 849 | cpp | 2165.cpp | class Solution {
public:
long long smallestNumber(long long num) {
if (num == 0) return 0;
bool positive = true;
if (num < 0) {
positive = false;
num = -num;
}
string str = to_string(num);
sort(str.begin(), str.end());
int len = str.length();
long long res = 0;
if (positive) {
int pos = 0;
while (str[pos] == '0') pos++;
if (pos > 0) {
str[0] = str[pos];
str[pos] = '0';
}
for (int i = 0; i < len; ++i) {
res = res * 10 + (str[i] - '0');
}
} else {
for (int i = len - 1; i >= 0; i--) {
res = res * 10 + (str[i] - '0');
}
}
return (positive ? res : -res);
}
};
|
2d7a61cdb5a51ac6b9d14bce15e1d1721b3d04f5 | 0f2eec7431f54518342e42d69eec4a6a50ea549d | /include/polygon_research.cpp | 028106732d8cc69e213247b5a76962d252f469fe | [] | no_license | luqmanarifin/grafika | 0d139c8b2c959d3286be93da6eb3ecf95dfeb5c0 | 335b692a1f57f831d2394c14486a7a3e7d74248d | refs/heads/master | 2020-04-10T08:08:47.715012 | 2018-01-24T11:06:42 | 2018-01-24T11:06:42 | 50,510,446 | 2 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 12,767 | cpp | polygon_research.cpp | #ifndef __POLYGON_H
#define __POLYGON_H
#include <cassert>
#include <bits/stdc++.h>
#include "point.h"
#include "framebuffer.h"
#include "line.h"
#include "color.h"
#include "vector.h"
using namespace std;
const double eps = 1e-13;
struct Polygon {
Polygon() {
warna = Color::WHITE;
points = NULL;
size = 0;
}
Polygon(Point<double>* _points, int _size) {
warna = Color::WHITE;
points = _points;
size = _size;
if (size > 2) generateNormal();
}
Polygon(const Polygon& _polygon) {
warna = _polygon.warna;
size = _polygon.size;
points = new Point<double>[size];
for(int i=0;i<size;i++){
points[i]=Point<double>(_polygon.points[i]);
}
if (size > 2) generateNormal();
}
Polygon& operator=(const Polygon& _polygon) {
warna = _polygon.warna;
size = _polygon.size;
if ( points != NULL) delete[] points;
points = new Point<double>[size];
for(int i=0;i<size;i++){
points[i]=Point<double>(_polygon.points[i]);
}
if (size > 2) generateNormal();
return *this;
}
~Polygon() {
if ( points != NULL) delete[] points;
}
double ratio(double a, double b) { return abs(a / b); }
void addCurve(curve(Point<double> a, Point<double> b, Point<double> c, Point<double> d) )
{
Vector<double> ab(a, b);
Vector<double> bc(b, c);
Vector<double> cd(c, d);
double magn1 = ab.magnitude * bc.magnitude;
double magn2 = bc.magnitude * cd.magnitude;
//warna = _color;
if (ratio( Vector<double>::dot( ab, bc ), magn1 ) > 0.995 &&
ratio( Vector<double>::dot( bc, cd ), magn2 ) > 0.995 ) {
//straightLine = new line((int)round(a.x), (int)round(a.y), (int)round(d.x), (int)round(d.y), color);
addPoint(a);
addPoint(d);
} else {
Point<double> d1 = (a + b) * 0.5;
Point<double> d2 = (b*2 + a + c) * 0.25;
Point<double> d3 = (a + b*3 + c*3 + d) * 0.125;
Point<double> d4 = (c*2 + b + d) * 0.25;
Point<double> d5 = (c + d) * 0.5;
addCurve(curve(a, d1, d2, d3));
addCurve(curve(d3, d4, d5, d));
}
}
Polygon& addPoint(const Point<double>& p) {
Point<double>* newPoints = new Point<double>[size + 1];
for(int i = 0; i < size; i++) {
newPoints[i] = points[i];
}
newPoints[size++] = p;
if ( points != NULL) delete[] points;
points = newPoints;
// update center
center.x *= (size - 1);
center.x += p.x;
center.x /= size;
center.y *= (size - 1);
center.y += p.y;
center.y /= size;
center.z *= (size - 1);
center.z += p.z;
center.z /= size;
// cout << center << endl;
if (size > 2) generateNormal();
return *this;
}
// Set Color
Polygon& setColor(int red, int green, int blue, int alpha) { warna = Color(red, green, blue, alpha); return *this; }
Polygon& setColor(const Color& color) { warna = color; return *this; }
static bool same(double a, double b) {
return fabs(a - b) < eps;
}
void print_frame(FrameBuffer& fb, int red, int green, int blue, int alpha) {
for(int i = 0; i < size; i++) {
int j = (i + 1) % size;
line((int) points[i].x, (int) points[i].y, (int) points[j].x, (int) points[j].y, Color(red, green, blue, alpha)).print(fb);
}
}
void dfs(FrameBuffer& fb, int a, int b) {
if(done[a][b]) return;
done[a][b] = 1;
printf("%d %d\n", a, b);
fb.set(a, b, warna);
dfs(fb, a, b + 1);
dfs(fb, a, b - 1);
dfs(fb, a + 1, b);
dfs(fb, a - 1, b);
}
// normalize the point to be printed
// this method does not change the properties of polygon
// parameter : the new normalized point that will be printed
// return the new size of point
int normalize(Point<int>* p) {
int sz = 0;
Point<int>* tmp = new Point<int>[size];
for(int i = 0; i < size; i++) {
Point<int> temp = Point<int>((int)(points[i].x + 0.5), (int)(points[i].y + 0.5), (int)(points[i].z + 0.5));
tmp[sz++] = temp;
}
sz = 0;
for(int i = 0; i < size; i++) {
if(sz >= 2) {
if(tmp[i].y == p[sz-1].y && tmp[i].y == p[sz-2].y) {
if(p[sz-2].x <= p[sz-1].x && p[sz-1].x <= tmp[i].x) {
p[sz-1] = tmp[i];
continue;
}
if(p[sz-2].x >= p[sz-1].x && p[sz-1].x >= tmp[i].x) {
p[sz-1] = tmp[i];
continue;
}
}
if(tmp[i].x == p[sz-1].x && tmp[i].x == p[sz-2].x) {
if(p[sz-2].y <= p[sz-1].y && p[sz-1].y <= tmp[i].y) {
p[sz-1] = tmp[i];
continue;
}
if(p[sz-2].y >= p[sz-1].y && p[sz-1].y >= tmp[i].y) {
p[sz-1] = tmp[i];
continue;
}
}
}
p[sz++] = tmp[i];
}
return sz;
}
// normalize polygon and print. normalize : removing redundant point
Polygon& normalize_and_print(FrameBuffer& fb) {
Point<int>* points = new Point<int>[size];
int size = normalize(points);
int ymin = 1e9, ymak = -1e9;
for(int i = 0; i < size; i++) {
ymin = min(ymin, points[i].y);
ymak = max(ymak, points[i].y);
}
int* a = new int[2 * size];
for(int y = ymin; y <= ymak; y++) {
int sz = 0;
for(int i = 0; i < size; i++) {
int j = (i + 1) % size;
int l = points[i].y;
int r = points[j].y;
if(min(l, r) <= y && y <= max(l, r)) {
int la = points[i].x;
int ra = points[j].x;
if(same(l, r)) {
a[sz++] = min(la, ra);
a[sz++] = max(la, ra);
} else {
int d = (int)round((double) fabs(l - y)*fabs(la - ra)/fabs(l - r));
a[sz++] = la + (la < ra? d : -d);
}
}
}
sort(a, a + sz);
for(int i = 0; i + 1 < sz; i += 2) {
for(int j = (int) a[i]; j <= a[i + 1]; j++) {
fb.set(j, y, warna);
}
}
}
int bmin = 1e9, bmak = -1e9;
for(int i = 0; i < size; i++) {
bmin = min(bmin, points[i].x);
bmak = max(bmak, points[i].x);
}
for(int b = bmin; b <= bmak; b++) {
int sz = 0;
for(int i = 0; i < size; i++) {
int j = (i + 1) % size;
int l = points[i].x;
int r = points[j].x;
if(min(l, r) <= b && b <= max(l, r)) {
int la = points[i].y;
int ra = points[j].y;
if(same(l, r)) {
a[sz++] = min(la, ra);
a[sz++] = max(la, ra);
} else {
int d = (int)round((double)abs(l - b)*abs(la - ra)/abs(l - r));
a[sz++] = la + (la < ra? d : -d);
}
}
}
sort(a, a + sz);
for(int i = 0; i + 1 < sz; i += 2) {
for(int j = (int) a[i]; j <= a[i + 1]; j++) {
fb.set(b, j, warna);
}
}
}
if ( a != NULL) delete[] a;
//print_frame(fb,255,255,255,0);
return *this;
}
// the casual method of print polygon. working nice in moving object
Polygon& print(FrameBuffer& fb) {
double ymin = 1e9, ymak = -1e9;
for(int i = 0; i < size; i++) {
ymin = min(ymin, points[i].y);
ymak = max(ymak, points[i].y);
}
double* a = new double[2 * size];
for(int y = ymin; y <= ymak; y++) {
int sz = 0;
for(int i = 0; i < size; i++) {
int j = (i + 1) % size;
double l = points[i].y;
double r = points[j].y;
if(min(l, r) <= y && y <= max(l, r)) {
double la = points[i].x;
double ra = points[j].x;
if(same(l, r)) {
a[sz++] = min(la, ra);
a[sz++] = max(la, ra);
} else {
double d = fabs(l - y)*fabs(la - ra)/fabs(l - r);
a[sz++] = la + (la < ra? d : -d);
}
}
}
sort(a, a + sz);
for(int i = 0; i + 1 < sz; i += 2) {
for(int j = (int) a[i]; j <= a[i + 1]; j++) {
fb.set(j, y, warna);
}
}
}
double bmin = 1e9, bmak = -1e9;
for(int i = 0; i < size; i++) {
bmin = min(bmin, points[i].x);
bmak = max(bmak, points[i].x);
}
for(int b = bmin; b <= bmak; b++) {
int sz = 0;
for(int i = 0; i < size; i++) {
int j = (i + 1) % size;
double l = points[i].x;
double r = points[j].x;
if(min(l, r) <= b && b <= max(l, r)) {
double la = points[i].y;
double ra = points[j].y;
if(same(l, r)) {
a[sz++] = min(la, ra);
a[sz++] = max(la, ra);
} else {
double d = abs(l - b)*abs(la - ra)/abs(l - r);
a[sz++] = la + (la < ra? d : -d);
}
}
}
sort(a, a + sz);
for(int i = 0; i + 1 < sz; i += 2) {
for(int j = (int) a[i]; j <= a[i + 1]; j++) {
fb.set(b, j, warna);
}
}
}
if ( a != NULL) delete[] a;
print_frame(fb,255,255,255,0);
return *this;
}
void print_dfs(FrameBuffer& fb) {
printf("%d\n", this->size);
Point<int>* p = new Point<int>[this->size];
int size = normalize(p);
int a_min = 1e9, a_mak = -1e9, b_min = 1e9, b_mak = -1e9;
for(int i = 0; i < size; i++) {
a_min = min(a_min, p[i].x);
a_mak = max(a_mak, p[i].x);
b_min = min(b_min, p[i].y);
b_mak = max(b_mak, p[i].y);
}
for(int i = a_min; i <= a_mak; i++) {
for(int j = b_min; j <= b_mak; j++) {
done[i][j] = 0;
}
}
int* up = new int[768];
int* down = new int[768];
int* lef = new int[1366];
int* rig = new int[1366];
fill(up, up + 768, 1e9);
fill(down, down + 768, -1e9);
fill(lef, lef + 1366, 1e9);
fill(rig, rig + 1366, -1e9);
for(int i = 0; i < size; i++) {
int j = (i + 1) % size;
// printf("aku suka asi %d from %d\n", i, size);
line* garis = new line(p[i], p[j], warna);
int size_line;
Point<int>* tmp = garis->generate(size_line);
//printf("%d\n", tmp);
// printf("size line jadi %d : %d %d to %d %d\n", size_line, p[i].x, p[i].y, p[j].x, p[j].y);
// for(int k = 0; k < size_line; k++) printf("%d %d\n", tmp[k].x, tmp[k].y);
for(int k = 0; k < size_line; k++) {
int a = tmp[k].x, b = tmp[k].y;
done[a][b] = 1;
up[a] = min(up[a], b);
down[a] = max(down[a], b);
lef[b] = min(lef[b], a);
rig[b] = max(rig[b], a);
fb.set(a, b, warna);
}
delete[] tmp;
delete garis;
}
printf("done print tepi %d-%d %d-%d\n", a_min, a_mak, b_min, b_mak);
bool found = 0;
for(int i = a_min; i <= a_mak && !found; i++) {
for(int j = b_min; j <= b_mak & !found; j++) {
if(up[i] < i && i < down[i] && lef[j] < j && j < rig[j] && !done[i][j]) {
dfs(fb, i, j);
found = 1;
}
}
}
printf("dfs done\n");
puts("done print polygon");
return *this;
}
int MaxX(){
int Max=0;
for(int i=0;i <size;i++){
if(points[i].x>Max){
Max = points[i].x;
}
}
return Max;
}
int MaxY(){
int Max=0;
for(int i=0;i <size;i++){
if(points[i].y>Max){
Max = points[i].y;
}
}
return Max;
}
int MinX(){
int Min=1400;
for(int i=0;i <size;i++){
if(points[i].x<Min){
Min = points[i].x;
}
}
return Min;
}
int MinY(){
int Min=800;
for(int i=0;i <size;i++){
if(points[i].y<Min){
Min = points[i].y;
}
}
return Min;
}
Polygon& resize(double factor, const Point<double>& center = Point<double>()) {
for (int i = 0; i < size; ++i) {
points[i].scale(factor, center);
}
this->center.scale(factor, center);
return *this;
}
Polygon& resizeCenter(double factor) {
return resize(factor, this->center);
}
Polygon& move(int x, int y) {
for (int i = 0; i < size; ++i) {
points[i].move(x, y);
}
center.move(x, y);
return *this;
}
Polygon& rotate(double degreeZ, const Point<double>& center = Point<double>(0, 0), double degreeX = 0, double degreeY = 0) {
for (int i = 0; i < size; ++i) {
points[i].rotate(degreeZ, center, degreeX, degreeY);
}
this->center.rotate(degreeZ, center, degreeX, degreeY);
if (size > 2) norm.rotate(degreeZ, degreeX, degreeY);
return *this;
}
Polygon& rotateCenter(double degreeZ, double degreeX = 0, double degreeY = 0) {
return rotate(degreeZ, this->center, degreeX, degreeY);
}
Polygon& generateNormal() {
assert(this->size > 2);
norm = Vector<double>::cross(Vector<double>(points[0],points[1]), Vector<double>(points[0], points[2]));
return *this;
}
Point<double>* points;
int size;
Point<double> center;
Vector<double> norm;
Color warna;
};
#endif
|
9060c217ac84a9d7c0ec471a289d7ff7b4115866 | 9ed1141efe9555f55c28974b8b29486c981eb97c | /3_28字符串匹配/3_28字符串匹配/3_28字符串匹配.cpp | 5d211b07a9a48a47a255989ff88b875d2c82e58f | [] | no_license | fwqaq/vscode | d7e6f17b3ddb1280f207e03006ccf45c70b4e22e | c69794ec1e3ea719226c719b7109319a16fda52a | refs/heads/master | 2022-03-02T21:08:03.918960 | 2019-08-29T15:16:56 | 2019-08-29T15:16:56 | 160,153,996 | 0 | 0 | null | null | null | null | GB18030 | C++ | false | false | 782 | cpp | 3_28字符串匹配.cpp | #include <iostream>
#include <set>
#include <string>
using namespace std;
int main(){
//输入两个字符串
//输入包括两行, 第一行一个字符串A, 字符串A长度length(1 ≤ length ≤ 50), A中每个字符都是'0'或者'1'。
// 第二行一个字符串B, 字符串B长度length(1 ≤ length ≤ 50), B中的字符包括'0', '1'和'?'。
string A;
string B;
cin >> A;
cin >> B;
set<string>se;
int A_len = A.length();
int B_len = B.length();
for (int i = 0; i < A_len - B_len + 1; i++){
int flag = 1;
for (int j = 0; j < B_len; j++){
if (!(B[j] == A[i + j] || B[j] == '?')){
flag = 0;
break;
}
}
if (flag){
string s = A.substr(i, B_len);
se.insert(s);
}
}
cout << se.size() << endl;
system("pause");
return EXIT_SUCCESS;
} |
5a386b2e44b2fbb4955942dd1a8b2815ec257453 | 9cc4ee6abd8dd3598c21562a3aecf8f2aed57e87 | /DS/MaxFlow/FordFulkerson.cpp | 20ed5e53c6bc1f865fbe5923350ac9b111e60232 | [] | no_license | Yariki/alg | e84457bb0cb6ad5e4386703d3d0867044a5e5743 | 49170a99d9f317b5d09bc4b68992da24f2694ddd | refs/heads/master | 2021-01-19T07:09:34.971829 | 2020-05-06T20:21:18 | 2020-05-06T20:21:18 | 60,982,635 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,507 | cpp | FordFulkerson.cpp | //
// Created by Yariki on 2/2/2020.
//
#include "FordFulkerson.h"
#include <limits>
#include <queue>
#include <deque>
FordFulkerson::FordFulkerson(FlowNetwork *network, int s, int t) {
value = 0;
while (hasAugmenticPath(network,s, t) > 0){
double bottle = numeric_limits<double>::max();
for(int v = t; v != s; v = edgeTo[v]->other(v)){
if(edgeTo[v] == NULL) continue;
bottle = std::min(bottle, edgeTo[v]->residualCapacity(v));
}
for (int v = t; v != s ; v = edgeTo[v]->other(v)) {
if(edgeTo[v] == NULL) continue;
edgeTo[v]->addResidualFlowTo(v,bottle);
}
value += bottle;
}
}
FordFulkerson::~FordFulkerson() {
}
double FordFulkerson::hasAugmenticPath(FlowNetwork *network, int s, int t) {
edgeTo = vector<FlowEdge*>(network->getV());
marked = vector<bool>(network->getV());
deque<int> q;
q.push_back(s);
while (!q.empty()){
int v = q.front();
q.pop_front();
auto edges = network->getAdj(v);
for (int i = 0; i < edges->size(); ++i) {
auto edge = edges->at(i);
int w = edge->other(v);
if(edge->residualCapacity(w) > 0 && !marked[w]){
edgeTo[w] = edge;
marked[w] = true;
q.push_back(w);
}
}
}
return marked[t];
}
double FordFulkerson::getValue() {
return value;
}
bool FordFulkerson::isCut(int v) {
return marked[v];
}
|
dbbbda0375bda0e06d947bd3d48a046cf6f17f66 | b9b5e350942f5d4114f2c66a7d4c816e0ffb1cc8 | /useless.cpp | bac6b02e3ff78b92a99efb8535f972ac06d2e536 | [] | no_license | gkatz20/test | 4fb6f144a0bca428b81b48e4be5c1a55bd62d221 | 180c500ffa8a509164e969c157b349a806fc2981 | refs/heads/master | 2021-01-23T03:53:15.455879 | 2017-03-25T04:00:46 | 2017-03-25T04:00:46 | 86,130,799 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 10 | cpp | useless.cpp | // its lit |
548a0723533a0ebf1674ceae23627d2ffa2be3d9 | a5b2c153e99b2194f2149300732af5745dc11a23 | /src/CGhostEasy.cpp | 35a9bf7845ae07f900187b181e29d7061652ca1d | [] | no_license | adameen/ascii-pacman | be114bdbb38894d334e9d9229131eb7c9cd7f021 | 5023a77e95ace1a2920a95572eac22d70cfb5e18 | refs/heads/master | 2021-07-24T03:52:03.386415 | 2017-11-03T18:21:17 | 2017-11-03T18:21:17 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,475 | cpp | CGhostEasy.cpp | #include "CGhostEasy.h"
CGhostEasy::CGhostEasy(CData& alldata) : m_LastChar(' '), m_CycleCounter(0){
int x, y;
m_Direction = 8; // first direction is up
alldata.getGhostIndex(x, y); // assigns coordinates to the ghost from member variable of CData
m_X = x;
m_Y = y;
m_OriginalX = m_X; // saves original coordinates to refresh it after the game is over
m_OriginalY = m_Y;
}
int CGhostEasy::move(const int button, CData & alldata){
int value = 0;
int random = -1;
int lastX = 0; // to check last coordinates - ghost should not be able to go back
int lastY = 0;
int oppositeDirection = 0; // if there is a "dead-end street", turn around
int up = alldata.getBool(m_X, m_Y-1); // to know if there is a free way in the up side
int down = alldata.getBool(m_X, m_Y+1);
int left = alldata.getBool(m_X-1, m_Y);
int right = alldata.getBool(m_X+1, m_Y);
srand (time(NULL)); // puts a seed of random number
if(m_Direction == 8){ // check last index and opposite direction if ghost's direction is "up"
lastX = m_X;
lastY = m_Y+1;
oppositeDirection = 2;
}
else if(m_Direction == 2){
lastX = m_X;
lastY = m_Y-1;
oppositeDirection = 8;
}
else if(m_Direction == 4){
lastX = m_X+1;
lastY = m_Y;
oppositeDirection = 6;
}
else{ //m_Direction == 6
lastX = m_X-1;
lastY = m_Y;
oppositeDirection = 4;
}
while(1){
m_CycleCounter++;
if(m_CycleCounter == 50){ // if there are 50 unsuccessful tries (iterates), turn around
if(oppositeDirection == 8) { value = moveUp(alldata); }
else if(oppositeDirection == 2) { value = moveDown(alldata); }
else if(oppositeDirection == 4) { value = moveLeft(alldata); }
else value = moveRight(alldata);
m_CycleCounter = 0;
break;
}
random = rand() % 4;
if(random == 0){ // check going up
if(up == 0 || (m_Y-1 == lastY && m_X == lastX)) continue; // if can't go up or would go back
else{
m_CycleCounter = 0;
value = moveUp(alldata);
break;
}
}
else if(random == 1){ // check going down
if(down == 0 || (m_Y+1 == lastY && m_X == lastX)) continue;
else{
m_CycleCounter = 0;
value = moveDown(alldata);
break;
}
}
else if(random == 2){ // check going left
if(left == 0 || (m_X-1 == lastX && m_Y == lastY)) continue;
else{
m_CycleCounter = 0;
value = moveLeft(alldata);
break;
}
}
else{ //random == 3 ...// check going right
if(right == 0 || (m_X+1 == lastX && m_Y == lastY)) continue;
else{
m_CycleCounter = 0;
value = moveRight(alldata);
break;
}
}
}
return value;
}
int CGhostEasy::moveUp(CData& alldata){
if(alldata.getChar(m_X, m_Y-1) == 'C' || alldata.getChar(m_X, m_Y-1) == 'O'){ // got pacman
m_Direction = 8;
return -1;
}
else if(alldata.getChar(m_X, m_Y-1) == 'A'){ // on the next index is another ghost - dont move, just turn around
m_Direction = 2;
return 0;
}
else{
alldata.changeCharMap(m_Y, m_X, m_LastChar);
m_LastChar = alldata.getChar(m_X, m_Y-1);
alldata.changeCharMap(m_Y-1, m_X, 'A');
m_Direction = 8;
m_Y--;
return 0;
}
}
int CGhostEasy::moveDown(CData& alldata){
if(alldata.getChar(m_X, m_Y+1) == 'C' || alldata.getChar(m_X, m_Y+1) == 'O'){
m_Direction = 8;
return -1;
}
else if(alldata.getChar(m_X, m_Y+1) == 'A'){
m_Direction = 8;
return 0;
}
else{
alldata.changeCharMap(m_Y, m_X, m_LastChar);
m_LastChar = alldata.getChar(m_X, m_Y+1);
alldata.changeCharMap(m_Y+1, m_X, 'A');
m_Direction = 2;
m_Y++;
return 0;
}
}
int CGhostEasy::moveLeft(CData& alldata){
if(alldata.getChar(m_X-1, m_Y) == 'C' || alldata.getChar(m_X-1, m_Y) == 'O'){
m_Direction = 8;
return -1;
}
else if(alldata.getChar(m_X-1, m_Y) == 'A'){
m_Direction = 6;
return 0;
}
else{
alldata.changeCharMap(m_Y, m_X, m_LastChar);
m_LastChar = alldata.getChar(m_X-1, m_Y);
alldata.changeCharMap(m_Y, m_X-1, 'A');
m_Direction = 4;
m_X--;
return 0;
}
}
int CGhostEasy::moveRight(CData& alldata){
if(alldata.getChar(m_X+1, m_Y) == 'C' || alldata.getChar(m_X+1, m_Y) == 'O'){
m_Direction = 8;
return -1;
}
else if(alldata.getChar(m_X+1, m_Y) == 'A'){
m_Direction = 4;
return 0;
}
else{
alldata.changeCharMap(m_Y, m_X, m_LastChar);
m_LastChar = alldata.getChar(m_X+1, m_Y);
alldata.changeCharMap(m_Y, m_X+1, 'A');
m_Direction = 6;
m_X++;
return 0;
}
}
void CGhostEasy::takeGhostHome(CData& alldata){ // after every pacman killing - put last char down and transport "home"
alldata.changeCharMap(m_Y, m_X, m_LastChar);
m_X = m_OriginalX;
m_Y = m_OriginalY;
alldata.changeCharMap(m_Y, m_X, 'A'); // puts ghost gome
m_LastChar = ' ';
}
|
1b94609e048165966f7e14005a1822e88d41df6e | c25b4a24dafd06d47749991f36083346dd231976 | /Algorithms/Implementation/Forming_a_Magic_Square.cpp | 5e4644801ab461fe7cc5912be0b8b42572d2da6e | [] | no_license | TonyHidalgo/HackerRank | d53e1567c98ac38fa81ce009119db3b49410e1b4 | 2a1e4a22922ae3d8b24a877cf24c6709196d39a4 | refs/heads/master | 2021-03-21T21:33:35.991865 | 2020-03-27T00:28:36 | 2020-03-27T00:28:36 | 247,328,749 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,893 | cpp | Forming_a_Magic_Square.cpp | #include <bits/stdc++.h>
using namespace std;
bool is_magic(vector<int> m)
{
vector<int> s[3];
// CONSTRUYO MATRIZ
for (size_t i = 0; i < 3; i++)
{
for (size_t j = 0; j < 3; j++)
{
if (i != 0)
s[i].push_back(m[(i + j) + i * 2]);
else
s[i].push_back(m[j]);
}
}
// FILAS
for (size_t i = 0; i < 3; i++)
{
int sum = 0;
for (size_t j = 0; j < 3; j++)
{
sum += s[i][j];
}
if (sum != 15)
return false;
}
// COLUMNAS
for (size_t i = 0; i < 3; i++)
{
int sum = 0;
for (size_t j = 0; j < 3; j++)
{
sum += s[j][i];
}
if (sum != 15)
return false;
}
// DIAGONALES
if (s[0][0] + s[1][1] + s[2][2] != 15 or s[0][2] + s[1][1] + s[2][0] != 15)
return false;
return true;
}
vector<vector<int>> generate_matriz()
{
vector<vector<int>> l;
vector<int> v(9);
for (int i = 0; i < 9; ++i)
v[i] = i + 1;
do
{
if (is_magic(v))
l.push_back(v);
} while (next_permutation(v.begin(), v.end()));
return l;
}
int main()
{
vector<int> m;
for (size_t i = 0; i < 3; i++)
{
int a, b, c;
cin >> a >> b >> c;
m.push_back(a);
m.push_back(b);
m.push_back(c);
}
if (is_magic(m))
{
cout << "0";
}
else
{
vector<vector<int>> magicos = generate_matriz();
vector<int> costos;
for (auto s : magicos)
{
int cost = 0;
for (size_t i = 0; i < 9; i++)
{
cost += abs(s[i] - m[i]);
}
costos.push_back(cost);
}
sort(costos.begin(), costos.end());
cout << costos[0] << endl;
}
} |
fdd41b4b6f023eaa3fb7722a271df989cf106089 | 1e1b4146b0ae8014ea24f7182e0794d4859faa1b | /parboil/common/src/parboil_hstreams.cpp | 7450b3090e8a347dd8344b0fa6ce270a659ff4b6 | [] | no_license | Wisdom-moon/hStreams-benchmark | ba351f1d74053a46cd5523b5ef1f81317fa16ac4 | bee0daf5069605a1135963846c494f304cd8331f | refs/heads/master | 2021-05-13T13:21:17.785653 | 2018-01-10T11:41:59 | 2018-01-10T11:41:59 | 116,703,866 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,544 | cpp | parboil_hstreams.cpp | /*
* (c) 2007 The Board of Trustees of the University of Illinois.
*/
#include <parboil_hstreams.h>
int parboil_hstreams_init(int logical_streams, char * lib_name)
{
uint32_t places_per_domain = 1;
uint32_t logical_streams_per_place = logical_streams;
HSTR_OPTIONS hstreams_options;
hStreams_GetCurrentOptions(&hstreams_options, sizeof(hstreams_options));
hstreams_options.verbose = 0;
hstreams_options.phys_domains_limit = 256; // Limit to 256 domains
char *libNames[20] = {NULL,NULL};
unsigned int libNameCnt = 0;
libNames[libNameCnt++] = lib_name;
hstreams_options.libNames = libNames;
hstreams_options.libNameCnt = (uint16_t)libNameCnt;
hStreams_SetOptions(&hstreams_options);
int iret = hStreams_app_init(places_per_domain, logical_streams_per_place);
if( iret != 0 )
{
printf("hstreams_app_init failed!\r\n");
exit(-1);
}
return 0;
}
double dtimeElapse(double t1)
{
double t2;
double telapsed;
struct timeval tv2;
gettimeofday(&tv2,NULL);
t2 = (tv2.tv_sec) * 1.0e6 + tv2.tv_usec;
telapsed = t2 - t1;
return( telapsed );
}
double dtimeSince(double t1,char *str)
{
double t2;
double telapsed;
struct timeval tv2;
gettimeofday(&tv2,NULL);
t2 = (tv2.tv_sec) *1.0e6 + tv2.tv_usec;
telapsed = t2 - t1;
printf("%.5g secs <-- Elapsed Time for: '%s'\r\n",telapsed,str);
fflush(stdout);
return( telapsed );
}
double dtimeGet()
{
double t;
struct timeval tv1;
gettimeofday(&tv1,NULL);
t = (tv1.tv_sec)* 1.0e6 + tv1.tv_usec;
t = t / 1.0e6;
return(t);
}
|
292b6d4a988d7725d25e8daa2a99329e16c6da8a | b367fe5f0c2c50846b002b59472c50453e1629bc | /xbox_leak_may_2020/xbox trunk/xbox/private/test/directx/d3d/conf/alphabld/invdestalpha.h | aa857fff8e73dc877904bfa9671a75df01c48f10 | [] | no_license | sgzwiz/xbox_leak_may_2020 | 11b441502a659c8da8a1aa199f89f6236dd59325 | fd00b4b3b2abb1ea6ef9ac64b755419741a3af00 | refs/heads/master | 2022-12-23T16:14:54.706755 | 2020-09-27T18:24:48 | 2020-09-27T18:24:48 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,796 | h | invdestalpha.h | /*==========================================================================;
*
* Copyright (C) 1994-1996 Microsoft Corporation. All Rights Reserved.
*
* File: InvDestAlpha.h
*
***************************************************************************/
#ifndef __INVDESTALPHA_H__
#define __INVDESTALPHA_H__
// InvDestAlpha/Zero Class definitions
class CInvDestAlphaZeroTest: public CAlphaBldTest
{
public:
CInvDestAlphaZeroTest();
~CInvDestAlphaZeroTest();
bool SetDefaultRenderStates(void);
};
// InvDestAlpha/One Class definitions
class CInvDestAlphaOneTest: public CAlphaBldTest
{
public:
CInvDestAlphaOneTest();
~CInvDestAlphaOneTest();
bool SetDefaultRenderStates(void);
};
// InvDestAlpha/SrcColor Class definitions
class CInvDestAlphaSrcColorTest: public CAlphaBldTest
{
public:
CInvDestAlphaSrcColorTest();
~CInvDestAlphaSrcColorTest();
bool SetDefaultRenderStates(void);
};
// InvDestAlpha/InvSrcColor Class definitions
class CInvDestAlphaInvSrcColorTest: public CAlphaBldTest
{
public:
CInvDestAlphaInvSrcColorTest();
~CInvDestAlphaInvSrcColorTest();
bool SetDefaultRenderStates(void);
};
// InvDestAlpha/SrcAlpha Class definitions
class CInvDestAlphaSrcAlphaTest: public CAlphaBldTest
{
public:
CInvDestAlphaSrcAlphaTest();
~CInvDestAlphaSrcAlphaTest();
bool SetDefaultRenderStates(void);
};
// InvDestAlpha/InvSrcAlpha Class definitions
class CInvDestAlphaInvSrcAlphaTest: public CAlphaBldTest
{
public:
CInvDestAlphaInvSrcAlphaTest();
~CInvDestAlphaInvSrcAlphaTest();
bool SetDefaultRenderStates(void);
};
// InvDestAlpha/DestAlpha Class definitions
class CInvDestAlphaDestAlphaTest: public CAlphaBldTest
{
public:
CInvDestAlphaDestAlphaTest();
~CInvDestAlphaDestAlphaTest();
bool SetDefaultRenderStates(void);
};
// InvDestAlpha/InvDestAlpha Class definitions
class CInvDestAlphaInvDestAlphaTest: public CAlphaBldTest
{
public:
CInvDestAlphaInvDestAlphaTest();
~CInvDestAlphaInvDestAlphaTest();
bool SetDefaultRenderStates(void);
};
// InvDestAlpha/DestColor Class definitions
class CInvDestAlphaDestColorTest: public CAlphaBldTest
{
public:
CInvDestAlphaDestColorTest();
~CInvDestAlphaDestColorTest();
bool SetDefaultRenderStates(void);
};
// InvDestAlpha/InvDestColor Class definitions
class CInvDestAlphaInvDestColorTest: public CAlphaBldTest
{
public:
CInvDestAlphaInvDestColorTest();
~CInvDestAlphaInvDestColorTest();
bool SetDefaultRenderStates(void);
};
// InvDestAlpha/SrcAlphaSat Class definitions
class CInvDestAlphaSrcAlphaSatTest: public CAlphaBldTest
{
public:
CInvDestAlphaSrcAlphaSatTest();
~CInvDestAlphaSrcAlphaSatTest();
bool SetDefaultRenderStates(void);
};
#endif |
bc626751840c11892d56f6355aaadc79dcbfc9f0 | 8c3b16c89409566edb71510dfe75a8a8c9beedea | /nf2x/src/executor/executor_select.cpp | 285226b020d9fefd47da7c9df7084b22c14b0563 | [] | no_license | jcshaw/namedfolders | 3a09736dc09b66da6922296d88d8e61c3db33af0 | ccc4d466d1d20b9f16bcd8bb54f7e16ee04b5858 | refs/heads/master | 2021-01-10T09:00:22.393541 | 2014-01-20T03:29:05 | 2014-01-20T03:29:05 | 54,491,456 | 0 | 0 | null | null | null | null | WINDOWS-1251 | C++ | false | false | 8,066 | cpp | executor_select.cpp | /*
* Far Named Folders 3.x
* Copyright (c) 2002-2010 by Victor Derevyanko, RAMMuS Group
* www: http://www.rammus.ru, http://derevyanko.blogspot.com/
* e-mail: dvpublic0@gmail.com
*/
#include "StdAfx.h"
#include "executor_select.h"
#include "StdAfx.h"
#include <cassert>
#include <vector>
#include <shlwapi.h>
#include <boost/bind.hpp>
#include "executor.h"
#include "Kernel.h"
#include "stlcatalogs.h"
#include "menu2.h"
#include "executor_addons.h"
#include "lang.h"
#include "codec_for_values.h"
#include "header.h"
#include "confirmations.h"
#include "strings_utils.h"
#include "Parser.h"
#include "searcherpaths.h"
#include "select_variants.h"
extern struct PluginStartupInfo g_PluginInfo;
extern struct FarStandardFunctions g_FSF;
using namespace nf;
//найти все пути, подходящие для Value и LocalPath
//и вернуть их полный список в DestListPaths
void nf::Selectors::GetPath(HANDLE hPlugin
, tstring const &Value
, tstring const &LocalPath0
, nf::twhat_to_search_t WhatToSearch
, std::list<tstring> &DestListPaths)
{
//p может содержать метасимволы
//находим все директории, удовлетворяющие panel.value
//комбинации символов указывающие на поиск неограниченной глубины
//заменяем спецсимволами
tstring LocalPath = LocalPath0;
LocalPath = Utils::ReplaceStringAll(LocalPath, _T(".*."), DEEP_REVERSE_SEARCH);
LocalPath = Utils::ReplaceStringAll(LocalPath, _T("\\*\\"), DEEP_DIRECT_SEARCH);
LocalPath = Utils::ReplaceStringAll(LocalPath, LEVEL_UP_TWO_POINTS, DEEP_UP_DIRECTORY);
if (nf::Parser::IsContainsMetachars(Value))
{ //при поиске начальной директории всегда ищем и директории
nf::SearchPathsPolices::CSearchFarPolice ssp(nf::WTS_DIRECTORIES);
// nf::SearchPathsPolices::CSearchSystemPolice ssp(false, false);
nf::CSearcherPaths sp(DestListPaths, ssp);
sp.SearchMatched(Value);
} else {
DestListPaths.push_back(Value);
}
if (! LocalPath.empty())
{ //учитываем локальный путь относительно каждой найденной директории
std::list<tstring> list_paths;
// LocalPath = Parser::ConvertToMask(LocalPath);
nf::SearchPathsPolices::CSearchSystemPolice ssp(WhatToSearch);
nf::CSearcherPaths sp(list_paths, ssp);
std::for_each(DestListPaths.begin(), DestListPaths.end()
, boost::bind(&nf::CSearcherPaths::SearchByPattern, &sp, LocalPath.c_str(), _1));
DestListPaths.swap(list_paths);
}
}
bool nf::Selectors::GetPath(HANDLE hPlugin
, tstring const &SrcPath
, tstring const &LocalPath0
, tstring &ResultPath
, nf::twhat_to_search_t WhatToSearch)
{
//найти все пути, подходящие для Value и LocalPath
//дать возможность пользователю выбрать требуемый путь
//и вернуть его в ResultPath
std::list<tstring> value_paths;
GetPath(hPlugin, SrcPath, LocalPath0, WhatToSearch, value_paths);
value_paths.sort();
//при игре в \ и .. легко могут появиться множественные варианты одного и того же файла
value_paths.unique();
//меню выбора вариантов
if (! value_paths.empty()) return Menu::SelectPath(value_paths, ResultPath) != 0;
return false;
};
//выбрать наиболее подходящий псевдоним из списка вариантов
//выбор на основе имени псевдонима
bool nf::Selectors::GetShortcut(HANDLE hPlugin
, nf::tparsed_command const &cmd
, nf::tshortcut_info& DestSh)
{
//псевдоалиас "."
if (cmd.shortcut == _T("."))
{
DestSh.bIsTemporary = false;
DestSh.catalog = _T("");
DestSh.shortcut = _T(".");
return true;
}
while (true)
{
nf::tshortcuts_list list;
size_t nexact = Shell::SelectShortcuts(cmd.shortcut.c_str(), cmd.catalog.c_str(), list);
//если найден один единственный точный вариант
//но есть и другие варианты
//то, в зависимости от настроек,
//переходим прямо к нему
//либо предлагаем выбрать другие варианты
bool bExpand = (nexact == 1)
? CSettings::GetInstance().GetValue(nf::ST_ALWAYS_EXPAND_SHORTCUTS)
: ! list.empty(); //требуется выбирать из меню..
if (bExpand)
{
int n = Menu::SelectShortcut(list, DestSh);
if (n == -1)
{ //удалить выбраный псевдоним..
nf::Commands::Deleter::DeleteShortcut(DestSh, false);
} else return n > 0;
} else {
if (!list.empty())
{
DestSh = *list.begin();
return true;
}
return false;
}
} //while
}
bool nf::Selectors::GetAllShortcuts(HANDLE hPlugin
, nf::tparsed_command const &cmd
, nf::tshortcuts_list& DestList)
{ //выбрать все подходящие псевдонимы из списка
size_t nexact = Shell::SelectShortcuts(cmd.shortcut.c_str(), cmd.catalog.c_str(), DestList);
if (cmd.shortcut == _T("."))
{ //псевдоалиас "."
nf::tshortcut_info sh;
sh.bIsTemporary = false;
sh.catalog = _T("");
sh.shortcut = _T(".");
DestList.push_back(sh);
}
return ! DestList.empty();
}
//выбрать наиболее подходящий каталог из списка вариантов
bool nf::Selectors::GetCatalog(HANDLE hPlugin
, nf::tparsed_command const &cmd
, nf::tcatalog_info &DestCatalog)
{
nf::tcatalogs_list list;
if (cmd.catalog.empty()){
DestCatalog = _T("");
return true; //корневой каталог - выбирать нечего...
}
tstring catalog_name = cmd.catalog;
Utils::RemoveTrailingChars(catalog_name, SLASH_CATS_CHAR);
Shell::SelectCatalogs(catalog_name.c_str(), list);
Utils::add_leading_char_if_not_exists(catalog_name, SLASH_CATS);
if (list.empty()) return false; //нет вариантов
//если найден один единственный точный вариант
//то переходим прямо к нему - иначе предлагаем выбрать варианты
bool bExpand = list.size() > 1; //требуется выбирать из меню..
if (bExpand)
{
int n = Menu::SelectCatalog(list, DestCatalog);
return n > 0;
} else {
DestCatalog = *list.begin();
return true;
}
}
bool nf::Selectors::FindBestDirectory(HANDLE hPlugin
, nf::tshortcut_value_parsed const &p
, tstring &DestDir)
{ //найти наилучшую директории
//если требуемой директории нет - найти ближайшую
assert(p.ValueType != nf::VAL_TYPE_PLUGIN_DIRECTORY); //остальные типы должны открывать через эмуляцию нажатия клавиш
tstring dir_oem = Utils::GetInternalToOem(p.value);
if (! ::PathFileExists(dir_oem.c_str()))
{ //находим ближайшую директорию
nf::tautobuffer_char buf(dir_oem.size()+1);
lstrcpy(&buf[0], dir_oem.c_str());
do {
if (! ::PathRemoveFileSpec(&buf[0])) return false; //ближайшей директории не оказалось..
} while (! ::PathFileExists(&buf[0]));
//!todo предложение удалить
//!подтвердить переход в ближайшую директорию
if (! nf::Confirmations::AskToGoToNearest(hPlugin, dir_oem.c_str(), &buf[0])) return false;
dir_oem = &buf[0];
}
DestDir = Utils::GetOemToInternal(dir_oem);
return true;
} //find_best_dir |
9c54140d10873b42c6fbcd2ca9c560937f9357a4 | 0cc5fc61e5c6f24062b61b93f8c81ccbcec1f78b | /Projects/CoX/Clients/Client_I0/renderer/RenderTree.h | 1724c9f8a8e0c7f92744fa63e617bb7e6f99967b | [
"BSD-3-Clause",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | Tristochi/Segs | d4259c95c599cd86e177db978308fd2b2aaa7ca9 | e7fb05fe1f763286adb116c787357f67387f3a7f | refs/heads/develop | 2020-05-16T08:15:26.195569 | 2019-04-22T17:48:52 | 2019-04-22T17:48:52 | 182,903,316 | 1 | 0 | BSD-3-Clause | 2019-04-23T02:01:38 | 2019-04-23T02:01:37 | null | UTF-8 | C++ | false | false | 1,533 | h | RenderTree.h | #pragma once
#include "utils/helpers.h"
#include "RenderBonedModel.h"
#include <vector>
struct GfxTree_Node;
struct Model;
struct SortThing
{
char blendMode;
char modelSource;
union
{
GfxTree_Node* gfxnode;
int vsIdx;
};
union
{
float distsq;
Model* model;
};
};
static_assert(sizeof(SortThing) == 0xC);
struct ViewSortNode
{
Matrix4x3 mat;
Vector3 mid;
Model *model;
uint8_t alpha;
char has_tint;
char has_texids;
float distsq;
GLuint rgbs;
struct EntLight *light;
RGBA tint_colors[2];
struct TextureBind *tex_binds[2];
};
static_assert(sizeof(ViewSortNode) == 0x60);
extern std::vector<SortThing> ModelArrayTypeSort;
extern std::vector<SortThing> ModelArrayDistSort;
extern std::vector<ViewSortNode> vsArray;
extern TextureBind *g_global_texbinds[3];
extern int nodeTotal;
extern int NodesDrawn;
extern int drawGfxNodeCalls;
extern int sortedByDist;
extern int sortedByType;
extern int viewspaceMatCount;
extern void segs_gfxTreeDrawNode(GfxTree_Node *basenode, const Matrix4x3 &parent_mat);
extern void segs_rendertree_modelDrawWorldmodel(ViewSortNode *vs);
extern void segs_modelDrawGfxNode(struct GfxTree_Node *node);
extern void patch_rendertree();
void segs_addViewSortNode(GfxTree_Node *node, Model *model, Matrix4x3 *mat, Vector3 *mid, int alpha, GLuint rgbs, RGBA *tint_colors, TextureBind **custom_texbinds, EntLight *light);
void segs_modelAddShadow(Matrix4x3 *mat, uint8_t alpha, Model *model, uint8_t mask);
|
743db241be824118373788057e13ca0202ff0ea3 | 210462f884c7e9a6d49d4462e648f22712bac7b1 | /CS-144-007-02/Prime/primeFunctions.h | 6e819598e57abbf6d87f971d4e82d1678eb3681b | [] | no_license | wallenben/CSI | d333bddb5fb64cdc5025765b48c2672bd7746492 | eba2aa11102127865c5dceca0566ffc0b0bcbc4d | refs/heads/main | 2023-02-23T13:08:11.790696 | 2021-01-25T20:06:11 | 2021-01-25T20:06:11 | 320,944,610 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 826 | h | primeFunctions.h | #ifndef PRIMEFUNCTIONS_H_2020_11_05
#define PRIMEFUNCTIONS_H_2020_11_05
#include <iostream>
#include <string>
using std::string;
using std::ostream;
using std::istream;
// check if a file has not been seen
// mark it as seen
// functions/enums/etc.
/**
@breif Determines if a number is prime.
Determines if a number is prime.
@param num The number to check if it is prime.
@return True if prime, false if not.
*/
bool isPrime(int num);
// TODO add more functions
// parameter passing
// by default - parameters are passed-by-value
// makes a copy
// passed-by-reference
// pass a memory address
// add an & between the type and the name
void outputPrimeNum(ostream& output, int num, bool prime);
string formatPrimeNum(int num, bool prime);
int getValidInput(istream& input);
#endif // PRIMEFUNCTIONS_H_2020_11_05 |
0f1436f6c62556a780e0514d5d50dff38f31cc9c | b4a2115cd440a7b8818f8627f463923888d48882 | /AutoIrrigationEsp/AutoIrrigationEsp.ino | 612e5d2a683f8560dc60178159e5bfd84eed8563 | [] | no_license | nrajpoot1146/AutoIrrigationSystem | 71a0b0571281d23584af41a1fab9eb99d0d42938 | 34932820d153289a4930b20e4423746e4a506948 | refs/heads/master | 2022-07-31T14:32:35.351862 | 2022-07-10T04:11:38 | 2022-07-10T04:11:38 | 182,558,624 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,755 | ino | AutoIrrigationEsp.ino | /*
*
* Temperature V0
* Humidity V1
* Moisture sensor-1 V2
* Moisture sensor-2 V3
* Moisture sensor-3 V4
* Moisture sensor-4 V5
*
* Solenoid valve status pin
*
* valve-1 V6
* valve-2 V7
* valve-3 V8
* valve-4 V9
*/
#define BLYNK_PRINT Serial
#include "Arduino.h"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ArduinoJson.h>
#define thmois 30
const char ssid[] = "Guitarist";
const char pass[] = "AnuragPa";
const char auth[] = "4650dc3d6cc9482ebdca59950bf272ff";
//The setup function is called once at startup of the sketch
StaticJsonBuffer<300> jb;
WidgetLED led1(V6);
WidgetLED led2(V7);
WidgetLED led3(V8);
WidgetLED led4(V9);
WidgetLED led5(V10);
BLYNK_WRITE(V11){
String pv = param.asStr();
Serial.println("%l="+pv);
}
BLYNK_WRITE(V12){
String pv = param.asStr();
Serial.println("%mo="+pv);
}
BLYNK_WRITE(V13){
String pv = param.asStr();
Serial.println("%m1="+pv);
}
BLYNK_WRITE(V14){
String pv = param.asStr();
Serial.println("%m2="+pv);
}
BLYNK_WRITE(V15){
String pv = param.asStr();
Serial.println("%m3="+pv);
}
BLYNK_WRITE(V16){
String pv = param.asStr();
Serial.println("%m4="+pv);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth,ssid,pass);
}
// The loop function is called in an endless loop
void loop()
{
Blynk.run();
if(Serial.available()){
String str = Serial.readStringUntil('#');
Serial.println(str);
if(str.startsWith("{") && str.endsWith("}")){
Serial.println("send to Blynk app...");
jb.clear();
JsonObject& jo = jb.parse(str);
sendToBlynkapp(jo);
}
}
}
void sendToBlynkapp(JsonObject& jo){
if(jo.containsKey("t")){
int temp = jo.get<int>("t");
Blynk.virtualWrite(V0,temp);
}
if(jo.containsKey("hm")){
int hum = jo.get<int>("hm");
Blynk.virtualWrite(V1,hum);
}
if(jo.containsKey("m1")){
int mois = jo.get<int>("m1");
Blynk.virtualWrite(V2,mois);
if(mois>thmois){
Blynk.email("prateekbajpai393@gmail.com","less moisture ","Excess moisture. ");
Blynk.notify("Moisture over. sensor 1.");
}
}
if(jo.containsKey("m2")){
int mois = jo.get<int>("m2");
Blynk.virtualWrite(V3,mois);
if(mois>thmois){
Blynk.email("prateekbajpai393@gmail.com","less moisture ","Excess moisture. ");
Blynk.notify("Moisture over. sensor 2");
}
}
if(jo.containsKey("m3")){
int mois = jo.get<int>("m3");
Blynk.virtualWrite(V4,mois);
if(mois>thmois){
Blynk.email("prateekbajpai393@gmail.com","less moisture ","Excess moisture. ");
Blynk.notify("Moisture over. sensor 3");
}
}
if(jo.containsKey("m4")){
int mois = jo.get<int>("m4");
Blynk.virtualWrite(V5,mois);
if(mois>thmois){
Blynk.email("prateekbajpai393@gmail.com","less moisture ","Excess moisture. ");
Blynk.notify("Moisture over. sensor 4");
}
}
if(jo.containsKey("s1s")){
int status = jo.get<int>("s1s");
switch(status){
case 1:
led1.on();
break;
case 0:
led1.off();
break;
}
}
if(jo.containsKey("s2s")){
int status = jo.get<int>("s2s");
switch(status){
case 1:
led2.on();
break;
case 0:
led2.off();
break;
}
}
if(jo.containsKey("s3s")){
int status = jo.get<int>("s3s");
switch(status){
case 1:
led3.on();
break;
case 0:
led3.off();
break;
}
}
if(jo.containsKey("s4s")){
int status = jo.get<int>("s4s");
switch(status){
case 1:
led4.on();
break;
case 0:
led4.off();
break;
}
}
if(jo.containsKey("md")){
int mode = jo.get<int>("md");
switch(mode){
case 1:
led5.on();
break;
case 0:
led5.off();
break;
}
}
}
|
b4a8fafaa8e15186f7ad55e972dd0dd31c1bd963 | 61b42ad48560ee2eadf7ebd24528044f1acf22b4 | /SpecialEffects.cpp | f546838a32372cfd11e7ea772f386a61fdf04f21 | [] | no_license | ElonMaks/Trainer | 97508db4b2ae36757de25795a2ed7728c9f02f5c | a9fb9f1808ef3a2302a7340e9b995deb330e5c35 | refs/heads/master | 2020-03-23T15:26:30.479615 | 2018-08-06T08:53:07 | 2018-08-06T08:53:07 | 141,748,322 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,140 | cpp | SpecialEffects.cpp | #include "SpecialEffects.h"
SpecialEffects::SpecialEffects(sf::Vector2f size, bool startDarken) {
rect.setSize(size);
rect.setFillColor(sf::Color(0, 0, 0, 0));
effect = NONE;
if (startDarken)
alpha = 255;
else
alpha = 0;
}
void SpecialEffects::darken(int time) {
fullTime = time;
effect = DARKEN;
threshold = 255;
effectClk.restart();
}
void SpecialEffects::brighten(int time) {
fullTime = time;
effect = BRIGHTEN;
threshold = 0;
effectClk.restart();
}
void SpecialEffects::update() {
switch (effect) {
case DARKEN: {
alpha = effectClk.getElapsedTime().asMilliseconds()
/ static_cast<float>(fullTime) * 255;
if (alpha >= threshold) {
effect = NONE;
alpha = threshold;
}
}
break;
case BRIGHTEN: {
alpha = 255
- effectClk.getElapsedTime().asMilliseconds()
/ static_cast<float>(fullTime) * 255;
if (alpha <= threshold) {
effect = NONE;
alpha = threshold;
}
}
break;
}
rect.setFillColor(sf::Color(0, 0, 0, alpha));
}
void SpecialEffects::draw(sf::RenderTarget &target,
sf::RenderStates states) const {
target.draw(rect);
}
SpecialEffects::~SpecialEffects() {
}
|
5d4c15b896f8cec075b94057a7bd112242fa0dea | 39f11f3d1315f213d99dcc2f074b686037cb5815 | /archive/td/Bridges_2735.cpp | 6e349a855be8781c6cf539d63fb1333036dc9dbf | [] | no_license | jdumas/acm | 84985c127a4edb72c4315ab0ca95b95038024e06 | 127d5497cd07574a84c1b56ecbe064daed5da059 | refs/heads/master | 2020-05-30T04:14:28.645335 | 2011-06-09T17:15:03 | 2011-06-09T17:15:03 | 1,560,744 | 1 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 1,964 | cpp | Bridges_2735.cpp | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector<vector<pair<int, int> > > graph;
typedef pair<double, int> weight; // Couple (poids, numéro) correspondant à une arête
int n, k, sh, sc;
graph g;
vector<int> deg; // Degré d'un sommet au fur et à mesure qu'on effeuille
vector<int> nbdesc; // Nombre de noeud dans l'arbre constitué des fils effeuillés + le noeud courant
vector<double> len; // Longueur d'une arête
vector<int> occur; // Nombre de chemins passant par cette arête
vector<weight> ordered; // L'ensemble des arêtes triées en fonction de leur poids
bool compare(const weight & w1, const weight & w2) {
return (w1.first < w2.first);
}
void effeuille(void) {
int i0, i, j, m, e;
vector<pair<int, int> >::iterator it;
vector<bool> vu(n, false);
vector<int> stack;
for (i = 0; i < n; ++i) {
deg[i] = g[i].size();
if (deg[i] == 1) {
vu[i] = true;
stack.push_back(i);
}
}
for (i0 = 0; i0 < n; ++i0) {
i = stack[i0];
m = nbdesc[i];
for (it = g[i].begin(); it < g[i].end(); ++it) {
j = it->first;
e = it->second;
if (occur[e] == 0)
occur[e] = m * (n - m);
if (vu[j]) continue;
deg[j] -= 1;
nbdesc[j] += m;
if (deg[j] != 1) continue;
vu[j] = true;
stack.push_back(j);
}
}
return;
}
void compute(void) {
int i;
double cost;
for (i = 0; i < n - 1; ++i) {
cost = occur[i] * len[i] * (sh - sc);
ordered[i] = make_pair(cost, 1+i);
}
sort(ordered.begin(), ordered.end(), compare);
for (i = 0; i < k; ++i)
cout << ordered[i].second << " ";
cout << endl;
}
int main(void) {
int i, x, y, l;
cin >> n >> k >> sh >> sc;
g.resize(n);
deg.resize(n);
nbdesc.resize(n, 1);
len.resize(n - 1);
occur.resize(n - 1);
ordered.resize(n - 1);
for (i = 0; i < n - 1; ++i) {
cin >> x >> y >> l;
--x;
--y;
len[i] = l;
g[x].push_back(make_pair(y, i));
g[y].push_back(make_pair(x, i));
}
effeuille();
compute();
return 0;
}
|
87a8aca402978f5e8a0f5878060dc64bbe0998c2 | 476af59c3267d2c865fef50a84a256dcf6dbe191 | /C++/Solution474.cpp | ecba246ec43b74c742825fcb25711dc3d705236e | [] | no_license | yogurt-shadow/leetcode | fb3c2f47e77c3b40b06fa65cffe63095bd6542e7 | c824fa13237421afa69d05bb48026e7a2e407d02 | refs/heads/master | 2023-08-29T04:09:43.859492 | 2021-11-11T15:16:15 | 2021-11-11T15:16:15 | 325,449,621 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,277 | cpp | Solution474.cpp | #include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
class Solution474 {
public:
int findMaxForm(vector<string>& strs, int m, int n) {
int size = strs.size();
vector<pii> vec(size);
for(int i = 0; i < size; i++){
string cur = strs[i];
int x = 0, y = 0;
for(auto ele: cur){
if(ele == '0'){
x ++;
}
else{
y ++;
}
}
vec[i] = {x, y};
}
viii dp(size + 1, vii(m + 1, vi(n + 1)));
for(int i = 1; i <= size; i++){
int x = vec[i - 1].first, y = vec[i - 1].second;
for(int j = 0; j <= m; j++){
for(int k = 0; k <= n; k++){
dp[i][j][k] = dp[i - 1][j][k];
if(x <= j && y <= k){
dp[i][j][k] = max(1 + dp[i - 1][j - x][k - y], dp[i][j][k]);
}
}
}
}
return dp[size][m][n];
}
}; |
90a8f7bcf6ff4d5cf1a39e61f4559f96165ef210 | a7183d3adea2be3707abe23d7d0276405c1e064a | /src/modules/nmx/test/NMXInstrumentTest.cpp | 4bd3f78bf0e11edddb9447921f79e632cf537b86 | [
"BSD-2-Clause",
"BSD-3-Clause"
] | permissive | ess-dmsc/event-formation-unit | 672fe93e4b885777a7b77cceeee2e0ef4659adce | 7d2e94662bbece96ccb079511030f9a044fbbb5c | refs/heads/master | 2023-09-01T12:31:53.905678 | 2023-08-23T08:34:26 | 2023-08-23T08:34:26 | 80,731,668 | 9 | 9 | BSD-2-Clause | 2023-09-11T09:24:52 | 2017-02-02T14:17:01 | C++ | UTF-8 | C++ | false | false | 24,447 | cpp | NMXInstrumentTest.cpp | // Copyright (C) 2022 European Spallation Source, ERIC. See LICENSE file
//===----------------------------------------------------------------------===//
///
/// \file
//===----------------------------------------------------------------------===//
#include <common/kafka/EV44Serializer.h>
#include <common/readout/ess/Parser.h>
#include <common/testutils/SaveBuffer.h>
#include <common/testutils/TestBase.h>
#include <nmx/NMXInstrument.h>
#include <stdio.h>
#include <string.h>
using namespace Nmx;
// clang-format off
std::string BadConfigFile{"deleteme_nmx_instr_config_bad.json"};
std::string BadConfigStr = R"(
{
"NotARealDetector" : "NMX",
"InstrumentGeometry" : "NMX",
"MaxSpanX" : 3,
"MaxSpanY" : 3,
"MaxGapX" : 2,
"MaxGapY" : 2,
"DefaultMinADC":50,
"Config" : [
{
"Ring" : 0,
"FEN": 0,
"Hybrid" : 0,
"Plane" : 0,
"Offset" : 0,
"ReversedChannels" : false,
"Panel" : 0,
"HybridId" : "E5533333222222221111111100000000"
},
{
"Ring" : 0,
"FEN": 0,
"Hybrid" : 1,
"Plane" : 1,
"Offset" : 0,
"ReversedChannels" : false,
"Panel" : 0,
"HybridId" : "E5533333222222221111111100000001"
}
]
}
)";
std::string BadConfig2File{"deleteme_nmx_instr_config_bad2.json"};
std::string BadConfig2Str = R"(
{
"Detector" : "NMX",
"InstrumentGeometry" : "Invalid",
}
)";
std::string ConfigFile{"deleteme_nmx_instr_config.json"};
std::string ConfigStr = R"(
{
"Detector" : "NMX",
"InstrumentGeometry" : "NMX",
"MaxXSpan" : 3,
"MaxYSpan" : 3,
"MinXSpan" : 2,
"MaxXGap" : 2,
"MaxYGap" : 2,
"DefaultMinADC":50,
"Config" : [
{
"Ring" : 0,
"FEN": 0,
"Hybrid" : 0,
"Plane" : 0,
"Offset" : 0,
"ReversedChannels" : false,
"Panel" : 0,
"HybridId" : "E5533333222222221111111100000000"
},
{
"Ring" : 0,
"FEN": 0,
"Hybrid" : 1,
"Plane" : 1,
"Offset" : 0,
"ReversedChannels" : false,
"Panel" : 0,
"HybridId" : "E5533333222222221111111100000001"
}
]
}
)";
//
std::vector<uint8_t> BadRingAndFENError {
// First readout
0x18, 0x01, 0x14, 0x00, // Data Header - Ring 23!
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x10, // GEO 0, TDC 0, VMM 0, CH 16
// Second readout
0x02, 0x18, 0x14, 0x00, // Data Header - Ring 2, FEN 3
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x11, 0x00, 0x00, 0x00, // Time LO 17 ticka
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x01, 0x10, // GEO 0, TDC 0, VMM 1, CH 16
};
std::vector<uint8_t> GoodEvent {
// First readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
// Second readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3D, // GEO 0, TDC 0, VMM 0, CH 61
// Third readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3C, // GEO 0, TDC 0, VMM 1, CH 60
};
std::vector<uint8_t> BadEventSmallXSpan {
// First readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
// Second readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3D, // GEO 0, TDC 0, VMM 1, CH 61
// Third readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3C, // GEO 0, TDC 0, VMM 1, CH 60
};
std::vector<uint8_t> SplitEventA {
// First readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3C, // GEO 0, TDC 0, VMM 1, CH 60
};
std::vector<uint8_t> SplitEventB {
// Second readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3D, // GEO 0, TDC 0, VMM 1, CH 61
// Third readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
// Fourth readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3D, // GEO 0, TDC 0, VMM 0, CH 61
};
std::vector<uint8_t> HighTOFError {
// First readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x01, 0x00, 0x00, 0x00, // Time HI 1 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3C, // GEO 0, TDC 0, VMM 1, CH 60
// Second readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x01, 0x00, 0x00, 0x00, // Time HI 1 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3D, // GEO 0, TDC 0, VMM 0, CH 61
// Third readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x01, 0x00, 0x00, 0x00, // Time HI 1 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
};
std::vector<uint8_t> BadEventLargeXSpan {
// First readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3C, // GEO 0, TDC 0, VMM 1, CH 60
// Second readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3D, // GEO 0, TDC 0, VMM 1, CH 61
// Second readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x0F, // GEO 0, TDC 0, VMM 1, CH 15
// Second readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3F, // GEO 0, TDC 0, VMM 1, CH 63
// Third readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
};
std::vector<uint8_t> BadEventLargeYSpan {
// First readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x1E, // GEO 0, TDC 0, VMM 1, CH 30
// Second readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3D, // GEO 0, TDC 0, VMM 1, CH 61
// Second readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3E, // GEO 0, TDC 0, VMM 1, CH 62
// Second readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3D, // GEO 0, TDC 0, VMM 0, CH 61
// Third readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
};
std::vector<uint8_t> BadEventLargeTimeSpan {
// First readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3C, // GEO 0, TDC 0, VMM 1, CH 60
// Second readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0xFF, 0x04, 0x00, 0x00, // Time LO 500 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3D, // GEO 0, TDC 0, VMM 1, CH 61
// Third readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x14, 0x00, 0x00, 0x00, // Time LO 20 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3E, // GEO 0, TDC 0, VMM 0, CH 62
// Fourth readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
};
std::vector<uint8_t> MaxADC {
// First readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 256
0x00, 0x00, 0x02, 0x3C, // GEO 0, TDC 0, VMM 1, CH 60
// Second readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0xD0, 0x07, // ADC = 2000, above threshold
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
};
std::vector<uint8_t> MinADC {
// First readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x28, 0x00, // ADC = 40, under default threshold required
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
// Second readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x4B, 0x00, // ADC = 75, over threshold required
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
// Third readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header, Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x28, 0x00, // ADC = 40, under default threshold required
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
};
std::vector<uint8_t> NoEventYOnly {
// First readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3C, // GEO 0, TDC 0, VMM 1, CH 60
// Second readout - plane Y
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3D, // GEO 0, TDC 0, VMM 1, CH 61
};
std::vector<uint8_t> NoEventXOnly {
// First readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60
// Second readout - plane X
0x00, 0x00, 0x14, 0x00, // Data Header - Ring 0, FEN 0
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3D, // GEO 0, TDC 0, VMM 0, CH 61
};
// clang-format on
class NMXInstrumentTest : public TestBase {
public:
protected:
struct Counters counters;
BaseSettings Settings;
EV44Serializer *serializer;
NMXInstrument *nmx;
ESSReadout::Parser::PacketHeaderV0 PacketHeader;
Event TestEvent; // used for testing generateEvents()
std::vector<Event> Events; // used for testing generateEvents()
void SetUp() override {
Settings.ConfigFile = ConfigFile;
serializer = new EV44Serializer(115000, "nmx");
counters = {};
memset(&PacketHeader, 0, sizeof(PacketHeader));
nmx = new NMXInstrument(counters, Settings, serializer);
nmx->setSerializer(serializer);
nmx->ESSReadoutParser.Packet.HeaderPtr = &PacketHeader;
}
void TearDown() override {}
void makeHeader(ESSReadout::Parser::PacketDataV0 &Packet,
std::vector<uint8_t> &testdata) {
Packet.HeaderPtr = &PacketHeader;
Packet.DataPtr = (char *)&testdata[0];
Packet.DataLength = testdata.size();
Packet.Time.setReference(0, 0);
Packet.Time.setPrevReference(0, 0);
}
};
/// THIS IS NOT A TEST, just ensure we also try dumping to hdf5
TEST_F(NMXInstrumentTest, DumpTofile) {
Settings.DumpFilePrefix = "deleteme_";
NMXInstrument NMXDump(counters, Settings, serializer);
NMXDump.setSerializer(serializer);
makeHeader(NMXDump.ESSReadoutParser.Packet, GoodEvent);
auto Res = NMXDump.VMMParser.parse(NMXDump.ESSReadoutParser.Packet);
NMXDump.processReadouts();
counters.VMMStats = NMXDump.VMMParser.Stats;
ASSERT_EQ(Res, 3);
ASSERT_EQ(counters.VMMStats.Readouts, 3);
}
// Test cases below
TEST_F(NMXInstrumentTest, BadConfig) {
Settings.ConfigFile = BadConfigFile;
EXPECT_THROW(NMXInstrument(counters, Settings, serializer),
std::runtime_error);
}
TEST_F(NMXInstrumentTest, BadConfig2) {
Settings.ConfigFile = BadConfig2File;
EXPECT_THROW(NMXInstrument(counters, Settings, serializer),
nlohmann::detail::parse_error);
}
TEST_F(NMXInstrumentTest, Constructor) {
ASSERT_EQ(counters.HybridMappingErrors, 0);
}
TEST_F(NMXInstrumentTest, BadRingAndFENError) {
makeHeader(nmx->ESSReadoutParser.Packet, BadRingAndFENError);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
ASSERT_EQ(Res, 0);
counters.VMMStats = nmx->VMMParser.Stats;
ASSERT_EQ(counters.VMMStats.ErrorFiber, 1);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 1);
}
TEST_F(NMXInstrumentTest, GoodEvent) {
makeHeader(nmx->ESSReadoutParser.Packet, GoodEvent);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
ASSERT_EQ(Res, 3);
counters.VMMStats = nmx->VMMParser.Stats;
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
// Ring and FEN IDs are within bounds, but Hybrid is not defined in config
nmx->processReadouts();
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
ASSERT_EQ(counters.VMMStats.Readouts, 3);
for (auto &builder : nmx->builders) {
builder.flush(true);
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 1);
}
TEST_F(NMXInstrumentTest, MaxADC) {
makeHeader(nmx->ESSReadoutParser.Packet, MaxADC);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
counters.VMMStats = nmx->VMMParser.Stats;
// ADC was above VMM threshold of 1023 once
ASSERT_EQ(counters.VMMStats.ErrorADC, 1);
ASSERT_EQ(Res, 1);
}
TEST_F(NMXInstrumentTest, MinADC) {
makeHeader(nmx->ESSReadoutParser.Packet, MinADC);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
counters.VMMStats = nmx->VMMParser.Stats;
ASSERT_EQ(Res, 3);
ASSERT_EQ(counters.VMMStats.ErrorADC, 0);
nmx->processReadouts();
ASSERT_EQ(counters.MinADC, 2); // ADC was under vessel specific threshold
// once, under general default once
}
TEST_F(NMXInstrumentTest, NoEventYOnly) {
makeHeader(nmx->ESSReadoutParser.Packet, NoEventYOnly);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
ASSERT_EQ(Res, 2);
counters.VMMStats = nmx->VMMParser.Stats;
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
nmx->processReadouts();
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
counters.VMMStats = nmx->VMMParser.Stats;
ASSERT_EQ(counters.VMMStats.Readouts, 2);
for (auto &builder : nmx->builders) {
builder.flush(true);
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 0);
ASSERT_EQ(counters.ClustersNoCoincidence, 1);
ASSERT_EQ(counters.ClustersMatchedYOnly, 1);
}
TEST_F(NMXInstrumentTest, NoEventXOnly) {
makeHeader(nmx->ESSReadoutParser.Packet, NoEventXOnly);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
ASSERT_EQ(Res, 2);
counters.VMMStats = nmx->VMMParser.Stats;
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
nmx->processReadouts();
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
ASSERT_EQ(counters.VMMStats.Readouts, 2);
for (auto &builder : nmx->builders) {
builder.flush(true);
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 0);
ASSERT_EQ(counters.ClustersNoCoincidence, 1);
ASSERT_EQ(counters.ClustersMatchedXOnly, 1);
}
TEST_F(NMXInstrumentTest, NoEvents) {
Events.push_back(TestEvent);
nmx->generateEvents(Events);
ASSERT_EQ(counters.Events, 0);
}
TEST_F(NMXInstrumentTest, PixelError) {
TestEvent.ClusterA.insert({0, 1, 100, 0});
TestEvent.ClusterA.insert({0, 2, 100, 0});
TestEvent.ClusterB.insert({0, 60000, 100, 1});
Events.push_back(TestEvent);
nmx->generateEvents(Events);
ASSERT_EQ(counters.Events, 0);
ASSERT_EQ(counters.PixelErrors, 1);
}
TEST_F(NMXInstrumentTest, BadEventLargeYSpan) {
makeHeader(nmx->ESSReadoutParser.Packet, BadEventLargeYSpan);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
ASSERT_EQ(Res, 5);
counters.VMMStats = nmx->VMMParser.Stats;
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
nmx->processReadouts();
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
ASSERT_EQ(counters.VMMStats.Readouts, 5);
for (auto &builder : nmx->builders) {
builder.flush(true);
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 0);
ASSERT_EQ(counters.ClustersTooLargeYSpan, 1);
}
TEST_F(NMXInstrumentTest, BadEventSmallXSpan) {
makeHeader(nmx->ESSReadoutParser.Packet, BadEventSmallXSpan);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
ASSERT_EQ(Res, 3);
counters.VMMStats = nmx->VMMParser.Stats;
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
nmx->processReadouts();
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
ASSERT_EQ(counters.VMMStats.Readouts, 3);
for (auto &builder : nmx->builders) {
builder.flush(true);
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 0);
ASSERT_EQ(counters.ClustersTooSmallXSpan, 1);
}
TEST_F(NMXInstrumentTest, BadEventLargeXSpan) {
makeHeader(nmx->ESSReadoutParser.Packet, BadEventLargeXSpan);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
ASSERT_EQ(Res, 5);
counters.VMMStats = nmx->VMMParser.Stats;
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
nmx->processReadouts();
ASSERT_EQ(counters.VMMStats.ErrorFiber, 0);
ASSERT_EQ(counters.VMMStats.ErrorFEN, 0);
ASSERT_EQ(counters.HybridMappingErrors, 0);
ASSERT_EQ(counters.VMMStats.Readouts, 5);
for (auto &builder : nmx->builders) {
builder.flush(true);
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 0);
ASSERT_EQ(counters.ClustersTooLargeXSpan, 1);
}
TEST_F(NMXInstrumentTest, NegativeTOF) {
auto &Packet = nmx->ESSReadoutParser.Packet;
makeHeader(nmx->ESSReadoutParser.Packet, GoodEvent);
Packet.Time.setReference(200, 0);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
counters.VMMStats = nmx->VMMParser.Stats;
nmx->processReadouts();
for (auto &builder : nmx->builders) {
builder.flush(true);
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(Res, 3);
ASSERT_EQ(counters.VMMStats.Readouts, 3);
ASSERT_EQ(counters.Events, 0);
ASSERT_EQ(counters.TimeErrors, 1);
}
TEST_F(NMXInstrumentTest, HighTOFError) {
makeHeader(nmx->ESSReadoutParser.Packet, HighTOFError);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
counters.VMMStats = nmx->VMMParser.Stats;
nmx->processReadouts();
for (auto &builder : nmx->builders) {
builder.flush(true);
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(Res, 3);
ASSERT_EQ(counters.VMMStats.Readouts, 3);
ASSERT_EQ(counters.Events, 0);
ASSERT_EQ(counters.TOFErrors, 1);
}
TEST_F(NMXInstrumentTest, BadEventLargeTimeSpan) {
makeHeader(nmx->ESSReadoutParser.Packet, BadEventLargeTimeSpan);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
counters.VMMStats = nmx->VMMParser.Stats;
nmx->processReadouts();
for (auto &builder : nmx->builders) {
builder.flush(true);
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(Res, 4);
ASSERT_EQ(counters.VMMStats.Readouts, 4);
ASSERT_EQ(counters.Events, 1);
ASSERT_EQ(counters.ClustersNoCoincidence, 1);
}
TEST_F(NMXInstrumentTest, EventCrossPackets) {
makeHeader(nmx->ESSReadoutParser.Packet, SplitEventA);
auto Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
counters.VMMStats = nmx->VMMParser.Stats;
nmx->processReadouts();
for (auto &builder : nmx->builders) {
builder.flush();
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(Res, 1);
makeHeader(nmx->ESSReadoutParser.Packet, SplitEventB);
Res = nmx->VMMParser.parse(nmx->ESSReadoutParser.Packet);
counters.VMMStats = nmx->VMMParser.Stats;
nmx->processReadouts();
for (auto &builder : nmx->builders) {
builder.flush(true);
nmx->generateEvents(builder.Events);
}
ASSERT_EQ(Res, 3);
ASSERT_EQ(counters.VMMStats.Readouts, 4);
ASSERT_EQ(counters.Events, 1);
}
int main(int argc, char **argv) {
saveBuffer(ConfigFile, (void *)ConfigStr.c_str(), ConfigStr.size());
saveBuffer(BadConfigFile, (void *)BadConfigStr.c_str(), BadConfigStr.size());
saveBuffer(BadConfig2File, (void *)BadConfig2Str.c_str(),
BadConfig2Str.size());
testing::InitGoogleTest(&argc, argv);
auto RetVal = RUN_ALL_TESTS();
deleteFile(ConfigFile);
deleteFile(BadConfigFile);
deleteFile(BadConfig2File);
return RetVal;
}
|
1466f597f3e19055a5b80887f5670fd23136a46c | 5b1e3895f6994b488cd73aa8d889429a64df8027 | /15520755.oop.lab1.1/PhanSo.cpp | 73fad2869d9b03b2523b3ee6f92e166a42643021 | [] | no_license | DucTamDinhUIT/OOP | 803c476eae7a8a58ad158d141b05fa0d5bd3d659 | 076f17270a0fef0ca4f741b9ea3326adb187f85b | refs/heads/master | 2021-05-17T01:10:33.135115 | 2020-03-28T19:31:28 | 2020-03-28T19:31:28 | 250,550,564 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 519 | cpp | PhanSo.cpp | #include "PhanSo.h"
int PhanSo::nhapPs()
{
cout << "Nhap tu&mau cua phan so: " << endl;
cin>>this->tu;
cin>>this->mau;
return 0;
}
int PhanSo::xuatPs()
{
cout << tu << '/' << mau << endl;
return 0;
}
int PhanSo::rutGon()
{
int a = abs(tu); //lay abc cua tu so
int b = abs(mau); //abs mau so
while (a*b != 0) //khac 0 & hop le
{
if (a > b) //tim hieu cua tu&mau
a = a - b;
else
b = b - a;
}
tu = tu / (a + b); //khong hieu gi luon
mau = mau / (a + b); //thuat toan Euclid
return tu, mau;
}
|
bcdb605ff2e43448e59ce7f7a636ac43744e5635 | a560fe54820abc3c010853f3fcb1137fab6cb546 | /1119.cpp | 427ea3fcf4401495163311a0a65240a214943191 | [] | no_license | kongzz311/Pat-Advansed | 09b5ae3df8297fe07c4c138e727cd271ad9b2301 | e15f508e64293f4df60f637ae9ddc337efd8bf36 | refs/heads/master | 2020-04-11T15:04:53.161849 | 2018-12-19T08:51:18 | 2018-12-19T08:51:18 | 161,878,905 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 296 | cpp | 1119.cpp | #include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> pre, post, in;
int main()
{
cin >> n;
for(int i = 0; i < n; i++){
int temp;
cin >> temp;
pre.push_back(temp);
}
for(int i = 0; i < n; i++){
int temp;
cin >> temp;
post.push_back(temp);
}
return 0;
} |
c696cf5ba51a4ff1105ab933e8f002ff50f37961 | e099fa182407f139a74e305a9a3b461ead42b4ae | /src/LangJava.cpp | d1c104acc7293595aa17214f526b2a36ad38f432 | [] | no_license | rajatmelavr/IDESelection | 83b0cc2701eccb2ce1525b4125028a9ed673956c | 7064b7a7963fb49a423e862070b61286d0d07bde | refs/heads/master | 2020-06-01T19:29:35.045352 | 2019-06-09T05:37:45 | 2019-06-09T05:37:45 | 190,900,768 | 0 | 0 | null | 2019-06-08T15:25:26 | 2019-06-08T14:59:38 | null | UTF-8 | C++ | false | false | 309 | cpp | LangJava.cpp | /*
* LangJava.cpp
* Description : Normal Class | Non Abstract
* Author : Raj Prajapati
* Date : 09-Jun-2019
*/
#include "LangJava.hpp"
namespace LangJava {
LangJava::LangJava() {
}
LangJava::~LangJava() {
}
std::string LangJava::getName(void) {
return "Java";
}
} /* namespace LangJava */
|
ab7ee55b3749c33ccc20c12f556755c6a339f62a | afa7843f90746fac7166913f89123b71061511a1 | /includes/Monome.hpp | 77fb2826993e3d1059234ead4d8e8b386b08a67f | [] | no_license | abassibe/ComputorV1 | 1916033b1172e6df637f1d16ce112f8c75113432 | 28c4e44a2cf834af199290556d510b5f8c31c98d | refs/heads/master | 2021-07-04T22:03:50.572055 | 2020-09-07T09:33:50 | 2020-09-07T09:33:50 | 174,195,568 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,204 | hpp | Monome.hpp | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Monome.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abassibe <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/28 15:57:38 by abassibe #+# #+# */
/* Updated: 2019/03/04 15:28:11 by abassibe ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MONOME_HPP
# define MONOME_HPP
# include <string>
class Monome
{
public:
~Monome();
Monome(std::string monome);
Monome(Monome const& copy);
Monome &operator=(Monome const& copy);
bool operator==(Monome const& copy);
float coef;
int exp;
char letter;
private:
Monome();
};
#endif
|
a4b86b342ce0c0846f1cd734349f58bebff88a1f | 8c93bd7aef951447f864e8b8a409f65ff9bc103a | /cpp/easy287.cpp | 2ea47fb1b22defc17ebd9f4293b98eb7259e5a33 | [] | no_license | redrails/DailyProgrammer | 34e6babb87048f74eda86c248d511a0e7fad87a8 | 0f57b96720db22400a5528c571e7275a3da13783 | refs/heads/master | 2021-01-18T22:12:47.675739 | 2016-10-19T14:39:04 | 2016-10-19T14:39:04 | 69,547,427 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,331 | cpp | easy287.cpp | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
/*
Main Problem
*/
int largest_digit(int last, int n){
if(n < 10){
if(n > last){
return n;
} else {
return last;
}
} else {
if(last > n%10){
return largest_digit(last, n/10);
} else {
return largest_digit(n%10, n/10);
}
}
}
/*
Bonus 1
*/
int backToInt(const vector<int>& numbers){
int c = 1;
int result = 0;
for(int i=0; i<numbers.size(); i++){
result += numbers.at(i)*c;
c*=10;
}
return result;
}
vector<int> getNumberAsVector(int n){
vector<int> numbers{};
for(int i=0; i<4; i++){
numbers.push_back(n%10);
n /= 10;
}
if(numbers.size() < 4){
int toPush = 4-numbers.size();
for(int i=0; i<toPush; i++){
numbers.insert(numbers.begin(), 0);
}
}
return numbers;
}
int desc_digits(int n){
vector<int> nums = getNumberAsVector(n);
sort(nums.begin(),nums.end());
return backToInt(nums);
}
int asc_digits(int n){
vector<int> nums = getNumberAsVector(n);
sort(nums.begin(),nums.end(), greater<int>());
return backToInt(nums);
}
bool twoUnique(int n){
vector<int> numbers = getNumberAsVector(n);
for(int i=1; i<4; i++){
if(numbers[i] != numbers[0]){
return true;
}
}
return false;
}
int kaprekar(int iter, int number){
if(!twoUnique(number)){
return 0;
}
if(number == 6174){
return iter;
} else {
return kaprekar(++iter, desc_digits(number) - asc_digits(number));
}
}
int main(){
cout << largest_digit(0, 1234) << "\n";
cout << largest_digit(0, 3253) << "\n";
cout << largest_digit(0, 9800) << "\n";
cout << largest_digit(0, 3333) << "\n";
cout << largest_digit(0, 120) << "\n";
cout << "======================\n";
cout << desc_digits(1234) << "\n";
cout << desc_digits(3253) << "\n";
cout << desc_digits(9800) << "\n";
cout << desc_digits(3333) << "\n";
cout << desc_digits(120) << "\n";
cout << "======================\n";
cout << kaprekar(0, 6589) << "\n";
cout << kaprekar(0, 5455) << "\n";
cout << kaprekar(0, 6174) << "\n";
}
|
9d3197bc8c4cbf8047e70b240028dc297dd316d2 | 01d5cff1d93772a6bb2101f0100e030154a0cc07 | /src/neo/http/parse/common.hpp | 73436a4f3ced22dc1ffb03ea1d0381b7188a12e8 | [] | no_license | baajarmeh/neo-http | c68a059e35974397ba871289d14435dcc643f824 | acd39d0671b6c2f4b4677071052dc0676c0c449a | refs/heads/master | 2023-03-19T05:30:20.710381 | 2021-01-31T04:07:02 | 2021-01-31T04:07:02 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 548 | hpp | common.hpp | #pragma once
#include <neo/const_buffer.hpp>
namespace neo::http {
constexpr bool is_crlf(const_buffer buf) {
return buf.size() == 2 && buf[0] == std::byte{'\r'} && buf[1] == std::byte{'\n'};
}
constexpr bool begins_with_crlf(const_buffer buf) {
return buf.size() >= 2 && is_crlf(buf.first(2));
}
constexpr std::ptrdiff_t find_crlf(const const_buffer buf) {
for (auto b2 = buf; b2; b2 += 1) {
if (begins_with_crlf(b2)) {
return b2.data() - buf.data();
}
}
return -1;
}
} // namespace neo::http |
051ba788c8fd912de360882bc7da7a0dbbd76a3b | 7ee7445bd2cea7fce4c0cf027d0d1566f35be217 | /src/ACEtk/details/verify/IsStrictlyPositive.hpp | 9dc61df757e482c7c56532e0818eccf5abc460f3 | [
"BSD-2-Clause"
] | permissive | njoy/ACEtk | dad21dd5e8bb5ad4c0928de0b7d6fe7493e35a49 | 172d37583851dc531a31f1a8b140f3d2b9922ee7 | refs/heads/develop | 2023-09-01T00:17:04.898576 | 2023-06-26T22:00:41 | 2023-06-26T22:00:41 | 95,158,830 | 16 | 7 | NOASSERTION | 2023-09-11T19:13:15 | 2017-06-22T21:41:07 | C++ | UTF-8 | C++ | false | false | 299 | hpp | IsStrictlyPositive.hpp | template< typename T, typename = void >
struct IsStrictlyPositive : std::false_type {};
template< typename T >
struct IsStrictlyPositive< T,
std::enable_if_t< utility::is_range< T >::value and
std::decay_t< T >::isStrictlyPositive >
> : std::true_type
{};
|
1be0632a1061a1591eea4d28ac079e997ad8663e | f9a71846508f94eb2af3510edbace5cfe5d2e512 | /SoulStones.cc | 52b0d026c1b5fc94348db57808fc7dfa70b53778 | [] | no_license | dillonmayhew/proj2720 | 287904e585833d8a7cba26477fd058ea772dec4c | 774ea7da684f9066354f60c407a09d71223fa824 | refs/heads/master | 2021-01-01T05:42:35.692811 | 2016-04-23T02:29:34 | 2016-04-23T02:29:34 | 56,284,234 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,385 | cc | SoulStones.cc | #include "SoulStones.h"
SoulStones::SoulStones()
{
image = NULL;
}
SoulStones::SoulStones(ALLEGRO_BITMAP *soulimage)
{
maxFrame = 49;
frameCount = 0;
frameDelay = 2;
frameWidth = 64;
frameHeight = 64;
setCurRow(rand()%19);
setCurColumn(0);
boundx = 15;
boundy = 15;
hit = false;
live = true;
x = rand()%gameWidth - frameWidth;
y = rand()%gameHeight - frameHeight;
image = soulimage;
}
void SoulStones::updateObj()
{
if(live)
{
if(++frameCount >= frameDelay)
{
if((getCurColumn() + 1) >= 32)
{
setCurColumn(0);
}
setCurColumn(getCurColumn() + 1);
frameCount = 0;
}
}
else
{
dissapear();
}
}
void SoulStones::dissapear()
{
if(getCurColumn() < 33){
hit = true;
setCurColumn(33);
}
if(++frameCount >= frameDelay)
{
if((getCurColumn() + 1) >= maxFrame)
{
hit = false;
setCurColumn(maxFrame);
}
setCurColumn(getCurColumn() + 1);
frameCount = 0;
}
}
void SoulStones::collidePlayer(Player *plyr)
{
if(live)
{
if(plyr->live)
{
if(x+boundx > (plyr->x - plyr->boundx) &&
x-boundx < (plyr->x + plyr->boundx) &&
y+boundy > (plyr->y - plyr->boundy) &&
y-boundy < (plyr->y + plyr->boundy))
{
plyr->soulCount += 1;
live = false;
}
}
}
}
void SoulStones::reset()
{
setCurColumn(0);
frameDelay = 2;
} |
7c9ad4074bd6fc776b997d6b6b997c19b8b8a004 | 5a1c6608e13a4df5c28007be8a21f4de48f42b92 | /Engine/Code/Engine/Math/PhysicsUtil.cpp | b4749fa61214faf8989c55188f6bea6f6dadc450 | [] | no_license | RollerSimmer/Guildhall-Projects | 8bcf52ceb23a0a7f05b06f0613201dcb89c80708 | 79f59a4d16726cf415eac214d3b4ff280facba08 | refs/heads/master | 2021-01-19T12:35:03.010982 | 2017-02-17T23:34:22 | 2017-02-17T23:34:22 | 82,342,157 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,076 | cpp | PhysicsUtil.cpp | #include "Engine/Math/PhysicsUtil.hpp"
#include "Engine/Math/MathUtil.hpp"
// code written by John Anderson
void transferMomentumGeneric(float massA, Vector2& velA, const Vector2& posA, float elasticityA, float massB, Vector2& velB, const Vector2& posB, float elasticityB)
{
//TODO: fix "sticking" issues when balls cling instead of rolling off smoothly.
Vector2 oldAmo = massA*velA;
Vector2 oldBmo = massB*velB;
Vector2 totalMo=oldAmo+oldBmo;
Vector2 L=posB-posA;
L.Normalize();
Vector2 oldAmoAlongL = L*dotProduct(oldAmo, L);
Vector2 oldBmoAlongL = L*dotProduct(oldBmo, L);
Vector2 oldTotalMoAlongL=oldAmoAlongL+oldBmoAlongL;
//float oldTotalMagAlongL=oldTotalMoAlongL.CalcLength();
// filter out very slow speeds
{
static float velsum=0;
static int counter=0;
float totalVel = velA.calcLength() + velB.calcLength();
velsum+=totalVel;
counter++;
if (counter >= 10000)
{
//float avgvel=velsum/counter;
counter=0;
}
const float VELOCITY_THRESHOLD = 1000.f;
if (totalVel < VELOCITY_THRESHOLD)
return;
}
Vector2 AmoAlongN = oldAmo-oldAmoAlongL;
Vector2 BmoAlongN = oldBmo-oldBmoAlongL;
Vector2 newAmoAlongL = oldBmoAlongL;
Vector2 newBmoAlongL = oldAmoAlongL;
Vector2 newAmo;
Vector2 newBmo;
float newAvelScale;
float newBvelScale;
if (massA == INFINITE_MASS && massB == INFINITE_MASS)
{
// set both momentums to zero
newAmo = newBmo = Vector2::ZERO;
newAvelScale = newBvelScale = 0.f;
}
else if (massA == INFINITE_MASS)
{
newAmo = Vector2::ZERO;
newBmo = -oldBmoAlongL+BmoAlongN;
newAvelScale = 0.f;
newBvelScale = 1.f / massB;
}
else if (massB == INFINITE_MASS)
{
newBmo = Vector2::ZERO;
newAmo = -oldAmoAlongL+AmoAlongN;
newBvelScale = 0.f;
newAvelScale = 1.f / massA;
}
else
{
newAmo = AmoAlongN + newAmoAlongL;
newBmo = BmoAlongN + newBmoAlongL;
newAvelScale = 1.f / massA;
newBvelScale = 1.f / massB;
}
velA = newAmo*newAvelScale*elasticityA;
velB = newBmo*newBvelScale*elasticityB;
} |
a039abca929ef6bff4e4394710b865414bb4c7f2 | 5d72062d0d014e075afbcdac5de7589433689013 | /Screening-Assignment/typing_speed_hatimkhambati26.cpp | c76662fa30439b23c0eec419400bf543f50adb5b | [] | no_license | HatimKhambati26/coding-batch-2020 | a34b10dbf2466a36a48ac6b1aaecc7e48a0a2a28 | 557c2517dc8e00665e076d6207d0259b40be5edc | refs/heads/master | 2022-12-09T16:16:43.260034 | 2020-09-01T23:03:05 | 2020-09-01T23:03:05 | 292,122,060 | 0 | 0 | null | 2020-09-01T22:35:52 | 2020-09-01T22:35:51 | null | UTF-8 | C++ | false | false | 3,540 | cpp | typing_speed_hatimkhambati26.cpp | // hatim.khambati26@gmail.com
// Assignment-I : Typing Speed Calculator
// Assumptions
// 1) User will enter one word at a time.
// 2) User has to press Enter key to submit the word.
// (Regardless of User enters whitespace after the word or not).
// 3) User cannot proceed to the next word,
// unless he/she types the current word correctly.
// 4) Whitespaces are not considered in calculation.
// Results
// 1) Characters Typed
// 2) Time Taken (in seconds)
// 3) Speed - Characters per Minute (cpm) [Whitespace excluded]
// 4) Accuracy (in pecentage) [Extra]
#include <bits/stdc++.h>
using namespace std;
vector<string> stok;
string test5[5];
int main()
{
// Storing each line of the file
ifstream file("shakespeare.txt");
int i = 0;
string inpline[1396], s;
if (file.is_open())
{
while (getline(file, s))
{
inpline[i] = s;
i++;
}
file.close();
}
// Take Random 5 Lines from the Input file for the Typing Speed Test
int cc = 0;
srand(time(0));
for (int i = 0; i < 5; ++i)
{
test5[i] = (inpline[rand() % 1396]);
cc += test5[i].size();
}
// Instruction Screen
system("clear");
cout << string(16, '*') << " Typing Speed Calculator " << string(16, '*') << "\n\n";
cout << string(20, ' ') << " Instructions!\n\n";
cout << "1) You will have enter one word at a time.\n\n";
cout << "2) You have to press Enter key to submit the word.\n (Regardless of you enter whitespace after the word or not).\n\n";
cout << "3) You cannot proceed to the next word,\n unless you type the current word correctly.\n\n";
cout << string(16, '*') << " Press Enter to Begin!! " << string(16, '*') << endl;
cin.ignore();
// Logic for Test begins here!!
int wc = 0, typedwords = 0;
// Initializing the Start time of the test
auto start = chrono::steady_clock::now();
for (int i = 0; i < 5; ++i)
{
// Tokenizing the Sentence
stringstream ss(test5[i]);
string token;
while (getline(ss, token, ' '))
stok.push_back(token);
// Looping through all tokens
for (auto w : stok)
{
string inp = "";
wc++;
// Taking input until the current word is correctly typed
while (inp != w)
{
system("clear");
cout << "(" << i + 1 << " of 5) " << test5[i] << "\n\n";
cout << " Current word" << endl;
cout << string(16, '*') << endl;
cout << w << endl;
cout << "->";
cin >> inp;
++typedwords;
}
}
stok.clear();
}
// Initializing the End time of the test
auto stop = chrono::steady_clock::now();
// Calculating the duration of test in and seconds
auto d_s = chrono::duration_cast<chrono::seconds>(stop - start).count();
// Calculating Characters per Minute
int cpm = (cc - wc + 1) * 60 / d_s;
// Calculating Accuracy
int acc = (wc * 100) / typedwords;
// Displaying Results
system("clear");
cout << string(16, '*') << " Typing Speed Calculator " << string(16, '*') << "\n\n";
cout << string(23, ' ') << " Results!\n\n";
cout << "Characters Typed: " << cc << "\n\n";
cout << "Time Taken: " << d_s << " sec\n\n";
cout << "Speed - Characters per Minute: " << cpm << " cpm\n\n";
cout << "Accuracy: " << acc << "%\n";
return 0;
} |
3595c347f384a6447f6d79a78ba63c44457697c7 | 34e17284d0e37aa8a28864c14782c7e8f4032a3c | /Combinatorics/Combinatorics - Template/src/Combinatorics.cpp | 3d7c2b016ba72d0b94bba635d29cc609e187ff33 | [] | no_license | InfiniteLoopify/data-structures | ab57b92f7391ed74bcf53a8b90d79bef6a9b72d3 | 8513fda112873c5043d4828f88553cc7ef7774f5 | refs/heads/master | 2022-08-27T02:40:00.978538 | 2020-05-24T20:52:12 | 2020-05-24T20:52:12 | 266,052,544 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,660 | cpp | Combinatorics.cpp | #include <iostream>
#include <vector>
#include <algorithm>
#include "Combinatorics.h"
#ifndef COMBINATORICS_IMP
#define COMBINATORICS_IMP
template <class T> Combinatorics<T>::Combinatorics(const std::vector<T> &tempList)
: m_repeat(true), m_count(0), m_objectList(tempList) {}
template <class T> Combinatorics<T>::~Combinatorics(){}
template <class T> void Combinatorics<T>::set_objectList(const std::vector<T> &tempList){m_objectList = tempList;}
template <class T> void Combinatorics<T>::set_repeat(bool doRepeat){m_repeat = doRepeat;}
template <class T> void Combinatorics<T>::reset_count(){m_count = 0;}
template <class T> int Combinatorics<T>::get_count(){return m_count;}
template <class T> int Combinatorics<T>::get_repeat(){return m_repeat;}
template <class T> void Combinatorics<T>::display_objectList()
{
for(int i = 0; i < m_objectList.size(); ++i)
std::cout << m_objectList[i];
std::cout << "\n";
}
template <class T> void Combinatorics<T>::display_combination()
{
for(int i = 0; i < m_combination.size(); ++i)
std::cout << m_combination[i];
std::cout << " ";
}
template <class T> void Combinatorics<T>::permutation(int length, int index)
{
if(length < 0 || (length > m_objectList.size() && m_repeat == false))
{
std::cout << "Invalid: \n(r > n) || (r < 0)\n";
return;
}
if(m_combination.size() >= length)
{
display_combination();
++m_count;
}
else
{
for(int i = 0; i < m_objectList.size(); ++i)
{
if ( (m_repeat == true) ||
std::find(m_combination.begin(), m_combination.end(), m_objectList[i]) == m_combination.end() )
{
m_combination.push_back(m_objectList[i]);
permutation(length, i);
m_combination.pop_back();
}
}
}
}
template <class T> void Combinatorics<T>::combination(int length, int index)
{
if(length < 0 || (length > m_objectList.size() && m_repeat == false))
{
std::cout << "Invalid: \n(r > n) || (r < 0)\n";
return;
}
if(m_combination.size() >= length)
{
display_combination();
++m_count;
}
else
{
for(int i = index; i < m_objectList.size(); ++i)
{
m_combination.push_back(m_objectList[i]);
if(m_repeat == true)
combination(length, i);
else
combination(length, i+1);
m_combination.pop_back();
}
}
}
#endif // COMBINATORICS_IMP
|
5b5d522d88b5d7adffaf0427feda3f432e53b0ce | a3d6556180e74af7b555f8d47d3fea55b94bcbda | /chrome/browser/extensions/api/declarative_content/default_content_predicate_evaluators.h | e444a0a28a7f960b004168505b7d495998d8435a | [
"BSD-3-Clause"
] | permissive | chromium/chromium | aaa9eda10115b50b0616d2f1aed5ef35d1d779d6 | a401d6cf4f7bf0e2d2e964c512ebb923c3d8832c | refs/heads/main | 2023-08-24T00:35:12.585945 | 2023-08-23T22:01:11 | 2023-08-23T22:01:11 | 120,360,765 | 17,408 | 7,102 | BSD-3-Clause | 2023-09-10T23:44:27 | 2018-02-05T20:55:32 | null | UTF-8 | C++ | false | false | 886 | h | default_content_predicate_evaluators.h | // Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_DEFAULT_CONTENT_PREDICATE_EVALUATORS_H_
#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_DEFAULT_CONTENT_PREDICATE_EVALUATORS_H_
#include <memory>
#include <vector>
#include "chrome/browser/extensions/api/declarative_content/content_predicate_evaluator.h"
namespace content {
class BrowserContext;
} // namespace content
namespace extensions {
std::vector<std::unique_ptr<ContentPredicateEvaluator>>
CreateDefaultContentPredicateEvaluators(
content::BrowserContext* browser_context,
ContentPredicateEvaluator::Delegate* delegate);
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_DEFAULT_CONTENT_PREDICATE_EVALUATORS_H_
|
1ebba7887f3c896e43931a8a346b112c07627d60 | 9d364a8161e6142c7cb7d23dedbf5ce86f306eaa | /Serwis/Serwis/MyForm.h | 29c9a6b3eaa57cb81161f151dc2e7b0013e2cc3c | [] | no_license | symygy/ServiceApp | b591a4902229ec61b6fa90e1f36770b969ba3b38 | b51b83a9159776080cc910838c0c485fb06d6284 | refs/heads/master | 2021-09-06T21:03:24.838717 | 2018-02-11T11:41:16 | 2018-02-11T11:41:16 | 114,285,587 | 0 | 0 | null | null | null | null | WINDOWS-1250 | C++ | false | false | 66,778 | h | MyForm.h | #pragma once
//#include "logowanie.h"
namespace Serwis {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace MySql::Data::MySqlClient;
/// <summary>
/// Podsumowanie informacji o MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
int id_uzytkownika;
private: System::Windows::Forms::DataGridView^ dgPodmioty;
public:
private: System::Windows::Forms::GroupBox^ groupBox5;
private: System::Windows::Forms::GroupBox^ groupBox6;
private: System::Windows::Forms::RichTextBox^ rtbPOpis;
private: System::Windows::Forms::GroupBox^ groupBox7;
private: System::Windows::Forms::TextBox^ tbPKod;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::TextBox^ tbPMiasto;
private: System::Windows::Forms::TextBox^ tbPUlica;
private: System::Windows::Forms::TextBox^ tbPNazwa;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::Label^ label8;
private: System::Windows::Forms::Label^ label9;
private: System::Windows::Forms::Button^ btnPSzukaj;
private: System::Windows::Forms::TextBox^ tbPSzukaj;
private: System::Windows::Forms::Button^ btnPUsun;
private: System::Windows::Forms::Button^ btnPModyfikuj;
private: System::Windows::Forms::Button^ btnPDodaj;
private: System::Windows::Forms::GroupBox^ groupBox8;
private: System::Windows::Forms::Button^ btnUstUsun;
private: System::Windows::Forms::Button^ btnUstModyfikuj;
private: System::Windows::Forms::Button^ btnUstDodaj;
private: System::Windows::Forms::TextBox^ tbUstLogin;
private: System::Windows::Forms::Label^ label13;
private: System::Windows::Forms::TextBox^ tbUstPowtorzH;
private: System::Windows::Forms::TextBox^ tbUstNoweH;
private: System::Windows::Forms::TextBox^ tbUstStareH;
private: System::Windows::Forms::Label^ label12;
private: System::Windows::Forms::Label^ label11;
private: System::Windows::Forms::Label^ label10;
private: System::Windows::Forms::Button^ btnUWybierz;
private: System::Windows::Forms::TextBox^ tbUWlasciciel;
private: System::Windows::Forms::Button^ btnPPrzypisz;
private: System::Windows::Forms::DataGridView^ dgUstawienia;
private: System::Windows::Forms::Button^ btnUstSzukaj;
private: System::Windows::Forms::TextBox^ tbUstSzukaj;
private: System::Windows::Forms::TextBox^ tbUstImie;
private: System::Windows::Forms::Label^ label15;
private: System::Windows::Forms::TextBox^ tbUstNazwisko;
private: System::Windows::Forms::Label^ label14;
private: System::Windows::Forms::Label^ label16;
private: System::Windows::Forms::Label^ label17;
private: System::Windows::Forms::Label^ lblZalogowano;
private: System::Windows::Forms::ToolTip^ toolTip1;
public:
//String^ konfiguracja = L"datasource=localhost; port=3306; username=root;password=password;database=serwis"; lokalny serwer
String^ konfiguracja = L"datasource=mn26.webd.pl; port=3306; username=symygy_serwis; password=Pass1234; database=symygy_service"; //hosting
MyForm(int uzytkownik)
{
InitializeComponent();
toolTip1->SetToolTip(lblZalogowano, "Tylko administrator może dodawać i usuwać użytkowników.");
id_uzytkownika = uzytkownik;
wczytanie_serwisantow();
if (id_uzytkownika == 1) {
lblZalogowano->Text = "administrator";
btnUstDodaj->Enabled = true;
//btnUstUsun->Enabled = true;
}
else
{
lblZalogowano->Text = "zwykły użytkownik";
btnUstDodaj->Enabled = false;
btnUstUsun->Enabled = false;
}
}
protected:
/// <summary>
/// Wyczyść wszystkie używane zasoby.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TabControl^ tabControl1;
protected:
private: System::Windows::Forms::TabPage^ tabPage1;
private: System::Windows::Forms::TabPage^ tabPage2;
private: System::Windows::Forms::TabPage^ tabPage3;
private: System::Windows::Forms::ImageList^ imageList1;
private: System::Windows::Forms::GroupBox^ groupBox1;
private: System::Windows::Forms::GroupBox^ groupBox2;
private: System::Windows::Forms::RadioButton^ rbUusluga;
private: System::Windows::Forms::RadioButton^ rbUPrzeglad;
private: System::Windows::Forms::RadioButton^ rbUNaprawa;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ tbUSeryjny;
private: System::Windows::Forms::TextBox^ tbUNazwa;
private: System::Windows::Forms::ComboBox^ cbUTyp;
private: System::Windows::Forms::DataGridView^ dgUrzadzenia;
private: System::Windows::Forms::GroupBox^ groupBox3;
private: System::Windows::Forms::ComboBox^ cbUSerwisant;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Button^ btnUSzukaj;
private: System::Windows::Forms::TextBox^ tbUSzukaj;
private: System::Windows::Forms::Button^ btnUUsun;
private: System::Windows::Forms::Button^ btnUModyfikuj;
private: System::Windows::Forms::Button^ btnUDodaj;
private: System::Windows::Forms::TabPage^ tabPage4;
private: System::Windows::Forms::RichTextBox^ rtbUOpis;
private: System::Windows::Forms::GroupBox^ groupBox4;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Wymagana zmienna projektanta.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Wymagana metoda wsparcia projektanta - nie należy modyfikować
/// zawartość tej metody z edytorem kodu.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->groupBox4 = (gcnew System::Windows::Forms::GroupBox());
this->rtbUOpis = (gcnew System::Windows::Forms::RichTextBox());
this->groupBox3 = (gcnew System::Windows::Forms::GroupBox());
this->btnUWybierz = (gcnew System::Windows::Forms::Button());
this->tbUWlasciciel = (gcnew System::Windows::Forms::TextBox());
this->cbUSerwisant = (gcnew System::Windows::Forms::ComboBox());
this->label5 = (gcnew System::Windows::Forms::Label());
this->tbUSeryjny = (gcnew System::Windows::Forms::TextBox());
this->tbUNazwa = (gcnew System::Windows::Forms::TextBox());
this->cbUTyp = (gcnew System::Windows::Forms::ComboBox());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label1 = (gcnew System::Windows::Forms::Label());
this->btnUSzukaj = (gcnew System::Windows::Forms::Button());
this->tbUSzukaj = (gcnew System::Windows::Forms::TextBox());
this->btnUUsun = (gcnew System::Windows::Forms::Button());
this->btnUModyfikuj = (gcnew System::Windows::Forms::Button());
this->btnUDodaj = (gcnew System::Windows::Forms::Button());
this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
this->rbUusluga = (gcnew System::Windows::Forms::RadioButton());
this->rbUPrzeglad = (gcnew System::Windows::Forms::RadioButton());
this->rbUNaprawa = (gcnew System::Windows::Forms::RadioButton());
this->dgUrzadzenia = (gcnew System::Windows::Forms::DataGridView());
this->tabPage3 = (gcnew System::Windows::Forms::TabPage());
this->dgPodmioty = (gcnew System::Windows::Forms::DataGridView());
this->groupBox5 = (gcnew System::Windows::Forms::GroupBox());
this->btnPPrzypisz = (gcnew System::Windows::Forms::Button());
this->groupBox6 = (gcnew System::Windows::Forms::GroupBox());
this->rtbPOpis = (gcnew System::Windows::Forms::RichTextBox());
this->groupBox7 = (gcnew System::Windows::Forms::GroupBox());
this->tbPKod = (gcnew System::Windows::Forms::TextBox());
this->label6 = (gcnew System::Windows::Forms::Label());
this->tbPMiasto = (gcnew System::Windows::Forms::TextBox());
this->tbPUlica = (gcnew System::Windows::Forms::TextBox());
this->tbPNazwa = (gcnew System::Windows::Forms::TextBox());
this->label7 = (gcnew System::Windows::Forms::Label());
this->label8 = (gcnew System::Windows::Forms::Label());
this->label9 = (gcnew System::Windows::Forms::Label());
this->btnPSzukaj = (gcnew System::Windows::Forms::Button());
this->tbPSzukaj = (gcnew System::Windows::Forms::TextBox());
this->btnPUsun = (gcnew System::Windows::Forms::Button());
this->btnPModyfikuj = (gcnew System::Windows::Forms::Button());
this->btnPDodaj = (gcnew System::Windows::Forms::Button());
this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
this->dgUstawienia = (gcnew System::Windows::Forms::DataGridView());
this->groupBox8 = (gcnew System::Windows::Forms::GroupBox());
this->label16 = (gcnew System::Windows::Forms::Label());
this->tbUstImie = (gcnew System::Windows::Forms::TextBox());
this->label15 = (gcnew System::Windows::Forms::Label());
this->tbUstNazwisko = (gcnew System::Windows::Forms::TextBox());
this->label14 = (gcnew System::Windows::Forms::Label());
this->btnUstSzukaj = (gcnew System::Windows::Forms::Button());
this->tbUstSzukaj = (gcnew System::Windows::Forms::TextBox());
this->btnUstUsun = (gcnew System::Windows::Forms::Button());
this->btnUstModyfikuj = (gcnew System::Windows::Forms::Button());
this->btnUstDodaj = (gcnew System::Windows::Forms::Button());
this->tbUstLogin = (gcnew System::Windows::Forms::TextBox());
this->label13 = (gcnew System::Windows::Forms::Label());
this->tbUstPowtorzH = (gcnew System::Windows::Forms::TextBox());
this->tbUstNoweH = (gcnew System::Windows::Forms::TextBox());
this->tbUstStareH = (gcnew System::Windows::Forms::TextBox());
this->label12 = (gcnew System::Windows::Forms::Label());
this->label11 = (gcnew System::Windows::Forms::Label());
this->label10 = (gcnew System::Windows::Forms::Label());
this->tabPage4 = (gcnew System::Windows::Forms::TabPage());
this->imageList1 = (gcnew System::Windows::Forms::ImageList(this->components));
this->label17 = (gcnew System::Windows::Forms::Label());
this->lblZalogowano = (gcnew System::Windows::Forms::Label());
this->toolTip1 = (gcnew System::Windows::Forms::ToolTip(this->components));
this->tabControl1->SuspendLayout();
this->tabPage2->SuspendLayout();
this->groupBox1->SuspendLayout();
this->groupBox4->SuspendLayout();
this->groupBox3->SuspendLayout();
this->groupBox2->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dgUrzadzenia))->BeginInit();
this->tabPage3->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dgPodmioty))->BeginInit();
this->groupBox5->SuspendLayout();
this->groupBox6->SuspendLayout();
this->groupBox7->SuspendLayout();
this->tabPage1->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dgUstawienia))->BeginInit();
this->groupBox8->SuspendLayout();
this->SuspendLayout();
//
// tabControl1
//
this->tabControl1->Alignment = System::Windows::Forms::TabAlignment::Bottom;
this->tabControl1->Controls->Add(this->tabPage2);
this->tabControl1->Controls->Add(this->tabPage3);
this->tabControl1->Controls->Add(this->tabPage1);
this->tabControl1->Controls->Add(this->tabPage4);
this->tabControl1->ImageList = this->imageList1;
this->tabControl1->Location = System::Drawing::Point(1, 1);
this->tabControl1->Multiline = true;
this->tabControl1->Name = L"tabControl1";
this->tabControl1->SelectedIndex = 0;
this->tabControl1->Size = System::Drawing::Size(1198, 595);
this->tabControl1->TabIndex = 0;
this->tabControl1->MouseClick += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::tabControl1_MouseClick);
//
// tabPage2
//
this->tabPage2->Controls->Add(this->groupBox1);
this->tabPage2->Controls->Add(this->dgUrzadzenia);
this->tabPage2->ImageIndex = 2;
this->tabPage2->ImeMode = System::Windows::Forms::ImeMode::NoControl;
this->tabPage2->Location = System::Drawing::Point(4, 4);
this->tabPage2->Name = L"tabPage2";
this->tabPage2->Padding = System::Windows::Forms::Padding(3);
this->tabPage2->Size = System::Drawing::Size(1190, 520);
this->tabPage2->TabIndex = 1;
this->tabPage2->Text = L"Urządzenia";
this->tabPage2->UseVisualStyleBackColor = true;
//
// groupBox1
//
this->groupBox1->Controls->Add(this->groupBox4);
this->groupBox1->Controls->Add(this->groupBox3);
this->groupBox1->Controls->Add(this->btnUSzukaj);
this->groupBox1->Controls->Add(this->tbUSzukaj);
this->groupBox1->Controls->Add(this->btnUUsun);
this->groupBox1->Controls->Add(this->btnUModyfikuj);
this->groupBox1->Controls->Add(this->btnUDodaj);
this->groupBox1->Controls->Add(this->groupBox2);
this->groupBox1->Location = System::Drawing::Point(7, 6);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(314, 497);
this->groupBox1->TabIndex = 0;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"Urządzenia";
//
// groupBox4
//
this->groupBox4->Controls->Add(this->rtbUOpis);
this->groupBox4->Location = System::Drawing::Point(6, 365);
this->groupBox4->Name = L"groupBox4";
this->groupBox4->Size = System::Drawing::Size(302, 87);
this->groupBox4->TabIndex = 17;
this->groupBox4->TabStop = false;
this->groupBox4->Text = L"Opis";
//
// rtbUOpis
//
this->rtbUOpis->Location = System::Drawing::Point(6, 19);
this->rtbUOpis->Name = L"rtbUOpis";
this->rtbUOpis->Size = System::Drawing::Size(290, 62);
this->rtbUOpis->TabIndex = 12;
this->rtbUOpis->Text = L"";
//
// groupBox3
//
this->groupBox3->Controls->Add(this->btnUWybierz);
this->groupBox3->Controls->Add(this->tbUWlasciciel);
this->groupBox3->Controls->Add(this->cbUSerwisant);
this->groupBox3->Controls->Add(this->label5);
this->groupBox3->Controls->Add(this->tbUSeryjny);
this->groupBox3->Controls->Add(this->tbUNazwa);
this->groupBox3->Controls->Add(this->cbUTyp);
this->groupBox3->Controls->Add(this->label4);
this->groupBox3->Controls->Add(this->label3);
this->groupBox3->Controls->Add(this->label2);
this->groupBox3->Controls->Add(this->label1);
this->groupBox3->Location = System::Drawing::Point(6, 94);
this->groupBox3->Name = L"groupBox3";
this->groupBox3->Size = System::Drawing::Size(302, 205);
this->groupBox3->TabIndex = 15;
this->groupBox3->TabStop = false;
this->groupBox3->Text = L"Dane podstawowe";
//
// btnUWybierz
//
this->btnUWybierz->Location = System::Drawing::Point(233, 127);
this->btnUWybierz->Name = L"btnUWybierz";
this->btnUWybierz->Size = System::Drawing::Size(63, 22);
this->btnUWybierz->TabIndex = 7;
this->btnUWybierz->Text = L"Wybierz";
this->btnUWybierz->UseVisualStyleBackColor = true;
this->btnUWybierz->Click += gcnew System::EventHandler(this, &MyForm::btnUWybierz_Click);
//
// tbUWlasciciel
//
this->tbUWlasciciel->Enabled = false;
this->tbUWlasciciel->Location = System::Drawing::Point(106, 129);
this->tbUWlasciciel->Name = L"tbUWlasciciel";
this->tbUWlasciciel->Size = System::Drawing::Size(121, 20);
this->tbUWlasciciel->TabIndex = 6;
//
// cbUSerwisant
//
this->cbUSerwisant->FormattingEnabled = true;
this->cbUSerwisant->Items->AddRange(gcnew cli::array< System::Object^ >(2) { L"Jakub Rusek", L"Michał Kurek" });
this->cbUSerwisant->Location = System::Drawing::Point(106, 162);
this->cbUSerwisant->Name = L"cbUSerwisant";
this->cbUSerwisant->Size = System::Drawing::Size(121, 21);
this->cbUSerwisant->Sorted = true;
this->cbUSerwisant->TabIndex = 8;
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(5, 165);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(56, 13);
this->label5->TabIndex = 13;
this->label5->Text = L"Serwisant:";
//
// tbUSeryjny
//
this->tbUSeryjny->Location = System::Drawing::Point(106, 96);
this->tbUSeryjny->Name = L"tbUSeryjny";
this->tbUSeryjny->Size = System::Drawing::Size(121, 20);
this->tbUSeryjny->TabIndex = 5;
//
// tbUNazwa
//
this->tbUNazwa->Location = System::Drawing::Point(106, 62);
this->tbUNazwa->Name = L"tbUNazwa";
this->tbUNazwa->Size = System::Drawing::Size(121, 20);
this->tbUNazwa->TabIndex = 4;
//
// cbUTyp
//
this->cbUTyp->FormattingEnabled = true;
this->cbUTyp->Items->AddRange(gcnew cli::array< System::Object^ >(5) {
L"Aparat EKG", L"Defibrylator", L"Kardiomonitor",
L"Pompa", L"Ssak"
});
this->cbUTyp->Location = System::Drawing::Point(106, 27);
this->cbUTyp->Name = L"cbUTyp";
this->cbUTyp->Size = System::Drawing::Size(121, 21);
this->cbUTyp->Sorted = true;
this->cbUTyp->TabIndex = 3;
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(5, 132);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(60, 13);
this->label4->TabIndex = 3;
this->label4->Text = L"Właściciel:";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(5, 99);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(76, 13);
this->label3->TabIndex = 2;
this->label3->Text = L"Numer seryjny:";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(5, 65);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(43, 13);
this->label2->TabIndex = 1;
this->label2->Text = L"Nazwa:";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(5, 30);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(28, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Typ:";
//
// btnUSzukaj
//
this->btnUSzukaj->Location = System::Drawing::Point(117, 65);
this->btnUSzukaj->Name = L"btnUSzukaj";
this->btnUSzukaj->Size = System::Drawing::Size(75, 23);
this->btnUSzukaj->TabIndex = 2;
this->btnUSzukaj->Text = L"Szukaj";
this->btnUSzukaj->UseVisualStyleBackColor = true;
this->btnUSzukaj->Click += gcnew System::EventHandler(this, &MyForm::btnUSzukaj_Click);
//
// tbUSzukaj
//
this->tbUSzukaj->Location = System::Drawing::Point(6, 39);
this->tbUSzukaj->Name = L"tbUSzukaj";
this->tbUSzukaj->Size = System::Drawing::Size(302, 20);
this->tbUSzukaj->TabIndex = 1;
//
// btnUUsun
//
this->btnUUsun->Enabled = false;
this->btnUUsun->Location = System::Drawing::Point(208, 462);
this->btnUUsun->Name = L"btnUUsun";
this->btnUUsun->Size = System::Drawing::Size(75, 23);
this->btnUUsun->TabIndex = 15;
this->btnUUsun->Text = L"usuń";
this->btnUUsun->UseVisualStyleBackColor = true;
this->btnUUsun->Click += gcnew System::EventHandler(this, &MyForm::btnUUsun_Click);
//
// btnUModyfikuj
//
this->btnUModyfikuj->Enabled = false;
this->btnUModyfikuj->Location = System::Drawing::Point(117, 462);
this->btnUModyfikuj->Name = L"btnUModyfikuj";
this->btnUModyfikuj->Size = System::Drawing::Size(75, 23);
this->btnUModyfikuj->TabIndex = 14;
this->btnUModyfikuj->Text = L"modyfikuj";
this->btnUModyfikuj->UseVisualStyleBackColor = true;
this->btnUModyfikuj->Click += gcnew System::EventHandler(this, &MyForm::btnUModyfikuj_Click);
//
// btnUDodaj
//
this->btnUDodaj->Location = System::Drawing::Point(27, 462);
this->btnUDodaj->Name = L"btnUDodaj";
this->btnUDodaj->Size = System::Drawing::Size(75, 23);
this->btnUDodaj->TabIndex = 13;
this->btnUDodaj->Text = L"dodaj";
this->btnUDodaj->UseVisualStyleBackColor = true;
this->btnUDodaj->Click += gcnew System::EventHandler(this, &MyForm::btnUDodaj_Click);
//
// groupBox2
//
this->groupBox2->Controls->Add(this->rbUusluga);
this->groupBox2->Controls->Add(this->rbUPrzeglad);
this->groupBox2->Controls->Add(this->rbUNaprawa);
this->groupBox2->Location = System::Drawing::Point(6, 303);
this->groupBox2->Name = L"groupBox2";
this->groupBox2->Size = System::Drawing::Size(302, 55);
this->groupBox2->TabIndex = 5;
this->groupBox2->TabStop = false;
this->groupBox2->Text = L"Kategoria";
//
// rbUusluga
//
this->rbUusluga->AutoSize = true;
this->rbUusluga->Location = System::Drawing::Point(189, 26);
this->rbUusluga->Name = L"rbUusluga";
this->rbUusluga->Size = System::Drawing::Size(58, 17);
this->rbUusluga->TabIndex = 11;
this->rbUusluga->Text = L"usługa";
this->rbUusluga->UseVisualStyleBackColor = true;
//
// rbUPrzeglad
//
this->rbUPrzeglad->AutoSize = true;
this->rbUPrzeglad->Checked = true;
this->rbUPrzeglad->Location = System::Drawing::Point(7, 26);
this->rbUPrzeglad->Name = L"rbUPrzeglad";
this->rbUPrzeglad->Size = System::Drawing::Size(65, 17);
this->rbUPrzeglad->TabIndex = 9;
this->rbUPrzeglad->TabStop = true;
this->rbUPrzeglad->Text = L"przegląd";
this->rbUPrzeglad->UseVisualStyleBackColor = true;
//
// rbUNaprawa
//
this->rbUNaprawa->AutoSize = true;
this->rbUNaprawa->Location = System::Drawing::Point(98, 26);
this->rbUNaprawa->Name = L"rbUNaprawa";
this->rbUNaprawa->Size = System::Drawing::Size(66, 17);
this->rbUNaprawa->TabIndex = 10;
this->rbUNaprawa->Text = L"naprawa";
this->rbUNaprawa->UseVisualStyleBackColor = true;
//
// dgUrzadzenia
//
this->dgUrzadzenia->AllowUserToAddRows = false;
this->dgUrzadzenia->AllowUserToOrderColumns = true;
this->dgUrzadzenia->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->dgUrzadzenia->Location = System::Drawing::Point(327, 6);
this->dgUrzadzenia->Name = L"dgUrzadzenia";
this->dgUrzadzenia->Size = System::Drawing::Size(856, 497);
this->dgUrzadzenia->TabIndex = 1;
this->dgUrzadzenia->CellClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &MyForm::dgUrzadzenia_CellClick);
//
// tabPage3
//
this->tabPage3->Controls->Add(this->dgPodmioty);
this->tabPage3->Controls->Add(this->groupBox5);
this->tabPage3->ImageIndex = 1;
this->tabPage3->Location = System::Drawing::Point(4, 4);
this->tabPage3->Name = L"tabPage3";
this->tabPage3->Padding = System::Windows::Forms::Padding(3);
this->tabPage3->Size = System::Drawing::Size(1190, 520);
this->tabPage3->TabIndex = 2;
this->tabPage3->Text = L"Podmioty";
this->tabPage3->UseVisualStyleBackColor = true;
//
// dgPodmioty
//
this->dgPodmioty->AllowUserToAddRows = false;
this->dgPodmioty->AllowUserToOrderColumns = true;
this->dgPodmioty->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->dgPodmioty->Location = System::Drawing::Point(328, 7);
this->dgPodmioty->Name = L"dgPodmioty";
this->dgPodmioty->Size = System::Drawing::Size(856, 497);
this->dgPodmioty->TabIndex = 2;
this->dgPodmioty->CellClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &MyForm::dgPodmioty_CellClick);
//
// groupBox5
//
this->groupBox5->Controls->Add(this->btnPPrzypisz);
this->groupBox5->Controls->Add(this->groupBox6);
this->groupBox5->Controls->Add(this->groupBox7);
this->groupBox5->Controls->Add(this->btnPSzukaj);
this->groupBox5->Controls->Add(this->tbPSzukaj);
this->groupBox5->Controls->Add(this->btnPUsun);
this->groupBox5->Controls->Add(this->btnPModyfikuj);
this->groupBox5->Controls->Add(this->btnPDodaj);
this->groupBox5->Location = System::Drawing::Point(7, 6);
this->groupBox5->Name = L"groupBox5";
this->groupBox5->Size = System::Drawing::Size(315, 497);
this->groupBox5->TabIndex = 1;
this->groupBox5->TabStop = false;
this->groupBox5->Text = L"Podmioty";
//
// btnPPrzypisz
//
this->btnPPrzypisz->Location = System::Drawing::Point(67, 451);
this->btnPPrzypisz->Name = L"btnPPrzypisz";
this->btnPPrzypisz->Size = System::Drawing::Size(173, 23);
this->btnPPrzypisz->TabIndex = 26;
this->btnPPrzypisz->Text = L"Przypisz podmiot do urządzenia";
this->btnPPrzypisz->UseVisualStyleBackColor = true;
this->btnPPrzypisz->Click += gcnew System::EventHandler(this, &MyForm::btnPPrzypisz_Click);
//
// groupBox6
//
this->groupBox6->Controls->Add(this->rtbPOpis);
this->groupBox6->Location = System::Drawing::Point(6, 266);
this->groupBox6->Name = L"groupBox6";
this->groupBox6->Size = System::Drawing::Size(303, 87);
this->groupBox6->TabIndex = 17;
this->groupBox6->TabStop = false;
this->groupBox6->Text = L"Opis";
//
// rtbPOpis
//
this->rtbPOpis->Location = System::Drawing::Point(6, 19);
this->rtbPOpis->Name = L"rtbPOpis";
this->rtbPOpis->Size = System::Drawing::Size(291, 62);
this->rtbPOpis->TabIndex = 22;
this->rtbPOpis->Text = L"";
//
// groupBox7
//
this->groupBox7->Controls->Add(this->tbPKod);
this->groupBox7->Controls->Add(this->label6);
this->groupBox7->Controls->Add(this->tbPMiasto);
this->groupBox7->Controls->Add(this->tbPUlica);
this->groupBox7->Controls->Add(this->tbPNazwa);
this->groupBox7->Controls->Add(this->label7);
this->groupBox7->Controls->Add(this->label8);
this->groupBox7->Controls->Add(this->label9);
this->groupBox7->Location = System::Drawing::Point(6, 94);
this->groupBox7->Name = L"groupBox7";
this->groupBox7->Size = System::Drawing::Size(303, 166);
this->groupBox7->TabIndex = 15;
this->groupBox7->TabStop = false;
this->groupBox7->Text = L"Dane podstawowe";
//
// tbPKod
//
this->tbPKod->Location = System::Drawing::Point(85, 123);
this->tbPKod->Name = L"tbPKod";
this->tbPKod->Size = System::Drawing::Size(212, 20);
this->tbPKod->TabIndex = 21;
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(5, 126);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(74, 13);
this->label6->TabIndex = 13;
this->label6->Text = L"Kod pocztowy";
//
// tbPMiasto
//
this->tbPMiasto->Location = System::Drawing::Point(85, 90);
this->tbPMiasto->Name = L"tbPMiasto";
this->tbPMiasto->Size = System::Drawing::Size(212, 20);
this->tbPMiasto->TabIndex = 20;
//
// tbPUlica
//
this->tbPUlica->Location = System::Drawing::Point(85, 57);
this->tbPUlica->Name = L"tbPUlica";
this->tbPUlica->Size = System::Drawing::Size(212, 20);
this->tbPUlica->TabIndex = 19;
//
// tbPNazwa
//
this->tbPNazwa->Location = System::Drawing::Point(85, 25);
this->tbPNazwa->Name = L"tbPNazwa";
this->tbPNazwa->Size = System::Drawing::Size(212, 20);
this->tbPNazwa->TabIndex = 18;
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::Drawing::Point(5, 93);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(38, 13);
this->label7->TabIndex = 3;
this->label7->Text = L"Miasto";
//
// label8
//
this->label8->AutoSize = true;
this->label8->Location = System::Drawing::Point(5, 60);
this->label8->Name = L"label8";
this->label8->Size = System::Drawing::Size(31, 13);
this->label8->TabIndex = 2;
this->label8->Text = L"Ulica";
//
// label9
//
this->label9->AutoSize = true;
this->label9->Location = System::Drawing::Point(5, 26);
this->label9->Name = L"label9";
this->label9->Size = System::Drawing::Size(43, 13);
this->label9->TabIndex = 1;
this->label9->Text = L"Nazwa:";
//
// btnPSzukaj
//
this->btnPSzukaj->Location = System::Drawing::Point(117, 65);
this->btnPSzukaj->Name = L"btnPSzukaj";
this->btnPSzukaj->Size = System::Drawing::Size(75, 23);
this->btnPSzukaj->TabIndex = 17;
this->btnPSzukaj->Text = L"Szukaj";
this->btnPSzukaj->UseVisualStyleBackColor = true;
this->btnPSzukaj->Click += gcnew System::EventHandler(this, &MyForm::btnPSzukaj_Click);
//
// tbPSzukaj
//
this->tbPSzukaj->Location = System::Drawing::Point(6, 39);
this->tbPSzukaj->Name = L"tbPSzukaj";
this->tbPSzukaj->Size = System::Drawing::Size(303, 20);
this->tbPSzukaj->TabIndex = 16;
//
// btnPUsun
//
this->btnPUsun->Enabled = false;
this->btnPUsun->Location = System::Drawing::Point(209, 389);
this->btnPUsun->Name = L"btnPUsun";
this->btnPUsun->Size = System::Drawing::Size(75, 23);
this->btnPUsun->TabIndex = 25;
this->btnPUsun->Text = L"usuń";
this->btnPUsun->UseVisualStyleBackColor = true;
this->btnPUsun->Click += gcnew System::EventHandler(this, &MyForm::btnPUsun_Click);
//
// btnPModyfikuj
//
this->btnPModyfikuj->Enabled = false;
this->btnPModyfikuj->Location = System::Drawing::Point(118, 389);
this->btnPModyfikuj->Name = L"btnPModyfikuj";
this->btnPModyfikuj->Size = System::Drawing::Size(75, 23);
this->btnPModyfikuj->TabIndex = 24;
this->btnPModyfikuj->Text = L"modyfikuj";
this->btnPModyfikuj->UseVisualStyleBackColor = true;
this->btnPModyfikuj->Click += gcnew System::EventHandler(this, &MyForm::btnPModyfikuj_Click);
//
// btnPDodaj
//
this->btnPDodaj->Location = System::Drawing::Point(28, 389);
this->btnPDodaj->Name = L"btnPDodaj";
this->btnPDodaj->Size = System::Drawing::Size(75, 23);
this->btnPDodaj->TabIndex = 23;
this->btnPDodaj->Text = L"dodaj";
this->btnPDodaj->UseVisualStyleBackColor = true;
this->btnPDodaj->Click += gcnew System::EventHandler(this, &MyForm::btnPDodaj_Click);
//
// tabPage1
//
this->tabPage1->Controls->Add(this->dgUstawienia);
this->tabPage1->Controls->Add(this->groupBox8);
this->tabPage1->ImageIndex = 5;
this->tabPage1->Location = System::Drawing::Point(4, 4);
this->tabPage1->Name = L"tabPage1";
this->tabPage1->Padding = System::Windows::Forms::Padding(3);
this->tabPage1->Size = System::Drawing::Size(1190, 520);
this->tabPage1->TabIndex = 0;
this->tabPage1->Text = L"Serwisanci";
this->tabPage1->UseVisualStyleBackColor = true;
//
// dgUstawienia
//
this->dgUstawienia->AllowUserToAddRows = false;
this->dgUstawienia->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->dgUstawienia->Location = System::Drawing::Point(329, 7);
this->dgUstawienia->Name = L"dgUstawienia";
this->dgUstawienia->ReadOnly = true;
this->dgUstawienia->Size = System::Drawing::Size(851, 500);
this->dgUstawienia->TabIndex = 1;
this->dgUstawienia->CellClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &MyForm::dgUstawienia_CellClick);
//
// groupBox8
//
this->groupBox8->Controls->Add(this->label16);
this->groupBox8->Controls->Add(this->tbUstImie);
this->groupBox8->Controls->Add(this->label15);
this->groupBox8->Controls->Add(this->tbUstNazwisko);
this->groupBox8->Controls->Add(this->label14);
this->groupBox8->Controls->Add(this->btnUstSzukaj);
this->groupBox8->Controls->Add(this->tbUstSzukaj);
this->groupBox8->Controls->Add(this->btnUstUsun);
this->groupBox8->Controls->Add(this->btnUstModyfikuj);
this->groupBox8->Controls->Add(this->btnUstDodaj);
this->groupBox8->Controls->Add(this->tbUstLogin);
this->groupBox8->Controls->Add(this->label13);
this->groupBox8->Controls->Add(this->tbUstPowtorzH);
this->groupBox8->Controls->Add(this->tbUstNoweH);
this->groupBox8->Controls->Add(this->tbUstStareH);
this->groupBox8->Controls->Add(this->label12);
this->groupBox8->Controls->Add(this->label11);
this->groupBox8->Controls->Add(this->label10);
this->groupBox8->Location = System::Drawing::Point(7, 6);
this->groupBox8->Name = L"groupBox8";
this->groupBox8->Size = System::Drawing::Size(316, 500);
this->groupBox8->TabIndex = 0;
this->groupBox8->TabStop = false;
this->groupBox8->Text = L"Edycja danych użytkownika";
//
// label16
//
this->label16->AutoSize = true;
this->label16->Location = System::Drawing::Point(6, 289);
this->label16->Name = L"label16";
this->label16->Size = System::Drawing::Size(0, 13);
this->label16->TabIndex = 23;
//
// tbUstImie
//
this->tbUstImie->Location = System::Drawing::Point(97, 119);
this->tbUstImie->Name = L"tbUstImie";
this->tbUstImie->Size = System::Drawing::Size(100, 20);
this->tbUstImie->TabIndex = 29;
//
// label15
//
this->label15->AutoSize = true;
this->label15->Location = System::Drawing::Point(6, 122);
this->label15->Name = L"label15";
this->label15->Size = System::Drawing::Size(29, 13);
this->label15->TabIndex = 20;
this->label15->Text = L"Imię:";
//
// tbUstNazwisko
//
this->tbUstNazwisko->Location = System::Drawing::Point(97, 145);
this->tbUstNazwisko->Name = L"tbUstNazwisko";
this->tbUstNazwisko->Size = System::Drawing::Size(100, 20);
this->tbUstNazwisko->TabIndex = 30;
//
// label14
//
this->label14->AutoSize = true;
this->label14->Location = System::Drawing::Point(6, 148);
this->label14->Name = L"label14";
this->label14->Size = System::Drawing::Size(56, 13);
this->label14->TabIndex = 18;
this->label14->Text = L"Nazwisko:";
//
// btnUstSzukaj
//
this->btnUstSzukaj->Location = System::Drawing::Point(117, 65);
this->btnUstSzukaj->Name = L"btnUstSzukaj";
this->btnUstSzukaj->Size = System::Drawing::Size(75, 23);
this->btnUstSzukaj->TabIndex = 28;
this->btnUstSzukaj->Text = L"Szukaj";
this->btnUstSzukaj->UseVisualStyleBackColor = true;
this->btnUstSzukaj->Click += gcnew System::EventHandler(this, &MyForm::btnUstSzukaj_Click);
//
// tbUstSzukaj
//
this->tbUstSzukaj->Location = System::Drawing::Point(6, 39);
this->tbUstSzukaj->Name = L"tbUstSzukaj";
this->tbUstSzukaj->Size = System::Drawing::Size(303, 20);
this->tbUstSzukaj->TabIndex = 27;
//
// btnUstUsun
//
this->btnUstUsun->Enabled = false;
this->btnUstUsun->Location = System::Drawing::Point(208, 289);
this->btnUstUsun->Name = L"btnUstUsun";
this->btnUstUsun->Size = System::Drawing::Size(75, 23);
this->btnUstUsun->TabIndex = 37;
this->btnUstUsun->Text = L"usuń";
this->btnUstUsun->UseVisualStyleBackColor = true;
this->btnUstUsun->Click += gcnew System::EventHandler(this, &MyForm::btnUstUsun_Click);
//
// btnUstModyfikuj
//
this->btnUstModyfikuj->Enabled = false;
this->btnUstModyfikuj->Location = System::Drawing::Point(117, 289);
this->btnUstModyfikuj->Name = L"btnUstModyfikuj";
this->btnUstModyfikuj->Size = System::Drawing::Size(75, 23);
this->btnUstModyfikuj->TabIndex = 36;
this->btnUstModyfikuj->Text = L"zmień hasło";
this->btnUstModyfikuj->UseVisualStyleBackColor = true;
this->btnUstModyfikuj->Click += gcnew System::EventHandler(this, &MyForm::btnUstModyfikuj_Click);
//
// btnUstDodaj
//
this->btnUstDodaj->Location = System::Drawing::Point(27, 289);
this->btnUstDodaj->Name = L"btnUstDodaj";
this->btnUstDodaj->Size = System::Drawing::Size(75, 23);
this->btnUstDodaj->TabIndex = 35;
this->btnUstDodaj->Text = L"dodaj";
this->btnUstDodaj->UseVisualStyleBackColor = true;
this->btnUstDodaj->Click += gcnew System::EventHandler(this, &MyForm::btnUstDodaj_Click);
//
// tbUstLogin
//
this->tbUstLogin->Location = System::Drawing::Point(97, 171);
this->tbUstLogin->Name = L"tbUstLogin";
this->tbUstLogin->Size = System::Drawing::Size(100, 20);
this->tbUstLogin->TabIndex = 31;
//
// label13
//
this->label13->AutoSize = true;
this->label13->Location = System::Drawing::Point(6, 174);
this->label13->Name = L"label13";
this->label13->Size = System::Drawing::Size(36, 13);
this->label13->TabIndex = 6;
this->label13->Text = L"Login:";
//
// tbUstPowtorzH
//
this->tbUstPowtorzH->Location = System::Drawing::Point(97, 250);
this->tbUstPowtorzH->Name = L"tbUstPowtorzH";
this->tbUstPowtorzH->PasswordChar = '*';
this->tbUstPowtorzH->Size = System::Drawing::Size(100, 20);
this->tbUstPowtorzH->TabIndex = 34;
this->tbUstPowtorzH->TextChanged += gcnew System::EventHandler(this, &MyForm::tbUstPowtorzH_TextChanged);
//
// tbUstNoweH
//
this->tbUstNoweH->Location = System::Drawing::Point(97, 224);
this->tbUstNoweH->Name = L"tbUstNoweH";
this->tbUstNoweH->PasswordChar = '*';
this->tbUstNoweH->Size = System::Drawing::Size(100, 20);
this->tbUstNoweH->TabIndex = 33;
this->tbUstNoweH->TextChanged += gcnew System::EventHandler(this, &MyForm::tbUstNoweH_TextChanged);
//
// tbUstStareH
//
this->tbUstStareH->Location = System::Drawing::Point(97, 198);
this->tbUstStareH->Name = L"tbUstStareH";
this->tbUstStareH->PasswordChar = '*';
this->tbUstStareH->Size = System::Drawing::Size(100, 20);
this->tbUstStareH->TabIndex = 32;
this->tbUstStareH->TextChanged += gcnew System::EventHandler(this, &MyForm::tbUstStareH_TextChanged);
//
// label12
//
this->label12->AutoSize = true;
this->label12->Location = System::Drawing::Point(6, 253);
this->label12->Name = L"label12";
this->label12->Size = System::Drawing::Size(78, 13);
this->label12->TabIndex = 2;
this->label12->Text = L"Powtórz hasło:";
//
// label11
//
this->label11->AutoSize = true;
this->label11->Location = System::Drawing::Point(6, 227);
this->label11->Name = L"label11";
this->label11->Size = System::Drawing::Size(68, 13);
this->label11->TabIndex = 1;
this->label11->Text = L"Nowe hasło:";
//
// label10
//
this->label10->AutoSize = true;
this->label10->Location = System::Drawing::Point(6, 201);
this->label10->Name = L"label10";
this->label10->Size = System::Drawing::Size(39, 13);
this->label10->TabIndex = 0;
this->label10->Text = L"Hasło:";
//
// tabPage4
//
this->tabPage4->ImageIndex = 3;
this->tabPage4->ImeMode = System::Windows::Forms::ImeMode::NoControl;
this->tabPage4->Location = System::Drawing::Point(4, 4);
this->tabPage4->Name = L"tabPage4";
this->tabPage4->Size = System::Drawing::Size(1190, 520);
this->tabPage4->TabIndex = 3;
this->tabPage4->Text = L"Zamknij";
this->tabPage4->UseVisualStyleBackColor = true;
//
// imageList1
//
this->imageList1->ImageStream = (cli::safe_cast<System::Windows::Forms::ImageListStreamer^>(resources->GetObject(L"imageList1.ImageStream")));
this->imageList1->TransparentColor = System::Drawing::Color::Transparent;
this->imageList1->Images->SetKeyName(0, L"gear.png");
this->imageList1->Images->SetKeyName(1, L"147-building.png");
this->imageList1->Images->SetKeyName(2, L"add_list.png");
this->imageList1->Images->SetKeyName(3, L"40-turn-off.png");
this->imageList1->Images->SetKeyName(4, L"icon100_com_137.png");
this->imageList1->Images->SetKeyName(5, L"16-users.png");
//
// label17
//
this->label17->AutoSize = true;
this->label17->Location = System::Drawing::Point(2, 599);
this->label17->Name = L"label17";
this->label17->Size = System::Drawing::Size(92, 13);
this->label17->TabIndex = 1;
this->label17->Text = L"Zalogowano jako:";
//
// lblZalogowano
//
this->lblZalogowano->AutoSize = true;
this->lblZalogowano->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(238)));
this->lblZalogowano->ForeColor = System::Drawing::Color::Red;
this->lblZalogowano->Location = System::Drawing::Point(91, 599);
this->lblZalogowano->Name = L"lblZalogowano";
this->lblZalogowano->Size = System::Drawing::Size(66, 13);
this->lblZalogowano->TabIndex = 2;
this->lblZalogowano->Text = L"administrator";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(1211, 615);
this->Controls->Add(this->lblZalogowano);
this->Controls->Add(this->label17);
this->Controls->Add(this->tabControl1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->MaximizeBox = false;
this->Name = L"MyForm";
this->Text = L"Aplikacja serwisowa";
this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
this->tabControl1->ResumeLayout(false);
this->tabPage2->ResumeLayout(false);
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
this->groupBox4->ResumeLayout(false);
this->groupBox3->ResumeLayout(false);
this->groupBox3->PerformLayout();
this->groupBox2->ResumeLayout(false);
this->groupBox2->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dgUrzadzenia))->EndInit();
this->tabPage3->ResumeLayout(false);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dgPodmioty))->EndInit();
this->groupBox5->ResumeLayout(false);
this->groupBox5->PerformLayout();
this->groupBox6->ResumeLayout(false);
this->groupBox7->ResumeLayout(false);
this->groupBox7->PerformLayout();
this->tabPage1->ResumeLayout(false);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dgUstawienia))->EndInit();
this->groupBox8->ResumeLayout(false);
this->groupBox8->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
//deklaracja zmiennych
int id_rekordu; //wybranie rekordu na ktorym pracuje - zmienna dla wszystkich siatek
String^ kategoria="";
String^ nazwa_podmiotu="";
// koniec deklaracji zmiennych
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: Void wyczysc(Control^ kontrolki){
for each (Control^ pole in kontrolki->Controls)
{
if (pole->GetType() == TextBox::typeid){ //jezeli kontrolka jest text boxem
pole->Text = "";
}
else if (pole->GetType() == ComboBox::typeid){ //jezeli kontrolka jest typu combo box
pole->Text = "";
}
else if (pole->GetType() == RichTextBox::typeid){
pole->Text = "";
}
}
}
// symygy_service.
private: Void wczytanie_serwisantow(){
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ zapytanie = gcnew MySqlCommand("SELECT CONCAT(imie, ' ' ,nazwisko) AS imie_nazwisko FROM symygy_service.uzytkownik;", laczBaze); // laczymy dane dwoch kolumn w jedna o nazwie: imie_nazwisko
// Wczytywanie do combo boxa Urzadzenia:Wlasciel zapisanych nazw podmiotow
MySqlDataReader^ dane;
try{
laczBaze->Open();
dane = zapytanie->ExecuteReader();
int i = 0;
cbUSerwisant->Items->Clear(); // czysci listę
while (dane->Read()){
cbUSerwisant->Items->Add(dane->GetString("imie_nazwisko"));
}
laczBaze->Close();
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
}
}
private: Void pokaz_siatke(){
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ zapytanie = gcnew MySqlCommand("SELECT * FROM symygy_service.urzadzenie ORDER BY nazwa;", laczBaze);
try {
MySqlDataAdapter^ moja = gcnew MySqlDataAdapter(); //interfejs pomiedzy baza a danumi
moja->SelectCommand = zapytanie;
DataTable^ tabela = gcnew DataTable(); //tworzymy tabele
moja->Fill(tabela); // wypelniamy tabele
BindingSource^ zrodlo = gcnew BindingSource(); //podlaczamy zrodlo danych
zrodlo->DataSource = tabela; //jako zrodlo danych ustawiamy tabele
dgUrzadzenia->DataSource = zrodlo; // w nasza siatke wczytujemy tabele z danymi
laczBaze->Close(); //zamykanie polaczenia z baza
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
}
}
private: Void pokaz_siatke_uzytkownicy(){
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ zapytanie = gcnew MySqlCommand("SELECT * FROM symygy_service.uzytkownik ORDER BY imie;", laczBaze);
try {
MySqlDataAdapter^ moja = gcnew MySqlDataAdapter(); //interfejs pomiedzy baza a danumi
moja->SelectCommand = zapytanie;
DataTable^ tabela = gcnew DataTable(); //tworzymy tabele
moja->Fill(tabela); // wypelniamy tabele
BindingSource^ zrodlo = gcnew BindingSource(); //podlaczamy zrodlo danych
zrodlo->DataSource = tabela; //jako zrodlo danych ustawiamy tabele
dgUstawienia->DataSource = zrodlo; // w nasza siatke wczytujemy tabele z danymi
laczBaze->Close(); //zamykanie polaczenia z baza
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
}
}
private: System::Void btnUSzukaj_Click(System::Object^ sender, System::EventArgs^ e) {
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja); //polaczenie zbaza
MySqlCommand^ zapytanie = gcnew MySqlCommand("SELECT * FROM symygy_service.urzadzenie WHERE CONCAT(nazwa, ' ', nr_seryjny, wlasciciel, kategoria, serwisant) LIKE '%" + tbUSzukaj->Text + "%' ORDER BY nazwa;", laczBaze);
try{
MySqlDataAdapter^ moja = gcnew MySqlDataAdapter(); //interfejs miedzy danymi a baza
moja->SelectCommand = zapytanie;
DataTable^tabela = gcnew DataTable();
moja->Fill(tabela);
BindingSource^ zrodlo = gcnew BindingSource(); // podlaczamy zrodlo
zrodlo->DataSource = tabela;
dgUrzadzenia->DataSource = zrodlo;
laczBaze->Close();
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
}
dgUrzadzenia->Columns[0]->Visible = false; // uktywamy urzadzenie id
}
private: System::Void dgUrzadzenia_CellClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
if (e->RowIndex >= 0){
id_rekordu = Convert::ToInt32(dgUrzadzenia->Rows[e->RowIndex]->Cells["urzadzenie_id"]->Value);
tbUNazwa->Text = dgUrzadzenia->Rows[e->RowIndex]->Cells["nazwa"]->Value->ToString();
tbUSeryjny->Text = dgUrzadzenia->Rows[e->RowIndex]->Cells["nr_seryjny"]->Value->ToString();
tbUWlasciciel->Text = dgUrzadzenia->Rows[e->RowIndex]->Cells["wlasciciel"]->Value->ToString();
cbUTyp->Text = dgUrzadzenia->Rows[e->RowIndex]->Cells["typ"]->Value->ToString();
cbUSerwisant->Text = dgUrzadzenia->Rows[e->RowIndex]->Cells["serwisant"]->Value->ToString();
rtbUOpis->Text = dgUrzadzenia->Rows[e->RowIndex]->Cells["opis"]->Value->ToString();
kategoria = dgUrzadzenia->Rows[e->RowIndex]->Cells["kategoria"]->Value->ToString();
if (kategoria == "naprawa") rbUNaprawa->Checked = true;
if (kategoria == "przegląd") rbUPrzeglad->Checked = true;
if (kategoria == "usługa") rbUusluga->Checked = true;
btnUModyfikuj->Enabled = true;
btnUUsun->Enabled = true;
}
}
private: System::Void btnUDodaj_Click(System::Object^ sender, System::EventArgs^ e) {
// dodawanie urzadzen do bazy
if (tbUNazwa->Text->Length < 3 || tbUSeryjny->Text->Length < 3 || tbUWlasciciel->Text->Length < 3 || cbUTyp->Text->Length < 3 || cbUSerwisant->Text->Length < 3){
MessageBox::Show("Uzupełnij brakujące dane !");
}
else{
MessageBox::Show("Urządzenie dodane pomyślnie");
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ polecenie = laczBaze->CreateCommand();
MySqlTransaction^ transakcja;
laczBaze->Open();
transakcja = laczBaze->BeginTransaction(IsolationLevel::ReadCommitted);
polecenie->Connection = laczBaze;
polecenie->Transaction = transakcja;
if (rbUNaprawa->Checked == true) kategoria = "naprawa";
if (rbUPrzeglad->Checked == true) kategoria = "przegląd";
if (rbUusluga->Checked == true) kategoria = "usługa";
try{
polecenie->CommandText = "INSERT INTO symygy_service.urzadzenie SET nazwa='" + tbUNazwa->Text + "', nr_seryjny='" + tbUSeryjny->Text + "', wlasciciel='" + tbUWlasciciel->Text + "',typ='" + cbUTyp->Text + "',serwisant='" + cbUSerwisant->Text + "', kategoria='" + kategoria + "', opis='"+rtbUOpis->Text+"' ";
polecenie->ExecuteNonQuery();
transakcja->Commit();
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
transakcja->Rollback();
}
laczBaze->Close();
}
wyczysc(groupBox3);
wyczysc(groupBox4);
pokaz_siatke();
}
private: System::Void tabControl1_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if (tabControl1->SelectedTab->TabIndex == 3) this->Close();
//if (tabControl1->SelectedTab->TabIndex == 4){
//}
/*logowanie^ loguj = gcnew logowanie();
MyForm^ serwis = gcnew MyForm();
serwis->Hide();
loguj->Show();
}*/
}
private: System::Void btnUUsun_Click(System::Object^ sender, System::EventArgs^ e) {
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ polecenie = laczBaze->CreateCommand();
MySqlTransaction^ transakcja;
laczBaze->Open();
transakcja = laczBaze->BeginTransaction(IsolationLevel::ReadCommitted);
polecenie->Connection = laczBaze;
polecenie->Transaction = transakcja;
try{
if (MessageBox::Show("Czy na pewno chcesz usunąć wybrane urządzenie?", "UWAGA!!!", MessageBoxButtons::YesNo, MessageBoxIcon::Warning) == System::Windows::Forms::DialogResult::Yes){
polecenie->CommandText = "DELETE FROM symygy_service.urzadzenie WHERE urzadzenie_id=" + id_rekordu + ";";
polecenie->ExecuteNonQuery();
transakcja->Commit(); // rozpoczecie transakcji mysql
MessageBox::Show("Urządzenie zostało usunięte");
}
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
transakcja->Rollback(); //cofanie transakcji
}
laczBaze->Close();
wyczysc(groupBox3);
wyczysc(groupBox4); //czyszczenie zawartosci pol
pokaz_siatke(); //Refresh tabeli
}
private: System::Void btnUModyfikuj_Click(System::Object^ sender, System::EventArgs^ e) {
if (tbUNazwa->Text->Length < 3 || tbUSeryjny->Text->Length < 3 || tbUWlasciciel->Text->Length < 3 || cbUTyp->Text->Length < 3 || cbUSerwisant->Text->Length < 3){
MessageBox::Show("Uzupełnij brakujące dane !");
}
else{
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ polecenie = laczBaze->CreateCommand();
MySqlTransaction^ transakcja;
laczBaze->Open();
transakcja = laczBaze->BeginTransaction(IsolationLevel::ReadCommitted); //odczyt zatwierdzonych danych
polecenie->Connection = laczBaze;
polecenie->Transaction = transakcja;
if (rbUNaprawa->Checked == true) kategoria = "naprawa";
if (rbUPrzeglad->Checked == true) kategoria = "przegląd";
if (rbUusluga->Checked == true) kategoria = "usługa";
try{
polecenie->CommandText = "UPDATE symygy_service.urzadzenie SET nazwa='" + tbUNazwa->Text + "', nr_seryjny='" + tbUSeryjny->Text + "', wlasciciel='"+ tbUWlasciciel->Text +"',typ='" + cbUTyp->Text + "',serwisant='" + cbUSerwisant->Text + "', kategoria='" + kategoria + "', opis='"+rtbUOpis->Text+"' WHERE urzadzenie_id="+id_rekordu+" ";
polecenie->ExecuteNonQuery();
transakcja->Commit(); // rozpoczecie transakcji mysql
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
transakcja->Rollback(); //cofanie transakcji
}
laczBaze->Close();
}
pokaz_siatke();
}
private: System::Void btnPSzukaj_Click(System::Object^ sender, System::EventArgs^ e) {
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja); //polaczenie zbaza
MySqlCommand^ zapytanie = gcnew MySqlCommand("SELECT * FROM symygy_service.podmiot WHERE CONCAT(nazwa, ' ', miasto, ulica) LIKE '%" +tbPSzukaj->Text + "%' ORDER BY nazwa;", laczBaze);
try{
MySqlDataAdapter^ moja = gcnew MySqlDataAdapter(); //interfejs miedzy danymi a baza
moja->SelectCommand = zapytanie;
DataTable^tabela = gcnew DataTable();
moja->Fill(tabela);
BindingSource^ zrodlo = gcnew BindingSource(); // podlaczamy zrodlo
zrodlo->DataSource = tabela;
dgPodmioty->DataSource = zrodlo;
laczBaze->Close();
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
}
dgPodmioty->Columns[0]->Visible = false; // uktywamy podmiot id
}
private: System::Void dgPodmioty_CellClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
if (e->RowIndex >= 0){
id_rekordu = Convert::ToInt32(dgPodmioty->Rows[e->RowIndex]->Cells["podmiot_id"]->Value);
tbPNazwa->Text = dgPodmioty->Rows[e->RowIndex]->Cells["nazwa"]->Value->ToString();
tbPUlica->Text = dgPodmioty->Rows[e->RowIndex]->Cells["ulica"]->Value->ToString();
tbPKod->Text = dgPodmioty->Rows[e->RowIndex]->Cells["kod_pocztowy"]->Value->ToString();
tbPMiasto->Text = dgPodmioty->Rows[e->RowIndex]->Cells["miasto"]->Value->ToString();
rtbPOpis->Text = dgPodmioty->Rows[e->RowIndex]->Cells["opis"]->Value->ToString();
btnPModyfikuj->Enabled = true;
btnPUsun->Enabled = true;
nazwa_podmiotu = tbPNazwa->Text;
}
}
private: void pokaz_podmiot(){
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja); //polaczenie zbaza
MySqlCommand^ zapytanie = gcnew MySqlCommand("SELECT * FROM symygy_service.podmiot ORDER BY nazwa;", laczBaze);
try{
MySqlDataAdapter^ moja = gcnew MySqlDataAdapter(); //interfejs miedzy danymi a baza
moja->SelectCommand = zapytanie;
DataTable^tabela = gcnew DataTable();
moja->Fill(tabela);
BindingSource^ zrodlo = gcnew BindingSource(); // podlaczamy zrodlo
zrodlo->DataSource = tabela;
dgPodmioty->DataSource = zrodlo;
laczBaze->Close();
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
}
dgPodmioty->Columns[0]->Visible = false; // uktywamy podmiot id
}
private: System::Void btnPDodaj_Click(System::Object^ sender, System::EventArgs^ e) {
if (tbPNazwa->Text->Length < 3 || tbPMiasto->Text->Length < 3 || tbPKod->Text->Length < 3 || tbPUlica->Text->Length < 3){
MessageBox::Show("Uzupełnij brakujące dane !");
}
else{
MessageBox::Show("Urządzenie dodane pomyślnie");
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ polecenie = laczBaze->CreateCommand();
MySqlTransaction^ transakcja;
laczBaze->Open();
transakcja = laczBaze->BeginTransaction(IsolationLevel::ReadCommitted);
polecenie->Connection = laczBaze;
polecenie->Transaction = transakcja;
try{
polecenie->CommandText = "INSERT INTO symygy_service.podmiot SET nazwa='" + tbPNazwa->Text + "', miasto='" + tbPMiasto->Text + "', ulica='" + tbPUlica->Text + "',kod_pocztowy='" + tbPKod->Text + "', opis='" + rtbPOpis->Text + "' ";
polecenie->ExecuteNonQuery();
transakcja->Commit();
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
transakcja->Rollback();
}
laczBaze->Close();
wyczysc(groupBox6);
wyczysc(groupBox7);
}
pokaz_podmiot();
}
private: System::Void btnPModyfikuj_Click(System::Object^ sender, System::EventArgs^ e) {
if (tbPNazwa->Text->Length < 3 || tbPMiasto->Text->Length < 3 || tbPKod->Text->Length < 3 || tbPUlica->Text->Length < 3){
MessageBox::Show("Uzupełnij brakujące dane !");
}
else{
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ polecenie = laczBaze->CreateCommand();
MySqlTransaction^ transakcja;
laczBaze->Open();
transakcja = laczBaze->BeginTransaction(IsolationLevel::ReadCommitted); //odczyt zatwierdzonych danych
polecenie->Connection = laczBaze;
polecenie->Transaction = transakcja;
try{
polecenie->CommandText = "UPDATE symygy_service.podmiot SET nazwa='" + tbPNazwa->Text + "', miasto='" + tbPMiasto->Text + "', ulica='" + tbPUlica->Text + "',kod_pocztowy='" + tbPKod->Text + "', opis='" + rtbPOpis->Text + "' WHERE podmiot_id='" + id_rekordu + "' ";
polecenie->ExecuteNonQuery();
transakcja->Commit(); // rozpoczecie transakcji mysql
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
transakcja->Rollback(); //cofanie transakcji
}
laczBaze->Close();
}
pokaz_podmiot();
}
private: System::Void btnPUsun_Click(System::Object^ sender, System::EventArgs^ e) {
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ polecenie = laczBaze->CreateCommand();
MySqlTransaction^ transakcja;
laczBaze->Open();
transakcja = laczBaze->BeginTransaction(IsolationLevel::ReadCommitted);
polecenie->Connection = laczBaze;
polecenie->Transaction = transakcja;
try{
if (MessageBox::Show("Czy na pewno chcesz usunąć wybrany podmioit?", "UWAGA!!!", MessageBoxButtons::YesNo, MessageBoxIcon::Warning) == System::Windows::Forms::DialogResult::Yes){
polecenie->CommandText = "DELETE FROM symygy_service.podmiot WHERE podmiot_id=" + id_rekordu + ";";
polecenie->ExecuteNonQuery();
transakcja->Commit(); // rozpoczecie transakcji mysql
MessageBox::Show("Podmiot został usunięty");
}
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
transakcja->Rollback(); //cofanie transakcji
}
laczBaze->Close();
wyczysc(groupBox6);
wyczysc(groupBox7); //czyszczenie zawartosci pol
pokaz_podmiot(); //Refresh tabeli
}
private: System::Void btnUWybierz_Click(System::Object^ sender, System::EventArgs^ e) {
tabControl1->SelectedTab = tabPage3;
pokaz_podmiot();
}
private: System::Void btnPPrzypisz_Click(System::Object^ sender, System::EventArgs^ e) {
try{
tbUWlasciciel->Text = tbPNazwa->Text;
tabControl1->SelectedTab = tabPage2;
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
//MessageBox::Show("Poprawnie przypisano podmiot do urządzenia.", "Ostrzeżenie", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
}
private: System::Void btnUstSzukaj_Click(System::Object^ sender, System::EventArgs^ e) {
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja); //polaczenie zbaza
MySqlCommand^ zapytanie = gcnew MySqlCommand("SELECT * FROM symygy_service.uzytkownik WHERE CONCAT(login, imie,' ',nazwisko) LIKE '%" + tbUstSzukaj->Text + "%' ORDER BY login;", laczBaze);
try{
MySqlDataAdapter^ moja = gcnew MySqlDataAdapter(); //interfejs miedzy danymi a baza
moja->SelectCommand = zapytanie;
DataTable^tabela = gcnew DataTable();
moja->Fill(tabela);
BindingSource^ zrodlo = gcnew BindingSource(); // podlaczamy zrodlo
zrodlo->DataSource = tabela;
dgUstawienia->DataSource = zrodlo;
laczBaze->Close();
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
}
dgUstawienia->Columns[0]->Visible = false; // uktywamy uzytkownik id
dgUstawienia->Columns[4]->Visible = false;
}
private: System::Void dgUstawienia_CellClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
if (e->RowIndex >= 0){
id_rekordu = Convert::ToInt32(dgUstawienia->Rows[e->RowIndex]->Cells["uzytkownik_id"]->Value);
tbUstImie->Text = dgUstawienia->Rows[e->RowIndex]->Cells["imie"]->Value->ToString();
tbUstNazwisko->Text = dgUstawienia->Rows[e->RowIndex]->Cells["nazwisko"]->Value->ToString();
tbUstLogin->Text = dgUstawienia->Rows[e->RowIndex]->Cells["login"]->Value->ToString();
btnUstModyfikuj->Enabled = true;
if (id_uzytkownika == 1){
btnUstUsun->Enabled = true;
}
else btnUstUsun->Enabled = false;
}
}
private: Void modyfikuj_pokaz(){ //pokazuje lub ukrywa przycisk Modyfikuj w zaleznosci od warunkow:
if ((tbUstStareH->Text != "") && (tbUstNoweH->Text != "") && (tbUstNoweH->Text == tbUstPowtorzH->Text)){
btnUstModyfikuj->Enabled = true;
}
else{
btnUstModyfikuj->Enabled = false;
}
}
private: System::Void btnUstModyfikuj_Click(System::Object^ sender, System::EventArgs^ e) {
// zamiana hasla
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ zapytanie = gcnew MySqlCommand("UPDATE symygy_service.uzytkownik SET haslo = PASSWORD('" + tbUstNoweH->Text + "') WHERE uzytkownik_id = " + id_rekordu + " AND haslo = PASSWORD('" + tbUstStareH->Text + "');", laczBaze);
try {
laczBaze->Open();
if (zapytanie->ExecuteNonQuery()){
MessageBox::Show("Zmiana hasła zakończona pomyślnie");
}
else{
MessageBox::Show("Podanie hasło jest niepoprawne");
}
laczBaze->Close(); //zawsze zamykamy baze
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
}
}
private: System::Void tbUstNoweH_TextChanged(System::Object^ sender, System::EventArgs^ e) {
modyfikuj_pokaz();
}
private: System::Void tbUstPowtorzH_TextChanged(System::Object^ sender, System::EventArgs^ e) {
modyfikuj_pokaz();
}
private: System::Void tbUstStareH_TextChanged(System::Object^ sender, System::EventArgs^ e) {
modyfikuj_pokaz();
}
private: System::Void btnUstDodaj_Click(System::Object^ sender, System::EventArgs^ e) {
//dodawanie uzytkownikow do bazy
if (tbUstImie->Text->Length < 3 || tbUstNazwisko->Text->Length < 3 || tbUstLogin->Text->Length <= 4 || tbUstStareH->Text->Length <= 3){
MessageBox::Show("Uzupełnij dane !");
}
else{
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ polecenie = laczBaze->CreateCommand();
MySqlTransaction^ transakcja;
laczBaze->Open();
transakcja = laczBaze->BeginTransaction(IsolationLevel::ReadCommitted);
polecenie->Connection = laczBaze;
polecenie->Transaction = transakcja;
try{
polecenie->CommandText = "INSERT INTO symygy_service.uzytkownik SET imie='" + tbUstImie->Text + "', nazwisko='" + tbUstNazwisko->Text + "', login='" + tbUstLogin->Text + "', haslo=PASSWORD('" + tbUstStareH->Text + "');";
polecenie->ExecuteNonQuery();
MessageBox::Show("Użytkownik został dodany do bazy danych.");
transakcja->Commit();
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
transakcja->Rollback();
}
laczBaze->Close();
}
pokaz_siatke_uzytkownicy();
wczytanie_serwisantow();
}
private: System::Void btnUstUsun_Click(System::Object^ sender, System::EventArgs^ e) {
if (id_rekordu == 1){
MessageBox::Show("Nie można usunąć administratora!");
}
else{
//if (tbUstStareH!=)
MySqlConnection^ laczBaze = gcnew MySqlConnection(konfiguracja);
MySqlCommand^ polecenie = laczBaze->CreateCommand();
MySqlTransaction^ transakcja;
laczBaze->Open();
transakcja = laczBaze->BeginTransaction(IsolationLevel::ReadCommitted);
polecenie->Connection = laczBaze;
polecenie->Transaction = transakcja;
try{
if (MessageBox::Show("Czy na pewno chcesz usunąć wybranego użytkownika?", "UWAGA!!!", MessageBoxButtons::YesNo, MessageBoxIcon::Warning) == System::Windows::Forms::DialogResult::Yes){
polecenie->CommandText = "DELETE FROM symygy_service.uzytkownik WHERE uzytkownik_id=" + id_rekordu + ";";
polecenie->ExecuteNonQuery(); // najpierw usuwamy z godziny bo to jest pochodna tabeli uzytkownik wiec na odwrot sie nie da
transakcja->Commit(); // rozpoczecie transakcji mysql
MessageBox::Show("Użytkownik został usunięty");
}
}
catch (Exception^ komunikat){
MessageBox::Show(komunikat->Message);
transakcja->Rollback(); //cofanie transakcji
}
laczBaze->Close();
}
wyczysc(groupBox8);
pokaz_siatke_uzytkownicy();
wczytanie_serwisantow();
}
};
}
|
20695fc2df36670c992cd34070e190f4e2ca9ea7 | 320194b0d3dc7a9652cf180aad2d25eec764271c | /Two Knights/main.cpp | 1f8d53f21bc9daed10acf71c38d40a2128aea99f | [] | no_license | ZeynepDilanKilic/CSES | d890ba70539ac97019d6e7f2c940bd4ac789c78b | 0996d8a970116ba5d3bd632709cdac581059dd04 | refs/heads/main | 2023-07-09T14:15:43.321404 | 2021-08-22T14:57:46 | 2021-08-22T14:57:46 | 388,906,283 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 284 | cpp | main.cpp | #include <iostream>
#define ll long long
using namespace std;
int main()
{
int n;
cin >> n;
for(int i = 1; i <=n; i++){
ll x1 = i*i, x2 = x1*(x1-1)/2;
if(i > 2)
x2 -= 4*(i - 1)* (i - 2);
cout << x2 << endl;
}
return 0;
}
|
d6899e0dd9adafd80f495cb72dd42e2eee5d6464 | 3b117ea09d3c8eacc484924e505debe79db856ea | /Asteroide.h | fb247c42d4a191dccc2e5137927412441b237341 | [] | no_license | nikoclass/t-asteroids | b274b02b13b2f36bf0ee6ab50f3f781673211b40 | 13adaf839214a0977661d79dc7486dc92a678702 | refs/heads/master | 2023-02-22T06:59:26.805910 | 2021-01-20T22:02:33 | 2021-01-20T22:02:33 | 331,443,853 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,519 | h | Asteroide.h | #ifndef ASTEROIDE_H_
#define ASTEROIDE_H_
#include "Engine.h"
#include "Esfera.h"
#include "Settings.h"
#include "Matematicas.h"
#include "Colisionable.h"
#include "Matriz4x4.h"
#include "ModoJuego.h"
class ModoJuego;
#include "BalaComun.h"
class BalaComun;
#include "Nave.h"
class Nave;
#include "Misil.h"
class Misil;
#include "Poder.h"
class Poder;
#include "BolaExplosiva.h"
#include "Explosion.h"
#include "Espiral.h"
#include "ServidorRed.h"
#include "Targeteable.h"
class Asteroide:public Colisionable, public ServidorRed, public Targeteable {
private:
int id;
float nivel;
float vida;
Vector velocidad;
Vector velocidadAngular;
float masa;
bool ya_choco;
float dt;
float maxVel; // lo seteo en el trasladar
public:
Asteroide(int id, float nivel,Objeto3d*modelo,Vector posicion);
virtual ~Asteroide();
void setPosicionTarget(Vector v){Colisionable::posicionar(v);}
Vector getPosicionTarget(){return Colisionable::getPosicion();}
float getNivel(){return nivel;}
void setModeloAsteroide(Objeto3d*);
void setVelocidad(Vector vel);
void setVelocidadAngular(Vector vel);
Vector getVelocidad();
Vector getVelocidadAngular();
float getMasa();
//colisionable
void tic(float dt);
void bang(Colisionable*);
float getDanio();
void setVida(float v);
float getVida();
void setVidaTarget(float v){setVida(v);}
float getVidaTarget(){return getVida();}
void recibirPaqueteServidor(PaqueteRed *paquete);
string getNombreServidor();
};
#endif /*ASTEROIDE_H_*/
|
6a12ddce0e5df832e2912cebb4c1bb6eb34315fc | 42dd71e4411bbfcac27d63f8cdee8869bbaf1fbc | /last year string.cpp | 68a8fc2d960eb9ac56b0f942c457e1ba945a980e | [] | no_license | montygupta32/Codeforces-Questions | 43af52b6f145457f2000b58de756acb629961704 | 85dbb3dd98b0e602fe850a191322209021710937 | refs/heads/master | 2023-07-15T04:34:31.354174 | 2021-08-14T00:41:46 | 2021-08-14T00:41:46 | 395,841,634 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 555 | cpp | last year string.cpp | #include<bits/stdc++.h>
using namespace std;
int main(){
int tc;
cin>>tc;
while(tc--){
int n;
cin>>n;
string s;
cin>>s;
int fact =0;
for(int i=0; i<=4; i++){
string str1 = s.substr(0,i);
string str2 = s.substr(n-4+i);
string result = str1 + str2;
if(result == "2020"){
fact=1;
break;
}
}
if(fact==1)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.