Upload folder using huggingface_hub (part 103)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard009/C++/0109950_toolboxcontroller.cpp +102 -0
- pool/shard009/C++/0109952_analyzer_tester.cc +88 -0
- pool/shard009/C++/0109956_Rectangle.cpp +64 -0
- pool/shard009/C++/0109958_FreeLink.cc +103 -0
- pool/shard009/C++/0109959_cryptauth_device_id_provider_impl.cc +44 -0
- pool/shard009/C++/0109960_slot1comp_mc.cpp +43 -0
- pool/shard009/C++/0109965_page_launcher_api.cc +39 -0
- pool/shard009/C++/0109967_3955491.cpp +80 -0
- pool/shard009/C++/0109969_GxsChannelUserNotify.cpp +51 -0
- pool/shard009/C++/0109970_SVGAngleInterpolationType.cpp +34 -0
- pool/shard009/C++/0109972_group_cipher_delegate.cpp +118 -0
- pool/shard009/C++/0109973_class1.cpp +30 -0
- pool/shard009/C++/0109975_CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84a.cpp +95 -0
- pool/shard009/C++/0109977_rounding.cpp +95 -0
- pool/shard009/C++/0109982_pointer_partial_void.cc +69 -0
- pool/shard009/C++/0109985_sample_attach.cc +243 -0
- pool/shard009/C++/0109986_QXmppInvokable.cpp +129 -0
- pool/shard009/C++/0109988_ckeyboardeventstranslator.cpp +189 -0
- pool/shard009/C++/0109996_CCTiledLayerTestCommon.cpp +145 -0
- pool/shard009/C++/0110000_Blob.cpp +208 -0
- pool/shard009/C++/0110004_cv_api.cc +172 -0
- pool/shard009/C++/0110005_gesture_point.cc +199 -0
- pool/shard009/C++/0110006_searchMatrix.cc +96 -0
- pool/shard009/C++/0110014_basic_string.cpp +127 -0
- pool/shard009/C++/0110021_BinaryTreePreorderTraversal.cc +31 -0
- pool/shard009/C++/0110022_BoostUtilities.cpp +170 -0
- pool/shard009/C++/0110026_h264_poc.cc +231 -0
- pool/shard009/C++/0110028_brake.cpp +27 -0
- pool/shard009/C++/0110036_protocol-parameter.cpp +230 -0
- pool/shard009/C++/0110038_AttributeList.cpp +229 -0
- pool/shard009/C++/0110046_rmsprop_op.cc +175 -0
- pool/shard009/C++/0110047_ClawHumanView.cpp +133 -0
- pool/shard009/C++/0110051_propitem.cpp +64 -0
- pool/shard009/C++/0110052_test_memory_pool.cpp +178 -0
- pool/shard009/C++/0110054_moveable2.cc +102 -0
- pool/shard009/C++/0110056_lambdaCaptureReference.cpp +28 -0
- pool/shard009/C++/0110060_drvkillu.cpp +214 -0
- pool/shard009/C++/0110061_test_api_observer_registry.cc +60 -0
- pool/shard009/C++/0110064_main.cpp +51 -0
- pool/shard009/C++/0110065_SampleRooFitMgr.cc +109 -0
- pool/shard009/C++/0110078_guide_algorithm_lowpass.cpp +294 -0
- pool/shard009/C++/0110079_MetadataParser.cpp +36 -0
- pool/shard009/C++/0110086_TestThriftCpp.cpp +62 -0
- pool/shard009/C++/0110087_PrefixLevelStorageMetrics.cpp +82 -0
- pool/shard009/C++/0110088_array.cpp +78 -0
- pool/shard009/C++/0110089_HarvbotStepper.cpp +214 -0
- pool/shard009/C++/0110095_if_tests.cpp +250 -0
- pool/shard009/C++/0110098_hotkeys.cpp +111 -0
- pool/shard009/C++/0110100_vfsStream.cpp +74 -0
- pool/shard009/C++/0110101_cell_contains.cpp +54 -0
pool/shard009/C++/0109950_toolboxcontroller.cpp
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* niepce - darkroom/toolboxcontroller.cpp
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2008-2014 Hubert Figuiere
|
| 5 |
+
*
|
| 6 |
+
* This program is free software: you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License as published by
|
| 8 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
* (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* This program is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <glibmm/i18n.h>
|
| 21 |
+
|
| 22 |
+
#include <gtkmm/box.h>
|
| 23 |
+
#include <gtkmm/scale.h>
|
| 24 |
+
#include <gtkmm/adjustment.h>
|
| 25 |
+
|
| 26 |
+
#include "toolboxcontroller.hpp"
|
| 27 |
+
#include "fwk/base/debug.hpp"
|
| 28 |
+
#include "fwk/toolkit/widgets/editablehscale.hpp"
|
| 29 |
+
#include "dritemwidget.hpp"
|
| 30 |
+
|
| 31 |
+
#ifndef DATADIR
|
| 32 |
+
#error DATADIR is not defined
|
| 33 |
+
#endif
|
| 34 |
+
|
| 35 |
+
namespace dr {
|
| 36 |
+
|
| 37 |
+
ToolboxController::ToolboxController()
|
| 38 |
+
: Dockable("tools", _("Develop"), "apply") // FIXME there is no equivalent it seems.
|
| 39 |
+
{
|
| 40 |
+
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
Gtk::Widget *
|
| 44 |
+
ToolboxController::buildWidget()
|
| 45 |
+
{
|
| 46 |
+
if(m_widget) {
|
| 47 |
+
return m_widget;
|
| 48 |
+
}
|
| 49 |
+
DrItemWidget *item = nullptr;
|
| 50 |
+
fwk::EditableHScale *s = nullptr;
|
| 51 |
+
|
| 52 |
+
Gtk::Box *toolbox = Dockable::build_vbox();
|
| 53 |
+
m_widget = toolbox;
|
| 54 |
+
DBG_ASSERT(toolbox, "vbox not found.");
|
| 55 |
+
|
| 56 |
+
item = manage(new DrItemWidget(_("Crop")));
|
| 57 |
+
toolbox->pack_start(*item, Gtk::PACK_SHRINK);
|
| 58 |
+
s = Gtk::manage(new fwk::EditableHScale("/org/gnome/Niepce/pixmaps/niepce-transform-rotate.png",
|
| 59 |
+
-45.0, 45.0, 0.5));
|
| 60 |
+
item->add_widget(_("Tilt"), *s);
|
| 61 |
+
|
| 62 |
+
item = manage(new DrItemWidget(_("White balance")));
|
| 63 |
+
toolbox->pack_start(*item, Gtk::PACK_SHRINK);
|
| 64 |
+
s = Gtk::manage(new fwk::EditableHScale(0.0, 100.0, 1.0));
|
| 65 |
+
item->add_widget(_("Color temperature"), *s);
|
| 66 |
+
|
| 67 |
+
item = manage(new DrItemWidget(_("Tone and colour")));
|
| 68 |
+
toolbox->pack_start(*item, Gtk::PACK_SHRINK);
|
| 69 |
+
s = Gtk::manage(new fwk::EditableHScale(-5.0, 5.0, 0.1));
|
| 70 |
+
// s->signal_value_changed().connect();
|
| 71 |
+
item->add_widget(_("Exposure"), *s);
|
| 72 |
+
s = Gtk::manage(new fwk::EditableHScale(0, 100, 1));
|
| 73 |
+
item->add_widget(_("Recovery"), *s);
|
| 74 |
+
s = Gtk::manage(new fwk::EditableHScale(0, 100, 1));
|
| 75 |
+
item->add_widget(_("Fill Light"), *s);
|
| 76 |
+
s = Gtk::manage(new fwk::EditableHScale(0, 100, 1));
|
| 77 |
+
item->add_widget(_("Blacks"), *s);
|
| 78 |
+
s = Gtk::manage(new fwk::EditableHScale(-100, 100, 1));
|
| 79 |
+
item->add_widget(_("Brightness"), *s);
|
| 80 |
+
s = Gtk::manage(new fwk::EditableHScale(-100, 100, 1));
|
| 81 |
+
item->add_widget(_("Contrast"), *s);
|
| 82 |
+
s = Gtk::manage(new fwk::EditableHScale(-100, 100, 1));
|
| 83 |
+
item->add_widget(_("Saturation"), *s);
|
| 84 |
+
s = Gtk::manage(new fwk::EditableHScale(-100, 100, 1));
|
| 85 |
+
item->add_widget(_("Vibrance"), *s);
|
| 86 |
+
|
| 87 |
+
return m_widget;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
/*
|
| 95 |
+
Local Variables:
|
| 96 |
+
mode:c++
|
| 97 |
+
c-file-style:"stroustrup"
|
| 98 |
+
c-file-offsets:((innamespace . 0))
|
| 99 |
+
indent-tabs-mode:nil
|
| 100 |
+
fill-column:80
|
| 101 |
+
End:
|
| 102 |
+
*/
|
pool/shard009/C++/0109952_analyzer_tester.cc
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#include "paddle/fluid/inference/analysis/analyzer.h"
|
| 16 |
+
|
| 17 |
+
#include <google/protobuf/text_format.h>
|
| 18 |
+
#include <gtest/gtest.h>
|
| 19 |
+
#include "paddle/fluid/inference/analysis/ut_helper.h"
|
| 20 |
+
#include "paddle/fluid/inference/api/paddle_inference_api.h"
|
| 21 |
+
#include "paddle/fluid/inference/api/paddle_inference_pass.h"
|
| 22 |
+
|
| 23 |
+
namespace paddle {
|
| 24 |
+
namespace inference {
|
| 25 |
+
namespace analysis {
|
| 26 |
+
|
| 27 |
+
using namespace framework; // NOLINT
|
| 28 |
+
|
| 29 |
+
TEST(Analyzer, analysis_without_tensorrt) {
|
| 30 |
+
FLAGS_IA_enable_tensorrt_subgraph_engine = false;
|
| 31 |
+
Argument argument;
|
| 32 |
+
argument.fluid_model_dir.reset(new std::string(FLAGS_inference_model_dir));
|
| 33 |
+
Analyzer analyser;
|
| 34 |
+
analyser.Run(&argument);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
TEST(Analyzer, analysis_with_tensorrt) {
|
| 38 |
+
FLAGS_IA_enable_tensorrt_subgraph_engine = true;
|
| 39 |
+
Argument argument;
|
| 40 |
+
argument.fluid_model_dir.reset(new std::string(FLAGS_inference_model_dir));
|
| 41 |
+
Analyzer analyser;
|
| 42 |
+
analyser.Run(&argument);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void TestWord2vecPrediction(const std::string &model_path) {
|
| 46 |
+
NativeConfig config;
|
| 47 |
+
config.model_dir = model_path;
|
| 48 |
+
config.use_gpu = false;
|
| 49 |
+
config.device = 0;
|
| 50 |
+
auto predictor =
|
| 51 |
+
::paddle::CreatePaddlePredictor<NativeConfig, PaddleEngineKind::kNative>(
|
| 52 |
+
config);
|
| 53 |
+
|
| 54 |
+
// One single batch
|
| 55 |
+
|
| 56 |
+
int64_t data[4] = {1, 2, 3, 4};
|
| 57 |
+
PaddleTensor tensor;
|
| 58 |
+
tensor.shape = std::vector<int>({4, 1});
|
| 59 |
+
tensor.data = PaddleBuf(data, sizeof(data));
|
| 60 |
+
tensor.dtype = PaddleDType::INT64;
|
| 61 |
+
|
| 62 |
+
// For simplicity, we set all the slots with the same data.
|
| 63 |
+
std::vector<PaddleTensor> slots(4, tensor);
|
| 64 |
+
std::vector<PaddleTensor> outputs;
|
| 65 |
+
CHECK(predictor->Run(slots, &outputs));
|
| 66 |
+
|
| 67 |
+
PADDLE_ENFORCE(outputs.size(), 1UL);
|
| 68 |
+
// Check the output buffer size and result of each tid.
|
| 69 |
+
PADDLE_ENFORCE(outputs.front().data.length(), 33168UL);
|
| 70 |
+
float result[5] = {0.00129761, 0.00151112, 0.000423564, 0.00108815,
|
| 71 |
+
0.000932706};
|
| 72 |
+
const size_t num_elements = outputs.front().data.length() / sizeof(float);
|
| 73 |
+
// The outputs' buffers are in CPU memory.
|
| 74 |
+
for (size_t i = 0; i < std::min(5UL, num_elements); i++) {
|
| 75 |
+
LOG(INFO) << "data: "
|
| 76 |
+
<< static_cast<float *>(outputs.front().data.data())[i];
|
| 77 |
+
PADDLE_ENFORCE(static_cast<float *>(outputs.front().data.data())[i],
|
| 78 |
+
result[i]);
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
TEST(Analyzer, word2vec_without_analysis) {
|
| 83 |
+
TestWord2vecPrediction(FLAGS_inference_model_dir);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
} // namespace analysis
|
| 87 |
+
} // namespace inference
|
| 88 |
+
} // namespace paddle
|
pool/shard009/C++/0109956_Rectangle.cpp
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <cmath>
|
| 2 |
+
|
| 3 |
+
#include <osg/Texture2D>
|
| 4 |
+
#include <osg/Image>
|
| 5 |
+
#include <osgDB/ReadFile>
|
| 6 |
+
#include <osg/CullFace>
|
| 7 |
+
|
| 8 |
+
#include "Rectangle.h"
|
| 9 |
+
|
| 10 |
+
// Rectangle (heigth, witdth)
|
| 11 |
+
ph::Rectangle::Rectangle(const int height, const int width) {
|
| 12 |
+
this->height = height;
|
| 13 |
+
this->width = width;
|
| 14 |
+
this->rectangle = new Geometry;
|
| 15 |
+
this->addDrawable(rectangle);
|
| 16 |
+
|
| 17 |
+
compute();
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
// creating vertices/ normals / indices; simple rectangle build from two triangles
|
| 21 |
+
void ph::Rectangle::compute() {
|
| 22 |
+
ref_ptr<Vec3Array> vertices = new Vec3Array();
|
| 23 |
+
ref_ptr<Vec3Array> normals = new Vec3Array();
|
| 24 |
+
ref_ptr<DrawElementsUInt> indices = new DrawElementsUInt(GL_TRIANGLE_STRIP);
|
| 25 |
+
|
| 26 |
+
vertices->push_back(Vec3((-1/2.0)*height, 0.0, (-1/2.0)*width));
|
| 27 |
+
vertices->push_back(Vec3((1/2.0)*height, 0.0, (-1/2.0)*width));
|
| 28 |
+
vertices->push_back(Vec3((-1/2.0)*height, 0.0, (1/2.0)*width));
|
| 29 |
+
vertices->push_back(Vec3((1/2.0)*height, 0.0, (1/2.0)*width));
|
| 30 |
+
|
| 31 |
+
indices->push_back(0); indices->push_back(1); indices->push_back(2);
|
| 32 |
+
indices->push_back(1); indices->push_back(2); indices->push_back(3);
|
| 33 |
+
|
| 34 |
+
this->rectangle->setVertexArray(vertices.get());
|
| 35 |
+
this->rectangle->addPrimitiveSet(indices.get());
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
// creating texture coordinates
|
| 39 |
+
void ph::Rectangle::setTextureCoordinates(int textureNumber) {
|
| 40 |
+
ref_ptr<Vec2Array> texcoords = new Vec2Array;
|
| 41 |
+
|
| 42 |
+
texcoords->push_back(Vec2(0.0,0.0));
|
| 43 |
+
texcoords->push_back(Vec2(1.0,0.0));
|
| 44 |
+
texcoords->push_back(Vec2(0.0,1.0));
|
| 45 |
+
texcoords->push_back(Vec2(1.0,1.0));
|
| 46 |
+
|
| 47 |
+
this->rectangle->setTexCoordArray(textureNumber, texcoords.get());
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
// setting texture on rectangle
|
| 51 |
+
void ph::Rectangle::setTexture(const int textureNumber, const string filename) {
|
| 52 |
+
this->setTextureCoordinates(textureNumber);
|
| 53 |
+
|
| 54 |
+
ref_ptr<Texture2D> texture = new Texture2D;
|
| 55 |
+
ref_ptr<Image> image = osgDB::readImageFile(filename);
|
| 56 |
+
texture->setWrap(Texture::WRAP_S, Texture::CLAMP_TO_EDGE);
|
| 57 |
+
texture->setImage(image.get());
|
| 58 |
+
this->getOrCreateStateSet()->setTextureAttributeAndModes(textureNumber, texture.get());
|
| 59 |
+
|
| 60 |
+
// enabling culling for rectangles / skybox
|
| 61 |
+
ref_ptr<CullFace> cull = new CullFace;
|
| 62 |
+
cull->setMode(CullFace::BACK);
|
| 63 |
+
this->getOrCreateStateSet()->setAttributeAndModes(cull.get());
|
| 64 |
+
}
|
pool/shard009/C++/0109958_FreeLink.cc
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* opencog/atoms/core/FreeLink.cc
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2015 Linas Vepstas
|
| 5 |
+
* All Rights Reserved
|
| 6 |
+
*
|
| 7 |
+
* This program is free software; you can redistribute it and/or modify
|
| 8 |
+
* it under the terms of the GNU Affero General Public License v3 as
|
| 9 |
+
* published by the Free Software Foundation and including the exceptions
|
| 10 |
+
* at http://opencog.org/wiki/Licenses
|
| 11 |
+
*
|
| 12 |
+
* This program is distributed in the hope that it will be useful,
|
| 13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 |
+
* GNU General Public License for more details.
|
| 16 |
+
*
|
| 17 |
+
* You should have received a copy of the GNU Affero General Public License
|
| 18 |
+
* along with this program; if not, write to:
|
| 19 |
+
* Free Software Foundation, Inc.,
|
| 20 |
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <opencog/atomspace/atom_types.h>
|
| 24 |
+
#include <opencog/atomspace/ClassServer.h>
|
| 25 |
+
#include "FreeLink.h"
|
| 26 |
+
#include "ScopeLink.h"
|
| 27 |
+
#include "VariableList.h"
|
| 28 |
+
|
| 29 |
+
using namespace opencog;
|
| 30 |
+
|
| 31 |
+
FreeLink::FreeLink(const HandleSeq& oset,
|
| 32 |
+
TruthValuePtr tv,
|
| 33 |
+
AttentionValuePtr av)
|
| 34 |
+
: Link(FREE_LINK, oset, tv, av)
|
| 35 |
+
{
|
| 36 |
+
init();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
FreeLink::FreeLink(const Handle& a,
|
| 40 |
+
TruthValuePtr tv,
|
| 41 |
+
AttentionValuePtr av)
|
| 42 |
+
: Link(FREE_LINK, a, tv, av)
|
| 43 |
+
{
|
| 44 |
+
init();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
FreeLink::FreeLink(Type t, const HandleSeq& oset,
|
| 48 |
+
TruthValuePtr tv,
|
| 49 |
+
AttentionValuePtr av)
|
| 50 |
+
: Link(t, oset, tv, av)
|
| 51 |
+
{
|
| 52 |
+
if (not classserver().isA(t, FREE_LINK))
|
| 53 |
+
throw InvalidParamException(TRACE_INFO, "Expecting a FreeLink");
|
| 54 |
+
|
| 55 |
+
// Derived classes have thier own init routines.
|
| 56 |
+
if (FREE_LINK != t) return;
|
| 57 |
+
init();
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
FreeLink::FreeLink(Type t, const Handle& a,
|
| 61 |
+
TruthValuePtr tv,
|
| 62 |
+
AttentionValuePtr av)
|
| 63 |
+
: Link(t, a, tv, av)
|
| 64 |
+
{
|
| 65 |
+
if (not classserver().isA(t, FREE_LINK))
|
| 66 |
+
throw InvalidParamException(TRACE_INFO, "Expecting a FreeLink");
|
| 67 |
+
|
| 68 |
+
// Derived classes have thier own init routines.
|
| 69 |
+
if (FREE_LINK != t) return;
|
| 70 |
+
init();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
FreeLink::FreeLink(Type t, const Handle& a, const Handle& b,
|
| 74 |
+
TruthValuePtr tv,
|
| 75 |
+
AttentionValuePtr av)
|
| 76 |
+
: Link(t, a, b, tv, av)
|
| 77 |
+
{
|
| 78 |
+
if (not classserver().isA(t, FREE_LINK))
|
| 79 |
+
throw InvalidParamException(TRACE_INFO, "Expecting a FreeLink");
|
| 80 |
+
|
| 81 |
+
// Derived classes have thier own init routines.
|
| 82 |
+
if (FREE_LINK != t) return;
|
| 83 |
+
init();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
FreeLink::FreeLink(Link& l)
|
| 87 |
+
: Link(l)
|
| 88 |
+
{
|
| 89 |
+
Type tscope = l.getType();
|
| 90 |
+
if (not classserver().isA(tscope, FREE_LINK))
|
| 91 |
+
throw InvalidParamException(TRACE_INFO, "Expecting a FreeLink");
|
| 92 |
+
|
| 93 |
+
// Derived classes have thier own init routines.
|
| 94 |
+
if (FREE_LINK != tscope) return;
|
| 95 |
+
init();
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/* ================================================================= */
|
| 99 |
+
|
| 100 |
+
void FreeLink::init(void)
|
| 101 |
+
{
|
| 102 |
+
_vars.find_variables(_outgoing);
|
| 103 |
+
}
|
pool/shard009/C++/0109959_cryptauth_device_id_provider_impl.cc
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "chrome/browser/ash/cryptauth/cryptauth_device_id_provider_impl.h"
|
| 6 |
+
|
| 7 |
+
#include "base/guid.h"
|
| 8 |
+
#include "base/no_destructor.h"
|
| 9 |
+
#include "chrome/browser/browser_process.h"
|
| 10 |
+
#include "chrome/common/pref_names.h"
|
| 11 |
+
#include "components/prefs/pref_registry_simple.h"
|
| 12 |
+
#include "components/prefs/pref_service.h"
|
| 13 |
+
|
| 14 |
+
namespace ash {
|
| 15 |
+
|
| 16 |
+
// static
|
| 17 |
+
void CryptAuthDeviceIdProviderImpl::RegisterLocalPrefs(
|
| 18 |
+
PrefRegistrySimple* registry) {
|
| 19 |
+
registry->RegisterStringPref(prefs::kCryptAuthDeviceId, std::string());
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
// static
|
| 23 |
+
const CryptAuthDeviceIdProviderImpl*
|
| 24 |
+
CryptAuthDeviceIdProviderImpl::GetInstance() {
|
| 25 |
+
static const base::NoDestructor<CryptAuthDeviceIdProviderImpl> provider;
|
| 26 |
+
return provider.get();
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
std::string CryptAuthDeviceIdProviderImpl::GetDeviceId() const {
|
| 30 |
+
PrefService* local_state = g_browser_process->local_state();
|
| 31 |
+
DCHECK(local_state);
|
| 32 |
+
|
| 33 |
+
std::string device_id = local_state->GetString(prefs::kCryptAuthDeviceId);
|
| 34 |
+
if (device_id.empty()) {
|
| 35 |
+
device_id = base::GenerateGUID();
|
| 36 |
+
local_state->SetString(prefs::kCryptAuthDeviceId, device_id);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
return device_id;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
CryptAuthDeviceIdProviderImpl::CryptAuthDeviceIdProviderImpl() = default;
|
| 43 |
+
|
| 44 |
+
} // namespace ash
|
pool/shard009/C++/0109960_slot1comp_mc.cpp
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2013-2017 DeSmuME team
|
| 3 |
+
|
| 4 |
+
This file is free software: you can redistribute it and/or modify
|
| 5 |
+
it under the terms of the GNU General Public License as published by
|
| 6 |
+
the Free Software Foundation, either version 2 of the License, or
|
| 7 |
+
(at your option) any later version.
|
| 8 |
+
|
| 9 |
+
This file is distributed in the hope that it will be useful,
|
| 10 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
GNU General Public License for more details.
|
| 13 |
+
|
| 14 |
+
You should have received a copy of the GNU General Public License
|
| 15 |
+
along with the this software. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
//this file contains the components used for emulating standard gamecard "MC" devices (eeprom, fram, flash)
|
| 19 |
+
//this is largely done by accessing the BackupDevice resources in the core emulator
|
| 20 |
+
|
| 21 |
+
#include "slot1comp_mc.h"
|
| 22 |
+
|
| 23 |
+
#include "../MMU.h"
|
| 24 |
+
#include "../NDSSystem.h"
|
| 25 |
+
|
| 26 |
+
Slot1Comp_MC g_Slot1Comp_MC;
|
| 27 |
+
|
| 28 |
+
u8 Slot1Comp_MC::auxspi_transaction(int PROCNUM, u8 value)
|
| 29 |
+
{
|
| 30 |
+
return MMU_new.backupDevice.data_command(value, PROCNUM);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
void Slot1Comp_MC::auxspi_reset(int PROCNUM)
|
| 34 |
+
{
|
| 35 |
+
MMU_new.backupDevice.reset_command();
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
void Slot1Comp_MC::connect()
|
| 39 |
+
{
|
| 40 |
+
//gamehack: not really a game hack
|
| 41 |
+
if(gameInfo.IsCode("AXBJ"))
|
| 42 |
+
MMU_new.backupDevice.uninitializedValue = 0x00; // Daigassou! Band Brothers DX (JP)
|
| 43 |
+
}
|
pool/shard009/C++/0109965_page_launcher_api.cc
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "chrome/browser/extensions/api/page_launcher/page_launcher_api.h"
|
| 6 |
+
|
| 7 |
+
#include "base/lazy_instance.h"
|
| 8 |
+
#include "base/memory/linked_ptr.h"
|
| 9 |
+
#include "chrome/browser/extensions/event_router.h"
|
| 10 |
+
#include "chrome/browser/extensions/extension_system.h"
|
| 11 |
+
#include "chrome/common/extensions/api/page_launcher.h"
|
| 12 |
+
#include "googleurl/src/gurl.h"
|
| 13 |
+
|
| 14 |
+
namespace extensions {
|
| 15 |
+
|
| 16 |
+
// static
|
| 17 |
+
void PageLauncherAPI::DispatchOnClickedEvent(
|
| 18 |
+
Profile* profile,
|
| 19 |
+
const std::string& extension_id,
|
| 20 |
+
const GURL& url,
|
| 21 |
+
const std::string& mimetype,
|
| 22 |
+
const std::string* page_title,
|
| 23 |
+
const std::string* selected_text) {
|
| 24 |
+
api::page_launcher::PageData data;
|
| 25 |
+
data.url = url.spec();
|
| 26 |
+
data.mimetype = mimetype;
|
| 27 |
+
if (page_title)
|
| 28 |
+
data.title.reset(new std::string(*page_title));
|
| 29 |
+
if (selected_text)
|
| 30 |
+
data.selection_text.reset(new std::string(*selected_text));
|
| 31 |
+
|
| 32 |
+
scoped_ptr<Event> event(
|
| 33 |
+
new Event("pageLauncher.onClicked",
|
| 34 |
+
api::page_launcher::OnClicked::Create(data)));
|
| 35 |
+
EventRouter* event_router = ExtensionSystem::Get(profile)->event_router();
|
| 36 |
+
event_router->DispatchEventToExtension(extension_id, event.Pass());
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
} // namespace extensions
|
pool/shard009/C++/0109967_3955491.cpp
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//Language: GNU C++
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
// #includes {{{
|
| 5 |
+
#include<stdio.h>
|
| 6 |
+
#include<stdlib.h>
|
| 7 |
+
#include<string.h>
|
| 8 |
+
#include<math.h>
|
| 9 |
+
#include<assert.h>
|
| 10 |
+
#include<stdarg.h>
|
| 11 |
+
#include<time.h>
|
| 12 |
+
#include<limits.h>
|
| 13 |
+
#include<ctype.h>
|
| 14 |
+
#include<string>
|
| 15 |
+
#include<map>
|
| 16 |
+
#include<set>
|
| 17 |
+
#include<queue>
|
| 18 |
+
#include<algorithm>
|
| 19 |
+
#include<vector>
|
| 20 |
+
#include<iostream>
|
| 21 |
+
#include<sstream>
|
| 22 |
+
using namespace std;
|
| 23 |
+
// }}}
|
| 24 |
+
// #defines {{{
|
| 25 |
+
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
|
| 26 |
+
#define SZ(x) ((int)(x).size())
|
| 27 |
+
#define ALL(x) (x).begin(),(x).end()
|
| 28 |
+
#define REP(i,n) for(int i=0;i<(n);i++)
|
| 29 |
+
#define REP1(i,a,b) for(int i=(a);i<=(b);i++)
|
| 30 |
+
#define PER(i,n) for(int i=(n)-1;i>=0;i--)
|
| 31 |
+
#define PER1(i,a,b) for(int i=(a);i>=(b);i--)
|
| 32 |
+
#define RI(x) scanf("%d",&x)
|
| 33 |
+
#define DRI(x) int x;RI(x)
|
| 34 |
+
#define RII(x,y) scanf("%d%d",&x,&y)
|
| 35 |
+
#define DRII(x,y) int x,y;RII(x,y)
|
| 36 |
+
#define RIII(x,y,z) scanf("%d%d%d",&x,&y,&z)
|
| 37 |
+
#define DRIII(x,y,z) int x,y,z;RIII(x,y,z)
|
| 38 |
+
#define RS(x) scanf("%s",x)
|
| 39 |
+
#define PI(x) printf("%d\n",x)
|
| 40 |
+
#define PIS(x) printf("%d ",x)
|
| 41 |
+
#define CASET int ___T,cas=1;scanf("%d",&___T);while(___T--)
|
| 42 |
+
#define CASEN0(n) int cas=1;while(scanf("%d",&n)!=EOF&&n)
|
| 43 |
+
#define CASEN(n) int cas=1;while(scanf("%d",&n)!=EOF)
|
| 44 |
+
#define MP make_pair
|
| 45 |
+
#define PB push_back
|
| 46 |
+
#define MS0(x) memset(x,0,sizeof(x))
|
| 47 |
+
#define MS1(x) memset(x,-1,sizeof(x))
|
| 48 |
+
|
| 49 |
+
#define F first
|
| 50 |
+
#define S second
|
| 51 |
+
typedef pair<int,int> PII;
|
| 52 |
+
typedef long long LL;
|
| 53 |
+
typedef unsigned long long ULL;
|
| 54 |
+
// }}}
|
| 55 |
+
int a[102][2],n;
|
| 56 |
+
int s[102];
|
| 57 |
+
bool dfs(int x,int y){
|
| 58 |
+
if (x==y) return true;
|
| 59 |
+
s[x]=1;
|
| 60 |
+
REP1(i,1,n){
|
| 61 |
+
if (!s[i] && ((a[i][0]<a[x][0] && a[i][1]>a[x][0])||(a[i][0]<a[x][1]&&a[i][1]>a[x][1])))
|
| 62 |
+
if (dfs(i,y)) return true;
|
| 63 |
+
}
|
| 64 |
+
return false;
|
| 65 |
+
|
| 66 |
+
}
|
| 67 |
+
main(){
|
| 68 |
+
DRI(t);
|
| 69 |
+
n=0;
|
| 70 |
+
REP(i,t){
|
| 71 |
+
DRIII(o,x,y);
|
| 72 |
+
if (o==1){
|
| 73 |
+
a[++n][0]=x;
|
| 74 |
+
a[n][1]=y;
|
| 75 |
+
}else{
|
| 76 |
+
MS0(s);
|
| 77 |
+
if (dfs(x,y)) puts("YES");else puts("NO");
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
}
|
pool/shard009/C++/0109969_GxsChannelUserNotify.cpp
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/****************************************************************
|
| 2 |
+
* RetroShare is distributed under the following license:
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2014 RetroShare Team
|
| 5 |
+
*
|
| 6 |
+
* This program is free software; you can redistribute it and/or
|
| 7 |
+
* modify it under the terms of the GNU General Public License
|
| 8 |
+
* as published by the Free Software Foundation; either version 2
|
| 9 |
+
* of the License, or (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* This program is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with this program; if not, write to the Free Software
|
| 18 |
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
| 19 |
+
* Boston, MA 02110-1301, USA.
|
| 20 |
+
****************************************************************/
|
| 21 |
+
|
| 22 |
+
#include "GxsChannelUserNotify.h"
|
| 23 |
+
#include "gui/MainWindow.h"
|
| 24 |
+
|
| 25 |
+
GxsChannelUserNotify::GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) :
|
| 26 |
+
GxsUserNotify(ifaceImpl, parent)
|
| 27 |
+
{
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
bool GxsChannelUserNotify::hasSetting(QString *name, QString *group)
|
| 31 |
+
{
|
| 32 |
+
if (name) *name = tr("Channel Post");
|
| 33 |
+
if (group) *group = "Channel";
|
| 34 |
+
|
| 35 |
+
return true;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
QIcon GxsChannelUserNotify::getIcon()
|
| 39 |
+
{
|
| 40 |
+
return QIcon(":/icons/png/channels.png");
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
QIcon GxsChannelUserNotify::getMainIcon(bool hasNew)
|
| 44 |
+
{
|
| 45 |
+
return hasNew ? QIcon(":/icons/png/channels-notify.png") : QIcon(":/icons/png/channels.png");
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void GxsChannelUserNotify::iconClicked()
|
| 49 |
+
{
|
| 50 |
+
MainWindow::showWindow(MainWindow::Channels);
|
| 51 |
+
}
|
pool/shard009/C++/0109970_SVGAngleInterpolationType.cpp
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2015 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "config.h"
|
| 6 |
+
#include "core/animation/SVGAngleInterpolationType.h"
|
| 7 |
+
|
| 8 |
+
#include "core/animation/InterpolationEnvironment.h"
|
| 9 |
+
#include "core/animation/StringKeyframe.h"
|
| 10 |
+
#include "core/svg/SVGAngle.h"
|
| 11 |
+
|
| 12 |
+
namespace blink {
|
| 13 |
+
|
| 14 |
+
PassOwnPtr<InterpolationValue> SVGAngleInterpolationType::maybeConvertNeutral() const
|
| 15 |
+
{
|
| 16 |
+
return InterpolationValue::create(*this, InterpolableNumber::create(0));
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
PassOwnPtr<InterpolationValue> SVGAngleInterpolationType::maybeConvertSVGValue(const SVGPropertyBase& svgValue) const
|
| 20 |
+
{
|
| 21 |
+
if (toSVGAngle(svgValue).orientType()->enumValue() != SVGMarkerOrientAngle)
|
| 22 |
+
return nullptr;
|
| 23 |
+
return InterpolationValue::create(*this, InterpolableNumber::create(toSVGAngle(svgValue).value()));
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGAngleInterpolationType::appliedSVGValue(const InterpolableValue& interpolableValue, const NonInterpolableValue*) const
|
| 27 |
+
{
|
| 28 |
+
double doubleValue = toInterpolableNumber(interpolableValue).value();
|
| 29 |
+
RefPtrWillBeRawPtr<SVGAngle> result = SVGAngle::create();
|
| 30 |
+
result->newValueSpecifiedUnits(SVGAngle::SVG_ANGLETYPE_DEG, doubleValue);
|
| 31 |
+
return result.release();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
} // namespace blink
|
pool/shard009/C++/0109972_group_cipher_delegate.cpp
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// The MIT License(MIT)
|
| 3 |
+
//
|
| 4 |
+
// Copyright(c) 2014 Demonsaw LLC
|
| 5 |
+
//
|
| 6 |
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
// of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
// in the Software without restriction, including without limitation the rights
|
| 9 |
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
// copies of the Software, and to permit persons to whom the Software is
|
| 11 |
+
// furnished to do so, subject to the following conditions:
|
| 12 |
+
//
|
| 13 |
+
// The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
// copies or substantial portions of the Software.
|
| 15 |
+
//
|
| 16 |
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 22 |
+
// SOFTWARE.
|
| 23 |
+
|
| 24 |
+
#include <QApplication>
|
| 25 |
+
#include <QColor>
|
| 26 |
+
#include <QComboBox>
|
| 27 |
+
#include <QListView>
|
| 28 |
+
#include <QRect>
|
| 29 |
+
#include <QPainter>
|
| 30 |
+
|
| 31 |
+
#include "component/group/group_security_component.h"
|
| 32 |
+
#include "delegate/group/group_cipher_delegate.h"
|
| 33 |
+
#include "entity/entity.h"
|
| 34 |
+
#include "security/cipher/aes.h"
|
| 35 |
+
#include "security/cipher/mars.h"
|
| 36 |
+
#include "security/cipher/rc6.h"
|
| 37 |
+
#include "security/cipher/serpent.h"
|
| 38 |
+
#include "security/cipher/twofish.h"
|
| 39 |
+
|
| 40 |
+
Q_DECLARE_METATYPE(eja::entity::ptr);
|
| 41 |
+
|
| 42 |
+
namespace eja
|
| 43 |
+
{
|
| 44 |
+
// Utility
|
| 45 |
+
QWidget* group_cipher_delegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
| 46 |
+
{
|
| 47 |
+
QComboBox* widget = new QComboBox(parent);
|
| 48 |
+
widget->addItem(cipher_name::aes);
|
| 49 |
+
widget->addItem(cipher_name::mars);
|
| 50 |
+
widget->addItem(cipher_name::rc6);
|
| 51 |
+
widget->addItem(cipher_name::serpent);
|
| 52 |
+
widget->addItem(cipher_name::twofish);
|
| 53 |
+
|
| 54 |
+
return widget;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void group_cipher_delegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
| 58 |
+
{
|
| 59 |
+
if (QComboBox* widget = qobject_cast<QComboBox*>(editor))
|
| 60 |
+
{
|
| 61 |
+
const auto data = index.data(Qt::EditRole).toString();
|
| 62 |
+
widget->setCurrentText(data);
|
| 63 |
+
}
|
| 64 |
+
else
|
| 65 |
+
{
|
| 66 |
+
QStyledItemDelegate::setEditorData(editor, index);
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void group_cipher_delegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
|
| 71 |
+
{
|
| 72 |
+
if (QComboBox* widget = qobject_cast<QComboBox*>(editor))
|
| 73 |
+
model->setData(index, widget->currentText(), Qt::EditRole);
|
| 74 |
+
else
|
| 75 |
+
QStyledItemDelegate::setModelData(editor, model, index);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
QSize group_cipher_delegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
| 79 |
+
{
|
| 80 |
+
// Data
|
| 81 |
+
auto variant = index.data(Qt::EditRole);
|
| 82 |
+
QString str = variant.toString();
|
| 83 |
+
|
| 84 |
+
// Size
|
| 85 |
+
QFontMetrics metrics(option.font);
|
| 86 |
+
QRect rect = metrics.boundingRect(str);
|
| 87 |
+
rect.setWidth(rect.width() + offset::padding);
|
| 88 |
+
|
| 89 |
+
return rect.size();
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
void group_cipher_delegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
| 93 |
+
{
|
| 94 |
+
QStyledItemDelegate::paint(painter, option, index);
|
| 95 |
+
|
| 96 |
+
if (option.state & QStyle::State_Enabled)
|
| 97 |
+
{
|
| 98 |
+
// Entity
|
| 99 |
+
const auto variant = index.data(Qt::DisplayRole);
|
| 100 |
+
const auto entity = variant.value<entity::ptr>();
|
| 101 |
+
if (!entity)
|
| 102 |
+
return;
|
| 103 |
+
|
| 104 |
+
// Security
|
| 105 |
+
const auto security = entity->get<group_security_component>();
|
| 106 |
+
const auto name = security->get_cipher();
|
| 107 |
+
|
| 108 |
+
painter->save();
|
| 109 |
+
painter->setRenderHint(QPainter::Antialiasing, true);
|
| 110 |
+
|
| 111 |
+
// Name
|
| 112 |
+
QRect rect = QRect(option.rect.left(), option.rect.top(), option.rect.width(), option.rect.height());
|
| 113 |
+
painter->drawText(rect, Qt::TextSingleLine | Qt::AlignVCenter, name.c_str());
|
| 114 |
+
|
| 115 |
+
painter->restore();
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
}
|
pool/shard009/C++/0109973_class1.cpp
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <iostream>
|
| 2 |
+
#include "class.h"
|
| 3 |
+
|
| 4 |
+
using namespace std;
|
| 5 |
+
|
| 6 |
+
CA::CA() {
|
| 7 |
+
a = 0;
|
| 8 |
+
cout << "Construction: " << a << endl;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
CA::~CA() {
|
| 12 |
+
cout << "Destruct: " << a << endl;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
void CA::setA(int x) {
|
| 16 |
+
a = x;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
void CA::print() {
|
| 20 |
+
cout << "print: " << a << endl;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
int main()
|
| 24 |
+
{
|
| 25 |
+
CA ca;
|
| 26 |
+
ca.setA(10);
|
| 27 |
+
ca.print();
|
| 28 |
+
|
| 29 |
+
return 0;
|
| 30 |
+
}
|
pool/shard009/C++/0109975_CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84a.cpp
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84a.cpp
|
| 3 |
+
Label Definition File: CWE762_Mismatched_Memory_Management_Routines__delete.label.xml
|
| 4 |
+
Template File: sources-sinks-84a.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 762 Mismatched Memory Management Routines
|
| 9 |
+
* BadSource: realloc Allocate data using realloc()
|
| 10 |
+
* GoodSource: Allocate data using new
|
| 11 |
+
* Sinks:
|
| 12 |
+
* GoodSink: Deallocate data using free()
|
| 13 |
+
* BadSink : Deallocate data using delete
|
| 14 |
+
* Flow Variant: 84 Data flow: data passed to class constructor and destructor by declaring the class object on the heap and deleting it after use
|
| 15 |
+
*
|
| 16 |
+
* */
|
| 17 |
+
|
| 18 |
+
#include "std_testcase.h"
|
| 19 |
+
#include "CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84.h"
|
| 20 |
+
|
| 21 |
+
namespace CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84
|
| 22 |
+
{
|
| 23 |
+
|
| 24 |
+
#ifndef OMITBAD
|
| 25 |
+
|
| 26 |
+
void bad()
|
| 27 |
+
{
|
| 28 |
+
int64_t * data;
|
| 29 |
+
/* Initialize data*/
|
| 30 |
+
data = NULL;
|
| 31 |
+
CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84_bad * badObject = new CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84_bad(data);
|
| 32 |
+
delete badObject;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
#endif /* OMITBAD */
|
| 36 |
+
|
| 37 |
+
#ifndef OMITGOOD
|
| 38 |
+
|
| 39 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 40 |
+
static void goodG2B()
|
| 41 |
+
{
|
| 42 |
+
int64_t * data;
|
| 43 |
+
/* Initialize data*/
|
| 44 |
+
data = NULL;
|
| 45 |
+
CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84_goodG2B * goodG2BObject = new CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84_goodG2B(data);
|
| 46 |
+
delete goodG2BObject;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/* goodG2B uses the BadSource with the GoodSink */
|
| 50 |
+
static void goodB2G()
|
| 51 |
+
{
|
| 52 |
+
int64_t * data;
|
| 53 |
+
/* Initialize data*/
|
| 54 |
+
data = NULL;
|
| 55 |
+
CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84_goodB2G * goodB2GObject = new CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84_goodB2G(data);
|
| 56 |
+
delete goodB2GObject;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
void good()
|
| 60 |
+
{
|
| 61 |
+
goodG2B();
|
| 62 |
+
goodB2G();
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
#endif /* OMITGOOD */
|
| 66 |
+
|
| 67 |
+
} /* close namespace */
|
| 68 |
+
|
| 69 |
+
/* Below is the main(). It is only used when building this testcase on
|
| 70 |
+
its own for testing or for building a binary to use in testing binary
|
| 71 |
+
analysis tools. It is not used when compiling all the testcases as one
|
| 72 |
+
application, which is how source code analysis tools are tested. */
|
| 73 |
+
|
| 74 |
+
#ifdef INCLUDEMAIN
|
| 75 |
+
|
| 76 |
+
using namespace CWE762_Mismatched_Memory_Management_Routines__delete_int64_t_realloc_84; /* so that we can use good and bad easily */
|
| 77 |
+
|
| 78 |
+
int main(int argc, char * argv[])
|
| 79 |
+
{
|
| 80 |
+
/* seed randomness */
|
| 81 |
+
srand( (unsigned)time(NULL) );
|
| 82 |
+
#ifndef OMITGOOD
|
| 83 |
+
printLine("Calling good()...");
|
| 84 |
+
good();
|
| 85 |
+
printLine("Finished good()");
|
| 86 |
+
#endif /* OMITGOOD */
|
| 87 |
+
#ifndef OMITBAD
|
| 88 |
+
printLine("Calling bad()...");
|
| 89 |
+
bad();
|
| 90 |
+
printLine("Finished bad()");
|
| 91 |
+
#endif /* OMITBAD */
|
| 92 |
+
return 0;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
#endif
|
pool/shard009/C++/0109977_rounding.cpp
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
| 2 |
+
/*
|
| 3 |
+
* Main authors:
|
| 4 |
+
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
|
| 5 |
+
*
|
| 6 |
+
* Contributing authors:
|
| 7 |
+
* Christian Schulte <schulte@gecode.org>
|
| 8 |
+
*
|
| 9 |
+
* Copyright:
|
| 10 |
+
* Christian Schulte, 2012
|
| 11 |
+
* Vincent Barichard, 2012
|
| 12 |
+
*
|
| 13 |
+
* Last modified:
|
| 14 |
+
* $Date$ by $Author$
|
| 15 |
+
* $Revision$
|
| 16 |
+
*
|
| 17 |
+
* This file is part of Gecode, the generic constraint
|
| 18 |
+
* development environment:
|
| 19 |
+
* http://www.gecode.org
|
| 20 |
+
*
|
| 21 |
+
* Permission is hereby granted, free of charge, to any person obtaining
|
| 22 |
+
* a copy of this software and associated documentation files (the
|
| 23 |
+
* "Software"), to deal in the Software without restriction, including
|
| 24 |
+
* without limitation the rights to use, copy, modify, merge, publish,
|
| 25 |
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
| 26 |
+
* permit persons to whom the Software is furnished to do so, subject to
|
| 27 |
+
* the following conditions:
|
| 28 |
+
*
|
| 29 |
+
* The above copyright notice and this permission notice shall be
|
| 30 |
+
* included in all copies or substantial portions of the Software.
|
| 31 |
+
*
|
| 32 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 33 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 34 |
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 35 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
| 36 |
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
| 37 |
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
| 38 |
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 39 |
+
*
|
| 40 |
+
*/
|
| 41 |
+
|
| 42 |
+
#include <gecode/float.hh>
|
| 43 |
+
|
| 44 |
+
#ifdef GECODE_HAS_MPFR
|
| 45 |
+
|
| 46 |
+
#include <gmp.h>
|
| 47 |
+
#include <mpfr.h>
|
| 48 |
+
|
| 49 |
+
namespace Gecode { namespace Float {
|
| 50 |
+
|
| 51 |
+
/// Type signatur of mpfr function
|
| 52 |
+
typedef int mpfr_func(mpfr_t, const __mpfr_struct*, mp_rnd_t);
|
| 53 |
+
|
| 54 |
+
/// Routine to call mpfr function with proper rounding
|
| 55 |
+
forceinline double
|
| 56 |
+
invoke_mpfr(FloatNum x, mpfr_func f, mp_rnd_t r) {
|
| 57 |
+
mpfr_t xx;
|
| 58 |
+
mpfr_init_set_d(xx, x, GMP_RNDN);
|
| 59 |
+
f(xx, xx, r);
|
| 60 |
+
FloatNum res = mpfr_get_d(xx, r);
|
| 61 |
+
mpfr_clear(xx);
|
| 62 |
+
return res;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/// Define mpfr functions with proper rounding
|
| 66 |
+
#define GECODE_GENR_FUNC(name) \
|
| 67 |
+
FloatNum Rounding::name##_down(FloatNum x) { \
|
| 68 |
+
return invoke_mpfr(x, mpfr_##name, GMP_RNDD); \
|
| 69 |
+
} \
|
| 70 |
+
FloatNum Rounding::name##_up(FloatNum x) { \
|
| 71 |
+
return invoke_mpfr(x, mpfr_##name, GMP_RNDU); \
|
| 72 |
+
}
|
| 73 |
+
GECODE_GENR_FUNC(exp)
|
| 74 |
+
GECODE_GENR_FUNC(log)
|
| 75 |
+
GECODE_GENR_FUNC(sin)
|
| 76 |
+
GECODE_GENR_FUNC(cos)
|
| 77 |
+
GECODE_GENR_FUNC(tan)
|
| 78 |
+
GECODE_GENR_FUNC(asin)
|
| 79 |
+
GECODE_GENR_FUNC(acos)
|
| 80 |
+
GECODE_GENR_FUNC(atan)
|
| 81 |
+
GECODE_GENR_FUNC(sinh)
|
| 82 |
+
GECODE_GENR_FUNC(cosh)
|
| 83 |
+
GECODE_GENR_FUNC(tanh)
|
| 84 |
+
GECODE_GENR_FUNC(asinh)
|
| 85 |
+
GECODE_GENR_FUNC(acosh)
|
| 86 |
+
GECODE_GENR_FUNC(atanh)
|
| 87 |
+
|
| 88 |
+
#undef GECODE_GENR_FUNC
|
| 89 |
+
|
| 90 |
+
}}
|
| 91 |
+
|
| 92 |
+
#endif
|
| 93 |
+
|
| 94 |
+
// STATISTICS: float-var
|
| 95 |
+
|
pool/shard009/C++/0109982_pointer_partial_void.cc
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// { dg-require-atomic-builtins "" }
|
| 2 |
+
// { dg-options "-std=gnu++0x" }
|
| 3 |
+
|
| 4 |
+
// Copyright (C) 2012-2013 Free Software Foundation, Inc.
|
| 5 |
+
//
|
| 6 |
+
// This file is part of the GNU ISO C++ Library. This library is free
|
| 7 |
+
// software; you can redistribute it and/or modify it under the
|
| 8 |
+
// terms of the GNU General Public License as published by the
|
| 9 |
+
// Free Software Foundation; either version 3, or (at your option)
|
| 10 |
+
// any later version.
|
| 11 |
+
|
| 12 |
+
// This library is distributed in the hope that it will be useful,
|
| 13 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 |
+
// GNU General Public License for more details.
|
| 16 |
+
|
| 17 |
+
// You should have received a copy of the GNU General Public License along
|
| 18 |
+
// with this library; see the file COPYING3. If not see
|
| 19 |
+
// <http://www.gnu.org/licenses/>.
|
| 20 |
+
|
| 21 |
+
#include <atomic>
|
| 22 |
+
#include <cstdlib> //std::abs
|
| 23 |
+
#include <testsuite_hooks.h>
|
| 24 |
+
|
| 25 |
+
// pointer arithimetic vs. atomic<void*>.
|
| 26 |
+
// atomic<void*> vs. explicitly specialized w/o operators, like atomic_bool?
|
| 27 |
+
int main(void)
|
| 28 |
+
{
|
| 29 |
+
using namespace std;
|
| 30 |
+
|
| 31 |
+
typedef int value_type;
|
| 32 |
+
const size_t n = 2;
|
| 33 |
+
value_type value = 42;
|
| 34 |
+
value_type* p = &value;
|
| 35 |
+
void* vp = p;
|
| 36 |
+
ptrdiff_t __attribute__((unused)) dist(0);
|
| 37 |
+
|
| 38 |
+
atomic<void*> a(vp);
|
| 39 |
+
|
| 40 |
+
// operator++
|
| 41 |
+
void* vp2(a);
|
| 42 |
+
a++;
|
| 43 |
+
void* vp3(a);
|
| 44 |
+
dist = reinterpret_cast<char*>(vp2) - reinterpret_cast<char*>(vp3);
|
| 45 |
+
VERIFY ( std::abs(dist) == 1 );
|
| 46 |
+
|
| 47 |
+
// operator--
|
| 48 |
+
void* vp4(a);
|
| 49 |
+
a--;
|
| 50 |
+
void* vp5(a);
|
| 51 |
+
dist = reinterpret_cast<char*>(vp4) - reinterpret_cast<char*>(vp5);
|
| 52 |
+
VERIFY ( std::abs(dist) == 1 );
|
| 53 |
+
|
| 54 |
+
// operator+=
|
| 55 |
+
void* vp6(a);
|
| 56 |
+
a+=n;
|
| 57 |
+
void* vp7(a);
|
| 58 |
+
dist = reinterpret_cast<char*>(vp6) - reinterpret_cast<char*>(vp7);
|
| 59 |
+
VERIFY ( std::abs(dist) == n );
|
| 60 |
+
|
| 61 |
+
// operator-=
|
| 62 |
+
void* vp8(a);
|
| 63 |
+
a-=n;
|
| 64 |
+
void* vp9(a);
|
| 65 |
+
dist = reinterpret_cast<char*>(vp8) - reinterpret_cast<char*>(vp9);
|
| 66 |
+
VERIFY ( std::abs(dist) == n );
|
| 67 |
+
|
| 68 |
+
return 0;
|
| 69 |
+
}
|
pool/shard009/C++/0109985_sample_attach.cc
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//----------------------------------------------------------------------------//
|
| 2 |
+
// //
|
| 3 |
+
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
|
| 4 |
+
// and distributed under the MIT License (MIT). //
|
| 5 |
+
// //
|
| 6 |
+
// Copyright (c) 2015 Guillaume Blanc //
|
| 7 |
+
// //
|
| 8 |
+
// Permission is hereby granted, free of charge, to any person obtaining a //
|
| 9 |
+
// copy of this software and associated documentation files (the "Software"), //
|
| 10 |
+
// to deal in the Software without restriction, including without limitation //
|
| 11 |
+
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
|
| 12 |
+
// and/or sell copies of the Software, and to permit persons to whom the //
|
| 13 |
+
// Software is furnished to do so, subject to the following conditions: //
|
| 14 |
+
// //
|
| 15 |
+
// The above copyright notice and this permission notice shall be included in //
|
| 16 |
+
// all copies or substantial portions of the Software. //
|
| 17 |
+
// //
|
| 18 |
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
|
| 19 |
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
|
| 20 |
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
|
| 21 |
+
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
|
| 22 |
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
|
| 23 |
+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
|
| 24 |
+
// DEALINGS IN THE SOFTWARE. //
|
| 25 |
+
// //
|
| 26 |
+
//----------------------------------------------------------------------------//
|
| 27 |
+
|
| 28 |
+
#include "ozz/animation/runtime/skeleton.h"
|
| 29 |
+
#include "ozz/animation/runtime/animation.h"
|
| 30 |
+
#include "ozz/animation/runtime/sampling_job.h"
|
| 31 |
+
#include "ozz/animation/runtime/local_to_model_job.h"
|
| 32 |
+
|
| 33 |
+
#include "ozz/base/log.h"
|
| 34 |
+
|
| 35 |
+
#include "ozz/base/memory/allocator.h"
|
| 36 |
+
|
| 37 |
+
#include "ozz/base/maths/vec_float.h"
|
| 38 |
+
#include "ozz/base/maths/simd_math.h"
|
| 39 |
+
#include "ozz/base/maths/box.h"
|
| 40 |
+
#include "ozz/base/maths/soa_transform.h"
|
| 41 |
+
|
| 42 |
+
#include "ozz/options/options.h"
|
| 43 |
+
|
| 44 |
+
#include "framework/application.h"
|
| 45 |
+
#include "framework/renderer.h"
|
| 46 |
+
#include "framework/imgui.h"
|
| 47 |
+
#include "framework/utils.h"
|
| 48 |
+
|
| 49 |
+
// Skeleton archive can be specified as an option.
|
| 50 |
+
OZZ_OPTIONS_DECLARE_STRING(
|
| 51 |
+
skeleton,
|
| 52 |
+
"Path to the skeleton (ozz archive format).",
|
| 53 |
+
"media/alain_skeleton.ozz",
|
| 54 |
+
false)
|
| 55 |
+
|
| 56 |
+
// Animation archive can be specified as an option.
|
| 57 |
+
OZZ_OPTIONS_DECLARE_STRING(
|
| 58 |
+
animation,
|
| 59 |
+
"Path to the animation (ozz archive format).",
|
| 60 |
+
"media/alain_walk.ozz",
|
| 61 |
+
false)
|
| 62 |
+
|
| 63 |
+
class AttachSampleApplication : public ozz::sample::Application {
|
| 64 |
+
public:
|
| 65 |
+
AttachSampleApplication()
|
| 66 |
+
: cache_(NULL),
|
| 67 |
+
attachment_(0),
|
| 68 |
+
offset_(-.02f, .03f, .05f) {
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
protected:
|
| 72 |
+
// Updates current animation time.
|
| 73 |
+
virtual bool OnUpdate(float _dt) {
|
| 74 |
+
// Updates current animation time.
|
| 75 |
+
controller_.Update(animation_, _dt);
|
| 76 |
+
|
| 77 |
+
// Samples optimized animation at t = animation_time_.
|
| 78 |
+
ozz::animation::SamplingJob sampling_job;
|
| 79 |
+
sampling_job.animation = &animation_;
|
| 80 |
+
sampling_job.cache = cache_;
|
| 81 |
+
sampling_job.time = controller_.time();
|
| 82 |
+
sampling_job.output = locals_;
|
| 83 |
+
if (!sampling_job.Run()) {
|
| 84 |
+
return false;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
// Converts from local space to model space matrices.
|
| 88 |
+
ozz::animation::LocalToModelJob ltm_job;
|
| 89 |
+
ltm_job.skeleton = &skeleton_;
|
| 90 |
+
ltm_job.input = locals_;
|
| 91 |
+
ltm_job.output = models_;
|
| 92 |
+
if (!ltm_job.Run()) {
|
| 93 |
+
return false;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
return true;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
// Samples animation, transforms to model space and renders.
|
| 100 |
+
virtual bool OnDisplay(ozz::sample::Renderer* _renderer) {
|
| 101 |
+
if (!_renderer->DrawPosture(skeleton_,
|
| 102 |
+
models_,
|
| 103 |
+
ozz::math::Float4x4::identity())) {
|
| 104 |
+
return false;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
// Prepares attached object transformation.
|
| 108 |
+
// Gets model space transformation of the joint.
|
| 109 |
+
const ozz::math::Float4x4& joint = models_[attachment_];
|
| 110 |
+
|
| 111 |
+
// Builds offset transformation matrix.
|
| 112 |
+
const ozz::math::SimdFloat4 translation =
|
| 113 |
+
ozz::math::simd_float4::Load3PtrU(&offset_.x);
|
| 114 |
+
|
| 115 |
+
// Concatenates joint and offset transformations.
|
| 116 |
+
const ozz::math::Float4x4 transform =
|
| 117 |
+
joint * ozz::math::Float4x4::Translation(translation);
|
| 118 |
+
|
| 119 |
+
// Prepare rendering.
|
| 120 |
+
const float thickness = .01f;
|
| 121 |
+
const float length = .5f;
|
| 122 |
+
const ozz::math::Box box(ozz::math::Float3(-thickness, -thickness, -length),
|
| 123 |
+
ozz::math::Float3(thickness, thickness, 0.f));
|
| 124 |
+
const ozz::sample::Renderer::Color colors[2] = {
|
| 125 |
+
{0xff, 0, 0, 0xff}, {0, 0xff, 0, 0xff}};
|
| 126 |
+
|
| 127 |
+
return _renderer->DrawBoxIm(box, transform, colors);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
virtual bool OnInitialize() {
|
| 131 |
+
ozz::memory::Allocator* allocator = ozz::memory::default_allocator();
|
| 132 |
+
|
| 133 |
+
// Reading skeleton.
|
| 134 |
+
if (!ozz::sample::LoadSkeleton(OPTIONS_skeleton, &skeleton_)) {
|
| 135 |
+
return false;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
// Reading animation.
|
| 139 |
+
if (!ozz::sample::LoadAnimation(OPTIONS_animation, &animation_)) {
|
| 140 |
+
return false;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
// Allocates runtime buffers.
|
| 144 |
+
const int num_joints = skeleton_.num_joints();
|
| 145 |
+
const int num_soa_joints = skeleton_.num_soa_joints();
|
| 146 |
+
locals_ = allocator->AllocateRange<ozz::math::SoaTransform>(num_soa_joints);
|
| 147 |
+
models_ = allocator->AllocateRange<ozz::math::Float4x4>(num_joints);
|
| 148 |
+
|
| 149 |
+
// Allocates a cache that matches animation requirements.
|
| 150 |
+
cache_ = allocator->New<ozz::animation::SamplingCache>(num_joints);
|
| 151 |
+
|
| 152 |
+
// Finds the joint where the object should be attached.
|
| 153 |
+
for (int i = 0; i < num_joints; i++) {
|
| 154 |
+
if (std::strstr(skeleton_.joint_names()[i], "LeftHandMiddle")) {
|
| 155 |
+
attachment_ = i;
|
| 156 |
+
break;
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
return true;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
virtual void OnDestroy() {
|
| 164 |
+
ozz::memory::Allocator* allocator = ozz::memory::default_allocator();
|
| 165 |
+
allocator->Deallocate(locals_);
|
| 166 |
+
allocator->Deallocate(models_);
|
| 167 |
+
allocator->Delete(cache_);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
virtual bool OnGui(ozz::sample::ImGui* _im_gui) {
|
| 171 |
+
// Exposes animation runtime playback controls.
|
| 172 |
+
{
|
| 173 |
+
static bool open = true;
|
| 174 |
+
ozz::sample::ImGui::OpenClose oc(_im_gui, "Animation control", &open);
|
| 175 |
+
if (open) {
|
| 176 |
+
controller_.OnGui(animation_, _im_gui);
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
// Exposes selection of the attachment joint.
|
| 181 |
+
{
|
| 182 |
+
static bool open = true;
|
| 183 |
+
ozz::sample::ImGui::OpenClose oc(_im_gui, "Attachment joint", &open);
|
| 184 |
+
if (open && skeleton_.num_joints() != 0) {
|
| 185 |
+
_im_gui->DoLabel("Select joint:");
|
| 186 |
+
char label[64];
|
| 187 |
+
std::sprintf(label, "%s (%d)",
|
| 188 |
+
skeleton_.joint_names()[attachment_],
|
| 189 |
+
attachment_);
|
| 190 |
+
_im_gui->DoSlider(label,
|
| 191 |
+
0, skeleton_.num_joints() - 1,
|
| 192 |
+
&attachment_);
|
| 193 |
+
|
| 194 |
+
_im_gui->DoLabel("Attachment offset:");
|
| 195 |
+
sprintf(label, "x: %02f", offset_.x);
|
| 196 |
+
_im_gui->DoSlider(label, -1.f, 1.f, &offset_.x);
|
| 197 |
+
sprintf(label, "y: %02f", offset_.y);
|
| 198 |
+
_im_gui->DoSlider(label, -1.f, 1.f, &offset_.y);
|
| 199 |
+
sprintf(label, "z: %02f", offset_.z);
|
| 200 |
+
_im_gui->DoSlider(label, -1.f, 1.f, &offset_.z);
|
| 201 |
+
}
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
return true;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
virtual void GetSceneBounds(ozz::math::Box* _bound) const {
|
| 208 |
+
ozz::sample::ComputePostureBounds(models_, _bound);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
private:
|
| 212 |
+
|
| 213 |
+
// Playback animation controller. This is a utility class that helps with
|
| 214 |
+
// controlling animation playback time.
|
| 215 |
+
ozz::sample::PlaybackController controller_;
|
| 216 |
+
|
| 217 |
+
// Runtime skeleton.
|
| 218 |
+
ozz::animation::Skeleton skeleton_;
|
| 219 |
+
|
| 220 |
+
// Runtime animation.
|
| 221 |
+
ozz::animation::Animation animation_;
|
| 222 |
+
|
| 223 |
+
// Sampling cache.
|
| 224 |
+
ozz::animation::SamplingCache* cache_;
|
| 225 |
+
|
| 226 |
+
// Buffer of local transforms as sampled from animation_.
|
| 227 |
+
ozz::Range<ozz::math::SoaTransform> locals_;
|
| 228 |
+
|
| 229 |
+
// Buffer of model space matrices.
|
| 230 |
+
ozz::Range<ozz::math::Float4x4> models_;
|
| 231 |
+
|
| 232 |
+
// Joint where the object is attached.
|
| 233 |
+
int attachment_;
|
| 234 |
+
|
| 235 |
+
// Offset, translation of the attached object from the joint.
|
| 236 |
+
ozz::math::Float3 offset_;
|
| 237 |
+
};
|
| 238 |
+
|
| 239 |
+
int main(int _argc, const char** _argv) {
|
| 240 |
+
const char* title =
|
| 241 |
+
"Ozz-animation sample: Attachment to animated skeleton joints";
|
| 242 |
+
return AttachSampleApplication().Run(_argc, _argv, "1.0", title);
|
| 243 |
+
}
|
pool/shard009/C++/0109986_QXmppInvokable.cpp
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2008-2021 The QXmpp developers
|
| 3 |
+
*
|
| 4 |
+
* Authors:
|
| 5 |
+
* Ian Reinhart Geiser
|
| 6 |
+
*
|
| 7 |
+
* Source:
|
| 8 |
+
* https://github.com/qxmpp-project/qxmpp
|
| 9 |
+
*
|
| 10 |
+
* This file is a part of QXmpp library.
|
| 11 |
+
*
|
| 12 |
+
* This library is free software; you can redistribute it and/or
|
| 13 |
+
* modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
* License as published by the Free Software Foundation; either
|
| 15 |
+
* version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
*
|
| 17 |
+
* This library is distributed in the hope that it will be useful,
|
| 18 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
* Lesser General Public License for more details.
|
| 21 |
+
*
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
#include "QXmppInvokable.h"
|
| 25 |
+
|
| 26 |
+
#include <QMetaMethod>
|
| 27 |
+
#include <QStringList>
|
| 28 |
+
#include <QVariant>
|
| 29 |
+
#include <qdebug.h>
|
| 30 |
+
|
| 31 |
+
/// Constructs a QXmppInvokable with the specified \a parent.
|
| 32 |
+
///
|
| 33 |
+
/// \param parent
|
| 34 |
+
|
| 35 |
+
QXmppInvokable::QXmppInvokable(QObject *parent)
|
| 36 |
+
: QObject(parent)
|
| 37 |
+
{
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
/// Destroys a QXmppInvokable.
|
| 41 |
+
|
| 42 |
+
QXmppInvokable::~QXmppInvokable()
|
| 43 |
+
{
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
QVariant QXmppInvokable::dispatch(const QByteArray &method, const QList<QVariant> &args)
|
| 47 |
+
{
|
| 48 |
+
buildMethodHash();
|
| 49 |
+
|
| 50 |
+
if (!m_methodHash.contains(method))
|
| 51 |
+
return QVariant();
|
| 52 |
+
|
| 53 |
+
int idx = m_methodHash[method];
|
| 54 |
+
if (paramTypes(args) != metaObject()->method(idx).parameterTypes())
|
| 55 |
+
return QVariant();
|
| 56 |
+
|
| 57 |
+
const char *typeName = metaObject()->method(idx).typeName();
|
| 58 |
+
int resultType = QMetaType::type(typeName);
|
| 59 |
+
|
| 60 |
+
void *result = QMetaType::create(resultType, nullptr);
|
| 61 |
+
|
| 62 |
+
QGenericReturnArgument ret(typeName, result);
|
| 63 |
+
QList<QGenericArgument> genericArgs;
|
| 64 |
+
QList<QVariant>::ConstIterator iter = args.begin();
|
| 65 |
+
while (iter != args.end()) {
|
| 66 |
+
const void *data = iter->data();
|
| 67 |
+
const char *name = iter->typeName();
|
| 68 |
+
genericArgs << QGenericArgument(name, data);
|
| 69 |
+
++iter;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if (QMetaObject::invokeMethod(this, method.constData(), ret,
|
| 73 |
+
genericArgs.value(0, QGenericArgument()),
|
| 74 |
+
genericArgs.value(1, QGenericArgument()),
|
| 75 |
+
genericArgs.value(2, QGenericArgument()),
|
| 76 |
+
genericArgs.value(3, QGenericArgument()),
|
| 77 |
+
genericArgs.value(4, QGenericArgument()),
|
| 78 |
+
genericArgs.value(5, QGenericArgument()),
|
| 79 |
+
genericArgs.value(6, QGenericArgument()),
|
| 80 |
+
genericArgs.value(7, QGenericArgument()),
|
| 81 |
+
genericArgs.value(8, QGenericArgument()),
|
| 82 |
+
genericArgs.value(9, QGenericArgument()))) {
|
| 83 |
+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
| 84 |
+
QVariant returnValue(QMetaType(resultType), result);
|
| 85 |
+
#else
|
| 86 |
+
QVariant returnValue(resultType, result);
|
| 87 |
+
#endif
|
| 88 |
+
QMetaType::destroy(resultType, result);
|
| 89 |
+
return returnValue;
|
| 90 |
+
} else {
|
| 91 |
+
qDebug("No such method '%s'", method.constData());
|
| 92 |
+
return QVariant();
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
QList<QByteArray> QXmppInvokable::paramTypes(const QList<QVariant> ¶ms)
|
| 97 |
+
{
|
| 98 |
+
QList<QByteArray> types;
|
| 99 |
+
for (const auto &variant : std::as_const(params))
|
| 100 |
+
types << variant.typeName();
|
| 101 |
+
return types;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
void QXmppInvokable::buildMethodHash()
|
| 105 |
+
{
|
| 106 |
+
QWriteLocker locker(&m_lock);
|
| 107 |
+
if (m_methodHash.size() > 0)
|
| 108 |
+
return;
|
| 109 |
+
|
| 110 |
+
int methodCount = metaObject()->methodCount();
|
| 111 |
+
for (int idx = 0; idx < methodCount; ++idx) {
|
| 112 |
+
QByteArray signature = metaObject()->method(idx).methodSignature();
|
| 113 |
+
m_methodHash[signature.left(signature.indexOf('('))] = idx;
|
| 114 |
+
// qDebug() << metaObject()->method(idx).parameterTypes();
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
QStringList QXmppInvokable::interfaces() const
|
| 119 |
+
{
|
| 120 |
+
QStringList results;
|
| 121 |
+
int methodCount = metaObject()->methodCount();
|
| 122 |
+
for (int idx = 0; idx < methodCount; ++idx) {
|
| 123 |
+
if (metaObject()->method(idx).methodType() == QMetaMethod::Slot) {
|
| 124 |
+
QByteArray signature = metaObject()->method(idx).methodSignature();
|
| 125 |
+
results << signature.left(signature.indexOf('('));
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
return results;
|
| 129 |
+
}
|
pool/shard009/C++/0109988_ckeyboardeventstranslator.cpp
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**************************************************************************
|
| 2 |
+
* Copyright (C) 2008 by Paf *
|
| 3 |
+
* *
|
| 4 |
+
* This program is free software; you can redistribute it and/or modify *
|
| 5 |
+
* it under the terms of the GNU General Public License as published by *
|
| 6 |
+
* the Free Software Foundation; either version 2 of the License, or *
|
| 7 |
+
* (at your option) any later version. *
|
| 8 |
+
* *
|
| 9 |
+
* This program is distributed in the hope that it will be useful, *
|
| 10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 12 |
+
* GNU General Public License for more details. *
|
| 13 |
+
* *
|
| 14 |
+
* You should have received a copy of the GNU General Public License *
|
| 15 |
+
* along with this program; if not, write to the *
|
| 16 |
+
* Free Software Foundation, Inc., *
|
| 17 |
+
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
| 18 |
+
***************************************************************************/
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
#include <boost/shared_ptr.hpp>
|
| 22 |
+
#include <boost/lexical_cast.hpp>
|
| 23 |
+
|
| 24 |
+
#include "../include/ckeyboardeventstranslator.h"
|
| 25 |
+
#include "../include/ctranslationevents.h"
|
| 26 |
+
#include "../../dynamicobject/include/dynamicobjectmanager.h"
|
| 27 |
+
#include "../../dynamicobject/include/float.h"
|
| 28 |
+
#include "../../core/include/cmessagemodule.h"
|
| 29 |
+
#include "../../log/include/clogmodule.h"
|
| 30 |
+
#include "../include/cinputmouseevents.h"
|
| 31 |
+
#include <OIS/OISKeyboard.h>
|
| 32 |
+
#include "../../time/include/ctimemodule.h"
|
| 33 |
+
|
| 34 |
+
#include "../../config.h"
|
| 35 |
+
|
| 36 |
+
using namespace boost;
|
| 37 |
+
using namespace Gnoll::Core;
|
| 38 |
+
using namespace Gnoll::DynamicObject;
|
| 39 |
+
using namespace Gnoll::Time;
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
namespace Gnoll
|
| 43 |
+
{
|
| 44 |
+
namespace Input
|
| 45 |
+
{
|
| 46 |
+
|
| 47 |
+
CKeyboardEventsTranslator::CKeyboardEventsTranslator(): keyUp("KEYBOARD_KEYUP"), keyDown("KEYBOARD_KEYDOWN"), m_lastTimeTriggerCalled(0)
|
| 48 |
+
{
|
| 49 |
+
|
| 50 |
+
DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr();
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Loading translation map : Keycode -> Action
|
| 55 |
+
*/
|
| 56 |
+
this->keyboardEventTranslationMap = pom->load("keyboardEventTranslationMap");
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Keyboard config
|
| 61 |
+
*/
|
| 62 |
+
this->keyboardConfig = pom->load("keyboardConfig");
|
| 63 |
+
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
CKeyboardEventsTranslator::~CKeyboardEventsTranslator()
|
| 68 |
+
{
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
void CKeyboardEventsTranslator::handle ( shared_ptr<CMessage> message )
|
| 73 |
+
{
|
| 74 |
+
/**
|
| 75 |
+
* Get the key code
|
| 76 |
+
*/
|
| 77 |
+
OIS::KeyCode keyCode = message->getData<OIS::KeyCode>();
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Get the value and convert it to a string
|
| 82 |
+
*/
|
| 83 |
+
string keyCodeValue = lexical_cast<string> (keyCode);
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "Looking for KeyCode [" + keyCodeValue + "]");
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* If an action is associated to this key code, an action message is sent
|
| 90 |
+
*/
|
| 91 |
+
if ( keyboardEventTranslationMap->hasAttribute(keyCodeValue) )
|
| 92 |
+
{
|
| 93 |
+
CTimeModule* timeModule = CTimeModule::getInstancePtr();
|
| 94 |
+
|
| 95 |
+
Messages::MessageType messageType = message->getType();
|
| 96 |
+
|
| 97 |
+
if (messageType == keyDown)
|
| 98 |
+
{
|
| 99 |
+
m_keyPressed[keyCodeValue] = timeModule->getMsecs();
|
| 100 |
+
|
| 101 |
+
if (m_durationKeyPressed.find(keyCodeValue) == m_durationKeyPressed.end())
|
| 102 |
+
{
|
| 103 |
+
m_durationKeyPressed[keyCodeValue] = 0;
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
else
|
| 107 |
+
{
|
| 108 |
+
m_durationKeyPressed[keyCodeValue] += timeModule->getMsecs() - m_keyPressed[keyCodeValue];
|
| 109 |
+
m_keyPressed[keyCodeValue] = 0;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
void CKeyboardEventsTranslator::trigger ( shared_ptr<CMessage> _msg )
|
| 118 |
+
{
|
| 119 |
+
|
| 120 |
+
Messages::MessageType actionEventType(ACTION_EVENT_TYPE);
|
| 121 |
+
CTimeModule* timeModule = CTimeModule::getInstancePtr();
|
| 122 |
+
|
| 123 |
+
shared_ptr<Float> defaultKeyboardSensibility = shared_ptr<Float> (new Float(1.0f));
|
| 124 |
+
shared_ptr< Gnoll::DynamicObject::Float > keyboardSensibility = keyboardConfig->getAttributeOrDefault<Float>("sensibility", defaultKeyboardSensibility);
|
| 125 |
+
|
| 126 |
+
unsigned long int now = timeModule->getMsecs();
|
| 127 |
+
unsigned long int period = now - m_lastTimeTriggerCalled;
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
for( map<string, unsigned long int>::iterator it = m_durationKeyPressed.begin(); it != m_durationKeyPressed.end(); it++)
|
| 131 |
+
{
|
| 132 |
+
unsigned long int timePressed = it->second;
|
| 133 |
+
|
| 134 |
+
if (m_keyPressed[it->first] != 0)
|
| 135 |
+
{
|
| 136 |
+
timePressed += now - m_keyPressed[it->first];
|
| 137 |
+
|
| 138 |
+
m_keyPressed[it->first] = now;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
if (timePressed > 0)
|
| 143 |
+
{
|
| 144 |
+
|
| 145 |
+
float intensity = (float) timePressed / (float) period * (*keyboardSensibility);
|
| 146 |
+
|
| 147 |
+
shared_ptr<List> actionList = keyboardEventTranslationMap->getAttribute<List>( it->first );
|
| 148 |
+
typedef list< shared_ptr<IAttribute> >::iterator ListIterator;
|
| 149 |
+
|
| 150 |
+
/**
|
| 151 |
+
* Send all action messages in the list
|
| 152 |
+
*/
|
| 153 |
+
for (ListIterator itAttrs = actionList->begin(); itAttrs != actionList->end(); itAttrs++)
|
| 154 |
+
{
|
| 155 |
+
if (shared_ptr<String> actionName = dynamic_pointer_cast<String>(*itAttrs))
|
| 156 |
+
{
|
| 157 |
+
ActionEvent actionEvent(*actionName, intensity);
|
| 158 |
+
|
| 159 |
+
shared_ptr<boost::any> data (new boost::any(actionEvent) ) ;
|
| 160 |
+
shared_ptr<CMessage> actionMessage (new CMessage( actionEventType, data ));
|
| 161 |
+
|
| 162 |
+
std::ostringstream tmpString;
|
| 163 |
+
|
| 164 |
+
try
|
| 165 |
+
{
|
| 166 |
+
CMessageModule::getInstancePtr()->getMessageManager()->queueMessage(actionMessage);
|
| 167 |
+
tmpString << "Message ajoute ["<< *actionName << "]" << endl;
|
| 168 |
+
}
|
| 169 |
+
catch(...)
|
| 170 |
+
{
|
| 171 |
+
tmpString << "Message NON ajoute ["<< *actionName << "]" << " of intensity ";
|
| 172 |
+
tmpString << intensity << " => " << timePressed << " / " << period << endl;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
Gnoll::Log::CLogModule::getInstancePtr()->logMessage( tmpString.str() );
|
| 176 |
+
|
| 177 |
+
it->second = 0;
|
| 178 |
+
}
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
m_lastTimeTriggerCalled = now;
|
| 184 |
+
}
|
| 185 |
+
};
|
| 186 |
+
};
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
|
pool/shard009/C++/0109996_CCTiledLayerTestCommon.cpp
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2012 Google Inc. All rights reserved.
|
| 3 |
+
*
|
| 4 |
+
* Redistribution and use in source and binary forms, with or without
|
| 5 |
+
* modification, are permitted provided that the following conditions
|
| 6 |
+
* are met:
|
| 7 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 8 |
+
* notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
* documentation and/or other materials provided with the distribution.
|
| 12 |
+
*
|
| 13 |
+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
|
| 14 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 15 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 16 |
+
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
|
| 17 |
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
| 20 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 22 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
#include "config.h"
|
| 26 |
+
|
| 27 |
+
#include "CCTiledLayerTestCommon.h"
|
| 28 |
+
|
| 29 |
+
using namespace WebCore;
|
| 30 |
+
|
| 31 |
+
namespace WebKitTests {
|
| 32 |
+
|
| 33 |
+
FakeLayerTextureUpdater::Texture::Texture(FakeLayerTextureUpdater* layer, PassOwnPtr<CCPrioritizedTexture> texture)
|
| 34 |
+
: LayerTextureUpdater::Texture(texture)
|
| 35 |
+
, m_layer(layer)
|
| 36 |
+
{
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
FakeLayerTextureUpdater::Texture::~Texture()
|
| 40 |
+
{
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
void FakeLayerTextureUpdater::Texture::updateRect(CCResourceProvider* resourceProvider, const IntRect&, const IntRect&)
|
| 44 |
+
{
|
| 45 |
+
texture()->acquireBackingTexture(resourceProvider);
|
| 46 |
+
m_layer->updateRect();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void FakeLayerTextureUpdater::Texture::prepareRect(const IntRect&, WebCore::CCRenderingStats&)
|
| 50 |
+
{
|
| 51 |
+
m_layer->prepareRect();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
FakeLayerTextureUpdater::FakeLayerTextureUpdater()
|
| 55 |
+
: m_prepareCount(0)
|
| 56 |
+
, m_updateCount(0)
|
| 57 |
+
, m_prepareRectCount(0)
|
| 58 |
+
{
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
FakeLayerTextureUpdater::~FakeLayerTextureUpdater()
|
| 62 |
+
{
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
void FakeLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize&, float, float, IntRect& resultingOpaqueRect, CCRenderingStats&)
|
| 66 |
+
{
|
| 67 |
+
m_prepareCount++;
|
| 68 |
+
m_lastUpdateRect = contentRect;
|
| 69 |
+
if (!m_rectToInvalidate.isEmpty()) {
|
| 70 |
+
m_layer->invalidateContentRect(m_rectToInvalidate);
|
| 71 |
+
m_rectToInvalidate = IntRect();
|
| 72 |
+
m_layer = 0;
|
| 73 |
+
}
|
| 74 |
+
resultingOpaqueRect = m_opaquePaintRect;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
void FakeLayerTextureUpdater::setRectToInvalidate(const IntRect& rect, FakeTiledLayerChromium* layer)
|
| 78 |
+
{
|
| 79 |
+
m_rectToInvalidate = rect;
|
| 80 |
+
m_layer = layer;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
PassOwnPtr<LayerTextureUpdater::Texture> FakeLayerTextureUpdater::createTexture(CCPrioritizedTextureManager* manager)
|
| 84 |
+
{
|
| 85 |
+
return adoptPtr(new Texture(this, CCPrioritizedTexture::create(manager)));
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
FakeCCTiledLayerImpl::FakeCCTiledLayerImpl(int id)
|
| 89 |
+
: CCTiledLayerImpl(id)
|
| 90 |
+
{
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
FakeCCTiledLayerImpl::~FakeCCTiledLayerImpl()
|
| 94 |
+
{
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
FakeTiledLayerChromium::FakeTiledLayerChromium(CCPrioritizedTextureManager* textureManager)
|
| 98 |
+
: TiledLayerChromium()
|
| 99 |
+
, m_fakeTextureUpdater(adoptRef(new FakeLayerTextureUpdater))
|
| 100 |
+
, m_textureManager(textureManager)
|
| 101 |
+
{
|
| 102 |
+
setTileSize(tileSize());
|
| 103 |
+
setTextureFormat(GraphicsContext3D::RGBA);
|
| 104 |
+
setBorderTexelOption(CCLayerTilingData::NoBorderTexels);
|
| 105 |
+
setIsDrawable(true); // So that we don't get false positives if any of these tests expect to return false from drawsContent() for other reasons.
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
FakeTiledLayerChromium::~FakeTiledLayerChromium()
|
| 109 |
+
{
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
void FakeTiledLayerChromium::setNeedsDisplayRect(const FloatRect& rect)
|
| 113 |
+
{
|
| 114 |
+
m_lastNeedsDisplayRect = rect;
|
| 115 |
+
TiledLayerChromium::setNeedsDisplayRect(rect);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
void FakeTiledLayerChromium::update(CCTextureUpdater& updater, const CCOcclusionTracker* occlusion, CCRenderingStats& stats)
|
| 119 |
+
{
|
| 120 |
+
updateContentRect(updater, visibleContentRect(), occlusion, stats);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
void FakeTiledLayerChromium::setTexturePriorities(const CCPriorityCalculator& calculator)
|
| 124 |
+
{
|
| 125 |
+
// Ensure there is always a target render surface available. If none has been
|
| 126 |
+
// set (the layer is an orphan for the test), then just set a surface on itself.
|
| 127 |
+
bool missingTargetRenderSurface = !renderTarget();
|
| 128 |
+
|
| 129 |
+
if (missingTargetRenderSurface)
|
| 130 |
+
createRenderSurface();
|
| 131 |
+
|
| 132 |
+
TiledLayerChromium::setTexturePriorities(calculator);
|
| 133 |
+
|
| 134 |
+
if (missingTargetRenderSurface) {
|
| 135 |
+
clearRenderSurface();
|
| 136 |
+
setRenderTarget(0);
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
FakeTiledLayerWithScaledBounds::FakeTiledLayerWithScaledBounds(CCPrioritizedTextureManager* textureManager)
|
| 141 |
+
: FakeTiledLayerChromium(textureManager)
|
| 142 |
+
{
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
} // namespace
|
pool/shard009/C++/0110000_Blob.cpp
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (c) 2012-2015, Coherent Labs AD
|
| 3 |
+
All rights reserved.
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without
|
| 6 |
+
modification, are permitted provided that the following conditions are met:
|
| 7 |
+
|
| 8 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 9 |
+
list of conditions and the following disclaimer.
|
| 10 |
+
|
| 11 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 12 |
+
this list of conditions and the following disclaimer in the documentation
|
| 13 |
+
and/or other materials provided with the distribution.
|
| 14 |
+
|
| 15 |
+
* Neither the name of Coherent UI nor the names of its
|
| 16 |
+
contributors may be used to endorse or promote products derived from
|
| 17 |
+
this software without specific prior written permission.
|
| 18 |
+
|
| 19 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 20 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 21 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 22 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 23 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 24 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 25 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 26 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 27 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 28 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
*/
|
| 30 |
+
#include "precompiled.h"
|
| 31 |
+
|
| 32 |
+
#include <Binding/Blob/Blob.h>
|
| 33 |
+
|
| 34 |
+
namespace Coherent
|
| 35 |
+
{
|
| 36 |
+
namespace Blob
|
| 37 |
+
{
|
| 38 |
+
const Value* GetNextValue(const Value* value)
|
| 39 |
+
{
|
| 40 |
+
return reinterpret_cast<const Value*>(reinterpret_cast<const char*>(value) + value->GetSize());
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
template <typename T>
|
| 44 |
+
T& Value::As()
|
| 45 |
+
{
|
| 46 |
+
return *reinterpret_cast<T*>(m_Storage);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
template Null& Value::As<Null>();
|
| 50 |
+
template Boolean& Value::As<Boolean>();
|
| 51 |
+
template Integer& Value::As<Integer>();
|
| 52 |
+
template UInteger& Value::As<UInteger>();
|
| 53 |
+
template Number& Value::As<Number>();
|
| 54 |
+
template String& Value::As<String>();
|
| 55 |
+
template Array& Value::As<Array>();
|
| 56 |
+
template Object& Value::As<Object>();
|
| 57 |
+
template Integer64& Value::As<Integer64>();
|
| 58 |
+
template WString& Value::As<WString>();
|
| 59 |
+
template Byte& Value::As<Byte>();
|
| 60 |
+
template UByte& Value::As<UByte>();
|
| 61 |
+
|
| 62 |
+
template <typename T>
|
| 63 |
+
const T& Value::As() const
|
| 64 |
+
{
|
| 65 |
+
return *reinterpret_cast<const T*>(m_Storage);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
template const Null& Value::As<Null>() const;
|
| 69 |
+
template const Boolean& Value::As<Boolean>() const;
|
| 70 |
+
template const Integer& Value::As<Integer>() const;
|
| 71 |
+
template const UInteger& Value::As<UInteger>() const;
|
| 72 |
+
template const Number& Value::As<Number>() const;
|
| 73 |
+
template const String& Value::As<String>() const;
|
| 74 |
+
template const Array& Value::As<Array>() const;
|
| 75 |
+
template const Object& Value::As<Object>() const;
|
| 76 |
+
template const Integer64& Value::As<Integer64>() const;
|
| 77 |
+
template const WString& Value::As<WString>() const;
|
| 78 |
+
template const Byte& Value::As<Byte>() const;
|
| 79 |
+
template const UByte& Value::As<UByte>() const;
|
| 80 |
+
|
| 81 |
+
struct SizeGetter
|
| 82 |
+
{
|
| 83 |
+
typedef size_t ResultType;
|
| 84 |
+
|
| 85 |
+
template <typename T>
|
| 86 |
+
ResultType Invoke(T& value) const
|
| 87 |
+
{
|
| 88 |
+
return value.GetSizeInBytes();
|
| 89 |
+
}
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
size_t Value::GetSize() const
|
| 93 |
+
{
|
| 94 |
+
return sizeof(AlignedType) + Invoke(SizeGetter());
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
Array::ConstIterator::ConstIterator(const Value* value) : m_Value(value)
|
| 98 |
+
{
|
| 99 |
+
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
Array::ConstIterator::~ConstIterator()
|
| 103 |
+
{
|
| 104 |
+
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
const Value& Array::ConstIterator::operator*() const
|
| 108 |
+
{
|
| 109 |
+
return *m_Value;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
const Value* Array::ConstIterator::operator->() const
|
| 113 |
+
{
|
| 114 |
+
return m_Value;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
Array::ConstIterator& Array::ConstIterator::operator++()
|
| 118 |
+
{
|
| 119 |
+
m_Value = GetNextValue(m_Value);
|
| 120 |
+
return *this;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
bool Array::ConstIterator::operator==(const ConstIterator& rhs) const
|
| 124 |
+
{
|
| 125 |
+
return m_Value == rhs.m_Value;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
bool Array::ConstIterator::operator!=(const ConstIterator& rhs) const
|
| 129 |
+
{
|
| 130 |
+
return m_Value != rhs.m_Value;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
Array::ConstIterator Array::Begin() const
|
| 134 |
+
{
|
| 135 |
+
return ConstIterator(reinterpret_cast<const Value*>(m_Storage));
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
Array::ConstIterator Array::End() const
|
| 139 |
+
{
|
| 140 |
+
return ConstIterator(reinterpret_cast<const Value*>(m_Storage + m_Size - 2 * sizeof(AlignedType)));
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
const Value* Object::EndOfStorage() const
|
| 144 |
+
{
|
| 145 |
+
return reinterpret_cast<const Value*>(m_Storage + m_Size - 2 * sizeof(AlignedType));
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
Object::ConstIterator Object::Begin() const
|
| 149 |
+
{
|
| 150 |
+
return ConstIterator(reinterpret_cast<const Value*>(m_Storage), EndOfStorage());
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
Object::ConstIterator Object::End() const
|
| 154 |
+
{
|
| 155 |
+
const Value* end = EndOfStorage();
|
| 156 |
+
return ConstIterator(end, end);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
Object::ConstIterator::ConstIterator(const Value* begin, const Value* end)
|
| 161 |
+
: m_Value(begin, nullptr)
|
| 162 |
+
, m_End(end)
|
| 163 |
+
{
|
| 164 |
+
if (m_Value.first != m_End)
|
| 165 |
+
{
|
| 166 |
+
m_Value.second = GetNextValue(m_Value.first);
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
Object::ConstIterator::~ConstIterator()
|
| 171 |
+
{
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
Object::ConstIterator& Object::ConstIterator::operator++()
|
| 176 |
+
{
|
| 177 |
+
m_Value.first = GetNextValue(m_Value.second);
|
| 178 |
+
if (m_Value.first != m_End)
|
| 179 |
+
{
|
| 180 |
+
m_Value.second = GetNextValue(m_Value.first);
|
| 181 |
+
}
|
| 182 |
+
return *this;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
const Object::ConstIterator::value_type& Object::ConstIterator::operator*() const
|
| 186 |
+
{
|
| 187 |
+
return m_Value;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
const Object::ConstIterator::value_type* Object::ConstIterator::operator->() const
|
| 191 |
+
{
|
| 192 |
+
return &m_Value;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
bool Object::ConstIterator::operator==(const Object::ConstIterator& rhs) const
|
| 196 |
+
{
|
| 197 |
+
return m_Value.first == rhs.m_Value.first && m_End == rhs.m_End;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
bool Object::ConstIterator::operator!=(const Object::ConstIterator& rhs) const
|
| 201 |
+
{
|
| 202 |
+
return m_Value.first != rhs.m_Value.first || m_End != rhs.m_End;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
}
|
| 208 |
+
}
|
pool/shard009/C++/0110004_cv_api.cc
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 3 |
+
* or more contributor license agreements. See the NOTICE file
|
| 4 |
+
* distributed with this work for additional information
|
| 5 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 6 |
+
* to you under the Apache License, Version 2.0 (the
|
| 7 |
+
* "License"); you may not use this file except in compliance
|
| 8 |
+
* with the License. You may obtain a copy of the License at
|
| 9 |
+
*
|
| 10 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
*
|
| 12 |
+
* Unless required by applicable law or agreed to in writing,
|
| 13 |
+
* software distributed under the License is distributed on an
|
| 14 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 15 |
+
* KIND, either express or implied. See the License for the
|
| 16 |
+
* specific language governing permissions and limitations
|
| 17 |
+
* under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
/*!
|
| 21 |
+
* Copyright (c) 2016 by Contributors
|
| 22 |
+
* \file cv_api.h
|
| 23 |
+
* \brief C API for opencv
|
| 24 |
+
* \author Junyuan Xie
|
| 25 |
+
*/
|
| 26 |
+
#include <dmlc/base.h>
|
| 27 |
+
#include <mxnet/base.h>
|
| 28 |
+
#include <mxnet/ndarray.h>
|
| 29 |
+
#include <opencv2/opencv.hpp>
|
| 30 |
+
#include "cv_api.h"
|
| 31 |
+
#include "../../src/c_api/c_api_common.h"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
using namespace mxnet;
|
| 35 |
+
// http://www.64lines.com/jpeg-width-height
|
| 36 |
+
// Gets the JPEG size from the array of data passed to the function, file reference: http://www.obrador.com/essentialjpeg/headerinfo.htm
|
| 37 |
+
bool get_jpeg_size(const unsigned char* data, mx_uint data_size, mx_uint *width, mx_uint *height) {
|
| 38 |
+
// Check for valid JPEG image
|
| 39 |
+
mx_uint i = 0; // Keeps track of the position within the file
|
| 40 |
+
if (data[i] == 0xFF && data[i+1] == 0xD8 && data[i+2] == 0xFF && data[i+3] == 0xE0) {
|
| 41 |
+
i += 4;
|
| 42 |
+
// Check for valid JPEG header (null terminated JFIF)
|
| 43 |
+
if (data[i+2] == 'J' && data[i+3] == 'F' && data[i+4] == 'I'
|
| 44 |
+
&& data[i+5] == 'F' && data[i+6] == 0x00) {
|
| 45 |
+
// Retrieve the block length of the first block since
|
| 46 |
+
// the first block will not contain the size of file
|
| 47 |
+
uint16_t block_length = data[i] * 256 + data[i+1];
|
| 48 |
+
while (i < data_size) {
|
| 49 |
+
i+=block_length; // Increase the file index to get to the next block
|
| 50 |
+
if (i >= data_size) return false; // Check to protect against segmentation faults
|
| 51 |
+
if (data[i] != 0xFF) return false; // Check that we are truly at the start of another block
|
| 52 |
+
if (data[i+1] == 0xC0) {
|
| 53 |
+
// 0xFFC0 is the "Start of frame" marker which contains the file size
|
| 54 |
+
// The structure of the 0xFFC0 block is quite simple
|
| 55 |
+
// [0xFFC0][ushort length][uchar precision][ushort x][ushort y]
|
| 56 |
+
*height = data[i+5]*256 + data[i+6];
|
| 57 |
+
*width = data[i+7]*256 + data[i+8];
|
| 58 |
+
return true;
|
| 59 |
+
} else {
|
| 60 |
+
i+=2; // Skip the block marker
|
| 61 |
+
block_length = data[i] * 256 + data[i+1]; // Go to the next block
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
return false; // If this point is reached then no size was found
|
| 65 |
+
} else {
|
| 66 |
+
return false; // Not a valid JFIF string
|
| 67 |
+
}
|
| 68 |
+
} else {
|
| 69 |
+
return false; // Not a valid SOI header
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
bool get_png_size(const unsigned char* data, mx_uint data_size, mx_uint *width, mx_uint *height) {
|
| 74 |
+
if (data[0] == 0x89 && data[1] == 0x50 && data[2] ==0x4E && data[3] == 0x47) {
|
| 75 |
+
unsigned char const* p = data + 16;
|
| 76 |
+
*width = ((p[0]*256 + p[1])*256 + p[2])*256 + p[3];
|
| 77 |
+
p += 4;
|
| 78 |
+
*height = ((p[0]*256 + p[1])*256 + p[2])*256 + p[3];
|
| 79 |
+
return true;
|
| 80 |
+
} else {
|
| 81 |
+
return false;
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
MXNET_DLL int MXCVImdecode(const unsigned char *img, const mx_uint len,
|
| 86 |
+
const int flag, NDArrayHandle *out) {
|
| 87 |
+
API_BEGIN();
|
| 88 |
+
mx_uint dims[3];
|
| 89 |
+
CHECK_GE(flag, 0) << "flag must be 0 (grayscale) or 1 (colored).";
|
| 90 |
+
dims[2] = flag == 0 ? 1 : 3;
|
| 91 |
+
if (get_jpeg_size(img, len, dims+1, dims)) {
|
| 92 |
+
} else if (get_png_size(img, len, dims+1, dims)) {
|
| 93 |
+
} else {
|
| 94 |
+
LOG(FATAL) << "Only supports png and jpg.";
|
| 95 |
+
}
|
| 96 |
+
NDArray ndout(mxnet::TShape(dims, dims+3), Context::CPU(), true, mshadow::kUint8);
|
| 97 |
+
unsigned char *img_cpy = new unsigned char[len];
|
| 98 |
+
memcpy(img_cpy, img, sizeof(unsigned char)*len);
|
| 99 |
+
Engine::Get()->PushSync([=](RunContext ctx){
|
| 100 |
+
ndout.CheckAndAlloc();
|
| 101 |
+
cv::Mat buf(1, len, CV_8U, img_cpy);
|
| 102 |
+
cv::Mat dst(dims[0], dims[1], flag == 0 ? CV_8U : CV_8UC3, ndout.data().dptr_);
|
| 103 |
+
#if (CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >= 3))
|
| 104 |
+
cv::imdecode(buf, flag | cv::IMREAD_IGNORE_ORIENTATION, &dst);
|
| 105 |
+
#else
|
| 106 |
+
cv::imdecode(buf, flag, &dst);
|
| 107 |
+
#endif
|
| 108 |
+
CHECK(!dst.empty());
|
| 109 |
+
delete[] img_cpy;
|
| 110 |
+
}, ndout.ctx(), {}, {ndout.var()});
|
| 111 |
+
NDArray *tmp = new NDArray();
|
| 112 |
+
*tmp = ndout;
|
| 113 |
+
*out = tmp;
|
| 114 |
+
API_END();
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
MXNET_DLL int MXCVResize(NDArrayHandle src, const mx_uint w, const mx_uint h,
|
| 119 |
+
const int interpolation, NDArrayHandle *out) {
|
| 120 |
+
API_BEGIN();
|
| 121 |
+
NDArray ndsrc = *static_cast<NDArray*>(src);
|
| 122 |
+
CHECK_EQ(ndsrc.shape().ndim(), 3);
|
| 123 |
+
CHECK_EQ(ndsrc.ctx(), Context::CPU());
|
| 124 |
+
CHECK_EQ(ndsrc.dtype(), mshadow::kUint8);
|
| 125 |
+
|
| 126 |
+
mx_uint dims[3] = {h, w, ndsrc.shape()[2]};
|
| 127 |
+
NDArray ndout(mxnet::TShape(dims, dims+3), Context::CPU(), true, mshadow::kUint8);
|
| 128 |
+
|
| 129 |
+
Engine::Get()->PushSync([=](RunContext ctx){
|
| 130 |
+
ndout.CheckAndAlloc();
|
| 131 |
+
cv::Mat buf(ndsrc.shape()[0], ndsrc.shape()[1],
|
| 132 |
+
dims[2] == 3 ? CV_8UC3 : CV_8U, ndsrc.data().dptr_);
|
| 133 |
+
cv::Mat dst(h, w, dims[2] == 3 ? CV_8UC3 : CV_8U, ndout.data().dptr_);
|
| 134 |
+
cv::resize(buf, dst, cv::Size(w, h), 0, 0, interpolation);
|
| 135 |
+
CHECK(!dst.empty());
|
| 136 |
+
}, ndout.ctx(), {ndsrc.var()}, {ndout.var()});
|
| 137 |
+
NDArray *tmp = new NDArray();
|
| 138 |
+
*tmp = ndout;
|
| 139 |
+
*out = tmp;
|
| 140 |
+
API_END();
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
MXNET_DLL int MXCVcopyMakeBorder(NDArrayHandle src,
|
| 144 |
+
const int top,
|
| 145 |
+
const int bot,
|
| 146 |
+
const int left,
|
| 147 |
+
const int right,
|
| 148 |
+
const int type,
|
| 149 |
+
const double value,
|
| 150 |
+
NDArrayHandle *out) {
|
| 151 |
+
API_BEGIN();
|
| 152 |
+
NDArray ndsrc = *static_cast<NDArray*>(src);
|
| 153 |
+
CHECK_EQ(ndsrc.shape().ndim(), 3);
|
| 154 |
+
CHECK_EQ(ndsrc.ctx(), Context::CPU());
|
| 155 |
+
CHECK_EQ(ndsrc.dtype(), mshadow::kUint8);
|
| 156 |
+
|
| 157 |
+
int h = ndsrc.shape()[0], w = ndsrc.shape()[1], c = ndsrc.shape()[2];
|
| 158 |
+
mx_uint dims[3] = {top+h+bot, left+w+right, c};
|
| 159 |
+
NDArray ndout(mxnet::TShape(dims, dims+3), Context::CPU(), true, mshadow::kUint8);
|
| 160 |
+
|
| 161 |
+
Engine::Get()->PushSync([=](RunContext ctx){
|
| 162 |
+
ndout.CheckAndAlloc();
|
| 163 |
+
cv::Mat buf(h, w, c == 3 ? CV_8UC3 : CV_8U, ndsrc.data().dptr_);
|
| 164 |
+
cv::Mat dst(top+h+bot, left+w+right, c == 3 ? CV_8UC3 : CV_8U, ndout.data().dptr_);
|
| 165 |
+
cv::copyMakeBorder(buf, dst, top, bot, left, right, type, cv::Scalar(value));
|
| 166 |
+
CHECK(!dst.empty());
|
| 167 |
+
}, ndout.ctx(), {ndsrc.var()}, {ndout.var()});
|
| 168 |
+
NDArray *tmp = new NDArray();
|
| 169 |
+
*tmp = ndout;
|
| 170 |
+
*out = tmp;
|
| 171 |
+
API_END();
|
| 172 |
+
}
|
pool/shard009/C++/0110005_gesture_point.cc
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "ui/base/gestures/gesture_point.h"
|
| 6 |
+
|
| 7 |
+
#include <cmath>
|
| 8 |
+
|
| 9 |
+
#include "base/basictypes.h"
|
| 10 |
+
#include "ui/base/events/event.h"
|
| 11 |
+
#include "ui/base/events/event_constants.h"
|
| 12 |
+
#include "ui/base/gestures/gesture_configuration.h"
|
| 13 |
+
#include "ui/base/gestures/gesture_types.h"
|
| 14 |
+
#include "ui/base/gestures/gesture_util.h"
|
| 15 |
+
|
| 16 |
+
namespace ui {
|
| 17 |
+
|
| 18 |
+
GesturePoint::GesturePoint()
|
| 19 |
+
: first_touch_time_(0.0),
|
| 20 |
+
last_touch_time_(0.0),
|
| 21 |
+
last_tap_time_(0.0),
|
| 22 |
+
velocity_calculator_(
|
| 23 |
+
GestureConfiguration::points_buffered_for_velocity()),
|
| 24 |
+
point_id_(-1),
|
| 25 |
+
touch_id_(-1) {
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
GesturePoint::~GesturePoint() {}
|
| 29 |
+
|
| 30 |
+
void GesturePoint::Reset() {
|
| 31 |
+
first_touch_time_ = last_touch_time_ = 0.0;
|
| 32 |
+
velocity_calculator_.ClearHistory();
|
| 33 |
+
point_id_ = -1;
|
| 34 |
+
clear_enclosing_rectangle();
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void GesturePoint::ResetVelocity() {
|
| 38 |
+
velocity_calculator_.ClearHistory();
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
void GesturePoint::UpdateValues(const TouchEvent& event) {
|
| 42 |
+
const int64 event_timestamp_microseconds =
|
| 43 |
+
event.time_stamp().InMicroseconds();
|
| 44 |
+
if (event.type() == ui::ET_TOUCH_MOVED) {
|
| 45 |
+
velocity_calculator_.PointSeen(event.location().x(),
|
| 46 |
+
event.location().y(),
|
| 47 |
+
event_timestamp_microseconds);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
last_touch_time_ = event.time_stamp().InSecondsF();
|
| 51 |
+
last_touch_position_ = event.location();
|
| 52 |
+
|
| 53 |
+
if (event.type() == ui::ET_TOUCH_PRESSED) {
|
| 54 |
+
first_touch_time_ = last_touch_time_;
|
| 55 |
+
first_touch_position_ = event.location();
|
| 56 |
+
velocity_calculator_.ClearHistory();
|
| 57 |
+
velocity_calculator_.PointSeen(event.location().x(),
|
| 58 |
+
event.location().y(),
|
| 59 |
+
event_timestamp_microseconds);
|
| 60 |
+
clear_enclosing_rectangle();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
UpdateEnclosingRectangle(event);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
void GesturePoint::UpdateForTap() {
|
| 67 |
+
// Update the tap-position and time, and reset every other state.
|
| 68 |
+
last_tap_time_ = last_touch_time_;
|
| 69 |
+
last_tap_position_ = last_touch_position_;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
void GesturePoint::UpdateForScroll() {
|
| 73 |
+
// Update the first-touch position and time so that the scroll-delta and
|
| 74 |
+
// scroll-velocity can be computed correctly for the next scroll gesture
|
| 75 |
+
// event.
|
| 76 |
+
first_touch_position_ = last_touch_position_;
|
| 77 |
+
first_touch_time_ = last_touch_time_;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
bool GesturePoint::IsInClickWindow(const TouchEvent& event) const {
|
| 81 |
+
return IsInClickTimeWindow() && IsInsideManhattanSquare(event);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
bool GesturePoint::IsInDoubleClickWindow(const TouchEvent& event) const {
|
| 85 |
+
return IsInSecondClickTimeWindow() &&
|
| 86 |
+
IsSecondClickInsideManhattanSquare(event);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const {
|
| 90 |
+
return event.type() == ui::ET_TOUCH_MOVED &&
|
| 91 |
+
!IsInsideManhattanSquare(event);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
bool GesturePoint::IsInFlickWindow(const TouchEvent& event) {
|
| 95 |
+
return IsOverMinFlickSpeed() &&
|
| 96 |
+
event.type() != ui::ET_TOUCH_CANCELLED;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
bool GesturePoint::DidScroll(const TouchEvent& event, int dist) const {
|
| 100 |
+
return abs(last_touch_position_.x() - first_touch_position_.x()) > dist ||
|
| 101 |
+
abs(last_touch_position_.y() - first_touch_position_.y()) > dist;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
bool GesturePoint::HasEnoughDataToEstablishRail() const {
|
| 105 |
+
int dx = x_delta();
|
| 106 |
+
int dy = y_delta();
|
| 107 |
+
|
| 108 |
+
int delta_squared = dx * dx + dy * dy;
|
| 109 |
+
return delta_squared > GestureConfiguration::min_scroll_delta_squared();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
bool GesturePoint::IsInHorizontalRailWindow() const {
|
| 113 |
+
int dx = x_delta();
|
| 114 |
+
int dy = y_delta();
|
| 115 |
+
return abs(dx) > GestureConfiguration::rail_start_proportion() * abs(dy);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
bool GesturePoint::IsInVerticalRailWindow() const {
|
| 119 |
+
int dx = x_delta();
|
| 120 |
+
int dy = y_delta();
|
| 121 |
+
return abs(dy) > GestureConfiguration::rail_start_proportion() * abs(dx);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
bool GesturePoint::BreaksHorizontalRail() {
|
| 125 |
+
float vx = XVelocity();
|
| 126 |
+
float vy = YVelocity();
|
| 127 |
+
return fabs(vy) > GestureConfiguration::rail_break_proportion() * fabs(vx) +
|
| 128 |
+
GestureConfiguration::min_rail_break_velocity();
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
bool GesturePoint::BreaksVerticalRail() {
|
| 132 |
+
float vx = XVelocity();
|
| 133 |
+
float vy = YVelocity();
|
| 134 |
+
return fabs(vx) > GestureConfiguration::rail_break_proportion() * fabs(vy) +
|
| 135 |
+
GestureConfiguration::min_rail_break_velocity();
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
bool GesturePoint::IsInClickTimeWindow() const {
|
| 139 |
+
double duration = last_touch_time_ - first_touch_time_;
|
| 140 |
+
return duration >=
|
| 141 |
+
GestureConfiguration::min_touch_down_duration_in_seconds_for_click() &&
|
| 142 |
+
duration <
|
| 143 |
+
GestureConfiguration::max_touch_down_duration_in_seconds_for_click();
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
bool GesturePoint::IsInSecondClickTimeWindow() const {
|
| 147 |
+
double duration = last_touch_time_ - last_tap_time_;
|
| 148 |
+
return duration < GestureConfiguration::max_seconds_between_double_click();
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
bool GesturePoint::IsInsideManhattanSquare(const TouchEvent& event) const {
|
| 152 |
+
return ui::gestures::IsInsideManhattanSquare(event.location(),
|
| 153 |
+
first_touch_position_);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
bool GesturePoint::IsSecondClickInsideManhattanSquare(
|
| 157 |
+
const TouchEvent& event) const {
|
| 158 |
+
int manhattan_distance = abs(event.location().x() - last_tap_position_.x()) +
|
| 159 |
+
abs(event.location().y() - last_tap_position_.y());
|
| 160 |
+
return manhattan_distance <
|
| 161 |
+
GestureConfiguration::max_distance_between_taps_for_double_tap();
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
bool GesturePoint::IsOverMinFlickSpeed() {
|
| 165 |
+
return velocity_calculator_.VelocitySquared() >
|
| 166 |
+
GestureConfiguration::min_flick_speed_squared();
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
void GesturePoint::UpdateEnclosingRectangle(const TouchEvent& event) {
|
| 170 |
+
int radius;
|
| 171 |
+
|
| 172 |
+
// Ignore this TouchEvent if it has a radius larger than the maximum
|
| 173 |
+
// allowed radius size.
|
| 174 |
+
if (event.radius_x() > GestureConfiguration::max_radius() ||
|
| 175 |
+
event.radius_y() > GestureConfiguration::max_radius())
|
| 176 |
+
return;
|
| 177 |
+
|
| 178 |
+
// If the device provides at least one of the radius values, take the larger
|
| 179 |
+
// of the two and use this as both the x radius and the y radius of the
|
| 180 |
+
// touch region. Otherwise use the default radius value.
|
| 181 |
+
// TODO(tdanderson): Implement a more specific check for the exact
|
| 182 |
+
// information provided by the device (0-2 radii values, force, angle) and
|
| 183 |
+
// use this to compute a more representative rectangular touch region.
|
| 184 |
+
if (event.radius_x() || event.radius_y())
|
| 185 |
+
radius = std::max(event.radius_x(), event.radius_y());
|
| 186 |
+
else
|
| 187 |
+
radius = GestureConfiguration::default_radius();
|
| 188 |
+
|
| 189 |
+
gfx::Rect rect(event.location().x() - radius,
|
| 190 |
+
event.location().y() - radius,
|
| 191 |
+
radius * 2,
|
| 192 |
+
radius * 2);
|
| 193 |
+
if (IsInClickWindow(event))
|
| 194 |
+
enclosing_rect_.Union(rect);
|
| 195 |
+
else
|
| 196 |
+
enclosing_rect_ = rect;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
} // namespace ui
|
pool/shard009/C++/0110006_searchMatrix.cc
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <vector>
|
| 2 |
+
#include <string>
|
| 3 |
+
#include <utility>
|
| 4 |
+
#include <iostream>
|
| 5 |
+
#include <algorithm>
|
| 6 |
+
#include <limits>
|
| 7 |
+
#include <numeric>
|
| 8 |
+
using namespace std;
|
| 9 |
+
|
| 10 |
+
class Solution {
|
| 11 |
+
public:
|
| 12 |
+
bool searchMatrix(vector<vector<int>>& matrix, int target) {
|
| 13 |
+
if (matrix.size() == 0 || matrix[0].size() == 0)
|
| 14 |
+
return false;
|
| 15 |
+
int i = 0, j = matrix.size(), mid;
|
| 16 |
+
while (i < j) {
|
| 17 |
+
mid = (i+j)/2;
|
| 18 |
+
if (matrix[mid][0] > target)
|
| 19 |
+
j = mid;
|
| 20 |
+
else if (matrix[mid].back() < target)
|
| 21 |
+
i = mid+1;
|
| 22 |
+
else
|
| 23 |
+
return std::binary_search (matrix[mid].begin(), matrix[mid].end(), target);
|
| 24 |
+
}
|
| 25 |
+
return false;
|
| 26 |
+
}
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
/*
|
| 30 |
+
* input: vector<vector<int>> int ## true|false
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
template<typename T>
|
| 34 |
+
istream& operator >> (istream& in, vector<T>& vi) {
|
| 35 |
+
T val;
|
| 36 |
+
vi.clear();
|
| 37 |
+
while (!in.eof() && isspace(in.peek())) in.get();
|
| 38 |
+
if (in.eof()) return in;
|
| 39 |
+
in.get();
|
| 40 |
+
|
| 41 |
+
while (true) {
|
| 42 |
+
while (isspace(in.peek())) in.get();
|
| 43 |
+
if (in.peek() == '}') {
|
| 44 |
+
in.get();
|
| 45 |
+
return in;
|
| 46 |
+
}
|
| 47 |
+
else if (in.peek() == ',') in.get();
|
| 48 |
+
in >> val;
|
| 49 |
+
vi.push_back(val);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
return in;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
template<typename T>
|
| 56 |
+
ostream& operator << (ostream& out, vector<T>& vi) {
|
| 57 |
+
out << "{";
|
| 58 |
+
if (vi.size() != 0)
|
| 59 |
+
out << vi[0];
|
| 60 |
+
for (int i = 1; i < vi.size(); i++)
|
| 61 |
+
out << ", " << vi[i];
|
| 62 |
+
out << "}";
|
| 63 |
+
return out;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
int main() {
|
| 68 |
+
bool err = false;
|
| 69 |
+
string buf;
|
| 70 |
+
vector<vector<int>> matrix;
|
| 71 |
+
int target;
|
| 72 |
+
bool res, expected;
|
| 73 |
+
cout.setf(std::ios_base::boolalpha);
|
| 74 |
+
|
| 75 |
+
while (true) {
|
| 76 |
+
cin >> matrix;
|
| 77 |
+
if (cin.eof()) break;
|
| 78 |
+
cin >> target >> buf >> buf;
|
| 79 |
+
if (buf == "true")
|
| 80 |
+
expected = true;
|
| 81 |
+
else
|
| 82 |
+
expected = false;
|
| 83 |
+
res = Solution().searchMatrix(matrix, target);
|
| 84 |
+
if (res != expected) {
|
| 85 |
+
err = true;
|
| 86 |
+
cout << "input: " << matrix << " " << target << endl
|
| 87 |
+
<< "result: " << res << endl
|
| 88 |
+
<< "expected: " << expected << endl << endl;
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
if (!err)
|
| 93 |
+
cout << "All tests passed!\n";
|
| 94 |
+
|
| 95 |
+
return 0;
|
| 96 |
+
}
|
pool/shard009/C++/0110014_basic_string.cpp
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
| 3 |
+
All rights reserved.
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without
|
| 6 |
+
modification, are permitted provided that the following conditions are met:
|
| 7 |
+
* Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
documentation and/or other materials provided with the distribution.
|
| 12 |
+
* Neither the name of cereal nor the
|
| 13 |
+
names of its contributors may be used to endorse or promote products
|
| 14 |
+
derived from this software without specific prior written permission.
|
| 15 |
+
|
| 16 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 17 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 18 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 19 |
+
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
| 20 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 21 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 22 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 23 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 24 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 25 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 26 |
+
*/
|
| 27 |
+
#include "common.hpp"
|
| 28 |
+
#include <boost/test/unit_test.hpp>
|
| 29 |
+
|
| 30 |
+
template <class IArchive, class OArchive>
|
| 31 |
+
void test_string_basic()
|
| 32 |
+
{
|
| 33 |
+
std::random_device rd;
|
| 34 |
+
std::mt19937 gen(rd());
|
| 35 |
+
|
| 36 |
+
for(size_t i=0; i<100; ++i)
|
| 37 |
+
{
|
| 38 |
+
std::basic_string<char> o_string = random_basic_string<char>(gen);
|
| 39 |
+
std::basic_string<char> o_string2 = "";
|
| 40 |
+
|
| 41 |
+
std::ostringstream os;
|
| 42 |
+
{
|
| 43 |
+
OArchive oar(os);
|
| 44 |
+
oar(o_string);
|
| 45 |
+
oar(o_string2);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
std::basic_string<char> i_string;
|
| 49 |
+
std::basic_string<char> i_string2;
|
| 50 |
+
|
| 51 |
+
std::istringstream is(os.str());
|
| 52 |
+
{
|
| 53 |
+
IArchive iar(is);
|
| 54 |
+
|
| 55 |
+
iar(i_string);
|
| 56 |
+
iar(i_string2);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
BOOST_CHECK_EQUAL(i_string, o_string);
|
| 60 |
+
BOOST_CHECK_EQUAL(i_string2, o_string2);
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
template <class IArchive, class OArchive>
|
| 65 |
+
void test_string_all()
|
| 66 |
+
{
|
| 67 |
+
std::random_device rd;
|
| 68 |
+
std::mt19937 gen(rd());
|
| 69 |
+
|
| 70 |
+
for(size_t i=0; i<100; ++i)
|
| 71 |
+
{
|
| 72 |
+
std::basic_string<char> o_string = random_basic_string<char>(gen);
|
| 73 |
+
std::basic_string<wchar_t> o_wstring = random_basic_string<wchar_t>(gen);
|
| 74 |
+
std::basic_string<char16_t> o_u16string = random_basic_string<char16_t>(gen);
|
| 75 |
+
std::basic_string<char32_t> o_u32string = random_basic_string<char32_t>(gen);
|
| 76 |
+
|
| 77 |
+
std::ostringstream os;
|
| 78 |
+
{
|
| 79 |
+
OArchive oar(os);
|
| 80 |
+
oar(o_string);
|
| 81 |
+
oar(o_wstring);
|
| 82 |
+
oar(o_u16string);
|
| 83 |
+
oar(o_u32string);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
std::basic_string<char> i_string;
|
| 87 |
+
std::basic_string<wchar_t> i_wstring;
|
| 88 |
+
std::basic_string<char16_t> i_u16string;
|
| 89 |
+
std::basic_string<char32_t> i_u32string;
|
| 90 |
+
|
| 91 |
+
std::istringstream is(os.str());
|
| 92 |
+
{
|
| 93 |
+
IArchive iar(is);
|
| 94 |
+
|
| 95 |
+
iar(i_string);
|
| 96 |
+
iar(i_wstring);
|
| 97 |
+
iar(i_u16string);
|
| 98 |
+
iar(i_u32string);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
BOOST_CHECK_EQUAL(i_string, o_string);
|
| 102 |
+
BOOST_CHECK_EQUAL_COLLECTIONS(i_wstring.begin(), i_wstring.end(), o_wstring.begin(), o_wstring.end());
|
| 103 |
+
BOOST_CHECK_EQUAL_COLLECTIONS(i_u16string.begin(), i_u16string.end(), o_u16string.begin(), o_u16string.end());
|
| 104 |
+
BOOST_CHECK_EQUAL_COLLECTIONS(i_u32string.begin(), i_u32string.end(), o_u32string.begin(), o_u32string.end());
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
BOOST_AUTO_TEST_CASE( binary_string )
|
| 109 |
+
{
|
| 110 |
+
test_string_all<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
BOOST_AUTO_TEST_CASE( portable_binary_string )
|
| 114 |
+
{
|
| 115 |
+
test_string_all<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
BOOST_AUTO_TEST_CASE( xml_string_basic )
|
| 119 |
+
{
|
| 120 |
+
test_string_basic<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
BOOST_AUTO_TEST_CASE( json_string_basic )
|
| 124 |
+
{
|
| 125 |
+
test_string_basic<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
| 126 |
+
}
|
| 127 |
+
|
pool/shard009/C++/0110021_BinaryTreePreorderTraversal.cc
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// https://oj.leetcode.com/problems/binary-tree-preorder-traversal/
|
| 2 |
+
namespace BinaryTreePreorderTraversal {
|
| 3 |
+
class Solution {
|
| 4 |
+
public:
|
| 5 |
+
vector<int> preorderTraversal(TreeNode *root) {
|
| 6 |
+
vector<int> v;
|
| 7 |
+
if (root == NULL) {
|
| 8 |
+
return v;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
stack<TreeNode *> s;
|
| 12 |
+
s.push(root);
|
| 13 |
+
while (!s.empty()) {
|
| 14 |
+
TreeNode * cur = s.top();
|
| 15 |
+
v.push_back(cur->val);
|
| 16 |
+
s.pop();
|
| 17 |
+
if (cur->right) {
|
| 18 |
+
s.push(cur->right);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
if (cur->left) {
|
| 22 |
+
s.push(cur->left);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
return v;
|
| 28 |
+
|
| 29 |
+
}
|
| 30 |
+
};
|
| 31 |
+
}
|
pool/shard009/C++/0110022_BoostUtilities.cpp
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "BoostUtilities.hpp"
|
| 2 |
+
#include "BoostConstants.hpp"
|
| 3 |
+
|
| 4 |
+
#include "stdlib.h"
|
| 5 |
+
|
| 6 |
+
namespace BoostUtilities
|
| 7 |
+
{
|
| 8 |
+
QueueSender::QueueSender(const char* queueName)
|
| 9 |
+
{
|
| 10 |
+
pQueue = new interop_message_queue(boost::interprocess::open_only, queueName);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
SharedMemReader::SharedMemReader(const char* name)
|
| 14 |
+
{
|
| 15 |
+
// The intermediate variables in this function are necessary for some reason.
|
| 16 |
+
std::string sharedMemName = BoostConstants::buildSharedMemName(name);
|
| 17 |
+
const char* sharedMemChar = sharedMemName.c_str();
|
| 18 |
+
pSharedMem = new boost::interprocess::shared_memory_object(boost::interprocess::open_only, sharedMemChar, boost::interprocess::read_only);
|
| 19 |
+
|
| 20 |
+
std::string mutexName = BoostConstants::buildMutexName(name);
|
| 21 |
+
const char* mutexChar = mutexName.c_str();
|
| 22 |
+
pMutex = new boost::interprocess::named_sharable_mutex(boost::interprocess::open_only, mutexChar);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
ByteBuffer SharedMemReader::fetchData()
|
| 26 |
+
{
|
| 27 |
+
// The lock will be released when this object goes out of scope
|
| 28 |
+
boost::interprocess::sharable_lock<boost::interprocess::named_sharable_mutex> myLock(*pMutex);
|
| 29 |
+
hasLock = true;
|
| 30 |
+
|
| 31 |
+
boost::interprocess::offset_t size;
|
| 32 |
+
pSharedMem->get_size(size);
|
| 33 |
+
|
| 34 |
+
if (size == 0)
|
| 35 |
+
{
|
| 36 |
+
// Bail out early because mapped_region will freak out if size is zero.
|
| 37 |
+
ByteBuffer empty;
|
| 38 |
+
empty.ptr = new char[1]; // Arbitrary valid pointer to an array. We'll be calling delete[] on this later.
|
| 39 |
+
empty.size = 0;
|
| 40 |
+
return empty;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
boost::interprocess::mapped_region region(*pSharedMem, boost::interprocess::read_only);
|
| 44 |
+
unsigned char *buffer = new unsigned char[region.get_size()];
|
| 45 |
+
memcpy(buffer, region.get_address(), region.get_size());
|
| 46 |
+
|
| 47 |
+
ByteBuffer buf;
|
| 48 |
+
buf.ptr = buffer;
|
| 49 |
+
buf.size = region.get_size();
|
| 50 |
+
|
| 51 |
+
hasLock = false;
|
| 52 |
+
|
| 53 |
+
return buf;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
void SharedMemReader::unlockMutex()
|
| 57 |
+
{
|
| 58 |
+
if (hasLock)
|
| 59 |
+
{
|
| 60 |
+
pMutex->unlock_sharable();
|
| 61 |
+
hasLock = false;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
SharedMemWriter::SharedMemWriter(const char* name, int size)
|
| 66 |
+
{
|
| 67 |
+
// The intermediate variables in this function are necessary for some reason.
|
| 68 |
+
|
| 69 |
+
pMemName = name;
|
| 70 |
+
|
| 71 |
+
std::string sharedMemName = BoostConstants::buildSharedMemName(name);
|
| 72 |
+
const char* sharedMemChar = sharedMemName.c_str();
|
| 73 |
+
boost::interprocess::shared_memory_object::remove(sharedMemChar);
|
| 74 |
+
pSharedMem = new boost::interprocess::shared_memory_object(boost::interprocess::create_only, sharedMemChar, boost::interprocess::read_write);
|
| 75 |
+
pSharedMem->truncate(size);
|
| 76 |
+
|
| 77 |
+
std::string mutexName = BoostConstants::buildMutexName(name);
|
| 78 |
+
const char* mutexChar = mutexName.c_str();
|
| 79 |
+
boost::interprocess::named_sharable_mutex::remove(mutexChar);
|
| 80 |
+
pMutex = new boost::interprocess::named_sharable_mutex(boost::interprocess::create_only, mutexChar);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
SharedMemWriter::~SharedMemWriter()
|
| 84 |
+
{
|
| 85 |
+
std::string mutexName = BoostConstants::buildMutexName(pMemName);
|
| 86 |
+
const char* mutexChar = mutexName.c_str();
|
| 87 |
+
boost::interprocess::named_sharable_mutex::remove(mutexChar);
|
| 88 |
+
boost::interprocess::shared_memory_object::remove(pSharedMem->get_name());
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
void SharedMemWriter::writeData(void* address, int size)
|
| 92 |
+
{
|
| 93 |
+
// The lock will be released when this object goes out of scope, i.e. when this function exits.
|
| 94 |
+
boost::interprocess::scoped_lock<boost::interprocess::named_sharable_mutex> myLock(*pMutex);
|
| 95 |
+
|
| 96 |
+
if (size > 0)
|
| 97 |
+
{
|
| 98 |
+
boost::interprocess::mapped_region region(*pSharedMem, boost::interprocess::read_write);
|
| 99 |
+
std::memcpy(region.get_address(), address, size);
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
RLBotCoreStatus QueueSender::sendMessage(void* message, int messageSize)
|
| 104 |
+
{
|
| 105 |
+
if (messageSize > pQueue->get_max_msg_size())
|
| 106 |
+
{
|
| 107 |
+
return RLBotCoreStatus::MessageLargerThanMax;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
bool sent = pQueue->try_send(message, messageSize, 0);
|
| 111 |
+
|
| 112 |
+
if (!sent)
|
| 113 |
+
{
|
| 114 |
+
return RLBotCoreStatus::BufferOverfilled;
|
| 115 |
+
}
|
| 116 |
+
return RLBotCoreStatus::Success;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
SharedByteReader::SharedByteReader(const char* name)
|
| 120 |
+
{
|
| 121 |
+
// The intermediate variables in this function are necessary for some reason.
|
| 122 |
+
std::string sharedMemName = BoostConstants::buildSharedMemName(name);
|
| 123 |
+
const char* sharedMemChar = sharedMemName.c_str();
|
| 124 |
+
pSharedMem = new boost::interprocess::shared_memory_object(boost::interprocess::open_only, sharedMemChar, boost::interprocess::read_only);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
// This is expected to be very fast and cheap to call because it does not take a lock
|
| 128 |
+
// and just reads a single byte from shared memory. Suitable for being called at
|
| 129 |
+
// high frequency from multiple processes.
|
| 130 |
+
char SharedByteReader::fetchByte()
|
| 131 |
+
{
|
| 132 |
+
boost::interprocess::offset_t size;
|
| 133 |
+
pSharedMem->get_size(size);
|
| 134 |
+
|
| 135 |
+
if (size == 0)
|
| 136 |
+
{
|
| 137 |
+
// Bail out early because mapped_region will freak out if size is zero.
|
| 138 |
+
return 0;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
boost::interprocess::mapped_region region(*pSharedMem, boost::interprocess::read_only);
|
| 142 |
+
return *(char*)(region.get_address());
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
SharedByteWriter::SharedByteWriter(const char* name)
|
| 146 |
+
{
|
| 147 |
+
// The intermediate variables in this function are necessary for some reason.
|
| 148 |
+
|
| 149 |
+
pMemName = name;
|
| 150 |
+
|
| 151 |
+
std::string sharedMemName = BoostConstants::buildSharedMemName(name);
|
| 152 |
+
const char* sharedMemChar = sharedMemName.c_str();
|
| 153 |
+
boost::interprocess::shared_memory_object::remove(sharedMemChar);
|
| 154 |
+
pSharedMem = new boost::interprocess::shared_memory_object(boost::interprocess::create_only, sharedMemChar, boost::interprocess::read_write);
|
| 155 |
+
pSharedMem->truncate(1);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
SharedByteWriter::~SharedByteWriter()
|
| 159 |
+
{
|
| 160 |
+
boost::interprocess::shared_memory_object::remove(pSharedMem->get_name());
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
void SharedByteWriter::writeByte(char data)
|
| 164 |
+
{
|
| 165 |
+
char dataArr[] = { data };
|
| 166 |
+
boost::interprocess::mapped_region region(*pSharedMem, boost::interprocess::read_write);
|
| 167 |
+
std::memcpy(region.get_address(), dataArr, 1);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
}
|
pool/shard009/C++/0110026_h264_poc.cc
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2014 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include <stddef.h>
|
| 6 |
+
|
| 7 |
+
#include <algorithm>
|
| 8 |
+
|
| 9 |
+
#include "base/logging.h"
|
| 10 |
+
#include "base/macros.h"
|
| 11 |
+
#include "media/filters/h264_parser.h"
|
| 12 |
+
#include "media/video/h264_poc.h"
|
| 13 |
+
|
| 14 |
+
namespace media {
|
| 15 |
+
|
| 16 |
+
H264POC::H264POC() {
|
| 17 |
+
Reset();
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
H264POC::~H264POC() {
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
void H264POC::Reset() {
|
| 24 |
+
// It shouldn't be necessary to reset these values, but doing so will improve
|
| 25 |
+
// reproducibility for buggy streams.
|
| 26 |
+
ref_pic_order_cnt_msb_ = 0;
|
| 27 |
+
ref_pic_order_cnt_lsb_ = 0;
|
| 28 |
+
prev_frame_num_ = 0;
|
| 29 |
+
prev_frame_num_offset_ = 0;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
// Check if a slice includes memory management control operation 5, which
|
| 33 |
+
// results in some |pic_order_cnt| state being cleared.
|
| 34 |
+
static bool HasMMCO5(const media::H264SliceHeader& slice_hdr) {
|
| 35 |
+
// Require that the frame actually has memory management control operations.
|
| 36 |
+
if (slice_hdr.nal_ref_idc == 0 ||
|
| 37 |
+
slice_hdr.idr_pic_flag ||
|
| 38 |
+
!slice_hdr.adaptive_ref_pic_marking_mode_flag) {
|
| 39 |
+
return false;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
for (size_t i = 0; i < arraysize(slice_hdr.ref_pic_marking); i++) {
|
| 43 |
+
int32_t op = slice_hdr.ref_pic_marking[i].memory_mgmnt_control_operation;
|
| 44 |
+
if (op == 5)
|
| 45 |
+
return true;
|
| 46 |
+
|
| 47 |
+
// Stop at the end of the list.
|
| 48 |
+
if (op == 0)
|
| 49 |
+
return false;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// Should not get here, the list is always zero terminated.
|
| 53 |
+
return false;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
bool H264POC::ComputePicOrderCnt(
|
| 57 |
+
const H264SPS* sps,
|
| 58 |
+
const H264SliceHeader& slice_hdr,
|
| 59 |
+
int32_t *pic_order_cnt) {
|
| 60 |
+
if (slice_hdr.field_pic_flag) {
|
| 61 |
+
DLOG(ERROR) << "Interlaced frames are not supported";
|
| 62 |
+
return false;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
bool mmco5 = HasMMCO5(slice_hdr);
|
| 66 |
+
int32_t max_frame_num = 1 << (sps->log2_max_frame_num_minus4 + 4);
|
| 67 |
+
int32_t max_pic_order_cnt_lsb =
|
| 68 |
+
1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
|
| 69 |
+
|
| 70 |
+
// Check for invalid (including duplicate) |frame_num| values. All cases are
|
| 71 |
+
// treated as gaps, which is to say that nothing is done. (Gaps don't affect
|
| 72 |
+
// POC computation.)
|
| 73 |
+
if (!slice_hdr.idr_pic_flag &&
|
| 74 |
+
slice_hdr.frame_num != (prev_frame_num_ + 1) % max_frame_num) {
|
| 75 |
+
if (!sps->gaps_in_frame_num_value_allowed_flag)
|
| 76 |
+
DLOG(WARNING) << "Invalid gap in frame_num";
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// Based on T-REC-H.264 8.2.1, "Decoding process for picture order
|
| 80 |
+
// count", available from http://www.itu.int/rec/T-REC-H.264.
|
| 81 |
+
//
|
| 82 |
+
// Reorganized slightly from spec pseudocode to handle MMCO5 when storing
|
| 83 |
+
// state instead of when loading it.
|
| 84 |
+
switch (sps->pic_order_cnt_type) {
|
| 85 |
+
case 0: {
|
| 86 |
+
int32_t prev_pic_order_cnt_msb = ref_pic_order_cnt_msb_;
|
| 87 |
+
int32_t prev_pic_order_cnt_lsb = ref_pic_order_cnt_lsb_;
|
| 88 |
+
|
| 89 |
+
// For an IDR picture, clear the state.
|
| 90 |
+
if (slice_hdr.idr_pic_flag) {
|
| 91 |
+
prev_pic_order_cnt_msb = 0;
|
| 92 |
+
prev_pic_order_cnt_lsb = 0;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
// 8-3. Derive |pic_order_cnt_msb|, accounting for wrapping which is
|
| 96 |
+
// detected when |pic_order_cnt_lsb| increases or decreases by at
|
| 97 |
+
// least half of its maximum.
|
| 98 |
+
int32_t pic_order_cnt_msb;
|
| 99 |
+
if ((slice_hdr.pic_order_cnt_lsb < prev_pic_order_cnt_lsb) &&
|
| 100 |
+
(prev_pic_order_cnt_lsb - slice_hdr.pic_order_cnt_lsb >=
|
| 101 |
+
max_pic_order_cnt_lsb / 2)) {
|
| 102 |
+
pic_order_cnt_msb = prev_pic_order_cnt_msb + max_pic_order_cnt_lsb;
|
| 103 |
+
} else if ((slice_hdr.pic_order_cnt_lsb > prev_pic_order_cnt_lsb) &&
|
| 104 |
+
(slice_hdr.pic_order_cnt_lsb - prev_pic_order_cnt_lsb >
|
| 105 |
+
max_pic_order_cnt_lsb / 2)) {
|
| 106 |
+
pic_order_cnt_msb = prev_pic_order_cnt_msb - max_pic_order_cnt_lsb;
|
| 107 |
+
} else {
|
| 108 |
+
pic_order_cnt_msb = prev_pic_order_cnt_msb;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
// 8-4, 8-5. Derive |top_field_order_count| and |bottom_field_order_cnt|
|
| 112 |
+
// (assuming no interlacing).
|
| 113 |
+
int32_t top_foc = pic_order_cnt_msb + slice_hdr.pic_order_cnt_lsb;
|
| 114 |
+
int32_t bottom_foc = top_foc + slice_hdr.delta_pic_order_cnt_bottom;
|
| 115 |
+
*pic_order_cnt = std::min(top_foc, bottom_foc);
|
| 116 |
+
|
| 117 |
+
// Store state.
|
| 118 |
+
prev_frame_num_ = slice_hdr.frame_num;
|
| 119 |
+
if (slice_hdr.nal_ref_idc != 0) {
|
| 120 |
+
if (mmco5) {
|
| 121 |
+
ref_pic_order_cnt_msb_ = 0;
|
| 122 |
+
ref_pic_order_cnt_lsb_ = top_foc;
|
| 123 |
+
} else {
|
| 124 |
+
ref_pic_order_cnt_msb_ = pic_order_cnt_msb;
|
| 125 |
+
ref_pic_order_cnt_lsb_ = slice_hdr.pic_order_cnt_lsb;
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
break;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
case 1: {
|
| 133 |
+
// 8-6. Derive |frame_num_offset|.
|
| 134 |
+
int32_t frame_num_offset;
|
| 135 |
+
if (slice_hdr.idr_pic_flag)
|
| 136 |
+
frame_num_offset = 0;
|
| 137 |
+
else if (prev_frame_num_ > slice_hdr.frame_num)
|
| 138 |
+
frame_num_offset = prev_frame_num_offset_ + max_frame_num;
|
| 139 |
+
else
|
| 140 |
+
frame_num_offset = prev_frame_num_offset_;
|
| 141 |
+
|
| 142 |
+
// 8-7. Derive |abs_frame_num|.
|
| 143 |
+
int32_t abs_frame_num;
|
| 144 |
+
if (sps->num_ref_frames_in_pic_order_cnt_cycle != 0)
|
| 145 |
+
abs_frame_num = frame_num_offset + slice_hdr.frame_num;
|
| 146 |
+
else
|
| 147 |
+
abs_frame_num = 0;
|
| 148 |
+
|
| 149 |
+
if (slice_hdr.nal_ref_idc == 0 && abs_frame_num > 0)
|
| 150 |
+
abs_frame_num--;
|
| 151 |
+
|
| 152 |
+
// 8-9. Derive |expected_pic_order_cnt| (the |pic_order_cnt| indicated
|
| 153 |
+
// by the cycle described in the SPS).
|
| 154 |
+
int32_t expected_pic_order_cnt = 0;
|
| 155 |
+
if (abs_frame_num > 0) {
|
| 156 |
+
// 8-8. Derive pic_order_cnt_cycle_cnt and
|
| 157 |
+
// frame_num_in_pic_order_cnt_cycle.
|
| 158 |
+
// Moved inside 8-9 to avoid division when this check is not done.
|
| 159 |
+
if (sps->num_ref_frames_in_pic_order_cnt_cycle == 0) {
|
| 160 |
+
DLOG(ERROR) << "Invalid num_ref_frames_in_pic_order_cnt_cycle";
|
| 161 |
+
return false;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
// H264Parser checks that num_ref_frames_in_pic_order_cnt_cycle < 255.
|
| 165 |
+
int32_t pic_order_cnt_cycle_cnt =
|
| 166 |
+
(abs_frame_num - 1) / sps->num_ref_frames_in_pic_order_cnt_cycle;
|
| 167 |
+
int32_t frame_num_in_pic_order_cnt_cycle =
|
| 168 |
+
(abs_frame_num - 1) % sps->num_ref_frames_in_pic_order_cnt_cycle;
|
| 169 |
+
|
| 170 |
+
// 8-9 continued.
|
| 171 |
+
expected_pic_order_cnt = pic_order_cnt_cycle_cnt *
|
| 172 |
+
sps->expected_delta_per_pic_order_cnt_cycle;
|
| 173 |
+
for (int32_t i = 0; i <= frame_num_in_pic_order_cnt_cycle; i++)
|
| 174 |
+
expected_pic_order_cnt += sps->offset_for_ref_frame[i];
|
| 175 |
+
}
|
| 176 |
+
if (slice_hdr.nal_ref_idc == 0)
|
| 177 |
+
expected_pic_order_cnt += sps->offset_for_non_ref_pic;
|
| 178 |
+
|
| 179 |
+
// 8-10. Derive |top_field_order_cnt| and |bottom_field_order_cnt|
|
| 180 |
+
// (assuming no interlacing).
|
| 181 |
+
int32_t top_foc = expected_pic_order_cnt + slice_hdr.delta_pic_order_cnt0;
|
| 182 |
+
int32_t bottom_foc = top_foc + sps->offset_for_top_to_bottom_field +
|
| 183 |
+
slice_hdr.delta_pic_order_cnt1;
|
| 184 |
+
*pic_order_cnt = std::min(top_foc, bottom_foc);
|
| 185 |
+
|
| 186 |
+
// Store state.
|
| 187 |
+
prev_frame_num_ = slice_hdr.frame_num;
|
| 188 |
+
prev_frame_num_offset_ = frame_num_offset;
|
| 189 |
+
if (mmco5)
|
| 190 |
+
prev_frame_num_offset_ = 0;
|
| 191 |
+
|
| 192 |
+
break;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
case 2: {
|
| 196 |
+
// 8-11. Derive |frame_num_offset|.
|
| 197 |
+
int32_t frame_num_offset;
|
| 198 |
+
if (slice_hdr.idr_pic_flag)
|
| 199 |
+
frame_num_offset = 0;
|
| 200 |
+
else if (prev_frame_num_ > slice_hdr.frame_num)
|
| 201 |
+
frame_num_offset = prev_frame_num_offset_ + max_frame_num;
|
| 202 |
+
else
|
| 203 |
+
frame_num_offset = prev_frame_num_offset_;
|
| 204 |
+
|
| 205 |
+
// 8-12, 8-13. Derive |temp_pic_order_count| (it's always the
|
| 206 |
+
// |pic_order_cnt|, regardless of interlacing).
|
| 207 |
+
if (slice_hdr.idr_pic_flag)
|
| 208 |
+
*pic_order_cnt = 0;
|
| 209 |
+
else if (slice_hdr.nal_ref_idc == 0)
|
| 210 |
+
*pic_order_cnt = 2 * (frame_num_offset + slice_hdr.frame_num) - 1;
|
| 211 |
+
else
|
| 212 |
+
*pic_order_cnt = 2 * (frame_num_offset + slice_hdr.frame_num);
|
| 213 |
+
|
| 214 |
+
// Store state.
|
| 215 |
+
prev_frame_num_ = slice_hdr.frame_num;
|
| 216 |
+
prev_frame_num_offset_ = frame_num_offset;
|
| 217 |
+
if (mmco5)
|
| 218 |
+
prev_frame_num_offset_ = 0;
|
| 219 |
+
|
| 220 |
+
break;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
default:
|
| 224 |
+
DLOG(ERROR) << "Invalid pic_order_cnt_type: " << sps->pic_order_cnt_type;
|
| 225 |
+
return false;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
return true;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
} // namespace media
|
pool/shard009/C++/0110028_brake.cpp
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "commands/brake.hpp"
|
| 2 |
+
#include "base/commands_baseclean.hpp"
|
| 3 |
+
#include <utility>
|
| 4 |
+
#include <cmath>
|
| 5 |
+
#include <algorithm>
|
| 6 |
+
|
| 7 |
+
namespace retrobotics {
|
| 8 |
+
namespace isobot {
|
| 9 |
+
namespace commands {
|
| 10 |
+
Brake::Brake()
|
| 11 |
+
: BaseClean{"Brake"} {
|
| 12 |
+
Requires(drive_);
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
auto Brake::Execute() -> void {
|
| 16 |
+
std::pair<double, double> accel_xy{oi_->accelerometer_->GetX(), oi_->accelerometer_->GetY()};
|
| 17 |
+
std::pair<double, double> accel_rt{std::hypot(accel_xy.first, accel_xy.second), std::atan2(
|
| 18 |
+
accel_xy.second, accel_xy.first) - oi_->accelerometer_angle_};
|
| 19 |
+
std::pair<double, double> wheels{-std::cos(accel_rt.second)
|
| 20 |
+
* (std::signbit(std::sin(accel_rt.first)) ? 1 : -1) * std::min(accel_rt.first, 1.), std::cos(
|
| 21 |
+
accel_rt.second) * (std::signbit(std::sin(accel_rt.first)) ? 1 : -1)
|
| 22 |
+
* std::min(accel_rt.first, 1.)};
|
| 23 |
+
drive_->set(wheels);
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
}
|
pool/shard009/C++/0110036_protocol-parameter.cpp
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* This file is part of TelepathyQt
|
| 3 |
+
*
|
| 4 |
+
* @copyright Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
|
| 5 |
+
* @copyright Copyright (C) 2010 Nokia Corporation
|
| 6 |
+
* @license LGPL 2.1
|
| 7 |
+
*
|
| 8 |
+
* This library is free software; you can redistribute it and/or
|
| 9 |
+
* modify it under the terms of the GNU Lesser General Public
|
| 10 |
+
* License as published by the Free Software Foundation; either
|
| 11 |
+
* version 2.1 of the License, or (at your option) any later version.
|
| 12 |
+
*
|
| 13 |
+
* This library is distributed in the hope that it will be useful,
|
| 14 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
* Lesser General Public License for more details.
|
| 17 |
+
*
|
| 18 |
+
* You should have received a copy of the GNU Lesser General Public
|
| 19 |
+
* License along with this library; if not, write to the Free Software
|
| 20 |
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <TelepathyQt/ProtocolParameter>
|
| 24 |
+
|
| 25 |
+
#include "TelepathyQt/debug-internal.h"
|
| 26 |
+
|
| 27 |
+
#include <TelepathyQt/Utils>
|
| 28 |
+
|
| 29 |
+
namespace Tp
|
| 30 |
+
{
|
| 31 |
+
|
| 32 |
+
struct TP_QT_NO_EXPORT ProtocolParameter::Private : public QSharedData
|
| 33 |
+
{
|
| 34 |
+
Private(const ParamSpec &sp)
|
| 35 |
+
: spec(sp),
|
| 36 |
+
type(variantTypeFromDBusSignature(spec.signature))
|
| 37 |
+
{
|
| 38 |
+
init();
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
Private(const QString &name, const QString &dbusSignature,
|
| 42 |
+
ConnMgrParamFlags flags, const QVariant &defaultValue)
|
| 43 |
+
: type(variantTypeFromDBusSignature(dbusSignature))
|
| 44 |
+
{
|
| 45 |
+
spec.name = name;
|
| 46 |
+
spec.flags = flags;
|
| 47 |
+
spec.signature = dbusSignature;
|
| 48 |
+
spec.defaultValue = QDBusVariant(defaultValue);
|
| 49 |
+
init();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
void init()
|
| 53 |
+
{
|
| 54 |
+
if (spec.flags & ConnMgrParamFlagHasDefault) {
|
| 55 |
+
if (spec.defaultValue.variant() == QVariant::Invalid) {
|
| 56 |
+
// flags contains HasDefault but no default value is passed,
|
| 57 |
+
// lets warn and build a default value from signature
|
| 58 |
+
warning() << "Building ProtocolParameter with flags containing ConnMgrParamFlagHasDefault"
|
| 59 |
+
" and no default value, generating a dummy one from signature";
|
| 60 |
+
spec.defaultValue = QDBusVariant(
|
| 61 |
+
parseValueWithDBusSignature(QString(), spec.signature));
|
| 62 |
+
}
|
| 63 |
+
} else {
|
| 64 |
+
if (spec.defaultValue.variant() != QVariant::Invalid) {
|
| 65 |
+
// flags does not contain HasDefault but a default value is passed,
|
| 66 |
+
// lets add HasDefault to flags
|
| 67 |
+
debug() << "Building ProtocolParameter with flags not containing ConnMgrParamFlagHasDefault"
|
| 68 |
+
" and a default value, updating flags to contain ConnMgrParamFlagHasDefault";
|
| 69 |
+
spec.flags |= ConnMgrParamFlagHasDefault;
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
ParamSpec spec;
|
| 75 |
+
QVariant::Type type;
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* \class ProtocolParameter
|
| 80 |
+
* \ingroup clientcm
|
| 81 |
+
* \headerfile TelepathyQt/protocol-parameter.h <TelepathyQt/ProtocolParameter>
|
| 82 |
+
*
|
| 83 |
+
* \brief The ProtocolParameter class represents a Telepathy protocol parameter.
|
| 84 |
+
*/
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
ProtocolParameter::ProtocolParameter()
|
| 88 |
+
{
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
ProtocolParameter::ProtocolParameter(const ParamSpec &spec)
|
| 92 |
+
: mPriv(new Private(spec))
|
| 93 |
+
{
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
ProtocolParameter::ProtocolParameter(const QString &name,
|
| 97 |
+
const QDBusSignature &dbusSignature,
|
| 98 |
+
ConnMgrParamFlags flags,
|
| 99 |
+
QVariant defaultValue)
|
| 100 |
+
: mPriv(new Private(name, dbusSignature.signature(), flags, defaultValue))
|
| 101 |
+
{
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
ProtocolParameter::ProtocolParameter(const QString &name,
|
| 105 |
+
const QString &dbusSignature,
|
| 106 |
+
ConnMgrParamFlags flags,
|
| 107 |
+
QVariant defaultValue)
|
| 108 |
+
: mPriv(new Private(name, dbusSignature, flags, defaultValue))
|
| 109 |
+
{
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
ProtocolParameter::ProtocolParameter(const ProtocolParameter &other)
|
| 113 |
+
: mPriv(other.mPriv)
|
| 114 |
+
{
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
ProtocolParameter::~ProtocolParameter()
|
| 118 |
+
{
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
ProtocolParameter &ProtocolParameter::operator=(const ProtocolParameter &other)
|
| 122 |
+
{
|
| 123 |
+
this->mPriv = other.mPriv;
|
| 124 |
+
return *this;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
bool ProtocolParameter::operator==(const ProtocolParameter &other) const
|
| 128 |
+
{
|
| 129 |
+
if (!isValid() || !other.isValid()) {
|
| 130 |
+
if (!isValid() && !other.isValid()) {
|
| 131 |
+
return true;
|
| 132 |
+
}
|
| 133 |
+
return false;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
return (mPriv->spec.name == other.name());
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
bool ProtocolParameter::operator==(const QString &name) const
|
| 140 |
+
{
|
| 141 |
+
if (!isValid()) {
|
| 142 |
+
return false;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
return (mPriv->spec.name == name);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
bool ProtocolParameter::operator<(const Tp::ProtocolParameter& other) const
|
| 149 |
+
{
|
| 150 |
+
return mPriv->spec.name < other.name();
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
QString ProtocolParameter::name() const
|
| 154 |
+
{
|
| 155 |
+
if (!isValid()) {
|
| 156 |
+
return QString();
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
return mPriv->spec.name;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
QDBusSignature ProtocolParameter::dbusSignature() const
|
| 163 |
+
{
|
| 164 |
+
if (!isValid()) {
|
| 165 |
+
return QDBusSignature();
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
return QDBusSignature(mPriv->spec.signature);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
QVariant::Type ProtocolParameter::type() const
|
| 172 |
+
{
|
| 173 |
+
if (!isValid()) {
|
| 174 |
+
return QVariant::Invalid;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
return mPriv->type;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
QVariant ProtocolParameter::defaultValue() const
|
| 181 |
+
{
|
| 182 |
+
if (!isValid()) {
|
| 183 |
+
return QVariant();
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
return mPriv->spec.defaultValue.variant();
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
bool ProtocolParameter::isRequired() const
|
| 190 |
+
{
|
| 191 |
+
if (!isValid()) {
|
| 192 |
+
return false;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
return mPriv->spec.flags & ConnMgrParamFlagRequired;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
bool ProtocolParameter::isSecret() const
|
| 199 |
+
{
|
| 200 |
+
if (!isValid()) {
|
| 201 |
+
return false;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
return mPriv->spec.flags & ConnMgrParamFlagSecret;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
bool ProtocolParameter::isRequiredForRegistration() const
|
| 208 |
+
{
|
| 209 |
+
if (!isValid()) {
|
| 210 |
+
return false;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
return mPriv->spec.flags & ConnMgrParamFlagRegister;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
ParamSpec ProtocolParameter::bareParameter() const
|
| 217 |
+
{
|
| 218 |
+
if (!isValid()) {
|
| 219 |
+
return ParamSpec();
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
return mPriv->spec;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
uint qHash(const ProtocolParameter& parameter)
|
| 226 |
+
{
|
| 227 |
+
return qHash(parameter.name());
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
} // Tp
|
pool/shard009/C++/0110038_AttributeList.cpp
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===--- AttributeList.cpp --------------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// The LLVM Compiler Infrastructure
|
| 4 |
+
//
|
| 5 |
+
// This file is distributed under the University of Illinois Open Source
|
| 6 |
+
// License. See LICENSE.TXT for details.
|
| 7 |
+
//
|
| 8 |
+
//===----------------------------------------------------------------------===//
|
| 9 |
+
//
|
| 10 |
+
// This file defines the AttributeList class implementation
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#include "clang/Sema/AttributeList.h"
|
| 15 |
+
#include "clang/AST/ASTContext.h"
|
| 16 |
+
#include "clang/AST/DeclCXX.h"
|
| 17 |
+
#include "clang/AST/DeclTemplate.h"
|
| 18 |
+
#include "clang/AST/Expr.h"
|
| 19 |
+
#include "clang/Basic/IdentifierTable.h"
|
| 20 |
+
#include "clang/Basic/TargetInfo.h"
|
| 21 |
+
#include "clang/Sema/SemaInternal.h"
|
| 22 |
+
#include "llvm/ADT/SmallString.h"
|
| 23 |
+
using namespace clang;
|
| 24 |
+
|
| 25 |
+
IdentifierLoc *IdentifierLoc::create(ASTContext &Ctx, SourceLocation Loc,
|
| 26 |
+
IdentifierInfo *Ident) {
|
| 27 |
+
IdentifierLoc *Result = new (Ctx) IdentifierLoc;
|
| 28 |
+
Result->Loc = Loc;
|
| 29 |
+
Result->Ident = Ident;
|
| 30 |
+
return Result;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
size_t AttributeList::allocated_size() const {
|
| 34 |
+
if (IsAvailability) return AttributeFactory::AvailabilityAllocSize;
|
| 35 |
+
else if (IsTypeTagForDatatype)
|
| 36 |
+
return AttributeFactory::TypeTagForDatatypeAllocSize;
|
| 37 |
+
else if (IsProperty)
|
| 38 |
+
return AttributeFactory::PropertyAllocSize;
|
| 39 |
+
return (sizeof(AttributeList) + NumArgs * sizeof(ArgsUnion));
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
AttributeFactory::AttributeFactory() {
|
| 43 |
+
// Go ahead and configure all the inline capacity. This is just a memset.
|
| 44 |
+
FreeLists.resize(InlineFreeListsCapacity);
|
| 45 |
+
}
|
| 46 |
+
AttributeFactory::~AttributeFactory() {}
|
| 47 |
+
|
| 48 |
+
static size_t getFreeListIndexForSize(size_t size) {
|
| 49 |
+
assert(size >= sizeof(AttributeList));
|
| 50 |
+
assert((size % sizeof(void*)) == 0);
|
| 51 |
+
return ((size - sizeof(AttributeList)) / sizeof(void*));
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
void *AttributeFactory::allocate(size_t size) {
|
| 55 |
+
// Check for a previously reclaimed attribute.
|
| 56 |
+
size_t index = getFreeListIndexForSize(size);
|
| 57 |
+
if (index < FreeLists.size()) {
|
| 58 |
+
if (AttributeList *attr = FreeLists[index]) {
|
| 59 |
+
FreeLists[index] = attr->NextInPool;
|
| 60 |
+
return attr;
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// Otherwise, allocate something new.
|
| 65 |
+
return Alloc.Allocate(size, alignof(AttributeFactory));
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
void AttributeFactory::reclaimPool(AttributeList *cur) {
|
| 69 |
+
assert(cur && "reclaiming empty pool!");
|
| 70 |
+
do {
|
| 71 |
+
// Read this here, because we're going to overwrite NextInPool
|
| 72 |
+
// when we toss 'cur' into the appropriate queue.
|
| 73 |
+
AttributeList *next = cur->NextInPool;
|
| 74 |
+
|
| 75 |
+
size_t size = cur->allocated_size();
|
| 76 |
+
size_t freeListIndex = getFreeListIndexForSize(size);
|
| 77 |
+
|
| 78 |
+
// Expand FreeLists to the appropriate size, if required.
|
| 79 |
+
if (freeListIndex >= FreeLists.size())
|
| 80 |
+
FreeLists.resize(freeListIndex+1);
|
| 81 |
+
|
| 82 |
+
// Add 'cur' to the appropriate free-list.
|
| 83 |
+
cur->NextInPool = FreeLists[freeListIndex];
|
| 84 |
+
FreeLists[freeListIndex] = cur;
|
| 85 |
+
|
| 86 |
+
cur = next;
|
| 87 |
+
} while (cur);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
void AttributePool::takePool(AttributeList *pool) {
|
| 91 |
+
assert(pool);
|
| 92 |
+
|
| 93 |
+
// Fast path: this pool is empty.
|
| 94 |
+
if (!Head) {
|
| 95 |
+
Head = pool;
|
| 96 |
+
return;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
// Reverse the pool onto the current head. This optimizes for the
|
| 100 |
+
// pattern of pulling a lot of pools into a single pool.
|
| 101 |
+
do {
|
| 102 |
+
AttributeList *next = pool->NextInPool;
|
| 103 |
+
pool->NextInPool = Head;
|
| 104 |
+
Head = pool;
|
| 105 |
+
pool = next;
|
| 106 |
+
} while (pool);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
#include "clang/Sema/AttrParsedAttrKinds.inc"
|
| 110 |
+
|
| 111 |
+
static StringRef normalizeAttrName(StringRef AttrName, StringRef ScopeName,
|
| 112 |
+
AttributeList::Syntax SyntaxUsed) {
|
| 113 |
+
// Normalize the attribute name, __foo__ becomes foo. This is only allowable
|
| 114 |
+
// for GNU attributes.
|
| 115 |
+
bool IsGNU = SyntaxUsed == AttributeList::AS_GNU ||
|
| 116 |
+
(SyntaxUsed == AttributeList::AS_CXX11 && ScopeName == "gnu");
|
| 117 |
+
if (IsGNU && AttrName.size() >= 4 && AttrName.startswith("__") &&
|
| 118 |
+
AttrName.endswith("__"))
|
| 119 |
+
AttrName = AttrName.slice(2, AttrName.size() - 2);
|
| 120 |
+
|
| 121 |
+
return AttrName;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name,
|
| 125 |
+
const IdentifierInfo *ScopeName,
|
| 126 |
+
Syntax SyntaxUsed) {
|
| 127 |
+
StringRef AttrName = Name->getName();
|
| 128 |
+
|
| 129 |
+
SmallString<64> FullName;
|
| 130 |
+
if (ScopeName)
|
| 131 |
+
FullName += ScopeName->getName();
|
| 132 |
+
|
| 133 |
+
AttrName = normalizeAttrName(AttrName, FullName, SyntaxUsed);
|
| 134 |
+
|
| 135 |
+
// Ensure that in the case of C++11 attributes, we look for '::foo' if it is
|
| 136 |
+
// unscoped.
|
| 137 |
+
if (ScopeName || SyntaxUsed == AS_CXX11)
|
| 138 |
+
FullName += "::";
|
| 139 |
+
FullName += AttrName;
|
| 140 |
+
|
| 141 |
+
return ::getAttrKind(FullName, SyntaxUsed);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
unsigned AttributeList::getAttributeSpellingListIndex() const {
|
| 145 |
+
// Both variables will be used in tablegen generated
|
| 146 |
+
// attribute spell list index matching code.
|
| 147 |
+
StringRef Scope = ScopeName ? ScopeName->getName() : "";
|
| 148 |
+
StringRef Name = normalizeAttrName(AttrName->getName(), Scope,
|
| 149 |
+
(AttributeList::Syntax)SyntaxUsed);
|
| 150 |
+
|
| 151 |
+
#include "clang/Sema/AttrSpellingListIndex.inc"
|
| 152 |
+
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
struct ParsedAttrInfo {
|
| 156 |
+
unsigned NumArgs : 4;
|
| 157 |
+
unsigned OptArgs : 4;
|
| 158 |
+
unsigned HasCustomParsing : 1;
|
| 159 |
+
unsigned IsTargetSpecific : 1;
|
| 160 |
+
unsigned IsType : 1;
|
| 161 |
+
unsigned IsStmt : 1;
|
| 162 |
+
unsigned IsKnownToGCC : 1;
|
| 163 |
+
|
| 164 |
+
bool (*DiagAppertainsToDecl)(Sema &S, const AttributeList &Attr,
|
| 165 |
+
const Decl *);
|
| 166 |
+
bool (*DiagLangOpts)(Sema &S, const AttributeList &Attr);
|
| 167 |
+
bool (*ExistsInTarget)(const TargetInfo &Target);
|
| 168 |
+
unsigned (*SpellingIndexToSemanticSpelling)(const AttributeList &Attr);
|
| 169 |
+
};
|
| 170 |
+
|
| 171 |
+
namespace {
|
| 172 |
+
#include "clang/Sema/AttrParsedAttrImpl.inc"
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
static const ParsedAttrInfo &getInfo(const AttributeList &A) {
|
| 176 |
+
return AttrInfoMap[A.getKind()];
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
unsigned AttributeList::getMinArgs() const {
|
| 180 |
+
return getInfo(*this).NumArgs;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
unsigned AttributeList::getMaxArgs() const {
|
| 184 |
+
return getMinArgs() + getInfo(*this).OptArgs;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
bool AttributeList::hasCustomParsing() const {
|
| 188 |
+
return getInfo(*this).HasCustomParsing;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
bool AttributeList::diagnoseAppertainsTo(Sema &S, const Decl *D) const {
|
| 192 |
+
return getInfo(*this).DiagAppertainsToDecl(S, *this, D);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
bool AttributeList::diagnoseLangOpts(Sema &S) const {
|
| 196 |
+
return getInfo(*this).DiagLangOpts(S, *this);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
bool AttributeList::isTargetSpecificAttr() const {
|
| 200 |
+
return getInfo(*this).IsTargetSpecific;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
bool AttributeList::isTypeAttr() const {
|
| 204 |
+
return getInfo(*this).IsType;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
bool AttributeList::isStmtAttr() const {
|
| 208 |
+
return getInfo(*this).IsStmt;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
bool AttributeList::existsInTarget(const TargetInfo &Target) const {
|
| 212 |
+
return getInfo(*this).ExistsInTarget(Target);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
bool AttributeList::isKnownToGCC() const {
|
| 216 |
+
return getInfo(*this).IsKnownToGCC;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
unsigned AttributeList::getSemanticSpelling() const {
|
| 220 |
+
return getInfo(*this).SpellingIndexToSemanticSpelling(*this);
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
bool AttributeList::hasVariadicArg() const {
|
| 224 |
+
// If the attribute has the maximum number of optional arguments, we will
|
| 225 |
+
// claim that as being variadic. If we someday get an attribute that
|
| 226 |
+
// legitimately bumps up against that maximum, we can use another bit to track
|
| 227 |
+
// whether it's truly variadic or not.
|
| 228 |
+
return getInfo(*this).OptArgs == 15;
|
| 229 |
+
}
|
pool/shard009/C++/0110046_rmsprop_op.cc
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
you may not use this file except in compliance with the License.
|
| 5 |
+
You may obtain a copy of the License at
|
| 6 |
+
|
| 7 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
|
| 9 |
+
Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
See the License for the specific language governing permissions and
|
| 13 |
+
limitations under the License. */
|
| 14 |
+
|
| 15 |
+
#include "paddle/fluid/operators/optimizers/rmsprop_op.h"
|
| 16 |
+
|
| 17 |
+
namespace paddle {
|
| 18 |
+
namespace operators {
|
| 19 |
+
|
| 20 |
+
class RmspropOp : public framework::OperatorWithKernel {
|
| 21 |
+
public:
|
| 22 |
+
using framework::OperatorWithKernel::OperatorWithKernel;
|
| 23 |
+
|
| 24 |
+
void InferShape(framework::InferShapeContext *ctx) const override {
|
| 25 |
+
PADDLE_ENFORCE_EQ(ctx->HasInput("Param"), true,
|
| 26 |
+
platform::errors::NotFound(
|
| 27 |
+
"Input(Param) of RmspropOp should not be null."));
|
| 28 |
+
PADDLE_ENFORCE_EQ(
|
| 29 |
+
ctx->HasInput("MeanSquare"), true,
|
| 30 |
+
platform::errors::NotFound(
|
| 31 |
+
"Input(MeanSquare) of RmspropOp should not be null."));
|
| 32 |
+
PADDLE_ENFORCE_EQ(
|
| 33 |
+
ctx->HasInput("LearningRate"), true,
|
| 34 |
+
platform::errors::NotFound(
|
| 35 |
+
"Input(LearningRate) of RmspropOp should not be null."));
|
| 36 |
+
PADDLE_ENFORCE_EQ(ctx->HasInput("Grad"), true,
|
| 37 |
+
platform::errors::NotFound(
|
| 38 |
+
"Input(Grad) of RmspropOp should not be null."));
|
| 39 |
+
PADDLE_ENFORCE_EQ(ctx->HasInput("Moment"), true,
|
| 40 |
+
platform::errors::NotFound(
|
| 41 |
+
"Input(Moment) of RmspropOp should not be null."));
|
| 42 |
+
PADDLE_ENFORCE_EQ(ctx->GetInputsVarType("Param").front(),
|
| 43 |
+
framework::proto::VarType::LOD_TENSOR,
|
| 44 |
+
platform::errors::InvalidArgument(
|
| 45 |
+
"The input var's type in RmspropOp should be "
|
| 46 |
+
"LoDTensor, but the received is %s",
|
| 47 |
+
ctx->GetInputsVarType("Param").front()));
|
| 48 |
+
|
| 49 |
+
PADDLE_ENFORCE_EQ(
|
| 50 |
+
ctx->HasOutput("ParamOut"), true,
|
| 51 |
+
platform::errors::NotFound(
|
| 52 |
+
"Output(param_out) of RmspropOp should not be null."));
|
| 53 |
+
PADDLE_ENFORCE_EQ(
|
| 54 |
+
ctx->HasOutput("MomentOut"), true,
|
| 55 |
+
platform::errors::NotFound(
|
| 56 |
+
"Output(MomentOut) of RmspropOp should not be null."));
|
| 57 |
+
PADDLE_ENFORCE_EQ(
|
| 58 |
+
ctx->HasOutput("MeanSquareOut"), true,
|
| 59 |
+
platform::errors::NotFound(
|
| 60 |
+
"Output(MeanSquareOut) of RmspropOp should not be null."));
|
| 61 |
+
if (ctx->Attrs().Get<bool>("centered")) {
|
| 62 |
+
PADDLE_ENFORCE_EQ(
|
| 63 |
+
ctx->HasOutput("MeanGradOut"), true,
|
| 64 |
+
platform::errors::NotFound(
|
| 65 |
+
"Output(MeanGradOut) of RmspropOp should not be null."));
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
auto param_dim = ctx->GetInputDim("Param");
|
| 69 |
+
PADDLE_ENFORCE_EQ(
|
| 70 |
+
param_dim, ctx->GetInputDim("Grad"),
|
| 71 |
+
platform::errors::InvalidArgument(
|
| 72 |
+
"Param and grad input of RmspropOp should have the same dimension. "
|
| 73 |
+
"But received Param's dim [%s] and Grad's dim [%s].",
|
| 74 |
+
param_dim, ctx->GetInputDim("Grad")));
|
| 75 |
+
PADDLE_ENFORCE_EQ(param_dim, ctx->GetInputDim("Moment"),
|
| 76 |
+
platform::errors::InvalidArgument(
|
| 77 |
+
"Param and Momentum input of RmspropOp "
|
| 78 |
+
"should have the same dimension. But received "
|
| 79 |
+
"Param's dim [%s] and Moment [%s]",
|
| 80 |
+
param_dim, ctx->GetInputDim("Moment")));
|
| 81 |
+
PADDLE_ENFORCE_EQ(param_dim, ctx->GetInputDim("MeanSquare"),
|
| 82 |
+
platform::errors::InvalidArgument(
|
| 83 |
+
"Param and Momentum input of RmspropOp "
|
| 84 |
+
"should have the same dimension. But received "
|
| 85 |
+
"Param's dim [%s] and MeanSquare [%s]",
|
| 86 |
+
param_dim, ctx->GetInputDim("MeanSquare")));
|
| 87 |
+
|
| 88 |
+
auto lr_dim = ctx->GetInputDim("LearningRate");
|
| 89 |
+
PADDLE_ENFORCE_EQ(framework::product(lr_dim), 1,
|
| 90 |
+
platform::errors::InvalidArgument(
|
| 91 |
+
"Learning Rate of RmspropOp should be a scalar. But "
|
| 92 |
+
"received LearningRate's dim [%s]",
|
| 93 |
+
framework::product(lr_dim)));
|
| 94 |
+
|
| 95 |
+
ctx->SetOutputDim("ParamOut", param_dim);
|
| 96 |
+
ctx->SetOutputDim("MomentOut", param_dim);
|
| 97 |
+
ctx->SetOutputDim("MeanSquareOut", param_dim);
|
| 98 |
+
if (ctx->Attrs().Get<bool>("centered")) {
|
| 99 |
+
ctx->SetOutputDim("MeanGradOut", param_dim);
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
};
|
| 103 |
+
|
| 104 |
+
class RmspropOpMaker : public framework::OpProtoAndCheckerMaker {
|
| 105 |
+
public:
|
| 106 |
+
void Make() override {
|
| 107 |
+
AddInput("Param",
|
| 108 |
+
"(Tensor, default Tensor<float>) "
|
| 109 |
+
"Input parameter value that has to be updated.");
|
| 110 |
+
AddInput("MeanSquare",
|
| 111 |
+
"(Tensor, default Tensor<float>)"
|
| 112 |
+
" The mean square value that gets updated.");
|
| 113 |
+
AddInput("MeanGrad",
|
| 114 |
+
"(Tensor, default Tensor<float>)"
|
| 115 |
+
" The moving average of gradient")
|
| 116 |
+
.AsDispensable();
|
| 117 |
+
AddInput("LearningRate",
|
| 118 |
+
"(Tensor, default Tensor<float>) "
|
| 119 |
+
"The learning rate should be a tensor of size 1.");
|
| 120 |
+
AddInput("Grad",
|
| 121 |
+
"(Tensor, default Tensor<float>) "
|
| 122 |
+
"Input gradient of the parameter.");
|
| 123 |
+
AddInput("Moment",
|
| 124 |
+
"(Tensor, default Tensor<float>) The moment that gets updated.");
|
| 125 |
+
|
| 126 |
+
AddOutput("ParamOut", "(Tensor) Output updated parameter value.");
|
| 127 |
+
AddOutput("MomentOut", "(Tensor) Output updated moment.");
|
| 128 |
+
AddOutput("MeanSquareOut", "(Tensor) Output Mean squared updated value.");
|
| 129 |
+
AddOutput("MeanGradOut",
|
| 130 |
+
"(Tensor) Output moving average of gradient updated value.");
|
| 131 |
+
|
| 132 |
+
AddAttr<float>("epsilon",
|
| 133 |
+
"(float, default 1e-10) Constant "
|
| 134 |
+
"for numerical stability.")
|
| 135 |
+
.SetDefault(1.0e-10f);
|
| 136 |
+
AddAttr<float>("decay",
|
| 137 |
+
"(float, default 0.9) "
|
| 138 |
+
"Discounting factor for coming gradient.")
|
| 139 |
+
.SetDefault(0.9f);
|
| 140 |
+
AddAttr<float>("momentum", "(float, default 0.0) Constant value.")
|
| 141 |
+
.SetDefault(0.0f);
|
| 142 |
+
AddAttr<bool>("centered", "(bool, default false) use centered rmsprop.")
|
| 143 |
+
.SetDefault(false);
|
| 144 |
+
AddComment(R"DOC(
|
| 145 |
+
Rmsprop Optimizer.
|
| 146 |
+
|
| 147 |
+
$$
|
| 148 |
+
MeanSquareOut = decay * MeanSquare + (1 - decay) * Grad * Grad \\
|
| 149 |
+
MomentOut = momentum * Moment +
|
| 150 |
+
\frac{LearningRate * Grad}{\sqrt{MeanSquareOut + epsilon}} \\
|
| 151 |
+
ParamOut = Param - MomentOut
|
| 152 |
+
$$
|
| 153 |
+
|
| 154 |
+
if centered is true:
|
| 155 |
+
|
| 156 |
+
mean_grad = decay * mean_square{t-1} + (1-decay) * gradient
|
| 157 |
+
mean_square = decay * mean_square{t-1} + (1-decay) * gradient ** 2
|
| 158 |
+
mom = momentum * mom{t-1} + learning_rate * g_t /
|
| 159 |
+
sqrt(mean_square - mean_grad**2 + epsilon)
|
| 160 |
+
param -= mom
|
| 161 |
+
|
| 162 |
+
The original slides that proposed Rmsprop: Slide 29 of
|
| 163 |
+
http://www.cs.toronto.edu/~tijmen/csc321/slides/lecture_slides_lec6.pdf)
|
| 164 |
+
|
| 165 |
+
)DOC");
|
| 166 |
+
}
|
| 167 |
+
};
|
| 168 |
+
} // namespace operators
|
| 169 |
+
} // namespace paddle
|
| 170 |
+
|
| 171 |
+
namespace ops = paddle::operators;
|
| 172 |
+
REGISTER_OP_WITHOUT_GRADIENT(rmsprop, ops::RmspropOp, ops::RmspropOpMaker);
|
| 173 |
+
REGISTER_OP_CPU_KERNEL(
|
| 174 |
+
rmsprop, ops::RmspropOpKernel<paddle::platform::CPUDeviceContext, float>,
|
| 175 |
+
ops::RmspropOpKernel<paddle::platform::CPUDeviceContext, double>);
|
pool/shard009/C++/0110047_ClawHumanView.cpp
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "ClawHumanView.h"
|
| 2 |
+
#include "ClawGameLogic.h"
|
| 3 |
+
#include "ActorController.h"
|
| 4 |
+
#include "Engine/UserInterface/GameHUD.h"
|
| 5 |
+
#include "Engine/Resource/Loaders/XmlLoader.h"
|
| 6 |
+
|
| 7 |
+
//---------------------------------------------------------------------------------------------------------------------
|
| 8 |
+
// ClawHumanView
|
| 9 |
+
//---------------------------------------------------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
ClawHumanView::ClawHumanView(SDL_Renderer* renderer)
|
| 12 |
+
: HumanView(renderer)
|
| 13 |
+
{
|
| 14 |
+
RegisterAllDelegates();
|
| 15 |
+
|
| 16 |
+
m_pCamera->SetSize((uint32)g_pApp->GetWindowSize().x, (uint32)g_pApp->GetWindowSize().y);
|
| 17 |
+
|
| 18 |
+
Point startingPos = Point(400, 4500);
|
| 19 |
+
m_pCamera->VSetPosition(startingPos);
|
| 20 |
+
|
| 21 |
+
m_pFreeCameraController.reset(new MovementController(m_pCamera));
|
| 22 |
+
|
| 23 |
+
m_pKeyboardHandler = m_pFreeCameraController;
|
| 24 |
+
m_pPointerHandler = m_pFreeCameraController;
|
| 25 |
+
m_pTouchHandler = m_pFreeCameraController;
|
| 26 |
+
g_pApp->RegisterTouchRecognizers(*m_pFreeCameraController);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
ClawHumanView::~ClawHumanView()
|
| 30 |
+
{
|
| 31 |
+
RemoveAllDelegates();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
bool ClawHumanView::VOnEvent(SDL_Event& event)
|
| 35 |
+
{
|
| 36 |
+
if (HumanView::VOnEvent(event))
|
| 37 |
+
{
|
| 38 |
+
return true;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// Handle game specific events
|
| 42 |
+
return false;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void ClawHumanView::VOnUpdate(uint32 msDiff)
|
| 46 |
+
{
|
| 47 |
+
// Update engine, then game specific stuff
|
| 48 |
+
HumanView::VOnUpdate(msDiff);
|
| 49 |
+
|
| 50 |
+
// Actor controller has higher priority
|
| 51 |
+
if (m_pActorController)
|
| 52 |
+
{
|
| 53 |
+
m_pActorController->OnUpdate(msDiff);
|
| 54 |
+
}
|
| 55 |
+
else if (m_pFreeCameraController)
|
| 56 |
+
{
|
| 57 |
+
m_pFreeCameraController->OnUpdate(msDiff);
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void ClawHumanView::VOnAttach(uint32 gameViewId, uint32 actorId)
|
| 62 |
+
{
|
| 63 |
+
HumanView::VOnAttach(gameViewId, actorId);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
void ClawHumanView::VSetControlledActor(uint32 actorId)
|
| 67 |
+
{
|
| 68 |
+
m_pControlledActor = static_pointer_cast<SceneNode>(m_pScene->FindActor(actorId));
|
| 69 |
+
|
| 70 |
+
if (!m_pControlledActor)
|
| 71 |
+
{
|
| 72 |
+
LOG_ERROR("Trying to assign control to invalid actor. Id: " + ToStr(actorId));
|
| 73 |
+
return;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
HumanView::VSetControlledActor(actorId);
|
| 77 |
+
|
| 78 |
+
/*m_pFreeCameraController.reset(new MovementController(m_pCamera));
|
| 79 |
+
m_pKeyboardHandler = m_pFreeCameraController;
|
| 80 |
+
m_pPointerHandler = m_pFreeCameraController;*/
|
| 81 |
+
|
| 82 |
+
m_pActorController.reset(new ActorController(m_pControlledActor));
|
| 83 |
+
m_pKeyboardHandler = m_pActorController;
|
| 84 |
+
m_pPointerHandler = m_pActorController;
|
| 85 |
+
m_pTouchHandler = m_pActorController;
|
| 86 |
+
g_pApp->RegisterTouchRecognizers(*m_pActorController);
|
| 87 |
+
|
| 88 |
+
m_pCamera->SetTarget(m_pControlledActor);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
bool ClawHumanView::VLoadGameDelegate(TiXmlElement* pLevelXmlElem, LevelData* pLevelData)
|
| 92 |
+
{
|
| 93 |
+
if (!HumanView::VLoadGameDelegate(pLevelXmlElem, pLevelData))
|
| 94 |
+
{
|
| 95 |
+
return false;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
if (!m_pHUD->Initialize(g_pApp->GetRenderer(), m_pCamera))
|
| 99 |
+
{
|
| 100 |
+
LOG_ERROR("Failed to create in-game HUD");
|
| 101 |
+
return false;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
TiXmlElement* pXmlIngameMenuRoot = XmlResourceLoader::LoadAndReturnRootXmlElement("INGAME_MENU.XML");
|
| 105 |
+
assert(pXmlIngameMenuRoot != NULL);
|
| 106 |
+
|
| 107 |
+
m_pIngameMenu.reset(new ScreenElementMenu(g_pApp->GetRenderer()));
|
| 108 |
+
if (!m_pIngameMenu->Initialize(pXmlIngameMenuRoot))
|
| 109 |
+
{
|
| 110 |
+
LOG_ERROR("Failed to create in-game Menu");
|
| 111 |
+
return false;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
m_ScreenElements.push_back(m_pHUD);
|
| 115 |
+
m_ScreenElements.push_back(m_pIngameMenu);
|
| 116 |
+
m_pIngameMenu->VSetVisible(false);
|
| 117 |
+
|
| 118 |
+
return true;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
//=====================================================================================================================
|
| 122 |
+
// ClawHumanView: Private implementations
|
| 123 |
+
//=====================================================================================================================
|
| 124 |
+
|
| 125 |
+
void ClawHumanView::RegisterAllDelegates()
|
| 126 |
+
{
|
| 127 |
+
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
void ClawHumanView::RemoveAllDelegates()
|
| 131 |
+
{
|
| 132 |
+
|
| 133 |
+
}
|
pool/shard009/C++/0110051_propitem.cpp
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#include "propitem.h"
|
| 3 |
+
|
| 4 |
+
PropItem::PropItem(const QString &name, const QVariant &value, PropItem *parent)
|
| 5 |
+
{
|
| 6 |
+
itemName = name;
|
| 7 |
+
itemValue = value;
|
| 8 |
+
parentItem = parent;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
PropItem::~PropItem()
|
| 12 |
+
{
|
| 13 |
+
qDeleteAll(childItems);
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
bool PropItem::setData(int column, const QVariant &value)
|
| 17 |
+
{
|
| 18 |
+
// We can only edit the right hand column
|
| 19 |
+
if (column != 1) return false;
|
| 20 |
+
itemValue = value;
|
| 21 |
+
return true;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
void PropItem::appendChild(PropItem *child)
|
| 25 |
+
{
|
| 26 |
+
childItems.append(child);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
PropItem *PropItem::child(int row)
|
| 30 |
+
{
|
| 31 |
+
return childItems.value(row);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
int PropItem::childCount() const
|
| 35 |
+
{
|
| 36 |
+
return childItems.count();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
int PropItem::row() const
|
| 40 |
+
{
|
| 41 |
+
if (parentItem)
|
| 42 |
+
return parentItem->childItems.indexOf(const_cast<PropItem*>(this));
|
| 43 |
+
return 0;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
int PropItem::columnCount() const
|
| 47 |
+
{
|
| 48 |
+
return 2;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
PropItem *PropItem::parent()
|
| 52 |
+
{
|
| 53 |
+
return parentItem;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
QString PropItem::name() const
|
| 57 |
+
{
|
| 58 |
+
return itemName;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
QVariant PropItem::value()
|
| 62 |
+
{
|
| 63 |
+
return itemValue;
|
| 64 |
+
}
|
pool/shard009/C++/0110052_test_memory_pool.cpp
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* Licensed to Qualys, Inc. (QUALYS) under one or more
|
| 3 |
+
* contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
* this work for additional information regarding copyright ownership.
|
| 5 |
+
* QUALYS licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
* (the "License"); you may not use this file except in compliance with
|
| 7 |
+
* the License. You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
****************************************************************************/
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* @file
|
| 20 |
+
* @brief IronBee++ Internals --- Memory Pool Tests
|
| 21 |
+
*
|
| 22 |
+
* @author Christopher Alfeld <calfeld@qualys.com>
|
| 23 |
+
**/
|
| 24 |
+
|
| 25 |
+
#include <ironbeepp/memory_pool.hpp>
|
| 26 |
+
#include <ironbeepp/exception.hpp>
|
| 27 |
+
#include <ironbeepp/test_fixture.hpp>
|
| 28 |
+
|
| 29 |
+
#include "gtest/gtest.h"
|
| 30 |
+
|
| 31 |
+
#include <string>
|
| 32 |
+
|
| 33 |
+
using namespace std;
|
| 34 |
+
|
| 35 |
+
class TestMemoryPool : public ::testing::Test, public IronBee::TestFixture
|
| 36 |
+
{
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
class test_callback
|
| 40 |
+
{
|
| 41 |
+
public:
|
| 42 |
+
test_callback(bool& called_flag) :
|
| 43 |
+
m_called_flag(called_flag)
|
| 44 |
+
{
|
| 45 |
+
// nop
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void operator()()
|
| 49 |
+
{
|
| 50 |
+
m_called_flag = true;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
private:
|
| 54 |
+
bool& m_called_flag;
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
TEST_F(TestMemoryPool, create)
|
| 58 |
+
{
|
| 59 |
+
IronBee::MemoryPool m;
|
| 60 |
+
|
| 61 |
+
m = IronBee::MemoryPool::create();
|
| 62 |
+
EXPECT_EQ(string("MemoryPool"), m.name());
|
| 63 |
+
m.destroy();
|
| 64 |
+
|
| 65 |
+
EXPECT_NO_THROW(m = IronBee::MemoryPool::create("Hello World"));
|
| 66 |
+
EXPECT_EQ(string("Hello World"), m.name());
|
| 67 |
+
|
| 68 |
+
IronBee::MemoryPool m2;
|
| 69 |
+
EXPECT_NO_THROW(m2 = IronBee::MemoryPool::create("WorldChild", m));
|
| 70 |
+
EXPECT_EQ(string("WorldChild"), m2.name());
|
| 71 |
+
m2.destroy();
|
| 72 |
+
|
| 73 |
+
EXPECT_NO_THROW(m2 = m.create_subpool());
|
| 74 |
+
EXPECT_EQ(string("SubPool"), m2.name());
|
| 75 |
+
m2.destroy();
|
| 76 |
+
|
| 77 |
+
EXPECT_NO_THROW(m2 = m.create_subpool("WorldChild2"));
|
| 78 |
+
EXPECT_EQ(string("WorldChild2"), m2.name());
|
| 79 |
+
m2.destroy();
|
| 80 |
+
m.destroy();
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
TEST_F(TestMemoryPool, basic)
|
| 84 |
+
{
|
| 85 |
+
IronBee::MemoryPool m = IronBee::MemoryPool::create();
|
| 86 |
+
char* p;
|
| 87 |
+
|
| 88 |
+
p = reinterpret_cast<char*>(m.alloc(20));
|
| 89 |
+
EXPECT_TRUE(p);
|
| 90 |
+
|
| 91 |
+
int* ip = m.allocate<int>(2);
|
| 92 |
+
EXPECT_TRUE(ip);
|
| 93 |
+
|
| 94 |
+
// With no introspection, testing is limited.
|
| 95 |
+
EXPECT_NO_THROW(m.clear());
|
| 96 |
+
EXPECT_NO_THROW(m.destroy());
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
TEST_F(TestMemoryPool, callbacks)
|
| 100 |
+
{
|
| 101 |
+
bool called_flag = false;
|
| 102 |
+
|
| 103 |
+
IronBee::MemoryPool m = IronBee::MemoryPool::create();
|
| 104 |
+
m.register_cleanup(test_callback(called_flag));
|
| 105 |
+
|
| 106 |
+
ASSERT_FALSE(called_flag);
|
| 107 |
+
m.clear();
|
| 108 |
+
EXPECT_TRUE(called_flag);
|
| 109 |
+
m.destroy();
|
| 110 |
+
EXPECT_TRUE(called_flag);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
TEST_F(TestMemoryPool, boolness)
|
| 114 |
+
{
|
| 115 |
+
IronBee::MemoryPool singular;
|
| 116 |
+
|
| 117 |
+
EXPECT_FALSE(singular);
|
| 118 |
+
|
| 119 |
+
ib_mpool_t* ib_memory_pool = reinterpret_cast<ib_mpool_t*>(1);
|
| 120 |
+
IronBee::MemoryPool nonsingular(ib_memory_pool);
|
| 121 |
+
|
| 122 |
+
EXPECT_TRUE(nonsingular);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
TEST_F(TestMemoryPool, expose_c)
|
| 126 |
+
{
|
| 127 |
+
ib_mpool_t* ib_memory_pool = reinterpret_cast<ib_mpool_t*>(1);
|
| 128 |
+
IronBee::MemoryPool m(ib_memory_pool);
|
| 129 |
+
|
| 130 |
+
ASSERT_TRUE(m);
|
| 131 |
+
EXPECT_EQ(ib_memory_pool, m.ib());
|
| 132 |
+
|
| 133 |
+
const IronBee::MemoryPool& cm = m;
|
| 134 |
+
ASSERT_TRUE(cm);
|
| 135 |
+
EXPECT_EQ(ib_memory_pool, cm.ib());
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
TEST_F(TestMemoryPool, scoped)
|
| 139 |
+
{
|
| 140 |
+
bool called_flag = false;
|
| 141 |
+
{
|
| 142 |
+
IronBee::ScopedMemoryPool scoped;
|
| 143 |
+
|
| 144 |
+
IronBee::MemoryPool m = scoped;
|
| 145 |
+
EXPECT_TRUE(m);
|
| 146 |
+
EXPECT_EQ(string("ScopedMemoryPool"), m.name());
|
| 147 |
+
|
| 148 |
+
m.register_cleanup(test_callback(called_flag));
|
| 149 |
+
}
|
| 150 |
+
EXPECT_TRUE(called_flag);
|
| 151 |
+
|
| 152 |
+
called_flag = false;
|
| 153 |
+
{
|
| 154 |
+
IronBee::ScopedMemoryPool scoped("Hello World");
|
| 155 |
+
|
| 156 |
+
IronBee::MemoryPool m = scoped;
|
| 157 |
+
EXPECT_TRUE(m);
|
| 158 |
+
EXPECT_EQ(string("Hello World"), m.name());
|
| 159 |
+
|
| 160 |
+
m.register_cleanup(test_callback(called_flag));
|
| 161 |
+
}
|
| 162 |
+
EXPECT_TRUE(called_flag);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
TEST_F(TestMemoryPool, Const)
|
| 166 |
+
{
|
| 167 |
+
IronBee::MemoryPool m = IronBee::MemoryPool::create();
|
| 168 |
+
IronBee::ConstMemoryPool cm = m;
|
| 169 |
+
|
| 170 |
+
EXPECT_EQ(cm, m);
|
| 171 |
+
|
| 172 |
+
IronBee::MemoryPool m2 = IronBee::MemoryPool::remove_const(cm);
|
| 173 |
+
|
| 174 |
+
EXPECT_EQ(cm, m2);
|
| 175 |
+
EXPECT_EQ(m, m2);
|
| 176 |
+
|
| 177 |
+
m.destroy();
|
| 178 |
+
}
|
pool/shard009/C++/0110054_moveable2.cc
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// { dg-options "-std=gnu++11" }
|
| 2 |
+
|
| 3 |
+
// Copyright (C) 2009-2015 Free Software Foundation, Inc.
|
| 4 |
+
//
|
| 5 |
+
// This file is part of the GNU ISO C++ Library. This library is free
|
| 6 |
+
// software; you can redistribute it and/or modify it under the
|
| 7 |
+
// terms of the GNU General Public License as published by the
|
| 8 |
+
// Free Software Foundation; either version 3, or (at your option)
|
| 9 |
+
// any later version.
|
| 10 |
+
|
| 11 |
+
// This library is distributed in the hope that it will be useful,
|
| 12 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
// GNU General Public License for more details.
|
| 15 |
+
|
| 16 |
+
// You should have received a copy of the GNU General Public License along
|
| 17 |
+
// with this library; see the file COPYING3. If not see
|
| 18 |
+
// <http://www.gnu.org/licenses/>.
|
| 19 |
+
|
| 20 |
+
// 25.3.4 [lib.alg.merge]
|
| 21 |
+
|
| 22 |
+
#include <algorithm>
|
| 23 |
+
#include <testsuite_hooks.h>
|
| 24 |
+
#include <testsuite_iterators.h>
|
| 25 |
+
#include <testsuite_rvalref.h>
|
| 26 |
+
|
| 27 |
+
using __gnu_test::test_container;
|
| 28 |
+
using __gnu_test::bidirectional_iterator_wrapper;
|
| 29 |
+
using __gnu_test::rvalstruct;
|
| 30 |
+
|
| 31 |
+
typedef test_container<rvalstruct, bidirectional_iterator_wrapper> container;
|
| 32 |
+
|
| 33 |
+
bool
|
| 34 |
+
are_ordered(const rvalstruct& lhs, const rvalstruct& rhs)
|
| 35 |
+
{ return lhs < rhs; }
|
| 36 |
+
|
| 37 |
+
void
|
| 38 |
+
test01()
|
| 39 |
+
{
|
| 40 |
+
bool test __attribute__((unused)) = true;
|
| 41 |
+
|
| 42 |
+
int array1[]={0,2,4,1,3,5};
|
| 43 |
+
rvalstruct rv_array1[6];
|
| 44 |
+
std::copy(array1, array1 + 6, rv_array1);
|
| 45 |
+
container con1(rv_array1, rv_array1 + 6);
|
| 46 |
+
std::inplace_merge(con1.begin(), con1.it(3), con1.end(), are_ordered);
|
| 47 |
+
VERIFY( rv_array1[0] == 0 && rv_array1[1] == 1 && rv_array1[2] == 2
|
| 48 |
+
&& rv_array1[3] == 3 && rv_array1[4] == 4 && rv_array1[5] == 5 );
|
| 49 |
+
|
| 50 |
+
int array2[]={0,2,4,5,1,3};
|
| 51 |
+
rvalstruct rv_array2[6];
|
| 52 |
+
std::copy(array2, array2 + 6, rv_array2);
|
| 53 |
+
container con2(rv_array2, rv_array2 + 6);
|
| 54 |
+
std::inplace_merge(con2.begin(), con2.it(4), con2.end(), are_ordered);
|
| 55 |
+
VERIFY( rv_array2[0] == 0 && rv_array2[1] == 1 && rv_array2[2] == 2
|
| 56 |
+
&& rv_array2[3] == 3 && rv_array2[4] == 4 && rv_array2[5] == 5 );
|
| 57 |
+
|
| 58 |
+
int array3[]={1,1,1,2,2,2};
|
| 59 |
+
rvalstruct rv_array3[6];
|
| 60 |
+
std::copy(array3, array3 + 6, rv_array3);
|
| 61 |
+
container con3(rv_array3, rv_array3 + 6);
|
| 62 |
+
std::inplace_merge(con3.begin(), con3.it(3), con3.end(), are_ordered);
|
| 63 |
+
VERIFY( rv_array3[0] == 1 && rv_array3[1] == 1 && rv_array3[2] == 1
|
| 64 |
+
&& rv_array3[3] == 2 && rv_array3[4] == 2 && rv_array3[5] == 2 );
|
| 65 |
+
|
| 66 |
+
int array4[]={1,1,1,1,2,2};
|
| 67 |
+
rvalstruct rv_array4[6];
|
| 68 |
+
std::copy(array4, array4 + 6, rv_array4);
|
| 69 |
+
container con4(rv_array4, rv_array4 + 6);
|
| 70 |
+
std::inplace_merge(con4.begin(), con4.it(4), con4.end(), are_ordered);
|
| 71 |
+
VERIFY( rv_array4[0] == 1 && rv_array4[1] == 1 && rv_array4[2] == 1
|
| 72 |
+
&& rv_array4[3] == 1 && rv_array4[4] == 2 && rv_array4[5] == 2 );
|
| 73 |
+
|
| 74 |
+
int array5[]={3,3,3,3};
|
| 75 |
+
rvalstruct rv_array5[4];
|
| 76 |
+
std::copy(array5, array5 + 4, rv_array5);
|
| 77 |
+
container con5(rv_array5, rv_array5 + 4);
|
| 78 |
+
std::inplace_merge(con5.begin(), con5.it(2), con5.end(), are_ordered);
|
| 79 |
+
VERIFY( rv_array5[0] == 3 && rv_array5[1] == 3 && rv_array5[2] == 3
|
| 80 |
+
&& rv_array5[3] == 3 );
|
| 81 |
+
|
| 82 |
+
int array6[]={3,3,3};
|
| 83 |
+
rvalstruct rv_array6[3];
|
| 84 |
+
std::copy(array6, array6 + 3, rv_array6);
|
| 85 |
+
container con6(rv_array6, rv_array6 + 3);
|
| 86 |
+
std::inplace_merge(con6.begin(), con6.it(0), con6.end(), are_ordered);
|
| 87 |
+
VERIFY( rv_array6[0] == 3 && rv_array6[1] == 3 && rv_array6[2] == 3 );
|
| 88 |
+
|
| 89 |
+
int array7[]={3,3};
|
| 90 |
+
rvalstruct rv_array7[2];
|
| 91 |
+
std::copy(array7, array7 + 2, rv_array7);
|
| 92 |
+
container con7(rv_array7, rv_array7 + 2);
|
| 93 |
+
std::inplace_merge(con7.begin(), con7.it(2), con7.end(), are_ordered);
|
| 94 |
+
VERIFY( rv_array7[0] == 3 && rv_array7[1] == 3 );
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
int
|
| 98 |
+
main()
|
| 99 |
+
{
|
| 100 |
+
test01();
|
| 101 |
+
return 0;
|
| 102 |
+
}
|
pool/shard009/C++/0110056_lambdaCaptureReference.cpp
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// lambdaCaptureReference.cpp
|
| 2 |
+
|
| 3 |
+
#include <functional>
|
| 4 |
+
#include <iostream>
|
| 5 |
+
|
| 6 |
+
std::function<int(int)> makeLambda(int a){
|
| 7 |
+
int local = 2 * a;
|
| 8 |
+
auto lam = [&local](int b){ return local + b; }; // 1
|
| 9 |
+
std::cout << "lam(5): "<< lam(5) << std::endl; // 2
|
| 10 |
+
return lam;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
int main(){
|
| 14 |
+
|
| 15 |
+
std::cout << std::endl;
|
| 16 |
+
|
| 17 |
+
int local = 10;
|
| 18 |
+
|
| 19 |
+
auto addLocal = [&local](int b){ return local + b; }; // 3
|
| 20 |
+
|
| 21 |
+
auto add10 = makeLambda(5);
|
| 22 |
+
|
| 23 |
+
std::cout << "addLocal(5): " << addLocal(5) << std::endl; // 4
|
| 24 |
+
std::cout << "add10(5): " << add10(5) << std::endl; // 5
|
| 25 |
+
|
| 26 |
+
std::cout << std::endl;
|
| 27 |
+
|
| 28 |
+
}
|
pool/shard009/C++/0110060_drvkillu.cpp
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
drvkillu.cpp : This file is part of pstoedit
|
| 3 |
+
Implementation of Kontour output driver.
|
| 4 |
+
|
| 5 |
+
Copyright (C) 1993 - 2009 Wolfgang Glunz, wglunz35_AT_pstoedit.net
|
| 6 |
+
Copyright (C) 1998,1999 Kai-Uwe Sattler, kus_AT_iti.cs.uni-magdeburg.de
|
| 7 |
+
|
| 8 |
+
This program is free software; you can redistribute it and/or modify
|
| 9 |
+
it under the terms of the GNU General Public License as published by
|
| 10 |
+
the Free Software Foundation; either version 2 of the License, or
|
| 11 |
+
(at your option) any later version.
|
| 12 |
+
|
| 13 |
+
This program is distributed in the hope that it will be useful,
|
| 14 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 16 |
+
GNU General Public License for more details.
|
| 17 |
+
|
| 18 |
+
You should have received a copy of the GNU General Public License
|
| 19 |
+
along with this program; if not, write to the Free Software
|
| 20 |
+
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
| 21 |
+
|
| 22 |
+
*/
|
| 23 |
+
#include "drvkillu.h"
|
| 24 |
+
#include I_fstream
|
| 25 |
+
#include I_stdio
|
| 26 |
+
#include I_stdlib
|
| 27 |
+
#include <math.h>
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
drvKontour::derivedConstructor(drvKontour):constructBase
|
| 32 |
+
{
|
| 33 |
+
// driver specific initializations
|
| 34 |
+
// and writing of header to output file
|
| 35 |
+
|
| 36 |
+
// <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE killustrator >
|
| 37 |
+
//<killustrator mime="application/x-killustrator" version="3" editor="KIllustrator" >
|
| 38 |
+
//
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
outf << "<?xml version=\"1.0\"?>\n<!DOCTYPE killustrator >"
|
| 42 |
+
<< "<killustrator mime=\"application/x-killustrator\" version=\"3\" editor=\"KIllustrator\" >\n";
|
| 43 |
+
|
| 44 |
+
outf << "<head>\n" <<
|
| 45 |
+
"<layout format=\"a4\" orientation=\"portrait\" width=\"210\"" <<
|
| 46 |
+
"height=\"297\" lmargin=\"0\" tmargin=\"0\" rmargin=\"0\" bmargin=\"0\" />\n"
|
| 47 |
+
<< "</head>\n";
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
drvKontour::~drvKontour()
|
| 51 |
+
{
|
| 52 |
+
// driver specific deallocations
|
| 53 |
+
// and writing of trailer to output file
|
| 54 |
+
outf << "</killustrator>\n";
|
| 55 |
+
options=0;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
void drvKontour::print_coords()
|
| 59 |
+
{
|
| 60 |
+
for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
|
| 61 |
+
const basedrawingelement & elem = pathElement(n);
|
| 62 |
+
switch (elem.getType()) {
|
| 63 |
+
case moveto:{
|
| 64 |
+
const Point & p = elem.getPoint(0);
|
| 65 |
+
outf << "<point x=\"" << p.x_ + x_offset
|
| 66 |
+
<< "\" y=\"" << currentDeviceHeight - p.y_ + y_offset << "\" />\n";
|
| 67 |
+
}
|
| 68 |
+
break;
|
| 69 |
+
case lineto:{
|
| 70 |
+
const Point & p = elem.getPoint(0);
|
| 71 |
+
outf << "<point x=\"" << p.x_ + x_offset
|
| 72 |
+
<< "\" y=\"" << currentDeviceHeight - p.y_ + y_offset << "\" />\n";
|
| 73 |
+
}
|
| 74 |
+
break;
|
| 75 |
+
case closepath:
|
| 76 |
+
break;
|
| 77 |
+
case curveto:{
|
| 78 |
+
for (unsigned int cp = 0; cp < 3; cp++) {
|
| 79 |
+
const Point & p = elem.getPoint(cp);
|
| 80 |
+
outf << "<point x=\"" << p.x_ + x_offset
|
| 81 |
+
<< "\" y=\"" << currentDeviceHeight - p.y_ + y_offset << "\" />\n";
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
break;
|
| 85 |
+
default:
|
| 86 |
+
errf << "\t\tFatal: unexpected case in drvKontour " << endl;
|
| 87 |
+
abort();
|
| 88 |
+
break;
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
void drvKontour::open_page()
|
| 95 |
+
{
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
void drvKontour::close_page()
|
| 99 |
+
{
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
void drvKontour::show_text(const TextInfo & textinfo)
|
| 103 |
+
{
|
| 104 |
+
static const float toRad = 3.14159265359f / 180.0f;
|
| 105 |
+
const double angle = (360.0 - textinfo.currentFontAngle) * toRad;
|
| 106 |
+
const double cosa = cos(angle);
|
| 107 |
+
const double sina = sin(angle);
|
| 108 |
+
outf << "<text matrix=\""
|
| 109 |
+
<< cosa << " " << sina << " 0 "
|
| 110 |
+
<< -sina << " " << cosa << " 0 "
|
| 111 |
+
<< textinfo.x << " " << currentDeviceHeight - textinfo.y << " 1"
|
| 112 |
+
<< "\""
|
| 113 |
+
<< " strokecolor=\""
|
| 114 |
+
<< cvtColor(textinfo.currentR) << " "
|
| 115 |
+
<< cvtColor(textinfo.currentG) << " "
|
| 116 |
+
<< cvtColor(textinfo.currentB) << "\""
|
| 117 |
+
<< " strokestyle=\"1\"" << " linewidth=\"0\"" << " fillstyle=\"0\"" << " align=\"0\" >\n";
|
| 118 |
+
outf << "<font face=\"";
|
| 119 |
+
if (::strcmp(textinfo.currentFontName.value(), "Times-Roman") == 0)
|
| 120 |
+
outf << "times";
|
| 121 |
+
else
|
| 122 |
+
outf << textinfo.currentFontName.value();
|
| 123 |
+
outf << "\" point-size=\"" << textinfo.currentFontSize << "\"" << " weight=\"";
|
| 124 |
+
if (strcmp(textinfo.currentFontWeight.value(), "Regular") == 0)
|
| 125 |
+
outf << 50;
|
| 126 |
+
else if (strcmp(textinfo.currentFontWeight.value(), "Bold") == 0)
|
| 127 |
+
outf << 87;
|
| 128 |
+
else
|
| 129 |
+
outf << 50;
|
| 130 |
+
outf << "\">\n";
|
| 131 |
+
|
| 132 |
+
const char *c = textinfo.thetext.value();
|
| 133 |
+
while (*c != '\0') {
|
| 134 |
+
if (*c == '<')
|
| 135 |
+
outf << "<";
|
| 136 |
+
else if (*c == '&')
|
| 137 |
+
outf << "&";
|
| 138 |
+
else if (*c == '>')
|
| 139 |
+
outf << ">";
|
| 140 |
+
else
|
| 141 |
+
outf << *c;
|
| 142 |
+
c++;
|
| 143 |
+
}
|
| 144 |
+
outf << "</font></text>\n";
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
void drvKontour::show_path()
|
| 148 |
+
{
|
| 149 |
+
if (isPolygon())
|
| 150 |
+
outf << "<polygon ";
|
| 151 |
+
else
|
| 152 |
+
outf << "<polyline ";
|
| 153 |
+
outf << "matrix=\"1 0 0 0 1 0 0 1\" "
|
| 154 |
+
<< "strokecolor=\"" << currentR() << " "
|
| 155 |
+
<< currentB() << " " << currentG() << "\" "
|
| 156 |
+
<< "strokestyle=\"" << 1 << "\" " << "linewidth=\"" << currentLineWidth() << "\" ";
|
| 157 |
+
if (currentShowType() == drvbase::fill) {
|
| 158 |
+
outf << "fillstyle=\"" << 1 << "\" " << "fillcolor=\"" << cvtColor(currentR())
|
| 159 |
+
<< " " << cvtColor(currentG())
|
| 160 |
+
<< " " << cvtColor(currentB()) << "\" ";
|
| 161 |
+
} else if (currentShowType() == drvbase::eofill) {
|
| 162 |
+
} else {
|
| 163 |
+
outf << "fillstyle=\"" << 0 << "\" ";
|
| 164 |
+
}
|
| 165 |
+
outf << "arrow1=\"0\" " << "arrow2=\"0\">\n";
|
| 166 |
+
print_coords();
|
| 167 |
+
if (isPolygon())
|
| 168 |
+
outf << "</polygon>\n";
|
| 169 |
+
else
|
| 170 |
+
outf << "</polyline>\n";
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
void drvKontour::show_rectangle(const float llx, const float lly,
|
| 174 |
+
const float urx, const float ury)
|
| 175 |
+
{
|
| 176 |
+
outf << "<rectangle "
|
| 177 |
+
<< "matrix=\"1 0 0 0 1 0 0 1\" "
|
| 178 |
+
<< "strokecolor=\"" << cvtColor(currentR()) << " "
|
| 179 |
+
<< cvtColor(currentB()) << " " << cvtColor(currentG()) << "\" "
|
| 180 |
+
<< "strokestyle=\"" << 1 << "\" "
|
| 181 |
+
<< "linewidth=\"" << currentLineWidth() << "\" "
|
| 182 |
+
<< "fillstyle=\"" << 0 << "\" "
|
| 183 |
+
<< "x=\"" << llx << "\" "
|
| 184 |
+
<< "y=\"" << currentDeviceHeight - lly << "\" "
|
| 185 |
+
<< "with=\"" << urx - llx << "\" "
|
| 186 |
+
<< "height=\"" << ury - lly << "\" " << "rounding=\"" << 0 << "\"/>" << endl;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
int drvKontour::cvtColor(float c)
|
| 190 |
+
{
|
| 191 |
+
return int ((c * 255.0) + 0.5);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
static DriverDescriptionT < drvKontour > D_Kontour("kil", ".kil format for Kontour", "","kil", false, // backend supports subpathes
|
| 195 |
+
// if subpathes are supported, the backend must deal with
|
| 196 |
+
// sequences of the following form
|
| 197 |
+
// moveto (start of subpath)
|
| 198 |
+
// lineto (a line segment)
|
| 199 |
+
// lineto
|
| 200 |
+
// moveto (start of a new subpath)
|
| 201 |
+
// lineto (a line segment)
|
| 202 |
+
// lineto
|
| 203 |
+
//
|
| 204 |
+
// If this argument is set to false each subpath is drawn
|
| 205 |
+
// individually which might not necessarily represent
|
| 206 |
+
// the original drawing.
|
| 207 |
+
false, // backend supports curves
|
| 208 |
+
false, // backend supports elements which are filled and have edges
|
| 209 |
+
true, // backend supports text
|
| 210 |
+
DriverDescription::noimage, // no support for PNG file images
|
| 211 |
+
DriverDescription::normalopen, false, // if format supports multiple pages in one file
|
| 212 |
+
false
|
| 213 |
+
/*clipping */
|
| 214 |
+
);
|
pool/shard009/C++/0110061_test_api_observer_registry.cc
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2021 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "extensions/browser/api/test/test_api_observer_registry.h"
|
| 6 |
+
|
| 7 |
+
#include <ostream>
|
| 8 |
+
|
| 9 |
+
#include "base/check.h"
|
| 10 |
+
#include "base/no_destructor.h"
|
| 11 |
+
|
| 12 |
+
namespace extensions {
|
| 13 |
+
|
| 14 |
+
TestApiObserverRegistry::TestApiObserverRegistry() = default;
|
| 15 |
+
TestApiObserverRegistry::~TestApiObserverRegistry() = default;
|
| 16 |
+
|
| 17 |
+
// static
|
| 18 |
+
TestApiObserverRegistry* TestApiObserverRegistry::GetInstance() {
|
| 19 |
+
static base::NoDestructor<TestApiObserverRegistry> registry;
|
| 20 |
+
return registry.get();
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
void TestApiObserverRegistry::NotifyTestPassed(
|
| 24 |
+
content::BrowserContext* browser_context) {
|
| 25 |
+
for (auto& observer : observers_) {
|
| 26 |
+
observer.OnTestPassed(browser_context);
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void TestApiObserverRegistry::NotifyTestFailed(
|
| 31 |
+
content::BrowserContext* browser_context,
|
| 32 |
+
const std::string& message) {
|
| 33 |
+
for (auto& observer : observers_) {
|
| 34 |
+
observer.OnTestFailed(browser_context, message);
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
bool TestApiObserverRegistry::NotifyTestMessage(
|
| 39 |
+
TestSendMessageFunction* function,
|
| 40 |
+
const std::string& message) {
|
| 41 |
+
bool any_listener_will_respond = false;
|
| 42 |
+
for (auto& observer : observers_) {
|
| 43 |
+
bool listener_will_respond = observer.OnTestMessage(function, message);
|
| 44 |
+
DCHECK(!any_listener_will_respond || !listener_will_respond)
|
| 45 |
+
<< "Only one listener may reply.";
|
| 46 |
+
any_listener_will_respond =
|
| 47 |
+
any_listener_will_respond || listener_will_respond;
|
| 48 |
+
}
|
| 49 |
+
return any_listener_will_respond;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
void TestApiObserverRegistry::AddObserver(TestApiObserver* observer) {
|
| 53 |
+
observers_.AddObserver(observer);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
void TestApiObserverRegistry::RemoveObserver(TestApiObserver* observer) {
|
| 57 |
+
observers_.RemoveObserver(observer);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
} // namespace extensions
|
pool/shard009/C++/0110064_main.cpp
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "main.h"
|
| 2 |
+
#include "AppDelegate.h"
|
| 3 |
+
#include "cocos2d.h"
|
| 4 |
+
|
| 5 |
+
#include <TCHAR.h>
|
| 6 |
+
#include <stdio.h>
|
| 7 |
+
#include <shellapi.h>
|
| 8 |
+
|
| 9 |
+
using namespace cocos2d;
|
| 10 |
+
|
| 11 |
+
int APIENTRY _tWinMain(HINSTANCE hInstance,
|
| 12 |
+
HINSTANCE hPrevInstance,
|
| 13 |
+
LPTSTR lpCmdLine,
|
| 14 |
+
int nCmdShow)
|
| 15 |
+
{
|
| 16 |
+
UNREFERENCED_PARAMETER(hPrevInstance);
|
| 17 |
+
UNREFERENCED_PARAMETER(lpCmdLine);
|
| 18 |
+
|
| 19 |
+
// set current working directory to executable's path
|
| 20 |
+
{
|
| 21 |
+
// get to path to the exe
|
| 22 |
+
TCHAR exePath[MAX_PATH];
|
| 23 |
+
GetModuleFileName(NULL, exePath, MAX_PATH);
|
| 24 |
+
|
| 25 |
+
// terminate the string at the end of the path
|
| 26 |
+
TCHAR* trailingSlash = wcsrchr(exePath, '\\');
|
| 27 |
+
if(trailingSlash)
|
| 28 |
+
*trailingSlash = NULL;
|
| 29 |
+
|
| 30 |
+
// switch to the directory of the exe
|
| 31 |
+
SetCurrentDirectory(exePath);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
bool fullscreen = false;
|
| 35 |
+
#ifdef NDEBUG
|
| 36 |
+
fullscreen = false;
|
| 37 |
+
#endif
|
| 38 |
+
|
| 39 |
+
// create the application instance
|
| 40 |
+
AppDelegate app;
|
| 41 |
+
|
| 42 |
+
// set the view
|
| 43 |
+
GLView* view = nullptr;
|
| 44 |
+
if (fullscreen)
|
| 45 |
+
view = GLViewImpl::createWithFullScreen("TwoScene");
|
| 46 |
+
else
|
| 47 |
+
view = GLViewImpl::createWithRect("TwoScene", Rect(0, 0, 1024, 768));
|
| 48 |
+
Director::getInstance()->setOpenGLView(view);
|
| 49 |
+
|
| 50 |
+
return Application::getInstance()->run();
|
| 51 |
+
}
|
pool/shard009/C++/0110065_SampleRooFitMgr.cc
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*******************************************************************************
|
| 2 |
+
*
|
| 3 |
+
* Filename : SampleRooFitMgr.cc
|
| 4 |
+
* Description : implementation of roofit manager class
|
| 5 |
+
* Author : Yi-Mu "Enoch" Chen [ ensc@hep1.phys.ntu.edu.tw ]
|
| 6 |
+
*
|
| 7 |
+
*******************************************************************************/
|
| 8 |
+
#include "TstarAnalysis/Common/interface/InitSample.hpp"
|
| 9 |
+
#include "TstarAnalysis/LimitCalc/interface/SampleRooFitMgr.hpp"
|
| 10 |
+
#include <iostream>
|
| 11 |
+
|
| 12 |
+
#include "RooDataSet.h"
|
| 13 |
+
|
| 14 |
+
using namespace std;
|
| 15 |
+
using namespace mgr;
|
| 16 |
+
|
| 17 |
+
/*******************************************************************************
|
| 18 |
+
* Static member function
|
| 19 |
+
*******************************************************************************/
|
| 20 |
+
RooRealVar&
|
| 21 |
+
SampleRooFitMgr::x(){ return *StaticVar( "x" ); }
|
| 22 |
+
|
| 23 |
+
/******************************************************************************/
|
| 24 |
+
|
| 25 |
+
RooRealVar&
|
| 26 |
+
SampleRooFitMgr::w(){ return *StaticVar( "w" ); }
|
| 27 |
+
|
| 28 |
+
/******************************************************************************/
|
| 29 |
+
|
| 30 |
+
double
|
| 31 |
+
SampleRooFitMgr::MinMass(){ return x().getMin(); }
|
| 32 |
+
|
| 33 |
+
/******************************************************************************/
|
| 34 |
+
|
| 35 |
+
double
|
| 36 |
+
SampleRooFitMgr::MaxMass(){ return x().getMax(); }
|
| 37 |
+
|
| 38 |
+
/******************************************************************************/
|
| 39 |
+
|
| 40 |
+
void
|
| 41 |
+
SampleRooFitMgr::InitStaticVars( const double min, const double max )
|
| 42 |
+
{
|
| 43 |
+
StaticNewVar( "x", "m_{t+jet}", "GeV/c^{2}", min, max );
|
| 44 |
+
StaticNewVar( "w", "event_weight", "", -1000, 1000 );
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/*******************************************************************************
|
| 48 |
+
* Constructor and destructor
|
| 49 |
+
*******************************************************************************/
|
| 50 |
+
SampleRooFitMgr::SampleRooFitMgr( const string& name, const ConfigReader& cfg ) :
|
| 51 |
+
Named( name ),
|
| 52 |
+
SampleGroup( name, cfg ),
|
| 53 |
+
RooFitMgr( name )
|
| 54 |
+
{
|
| 55 |
+
definesets();
|
| 56 |
+
|
| 57 |
+
for( auto& sample : SampleList() ){
|
| 58 |
+
// Caching sample wide variable (weight sums.. etc), see Common/src/InitSample.cc
|
| 59 |
+
InitSampleFromEDM( sample );
|
| 60 |
+
|
| 61 |
+
// Fitting the defined dataset, see LimitCalc/src/SampleRooFitMgr_FillSet.cc
|
| 62 |
+
fillsets( sample );
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/******************************************************************************/
|
| 67 |
+
|
| 68 |
+
SampleRooFitMgr::~SampleRooFitMgr()
|
| 69 |
+
{
|
| 70 |
+
// for( const auto& name : VarNameList() ){
|
| 71 |
+
// RooRealVar* var = Var( name );
|
| 72 |
+
// printf( "%-50s %8.4lf %8.4f %8.4f\n", var->GetName(), var->getVal(), var->getErrorHi(), var->getErrorLo() );
|
| 73 |
+
// fflush( stdout );
|
| 74 |
+
// }
|
| 75 |
+
|
| 76 |
+
// for( const auto& name : FuncNameList() ){
|
| 77 |
+
// RooAbsReal* func = Func( name );
|
| 78 |
+
// printf( "%50s %8.1lf\n", func->GetName(), func->getVal() );
|
| 79 |
+
// fflush( stdout );
|
| 80 |
+
// }
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
/*******************************************************************************
|
| 85 |
+
* RooAbsData argument options
|
| 86 |
+
*******************************************************************************/
|
| 87 |
+
RooAbsData*
|
| 88 |
+
SampleRooFitMgr::NewDataSet( const std::string& name )
|
| 89 |
+
{
|
| 90 |
+
if( DataSet( name ) ){
|
| 91 |
+
return DataSet( name );
|
| 92 |
+
} else {
|
| 93 |
+
RooDataSet* set = new RooDataSet(// Using unbinned RooDataSet object
|
| 94 |
+
name.c_str(), "",
|
| 95 |
+
RooArgSet( x(), w() ),
|
| 96 |
+
RooFit::WeightVar( w() )
|
| 97 |
+
);
|
| 98 |
+
AddDataSet( set );
|
| 99 |
+
return set;
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/******************************************************************************/
|
| 104 |
+
|
| 105 |
+
RooAbsData*
|
| 106 |
+
SampleRooFitMgr::DataSet( const std::string& name )
|
| 107 |
+
{
|
| 108 |
+
return RooFitMgr::DataSet( name );
|
| 109 |
+
}
|
pool/shard009/C++/0110078_guide_algorithm_lowpass.cpp
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* guide_algorithm_lowpass.cpp
|
| 3 |
+
* PHD Guiding
|
| 4 |
+
*
|
| 5 |
+
* Created by Bret McKee
|
| 6 |
+
* Copyright (c) 2012 Bret McKee
|
| 7 |
+
* All rights reserved.
|
| 8 |
+
*
|
| 9 |
+
* Based upon work by Craig Stark.
|
| 10 |
+
* Copyright (c) 2006-2010 Craig Stark.
|
| 11 |
+
* All rights reserved.
|
| 12 |
+
*
|
| 13 |
+
* This source code is distributed under the following "BSD" license
|
| 14 |
+
* Redistribution and use in source and binary forms, with or without
|
| 15 |
+
* modification, are permitted provided that the following conditions are met:
|
| 16 |
+
* Redistributions of source code must retain the above copyright notice,
|
| 17 |
+
* this list of conditions and the following disclaimer.
|
| 18 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 19 |
+
* this list of conditions and the following disclaimer in the
|
| 20 |
+
* documentation and/or other materials provided with the distribution.
|
| 21 |
+
* Neither the name of Bret McKee, Dad Dog Development,
|
| 22 |
+
* Craig Stark, Stark Labs nor the names of its
|
| 23 |
+
* contributors may be used to endorse or promote products derived from
|
| 24 |
+
* this software without specific prior written permission.
|
| 25 |
+
*
|
| 26 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 27 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 28 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 29 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
| 30 |
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 31 |
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 32 |
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 33 |
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 34 |
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 35 |
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 36 |
+
* POSSIBILITY OF SUCH DAMAGE.
|
| 37 |
+
*
|
| 38 |
+
*/
|
| 39 |
+
|
| 40 |
+
#include "phd.h"
|
| 41 |
+
|
| 42 |
+
static const double DefaultMinMove = 0.2;
|
| 43 |
+
static const double DefaultSlopeWeight = 5.0;
|
| 44 |
+
|
| 45 |
+
GuideAlgorithmLowpass::GuideAlgorithmLowpass(Mount *pMount, GuideAxis axis)
|
| 46 |
+
: GuideAlgorithm(pMount, axis)
|
| 47 |
+
{
|
| 48 |
+
double minMove = pConfig->Profile.GetDouble(GetConfigPath() + "/minMove", DefaultMinMove);
|
| 49 |
+
SetMinMove(minMove);
|
| 50 |
+
|
| 51 |
+
double slopeWeight = pConfig->Profile.GetDouble(GetConfigPath() + "/SlopeWeight", DefaultSlopeWeight);
|
| 52 |
+
SetSlopeWeight(slopeWeight);
|
| 53 |
+
|
| 54 |
+
reset();
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
GuideAlgorithmLowpass::~GuideAlgorithmLowpass(void)
|
| 58 |
+
{
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
GUIDE_ALGORITHM GuideAlgorithmLowpass::Algorithm(void)
|
| 62 |
+
{
|
| 63 |
+
return GUIDE_ALGORITHM_LOWPASS;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
void GuideAlgorithmLowpass::reset(void)
|
| 67 |
+
{
|
| 68 |
+
m_history.Empty();
|
| 69 |
+
|
| 70 |
+
while (m_history.GetCount() < HISTORY_SIZE)
|
| 71 |
+
{
|
| 72 |
+
m_history.Add(0.0);
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
double GuideAlgorithmLowpass::result(double input)
|
| 77 |
+
{
|
| 78 |
+
m_history.Add(input);
|
| 79 |
+
|
| 80 |
+
ArrayOfDbl sortedHistory(m_history);
|
| 81 |
+
sortedHistory.Sort(dbl_sort_func);
|
| 82 |
+
|
| 83 |
+
m_history.RemoveAt(0);
|
| 84 |
+
unsigned int numpts = m_history.GetCount();
|
| 85 |
+
|
| 86 |
+
double median = sortedHistory[sortedHistory.GetCount()/2];
|
| 87 |
+
double slope = CalcSlope(m_history);
|
| 88 |
+
double dReturn = median + m_slopeWeight*slope;
|
| 89 |
+
|
| 90 |
+
if (fabs(dReturn) > fabs(input))
|
| 91 |
+
{
|
| 92 |
+
Debug.Write(wxString::Format("GuideAlgorithmLowpass::Result() input %.2f is < calculated value %.2f, using input\n", input, dReturn));
|
| 93 |
+
dReturn = input;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
//TODO: Undertand this. I think this is wrong, since it divides the orignial input
|
| 97 |
+
// by 11 if it was less than the computed value. And since the computed
|
| 98 |
+
// value is median + slope, I'm not sure that it should be divided by 11
|
| 99 |
+
// either. But the goal of this exercise is to be bug for bug compatible
|
| 100 |
+
// with PHD 1.x
|
| 101 |
+
|
| 102 |
+
if (fabs(input) < m_minMove)
|
| 103 |
+
{
|
| 104 |
+
dReturn = 0.0;
|
| 105 |
+
}
|
| 106 |
+
else
|
| 107 |
+
{
|
| 108 |
+
// Look for a direction reversal - possibly due to backlash comp
|
| 109 |
+
if (numpts > 2 && (m_history[numpts - 2] * m_history[numpts - 1] < 0))
|
| 110 |
+
m_pMount->FlagBacklashOverShoot(fabs(input) - m_minMove, m_guideAxis);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
Debug.Write(wxString::Format("GuideAlgorithmLowpass::Result() returns %.2f from input %.2f\n", dReturn, input));
|
| 114 |
+
|
| 115 |
+
return dReturn;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
double GuideAlgorithmLowpass::GetMinMove(void)
|
| 119 |
+
{
|
| 120 |
+
return m_minMove;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
bool GuideAlgorithmLowpass::SetMinMove(double minMove)
|
| 124 |
+
{
|
| 125 |
+
bool bError = false;
|
| 126 |
+
|
| 127 |
+
try
|
| 128 |
+
{
|
| 129 |
+
if (minMove < 0)
|
| 130 |
+
{
|
| 131 |
+
throw ERROR_INFO("invalid minMove");
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
m_minMove = minMove;
|
| 135 |
+
|
| 136 |
+
}
|
| 137 |
+
catch (wxString Msg)
|
| 138 |
+
{
|
| 139 |
+
POSSIBLY_UNUSED(Msg);
|
| 140 |
+
bError = true;
|
| 141 |
+
m_minMove = DefaultMinMove;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
pConfig->Profile.SetDouble(GetConfigPath() + "/minMove", m_minMove);
|
| 145 |
+
|
| 146 |
+
return bError;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
double GuideAlgorithmLowpass::GetSlopeWeight(void)
|
| 150 |
+
{
|
| 151 |
+
return m_slopeWeight;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
bool GuideAlgorithmLowpass::SetSlopeWeight(double slopeWeight)
|
| 155 |
+
{
|
| 156 |
+
bool bError = false;
|
| 157 |
+
|
| 158 |
+
try
|
| 159 |
+
{
|
| 160 |
+
if (slopeWeight < 0.0)
|
| 161 |
+
{
|
| 162 |
+
throw ERROR_INFO("invalid slopeWeight");
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
m_slopeWeight = slopeWeight;
|
| 166 |
+
}
|
| 167 |
+
catch (wxString Msg)
|
| 168 |
+
{
|
| 169 |
+
POSSIBLY_UNUSED(Msg);
|
| 170 |
+
bError = true;
|
| 171 |
+
m_slopeWeight = DefaultSlopeWeight;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
pConfig->Profile.SetDouble(GetConfigPath() + "/SlopeWeight", m_slopeWeight);
|
| 175 |
+
|
| 176 |
+
return bError;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
wxString GuideAlgorithmLowpass::GetSettingsSummary()
|
| 180 |
+
{
|
| 181 |
+
// return a loggable summary of current mount settings
|
| 182 |
+
return wxString::Format("Slope weight = %.3f, Minimum move = %.3f\n",
|
| 183 |
+
GetSlopeWeight(),
|
| 184 |
+
GetMinMove()
|
| 185 |
+
);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
ConfigDialogPane *GuideAlgorithmLowpass::GetConfigDialogPane(wxWindow *pParent)
|
| 189 |
+
{
|
| 190 |
+
return new GuideAlgorithmLowpassConfigDialogPane(pParent, this);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
GuideAlgorithmLowpass::
|
| 194 |
+
GuideAlgorithmLowpassConfigDialogPane::
|
| 195 |
+
GuideAlgorithmLowpassConfigDialogPane(wxWindow *pParent, GuideAlgorithmLowpass *pGuideAlgorithm)
|
| 196 |
+
: ConfigDialogPane(_("Lowpass Guide Algorithm"), pParent)
|
| 197 |
+
{
|
| 198 |
+
int width;
|
| 199 |
+
|
| 200 |
+
m_pGuideAlgorithm = pGuideAlgorithm;
|
| 201 |
+
|
| 202 |
+
width = StringWidth(_T("000.00"));
|
| 203 |
+
m_pSlopeWeight = new wxSpinCtrlDouble(pParent, wxID_ANY,_T("foo2"), wxPoint(-1,-1),
|
| 204 |
+
wxSize(width+30, -1), wxSP_ARROW_KEYS, 0.0, 20.0, 0.0, 0.5,_T("SlopeWeight"));
|
| 205 |
+
m_pSlopeWeight->SetDigits(2);
|
| 206 |
+
|
| 207 |
+
DoAdd(_("Slope Weight"), m_pSlopeWeight,
|
| 208 |
+
_("Weighting of slope parameter in lowpass auto-dec"));
|
| 209 |
+
|
| 210 |
+
width = StringWidth(_T("000.00"));
|
| 211 |
+
m_pMinMove = new wxSpinCtrlDouble(pParent, wxID_ANY,_T("foo2"), wxPoint(-1,-1),
|
| 212 |
+
wxSize(width+30, -1), wxSP_ARROW_KEYS, 0.0, 20.0, 0.0, 0.05,_T("MinMove"));
|
| 213 |
+
m_pMinMove->SetDigits(2);
|
| 214 |
+
|
| 215 |
+
DoAdd(_("Minimum Move (pixels)"), m_pMinMove,
|
| 216 |
+
_("How many (fractional) pixels must the star move to trigger a guide pulse? Default = 0.15"));
|
| 217 |
+
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
GuideAlgorithmLowpass::
|
| 221 |
+
GuideAlgorithmLowpassConfigDialogPane::
|
| 222 |
+
~GuideAlgorithmLowpassConfigDialogPane(void)
|
| 223 |
+
{
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
void GuideAlgorithmLowpass::
|
| 227 |
+
GuideAlgorithmLowpassConfigDialogPane::
|
| 228 |
+
LoadValues(void)
|
| 229 |
+
{
|
| 230 |
+
m_pSlopeWeight->SetValue(m_pGuideAlgorithm->GetSlopeWeight());
|
| 231 |
+
m_pMinMove->SetValue(m_pGuideAlgorithm->GetMinMove());
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
void GuideAlgorithmLowpass::
|
| 235 |
+
GuideAlgorithmLowpassConfigDialogPane::
|
| 236 |
+
UnloadValues(void)
|
| 237 |
+
{
|
| 238 |
+
m_pGuideAlgorithm->SetSlopeWeight(m_pSlopeWeight->GetValue());
|
| 239 |
+
m_pGuideAlgorithm->SetMinMove(m_pMinMove->GetValue());
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
GraphControlPane *GuideAlgorithmLowpass::GetGraphControlPane(wxWindow *pParent, const wxString& label)
|
| 243 |
+
{
|
| 244 |
+
return new GuideAlgorithmLowpassGraphControlPane(pParent, this, label);
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
GuideAlgorithmLowpass::
|
| 248 |
+
GuideAlgorithmLowpassGraphControlPane::
|
| 249 |
+
GuideAlgorithmLowpassGraphControlPane(wxWindow *pParent, GuideAlgorithmLowpass *pGuideAlgorithm, const wxString& label)
|
| 250 |
+
: GraphControlPane(pParent, label)
|
| 251 |
+
{
|
| 252 |
+
int width;
|
| 253 |
+
|
| 254 |
+
m_pGuideAlgorithm = pGuideAlgorithm;
|
| 255 |
+
|
| 256 |
+
width = StringWidth(_T("000.00"));
|
| 257 |
+
m_pSlopeWeight = new wxSpinCtrlDouble(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
| 258 |
+
wxSize(width+30, -1), wxSP_ARROW_KEYS, 0.0, 20.0, 0.0, 0.5,_T("SlopeWeight"));
|
| 259 |
+
m_pSlopeWeight->SetDigits(2);
|
| 260 |
+
m_pSlopeWeight->Bind(wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, &GuideAlgorithmLowpass::GuideAlgorithmLowpassGraphControlPane::OnSlopeWeightSpinCtrlDouble, this);
|
| 261 |
+
DoAdd(m_pSlopeWeight, _("Sl W"));
|
| 262 |
+
|
| 263 |
+
width = StringWidth(_T("000.00"));
|
| 264 |
+
m_pMinMove = new wxSpinCtrlDouble(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
| 265 |
+
wxSize(width+30, -1), wxSP_ARROW_KEYS, 0.0, 20.0, 0.0, 0.05,_T("MinMove"));
|
| 266 |
+
m_pMinMove->SetDigits(2);
|
| 267 |
+
m_pMinMove->Bind(wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, &GuideAlgorithmLowpass::GuideAlgorithmLowpassGraphControlPane::OnMinMoveSpinCtrlDouble, this);
|
| 268 |
+
DoAdd(m_pMinMove, _("MnMo"));
|
| 269 |
+
|
| 270 |
+
m_pSlopeWeight->SetValue(m_pGuideAlgorithm->GetSlopeWeight());
|
| 271 |
+
m_pMinMove->SetValue(m_pGuideAlgorithm->GetMinMove());
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
GuideAlgorithmLowpass::
|
| 275 |
+
GuideAlgorithmLowpassGraphControlPane::
|
| 276 |
+
~GuideAlgorithmLowpassGraphControlPane(void)
|
| 277 |
+
{
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
void GuideAlgorithmLowpass::
|
| 281 |
+
GuideAlgorithmLowpassGraphControlPane::
|
| 282 |
+
OnSlopeWeightSpinCtrlDouble(wxSpinDoubleEvent& evt)
|
| 283 |
+
{
|
| 284 |
+
m_pGuideAlgorithm->SetSlopeWeight(m_pSlopeWeight->GetValue());
|
| 285 |
+
GuideLog.SetGuidingParam(m_pGuideAlgorithm->GetAxis() + " Low-pass slope weight", m_pSlopeWeight->GetValue());
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
void GuideAlgorithmLowpass::
|
| 289 |
+
GuideAlgorithmLowpassGraphControlPane::
|
| 290 |
+
OnMinMoveSpinCtrlDouble(wxSpinDoubleEvent& evt)
|
| 291 |
+
{
|
| 292 |
+
m_pGuideAlgorithm->SetMinMove(m_pMinMove->GetValue());
|
| 293 |
+
GuideLog.SetGuidingParam(m_pGuideAlgorithm->GetAxis() + " Low-pass minimum move", m_pMinMove->GetValue());
|
| 294 |
+
}
|
pool/shard009/C++/0110079_MetadataParser.cpp
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#if defined(ENABLE_METADATAPARSER)
|
| 2 |
+
|
| 3 |
+
#include "MetadataParser.h"
|
| 4 |
+
#include "Trace.h"
|
| 5 |
+
#include <libcpphaggle/Pair.h>
|
| 6 |
+
|
| 7 |
+
unsigned int MetadataParser::num = 0;
|
| 8 |
+
MetadataParser::registry_t MetadataParser::registry;
|
| 9 |
+
|
| 10 |
+
MetadataParser::MetadataParser(const string _parsekey) : parsekey(_parsekey)
|
| 11 |
+
{
|
| 12 |
+
Pair<registry_t::iterator, bool> ret;
|
| 13 |
+
|
| 14 |
+
ret = registry.insert(make_pair(parsekey, this));
|
| 15 |
+
|
| 16 |
+
if (!ret.second) {
|
| 17 |
+
HAGGLE_ERR("Parser with given name '%s' already registered", parsekey.c_str());
|
| 18 |
+
return;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
HAGGLE_DBG("Registered metadata parser with key \'%s\'\n", parsekey.c_str());
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
MetadataParser::~MetadataParser()
|
| 25 |
+
{
|
| 26 |
+
HAGGLE_DBG("Unregistered metadata parser with key \'%s\'\n", parsekey.c_str());
|
| 27 |
+
registry.erase(parsekey);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
MetadataParser *MetadataParser::getParser(string& key)
|
| 31 |
+
{
|
| 32 |
+
registry_t::iterator it = registry.find(key);
|
| 33 |
+
return (it == registry.end() ? NULL : (*it).second);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
#endif /* ENABLE_METADATAPARSER */
|
pool/shard009/C++/0110086_TestThriftCpp.cpp
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 3 |
+
* or more contributor license agreements. See the NOTICE file
|
| 4 |
+
* distributed with this work for additional information
|
| 5 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 6 |
+
* to you under the Apache License, Version 2.0 (the
|
| 7 |
+
* "License"); you may not use this file except in compliance
|
| 8 |
+
* with the License. You may obtain a copy of the License at
|
| 9 |
+
*
|
| 10 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
*
|
| 12 |
+
* Unless required by applicable law or agreed to in writing,
|
| 13 |
+
* software distributed under the License is distributed on an
|
| 14 |
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 15 |
+
* KIND, either express or implied. See the License for the
|
| 16 |
+
* specific language governing permissions and limitations
|
| 17 |
+
* under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <stdio.h>
|
| 21 |
+
#include <stdlib.h>
|
| 22 |
+
#include <string.h>
|
| 23 |
+
#include <unistd.h>
|
| 24 |
+
#include <sys/time.h>
|
| 25 |
+
|
| 26 |
+
#include <protocol/TBinaryProtocol.h>
|
| 27 |
+
#include <transport/TSocket.h>
|
| 28 |
+
#include <transport/TTransportUtils.h>
|
| 29 |
+
|
| 30 |
+
#include "../gen-cpp/ThriftNeptuneService.h"
|
| 31 |
+
|
| 32 |
+
using namespace std;
|
| 33 |
+
using namespace apache::thrift;
|
| 34 |
+
using namespace apache::thrift::protocol;
|
| 35 |
+
using namespace apache::thrift::transport;
|
| 36 |
+
|
| 37 |
+
using namespace neptune;
|
| 38 |
+
using namespace boost;
|
| 39 |
+
|
| 40 |
+
int main(int argc, char** argv) {
|
| 41 |
+
if(argc < 3) {
|
| 42 |
+
printf("Usage: TestThriftCpp <thrift server host> <port>\n");
|
| 43 |
+
printf(" TestThriftCpp localhost 7002\n");
|
| 44 |
+
return 0;
|
| 45 |
+
}
|
| 46 |
+
shared_ptr<TTransport> socket(new TSocket(argv[1], atoi(argv[2])));
|
| 47 |
+
shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
| 48 |
+
shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
| 49 |
+
ThriftNeptuneServiceClient client(protocol);
|
| 50 |
+
|
| 51 |
+
try {
|
| 52 |
+
transport->open();
|
| 53 |
+
|
| 54 |
+
ThriftTableSchema schema;
|
| 55 |
+
client.descTable(schema, "META");
|
| 56 |
+
printf("Test OK\n");
|
| 57 |
+
printf("TableName: %s\n", schema.tableName.c_str());
|
| 58 |
+
transport->close();
|
| 59 |
+
} catch (TException &tx) {
|
| 60 |
+
printf("ERROR: %s\n", tx.what());
|
| 61 |
+
}
|
| 62 |
+
}
|
pool/shard009/C++/0110087_PrefixLevelStorageMetrics.cpp
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
| 3 |
+
* SPDX-License-Identifier: Apache-2.0.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#include <aws/s3control/model/PrefixLevelStorageMetrics.h>
|
| 7 |
+
#include <aws/core/utils/xml/XmlSerializer.h>
|
| 8 |
+
#include <aws/core/utils/StringUtils.h>
|
| 9 |
+
#include <aws/core/utils/memory/stl/AWSStringStream.h>
|
| 10 |
+
|
| 11 |
+
#include <utility>
|
| 12 |
+
|
| 13 |
+
using namespace Aws::Utils::Xml;
|
| 14 |
+
using namespace Aws::Utils;
|
| 15 |
+
|
| 16 |
+
namespace Aws
|
| 17 |
+
{
|
| 18 |
+
namespace S3Control
|
| 19 |
+
{
|
| 20 |
+
namespace Model
|
| 21 |
+
{
|
| 22 |
+
|
| 23 |
+
PrefixLevelStorageMetrics::PrefixLevelStorageMetrics() :
|
| 24 |
+
m_isEnabled(false),
|
| 25 |
+
m_isEnabledHasBeenSet(false),
|
| 26 |
+
m_selectionCriteriaHasBeenSet(false)
|
| 27 |
+
{
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
PrefixLevelStorageMetrics::PrefixLevelStorageMetrics(const XmlNode& xmlNode) :
|
| 31 |
+
m_isEnabled(false),
|
| 32 |
+
m_isEnabledHasBeenSet(false),
|
| 33 |
+
m_selectionCriteriaHasBeenSet(false)
|
| 34 |
+
{
|
| 35 |
+
*this = xmlNode;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
PrefixLevelStorageMetrics& PrefixLevelStorageMetrics::operator =(const XmlNode& xmlNode)
|
| 39 |
+
{
|
| 40 |
+
XmlNode resultNode = xmlNode;
|
| 41 |
+
|
| 42 |
+
if(!resultNode.IsNull())
|
| 43 |
+
{
|
| 44 |
+
XmlNode isEnabledNode = resultNode.FirstChild("IsEnabled");
|
| 45 |
+
if(!isEnabledNode.IsNull())
|
| 46 |
+
{
|
| 47 |
+
m_isEnabled = StringUtils::ConvertToBool(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(isEnabledNode.GetText()).c_str()).c_str());
|
| 48 |
+
m_isEnabledHasBeenSet = true;
|
| 49 |
+
}
|
| 50 |
+
XmlNode selectionCriteriaNode = resultNode.FirstChild("SelectionCriteria");
|
| 51 |
+
if(!selectionCriteriaNode.IsNull())
|
| 52 |
+
{
|
| 53 |
+
m_selectionCriteria = selectionCriteriaNode;
|
| 54 |
+
m_selectionCriteriaHasBeenSet = true;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
return *this;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void PrefixLevelStorageMetrics::AddToNode(XmlNode& parentNode) const
|
| 62 |
+
{
|
| 63 |
+
Aws::StringStream ss;
|
| 64 |
+
if(m_isEnabledHasBeenSet)
|
| 65 |
+
{
|
| 66 |
+
XmlNode isEnabledNode = parentNode.CreateChildElement("IsEnabled");
|
| 67 |
+
ss << std::boolalpha << m_isEnabled;
|
| 68 |
+
isEnabledNode.SetText(ss.str());
|
| 69 |
+
ss.str("");
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if(m_selectionCriteriaHasBeenSet)
|
| 73 |
+
{
|
| 74 |
+
XmlNode selectionCriteriaNode = parentNode.CreateChildElement("SelectionCriteria");
|
| 75 |
+
m_selectionCriteria.AddToNode(selectionCriteriaNode);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
} // namespace Model
|
| 81 |
+
} // namespace S3Control
|
| 82 |
+
} // namespace Aws
|
pool/shard009/C++/0110088_array.cpp
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "array.h"
|
| 2 |
+
|
| 3 |
+
#include <valarray>
|
| 4 |
+
#include <cstdarg>
|
| 5 |
+
#include <iostream>
|
| 6 |
+
#include <ostream>
|
| 7 |
+
#include <ios>
|
| 8 |
+
|
| 9 |
+
using std::valarray;
|
| 10 |
+
using std::cerr;
|
| 11 |
+
using std::endl;
|
| 12 |
+
using std::slice_array;
|
| 13 |
+
using std::slice;
|
| 14 |
+
using std::ostream;
|
| 15 |
+
|
| 16 |
+
Array::Array(int n, int len) : dims(n), mem(len) {
|
| 17 |
+
for (int i=0; i < (int)mem.size(); i++)
|
| 18 |
+
mem[i] = 0;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
int prod(std::valarray<int> x) {
|
| 22 |
+
int res = 1;
|
| 23 |
+
for (int i=0; i < (int)x.size(); i++) {
|
| 24 |
+
res *= x[i];
|
| 25 |
+
}
|
| 26 |
+
return res;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
double& Array::pos(Nop nop, ...) {
|
| 30 |
+
va_list ap;
|
| 31 |
+
va_start(ap, nop);
|
| 32 |
+
int dimprod = 1;
|
| 33 |
+
int cell = 0;
|
| 34 |
+
for (int i = 0; i < (int)dims.size(); i++) {
|
| 35 |
+
int x = va_arg(ap, int);
|
| 36 |
+
cell += dimprod*x;
|
| 37 |
+
dimprod *= dims[i];
|
| 38 |
+
}
|
| 39 |
+
va_end(ap);
|
| 40 |
+
return mem[cell];
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
void Array::set_dims(Nop nop, ...) {
|
| 44 |
+
va_list ap;
|
| 45 |
+
va_start(ap, nop);
|
| 46 |
+
for (int i = 0; i < (int)dims.size(); i++) {
|
| 47 |
+
int d = va_arg(ap, int);
|
| 48 |
+
dims[i] = d;
|
| 49 |
+
}
|
| 50 |
+
va_end(ap);
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
double& Array::posi(int i) {
|
| 55 |
+
return mem[i];
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* A print stream operator for Array objects */
|
| 59 |
+
ostream& operator<<(ostream &s, const Array &a) {
|
| 60 |
+
int p = prod(a.dims);
|
| 61 |
+
std::ios_base::fmtflags old = s.flags();
|
| 62 |
+
s.setf(std::ios_base::fixed);
|
| 63 |
+
s.precision(9);
|
| 64 |
+
s << "dims has product p=" << p << endl << " ";
|
| 65 |
+
for (int i=0; i <(int)a.mem.size(); i++) {
|
| 66 |
+
s << a.mem[i] << " ";
|
| 67 |
+
if ((i+1) % 6 == 0)
|
| 68 |
+
s << endl << " ";
|
| 69 |
+
}
|
| 70 |
+
s.flags(old);
|
| 71 |
+
return s;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
/* END */
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
pool/shard009/C++/0110089_HarvbotStepper.cpp
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <math.h>
|
| 2 |
+
#include "HarvbotStepper.h"
|
| 3 |
+
|
| 4 |
+
void HarvbotStepper::moveTo(long absolute)
|
| 5 |
+
{
|
| 6 |
+
if (_targetPos != absolute)
|
| 7 |
+
{
|
| 8 |
+
_direction = (absolute > _targetPos) ? DIRECTION_CW : DIRECTION_CCW;
|
| 9 |
+
|
| 10 |
+
unsigned int time = 0;
|
| 11 |
+
do
|
| 12 |
+
{
|
| 13 |
+
time = micros();
|
| 14 |
+
} while (time < _lastStepTime + _pulsePeriod);
|
| 15 |
+
digitalWrite(_dirPin, _direction ? HIGH : LOW);
|
| 16 |
+
|
| 17 |
+
_targetPos = absolute;
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
void HarvbotStepper::move(long relative)
|
| 22 |
+
{
|
| 23 |
+
moveTo(_currentPos + relative);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
bool HarvbotStepper::runSpeed()
|
| 27 |
+
{
|
| 28 |
+
if (distanceToGo() != 0)
|
| 29 |
+
{
|
| 30 |
+
unsigned int time = micros();
|
| 31 |
+
if (time < _lastStepTime + _pulsePeriod)
|
| 32 |
+
{
|
| 33 |
+
return true;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
_lastStepTime = time;
|
| 37 |
+
|
| 38 |
+
if (_direction == DIRECTION_CW)
|
| 39 |
+
{
|
| 40 |
+
// Clockwise
|
| 41 |
+
_currentPos += 1;
|
| 42 |
+
}
|
| 43 |
+
else
|
| 44 |
+
{
|
| 45 |
+
// Anticlockwise
|
| 46 |
+
_currentPos -= 1;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
step(_currentPos);
|
| 50 |
+
return true;
|
| 51 |
+
}
|
| 52 |
+
else
|
| 53 |
+
{
|
| 54 |
+
return false;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
long HarvbotStepper::distanceToGo()
|
| 59 |
+
{
|
| 60 |
+
return _targetPos - _currentPos;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
long HarvbotStepper::targetPosition()
|
| 64 |
+
{
|
| 65 |
+
return _targetPos;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
long HarvbotStepper::currentPosition()
|
| 69 |
+
{
|
| 70 |
+
return _currentPos;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
void HarvbotStepper::setCurrentPosition(long position)
|
| 74 |
+
{
|
| 75 |
+
_targetPos = _currentPos = position;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
bool HarvbotStepper::run()
|
| 79 |
+
{
|
| 80 |
+
if (runSpeed())
|
| 81 |
+
return distanceToGo() != 0;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
HarvbotStepper::HarvbotStepper(uint8_t stepPin, uint8_t dirPin, bool enable)
|
| 85 |
+
{
|
| 86 |
+
_stepPin = stepPin;
|
| 87 |
+
_dirPin = dirPin;
|
| 88 |
+
_currentPos = 0;
|
| 89 |
+
_targetPos = 0;
|
| 90 |
+
setEngineFrequency(1000);
|
| 91 |
+
_enablePin = 0xff;
|
| 92 |
+
_lastStepTime = 0;
|
| 93 |
+
|
| 94 |
+
// NEW
|
| 95 |
+
_direction = DIRECTION_CCW;
|
| 96 |
+
|
| 97 |
+
if (enable)
|
| 98 |
+
enableOutputs();
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
void HarvbotStepper::setEngineFrequency(unsigned int frequency)
|
| 102 |
+
{
|
| 103 |
+
_engineFrequency = frequency;
|
| 104 |
+
_pulsePeriod = 1000000 / frequency;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
unsigned int HarvbotStepper::engineFrequency()
|
| 108 |
+
{
|
| 109 |
+
return _engineFrequency;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
void HarvbotStepper::setPulsePeriod(unsigned int waitInterval)
|
| 113 |
+
{
|
| 114 |
+
if (_engineFrequency < 1000000 / _engineFrequency)
|
| 115 |
+
{
|
| 116 |
+
_pulsePeriod = 1000000 / _engineFrequency;
|
| 117 |
+
}
|
| 118 |
+
else
|
| 119 |
+
{
|
| 120 |
+
_pulsePeriod = waitInterval;
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
unsigned int HarvbotStepper::pulsePeriod()
|
| 125 |
+
{
|
| 126 |
+
return _pulsePeriod;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
bool HarvbotStepper::direction()
|
| 130 |
+
{
|
| 131 |
+
return _direction;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
// Subclasses can override
|
| 135 |
+
void HarvbotStepper::step(long step)
|
| 136 |
+
{
|
| 137 |
+
digitalWrite(_stepPin, HIGH); // Set direction first else get rogue pulses
|
| 138 |
+
delayMicroseconds(1);
|
| 139 |
+
digitalWrite(_stepPin, LOW); // step LOW
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
// Prevents power consumption on the outputs
|
| 143 |
+
void HarvbotStepper::disableOutputs()
|
| 144 |
+
{
|
| 145 |
+
digitalWrite(_dirPin, LOW);
|
| 146 |
+
digitalWrite(_stepPin, LOW);
|
| 147 |
+
if (_enablePin != 0xff)
|
| 148 |
+
digitalWrite(_enablePin, LOW ^ _enableInverted);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
void HarvbotStepper::enableOutputs()
|
| 152 |
+
{
|
| 153 |
+
pinMode(_dirPin, OUTPUT);
|
| 154 |
+
pinMode(_stepPin, OUTPUT);
|
| 155 |
+
|
| 156 |
+
if (_enablePin != 0xff)
|
| 157 |
+
{
|
| 158 |
+
pinMode(_enablePin, OUTPUT);
|
| 159 |
+
digitalWrite(_enablePin, HIGH ^ _enableInverted);
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
void HarvbotStepper::setEnablePin(uint8_t enablePin)
|
| 164 |
+
{
|
| 165 |
+
_enablePin = enablePin;
|
| 166 |
+
|
| 167 |
+
// This happens after construction, so init pin now.
|
| 168 |
+
if (_enablePin != 0xff)
|
| 169 |
+
{
|
| 170 |
+
pinMode(_enablePin, OUTPUT);
|
| 171 |
+
digitalWrite(_enablePin, HIGH ^ _enableInverted);
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
// Blocks until the target position is reached and stopped
|
| 176 |
+
void HarvbotStepper::runToPosition()
|
| 177 |
+
{
|
| 178 |
+
while (run())
|
| 179 |
+
;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
bool HarvbotStepper::runSpeedToPosition()
|
| 183 |
+
{
|
| 184 |
+
if (_targetPos == _currentPos)
|
| 185 |
+
return false;
|
| 186 |
+
if (_targetPos >_currentPos)
|
| 187 |
+
_direction = DIRECTION_CW;
|
| 188 |
+
else
|
| 189 |
+
_direction = DIRECTION_CCW;
|
| 190 |
+
return runSpeed();
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// Blocks until the new target position is reached
|
| 194 |
+
void HarvbotStepper::runToNewPosition(long position)
|
| 195 |
+
{
|
| 196 |
+
moveTo(position);
|
| 197 |
+
runToPosition();
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
void HarvbotStepper::stop()
|
| 201 |
+
{
|
| 202 |
+
digitalWrite(_dirPin, LOW);
|
| 203 |
+
digitalWrite(_stepPin, LOW);
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
uint8_t HarvbotStepper::stepPin()
|
| 207 |
+
{
|
| 208 |
+
return _stepPin;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
uint8_t HarvbotStepper::directionPin()
|
| 212 |
+
{
|
| 213 |
+
return _dirPin;
|
| 214 |
+
}
|
pool/shard009/C++/0110095_if_tests.cpp
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*=============================================================================
|
| 2 |
+
Copyright (c) 2004 Stefan Slapeta
|
| 3 |
+
Copyright (c) 2002-2003 Martin Wille
|
| 4 |
+
http://spirit.sourceforge.net/
|
| 5 |
+
|
| 6 |
+
Use, modification and distribution is subject to the Boost Software
|
| 7 |
+
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
| 8 |
+
http://www.boost.org/LICENSE_1_0.txt)
|
| 9 |
+
=============================================================================*/
|
| 10 |
+
// vi:ts=4:sw=4:et
|
| 11 |
+
// Tests for BOOST_SPIRIT_CLASSIC_NS::if_p
|
| 12 |
+
// [28-Dec-2002]
|
| 13 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 14 |
+
#include <iostream>
|
| 15 |
+
#include <cstring>
|
| 16 |
+
#include <boost/spirit/include/classic_core.hpp>
|
| 17 |
+
#include <boost/spirit/include/classic_if.hpp>
|
| 18 |
+
#include <boost/spirit/include/classic_assign_actor.hpp>
|
| 19 |
+
#include <boost/ref.hpp>
|
| 20 |
+
#include "impl/string_length.hpp"
|
| 21 |
+
|
| 22 |
+
namespace local
|
| 23 |
+
{
|
| 24 |
+
template <typename T>
|
| 25 |
+
struct var_wrapper
|
| 26 |
+
: public ::boost::reference_wrapper<T>
|
| 27 |
+
{
|
| 28 |
+
typedef ::boost::reference_wrapper<T> parent;
|
| 29 |
+
|
| 30 |
+
explicit inline var_wrapper(T& t) : parent(t) {}
|
| 31 |
+
|
| 32 |
+
inline T& operator()() const { return parent::get(); }
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
template <typename T>
|
| 36 |
+
inline var_wrapper<T>
|
| 37 |
+
var(T& t)
|
| 38 |
+
{
|
| 39 |
+
return var_wrapper<T>(t);
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
typedef ::BOOST_SPIRIT_CLASSIC_NS::rule<> rule_t;
|
| 44 |
+
typedef ::BOOST_SPIRIT_CLASSIC_NS::rule<BOOST_SPIRIT_CLASSIC_NS::no_actions_scanner<>::type >
|
| 45 |
+
no_actions_rule_t;
|
| 46 |
+
|
| 47 |
+
unsigned int test_count = 0;
|
| 48 |
+
unsigned int error_count = 0;
|
| 49 |
+
|
| 50 |
+
unsigned int number_result;
|
| 51 |
+
static const unsigned int kError = 999;
|
| 52 |
+
static const bool good = true;
|
| 53 |
+
static const bool bad = false;
|
| 54 |
+
|
| 55 |
+
rule_t hex_prefix;
|
| 56 |
+
no_actions_rule_t oct_prefix;
|
| 57 |
+
rule_t hex_rule, oct_rule, dec_rule;
|
| 58 |
+
|
| 59 |
+
rule_t auto_number_rule;
|
| 60 |
+
rule_t hex_or_dec_number_rule;
|
| 61 |
+
|
| 62 |
+
void
|
| 63 |
+
test_number(char const *s, unsigned int wanted, rule_t const &r)
|
| 64 |
+
{
|
| 65 |
+
using namespace std;
|
| 66 |
+
|
| 67 |
+
++test_count;
|
| 68 |
+
|
| 69 |
+
number_result = wanted-1;
|
| 70 |
+
::BOOST_SPIRIT_CLASSIC_NS::parse_info<> m = ::BOOST_SPIRIT_CLASSIC_NS::parse(s, s + test_impl::string_length(s), r);
|
| 71 |
+
|
| 72 |
+
bool result = wanted == kError?(m.full?bad:good): (number_result==wanted);
|
| 73 |
+
|
| 74 |
+
if (m.full && (m.length != test_impl::string_length(s)))
|
| 75 |
+
result = bad;
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
if (result==good)
|
| 79 |
+
cout << "PASSED";
|
| 80 |
+
else
|
| 81 |
+
{
|
| 82 |
+
++error_count;
|
| 83 |
+
cout << "FAILED";
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
cout << ": \"" << s << "\" ==> ";
|
| 87 |
+
if (number_result==wanted-1)
|
| 88 |
+
cout << "<error>";
|
| 89 |
+
else
|
| 90 |
+
cout << number_result;
|
| 91 |
+
|
| 92 |
+
cout << "\n";
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
void
|
| 96 |
+
test_enclosed_fail()
|
| 97 |
+
{
|
| 98 |
+
using namespace std;
|
| 99 |
+
|
| 100 |
+
using ::BOOST_SPIRIT_CLASSIC_NS::if_p;
|
| 101 |
+
using ::BOOST_SPIRIT_CLASSIC_NS::str_p;
|
| 102 |
+
using ::BOOST_SPIRIT_CLASSIC_NS::nothing_p;
|
| 103 |
+
|
| 104 |
+
cout << "\nfail enclosed parser:\n";
|
| 105 |
+
|
| 106 |
+
const char *p = "abc";
|
| 107 |
+
|
| 108 |
+
::BOOST_SPIRIT_CLASSIC_NS::strlit<const char*> success_p = str_p(p);
|
| 109 |
+
::BOOST_SPIRIT_CLASSIC_NS::strlit<const char*> fail_p = str_p("xxx");
|
| 110 |
+
|
| 111 |
+
::BOOST_SPIRIT_CLASSIC_NS::rule<> r = if_p(success_p)[nothing_p];
|
| 112 |
+
|
| 113 |
+
::BOOST_SPIRIT_CLASSIC_NS::parse_info<> m = ::BOOST_SPIRIT_CLASSIC_NS::parse(p, r);
|
| 114 |
+
|
| 115 |
+
if (m.full) {
|
| 116 |
+
cout << "FAILED: if --> match" << endl;
|
| 117 |
+
++error_count;
|
| 118 |
+
} else {
|
| 119 |
+
cout << "PASSED: if --> no_match" << endl;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
r = if_p(fail_p)[success_p].else_p[nothing_p];
|
| 123 |
+
|
| 124 |
+
m = ::BOOST_SPIRIT_CLASSIC_NS::parse(p, r);
|
| 125 |
+
|
| 126 |
+
if (m.full) {
|
| 127 |
+
cout << "FAILED: else --> match" << endl;
|
| 128 |
+
++error_count;
|
| 129 |
+
} else {
|
| 130 |
+
cout << "PASSED: else --> no_match" << endl;
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
int
|
| 135 |
+
main()
|
| 136 |
+
{
|
| 137 |
+
using namespace std;
|
| 138 |
+
using ::BOOST_SPIRIT_CLASSIC_NS::if_p;
|
| 139 |
+
using ::BOOST_SPIRIT_CLASSIC_NS::uint_p;
|
| 140 |
+
using ::BOOST_SPIRIT_CLASSIC_NS::oct_p;
|
| 141 |
+
using ::BOOST_SPIRIT_CLASSIC_NS::hex_p;
|
| 142 |
+
using ::BOOST_SPIRIT_CLASSIC_NS::str_p;
|
| 143 |
+
using ::BOOST_SPIRIT_CLASSIC_NS::ch_p;
|
| 144 |
+
using ::BOOST_SPIRIT_CLASSIC_NS::assign_a;
|
| 145 |
+
|
| 146 |
+
cout << "/////////////////////////////////////////////////////////\n";
|
| 147 |
+
cout << "\n";
|
| 148 |
+
cout << " if_p test\n";
|
| 149 |
+
cout << "\n";
|
| 150 |
+
cout << "/////////////////////////////////////////////////////////\n";
|
| 151 |
+
cout << "\n";
|
| 152 |
+
|
| 153 |
+
bool as_hex;
|
| 154 |
+
|
| 155 |
+
#if qDebug
|
| 156 |
+
BOOST_SPIRIT_DEBUG_RULE(hex_prefix);
|
| 157 |
+
BOOST_SPIRIT_DEBUG_RULE(hex_rule);
|
| 158 |
+
BOOST_SPIRIT_DEBUG_RULE(oct_prefix);
|
| 159 |
+
BOOST_SPIRIT_DEBUG_RULE(oct_rule);
|
| 160 |
+
BOOST_SPIRIT_DEBUG_RULE(dec_rule);
|
| 161 |
+
BOOST_SPIRIT_DEBUG_RULE(auto_number_rule);
|
| 162 |
+
BOOST_SPIRIT_DEBUG_RULE(hex_or_dec_number_rule);
|
| 163 |
+
#endif
|
| 164 |
+
|
| 165 |
+
hex_prefix = str_p("0x");
|
| 166 |
+
oct_prefix = ch_p('0');
|
| 167 |
+
|
| 168 |
+
hex_rule = hex_p[assign_a(number_result)];
|
| 169 |
+
oct_rule = oct_p[assign_a(number_result)];
|
| 170 |
+
dec_rule = uint_p[assign_a(number_result)];
|
| 171 |
+
|
| 172 |
+
auto_number_rule =
|
| 173 |
+
if_p(hex_prefix)
|
| 174 |
+
[hex_rule]
|
| 175 |
+
.else_p
|
| 176 |
+
[
|
| 177 |
+
if_p(::BOOST_SPIRIT_CLASSIC_NS::eps_p(oct_prefix))
|
| 178 |
+
[oct_rule]
|
| 179 |
+
.else_p
|
| 180 |
+
[dec_rule]
|
| 181 |
+
];
|
| 182 |
+
|
| 183 |
+
hex_or_dec_number_rule =
|
| 184 |
+
if_p(local::var(as_hex))[hex_prefix>>hex_rule].else_p[dec_rule];
|
| 185 |
+
|
| 186 |
+
cout << "auto:\n";
|
| 187 |
+
test_number("", kError, auto_number_rule);
|
| 188 |
+
test_number("0", 0, auto_number_rule);
|
| 189 |
+
test_number("1", 1, auto_number_rule);
|
| 190 |
+
test_number("00", 0, auto_number_rule);
|
| 191 |
+
test_number("0x", kError, auto_number_rule);
|
| 192 |
+
test_number("0x0", 0, auto_number_rule);
|
| 193 |
+
test_number("0755", 493, auto_number_rule);
|
| 194 |
+
test_number("0x100", 256, auto_number_rule);
|
| 195 |
+
|
| 196 |
+
cout << "\ndecimal:\n";
|
| 197 |
+
as_hex = false;
|
| 198 |
+
test_number("", kError, hex_or_dec_number_rule);
|
| 199 |
+
test_number("100", 100, hex_or_dec_number_rule);
|
| 200 |
+
test_number("0x100", kError, hex_or_dec_number_rule);
|
| 201 |
+
test_number("0xff", kError, hex_or_dec_number_rule);
|
| 202 |
+
|
| 203 |
+
cout << "\nhexadecimal:\n";
|
| 204 |
+
as_hex = true;
|
| 205 |
+
test_number("", kError, hex_or_dec_number_rule);
|
| 206 |
+
test_number("0x100", 256, hex_or_dec_number_rule);
|
| 207 |
+
test_number("0xff", 255, hex_or_dec_number_rule);
|
| 208 |
+
|
| 209 |
+
//////////////////////////////////
|
| 210 |
+
// tests for if_p without else-parser
|
| 211 |
+
cout << "\nno-else:\n";
|
| 212 |
+
rule_t r = if_p(::BOOST_SPIRIT_CLASSIC_NS::eps_p('0'))[oct_rule];
|
| 213 |
+
|
| 214 |
+
test_number("0", 0, r);
|
| 215 |
+
|
| 216 |
+
++test_count;
|
| 217 |
+
::BOOST_SPIRIT_CLASSIC_NS::parse_info<> m = ::BOOST_SPIRIT_CLASSIC_NS::parse("", r);
|
| 218 |
+
if (!m.hit || !m.full || m.length!=0)
|
| 219 |
+
{
|
| 220 |
+
std::cout << "FAILED: \"\" ==> <error>\n";
|
| 221 |
+
++error_count;
|
| 222 |
+
}
|
| 223 |
+
else
|
| 224 |
+
std::cout << "PASSED: \"\" ==> <empty match>\n";
|
| 225 |
+
|
| 226 |
+
++test_count;
|
| 227 |
+
m = ::BOOST_SPIRIT_CLASSIC_NS::parse("junk", r);
|
| 228 |
+
if (!m.hit || m.full || m.length!=0)
|
| 229 |
+
{
|
| 230 |
+
std::cout << "FAILED: \"junk\" ==> <error>\n";
|
| 231 |
+
++error_count;
|
| 232 |
+
}
|
| 233 |
+
else
|
| 234 |
+
std::cout << "PASSED: \"junk\" ==> <empty match>\n";
|
| 235 |
+
|
| 236 |
+
test_enclosed_fail();
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
//////////////////////////////////
|
| 240 |
+
// report results
|
| 241 |
+
std::cout << "\n ";
|
| 242 |
+
if (error_count==0)
|
| 243 |
+
cout << "All " << test_count << " if_p-tests passed.\n"
|
| 244 |
+
<< "Test concluded successfully\n";
|
| 245 |
+
else
|
| 246 |
+
cout << error_count << " of " << test_count << " if_p-tests failed\n"
|
| 247 |
+
<< "Test failed\n";
|
| 248 |
+
|
| 249 |
+
return error_count!=0;
|
| 250 |
+
}
|
pool/shard009/C++/0110098_hotkeys.cpp
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <QKeySequence>
|
| 2 |
+
#include <QSettings>
|
| 3 |
+
#include "hotkeys.hxx"
|
| 4 |
+
#include <map>
|
| 5 |
+
|
| 6 |
+
struct Hotkey
|
| 7 |
+
{
|
| 8 |
+
Hotkey() : shortcut(NULL), context(Qt::WindowShortcut) {}
|
| 9 |
+
|
| 10 |
+
QKeySequence keyseq;
|
| 11 |
+
QShortcut* shortcut;
|
| 12 |
+
Qt::ShortcutContext context;
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
typedef std::map<QString, Hotkey> HotkeyMap;
|
| 16 |
+
typedef std::map<QString, HotkeyMap> HotkeyGroupMap;
|
| 17 |
+
|
| 18 |
+
HotkeyGroupMap hotkey_groups;
|
| 19 |
+
|
| 20 |
+
void SaveHotkeys(QSettings& settings)
|
| 21 |
+
{
|
| 22 |
+
settings.beginGroup("Shortcuts");
|
| 23 |
+
|
| 24 |
+
for (auto group : hotkey_groups)
|
| 25 |
+
{
|
| 26 |
+
settings.beginGroup(group.first);
|
| 27 |
+
for (auto hotkey : group.second)
|
| 28 |
+
{
|
| 29 |
+
settings.beginGroup(hotkey.first);
|
| 30 |
+
settings.setValue(QString("KeySeq"), hotkey.second.keyseq.toString());
|
| 31 |
+
settings.setValue(QString("Context"), hotkey.second.context);
|
| 32 |
+
settings.endGroup();
|
| 33 |
+
}
|
| 34 |
+
settings.endGroup();
|
| 35 |
+
}
|
| 36 |
+
settings.endGroup();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
void LoadHotkeys(QSettings& settings)
|
| 40 |
+
{
|
| 41 |
+
settings.beginGroup("Shortcuts");
|
| 42 |
+
|
| 43 |
+
// Make sure NOT to use a reference here because it would become invalid once we call beginGroup()
|
| 44 |
+
QStringList groups = settings.childGroups();
|
| 45 |
+
for (auto group : groups)
|
| 46 |
+
{
|
| 47 |
+
settings.beginGroup(group);
|
| 48 |
+
|
| 49 |
+
QStringList hotkeys = settings.childGroups();
|
| 50 |
+
for (auto hotkey : hotkeys)
|
| 51 |
+
{
|
| 52 |
+
settings.beginGroup(hotkey);
|
| 53 |
+
|
| 54 |
+
// RegisterHotkey assigns default keybindings, so use old values as default parameters
|
| 55 |
+
Hotkey& hk = hotkey_groups[group][hotkey];
|
| 56 |
+
hk.keyseq = QKeySequence::fromString(settings.value("KeySeq", hk.keyseq.toString()).toString());
|
| 57 |
+
hk.context = (Qt::ShortcutContext)settings.value("Context", hk.context).toInt();
|
| 58 |
+
if (hk.shortcut)
|
| 59 |
+
hk.shortcut->setKey(hk.keyseq);
|
| 60 |
+
|
| 61 |
+
settings.endGroup();
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
settings.endGroup();
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
settings.endGroup();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void RegisterHotkey(const QString& group, const QString& action, const QKeySequence& default_keyseq, Qt::ShortcutContext default_context)
|
| 71 |
+
{
|
| 72 |
+
if (hotkey_groups[group].find(action) == hotkey_groups[group].end())
|
| 73 |
+
{
|
| 74 |
+
hotkey_groups[group][action].keyseq = default_keyseq;
|
| 75 |
+
hotkey_groups[group][action].context = default_context;
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
QShortcut* GetHotkey(const QString& group, const QString& action, QWidget* widget)
|
| 80 |
+
{
|
| 81 |
+
Hotkey& hk = hotkey_groups[group][action];
|
| 82 |
+
|
| 83 |
+
if (!hk.shortcut)
|
| 84 |
+
hk.shortcut = new QShortcut(hk.keyseq, widget, NULL, NULL, hk.context);
|
| 85 |
+
|
| 86 |
+
return hk.shortcut;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
GHotkeysDialog::GHotkeysDialog(QWidget* parent): QDialog(parent)
|
| 91 |
+
{
|
| 92 |
+
ui.setupUi(this);
|
| 93 |
+
|
| 94 |
+
for (auto group : hotkey_groups)
|
| 95 |
+
{
|
| 96 |
+
QTreeWidgetItem* toplevel_item = new QTreeWidgetItem(QStringList(group.first));
|
| 97 |
+
for (auto hotkey : group.second)
|
| 98 |
+
{
|
| 99 |
+
QStringList columns;
|
| 100 |
+
columns << hotkey.first << hotkey.second.keyseq.toString();
|
| 101 |
+
QTreeWidgetItem* item = new QTreeWidgetItem(columns);
|
| 102 |
+
toplevel_item->addChild(item);
|
| 103 |
+
}
|
| 104 |
+
ui.treeWidget->addTopLevelItem(toplevel_item);
|
| 105 |
+
}
|
| 106 |
+
// TODO: Make context configurable as well (hiding the column for now)
|
| 107 |
+
ui.treeWidget->setColumnCount(2);
|
| 108 |
+
|
| 109 |
+
ui.treeWidget->resizeColumnToContents(0);
|
| 110 |
+
ui.treeWidget->resizeColumnToContents(1);
|
| 111 |
+
}
|
pool/shard009/C++/0110100_vfsStream.cpp
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "stdafx.h"
|
| 2 |
+
#include "vfsStream.h"
|
| 3 |
+
|
| 4 |
+
vfsStream::vfsStream()
|
| 5 |
+
{
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
vfsStream::~vfsStream()
|
| 9 |
+
{
|
| 10 |
+
Close();
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
void vfsStream::Reset()
|
| 14 |
+
{
|
| 15 |
+
m_pos = 0;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
bool vfsStream::Close()
|
| 19 |
+
{
|
| 20 |
+
Reset();
|
| 21 |
+
|
| 22 |
+
return true;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
u64 vfsStream::GetSize()
|
| 26 |
+
{
|
| 27 |
+
u64 last_pos = Tell();
|
| 28 |
+
Seek(0, vfsSeekEnd);
|
| 29 |
+
u64 size = Tell();
|
| 30 |
+
Seek(last_pos, vfsSeekSet);
|
| 31 |
+
|
| 32 |
+
return size;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
u64 vfsStream::Write(const void* src, u64 size)
|
| 36 |
+
{
|
| 37 |
+
m_pos += size;
|
| 38 |
+
|
| 39 |
+
return size;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
u64 vfsStream::Read(void* dst, u64 size)
|
| 43 |
+
{
|
| 44 |
+
m_pos += size;
|
| 45 |
+
|
| 46 |
+
return size;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
u64 vfsStream::Seek(s64 offset, vfsSeekMode mode)
|
| 50 |
+
{
|
| 51 |
+
switch(mode)
|
| 52 |
+
{
|
| 53 |
+
case vfsSeekSet: m_pos = offset; break;
|
| 54 |
+
case vfsSeekCur: m_pos += offset; break;
|
| 55 |
+
case vfsSeekEnd: m_pos = GetSize() + offset; break;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
return m_pos;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
u64 vfsStream::Tell() const
|
| 62 |
+
{
|
| 63 |
+
return m_pos;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
bool vfsStream::Eof()
|
| 67 |
+
{
|
| 68 |
+
return Tell() >= GetSize();
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
bool vfsStream::IsOpened() const
|
| 72 |
+
{
|
| 73 |
+
return true;
|
| 74 |
+
}
|
pool/shard009/C++/0110101_cell_contains.cpp
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*******************************************************************************
|
| 2 |
+
* Copyright (c) 2015-2018 Skymind, Inc.
|
| 3 |
+
*
|
| 4 |
+
* This program and the accompanying materials are made available under the
|
| 5 |
+
* terms of the Apache License, Version 2.0 which is available at
|
| 6 |
+
* https://www.apache.org/licenses/LICENSE-2.0.
|
| 7 |
+
*
|
| 8 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 9 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 10 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 11 |
+
* License for the specific language governing permissions and limitations
|
| 12 |
+
* under the License.
|
| 13 |
+
*
|
| 14 |
+
* SPDX-License-Identifier: Apache-2.0
|
| 15 |
+
******************************************************************************/
|
| 16 |
+
|
| 17 |
+
//
|
| 18 |
+
// @author George A. Shulinok <sgazeos@gmail.com), created on 5/15/2019.
|
| 19 |
+
//
|
| 20 |
+
|
| 21 |
+
#include <system/op_boilerplate.h>
|
| 22 |
+
#if NOT_EXCLUDED(OP_cell_contains)
|
| 23 |
+
|
| 24 |
+
#include <ops/declarable/CustomOperations.h>
|
| 25 |
+
#include <ops/declarable/helpers/BarnesHutTsne.h>
|
| 26 |
+
|
| 27 |
+
namespace sd {
|
| 28 |
+
namespace ops {
|
| 29 |
+
|
| 30 |
+
CUSTOM_OP_IMPL(cell_contains, 3, 1, false, 0, 1) {
|
| 31 |
+
auto corner = INPUT_VARIABLE(0);
|
| 32 |
+
auto width = INPUT_VARIABLE(1);
|
| 33 |
+
auto point = INPUT_VARIABLE(2);
|
| 34 |
+
|
| 35 |
+
auto output = OUTPUT_VARIABLE(0);
|
| 36 |
+
auto dimension = INT_ARG(0);
|
| 37 |
+
output->assign(helpers::cell_contains(corner, width, point, dimension));
|
| 38 |
+
return Status::OK();
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
DECLARE_TYPES(cell_contains) {
|
| 42 |
+
getOpDescriptor()
|
| 43 |
+
->setAllowedInputTypes(sd::DataType::ANY)
|
| 44 |
+
->setAllowedOutputTypes(sd::DataType::BOOL)
|
| 45 |
+
->setSameMode(false);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
DECLARE_SHAPE_FN(cell_contains) {
|
| 49 |
+
return SHAPELIST(CONSTANT(ShapeBuilders::createScalarShapeInfo(sd::DataType::BOOL, block.workspace())));
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
#endif
|