Upload folder using huggingface_hub (part 91)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard008/C++/0096630_multiprocess_test_helper.cc +99 -0
- pool/shard008/C++/0096632_aoj1275_3.cpp +23 -0
- pool/shard008/C++/0096635_ToolWorld.cpp +72 -0
- pool/shard008/C++/0096639_gf2m.cpp +132 -0
- pool/shard008/C++/0096640_test_photos.cpp +110 -0
- pool/shard008/C++/0096642_storage_notification_service_impl.cc +52 -0
- pool/shard008/C++/0096648_mac_traj2_test.cc +137 -0
- pool/shard008/C++/0096655_boss_grobbulus.cpp +163 -0
- pool/shard008/C++/0096661_loop_tests.cpp +138 -0
- pool/shard008/C++/0096662_CWE190_Integer_Overflow__short_fscanf_multiply_84a.cpp +92 -0
- pool/shard008/C++/0096663_TestApplication.cpp +64 -0
- pool/shard008/C++/0096664_main.cpp +82 -0
- pool/shard008/C++/0096665_unsafe_test.cc +40 -0
- pool/shard008/C++/0096666_get_numvols.cc +73 -0
- pool/shard008/C++/0096670_fetch.cpp +37 -0
- pool/shard008/C++/0096672_MediaFile.cpp +190 -0
- pool/shard008/C++/0096675_console_reporter.cc +190 -0
- pool/shard008/C++/0096676_mock_media_stream_video_source.cc +152 -0
- pool/shard008/C++/0096679_exE.cpp +93 -0
- pool/shard008/C++/0096680_A.cpp +103 -0
- pool/shard008/C++/0096682_tst_qsysteminfo.cpp +297 -0
- pool/shard008/C++/0096684_OpenCLGpuRegistry.cpp +119 -0
- pool/shard008/C++/0096686_remote_command_job.cc +169 -0
- pool/shard008/C++/0096687_stream_infra.cpp +110 -0
- pool/shard008/C++/0096690_jinvoker.cpp +206 -0
- pool/shard008/C++/0096693_search-a-range-sorted-array.cc +76 -0
- pool/shard008/C++/0096695_preload_request.cc +158 -0
- pool/shard008/C++/0096696_collection.cpp +122 -0
- pool/shard008/C++/0096697_rendezvous.cpp +32 -0
- pool/shard008/C++/0096701_Resources.cpp +32 -0
- pool/shard008/C++/0096704_SkXfermodeImageFilter.cpp +211 -0
- pool/shard008/C++/0096710_version_tests.cpp +66 -0
- pool/shard008/C++/0096711_ContactPublisher.cc +82 -0
- pool/shard008/C++/0096712_ash_touch_exploration_manager_chromeos.cc +127 -0
- pool/shard008/C++/0096713_TillageParameter.cpp +33 -0
- pool/shard008/C++/0096715_ast.cpp +34 -0
- pool/shard008/C++/0096717_database.cpp +162 -0
- pool/shard008/C++/0096720_data_encryption_win_unittest.cc +31 -0
- pool/shard008/C++/0096721_mitkGetSimulationDataNode.cpp +45 -0
- pool/shard008/C++/0096722_CWE124_Buffer_Underwrite__malloc_char_ncpy_33.cpp +124 -0
- pool/shard008/C++/0096727_correctiq_swapiq_impl.cc +95 -0
- pool/shard008/C++/0096731_LinkParserImpl.cpp +33 -0
- pool/shard008/C++/0096738_zhtmllistmodel.cpp +151 -0
- pool/shard008/C++/0096740_examples.cpp +33 -0
- pool/shard008/C++/0096741_SignatureBuilder.cpp +29 -0
- pool/shard008/C++/0096747_CPStringTools.cpp +85 -0
- pool/shard008/C++/0096748_chordsdescriptors.cpp +244 -0
- pool/shard008/C++/0096750_web_task_runner_impl.cc +73 -0
- pool/shard008/C++/0096756_stylemodel.cpp +236 -0
- pool/shard008/C++/0096760_Wizard.cc +29 -0
pool/shard008/C++/0096630_multiprocess_test_helper.cc
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 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 "third_party/mojo/src/mojo/edk/test/multiprocess_test_helper.h"
|
| 6 |
+
|
| 7 |
+
#include "base/command_line.h"
|
| 8 |
+
#include "base/logging.h"
|
| 9 |
+
#include "base/process/kill.h"
|
| 10 |
+
#include "base/process/process_handle.h"
|
| 11 |
+
#include "build/build_config.h"
|
| 12 |
+
#include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
|
| 13 |
+
|
| 14 |
+
namespace mojo {
|
| 15 |
+
namespace test {
|
| 16 |
+
|
| 17 |
+
MultiprocessTestHelper::MultiprocessTestHelper() {
|
| 18 |
+
platform_channel_pair_.reset(new embedder::PlatformChannelPair());
|
| 19 |
+
server_platform_handle = platform_channel_pair_->PassServerHandle();
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
MultiprocessTestHelper::~MultiprocessTestHelper() {
|
| 23 |
+
CHECK(!test_child_.IsValid());
|
| 24 |
+
server_platform_handle.reset();
|
| 25 |
+
platform_channel_pair_.reset();
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
void MultiprocessTestHelper::StartChild(const std::string& test_child_name) {
|
| 29 |
+
StartChildWithExtraSwitch(test_child_name, std::string(), std::string());
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void MultiprocessTestHelper::StartChildWithExtraSwitch(
|
| 33 |
+
const std::string& test_child_name,
|
| 34 |
+
const std::string& switch_string,
|
| 35 |
+
const std::string& switch_value) {
|
| 36 |
+
CHECK(platform_channel_pair_);
|
| 37 |
+
CHECK(!test_child_name.empty());
|
| 38 |
+
CHECK(!test_child_.IsValid());
|
| 39 |
+
|
| 40 |
+
std::string test_child_main = test_child_name + "TestChildMain";
|
| 41 |
+
|
| 42 |
+
base::CommandLine command_line(
|
| 43 |
+
base::GetMultiProcessTestChildBaseCommandLine());
|
| 44 |
+
embedder::HandlePassingInformation handle_passing_info;
|
| 45 |
+
platform_channel_pair_->PrepareToPassClientHandleToChildProcess(
|
| 46 |
+
&command_line, &handle_passing_info);
|
| 47 |
+
|
| 48 |
+
if (!switch_string.empty()) {
|
| 49 |
+
CHECK(!command_line.HasSwitch(switch_string));
|
| 50 |
+
if (!switch_value.empty())
|
| 51 |
+
command_line.AppendSwitchASCII(switch_string, switch_value);
|
| 52 |
+
else
|
| 53 |
+
command_line.AppendSwitch(switch_string);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
base::LaunchOptions options;
|
| 57 |
+
#if defined(OS_POSIX)
|
| 58 |
+
options.fds_to_remap = &handle_passing_info;
|
| 59 |
+
#elif defined(OS_WIN)
|
| 60 |
+
options.start_hidden = true;
|
| 61 |
+
options.handles_to_inherit = &handle_passing_info;
|
| 62 |
+
#else
|
| 63 |
+
#error "Not supported yet."
|
| 64 |
+
#endif
|
| 65 |
+
|
| 66 |
+
test_child_ =
|
| 67 |
+
base::SpawnMultiProcessTestChild(test_child_main, command_line, options);
|
| 68 |
+
platform_channel_pair_->ChildProcessLaunched();
|
| 69 |
+
|
| 70 |
+
CHECK(test_child_.IsValid());
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
int MultiprocessTestHelper::WaitForChildShutdown() {
|
| 74 |
+
CHECK(test_child_.IsValid());
|
| 75 |
+
|
| 76 |
+
int rv = -1;
|
| 77 |
+
CHECK(
|
| 78 |
+
test_child_.WaitForExitWithTimeout(TestTimeouts::action_timeout(), &rv));
|
| 79 |
+
test_child_.Close();
|
| 80 |
+
return rv;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
bool MultiprocessTestHelper::WaitForChildTestShutdown() {
|
| 84 |
+
return WaitForChildShutdown() == 0;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
// static
|
| 88 |
+
void MultiprocessTestHelper::ChildSetup() {
|
| 89 |
+
CHECK(base::CommandLine::InitializedForCurrentProcess());
|
| 90 |
+
client_platform_handle =
|
| 91 |
+
embedder::PlatformChannelPair::PassClientHandleFromParentProcess(
|
| 92 |
+
*base::CommandLine::ForCurrentProcess());
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
// static
|
| 96 |
+
embedder::ScopedPlatformHandle MultiprocessTestHelper::client_platform_handle;
|
| 97 |
+
|
| 98 |
+
} // namespace test
|
| 99 |
+
} // namespace mojo
|
pool/shard008/C++/0096632_aoj1275_3.cpp
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <bits/stdc++.h>
|
| 2 |
+
|
| 3 |
+
using namespace std;
|
| 4 |
+
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
|
| 5 |
+
#define REP(i,x) FOR(i,0,x)
|
| 6 |
+
|
| 7 |
+
int main() {
|
| 8 |
+
// use scanf in CodeForces!
|
| 9 |
+
cin.tie(0);
|
| 10 |
+
ios_base::sync_with_stdio(false);
|
| 11 |
+
while (1) {
|
| 12 |
+
int N, K, M; cin >> N >> K >> M;
|
| 13 |
+
if (N == 0 and K == 0 and M == 0) break;
|
| 14 |
+
M--;
|
| 15 |
+
vector<int> stones(N); REP(i, N) stones[i] = i;
|
| 16 |
+
while (stones.size() > 1) {
|
| 17 |
+
stones.erase(stones.begin() + M);
|
| 18 |
+
M = (M + K - 1 + stones.size()) % stones.size();
|
| 19 |
+
}
|
| 20 |
+
cout << stones[0] + 1 << endl;
|
| 21 |
+
}
|
| 22 |
+
return 0;
|
| 23 |
+
}
|
pool/shard008/C++/0096635_ToolWorld.cpp
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* ToolWorld.cpp
|
| 3 |
+
*
|
| 4 |
+
* Created on: Jul 4, 2015
|
| 5 |
+
* Author: dwarf
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
#include <ToolWorld.h>
|
| 9 |
+
#include "World.h"
|
| 10 |
+
#include "Mouse.h"
|
| 11 |
+
#include "CoordinateConverter.h"
|
| 12 |
+
#include <cmath>
|
| 13 |
+
|
| 14 |
+
namespace gui {
|
| 15 |
+
|
| 16 |
+
ToolWorld::ToolWorld() : path("./level/lvl1"), width(0), height(0){
|
| 17 |
+
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
ToolWorld::~ToolWorld() {
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
void ToolWorld::begin(float x, float y, int button){
|
| 24 |
+
if(button == 1){
|
| 25 |
+
game::world::loadWorld(path, x, y);
|
| 26 |
+
}
|
| 27 |
+
else if(button == 3){
|
| 28 |
+
game::world::unloadWorld(x, y);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
void ToolWorld::step(float x, float y, int button){
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void ToolWorld::stop(float x, float y, int button){
|
| 38 |
+
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
std::string ToolWorld::getName(){
|
| 42 |
+
return "World";
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
std::string ToolWorld::setParameter(std::string name, std::string value){
|
| 46 |
+
if(name == "path"){
|
| 47 |
+
path = value;
|
| 48 |
+
std::pair<int, int> p = game::world::getWorldSizeFromFile(path);
|
| 49 |
+
width = p.first;
|
| 50 |
+
height = p.second;
|
| 51 |
+
return "set path";
|
| 52 |
+
}
|
| 53 |
+
else{
|
| 54 |
+
return "options: path";
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
void ToolWorld::render(float upateFactor){
|
| 59 |
+
|
| 60 |
+
float *f = getMousePosition();
|
| 61 |
+
float *v = screenToWorldSpace(f[0], f[1]);
|
| 62 |
+
float x, y;
|
| 63 |
+
x = floor(v[0]);
|
| 64 |
+
y = floor(v[1]);
|
| 65 |
+
|
| 66 |
+
render::drawRect(x + width / 2, y + height / 2, width, height, 0, toolOverlayColor);
|
| 67 |
+
|
| 68 |
+
delete[] v;
|
| 69 |
+
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
} /* namespace gui */
|
pool/shard008/C++/0096639_gf2m.cpp
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/*
|
| 3 |
+
* This file is part of Codecrypt.
|
| 4 |
+
*
|
| 5 |
+
* Codecrypt is free software: you can redistribute it and/or modify it
|
| 6 |
+
* under the terms of the GNU Lesser General Public License as published by
|
| 7 |
+
* the Free Software Foundation, either version 3 of the License, or (at
|
| 8 |
+
* your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* Codecrypt is distributed in the hope that it will be useful, but WITHOUT
|
| 11 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 12 |
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
| 13 |
+
* License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU Lesser General Public License
|
| 16 |
+
* along with Codecrypt. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
#include "gf2m.h"
|
| 20 |
+
|
| 21 |
+
/*
|
| 22 |
+
* helpful stuff for arithmetic in GF(2^m) - polynomials over GF(2).
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
int gf2p_degree (uint p)
|
| 26 |
+
{
|
| 27 |
+
int r = 0;
|
| 28 |
+
while (p) {
|
| 29 |
+
++r;
|
| 30 |
+
p >>= 1;
|
| 31 |
+
}
|
| 32 |
+
return r - 1;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
uint gf2p_mod (uint a, uint p)
|
| 36 |
+
{
|
| 37 |
+
if (!p) return 0;
|
| 38 |
+
int t, degp = gf2p_degree (p);
|
| 39 |
+
while ( (t = gf2p_degree (a) ) >= degp) {
|
| 40 |
+
a ^= (p << (t - degp) );
|
| 41 |
+
}
|
| 42 |
+
return a;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
uint gf2p_gcd (uint a, uint b)
|
| 46 |
+
{
|
| 47 |
+
uint c;
|
| 48 |
+
if (!a) return b;
|
| 49 |
+
while (b) {
|
| 50 |
+
c = gf2p_mod (a, b);
|
| 51 |
+
a = b;
|
| 52 |
+
b = c;
|
| 53 |
+
}
|
| 54 |
+
return a;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
uint gf2p_modmult (uint a, uint b, uint p)
|
| 58 |
+
{
|
| 59 |
+
a = gf2p_mod (a, p);
|
| 60 |
+
b = gf2p_mod (b, p);
|
| 61 |
+
uint r = 0;
|
| 62 |
+
uint d = 1 << gf2p_degree (p);
|
| 63 |
+
if (b) while (a) {
|
| 64 |
+
if (a & 1) r ^= b;
|
| 65 |
+
a >>= 1;
|
| 66 |
+
b <<= 1;
|
| 67 |
+
if (b >= d) b ^= p;
|
| 68 |
+
}
|
| 69 |
+
return r;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
bool is_irreducible_gf2_poly (uint p)
|
| 73 |
+
{
|
| 74 |
+
if (!p) return false;
|
| 75 |
+
int d = gf2p_degree (p) / 2;
|
| 76 |
+
uint test = 2; //x^1+0
|
| 77 |
+
for (int i = 1; i <= d; ++i) {
|
| 78 |
+
test = gf2p_modmult (test, test, p);
|
| 79 |
+
|
| 80 |
+
if (gf2p_gcd (test ^ 2 /* test - x^1 */, p) != 1)
|
| 81 |
+
return false;
|
| 82 |
+
}
|
| 83 |
+
return true;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
bool gf2m::create (uint M)
|
| 87 |
+
{
|
| 88 |
+
if (M < 1) return false; //too small.
|
| 89 |
+
m = M;
|
| 90 |
+
n = 1 << m;
|
| 91 |
+
if (!n) return false; //too big.
|
| 92 |
+
poly = 0;
|
| 93 |
+
|
| 94 |
+
/*
|
| 95 |
+
* find a conway polynomial for given degree. First we "filter out" the
|
| 96 |
+
* possibilities that cannot be conway (reducible ones), then we check
|
| 97 |
+
* that Z2[x]/poly is a field.
|
| 98 |
+
*/
|
| 99 |
+
for (uint t = (1 << m) + 1, e = 1 << (m + 1); t < e; t += 2) {
|
| 100 |
+
|
| 101 |
+
if (!is_irreducible_gf2_poly (t) ) continue;
|
| 102 |
+
|
| 103 |
+
//try to prepare log and antilog tables
|
| 104 |
+
log.resize (n, 0);
|
| 105 |
+
antilog.resize (n, 0);
|
| 106 |
+
log[0] = n - 1;
|
| 107 |
+
antilog[n - 1] = 0;
|
| 108 |
+
|
| 109 |
+
uint i, xi = 1; //x^0
|
| 110 |
+
for (i = 0; i < n - 1; ++i) {
|
| 111 |
+
if (log[xi] != 0) { //not a cyclic group
|
| 112 |
+
log.clear();
|
| 113 |
+
antilog.clear();
|
| 114 |
+
break;
|
| 115 |
+
}
|
| 116 |
+
log[xi] = i;
|
| 117 |
+
antilog[i] = xi;
|
| 118 |
+
|
| 119 |
+
xi <<= 1; //multiply by x
|
| 120 |
+
xi = gf2p_mod (xi, t);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
//if it broke...
|
| 124 |
+
if (i < n - 1) continue;
|
| 125 |
+
poly = t;
|
| 126 |
+
break;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
if (!poly) return false;
|
| 130 |
+
|
| 131 |
+
return true;
|
| 132 |
+
}
|
pool/shard008/C++/0096640_test_photos.cpp
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Unit tests for libkvkontakte.
|
| 3 |
+
* Copyright (C) 2015 Alexander Potashev <aspotashev@gmail.com>
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License along
|
| 16 |
+
* with this program; if not, write to the Free Software Foundation, Inc.,
|
| 17 |
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "test_photos.h"
|
| 21 |
+
|
| 22 |
+
#include <libkvkontakte/uploadphotosjob.h>
|
| 23 |
+
#include <libkvkontakte/photolistjob.h>
|
| 24 |
+
#include <libkvkontakte/photojob.h>
|
| 25 |
+
#include <libkvkontakte/createalbumjob.h>
|
| 26 |
+
|
| 27 |
+
#include <qtest_kde.h>
|
| 28 |
+
|
| 29 |
+
#include <QtGui/QImage>
|
| 30 |
+
|
| 31 |
+
#define ALBUM1_NAME "__album for unit testing of libkvkontakte #1"
|
| 32 |
+
|
| 33 |
+
using namespace Vkontakte;
|
| 34 |
+
|
| 35 |
+
TestPhotos::TestPhotos()
|
| 36 |
+
: VkTestBase()
|
| 37 |
+
, m_albumId(-1)
|
| 38 |
+
, m_photoId(-1)
|
| 39 |
+
{
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
void TestPhotos::initTestCase()
|
| 43 |
+
{
|
| 44 |
+
authenticate(AppPermissions::Photos);
|
| 45 |
+
|
| 46 |
+
// Create album for testing
|
| 47 |
+
CreateAlbumJob* const albumJob = new CreateAlbumJob(
|
| 48 |
+
accessToken(), ALBUM1_NAME, QString("Description for %1").arg(ALBUM1_NAME),
|
| 49 |
+
AlbumInfo::PRIVACY_PRIVATE, AlbumInfo::PRIVACY_PRIVATE);
|
| 50 |
+
albumJob->exec();
|
| 51 |
+
QVERIFY(!albumJob->error());
|
| 52 |
+
|
| 53 |
+
m_albumId = albumJob->album()->aid();
|
| 54 |
+
|
| 55 |
+
// Upload photo for testing
|
| 56 |
+
UploadPhotosJob* const job = new UploadPhotosJob(
|
| 57 |
+
accessToken(),
|
| 58 |
+
QStringList() << QString(AUTOTESTS_DATA_DIR) + "/image1.png",
|
| 59 |
+
true, m_albumId);
|
| 60 |
+
job->exec();
|
| 61 |
+
QVERIFY(!job->error());
|
| 62 |
+
|
| 63 |
+
QList<PhotoInfoPtr> list = job->list();
|
| 64 |
+
QCOMPARE(list.size(), 1);
|
| 65 |
+
|
| 66 |
+
const PhotoInfoPtr photo = list.at(0);
|
| 67 |
+
m_photoId = photo->pid();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void TestPhotos::testPhotoListJob()
|
| 71 |
+
{
|
| 72 |
+
PhotoListJob* const job = new PhotoListJob(
|
| 73 |
+
accessToken(), 0, m_albumId, QIntList() << m_photoId);
|
| 74 |
+
job->exec();
|
| 75 |
+
QVERIFY(!job->error());
|
| 76 |
+
|
| 77 |
+
QList<PhotoInfoPtr> list = job->list();
|
| 78 |
+
QCOMPARE(list.size(), 1);
|
| 79 |
+
|
| 80 |
+
const PhotoInfoPtr photo = list.at(0);
|
| 81 |
+
QCOMPARE(photo->pid(), m_photoId);
|
| 82 |
+
|
| 83 |
+
// Download the image
|
| 84 |
+
PhotoJob* const photoJob = new PhotoJob(photo->src());
|
| 85 |
+
photoJob->exec();
|
| 86 |
+
QVERIFY(!photoJob->error());
|
| 87 |
+
|
| 88 |
+
QImage image = photoJob->photo();
|
| 89 |
+
QCOMPARE(image.size(), QSize(10, 10));
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
void TestPhotos::testUploadMultiple()
|
| 93 |
+
{
|
| 94 |
+
// Upload multiple photos at once
|
| 95 |
+
const int count = 10;
|
| 96 |
+
|
| 97 |
+
QStringList files;
|
| 98 |
+
for (int i = 0; i < count; ++i)
|
| 99 |
+
files << QString(AUTOTESTS_DATA_DIR) + "/image1.png";
|
| 100 |
+
|
| 101 |
+
UploadPhotosJob* const job = new UploadPhotosJob(
|
| 102 |
+
accessToken(), files, true, m_albumId);
|
| 103 |
+
job->exec();
|
| 104 |
+
QVERIFY(!job->error());
|
| 105 |
+
|
| 106 |
+
QList<PhotoInfoPtr> list = job->list();
|
| 107 |
+
QCOMPARE(list.size(), count);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
QTEST_KDEMAIN(TestPhotos, GUI)
|
pool/shard008/C++/0096642_storage_notification_service_impl.cc
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2019 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/storage/storage_notification_service_impl.h"
|
| 6 |
+
|
| 7 |
+
#include "base/command_line.h"
|
| 8 |
+
#include "base/strings/string_number_conversions.h"
|
| 9 |
+
#include "base/time/time.h"
|
| 10 |
+
#include "build/build_config.h"
|
| 11 |
+
#include "chrome/browser/profiles/profile.h"
|
| 12 |
+
#include "chrome/common/chrome_switches.h"
|
| 13 |
+
|
| 14 |
+
#if !defined(OS_ANDROID)
|
| 15 |
+
#include "chrome/browser/ui/storage_pressure_bubble.h"
|
| 16 |
+
#endif
|
| 17 |
+
|
| 18 |
+
namespace {
|
| 19 |
+
|
| 20 |
+
// Minimum interval between consecutive storage pressure notifications.
|
| 21 |
+
const base::TimeDelta kDiskPressureNotificationInterval = base::Days(1);
|
| 22 |
+
|
| 23 |
+
const base::TimeDelta GetThrottlingInterval() {
|
| 24 |
+
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
| 25 |
+
int int_value;
|
| 26 |
+
if (command_line->HasSwitch(switches::kStoragePressureNotificationInterval)) {
|
| 27 |
+
const std::string string_value = command_line->GetSwitchValueASCII(
|
| 28 |
+
switches::kStoragePressureNotificationInterval);
|
| 29 |
+
if (base::StringToInt(string_value, &int_value) && int_value >= 0) {
|
| 30 |
+
return base::Minutes(int_value);
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
return kDiskPressureNotificationInterval;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
} // namespace
|
| 37 |
+
|
| 38 |
+
void StorageNotificationServiceImpl::MaybeShowStoragePressureNotification(
|
| 39 |
+
const url::Origin origin) {
|
| 40 |
+
if (!disk_pressure_notification_last_sent_at_.is_null() &&
|
| 41 |
+
base::TimeTicks::Now() - disk_pressure_notification_last_sent_at_ <
|
| 42 |
+
GetThrottlingInterval()) {
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
chrome::ShowStoragePressureBubble(origin);
|
| 47 |
+
disk_pressure_notification_last_sent_at_ = base::TimeTicks::Now();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
StorageNotificationServiceImpl::StorageNotificationServiceImpl() = default;
|
| 51 |
+
|
| 52 |
+
StorageNotificationServiceImpl::~StorageNotificationServiceImpl() = default;
|
pool/shard008/C++/0096648_mac_traj2_test.cc
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***********************************************************************
|
| 2 |
+
|
| 3 |
+
Copyright 2007-2010 Carnegie Mellon University and Intel Corporation
|
| 4 |
+
Author: Mike Vande Weghe <vandeweg@cmu.edu>
|
| 5 |
+
|
| 6 |
+
This file is part of owd.
|
| 7 |
+
|
| 8 |
+
owd is free software; you can redistribute it and/or modify
|
| 9 |
+
it under the terms of the GNU Lesser General Public License as published by
|
| 10 |
+
the Free Software Foundation; either version 3 of the License, or (at your
|
| 11 |
+
option) any later version.
|
| 12 |
+
|
| 13 |
+
owd 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 Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
You should have received a copy of the GNU Lesser General Public License
|
| 19 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 20 |
+
|
| 21 |
+
***********************************************************************/
|
| 22 |
+
|
| 23 |
+
#include "MacJointTraj.hh"
|
| 24 |
+
#include <stdio.h>
|
| 25 |
+
|
| 26 |
+
const double MacAccelElement::epsilon;
|
| 27 |
+
|
| 28 |
+
int main(int argc, char **argv) {
|
| 29 |
+
if (argc < 2) {
|
| 30 |
+
printf("Usage: mac_traj_test <trajectory_file>\n");
|
| 31 |
+
exit(1);
|
| 32 |
+
}
|
| 33 |
+
char *filename = argv[1];
|
| 34 |
+
FILE *csv = fopen(filename,"r");
|
| 35 |
+
if (!csv) {
|
| 36 |
+
printf("Cannot open csv file %s\n",argv[1]);
|
| 37 |
+
exit(1);
|
| 38 |
+
}
|
| 39 |
+
TrajPoint tp;
|
| 40 |
+
TrajType traj;
|
| 41 |
+
TrajType traj2;
|
| 42 |
+
tp.resize(2);
|
| 43 |
+
while (fscanf(csv,"%lf: %lf, %lf\n",
|
| 44 |
+
&tp.blend_radius, &tp[0],&tp[1]) == 3) {
|
| 45 |
+
traj.push_back(tp);
|
| 46 |
+
tp.blend_radius=0.0;
|
| 47 |
+
traj2.push_back(tp);
|
| 48 |
+
}
|
| 49 |
+
fclose(csv);
|
| 50 |
+
|
| 51 |
+
// wipe out the previous output file, if any
|
| 52 |
+
unlink("traj.csv");
|
| 53 |
+
|
| 54 |
+
JointPos max_v;
|
| 55 |
+
|
| 56 |
+
// max_v.push_back(40);
|
| 57 |
+
// max_v.push_back(30);
|
| 58 |
+
// max_v.push_back(30);
|
| 59 |
+
// max_v.push_back(60);
|
| 60 |
+
// max_v.push_back(80);
|
| 61 |
+
// max_v.push_back(80);
|
| 62 |
+
// max_v.push_back(90);
|
| 63 |
+
max_v.push_back(60);
|
| 64 |
+
max_v.push_back(120);
|
| 65 |
+
// max_v *= 4;
|
| 66 |
+
max_v *= 3.141592654/180; // degrees to radians
|
| 67 |
+
JointPos max_a(max_v); // accels as a function of vels
|
| 68 |
+
double max_j = max_a[0]*10.0; // jerk is 10x accel
|
| 69 |
+
|
| 70 |
+
MacJointTraj *mjt,*mjt2;
|
| 71 |
+
try {
|
| 72 |
+
mjt = new MacJointTraj(traj,max_v,max_a,max_j,true,false,1);
|
| 73 |
+
mjt2= new MacJointTraj(traj2,max_v,max_a,max_j,true,false,1);
|
| 74 |
+
} catch (char *errstr) {
|
| 75 |
+
printf("Error: %s\n",errstr);
|
| 76 |
+
exit(1);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
printf("Trajectory computation done:\n");
|
| 80 |
+
mjt->dump();
|
| 81 |
+
|
| 82 |
+
try {
|
| 83 |
+
FILE *csv = fopen("traj.csv","w");
|
| 84 |
+
if (!csv) {
|
| 85 |
+
printf("Cannot output to traj.csv\n");
|
| 86 |
+
exit(1);
|
| 87 |
+
}
|
| 88 |
+
double y[3],yd[3],ydd[3];
|
| 89 |
+
double y2[3],yd2[3],ydd2[3];
|
| 90 |
+
double delta_t = mjt->traj_duration/1000;
|
| 91 |
+
double elapsed_time=0;
|
| 92 |
+
double path_vel, path_accel, path_vel2, path_accel2;
|
| 93 |
+
double max_path_vel,max_path_accel;
|
| 94 |
+
mjt->run(); mjt2->run();
|
| 95 |
+
mjt->evaluate(y,yd,ydd,0);
|
| 96 |
+
mjt2->evaluate(y2,yd2,ydd2,0);
|
| 97 |
+
mjt->get_path_values(&path_vel2,&path_accel2);
|
| 98 |
+
double y_sum = *y - *yd*delta_t; // initial position at -delta_t
|
| 99 |
+
double yd_sum = *yd - *ydd*delta_t; // initial velocity at -delta_t
|
| 100 |
+
while ((mjt->state() != MacJointTraj::DONE)
|
| 101 |
+
|| (mjt2->state() != MacJointTraj::DONE)) {
|
| 102 |
+
y_sum += *(yd+1) * delta_t; // integrate the velocity
|
| 103 |
+
yd_sum += *(ydd+1) * delta_t; // integrate the acceleration
|
| 104 |
+
fprintf(csv,"%3.4f, ",elapsed_time);
|
| 105 |
+
for (unsigned int j=1; j<=max_v.size(); ++j) {
|
| 106 |
+
fprintf(csv,"%2.8f, ",y[j]);
|
| 107 |
+
}
|
| 108 |
+
for (unsigned int j=1; j<=max_v.size(); ++j) {
|
| 109 |
+
fprintf(csv,"%2.8f, ",yd[j]);
|
| 110 |
+
}
|
| 111 |
+
for (unsigned int j=1; j<=max_v.size(); ++j) {
|
| 112 |
+
fprintf(csv,"%2.8f, ",ydd[j]);
|
| 113 |
+
}
|
| 114 |
+
fprintf(csv,"%2.8f, ",y_sum); // double-check vs. y[0]
|
| 115 |
+
fprintf(csv,"%2.8f, ",yd_sum); // double_check vs. yd[0]
|
| 116 |
+
fprintf(csv,"%2.8f, %2.8f, ",path_vel, path_accel);
|
| 117 |
+
fprintf(csv,"%2.8f, %2.8f, %2.8f, ",max_path_vel, max_path_accel, -max_path_accel);
|
| 118 |
+
|
| 119 |
+
fprintf(csv,"%2.8f, %2.8f, %2.8f, %2.8f\n",
|
| 120 |
+
y2[1],y2[2],path_vel2, path_accel2);
|
| 121 |
+
// next sample
|
| 122 |
+
mjt->evaluate(y,yd,ydd,delta_t);
|
| 123 |
+
mjt2->evaluate(y2,yd2,ydd2,delta_t);
|
| 124 |
+
mjt->get_path_values(&path_vel,&path_accel);
|
| 125 |
+
mjt2->get_path_values(&path_vel2,&path_accel2);
|
| 126 |
+
mjt->get_limits(&max_path_vel,&max_path_accel);
|
| 127 |
+
elapsed_time += delta_t;
|
| 128 |
+
}
|
| 129 |
+
fclose(csv);
|
| 130 |
+
} catch (char *errstr) {
|
| 131 |
+
printf("Error during eval loop: %s\n",errstr);
|
| 132 |
+
exit(1);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
exit(0);
|
| 136 |
+
}
|
| 137 |
+
|
pool/shard008/C++/0096655_boss_grobbulus.cpp
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2011-2014 Project SkyFire <http://www.projectskyfire.org/>
|
| 3 |
+
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
|
| 4 |
+
* Copyright (C) 2005-2014 MaNGOS <http://getmangos.com/>
|
| 5 |
+
* Copyright (C) 2006-2014 ScriptDev2 <https://github.com/scriptdev2/scriptdev2/>
|
| 6 |
+
*
|
| 7 |
+
* This program is free software; you can redistribute it and/or modify it
|
| 8 |
+
* under the terms of the GNU General Public License as published by the
|
| 9 |
+
* Free Software Foundation; either version 3 of the License, or (at your
|
| 10 |
+
* option) any later version.
|
| 11 |
+
*
|
| 12 |
+
* This program is distributed in the hope that it will be useful, but WITHOUT
|
| 13 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 14 |
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 15 |
+
* more details.
|
| 16 |
+
*
|
| 17 |
+
* You should have received a copy of the GNU General Public License along
|
| 18 |
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include "ScriptMgr.h"
|
| 22 |
+
#include "ScriptedCreature.h"
|
| 23 |
+
#include "naxxramas.h"
|
| 24 |
+
#include "SpellInfo.h"
|
| 25 |
+
|
| 26 |
+
enum Spells
|
| 27 |
+
{
|
| 28 |
+
SPELL_BOMBARD_SLIME = 28280,
|
| 29 |
+
SPELL_POISON_CLOUD = 28240,
|
| 30 |
+
SPELL_MUTATING_INJECTION = 28169,
|
| 31 |
+
SPELL_SLIME_SPRAY = 28157,
|
| 32 |
+
H_SPELL_SLIME_SPRAY = 54364,
|
| 33 |
+
SPELL_BERSERK = 26662,
|
| 34 |
+
SPELL_POISON_CLOUD_ADD = 59116
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
enum Events
|
| 38 |
+
{
|
| 39 |
+
EVENT_BERSERK = 1,
|
| 40 |
+
EVENT_CLOUD = 2,
|
| 41 |
+
EVENT_INJECT = 3,
|
| 42 |
+
EVENT_SPRAY = 4
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
enum CreatureId
|
| 46 |
+
{
|
| 47 |
+
NPC_FALLOUT_SLIME = 16290
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
class boss_grobbulus : public CreatureScript
|
| 51 |
+
{
|
| 52 |
+
public:
|
| 53 |
+
boss_grobbulus() : CreatureScript("boss_grobbulus") { }
|
| 54 |
+
|
| 55 |
+
CreatureAI* GetAI(Creature* creature) const OVERRIDE
|
| 56 |
+
{
|
| 57 |
+
return new boss_grobbulusAI(creature);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
struct boss_grobbulusAI : public BossAI
|
| 61 |
+
{
|
| 62 |
+
boss_grobbulusAI(Creature* creature) : BossAI(creature, BOSS_GROBBULUS)
|
| 63 |
+
{
|
| 64 |
+
me->ApplySpellImmune(0, IMMUNITY_ID, SPELL_POISON_CLOUD_ADD, true);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
void EnterCombat(Unit* /*who*/) OVERRIDE
|
| 68 |
+
{
|
| 69 |
+
_EnterCombat();
|
| 70 |
+
events.ScheduleEvent(EVENT_CLOUD, 15000);
|
| 71 |
+
events.ScheduleEvent(EVENT_INJECT, 20000);
|
| 72 |
+
events.ScheduleEvent(EVENT_SPRAY, 15000+rand()%15000); //not sure
|
| 73 |
+
events.ScheduleEvent(EVENT_BERSERK, 12*60000);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
void SpellHitTarget(Unit* target, const SpellInfo* spell) OVERRIDE
|
| 77 |
+
{
|
| 78 |
+
if (spell->Id == uint32(SPELL_SLIME_SPRAY))
|
| 79 |
+
{
|
| 80 |
+
if (TempSummon* slime = me->SummonCreature(NPC_FALLOUT_SLIME, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 0))
|
| 81 |
+
DoZoneInCombat(slime);
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
void UpdateAI(uint32 diff) OVERRIDE
|
| 86 |
+
{
|
| 87 |
+
if (!UpdateVictim())
|
| 88 |
+
return;
|
| 89 |
+
|
| 90 |
+
events.Update(diff);
|
| 91 |
+
|
| 92 |
+
while (uint32 eventId = events.ExecuteEvent())
|
| 93 |
+
{
|
| 94 |
+
switch (eventId)
|
| 95 |
+
{
|
| 96 |
+
case EVENT_CLOUD:
|
| 97 |
+
DoCastAOE(SPELL_POISON_CLOUD);
|
| 98 |
+
events.ScheduleEvent(EVENT_CLOUD, 15000);
|
| 99 |
+
return;
|
| 100 |
+
case EVENT_BERSERK:
|
| 101 |
+
DoCastAOE(SPELL_BERSERK);
|
| 102 |
+
return;
|
| 103 |
+
case EVENT_SPRAY:
|
| 104 |
+
DoCastAOE(SPELL_SLIME_SPRAY);
|
| 105 |
+
events.ScheduleEvent(EVENT_SPRAY, 15000+rand()%15000);
|
| 106 |
+
return;
|
| 107 |
+
case EVENT_INJECT:
|
| 108 |
+
if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 1))
|
| 109 |
+
if (!target->HasAura(SPELL_MUTATING_INJECTION))
|
| 110 |
+
DoCast(target, SPELL_MUTATING_INJECTION);
|
| 111 |
+
events.ScheduleEvent(EVENT_INJECT, 8000 + uint32(120 * me->GetHealthPct()));
|
| 112 |
+
return;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
DoMeleeAttackIfReady();
|
| 117 |
+
}
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
class npc_grobbulus_poison_cloud : public CreatureScript
|
| 123 |
+
{
|
| 124 |
+
public:
|
| 125 |
+
npc_grobbulus_poison_cloud() : CreatureScript("npc_grobbulus_poison_cloud") { }
|
| 126 |
+
|
| 127 |
+
CreatureAI* GetAI(Creature* creature) const OVERRIDE
|
| 128 |
+
{
|
| 129 |
+
return new npc_grobbulus_poison_cloudAI(creature);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
struct npc_grobbulus_poison_cloudAI : public ScriptedAI
|
| 133 |
+
{
|
| 134 |
+
npc_grobbulus_poison_cloudAI(Creature* creature) : ScriptedAI(creature)
|
| 135 |
+
{
|
| 136 |
+
SetCombatMovement(false);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
uint32 Cloud_Timer;
|
| 140 |
+
|
| 141 |
+
void Reset() OVERRIDE
|
| 142 |
+
{
|
| 143 |
+
Cloud_Timer = 1000;
|
| 144 |
+
me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
void UpdateAI(uint32 diff) OVERRIDE
|
| 148 |
+
{
|
| 149 |
+
if (Cloud_Timer <= diff)
|
| 150 |
+
{
|
| 151 |
+
DoCast(me, SPELL_POISON_CLOUD_ADD);
|
| 152 |
+
Cloud_Timer = 10000;
|
| 153 |
+
} else Cloud_Timer -= diff;
|
| 154 |
+
}
|
| 155 |
+
};
|
| 156 |
+
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
void AddSC_boss_grobbulus()
|
| 160 |
+
{
|
| 161 |
+
new boss_grobbulus();
|
| 162 |
+
new npc_grobbulus_poison_cloud();
|
| 163 |
+
}
|
pool/shard008/C++/0096661_loop_tests.cpp
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 2 |
+
// you may not use this file except in compliance with the License.
|
| 3 |
+
// You may obtain a copy of the License at
|
| 4 |
+
//
|
| 5 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 6 |
+
//
|
| 7 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 8 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 9 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 10 |
+
// See the License for the specific language governing permissions and
|
| 11 |
+
// limitations under the License
|
| 12 |
+
|
| 13 |
+
#include <gmock/gmock.h>
|
| 14 |
+
|
| 15 |
+
#include <atomic>
|
| 16 |
+
#include <string>
|
| 17 |
+
|
| 18 |
+
#include <process/future.hpp>
|
| 19 |
+
#include <process/gtest.hpp>
|
| 20 |
+
#include <process/loop.hpp>
|
| 21 |
+
#include <process/queue.hpp>
|
| 22 |
+
|
| 23 |
+
using process::Break;
|
| 24 |
+
using process::Continue;
|
| 25 |
+
using process::ControlFlow;
|
| 26 |
+
using process::Future;
|
| 27 |
+
using process::loop;
|
| 28 |
+
using process::Promise;
|
| 29 |
+
using process::Queue;
|
| 30 |
+
|
| 31 |
+
using std::string;
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
TEST(LoopTest, Sync)
|
| 35 |
+
{
|
| 36 |
+
std::atomic_int value = ATOMIC_VAR_INIT(1);
|
| 37 |
+
|
| 38 |
+
Future<Nothing> future = loop(
|
| 39 |
+
[&]() {
|
| 40 |
+
return value.load();
|
| 41 |
+
},
|
| 42 |
+
[](int i) -> ControlFlow<Nothing> {
|
| 43 |
+
if (i != 0) {
|
| 44 |
+
return Continue();
|
| 45 |
+
}
|
| 46 |
+
return Break();
|
| 47 |
+
});
|
| 48 |
+
|
| 49 |
+
EXPECT_TRUE(future.isPending());
|
| 50 |
+
|
| 51 |
+
value.store(0);
|
| 52 |
+
|
| 53 |
+
AWAIT_READY(future);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
TEST(LoopTest, Async)
|
| 58 |
+
{
|
| 59 |
+
Queue<int> queue;
|
| 60 |
+
|
| 61 |
+
Promise<int> promise1;
|
| 62 |
+
Promise<string> promise2;
|
| 63 |
+
|
| 64 |
+
Future<string> future = loop(
|
| 65 |
+
[&]() {
|
| 66 |
+
return queue.get();
|
| 67 |
+
},
|
| 68 |
+
[&](int i) {
|
| 69 |
+
promise1.set(i);
|
| 70 |
+
return promise2.future()
|
| 71 |
+
.then([](const string& s) -> ControlFlow<string> {
|
| 72 |
+
return Break(s);
|
| 73 |
+
});
|
| 74 |
+
});
|
| 75 |
+
|
| 76 |
+
EXPECT_TRUE(future.isPending());
|
| 77 |
+
|
| 78 |
+
queue.put(1);
|
| 79 |
+
|
| 80 |
+
AWAIT_EQ(1, promise1.future());
|
| 81 |
+
|
| 82 |
+
EXPECT_TRUE(future.isPending());
|
| 83 |
+
|
| 84 |
+
string s = "Hello world!";
|
| 85 |
+
|
| 86 |
+
promise2.set(s);
|
| 87 |
+
|
| 88 |
+
AWAIT_EQ(s, future);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
TEST(LoopTest, DiscardIterate)
|
| 93 |
+
{
|
| 94 |
+
Promise<int> promise;
|
| 95 |
+
|
| 96 |
+
promise.future().onDiscard([&]() { promise.discard(); });
|
| 97 |
+
|
| 98 |
+
Future<Nothing> future = loop(
|
| 99 |
+
[&]() {
|
| 100 |
+
return promise.future();
|
| 101 |
+
},
|
| 102 |
+
[&](int i) -> ControlFlow<Nothing> {
|
| 103 |
+
return Break();
|
| 104 |
+
});
|
| 105 |
+
|
| 106 |
+
EXPECT_TRUE(future.isPending());
|
| 107 |
+
|
| 108 |
+
future.discard();
|
| 109 |
+
|
| 110 |
+
AWAIT_DISCARDED(future);
|
| 111 |
+
EXPECT_TRUE(promise.future().hasDiscard());
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
TEST(LoopTest, DiscardBody)
|
| 116 |
+
{
|
| 117 |
+
Promise<Nothing> promise;
|
| 118 |
+
|
| 119 |
+
promise.future().onDiscard([&]() { promise.discard(); });
|
| 120 |
+
|
| 121 |
+
Future<Nothing> future = loop(
|
| 122 |
+
[&]() {
|
| 123 |
+
return 42;
|
| 124 |
+
},
|
| 125 |
+
[&](int i) {
|
| 126 |
+
return promise.future()
|
| 127 |
+
.then([]() -> ControlFlow<Nothing> {
|
| 128 |
+
return Break();
|
| 129 |
+
});
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
EXPECT_TRUE(future.isPending());
|
| 133 |
+
|
| 134 |
+
future.discard();
|
| 135 |
+
|
| 136 |
+
AWAIT_DISCARDED(future);
|
| 137 |
+
EXPECT_TRUE(promise.future().hasDiscard());
|
| 138 |
+
}
|
pool/shard008/C++/0096662_CWE190_Integer_Overflow__short_fscanf_multiply_84a.cpp
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE190_Integer_Overflow__short_fscanf_multiply_84a.cpp
|
| 3 |
+
Label Definition File: CWE190_Integer_Overflow.label.xml
|
| 4 |
+
Template File: sources-sinks-84a.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 190 Integer Overflow
|
| 9 |
+
* BadSource: fscanf Read data from the console using fscanf()
|
| 10 |
+
* GoodSource: Set data to a small, non-zero number (two)
|
| 11 |
+
* Sinks: multiply
|
| 12 |
+
* GoodSink: Ensure there will not be an overflow before multiplying data by 2
|
| 13 |
+
* BadSink : If data is positive, multiply by 2, which can cause an overflow
|
| 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 "CWE190_Integer_Overflow__short_fscanf_multiply_84.h"
|
| 20 |
+
|
| 21 |
+
namespace CWE190_Integer_Overflow__short_fscanf_multiply_84
|
| 22 |
+
{
|
| 23 |
+
|
| 24 |
+
#ifndef OMITBAD
|
| 25 |
+
|
| 26 |
+
void bad()
|
| 27 |
+
{
|
| 28 |
+
short data;
|
| 29 |
+
data = 0;
|
| 30 |
+
CWE190_Integer_Overflow__short_fscanf_multiply_84_bad * badObject = new CWE190_Integer_Overflow__short_fscanf_multiply_84_bad(data);
|
| 31 |
+
delete badObject;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
#endif /* OMITBAD */
|
| 35 |
+
|
| 36 |
+
#ifndef OMITGOOD
|
| 37 |
+
|
| 38 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 39 |
+
static void goodG2B()
|
| 40 |
+
{
|
| 41 |
+
short data;
|
| 42 |
+
data = 0;
|
| 43 |
+
CWE190_Integer_Overflow__short_fscanf_multiply_84_goodG2B * goodG2BObject = new CWE190_Integer_Overflow__short_fscanf_multiply_84_goodG2B(data);
|
| 44 |
+
delete goodG2BObject;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/* goodG2B uses the BadSource with the GoodSink */
|
| 48 |
+
static void goodB2G()
|
| 49 |
+
{
|
| 50 |
+
short data;
|
| 51 |
+
data = 0;
|
| 52 |
+
CWE190_Integer_Overflow__short_fscanf_multiply_84_goodB2G * goodB2GObject = new CWE190_Integer_Overflow__short_fscanf_multiply_84_goodB2G(data);
|
| 53 |
+
delete goodB2GObject;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
void good()
|
| 57 |
+
{
|
| 58 |
+
goodG2B();
|
| 59 |
+
goodB2G();
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
#endif /* OMITGOOD */
|
| 63 |
+
|
| 64 |
+
} /* close namespace */
|
| 65 |
+
|
| 66 |
+
/* Below is the main(). It is only used when building this testcase on
|
| 67 |
+
its own for testing or for building a binary to use in testing binary
|
| 68 |
+
analysis tools. It is not used when compiling all the testcases as one
|
| 69 |
+
application, which is how source code analysis tools are tested. */
|
| 70 |
+
|
| 71 |
+
#ifdef INCLUDEMAIN
|
| 72 |
+
|
| 73 |
+
using namespace CWE190_Integer_Overflow__short_fscanf_multiply_84; /* so that we can use good and bad easily */
|
| 74 |
+
|
| 75 |
+
int main(int argc, char * argv[])
|
| 76 |
+
{
|
| 77 |
+
/* seed randomness */
|
| 78 |
+
srand( (unsigned)time(NULL) );
|
| 79 |
+
#ifndef OMITGOOD
|
| 80 |
+
printLine("Calling good()...");
|
| 81 |
+
good();
|
| 82 |
+
printLine("Finished good()");
|
| 83 |
+
#endif /* OMITGOOD */
|
| 84 |
+
#ifndef OMITBAD
|
| 85 |
+
printLine("Calling bad()...");
|
| 86 |
+
bad();
|
| 87 |
+
printLine("Finished bad()");
|
| 88 |
+
#endif /* OMITBAD */
|
| 89 |
+
return 0;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
#endif
|
pool/shard008/C++/0096663_TestApplication.cpp
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// TestApplication.cpp : Defines the entry point for the console application.
|
| 2 |
+
//
|
| 3 |
+
|
| 4 |
+
#include "stdafx.h"
|
| 5 |
+
#include <Windows.h>
|
| 6 |
+
#include <iostream>
|
| 7 |
+
|
| 8 |
+
#include "../TelemetryProvider/MappedTelemetryData.h"
|
| 9 |
+
|
| 10 |
+
float MetersPerSecondToKilometersPerHour(float metersPerSecond)
|
| 11 |
+
{
|
| 12 |
+
return metersPerSecond * 3.6f;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
void DisplaySpeedFromMappedFile()
|
| 16 |
+
{
|
| 17 |
+
auto mappedFile = CreateFileMapping(
|
| 18 |
+
INVALID_HANDLE_VALUE, // use paging file
|
| 19 |
+
NULL, // default security
|
| 20 |
+
PAGE_READWRITE, // read/write access
|
| 21 |
+
0, // maximum object size (high-order DWORD)
|
| 22 |
+
sizeof(MappedTelemetryData), // maximum object size (low-order DWORD)
|
| 23 |
+
L"SCS_Telemetry_Data_OG"); // name of mapping object
|
| 24 |
+
|
| 25 |
+
while (true)
|
| 26 |
+
{
|
| 27 |
+
auto filePtr = MapViewOfFile(mappedFile, FILE_MAP_READ, 0, 0, sizeof(MappedTelemetryData));
|
| 28 |
+
|
| 29 |
+
MappedTelemetryData* data = (MappedTelemetryData*)filePtr;
|
| 30 |
+
|
| 31 |
+
if (data->gamePaused)
|
| 32 |
+
{
|
| 33 |
+
std::cout << "The game is paused ..." << std::endl;
|
| 34 |
+
}
|
| 35 |
+
else
|
| 36 |
+
{
|
| 37 |
+
std::cout << "You're driving " << MetersPerSecondToKilometersPerHour(data->speed) << " kph" << std::endl;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
UnmapViewOfFile(filePtr);
|
| 41 |
+
|
| 42 |
+
Sleep(20);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
CloseHandle(mappedFile);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
int _tmain(int argc, _TCHAR* argv[])
|
| 49 |
+
{
|
| 50 |
+
//auto mmf = new MemoryMappedFile();
|
| 51 |
+
//auto mapped = mmf->IsFileMapped();
|
| 52 |
+
|
| 53 |
+
//MappedTelemetryData data;
|
| 54 |
+
//data.speed = 12.34f;
|
| 55 |
+
|
| 56 |
+
//mmf->UpdateMappedFile(data);
|
| 57 |
+
|
| 58 |
+
//delete mmf;
|
| 59 |
+
|
| 60 |
+
while (true)
|
| 61 |
+
{
|
| 62 |
+
DisplaySpeedFromMappedFile();
|
| 63 |
+
}
|
| 64 |
+
}
|
pool/shard008/C++/0096664_main.cpp
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This autogenerated skeleton file illustrates how to build a server.
|
| 2 |
+
// You should copy it to another filename to avoid overwriting it.
|
| 3 |
+
|
| 4 |
+
#include "rsg/actor.hpp"
|
| 5 |
+
#include "rsg/mailbox.hpp"
|
| 6 |
+
#include "rsg/comm.hpp"
|
| 7 |
+
#include "rsg/host.hpp"
|
| 8 |
+
#include "../../../src/common.hpp"
|
| 9 |
+
|
| 10 |
+
#include "xbt.h"
|
| 11 |
+
#include "simgrid/s4u.hpp"
|
| 12 |
+
|
| 13 |
+
#include <iostream>
|
| 14 |
+
#include <sys/types.h>
|
| 15 |
+
#include <string>
|
| 16 |
+
#include <unistd.h>
|
| 17 |
+
#include <thread>
|
| 18 |
+
#include <inttypes.h>
|
| 19 |
+
|
| 20 |
+
#include <boost/uuid/uuid.hpp> // uuid class
|
| 21 |
+
#include <boost/uuid/uuid_generators.hpp> // generators
|
| 22 |
+
#include <boost/uuid/uuid_io.hpp> // streaming operators etc.
|
| 23 |
+
|
| 24 |
+
XBT_LOG_NEW_CATEGORY(RSG_THRIFT_CLIENT, "Remote SimGrid");
|
| 25 |
+
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(RSG_THRIFT_REMOTE_CLIENT, RSG_THRIFT_CLIENT , "RSG server (Remote SimGrid)");
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
using boost::shared_ptr;
|
| 29 |
+
using namespace ::simgrid;
|
| 30 |
+
|
| 31 |
+
#define UNUSED(x) (void)(x)
|
| 32 |
+
|
| 33 |
+
class PidComp {
|
| 34 |
+
public:
|
| 35 |
+
PidComp(std::string name) : pName(name) {}
|
| 36 |
+
std::string pName;
|
| 37 |
+
int operator()(void * ) {
|
| 38 |
+
rsg::MailboxPtr mbox = rsg::Mailbox::byName(this->pName.c_str());
|
| 39 |
+
int *pid = (int*) rsg::this_actor::recv(*mbox);
|
| 40 |
+
int id = rsg::this_actor::getPid();
|
| 41 |
+
XBT_INFO("PidComp -> [%d:%d] %d",id, *pid ,id - *pid);
|
| 42 |
+
free(pid);
|
| 43 |
+
rsg::this_actor::quit();
|
| 44 |
+
return 1;
|
| 45 |
+
}
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
int Spwaner(void * ) {
|
| 50 |
+
rsg::HostPtr host1 = rsg::Host::by_name("host1");
|
| 51 |
+
|
| 52 |
+
for(int i = 0; i < 100; i++) {
|
| 53 |
+
std::string name = "PidComp" + std::to_string(i) + "__" + std::to_string(rsg::this_actor::getPid());
|
| 54 |
+
rsg::MailboxPtr mbox = rsg::Mailbox::byName(name.c_str());
|
| 55 |
+
|
| 56 |
+
rsg::Actor* actor = rsg::Actor::createActor("hello" , host1 , PidComp(name), NULL);
|
| 57 |
+
int pid = actor->getPid();
|
| 58 |
+
rsg::this_actor::send(*mbox, (char*) &(pid), sizeof(int));
|
| 59 |
+
actor->join();
|
| 60 |
+
delete actor;
|
| 61 |
+
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
rsg::this_actor::quit();
|
| 65 |
+
return 1;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
int main(int argc, char **argv) {
|
| 69 |
+
rsg::HostPtr host1 = rsg::Host::by_name("host1");
|
| 70 |
+
|
| 71 |
+
for(int i = 0; i < 4; i++) {
|
| 72 |
+
rsg::Actor* actor = rsg::Actor::createActor("spawner" , host1 , Spwaner, NULL);
|
| 73 |
+
UNUSED(actor);
|
| 74 |
+
actor->join();
|
| 75 |
+
delete actor;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
rsg::this_actor::sleep(1000);
|
| 79 |
+
rsg::this_actor::quit();
|
| 80 |
+
|
| 81 |
+
return 0;
|
| 82 |
+
}
|
pool/shard008/C++/0096665_unsafe_test.cc
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2014 The Android Open Source Project
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
#include "art_method-inl.h"
|
| 18 |
+
#include "jni.h"
|
| 19 |
+
#include "mirror/array.h"
|
| 20 |
+
#include "mirror/class.h"
|
| 21 |
+
#include "mirror/class-inl.h"
|
| 22 |
+
#include "mirror/object-inl.h"
|
| 23 |
+
#include "scoped_thread_state_change.h"
|
| 24 |
+
|
| 25 |
+
namespace art {
|
| 26 |
+
|
| 27 |
+
extern "C" JNIEXPORT jint JNICALL Java_Main_vmArrayBaseOffset(JNIEnv* env, jclass, jobject classObj) {
|
| 28 |
+
ScopedObjectAccess soa(env);
|
| 29 |
+
mirror::Class* klass = soa.Decode<mirror::Class*>(classObj);
|
| 30 |
+
return mirror::Array::DataOffset(
|
| 31 |
+
Primitive::ComponentSize(klass->GetComponentType()->GetPrimitiveType())).Int32Value();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
extern "C" JNIEXPORT jint JNICALL Java_Main_vmArrayIndexScale(JNIEnv* env, jclass, jobject classObj) {
|
| 35 |
+
ScopedObjectAccess soa(env);
|
| 36 |
+
mirror::Class* klass = soa.Decode<mirror::Class*>(classObj);
|
| 37 |
+
return Primitive::ComponentSize(klass->GetComponentType()->GetPrimitiveType());
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
} // namespace art
|
pool/shard008/C++/0096666_get_numvols.cc
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* @BEGIN LICENSE
|
| 3 |
+
*
|
| 4 |
+
* Psi4: an open-source quantum chemistry software package
|
| 5 |
+
*
|
| 6 |
+
* Copyright (c) 2007-2019 The Psi4 Developers.
|
| 7 |
+
*
|
| 8 |
+
* The copyrights for code used from other parties are included in
|
| 9 |
+
* the corresponding files.
|
| 10 |
+
*
|
| 11 |
+
* This file is part of Psi4.
|
| 12 |
+
*
|
| 13 |
+
* Psi4 is free software; you can redistribute it and/or modify
|
| 14 |
+
* it under the terms of the GNU Lesser General Public License as published by
|
| 15 |
+
* the Free Software Foundation, version 3.
|
| 16 |
+
*
|
| 17 |
+
* Psi4 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
|
| 20 |
+
* GNU Lesser General Public License for more details.
|
| 21 |
+
*
|
| 22 |
+
* You should have received a copy of the GNU Lesser General Public License along
|
| 23 |
+
* with Psi4; if not, write to the Free Software Foundation, Inc.,
|
| 24 |
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
| 25 |
+
*
|
| 26 |
+
* @END LICENSE
|
| 27 |
+
*/
|
| 28 |
+
|
| 29 |
+
/*!
|
| 30 |
+
\file
|
| 31 |
+
\ingroup PSIO
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
#include "psi4/pragma.h"
|
| 35 |
+
PRAGMA_WARNING_PUSH
|
| 36 |
+
PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS
|
| 37 |
+
#include <memory>
|
| 38 |
+
PRAGMA_WARNING_POP
|
| 39 |
+
#include <cstdio>
|
| 40 |
+
#include <cstdlib>
|
| 41 |
+
#include "psi4/libpsio/psio.h"
|
| 42 |
+
#include "psi4/libpsio/psio.hpp"
|
| 43 |
+
|
| 44 |
+
namespace psi {
|
| 45 |
+
|
| 46 |
+
size_t PSIO::get_numvols(size_t unit) {
|
| 47 |
+
std::string charnum;
|
| 48 |
+
charnum = filecfg_kwd("PSI", "NVOLUME", unit);
|
| 49 |
+
if (!charnum.empty()) return ((size_t)atoi(charnum.c_str()));
|
| 50 |
+
charnum = filecfg_kwd("PSI", "NVOLUME", -1);
|
| 51 |
+
if (!charnum.empty()) return ((size_t)atoi(charnum.c_str()));
|
| 52 |
+
charnum = filecfg_kwd("DEFAULT", "NVOLUME", unit);
|
| 53 |
+
if (!charnum.empty()) return ((size_t)atoi(charnum.c_str()));
|
| 54 |
+
charnum = filecfg_kwd("DEFAULT", "NVOLUME", -1);
|
| 55 |
+
if (!charnum.empty()) return ((size_t)atoi(charnum.c_str()));
|
| 56 |
+
|
| 57 |
+
// assume that the default has been provided already
|
| 58 |
+
abort();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
size_t psio_get_numvols_default() {
|
| 62 |
+
std::string charnum;
|
| 63 |
+
|
| 64 |
+
charnum = _default_psio_lib_->filecfg_kwd("PSI", "NVOLUME", -1);
|
| 65 |
+
if (!charnum.empty()) return ((size_t)atoi(charnum.c_str()));
|
| 66 |
+
charnum = _default_psio_lib_->filecfg_kwd("DEFAULT", "NVOLUME", -1);
|
| 67 |
+
if (!charnum.empty()) return ((size_t)atoi(charnum.c_str()));
|
| 68 |
+
|
| 69 |
+
// assume that the default has been provided already
|
| 70 |
+
abort();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
} // namespace psi
|
pool/shard008/C++/0096670_fetch.cpp
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <iostream>
|
| 2 |
+
|
| 3 |
+
#include "ocilib.hpp"
|
| 4 |
+
|
| 5 |
+
/* requires script demo/products.sql */
|
| 6 |
+
|
| 7 |
+
using namespace ocilib;
|
| 8 |
+
|
| 9 |
+
int main(void)
|
| 10 |
+
{
|
| 11 |
+
try
|
| 12 |
+
{
|
| 13 |
+
Environment::Initialize();
|
| 14 |
+
|
| 15 |
+
Connection con("db", "usr", "pwd");
|
| 16 |
+
|
| 17 |
+
Statement st(con);
|
| 18 |
+
st.Execute("select * from products");
|
| 19 |
+
|
| 20 |
+
Resultset rs = st.GetResultset();
|
| 21 |
+
while (rs++)
|
| 22 |
+
{
|
| 23 |
+
std::cout << "code:" << rs.Get<ostring>(1) << " name:" << rs.Get<ostring>(2) << std::endl;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
std::cout << "=> Total fetched rows : " << rs.GetCount() << std::endl;
|
| 27 |
+
|
| 28 |
+
}
|
| 29 |
+
catch (std::exception &ex)
|
| 30 |
+
{
|
| 31 |
+
std::cout << ex.what() << std::endl;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
Environment::Cleanup();
|
| 35 |
+
|
| 36 |
+
return EXIT_SUCCESS;
|
| 37 |
+
}
|
pool/shard008/C++/0096672_MediaFile.cpp
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************
|
| 2 |
+
* Media Explorer
|
| 3 |
+
*****************************************************************************/
|
| 4 |
+
|
| 5 |
+
#include "stdafx.h"
|
| 6 |
+
#if HAVE_CONFIG_H
|
| 7 |
+
# include "config.h"
|
| 8 |
+
#endif
|
| 9 |
+
|
| 10 |
+
#include "Media.h"
|
| 11 |
+
#include "MediaFile.h"
|
| 12 |
+
#include "MediaFolder.h"
|
| 13 |
+
#include "database/SqliteTools.h"
|
| 14 |
+
|
| 15 |
+
using mxp::policy::MediaFileTable;
|
| 16 |
+
const std::string MediaFileTable::Name = "MediaFile";
|
| 17 |
+
const std::string MediaFileTable::PrimaryKeyColumn = "id_file";
|
| 18 |
+
int64_t mxp::MediaFile::* const MediaFileTable::PrimaryKey = &mxp::MediaFile::m_id;
|
| 19 |
+
|
| 20 |
+
mxp::MediaFile::MediaFile(MediaExplorerPtr ml, sqlite::Row& row)
|
| 21 |
+
: m_ml(ml)
|
| 22 |
+
, m_id{}
|
| 23 |
+
, m_mediaId{}
|
| 24 |
+
, m_mrl{}
|
| 25 |
+
, m_type{}
|
| 26 |
+
, m_lastModificationDate{}
|
| 27 |
+
, m_numServicesParsed{}
|
| 28 |
+
, m_folderId{}
|
| 29 |
+
, m_isPresent{}
|
| 30 |
+
, m_isRemovable{} {
|
| 31 |
+
row >> m_id
|
| 32 |
+
>> m_mediaId
|
| 33 |
+
>> m_mrl
|
| 34 |
+
>> m_type
|
| 35 |
+
>> m_lastModificationDate
|
| 36 |
+
>> m_numServicesParsed
|
| 37 |
+
>> m_folderId
|
| 38 |
+
>> m_isPresent
|
| 39 |
+
>> m_isRemovable;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
mxp::MediaFile::MediaFile(MediaExplorerPtr ml, int64_t mediaId, MediaFileType type, const fs::IFile& file, int64_t folderId, bool isRemovable)
|
| 43 |
+
: m_ml(ml)
|
| 44 |
+
, m_id(0)
|
| 45 |
+
, m_mediaId(mediaId)
|
| 46 |
+
, m_mrl(isRemovable == true ? file.GetName() : file.GetFullPath())
|
| 47 |
+
, m_type(type)
|
| 48 |
+
, m_lastModificationDate(file.GetLastModificationDate())
|
| 49 |
+
, m_numServicesParsed(0)
|
| 50 |
+
, m_folderId(folderId)
|
| 51 |
+
, m_isPresent(true)
|
| 52 |
+
, m_isRemovable(isRemovable) {
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
int64_t mxp::MediaFile::Id() const {
|
| 56 |
+
return m_id;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
const std::string& mxp::MediaFile::GetMrl() const {
|
| 60 |
+
if (m_isRemovable == false)
|
| 61 |
+
return m_mrl;
|
| 62 |
+
|
| 63 |
+
auto lock = m_fullPath.Lock();
|
| 64 |
+
if (m_fullPath.IsCached())
|
| 65 |
+
return m_fullPath;
|
| 66 |
+
|
| 67 |
+
auto folder = MediaFolder::Fetch(m_ml, m_folderId);
|
| 68 |
+
if (folder == nullptr)
|
| 69 |
+
return m_mrl;
|
| 70 |
+
|
| 71 |
+
m_fullPath = folder->path() + m_mrl;
|
| 72 |
+
|
| 73 |
+
return m_fullPath;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
mxp::MediaFileType mxp::MediaFile::GetType() const {
|
| 77 |
+
return m_type;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
time_t mxp::MediaFile::LastModificationDate() const {
|
| 81 |
+
return m_lastModificationDate;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
void mxp::MediaFile::SetServicesParsedCount(unsigned int value) {
|
| 85 |
+
if(m_numServicesParsed == value) {
|
| 86 |
+
return;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
static const auto req = "UPDATE " + MediaFileTable::Name + " SET services_parsed_count=? WHERE " + MediaFileTable::PrimaryKeyColumn + "=?";
|
| 90 |
+
if(sqlite::Tools::ExecuteUpdate(m_ml->GetConnection(), req, value, m_id) == false) {
|
| 91 |
+
return;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
m_numServicesParsed = value;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
unsigned int mxp::MediaFile::GetServicesParsedCount() const {
|
| 98 |
+
return m_numServicesParsed;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
std::shared_ptr<mxp::Media> mxp::MediaFile::GetMedia() const {
|
| 102 |
+
auto lock = m_media.Lock();
|
| 103 |
+
if (m_media.IsCached() == false) {
|
| 104 |
+
m_media = Media::Fetch(m_ml, m_mediaId);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
return m_media.Get().lock();
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
bool mxp::MediaFile::Destroy() const {
|
| 111 |
+
return DatabaseHelpers::destroy(m_ml, m_id);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
bool mxp::MediaFile::CreateTable(DBConnection connection) noexcept {
|
| 115 |
+
static const auto req = "CREATE TABLE IF NOT EXISTS " + MediaFileTable::Name + "(" +
|
| 116 |
+
MediaFileTable::PrimaryKeyColumn + " INTEGER PRIMARY KEY AUTOINCREMENT,"
|
| 117 |
+
"media_id INT NOT NULL,"
|
| 118 |
+
"mrl TEXT,"
|
| 119 |
+
"type UNSIGNED INTEGER,"
|
| 120 |
+
"last_modification_date UNSIGNED INT,"
|
| 121 |
+
"services_parsed_count UNSIGNED INT NOT NULL DEFAULT 0,"
|
| 122 |
+
"folder_id UNSIGNED INTEGER,"
|
| 123 |
+
"is_present BOOLEAN NOT NULL DEFAULT 1,"
|
| 124 |
+
"is_removable BOOLEAN NOT NULL,"
|
| 125 |
+
"FOREIGN KEY (media_id) REFERENCES " + policy::MediaTable::Name + "(" + policy::MediaTable::PrimaryKeyColumn + ") ON DELETE CASCADE,"
|
| 126 |
+
"FOREIGN KEY (folder_id) REFERENCES " + policy::MediaFolderTable::Name + "(" + policy::MediaFolderTable::PrimaryKeyColumn + ") ON DELETE CASCADE,"
|
| 127 |
+
"UNIQUE(mrl, folder_id) ON CONFLICT FAIL"
|
| 128 |
+
")";
|
| 129 |
+
static const auto triggerReq = "CREATE TRIGGER IF NOT EXISTS is_folder_present AFTER UPDATE OF is_present ON "
|
| 130 |
+
+ policy::MediaFolderTable::Name +
|
| 131 |
+
" BEGIN"
|
| 132 |
+
" UPDATE " + MediaFileTable::Name + " SET is_present = new.is_present WHERE folder_id = new.id_folder;"
|
| 133 |
+
" END";
|
| 134 |
+
static const auto indexReq = "CREATE INDEX IF NOT EXISTS file_media_id_index ON " + MediaFileTable::Name + "(media_id)";
|
| 135 |
+
|
| 136 |
+
bool success;
|
| 137 |
+
try {
|
| 138 |
+
success = sqlite::Tools::ExecuteRequest(connection, req) &&
|
| 139 |
+
sqlite::Tools::ExecuteRequest(connection, triggerReq) &&
|
| 140 |
+
sqlite::Tools::ExecuteRequest(connection, indexReq);
|
| 141 |
+
} catch (std::exception& ex) {
|
| 142 |
+
LOG_ERROR("Failed to create table for ", policy::MediaTable::Name, ": ", ex.what());
|
| 143 |
+
success = false;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
return success;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
std::shared_ptr<mxp::MediaFile> mxp::MediaFile::Create(MediaExplorerPtr ml, int64_t mediaId, MediaFileType type, const fs::IFile& fileFs, int64_t folderId, bool isRemovable) noexcept {
|
| 150 |
+
std::shared_ptr<MediaFile> self;
|
| 151 |
+
static const auto req = "INSERT INTO " + MediaFileTable::Name + "(media_id, mrl, type, folder_id, last_modification_date, is_removable) VALUES(?, ?, ?, ?, ?, ?)";
|
| 152 |
+
|
| 153 |
+
try {
|
| 154 |
+
self = std::make_shared<MediaFile>(ml, mediaId, type, fileFs, folderId, isRemovable);
|
| 155 |
+
|
| 156 |
+
#pragma warning( suppress : 4244 )
|
| 157 |
+
if(insert(ml, self, req, mediaId, self->m_mrl, type, sqlite::ForeignKey(folderId), self->m_lastModificationDate, isRemovable) == false) {
|
| 158 |
+
self = nullptr;
|
| 159 |
+
} else {
|
| 160 |
+
self->m_fullPath = fileFs.GetFullPath();
|
| 161 |
+
}
|
| 162 |
+
} catch (std::exception& ex) {
|
| 163 |
+
LOG_ERROR("Failed to create MediaFile: ", ex.what());
|
| 164 |
+
self = nullptr;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
return self;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
std::shared_ptr<mxp::MediaFile> mxp::MediaFile::FindByPath(MediaExplorerPtr ml, const std::string& path) {
|
| 171 |
+
static const auto req = "SELECT * FROM " + MediaFileTable::Name + " WHERE mrl = ?";
|
| 172 |
+
auto file = Fetch(ml, req, path);
|
| 173 |
+
if(file == nullptr)
|
| 174 |
+
return nullptr;
|
| 175 |
+
// safety checks: since this only works for files on non removable devices, isPresent must be true
|
| 176 |
+
// and isRemovable must be false
|
| 177 |
+
assert(file->m_isPresent == true);
|
| 178 |
+
assert(file->m_isRemovable == false);
|
| 179 |
+
return file;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
std::shared_ptr<mxp::MediaFile> mxp::MediaFile::FindByFileName(MediaExplorerPtr ml, const std::string& fileName, int64_t folderId) {
|
| 183 |
+
static const auto req = "SELECT * FROM " + MediaFileTable::Name + " WHERE mrl = ? AND folder_id = ?";
|
| 184 |
+
auto file = Fetch(ml, req, fileName, folderId);
|
| 185 |
+
if(file == nullptr)
|
| 186 |
+
return nullptr;
|
| 187 |
+
|
| 188 |
+
assert(file->m_isRemovable == true);
|
| 189 |
+
return file;
|
| 190 |
+
}
|
pool/shard008/C++/0096675_console_reporter.cc
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2015 Google Inc. 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 <algorithm>
|
| 16 |
+
#include <cstdint>
|
| 17 |
+
#include <cstdio>
|
| 18 |
+
#include <cstring>
|
| 19 |
+
#include <iostream>
|
| 20 |
+
#include <string>
|
| 21 |
+
#include <tuple>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
#include "benchmark/benchmark.h"
|
| 25 |
+
#include "check.h"
|
| 26 |
+
#include "colorprint.h"
|
| 27 |
+
#include "commandlineflags.h"
|
| 28 |
+
#include "complexity.h"
|
| 29 |
+
#include "counter.h"
|
| 30 |
+
#include "internal_macros.h"
|
| 31 |
+
#include "string_util.h"
|
| 32 |
+
#include "timers.h"
|
| 33 |
+
|
| 34 |
+
namespace benchmark {
|
| 35 |
+
|
| 36 |
+
bool ConsoleReporter::ReportContext(const Context& context) {
|
| 37 |
+
name_field_width_ = context.name_field_width;
|
| 38 |
+
printed_header_ = false;
|
| 39 |
+
prev_counters_.clear();
|
| 40 |
+
|
| 41 |
+
PrintBasicContext(&GetErrorStream(), context);
|
| 42 |
+
|
| 43 |
+
#ifdef BENCHMARK_OS_WINDOWS
|
| 44 |
+
if ((output_options_ & OO_Color) && &std::cout != &GetOutputStream()) {
|
| 45 |
+
GetErrorStream()
|
| 46 |
+
<< "Color printing is only supported for stdout on windows."
|
| 47 |
+
" Disabling color printing\n";
|
| 48 |
+
output_options_ = static_cast< OutputOptions >(output_options_ & ~OO_Color);
|
| 49 |
+
}
|
| 50 |
+
#endif
|
| 51 |
+
|
| 52 |
+
return true;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
void ConsoleReporter::PrintHeader(const Run& run) {
|
| 56 |
+
std::string str = FormatString("%-*s %13s %15s %12s", static_cast<int>(name_field_width_),
|
| 57 |
+
"Benchmark", "Time", "CPU", "Iterations");
|
| 58 |
+
if(!run.counters.empty()) {
|
| 59 |
+
if(output_options_ & OO_Tabular) {
|
| 60 |
+
for(auto const& c : run.counters) {
|
| 61 |
+
str += FormatString(" %10s", c.first.c_str());
|
| 62 |
+
}
|
| 63 |
+
} else {
|
| 64 |
+
str += " UserCounters...";
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
std::string line = std::string(str.length(), '-');
|
| 68 |
+
GetOutputStream() << line << "\n" << str << "\n" << line << "\n";
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
void ConsoleReporter::ReportRuns(const std::vector<Run>& reports) {
|
| 72 |
+
for (const auto& run : reports) {
|
| 73 |
+
// print the header:
|
| 74 |
+
// --- if none was printed yet
|
| 75 |
+
bool print_header = !printed_header_;
|
| 76 |
+
// --- or if the format is tabular and this run
|
| 77 |
+
// has different fields from the prev header
|
| 78 |
+
print_header |= (output_options_ & OO_Tabular) &&
|
| 79 |
+
(!internal::SameNames(run.counters, prev_counters_));
|
| 80 |
+
if (print_header) {
|
| 81 |
+
printed_header_ = true;
|
| 82 |
+
prev_counters_ = run.counters;
|
| 83 |
+
PrintHeader(run);
|
| 84 |
+
}
|
| 85 |
+
// As an alternative to printing the headers like this, we could sort
|
| 86 |
+
// the benchmarks by header and then print. But this would require
|
| 87 |
+
// waiting for the full results before printing, or printing twice.
|
| 88 |
+
PrintRunData(run);
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
static void IgnoreColorPrint(std::ostream& out, LogColor, const char* fmt,
|
| 93 |
+
...) {
|
| 94 |
+
va_list args;
|
| 95 |
+
va_start(args, fmt);
|
| 96 |
+
out << FormatString(fmt, args);
|
| 97 |
+
va_end(args);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
static std::string FormatTime(double time) {
|
| 102 |
+
// Align decimal places...
|
| 103 |
+
if (time < 1.0) {
|
| 104 |
+
return FormatString("%10.3f", time);
|
| 105 |
+
}
|
| 106 |
+
if (time < 10.0) {
|
| 107 |
+
return FormatString("%10.2f", time);
|
| 108 |
+
}
|
| 109 |
+
if (time < 100.0) {
|
| 110 |
+
return FormatString("%10.1f", time);
|
| 111 |
+
}
|
| 112 |
+
return FormatString("%10.0f", time);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
void ConsoleReporter::PrintRunData(const Run& result) {
|
| 116 |
+
typedef void(PrinterFn)(std::ostream&, LogColor, const char*, ...);
|
| 117 |
+
auto& Out = GetOutputStream();
|
| 118 |
+
PrinterFn* printer = (output_options_ & OO_Color) ?
|
| 119 |
+
(PrinterFn*)ColorPrintf : IgnoreColorPrint;
|
| 120 |
+
auto name_color =
|
| 121 |
+
(result.report_big_o || result.report_rms) ? COLOR_BLUE : COLOR_GREEN;
|
| 122 |
+
printer(Out, name_color, "%-*s ", name_field_width_,
|
| 123 |
+
result.benchmark_name().c_str());
|
| 124 |
+
|
| 125 |
+
if (result.error_occurred) {
|
| 126 |
+
printer(Out, COLOR_RED, "ERROR OCCURRED: \'%s\'",
|
| 127 |
+
result.error_message.c_str());
|
| 128 |
+
printer(Out, COLOR_DEFAULT, "\n");
|
| 129 |
+
return;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
const double real_time = result.GetAdjustedRealTime();
|
| 133 |
+
const double cpu_time = result.GetAdjustedCPUTime();
|
| 134 |
+
const std::string real_time_str = FormatTime(real_time);
|
| 135 |
+
const std::string cpu_time_str = FormatTime(cpu_time);
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
if (result.report_big_o) {
|
| 139 |
+
std::string big_o = GetBigOString(result.complexity);
|
| 140 |
+
printer(Out, COLOR_YELLOW, "%10.2f %-4s %10.2f %-4s ", real_time, big_o.c_str(),
|
| 141 |
+
cpu_time, big_o.c_str());
|
| 142 |
+
} else if (result.report_rms) {
|
| 143 |
+
printer(Out, COLOR_YELLOW, "%10.0f %-4s %10.0f %-4s ", real_time * 100, "%",
|
| 144 |
+
cpu_time * 100, "%");
|
| 145 |
+
} else if (result.run_type != Run::RT_Aggregate ||
|
| 146 |
+
result.aggregate_unit == StatisticUnit::kTime) {
|
| 147 |
+
const char* timeLabel = GetTimeUnitString(result.time_unit);
|
| 148 |
+
printer(Out, COLOR_YELLOW, "%s %-4s %s %-4s ", real_time_str.c_str(), timeLabel,
|
| 149 |
+
cpu_time_str.c_str(), timeLabel);
|
| 150 |
+
} else {
|
| 151 |
+
assert(result.aggregate_unit == StatisticUnit::kPercentage);
|
| 152 |
+
printer(Out, COLOR_YELLOW, "%10.2f %-4s %10.2f %-4s ",
|
| 153 |
+
(100. * result.real_accumulated_time), "%",
|
| 154 |
+
(100. * result.cpu_accumulated_time), "%");
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
if (!result.report_big_o && !result.report_rms) {
|
| 158 |
+
printer(Out, COLOR_CYAN, "%10lld", result.iterations);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
for (auto& c : result.counters) {
|
| 162 |
+
const std::size_t cNameLen = std::max(std::string::size_type(10),
|
| 163 |
+
c.first.length());
|
| 164 |
+
std::string s;
|
| 165 |
+
const char* unit = "";
|
| 166 |
+
if (result.run_type == Run::RT_Aggregate &&
|
| 167 |
+
result.aggregate_unit == StatisticUnit::kPercentage) {
|
| 168 |
+
s = StrFormat("%.2f", 100. * c.second.value);
|
| 169 |
+
unit = "%";
|
| 170 |
+
} else {
|
| 171 |
+
s = HumanReadableNumber(c.second.value, c.second.oneK);
|
| 172 |
+
if (c.second.flags & Counter::kIsRate)
|
| 173 |
+
unit = (c.second.flags & Counter::kInvert) ? "s" : "/s";
|
| 174 |
+
}
|
| 175 |
+
if (output_options_ & OO_Tabular) {
|
| 176 |
+
printer(Out, COLOR_DEFAULT, " %*s%s", cNameLen - strlen(unit), s.c_str(),
|
| 177 |
+
unit);
|
| 178 |
+
} else {
|
| 179 |
+
printer(Out, COLOR_DEFAULT, " %s=%s%s", c.first.c_str(), s.c_str(), unit);
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
if (!result.report_label.empty()) {
|
| 184 |
+
printer(Out, COLOR_DEFAULT, " %s", result.report_label.c_str());
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
printer(Out, COLOR_DEFAULT, "\n");
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
} // end namespace benchmark
|
pool/shard008/C++/0096676_mock_media_stream_video_source.cc
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "third_party/blink/renderer/modules/mediastream/mock_media_stream_video_source.h"
|
| 6 |
+
|
| 7 |
+
#include "base/bind.h"
|
| 8 |
+
#include "base/location.h"
|
| 9 |
+
#include "base/task/single_thread_task_runner.h"
|
| 10 |
+
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
|
| 11 |
+
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
|
| 12 |
+
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
|
| 13 |
+
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
|
| 14 |
+
|
| 15 |
+
namespace blink {
|
| 16 |
+
|
| 17 |
+
MockMediaStreamVideoSource::MockMediaStreamVideoSource()
|
| 18 |
+
: MockMediaStreamVideoSource(false) {}
|
| 19 |
+
|
| 20 |
+
MockMediaStreamVideoSource::MockMediaStreamVideoSource(
|
| 21 |
+
bool respond_to_request_refresh_frame)
|
| 22 |
+
: MediaStreamVideoSource(scheduler::GetSingleThreadTaskRunnerForTesting()),
|
| 23 |
+
respond_to_request_refresh_frame_(respond_to_request_refresh_frame),
|
| 24 |
+
max_requested_height_(0),
|
| 25 |
+
max_requested_width_(0),
|
| 26 |
+
max_requested_frame_rate_(0.0),
|
| 27 |
+
attempted_to_start_(false) {}
|
| 28 |
+
|
| 29 |
+
MockMediaStreamVideoSource::MockMediaStreamVideoSource(
|
| 30 |
+
const media::VideoCaptureFormat& format,
|
| 31 |
+
bool respond_to_request_refresh_frame)
|
| 32 |
+
: MediaStreamVideoSource(scheduler::GetSingleThreadTaskRunnerForTesting()),
|
| 33 |
+
format_(format),
|
| 34 |
+
respond_to_request_refresh_frame_(respond_to_request_refresh_frame),
|
| 35 |
+
max_requested_height_(format.frame_size.height()),
|
| 36 |
+
max_requested_width_(format.frame_size.width()),
|
| 37 |
+
max_requested_frame_rate_(format.frame_rate),
|
| 38 |
+
attempted_to_start_(false) {}
|
| 39 |
+
|
| 40 |
+
MockMediaStreamVideoSource::~MockMediaStreamVideoSource() {}
|
| 41 |
+
|
| 42 |
+
void MockMediaStreamVideoSource::StartMockedSource() {
|
| 43 |
+
DCHECK(attempted_to_start_);
|
| 44 |
+
attempted_to_start_ = false;
|
| 45 |
+
OnStartDone(mojom::blink::MediaStreamRequestResult::OK);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void MockMediaStreamVideoSource::FailToStartMockedSource() {
|
| 49 |
+
DCHECK(attempted_to_start_);
|
| 50 |
+
attempted_to_start_ = false;
|
| 51 |
+
OnStartDone(
|
| 52 |
+
mojom::blink::MediaStreamRequestResult::TRACK_START_FAILURE_VIDEO);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
void MockMediaStreamVideoSource::RequestRefreshFrame() {
|
| 56 |
+
DCHECK(!frame_callback_.is_null());
|
| 57 |
+
if (respond_to_request_refresh_frame_) {
|
| 58 |
+
const scoped_refptr<media::VideoFrame> frame =
|
| 59 |
+
media::VideoFrame::CreateColorFrame(format_.frame_size, 0, 0, 0,
|
| 60 |
+
base::TimeDelta());
|
| 61 |
+
PostCrossThreadTask(
|
| 62 |
+
*io_task_runner(), FROM_HERE,
|
| 63 |
+
CrossThreadBindOnce(frame_callback_, frame,
|
| 64 |
+
std::vector<scoped_refptr<media::VideoFrame>>(),
|
| 65 |
+
base::TimeTicks()));
|
| 66 |
+
}
|
| 67 |
+
OnRequestRefreshFrame();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void MockMediaStreamVideoSource::OnHasConsumers(bool has_consumers) {
|
| 71 |
+
is_suspended_ = !has_consumers;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
VideoCaptureFeedbackCB MockMediaStreamVideoSource::GetFeedbackCallback() const {
|
| 75 |
+
return WTF::BindRepeating(&MockMediaStreamVideoSource::OnFrameFeedback,
|
| 76 |
+
WTF::Unretained(this));
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
base::WeakPtr<MediaStreamVideoSource> MockMediaStreamVideoSource::GetWeakPtr()
|
| 80 |
+
const {
|
| 81 |
+
return weak_factory_.GetWeakPtr();
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
void MockMediaStreamVideoSource::DoChangeSource(
|
| 85 |
+
const MediaStreamDevice& new_device) {
|
| 86 |
+
ChangeSourceImpl(new_device);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void MockMediaStreamVideoSource::StartSourceImpl(
|
| 90 |
+
VideoCaptureDeliverFrameCB frame_callback,
|
| 91 |
+
EncodedVideoFrameCB encoded_frame_callback) {
|
| 92 |
+
DCHECK(frame_callback_.is_null());
|
| 93 |
+
DCHECK(encoded_frame_callback_.is_null());
|
| 94 |
+
attempted_to_start_ = true;
|
| 95 |
+
frame_callback_ = std::move(frame_callback);
|
| 96 |
+
encoded_frame_callback_ = std::move(encoded_frame_callback);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
void MockMediaStreamVideoSource::StopSourceImpl() {}
|
| 100 |
+
|
| 101 |
+
absl::optional<media::VideoCaptureFormat>
|
| 102 |
+
MockMediaStreamVideoSource::GetCurrentFormat() const {
|
| 103 |
+
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
| 104 |
+
return absl::optional<media::VideoCaptureFormat>(format_);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
absl::optional<media::VideoCaptureParams>
|
| 108 |
+
MockMediaStreamVideoSource::GetCurrentCaptureParams() const {
|
| 109 |
+
media::VideoCaptureParams params;
|
| 110 |
+
params.requested_format = format_;
|
| 111 |
+
return params;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
void MockMediaStreamVideoSource::DeliverVideoFrame(
|
| 115 |
+
scoped_refptr<media::VideoFrame> frame) {
|
| 116 |
+
DCHECK(!is_stopped_for_restart_);
|
| 117 |
+
DCHECK(!frame_callback_.is_null());
|
| 118 |
+
PostCrossThreadTask(
|
| 119 |
+
*io_task_runner(), FROM_HERE,
|
| 120 |
+
CrossThreadBindOnce(frame_callback_, std::move(frame),
|
| 121 |
+
std::vector<scoped_refptr<media::VideoFrame>>(),
|
| 122 |
+
base::TimeTicks()));
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
void MockMediaStreamVideoSource::DeliverEncodedVideoFrame(
|
| 126 |
+
scoped_refptr<EncodedVideoFrame> frame) {
|
| 127 |
+
DCHECK(!is_stopped_for_restart_);
|
| 128 |
+
DCHECK(!encoded_frame_callback_.is_null());
|
| 129 |
+
PostCrossThreadTask(*io_task_runner(), FROM_HERE,
|
| 130 |
+
CrossThreadBindOnce(encoded_frame_callback_,
|
| 131 |
+
std::move(frame), base::TimeTicks()));
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
void MockMediaStreamVideoSource::StopSourceForRestartImpl() {
|
| 135 |
+
if (can_stop_for_restart_)
|
| 136 |
+
is_stopped_for_restart_ = true;
|
| 137 |
+
OnStopForRestartDone(is_stopped_for_restart_);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
void MockMediaStreamVideoSource::RestartSourceImpl(
|
| 141 |
+
const media::VideoCaptureFormat& new_format) {
|
| 142 |
+
DCHECK(is_stopped_for_restart_);
|
| 143 |
+
if (!can_restart_) {
|
| 144 |
+
OnRestartDone(false);
|
| 145 |
+
return;
|
| 146 |
+
}
|
| 147 |
+
is_stopped_for_restart_ = false;
|
| 148 |
+
format_ = new_format;
|
| 149 |
+
OnRestartDone(true);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
} // namespace blink
|
pool/shard008/C++/0096679_exE.cpp
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <iostream>
|
| 2 |
+
#include <deque>
|
| 3 |
+
#include <string>
|
| 4 |
+
#include <vector>
|
| 5 |
+
#include <set>
|
| 6 |
+
#include <algorithm>
|
| 7 |
+
#include <cstdlib>
|
| 8 |
+
#include <stdio.h>
|
| 9 |
+
#include <cstring>
|
| 10 |
+
|
| 11 |
+
//tamanho maximo do numero analisado
|
| 12 |
+
#define MAX 2000000
|
| 13 |
+
|
| 14 |
+
using namespace std;
|
| 15 |
+
|
| 16 |
+
//fila como variavel global
|
| 17 |
+
deque<int> fila;
|
| 18 |
+
vector< deque<int> > resposta;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
void verifica(int ini, int aux){
|
| 22 |
+
|
| 23 |
+
//fazendo o for ate a quantidade maxima de vezes do mesmo i aparecer
|
| 24 |
+
for (int i = ini; i * i <= aux; i++){
|
| 25 |
+
if (aux%i == 0) {
|
| 26 |
+
fila.push_back(i);
|
| 27 |
+
verifica(i, aux/i);
|
| 28 |
+
fila.pop_back();
|
| 29 |
+
}
|
| 30 |
+
//caso nao seja divisivel, o for continua e vai para o proximo numero
|
| 31 |
+
}
|
| 32 |
+
//armazenar o ultimo antes de colocar no vector de fils
|
| 33 |
+
fila.push_back(aux);
|
| 34 |
+
resposta.push_back(fila);
|
| 35 |
+
fila.pop_back();
|
| 36 |
+
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
int main(int argc, char const *argv[]){
|
| 41 |
+
|
| 42 |
+
int num;
|
| 43 |
+
int aux;
|
| 44 |
+
int tam_total, tam_parcial;
|
| 45 |
+
int inicio_contagem;
|
| 46 |
+
|
| 47 |
+
//analisando caso por caso até o zero
|
| 48 |
+
while(cin >> num){
|
| 49 |
+
//parando quando achar o zero
|
| 50 |
+
if(num == 0){
|
| 51 |
+
break;
|
| 52 |
+
}
|
| 53 |
+
//antes de comecar zera a fila
|
| 54 |
+
fila.clear();
|
| 55 |
+
resposta.clear();
|
| 56 |
+
//anotando o valor em uma variavel reserva
|
| 57 |
+
aux = num;
|
| 58 |
+
inicio_contagem = 2;
|
| 59 |
+
|
| 60 |
+
//chama se tiver para fatorar
|
| 61 |
+
if(num < 2){
|
| 62 |
+
//nao faz nada pois nao tem como fatorar
|
| 63 |
+
cout << "0" << endl;
|
| 64 |
+
}else{
|
| 65 |
+
//chama a funcao recursiva
|
| 66 |
+
verifica(inicio_contagem, aux);
|
| 67 |
+
|
| 68 |
+
tam_total = resposta.size();
|
| 69 |
+
cout << tam_total - 1 << endl;
|
| 70 |
+
|
| 71 |
+
//imprimir os valores
|
| 72 |
+
for(int i = 0; i < tam_total - 1; i++){
|
| 73 |
+
//pegando o tamanho parcial
|
| 74 |
+
tam_parcial = resposta[i].size();
|
| 75 |
+
for(int j = 0; j < tam_parcial; j++){
|
| 76 |
+
//exibindo fila por fila salva no set
|
| 77 |
+
if(j > 0){
|
| 78 |
+
cout << " " << resposta[i][j];
|
| 79 |
+
}else{
|
| 80 |
+
cout << resposta[i][j];
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
//pula uma linha
|
| 84 |
+
cout << endl;
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
return 0;
|
| 93 |
+
}
|
pool/shard008/C++/0096680_A.cpp
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <bits/stdc++.h>
|
| 2 |
+
using namespace std;
|
| 3 |
+
|
| 4 |
+
typedef long long ll;
|
| 5 |
+
#define INF 0x3f3f3f3f3f3f3f3f
|
| 6 |
+
#define MOD 1000000007
|
| 7 |
+
#define rep(i,a,n) for (int i=a;i<n;i++)
|
| 8 |
+
#define per(i,a,n) for (int i=n-1;i>=a;i--)
|
| 9 |
+
#define pb push_back
|
| 10 |
+
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
|
| 11 |
+
const double pi = acos(-1.0);
|
| 12 |
+
|
| 13 |
+
// r x c
|
| 14 |
+
// rice
|
| 15 |
+
// k chicken <= rice
|
| 16 |
+
// same chicken 连通图
|
| 17 |
+
|
| 18 |
+
int t;
|
| 19 |
+
int r,c,k;
|
| 20 |
+
|
| 21 |
+
char farm[110][110];
|
| 22 |
+
int ans[110][110];
|
| 23 |
+
|
| 24 |
+
// min(max rice- min rice)
|
| 25 |
+
|
| 26 |
+
// 26*2+10 = 62
|
| 27 |
+
|
| 28 |
+
char s[]="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
int minr ;
|
| 32 |
+
int maxr ;
|
| 33 |
+
int maxcnt ;
|
| 34 |
+
int mincnt ;
|
| 35 |
+
int nowcnt ;
|
| 36 |
+
int nowidx ;
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
void addnowidx(){
|
| 40 |
+
if(nowidx+1 < k){
|
| 41 |
+
nowidx++;
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void op(int i,int j){
|
| 46 |
+
ans[i][j] = nowidx;
|
| 47 |
+
if(farm[i][j] !='R')return;
|
| 48 |
+
nowcnt++;
|
| 49 |
+
if(nowcnt <= minr*mincnt){
|
| 50 |
+
if(nowcnt % minr != 0){
|
| 51 |
+
return ;
|
| 52 |
+
}
|
| 53 |
+
addnowidx();
|
| 54 |
+
}else{
|
| 55 |
+
if((nowcnt-minr*mincnt) % maxr != 0){
|
| 56 |
+
return ;
|
| 57 |
+
}
|
| 58 |
+
addnowidx();
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
int main(){
|
| 63 |
+
cin>>t;
|
| 64 |
+
|
| 65 |
+
while(t--){
|
| 66 |
+
scanf("%d %d %d",&r,&c,&k);
|
| 67 |
+
int rice = 0;
|
| 68 |
+
rep(i,0,r){
|
| 69 |
+
scanf("%s",farm[i]);
|
| 70 |
+
rep(j,0,c){
|
| 71 |
+
rice+=farm[i][j] == 'R';
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
minr = rice/k; // >= 1
|
| 75 |
+
maxr = minr+ !!(rice%k);
|
| 76 |
+
maxcnt = rice%k;
|
| 77 |
+
mincnt = k-maxcnt;
|
| 78 |
+
assert(minr*mincnt+maxr*maxcnt == rice);
|
| 79 |
+
|
| 80 |
+
// printf("m m m m = %d %d %d %d\n",minr,mincnt,maxr,maxcnt);
|
| 81 |
+
nowcnt = 0;
|
| 82 |
+
nowidx = 0;
|
| 83 |
+
rep(i,0,r){
|
| 84 |
+
if(i %2 == 0){
|
| 85 |
+
rep(j,0,c){
|
| 86 |
+
op(i,j);
|
| 87 |
+
}
|
| 88 |
+
}else {
|
| 89 |
+
per(j,0,c){
|
| 90 |
+
op(i,j);
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
rep(i,0,r){
|
| 95 |
+
rep(j,0,c){
|
| 96 |
+
printf("%c",s[ans[i][j]]);
|
| 97 |
+
}
|
| 98 |
+
printf("\n");
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
return 0;
|
| 103 |
+
}
|
pool/shard008/C++/0096682_tst_qsysteminfo.cpp
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/****************************************************************************
|
| 2 |
+
**
|
| 3 |
+
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
| 4 |
+
** Contact: http://www.qt-project.org/legal
|
| 5 |
+
**
|
| 6 |
+
** This file is part of the Qt Mobility Components.
|
| 7 |
+
**
|
| 8 |
+
** $QT_BEGIN_LICENSE:LGPL$
|
| 9 |
+
** Commercial License Usage
|
| 10 |
+
** Licensees holding valid commercial Qt licenses may use this file in
|
| 11 |
+
** accordance with the commercial license agreement provided with the
|
| 12 |
+
** Software or, alternatively, in accordance with the terms contained in
|
| 13 |
+
** a written agreement between you and Digia. For licensing terms and
|
| 14 |
+
** conditions see http://qt.digia.com/licensing. For further information
|
| 15 |
+
** use the contact form at http://qt.digia.com/contact-us.
|
| 16 |
+
**
|
| 17 |
+
** GNU Lesser General Public License Usage
|
| 18 |
+
** Alternatively, this file may be used under the terms of the GNU Lesser
|
| 19 |
+
** General Public License version 2.1 as published by the Free Software
|
| 20 |
+
** Foundation and appearing in the file LICENSE.LGPL included in the
|
| 21 |
+
** packaging of this file. Please review the following information to
|
| 22 |
+
** ensure the GNU Lesser General Public License version 2.1 requirements
|
| 23 |
+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
| 24 |
+
**
|
| 25 |
+
** In addition, as a special exception, Digia gives you certain additional
|
| 26 |
+
** rights. These rights are described in the Digia Qt LGPL Exception
|
| 27 |
+
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
| 28 |
+
**
|
| 29 |
+
** GNU General Public License Usage
|
| 30 |
+
** Alternatively, this file may be used under the terms of the GNU
|
| 31 |
+
** General Public License version 3.0 as published by the Free Software
|
| 32 |
+
** Foundation and appearing in the file LICENSE.GPL included in the
|
| 33 |
+
** packaging of this file. Please review the following information to
|
| 34 |
+
** ensure the GNU General Public License version 3.0 requirements will be
|
| 35 |
+
** met: http://www.gnu.org/copyleft/gpl.html.
|
| 36 |
+
**
|
| 37 |
+
**
|
| 38 |
+
** $QT_END_LICENSE$
|
| 39 |
+
**
|
| 40 |
+
****************************************************************************/
|
| 41 |
+
|
| 42 |
+
//TESTED_COMPONENT=src/systeminfo
|
| 43 |
+
|
| 44 |
+
#include <QtTest/QtTest>
|
| 45 |
+
#include "qsysteminfo.h"
|
| 46 |
+
#include "qsysteminfo_simulator_p.h"
|
| 47 |
+
#include <QDebug>
|
| 48 |
+
|
| 49 |
+
QTM_USE_NAMESPACE
|
| 50 |
+
Q_DECLARE_METATYPE(QSystemInfo::Version);
|
| 51 |
+
Q_DECLARE_METATYPE(QSystemInfo::Feature);
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Starts an event loop that runs until the given signal is received.
|
| 55 |
+
* Optionally the event loop can return earlier on a timeout.
|
| 56 |
+
*
|
| 57 |
+
* \return \p true if the requested signal was received
|
| 58 |
+
* \p false on timeout
|
| 59 |
+
*/
|
| 60 |
+
#ifdef TESTR
|
| 61 |
+
|
| 62 |
+
static bool waitForSignal(QObject *obj, const char *signal, int timeout = 0)
|
| 63 |
+
{
|
| 64 |
+
QEventLoop loop;
|
| 65 |
+
QObject::connect(obj, signal, &loop, SLOT(quit()));
|
| 66 |
+
QTimer timer;
|
| 67 |
+
QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
|
| 68 |
+
if (timeout > 0) {
|
| 69 |
+
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
| 70 |
+
timer.setSingleShot(true);
|
| 71 |
+
timer.start(timeout);
|
| 72 |
+
}
|
| 73 |
+
loop.exec();
|
| 74 |
+
return timeoutSpy.isEmpty();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
//static void setLanguage(const QString & lang)
|
| 78 |
+
//{
|
| 79 |
+
// QSystemInfoPrivate *s = getSystemInfoPrivate();
|
| 80 |
+
// s->setCurrentLanguage(lang);
|
| 81 |
+
//}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class ChangeLanguageThread : public QThread
|
| 85 |
+
{
|
| 86 |
+
public:
|
| 87 |
+
void run()
|
| 88 |
+
{
|
| 89 |
+
SystemInfoConnection si;
|
| 90 |
+
QSystemInfoPrivate *d = si.systeminfoPrivate();
|
| 91 |
+
d->setCurrentLanguage(lang);
|
| 92 |
+
|
| 93 |
+
}
|
| 94 |
+
QString lang;
|
| 95 |
+
};
|
| 96 |
+
#endif
|
| 97 |
+
|
| 98 |
+
class tst_QSystemInfo : public QObject
|
| 99 |
+
{
|
| 100 |
+
Q_OBJECT
|
| 101 |
+
|
| 102 |
+
public:
|
| 103 |
+
tst_QSystemInfo();
|
| 104 |
+
virtual ~tst_QSystemInfo();
|
| 105 |
+
|
| 106 |
+
friend class QSystemInfo;
|
| 107 |
+
|
| 108 |
+
private slots:
|
| 109 |
+
void initTestCase();
|
| 110 |
+
|
| 111 |
+
void tst_currentLanguage();
|
| 112 |
+
void tst_availableLanguages();
|
| 113 |
+
|
| 114 |
+
void tst_versions_data();
|
| 115 |
+
void tst_versions();
|
| 116 |
+
|
| 117 |
+
void tst_countryCode();
|
| 118 |
+
|
| 119 |
+
void tst_hasFeatures_data();
|
| 120 |
+
void tst_hasFeatures();
|
| 121 |
+
|
| 122 |
+
void tst_detailFeatures_data();
|
| 123 |
+
void tst_detailFeatures();
|
| 124 |
+
#ifdef TESTR
|
| 125 |
+
void currentLanguageChanged();
|
| 126 |
+
|
| 127 |
+
void slotCurrentLanguageChanged(const QString &);
|
| 128 |
+
#endif
|
| 129 |
+
private:
|
| 130 |
+
#ifdef TESTR
|
| 131 |
+
ChangeLanguageThread *changeLangThread;
|
| 132 |
+
#endif
|
| 133 |
+
};
|
| 134 |
+
|
| 135 |
+
tst_QSystemInfo::tst_QSystemInfo()
|
| 136 |
+
{
|
| 137 |
+
#ifdef TESTR
|
| 138 |
+
changeLangThread = new ChangeLanguageThread();
|
| 139 |
+
#endif
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
tst_QSystemInfo::~tst_QSystemInfo()
|
| 143 |
+
{
|
| 144 |
+
#ifdef TESTR
|
| 145 |
+
delete changeLangThread, changeLangThread = 0;
|
| 146 |
+
#endif
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
void tst_QSystemInfo::initTestCase()
|
| 150 |
+
{
|
| 151 |
+
qRegisterMetaType<QSystemInfo::Version>("QSystemInfo::Version");
|
| 152 |
+
qRegisterMetaType<QSystemInfo::Feature>("QSystemInfo::Feature");
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
void tst_QSystemInfo::tst_currentLanguage()
|
| 156 |
+
{
|
| 157 |
+
QSystemInfo si;
|
| 158 |
+
#ifdef TESTR
|
| 159 |
+
SystemInfoConnection sic;
|
| 160 |
+
QSystemInfoPrivate *d = sic.systeminfoPrivate();
|
| 161 |
+
d->setInitialData();
|
| 162 |
+
#endif
|
| 163 |
+
QVERIFY(!si.currentLanguage().isEmpty());
|
| 164 |
+
QCOMPARE(si.currentLanguage().length(), 2);
|
| 165 |
+
QVERIFY(si.currentLanguage() == si.currentLanguage().toLower());
|
| 166 |
+
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
void tst_QSystemInfo::tst_availableLanguages()
|
| 170 |
+
{
|
| 171 |
+
QSystemInfo si;
|
| 172 |
+
#ifdef TESTR
|
| 173 |
+
SystemInfoConnection sic;
|
| 174 |
+
QSystemInfoPrivate *d = sic.systeminfoPrivate();
|
| 175 |
+
d->setInitialData();
|
| 176 |
+
#endif
|
| 177 |
+
QVERIFY(!si.availableLanguages().isEmpty());
|
| 178 |
+
QStringList available = si.availableLanguages();
|
| 179 |
+
foreach(QString lang, available) {
|
| 180 |
+
QCOMPARE(lang.length(), 2);
|
| 181 |
+
QVERIFY(lang == lang.toLower());
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
void tst_QSystemInfo::tst_versions_data()
|
| 186 |
+
{
|
| 187 |
+
QTest::addColumn<QSystemInfo::Version>("version");
|
| 188 |
+
QTest::addColumn<QString>("parameter");
|
| 189 |
+
|
| 190 |
+
QTest::newRow("Os") << QSystemInfo::Os << "";
|
| 191 |
+
QTest::newRow("QtCore") << QSystemInfo::QtCore << "";
|
| 192 |
+
QTest::newRow("Firmware") << QSystemInfo::Firmware << "";
|
| 193 |
+
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
void tst_QSystemInfo::tst_versions()
|
| 197 |
+
{
|
| 198 |
+
{
|
| 199 |
+
QFETCH(QSystemInfo::Version, version);
|
| 200 |
+
QFETCH(QString, parameter);
|
| 201 |
+
QSystemInfo si;
|
| 202 |
+
#ifdef TESTR
|
| 203 |
+
SystemInfoConnection sic;
|
| 204 |
+
QSystemInfoPrivate *d = sic.systeminfoPrivate();
|
| 205 |
+
d->setInitialData();
|
| 206 |
+
#endif
|
| 207 |
+
QString vers = si.version(version, parameter);
|
| 208 |
+
QVERIFY(!vers.isEmpty()
|
| 209 |
+
|| vers.isEmpty());
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
void tst_QSystemInfo::tst_countryCode()
|
| 214 |
+
{
|
| 215 |
+
QSystemInfo si;
|
| 216 |
+
#ifdef TESTR
|
| 217 |
+
SystemInfoConnection sic;
|
| 218 |
+
QSystemInfoPrivate *d = sic.systeminfoPrivate();
|
| 219 |
+
d->setInitialData();
|
| 220 |
+
#endif
|
| 221 |
+
QVERIFY(!si.currentCountryCode().isEmpty());
|
| 222 |
+
QCOMPARE(si.currentCountryCode().length(),2);
|
| 223 |
+
QVERIFY(si.currentCountryCode() == si.currentCountryCode().toUpper());
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
void tst_QSystemInfo::tst_hasFeatures_data()
|
| 227 |
+
{
|
| 228 |
+
QTest::addColumn<QSystemInfo::Feature>("feature");
|
| 229 |
+
|
| 230 |
+
QTest::newRow("Bluetooth") << QSystemInfo::BluetoothFeature;
|
| 231 |
+
QTest::newRow("CameraFeature") << QSystemInfo::CameraFeature;
|
| 232 |
+
QTest::newRow("FmradioFeature") << QSystemInfo::FmradioFeature;
|
| 233 |
+
QTest::newRow("IrFeature") << QSystemInfo::IrFeature;
|
| 234 |
+
QTest::newRow("LedFeature") << QSystemInfo::LedFeature;
|
| 235 |
+
QTest::newRow("MemcardFeature") << QSystemInfo::MemcardFeature;
|
| 236 |
+
QTest::newRow("UsbFeature") << QSystemInfo::UsbFeature;
|
| 237 |
+
QTest::newRow("VibFeature") << QSystemInfo::VibFeature;
|
| 238 |
+
QTest::newRow("WlanFeature") << QSystemInfo::WlanFeature;
|
| 239 |
+
QTest::newRow("SimFeature") << QSystemInfo::SimFeature;
|
| 240 |
+
QTest::newRow("LocationFeature") << QSystemInfo::LocationFeature;
|
| 241 |
+
QTest::newRow("VideoOutFeature") << QSystemInfo::VideoOutFeature;
|
| 242 |
+
QTest::newRow("HapticsFeature") << QSystemInfo::HapticsFeature;
|
| 243 |
+
QTest::newRow("FmTransmitterFeature") << QSystemInfo::FmTransmitterFeature;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
void tst_QSystemInfo::tst_hasFeatures()
|
| 247 |
+
{
|
| 248 |
+
{
|
| 249 |
+
QFETCH(QSystemInfo::Feature, feature);
|
| 250 |
+
QSystemInfo si;
|
| 251 |
+
#ifdef TESTR
|
| 252 |
+
SystemInfoConnection sic;
|
| 253 |
+
QSystemInfoPrivate *d = sic.systeminfoPrivate();
|
| 254 |
+
d->setInitialData();
|
| 255 |
+
#endif
|
| 256 |
+
QVERIFY(si.hasFeatureSupported(feature) == false
|
| 257 |
+
|| si.hasFeatureSupported(feature) == true);
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
void tst_QSystemInfo::tst_detailFeatures_data()
|
| 262 |
+
{
|
| 263 |
+
tst_hasFeatures_data();
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
void tst_QSystemInfo::tst_detailFeatures()
|
| 267 |
+
{
|
| 268 |
+
// {
|
| 269 |
+
// QFETCH(QSystemInfo::Feature, feature);
|
| 270 |
+
// QSystemInfo si;
|
| 271 |
+
// QVERIFY(!si.getDetailOfFeature(feature).isEmpty());
|
| 272 |
+
// }
|
| 273 |
+
}
|
| 274 |
+
#ifdef TESTR
|
| 275 |
+
|
| 276 |
+
void tst_QSystemInfo::currentLanguageChanged()
|
| 277 |
+
{
|
| 278 |
+
QSystemInfo si;
|
| 279 |
+
connect(&si,SIGNAL(currentLanguageChanged(const QString &)),this,
|
| 280 |
+
SLOT(slotCurrentLanguageChanged(const QString &)));
|
| 281 |
+
|
| 282 |
+
changeLangThread->lang = "kl";
|
| 283 |
+
changeLangThread->start();
|
| 284 |
+
QSignalSpy errorSpy(&si, SIGNAL(currentLanguageChanged(const QString &)));
|
| 285 |
+
QVERIFY(::waitForSignal(&si, SIGNAL(currentLanguageChanged(const QString &)), 10 * 1000));
|
| 286 |
+
QVERIFY(errorSpy.count() == 1);
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
void tst_QSystemInfo::slotCurrentLanguageChanged(const QString &lang)
|
| 290 |
+
{
|
| 291 |
+
QVERIFY(lang == "kl");
|
| 292 |
+
}
|
| 293 |
+
#endif
|
| 294 |
+
|
| 295 |
+
QTEST_MAIN(tst_QSystemInfo)
|
| 296 |
+
#include "tst_qsysteminfo.moc"
|
| 297 |
+
|
pool/shard008/C++/0096684_OpenCLGpuRegistry.cpp
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* UGENE - Integrated Bioinformatics Tools.
|
| 3 |
+
* Copyright (C) 2008-2022 UniPro <ugene@unipro.ru>
|
| 4 |
+
* http://ugene.net
|
| 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, Boston,
|
| 19 |
+
* MA 02110-1301, USA.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#ifdef OPENCL_SUPPORT
|
| 23 |
+
|
| 24 |
+
# include <algorithm>
|
| 25 |
+
# include <functional>
|
| 26 |
+
|
| 27 |
+
# include <U2Core/AppContext.h>
|
| 28 |
+
# include <U2Core/Settings.h>
|
| 29 |
+
# include <U2Core/U2SafePoints.h>
|
| 30 |
+
|
| 31 |
+
# include "OpenCLGpuRegistry.h"
|
| 32 |
+
|
| 33 |
+
namespace U2 {
|
| 34 |
+
|
| 35 |
+
OpenCLGpuRegistry::OpenCLGpuRegistry()
|
| 36 |
+
: openCLHelper(nullptr) {
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
OpenCLGpuRegistry::~OpenCLGpuRegistry() {
|
| 40 |
+
qDeleteAll(gpus.values());
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
void OpenCLGpuRegistry::registerOpenCLGpu(OpenCLGpuModel* gpu) {
|
| 44 |
+
assert(!gpus.contains(gpu->getId()));
|
| 45 |
+
gpus.insert(gpu->getId(), gpu);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void OpenCLGpuRegistry::unregisterOpenCLGpu(OpenCLGpuModel* gpu) {
|
| 49 |
+
CHECK(gpus.contains(gpu->getId()), );
|
| 50 |
+
delete gpus.take(gpu->getId());
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
OpenCLGpuModel* OpenCLGpuRegistry::getGpuById(cl_device_id id) const {
|
| 54 |
+
return gpus.value(id, 0);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
OpenCLGpuModel* OpenCLGpuRegistry::getGpuByName(const QString& name) const {
|
| 58 |
+
OpenCLGpuModel* gpu = nullptr;
|
| 59 |
+
foreach (OpenCLGpuModel* m, gpus.values()) {
|
| 60 |
+
CHECK_CONTINUE(m->getName() == name);
|
| 61 |
+
|
| 62 |
+
gpu = m;
|
| 63 |
+
break;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return gpu;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
QList<OpenCLGpuModel*> OpenCLGpuRegistry::getRegisteredGpus() const {
|
| 70 |
+
return gpus.values();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
OpenCLGpuModel* OpenCLGpuRegistry::getEnabledGpu() const {
|
| 74 |
+
QList<OpenCLGpuModel*> registeredGpus = getRegisteredGpus();
|
| 75 |
+
|
| 76 |
+
OpenCLGpuModel* enabledGpu = nullptr;
|
| 77 |
+
foreach (OpenCLGpuModel* m, registeredGpus) {
|
| 78 |
+
if (m && m->isEnabled()) {
|
| 79 |
+
enabledGpu = m;
|
| 80 |
+
break;
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
return enabledGpu;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
QString OpenCLGpuRegistry::getEnabledGpuName() const {
|
| 88 |
+
OpenCLGpuModel* enabledGpu = getEnabledGpu();
|
| 89 |
+
CHECK(nullptr != enabledGpu, QString());
|
| 90 |
+
|
| 91 |
+
return enabledGpu->getName();
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
OpenCLGpuModel* OpenCLGpuRegistry::acquireEnabledGpuIfReady() {
|
| 95 |
+
OpenCLGpuModel* model = nullptr;
|
| 96 |
+
foreach (OpenCLGpuModel* gpuModel, gpus.values()) {
|
| 97 |
+
CHECK_CONTINUE(gpuModel->isEnabled());
|
| 98 |
+
CHECK_BREAK(gpuModel->isReady());
|
| 99 |
+
|
| 100 |
+
gpuModel->setAcquired(true);
|
| 101 |
+
model = gpuModel;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
return model;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
void OpenCLGpuRegistry::saveGpusSettings() const {
|
| 108 |
+
Settings* s = AppContext::getSettings();
|
| 109 |
+
foreach (OpenCLGpuModel* m, gpus) {
|
| 110 |
+
CHECK_CONTINUE(m->isEnabled());
|
| 111 |
+
|
| 112 |
+
s->setValue(OPENCL_GPU_REGISTRY_SETTINGS_GPU_ENABLED, QVariant(m->getName()));
|
| 113 |
+
break;
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
} // namespace U2
|
| 118 |
+
|
| 119 |
+
#endif /*OPENCL_SUPPORT*/
|
pool/shard008/C++/0096686_remote_command_job.cc
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "components/policy/core/common/remote_commands/remote_command_job.h"
|
| 6 |
+
|
| 7 |
+
#include <utility>
|
| 8 |
+
|
| 9 |
+
#include "base/bind.h"
|
| 10 |
+
#include "base/syslog_logging.h"
|
| 11 |
+
|
| 12 |
+
namespace policy {
|
| 13 |
+
|
| 14 |
+
namespace {
|
| 15 |
+
|
| 16 |
+
constexpr base::TimeDelta kDefaultCommandTimeout = base::Minutes(10);
|
| 17 |
+
constexpr base::TimeDelta kDefaultCommandExpirationTime = base::Minutes(10);
|
| 18 |
+
|
| 19 |
+
} // namespace
|
| 20 |
+
|
| 21 |
+
RemoteCommandJob::~RemoteCommandJob() {
|
| 22 |
+
DCHECK(thread_checker_.CalledOnValidThread());
|
| 23 |
+
if (status_ == RUNNING)
|
| 24 |
+
Terminate();
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
bool RemoteCommandJob::Init(
|
| 28 |
+
base::TimeTicks now,
|
| 29 |
+
const enterprise_management::RemoteCommand& command,
|
| 30 |
+
const enterprise_management::SignedData* signed_command) {
|
| 31 |
+
DCHECK(thread_checker_.CalledOnValidThread());
|
| 32 |
+
DCHECK_EQ(NOT_INITIALIZED, status_);
|
| 33 |
+
|
| 34 |
+
status_ = INVALID;
|
| 35 |
+
|
| 36 |
+
if (!command.has_type() || !command.has_command_id())
|
| 37 |
+
return false;
|
| 38 |
+
DCHECK_EQ(command.type(), GetType());
|
| 39 |
+
|
| 40 |
+
unique_id_ = command.command_id();
|
| 41 |
+
if (signed_command)
|
| 42 |
+
signed_command_ = *signed_command;
|
| 43 |
+
|
| 44 |
+
if (command.has_age_of_command()) {
|
| 45 |
+
// Use age of command provided by server to estimate the command issued time
|
| 46 |
+
// as a local TimeTick. We need to store issued time instead of age of
|
| 47 |
+
// command, since the execution time of command might be different from the
|
| 48 |
+
// time we got it from server.
|
| 49 |
+
// It's just an estimation since we lost the time the response was
|
| 50 |
+
// transmitted over the network.
|
| 51 |
+
issued_time_ = now - base::Milliseconds(command.age_of_command());
|
| 52 |
+
} else {
|
| 53 |
+
SYSLOG(WARNING) << "No age_of_command provided by server for command "
|
| 54 |
+
<< unique_id_ << ".";
|
| 55 |
+
// Otherwise, assuming the command was issued just now.
|
| 56 |
+
issued_time_ = now;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (!ParseCommandPayload(command.payload())) {
|
| 60 |
+
SYSLOG(ERROR) << "Unable to parse command payload for type "
|
| 61 |
+
<< command.type() << ": " << command.payload();
|
| 62 |
+
return false;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
SYSLOG(INFO) << "Remote command type " << command.type() << " with id "
|
| 66 |
+
<< command.command_id() << " initialized.";
|
| 67 |
+
|
| 68 |
+
status_ = NOT_STARTED;
|
| 69 |
+
return true;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
bool RemoteCommandJob::Run(base::Time now,
|
| 73 |
+
base::TimeTicks now_ticks,
|
| 74 |
+
FinishedCallback finished_callback) {
|
| 75 |
+
DCHECK(thread_checker_.CalledOnValidThread());
|
| 76 |
+
|
| 77 |
+
if (status_ == INVALID) {
|
| 78 |
+
SYSLOG(ERROR) << "Remote command " << unique_id_ << " is invalid.";
|
| 79 |
+
return false;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
DCHECK_EQ(NOT_STARTED, status_);
|
| 83 |
+
|
| 84 |
+
if (IsExpired(now_ticks)) {
|
| 85 |
+
SYSLOG(ERROR) << "Remote command " << unique_id_
|
| 86 |
+
<< " expired (it was issued " << now_ticks - issued_time_
|
| 87 |
+
<< " ago).";
|
| 88 |
+
status_ = EXPIRED;
|
| 89 |
+
return false;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
execution_started_time_ = now;
|
| 93 |
+
status_ = RUNNING;
|
| 94 |
+
finished_callback_ = std::move(finished_callback);
|
| 95 |
+
|
| 96 |
+
RunImpl(
|
| 97 |
+
base::BindOnce(&RemoteCommandJob::OnCommandExecutionFinishedWithResult,
|
| 98 |
+
weak_factory_.GetWeakPtr(), true),
|
| 99 |
+
base::BindOnce(&RemoteCommandJob::OnCommandExecutionFinishedWithResult,
|
| 100 |
+
weak_factory_.GetWeakPtr(), false));
|
| 101 |
+
|
| 102 |
+
// The command is expected to run asynchronously.
|
| 103 |
+
DCHECK_EQ(RUNNING, status_);
|
| 104 |
+
|
| 105 |
+
return true;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
void RemoteCommandJob::Terminate() {
|
| 109 |
+
DCHECK(thread_checker_.CalledOnValidThread());
|
| 110 |
+
|
| 111 |
+
if (IsExecutionFinished())
|
| 112 |
+
return;
|
| 113 |
+
|
| 114 |
+
DCHECK_EQ(RUNNING, status_);
|
| 115 |
+
|
| 116 |
+
status_ = TERMINATED;
|
| 117 |
+
weak_factory_.InvalidateWeakPtrs();
|
| 118 |
+
|
| 119 |
+
TerminateImpl();
|
| 120 |
+
|
| 121 |
+
if (finished_callback_)
|
| 122 |
+
std::move(finished_callback_).Run();
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
base::TimeDelta RemoteCommandJob::GetCommandTimeout() const {
|
| 126 |
+
return kDefaultCommandTimeout;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
bool RemoteCommandJob::IsExecutionFinished() const {
|
| 130 |
+
return status_ == SUCCEEDED || status_ == FAILED || status_ == TERMINATED;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
std::unique_ptr<std::string> RemoteCommandJob::GetResultPayload() const {
|
| 134 |
+
DCHECK(thread_checker_.CalledOnValidThread());
|
| 135 |
+
DCHECK(status_ == SUCCEEDED || status_ == FAILED);
|
| 136 |
+
|
| 137 |
+
if (!result_payload_)
|
| 138 |
+
return nullptr;
|
| 139 |
+
|
| 140 |
+
return result_payload_->Serialize();
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
RemoteCommandJob::RemoteCommandJob() : status_(NOT_INITIALIZED) {}
|
| 144 |
+
|
| 145 |
+
bool RemoteCommandJob::ParseCommandPayload(const std::string& command_payload) {
|
| 146 |
+
return true;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
bool RemoteCommandJob::IsExpired(base::TimeTicks now) {
|
| 150 |
+
return now > issued_time() + kDefaultCommandExpirationTime;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
void RemoteCommandJob::TerminateImpl() {
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
void RemoteCommandJob::OnCommandExecutionFinishedWithResult(
|
| 157 |
+
bool succeeded,
|
| 158 |
+
std::unique_ptr<RemoteCommandJob::ResultPayload> result_payload) {
|
| 159 |
+
DCHECK(thread_checker_.CalledOnValidThread());
|
| 160 |
+
DCHECK_EQ(RUNNING, status_);
|
| 161 |
+
status_ = succeeded ? SUCCEEDED : FAILED;
|
| 162 |
+
|
| 163 |
+
result_payload_ = std::move(result_payload);
|
| 164 |
+
|
| 165 |
+
if (finished_callback_)
|
| 166 |
+
std::move(finished_callback_).Run();
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
} // namespace policy
|
pool/shard008/C++/0096687_stream_infra.cpp
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <glog/logging.h>
|
| 2 |
+
#include <streams/stream_infra.h>
|
| 3 |
+
#include <algorithm>
|
| 4 |
+
#include <iostream>
|
| 5 |
+
#include <util/util.h>
|
| 6 |
+
|
| 7 |
+
namespace {
|
| 8 |
+
|
| 9 |
+
streams_t join(const streams_t & left, const streams_t & right) {
|
| 10 |
+
|
| 11 |
+
streams_t stream;
|
| 12 |
+
|
| 13 |
+
stream.insert(stream.end(), left.begin(), left.end());
|
| 14 |
+
stream.insert(stream.end(), right.begin(), right.end());
|
| 15 |
+
|
| 16 |
+
return std::move(stream);
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
fwd_new_stream_fn_t forward(streams_t::iterator begin, streams_t::iterator end)
|
| 20 |
+
{
|
| 21 |
+
|
| 22 |
+
streams_t s;
|
| 23 |
+
std::copy(begin, end, back_inserter(s));
|
| 24 |
+
|
| 25 |
+
return [=]() mutable -> forward_fn_t
|
| 26 |
+
{
|
| 27 |
+
|
| 28 |
+
init_streams(s);
|
| 29 |
+
|
| 30 |
+
return [=](next_events_t events)
|
| 31 |
+
{
|
| 32 |
+
for (const auto & event : events) {
|
| 33 |
+
push_event(s, event);
|
| 34 |
+
}
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
streams_t create_stream(const on_event_fn_t fn) {
|
| 44 |
+
|
| 45 |
+
return {{[=](fwd_new_stream_fn_t){ return fn; }, fn}};
|
| 46 |
+
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
streams_t create_stream(const on_init_simple_fn_t fn) {
|
| 50 |
+
|
| 51 |
+
return {{[=](fwd_new_stream_fn_t){ return fn(); }, {}}};
|
| 52 |
+
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
streams_t create_stream(const on_init_fn_t fn) {
|
| 56 |
+
|
| 57 |
+
return {{fn, {}}};
|
| 58 |
+
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
void init_streams(streams_t & streams) {
|
| 64 |
+
|
| 65 |
+
for (size_t j = 0, i = streams.size() - 1; j < streams.size() ; i--, j++) {
|
| 66 |
+
|
| 67 |
+
auto & node = streams[i];
|
| 68 |
+
|
| 69 |
+
node.on_event = node.on_init(forward(streams.end() - j , streams.end()));
|
| 70 |
+
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
streams_t operator>>(const streams_t & left, const streams_t & right) {
|
| 76 |
+
return std::move(join(left, right));
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
next_events_t push_event(const streams_t & stream, const Event & event) {
|
| 80 |
+
|
| 81 |
+
next_events_t next_events;
|
| 82 |
+
|
| 83 |
+
for (const auto & node: stream) {
|
| 84 |
+
|
| 85 |
+
if (next_events.empty()) { // First iteration
|
| 86 |
+
|
| 87 |
+
next_events = node.on_event(event);
|
| 88 |
+
|
| 89 |
+
} else {
|
| 90 |
+
|
| 91 |
+
const auto aux_next_events(next_events);
|
| 92 |
+
next_events.clear();
|
| 93 |
+
|
| 94 |
+
for (const auto & e : aux_next_events) {
|
| 95 |
+
|
| 96 |
+
const auto res = node.on_event(e);
|
| 97 |
+
std::copy(begin(res), end(res), back_inserter(next_events));
|
| 98 |
+
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
if (next_events.empty()) {
|
| 104 |
+
return {};
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
return next_events;
|
| 110 |
+
}
|
pool/shard008/C++/0096690_jinvoker.cpp
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2006, 2011, Oracle and/or its affiliates. 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 |
+
*
|
| 8 |
+
* - Redistributions of source code must retain the above copyright
|
| 9 |
+
* notice, this list of conditions and the following disclaimer.
|
| 10 |
+
*
|
| 11 |
+
* - Redistributions in binary form must reproduce the above copyright
|
| 12 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 13 |
+
* documentation and/or other materials provided with the distribution.
|
| 14 |
+
*
|
| 15 |
+
* - Neither the name of Oracle nor the names of its
|
| 16 |
+
* contributors may be used to endorse or promote products derived
|
| 17 |
+
* from this software without specific prior written permission.
|
| 18 |
+
*
|
| 19 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
| 20 |
+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
| 21 |
+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 22 |
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
| 23 |
+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 24 |
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| 25 |
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 26 |
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 27 |
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 28 |
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 30 |
+
*/
|
| 31 |
+
|
| 32 |
+
/*
|
| 33 |
+
* This source code is provided to illustrate the usage of a given feature
|
| 34 |
+
* or technique and has been deliberately simplified. Additional steps
|
| 35 |
+
* required for a production-quality application, such as security checks,
|
| 36 |
+
* input validation and proper error handling, might not be present in
|
| 37 |
+
* this sample code.
|
| 38 |
+
*/
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
#include <memory.h>
|
| 42 |
+
#include <stdlib.h>
|
| 43 |
+
#include "jinvokerExp.h"
|
| 44 |
+
|
| 45 |
+
static int g_nExitCode = 0;
|
| 46 |
+
|
| 47 |
+
void system_exit(jint nCode){
|
| 48 |
+
g_nExitCode = nCode;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/*
|
| 52 |
+
Allocating and providing the JVM init argumets.
|
| 53 |
+
By MakeJavaVMInitArgs() it is provided two options: providing CLASSPATH
|
| 54 |
+
environment variable value and function java.lang.System.exit()
|
| 55 |
+
redefinition in order to get the exit code.
|
| 56 |
+
See the description of the JNI API in
|
| 57 |
+
http://jre.sfbay/java/re/jdk/6/promoted/latest/docs/technotes/guides/jni/spec/invocation.html#wp9502
|
| 58 |
+
*/
|
| 59 |
+
|
| 60 |
+
int MakeJavaVMInitArgs( void** ppArgs ){
|
| 61 |
+
|
| 62 |
+
int nOptSize = 2;
|
| 63 |
+
JavaVMInitArgs* pArgs = new JavaVMInitArgs();
|
| 64 |
+
JavaVMOption* pOptions = new JavaVMOption[nOptSize];
|
| 65 |
+
|
| 66 |
+
//provide CLASSPATH value to java.class.path
|
| 67 |
+
|
| 68 |
+
char* szClassPath = getenv("CLASSPATH");
|
| 69 |
+
if( szClassPath == NULL )
|
| 70 |
+
szClassPath = ".";
|
| 71 |
+
|
| 72 |
+
pOptions[0].optionString = new char[strlen("-Djava.class.path=")+
|
| 73 |
+
strlen(szClassPath)+1];
|
| 74 |
+
sprintf( pOptions[0].optionString, "-Djava.class.path=%s", szClassPath );
|
| 75 |
+
|
| 76 |
+
//redefine java.lang.System.exit()
|
| 77 |
+
|
| 78 |
+
pOptions[1].optionString = "exit";
|
| 79 |
+
pOptions[1].extraInfo = system_exit;
|
| 80 |
+
|
| 81 |
+
//Fill the arguments
|
| 82 |
+
|
| 83 |
+
memset(pArgs, 0, sizeof(JavaVMInitArgs));
|
| 84 |
+
pArgs->version = 0x00010002;
|
| 85 |
+
pArgs->options = pOptions;
|
| 86 |
+
pArgs->nOptions = nOptSize;
|
| 87 |
+
pArgs->ignoreUnrecognized = JNI_TRUE;
|
| 88 |
+
|
| 89 |
+
*ppArgs = pArgs;
|
| 90 |
+
|
| 91 |
+
return 0;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/*
|
| 95 |
+
Free the allocated JVM init argumets
|
| 96 |
+
*/
|
| 97 |
+
|
| 98 |
+
void FreeJavaVMInitArgs( void* pArgs ){
|
| 99 |
+
delete ((JavaVMInitArgs*)pArgs)->options[0].optionString;
|
| 100 |
+
delete ((JavaVMInitArgs*)pArgs)->options;
|
| 101 |
+
delete pArgs;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/*
|
| 105 |
+
Static wrapper on FindClass() JNI function.
|
| 106 |
+
See the description in
|
| 107 |
+
http://jre.sfbay/java/re/jdk/6/promoted/latest/docs/technotes/guides/jni/spec/functions.html#wp16027
|
| 108 |
+
*/
|
| 109 |
+
|
| 110 |
+
int FindClass( JNIEnv* pEnv,
|
| 111 |
+
const char* szClass,
|
| 112 |
+
jclass* pClass ){
|
| 113 |
+
|
| 114 |
+
*pClass = pEnv->FindClass( szClass );
|
| 115 |
+
|
| 116 |
+
if(pEnv->ExceptionCheck() == JNI_TRUE){
|
| 117 |
+
pEnv->ExceptionDescribe();
|
| 118 |
+
return -1;
|
| 119 |
+
}
|
| 120 |
+
if(*pClass != NULL)
|
| 121 |
+
return 0;
|
| 122 |
+
else
|
| 123 |
+
return -2;
|
| 124 |
+
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/*
|
| 128 |
+
Static wrapper on GetStaticMethodID() JNI function.
|
| 129 |
+
See the description in
|
| 130 |
+
http://jre.sfbay/java/re/jdk/6/promoted/latest/docs/technotes/guides/jni/spec/functions.html#wp20949
|
| 131 |
+
*/
|
| 132 |
+
|
| 133 |
+
int GetStaticMethodID(JNIEnv* pEnv,
|
| 134 |
+
jclass pClass,
|
| 135 |
+
const char* szName,
|
| 136 |
+
const char* szArgs,
|
| 137 |
+
jmethodID* pMid){
|
| 138 |
+
|
| 139 |
+
*pMid = pEnv->GetStaticMethodID( pClass, szName, szArgs);
|
| 140 |
+
|
| 141 |
+
if(pEnv->ExceptionCheck() == JNI_TRUE){
|
| 142 |
+
pEnv->ExceptionDescribe();
|
| 143 |
+
return -1;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
if( *pMid != NULL )
|
| 147 |
+
return 0;
|
| 148 |
+
else
|
| 149 |
+
return -2;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/*
|
| 153 |
+
Static wrapper on NewObjectArray() JNI function.
|
| 154 |
+
See the description in
|
| 155 |
+
http://jre.sfbay/java/re/jdk/6/promoted/latest/docs/technotes/guides/jni/spec/functions.html#wp21619
|
| 156 |
+
*/
|
| 157 |
+
|
| 158 |
+
int NewObjectArray( JNIEnv* pEnv,
|
| 159 |
+
int nDimension,
|
| 160 |
+
const char* szType,
|
| 161 |
+
jobjectArray* pArray ){
|
| 162 |
+
|
| 163 |
+
*pArray = pEnv->NewObjectArray( nDimension, pEnv->FindClass( szType ), NULL);
|
| 164 |
+
|
| 165 |
+
if(pEnv->ExceptionCheck() == JNI_TRUE){
|
| 166 |
+
pEnv->ExceptionDescribe();
|
| 167 |
+
return -1;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
if( pArray != NULL )
|
| 171 |
+
return 0;
|
| 172 |
+
else
|
| 173 |
+
return -2;
|
| 174 |
+
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
/*
|
| 178 |
+
Static wrapper on CallStaticVoidMethod() JNI function.
|
| 179 |
+
See the description in
|
| 180 |
+
http://jre.sfbay/java/re/jdk/6/promoted/latest/docs/technotes/guides/jni/spec/functions.html#wp4796
|
| 181 |
+
*/
|
| 182 |
+
|
| 183 |
+
int CallStaticVoidMethod( JNIEnv* pEnv,
|
| 184 |
+
jclass pClass,
|
| 185 |
+
jmethodID pMid,
|
| 186 |
+
void* pArgs){
|
| 187 |
+
|
| 188 |
+
g_nExitCode = 0;
|
| 189 |
+
pEnv->CallStaticVoidMethod( pClass, pMid, pArgs);
|
| 190 |
+
if( pEnv->ExceptionCheck() == JNI_TRUE ){
|
| 191 |
+
pEnv->ExceptionDescribe();
|
| 192 |
+
return -1;
|
| 193 |
+
}else
|
| 194 |
+
return g_nExitCode;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
/*
|
| 198 |
+
Static wrapper on DestroyJavaVM() JNI function.
|
| 199 |
+
See the description in
|
| 200 |
+
http://jre.sfbay/java/re/jdk/6/promoted/latest/docs/technotes/guides/jni/spec/invocation.html#destroy_java_vm
|
| 201 |
+
*/
|
| 202 |
+
|
| 203 |
+
int DestroyJavaVM( JavaVM* pJVM ){
|
| 204 |
+
pJVM->DestroyJavaVM();
|
| 205 |
+
return 0;
|
| 206 |
+
}
|
pool/shard008/C++/0096693_search-a-range-sorted-array.cc
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2013 Elements of Programming Interviews. All rights reserved.
|
| 2 |
+
|
| 3 |
+
#include <algorithm>
|
| 4 |
+
#include <cassert>
|
| 5 |
+
#include <iostream>
|
| 6 |
+
#include <random>
|
| 7 |
+
#include <string>
|
| 8 |
+
#include <utility>
|
| 9 |
+
#include <vector>
|
| 10 |
+
|
| 11 |
+
using std::cout;
|
| 12 |
+
using std::default_random_engine;
|
| 13 |
+
using std::endl;
|
| 14 |
+
using std::pair;
|
| 15 |
+
using std::random_device;
|
| 16 |
+
using std::stoul;
|
| 17 |
+
using std::uniform_int_distribution;
|
| 18 |
+
using std::vector;
|
| 19 |
+
|
| 20 |
+
// @include
|
| 21 |
+
pair<int, int> search_range(const vector<int>& A, int target) {
|
| 22 |
+
auto result = equal_range(A.cbegin(), A.cend(), target);
|
| 23 |
+
if (*result.first != target) {
|
| 24 |
+
return {-1, -1};
|
| 25 |
+
}
|
| 26 |
+
return {distance(A.begin(), result.first),
|
| 27 |
+
distance(A.begin(), result.second - 1)};
|
| 28 |
+
}
|
| 29 |
+
// @exclude
|
| 30 |
+
|
| 31 |
+
pair<int, int> check_ans(const vector<int>& A, int target) {
|
| 32 |
+
size_t a = 0;
|
| 33 |
+
while (a < A.size() && A[a] < target) {
|
| 34 |
+
++a;
|
| 35 |
+
}
|
| 36 |
+
if (A[a] != target) {
|
| 37 |
+
return {-1, -1};
|
| 38 |
+
}
|
| 39 |
+
int b = A.size() - 1;
|
| 40 |
+
while (b >= 0 && A[b] > target) {
|
| 41 |
+
--b;
|
| 42 |
+
}
|
| 43 |
+
return {a, b};
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
int main(int argc, char** argv) {
|
| 47 |
+
default_random_engine gen((random_device())());
|
| 48 |
+
for (int times = 0; times < 1000; ++times) {
|
| 49 |
+
size_t n;
|
| 50 |
+
if (argc == 2) {
|
| 51 |
+
n = stoul(argv[1]);
|
| 52 |
+
} else {
|
| 53 |
+
uniform_int_distribution<size_t> n_dis(0, 100000);
|
| 54 |
+
n = n_dis(gen);
|
| 55 |
+
}
|
| 56 |
+
uniform_int_distribution<int> A_dis(0, static_cast<int>(n));
|
| 57 |
+
vector<int> A;
|
| 58 |
+
generate_n(back_inserter(A), n, [&] { return A_dis(gen); });
|
| 59 |
+
sort(A.begin(), A.end());
|
| 60 |
+
/*
|
| 61 |
+
for (int a : A) {
|
| 62 |
+
cout << a << " ";
|
| 63 |
+
}
|
| 64 |
+
cout << endl;
|
| 65 |
+
*/
|
| 66 |
+
int target = A_dis(gen);
|
| 67 |
+
// cout << "target = " << target << endl;
|
| 68 |
+
auto result = search_range(A, target), ans = check_ans(A, target);
|
| 69 |
+
/*
|
| 70 |
+
cout << result.first << ", " << result.second << endl;
|
| 71 |
+
cout << ans.first << ", " << ans.second << endl;
|
| 72 |
+
*/
|
| 73 |
+
assert(result == ans);
|
| 74 |
+
}
|
| 75 |
+
return 0;
|
| 76 |
+
}
|
pool/shard008/C++/0096695_preload_request.cc
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "third_party/blink/renderer/core/html/parser/preload_request.h"
|
| 6 |
+
|
| 7 |
+
#include "third_party/blink/public/common/features.h"
|
| 8 |
+
#include "third_party/blink/renderer/core/dom/document.h"
|
| 9 |
+
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
|
| 10 |
+
#include "third_party/blink/renderer/core/frame/local_frame.h"
|
| 11 |
+
#include "third_party/blink/renderer/core/frame/settings.h"
|
| 12 |
+
#include "third_party/blink/renderer/core/loader/document_loader.h"
|
| 13 |
+
#include "third_party/blink/renderer/core/loader/preload_helper.h"
|
| 14 |
+
#include "third_party/blink/renderer/core/script/document_write_intervention.h"
|
| 15 |
+
#include "third_party/blink/renderer/core/script/script_loader.h"
|
| 16 |
+
#include "third_party/blink/renderer/platform/loader/fetch/cross_origin_attribute_value.h"
|
| 17 |
+
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_info.h"
|
| 18 |
+
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
|
| 19 |
+
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
|
| 20 |
+
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h"
|
| 21 |
+
#include "third_party/blink/renderer/platform/network/network_state_notifier.h"
|
| 22 |
+
#include "third_party/blink/renderer/platform/weborigin/security_policy.h"
|
| 23 |
+
|
| 24 |
+
namespace blink {
|
| 25 |
+
|
| 26 |
+
PreloadRequest::ExclusionInfo::ExclusionInfo(const KURL& document_url,
|
| 27 |
+
HashSet<KURL> scopes,
|
| 28 |
+
HashSet<KURL> resources)
|
| 29 |
+
: document_url_(document_url),
|
| 30 |
+
scopes_(std::move(scopes)),
|
| 31 |
+
resources_(std::move(resources)) {}
|
| 32 |
+
|
| 33 |
+
PreloadRequest::ExclusionInfo::~ExclusionInfo() = default;
|
| 34 |
+
|
| 35 |
+
bool PreloadRequest::ExclusionInfo::ShouldExclude(
|
| 36 |
+
const KURL& base_url,
|
| 37 |
+
const String& resource_url) const {
|
| 38 |
+
if (resources_.IsEmpty() && scopes_.IsEmpty())
|
| 39 |
+
return false;
|
| 40 |
+
KURL url = KURL(base_url.IsEmpty() ? document_url_ : base_url, resource_url);
|
| 41 |
+
if (resources_.Contains(url))
|
| 42 |
+
return true;
|
| 43 |
+
for (const auto& scope : scopes_) {
|
| 44 |
+
if (url.GetString().StartsWith(scope.GetString()))
|
| 45 |
+
return true;
|
| 46 |
+
}
|
| 47 |
+
return false;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
KURL PreloadRequest::CompleteURL(Document* document) {
|
| 51 |
+
if (!base_url_.IsEmpty())
|
| 52 |
+
return document->CompleteURLWithOverride(resource_url_, base_url_);
|
| 53 |
+
return document->CompleteURL(resource_url_);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// static
|
| 57 |
+
std::unique_ptr<PreloadRequest> PreloadRequest::CreateIfNeeded(
|
| 58 |
+
const String& initiator_name,
|
| 59 |
+
const TextPosition& initiator_position,
|
| 60 |
+
const String& resource_url,
|
| 61 |
+
const KURL& base_url,
|
| 62 |
+
ResourceType resource_type,
|
| 63 |
+
const network::mojom::ReferrerPolicy referrer_policy,
|
| 64 |
+
ResourceFetcher::IsImageSet is_image_set,
|
| 65 |
+
const ExclusionInfo* exclusion_info,
|
| 66 |
+
const FetchParameters::ResourceWidth& resource_width,
|
| 67 |
+
const ClientHintsPreferences& client_hints_preferences,
|
| 68 |
+
RequestType request_type) {
|
| 69 |
+
// Never preload data URLs. We also disallow relative ref URLs which become
|
| 70 |
+
// data URLs if the document's URL is a data URL. We don't want to create
|
| 71 |
+
// extra resource requests with data URLs to avoid copy / initialization
|
| 72 |
+
// overhead, which can be significant for large URLs.
|
| 73 |
+
if (resource_url.IsEmpty() || resource_url.StartsWith("#") ||
|
| 74 |
+
ProtocolIs(resource_url, "data")) {
|
| 75 |
+
return nullptr;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if (exclusion_info && exclusion_info->ShouldExclude(base_url, resource_url))
|
| 79 |
+
return nullptr;
|
| 80 |
+
|
| 81 |
+
return base::WrapUnique(new PreloadRequest(
|
| 82 |
+
initiator_name, initiator_position, resource_url, base_url, resource_type,
|
| 83 |
+
resource_width, client_hints_preferences, request_type, referrer_policy,
|
| 84 |
+
is_image_set));
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
Resource* PreloadRequest::Start(Document* document) {
|
| 88 |
+
DCHECK(document->domWindow());
|
| 89 |
+
|
| 90 |
+
FetchInitiatorInfo initiator_info;
|
| 91 |
+
initiator_info.name = AtomicString(initiator_name_);
|
| 92 |
+
initiator_info.position = initiator_position_;
|
| 93 |
+
|
| 94 |
+
const KURL& url = CompleteURL(document);
|
| 95 |
+
// Data URLs are filtered out in the preload scanner.
|
| 96 |
+
DCHECK(!url.ProtocolIsData());
|
| 97 |
+
|
| 98 |
+
ResourceRequest resource_request(url);
|
| 99 |
+
resource_request.SetReferrerPolicy(referrer_policy_);
|
| 100 |
+
|
| 101 |
+
resource_request.SetRequestContext(
|
| 102 |
+
ResourceFetcher::DetermineRequestContext(resource_type_, is_image_set_));
|
| 103 |
+
resource_request.SetRequestDestination(
|
| 104 |
+
ResourceFetcher::DetermineRequestDestination(resource_type_));
|
| 105 |
+
|
| 106 |
+
resource_request.SetFetchPriorityHint(fetch_priority_hint_);
|
| 107 |
+
|
| 108 |
+
ResourceLoaderOptions options(document->domWindow()->GetCurrentWorld());
|
| 109 |
+
options.initiator_info = initiator_info;
|
| 110 |
+
FetchParameters params(std::move(resource_request), options);
|
| 111 |
+
|
| 112 |
+
auto* origin = document->domWindow()->GetSecurityOrigin();
|
| 113 |
+
if (script_type_ == mojom::blink::ScriptType::kModule) {
|
| 114 |
+
DCHECK_EQ(resource_type_, ResourceType::kScript);
|
| 115 |
+
params.SetCrossOriginAccessControl(
|
| 116 |
+
origin, ScriptLoader::ModuleScriptCredentialsMode(cross_origin_));
|
| 117 |
+
params.SetModuleScript();
|
| 118 |
+
} else if (cross_origin_ != kCrossOriginAttributeNotSet) {
|
| 119 |
+
params.SetCrossOriginAccessControl(origin, cross_origin_);
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
params.SetDefer(defer_);
|
| 123 |
+
params.SetResourceWidth(resource_width_);
|
| 124 |
+
params.GetClientHintsPreferences().UpdateFrom(client_hints_preferences_);
|
| 125 |
+
params.SetIntegrityMetadata(integrity_metadata_);
|
| 126 |
+
params.SetContentSecurityPolicyNonce(nonce_);
|
| 127 |
+
params.SetParserDisposition(kParserInserted);
|
| 128 |
+
|
| 129 |
+
if (request_type_ == kRequestTypeLinkRelPreload)
|
| 130 |
+
params.SetLinkPreload(true);
|
| 131 |
+
|
| 132 |
+
if (script_type_ == mojom::blink::ScriptType::kModule) {
|
| 133 |
+
DCHECK_EQ(resource_type_, ResourceType::kScript);
|
| 134 |
+
params.SetDecoderOptions(TextResourceDecoderOptions::CreateUTF8Decode());
|
| 135 |
+
} else if (resource_type_ == ResourceType::kScript ||
|
| 136 |
+
resource_type_ == ResourceType::kCSSStyleSheet) {
|
| 137 |
+
params.SetCharset(charset_.IsEmpty() ? document->Encoding()
|
| 138 |
+
: WTF::TextEncoding(charset_));
|
| 139 |
+
}
|
| 140 |
+
FetchParameters::SpeculativePreloadType speculative_preload_type =
|
| 141 |
+
FetchParameters::SpeculativePreloadType::kInDocument;
|
| 142 |
+
if (from_insertion_scanner_) {
|
| 143 |
+
speculative_preload_type =
|
| 144 |
+
FetchParameters::SpeculativePreloadType::kInserted;
|
| 145 |
+
}
|
| 146 |
+
params.SetSpeculativePreloadType(speculative_preload_type);
|
| 147 |
+
|
| 148 |
+
if (resource_type_ == ResourceType::kScript) {
|
| 149 |
+
// We intentionally ignore the returned value, because we don't resend
|
| 150 |
+
// the async request to the blocked script here.
|
| 151 |
+
MaybeDisallowFetchForDocWrittenScript(params, *document);
|
| 152 |
+
}
|
| 153 |
+
params.SetRenderBlockingBehavior(render_blocking_behavior_);
|
| 154 |
+
|
| 155 |
+
return PreloadHelper::StartPreload(resource_type_, params, *document);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
} // namespace blink
|
pool/shard008/C++/0096696_collection.cpp
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2006-2008 The FLWOR Foundation.
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
#include "collection.h"
|
| 18 |
+
|
| 19 |
+
#include "store/api/item.h"
|
| 20 |
+
#include "store/api/ic.h"
|
| 21 |
+
|
| 22 |
+
#include "node_items.h"
|
| 23 |
+
#include "simple_store.h"
|
| 24 |
+
#include "simple_index.h"
|
| 25 |
+
|
| 26 |
+
namespace zorba {
|
| 27 |
+
namespace simplestore {
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
/*******************************************************************************
|
| 31 |
+
|
| 32 |
+
*******************************************************************************/
|
| 33 |
+
void Collection::getIndexes(std::vector<store::Index*>& indexes)
|
| 34 |
+
{
|
| 35 |
+
getIndexes(getName(), indexes);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
/*******************************************************************************
|
| 40 |
+
Static method
|
| 41 |
+
*******************************************************************************/
|
| 42 |
+
void Collection::getIndexes(
|
| 43 |
+
const store::Item* name,
|
| 44 |
+
std::vector<store::Index*>& indexes)
|
| 45 |
+
{
|
| 46 |
+
const IndexSet& availableIndexes = GET_STORE().getIndices();
|
| 47 |
+
|
| 48 |
+
IndexSet::iterator idxIte = availableIndexes.begin();
|
| 49 |
+
IndexSet::iterator idxEnd = availableIndexes.end();
|
| 50 |
+
|
| 51 |
+
for (; idxIte != idxEnd; ++idxIte)
|
| 52 |
+
{
|
| 53 |
+
IndexImpl* index = static_cast<IndexImpl*>((*idxIte).second.getp());
|
| 54 |
+
const store::IndexSpecification& indexSpec = index->getSpecification();
|
| 55 |
+
|
| 56 |
+
const std::vector<store::Item_t>& indexSources = indexSpec.theSources;
|
| 57 |
+
csize numIndexSources = indexSources.size();
|
| 58 |
+
|
| 59 |
+
for (csize i = 0; i < numIndexSources; ++i)
|
| 60 |
+
{
|
| 61 |
+
if (indexSources[i]->equals(name))
|
| 62 |
+
{
|
| 63 |
+
indexes.push_back(index);
|
| 64 |
+
break;
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
/*******************************************************************************
|
| 72 |
+
|
| 73 |
+
*******************************************************************************/
|
| 74 |
+
void Collection::getActiveICs(std::vector<store::IC*>& ics)
|
| 75 |
+
{
|
| 76 |
+
getActiveICs(getName(), ics);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
/*******************************************************************************
|
| 81 |
+
Static method
|
| 82 |
+
*******************************************************************************/
|
| 83 |
+
void Collection::getActiveICs(
|
| 84 |
+
const store::Item* name,
|
| 85 |
+
std::vector<store::IC*>& ics)
|
| 86 |
+
{
|
| 87 |
+
store::Iterator_t activeICNames = GET_STORE().listActiveICNames();
|
| 88 |
+
|
| 89 |
+
store::Item_t activeICName;
|
| 90 |
+
activeICNames->open();
|
| 91 |
+
|
| 92 |
+
while ( activeICNames->next(activeICName) )
|
| 93 |
+
{
|
| 94 |
+
|
| 95 |
+
store::IC* activeIC = GET_STORE().getIC(activeICName);
|
| 96 |
+
|
| 97 |
+
switch( activeIC->getICKind() )
|
| 98 |
+
{
|
| 99 |
+
case store::IC::ic_collection:
|
| 100 |
+
if ( activeIC->getCollectionName()->equals(name) )
|
| 101 |
+
ics.push_back(activeIC);
|
| 102 |
+
break;
|
| 103 |
+
|
| 104 |
+
case store::IC::ic_foreignkey:
|
| 105 |
+
if ( activeIC->getToCollectionName()->equals(name) )
|
| 106 |
+
ics.push_back(activeIC);
|
| 107 |
+
|
| 108 |
+
if ( activeIC->getFromCollectionName()->equals(name) )
|
| 109 |
+
ics.push_back(activeIC);
|
| 110 |
+
break;
|
| 111 |
+
|
| 112 |
+
default:
|
| 113 |
+
ZORBA_ASSERT(false);
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
activeICNames->close();
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
} /* namespace simplestore */
|
| 122 |
+
} /* namespace zorba */
|
pool/shard008/C++/0096697_rendezvous.cpp
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//Jakub Michalec
|
| 2 |
+
#include "Semaphore.h"
|
| 3 |
+
#include <iostream>
|
| 4 |
+
#include <thread>
|
| 5 |
+
//Task: A1 always prints before B1, and B2 always prints before A2.
|
| 6 |
+
|
| 7 |
+
void taskOne(std::shared_ptr<Semaphore> sem1,std::shared_ptr<Semaphore> sem2){
|
| 8 |
+
std::cout << "A1"<<std::endl;
|
| 9 |
+
sem1->Signal();
|
| 10 |
+
sem2->Wait();
|
| 11 |
+
std::cout << "A2"<<std::endl;
|
| 12 |
+
}
|
| 13 |
+
void taskTwo(std::shared_ptr<Semaphore> sem1,std::shared_ptr<Semaphore> sem2){
|
| 14 |
+
std::cout << "B1"<<std::endl;
|
| 15 |
+
sem2->Signal();
|
| 16 |
+
sem1->Wait();
|
| 17 |
+
std::cout << "B2"<<std::endl;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
int main(void){
|
| 21 |
+
std::thread threadOne, threadTwo;
|
| 22 |
+
std::shared_ptr<Semaphore> sem1( new Semaphore);
|
| 23 |
+
std::shared_ptr<Semaphore> sem2( new Semaphore);
|
| 24 |
+
/**< Launch the threads */
|
| 25 |
+
threadOne=std::thread(taskTwo, sem1, sem2);
|
| 26 |
+
threadTwo=std::thread(taskOne, sem1, sem2);
|
| 27 |
+
|
| 28 |
+
std::cout << "Launched from the main\n";
|
| 29 |
+
threadOne.join();
|
| 30 |
+
threadTwo.join();
|
| 31 |
+
return 0;
|
| 32 |
+
}
|
pool/shard008/C++/0096701_Resources.cpp
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2014 Google Inc.
|
| 3 |
+
*
|
| 4 |
+
* Use of this source code is governed by a BSD-style license that can be
|
| 5 |
+
* found in the LICENSE file.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
#include "Resources.h"
|
| 9 |
+
#include "SkBitmap.h"
|
| 10 |
+
#include "SkCommandLineFlags.h"
|
| 11 |
+
#include "SkData.h"
|
| 12 |
+
#include "SkDecodingImageGenerator.h"
|
| 13 |
+
#include "SkOSFile.h"
|
| 14 |
+
|
| 15 |
+
DEFINE_string2(resourcePath, i, "resources", "Directory with test resources: images, fonts, etc.");
|
| 16 |
+
|
| 17 |
+
SkString GetResourcePath(const char* resource) {
|
| 18 |
+
return SkOSPath::Join(FLAGS_resourcePath[0], resource);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
void SetResourcePath(const char* resource) {
|
| 22 |
+
FLAGS_resourcePath.set(0, resource);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) {
|
| 26 |
+
SkString resourcePath = GetResourcePath(resource);
|
| 27 |
+
SkAutoTUnref<SkData> resourceData(
|
| 28 |
+
SkData::NewFromFileName(resourcePath.c_str()));
|
| 29 |
+
return resourceData && SkInstallDiscardablePixelRef(
|
| 30 |
+
SkDecodingImageGenerator::Create(
|
| 31 |
+
resourceData, SkDecodingImageGenerator::Options()), dst);
|
| 32 |
+
}
|
pool/shard008/C++/0096704_SkXfermodeImageFilter.cpp
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2013 The Android Open Source Project
|
| 3 |
+
*
|
| 4 |
+
* Use of this source code is governed by a BSD-style license that can be
|
| 5 |
+
* found in the LICENSE file.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
#include "SkXfermodeImageFilter.h"
|
| 9 |
+
#include "SkCanvas.h"
|
| 10 |
+
#include "SkDevice.h"
|
| 11 |
+
#include "SkColorPriv.h"
|
| 12 |
+
#include "SkReadBuffer.h"
|
| 13 |
+
#include "SkWriteBuffer.h"
|
| 14 |
+
#include "SkXfermode.h"
|
| 15 |
+
#if SK_SUPPORT_GPU
|
| 16 |
+
#include "GrContext.h"
|
| 17 |
+
#include "GrDrawContext.h"
|
| 18 |
+
#include "effects/GrTextureDomain.h"
|
| 19 |
+
#include "SkGr.h"
|
| 20 |
+
#endif
|
| 21 |
+
|
| 22 |
+
///////////////////////////////////////////////////////////////////////////////
|
| 23 |
+
|
| 24 |
+
SkXfermodeImageFilter::SkXfermodeImageFilter(SkXfermode* mode,
|
| 25 |
+
SkImageFilter* inputs[2],
|
| 26 |
+
const CropRect* cropRect)
|
| 27 |
+
: INHERITED(2, inputs, cropRect), fMode(mode) {
|
| 28 |
+
SkSafeRef(fMode);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
SkXfermodeImageFilter::~SkXfermodeImageFilter() {
|
| 32 |
+
SkSafeUnref(fMode);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
SkFlattenable* SkXfermodeImageFilter::CreateProc(SkReadBuffer& buffer) {
|
| 36 |
+
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2);
|
| 37 |
+
SkAutoTUnref<SkXfermode> mode(buffer.readXfermode());
|
| 38 |
+
return Create(mode, common.getInput(0), common.getInput(1), &common.cropRect());
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
void SkXfermodeImageFilter::flatten(SkWriteBuffer& buffer) const {
|
| 42 |
+
this->INHERITED::flatten(buffer);
|
| 43 |
+
buffer.writeFlattenable(fMode);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
bool SkXfermodeImageFilter::onFilterImage(Proxy* proxy,
|
| 47 |
+
const SkBitmap& src,
|
| 48 |
+
const Context& ctx,
|
| 49 |
+
SkBitmap* dst,
|
| 50 |
+
SkIPoint* offset) const {
|
| 51 |
+
SkBitmap background = src, foreground = src;
|
| 52 |
+
SkImageFilter* backgroundInput = getInput(0);
|
| 53 |
+
SkImageFilter* foregroundInput = getInput(1);
|
| 54 |
+
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
|
| 55 |
+
if (backgroundInput &&
|
| 56 |
+
!backgroundInput->filterImage(proxy, src, ctx, &background, &backgroundOffset)) {
|
| 57 |
+
background.reset();
|
| 58 |
+
}
|
| 59 |
+
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
|
| 60 |
+
if (foregroundInput &&
|
| 61 |
+
!foregroundInput->filterImage(proxy, src, ctx, &foreground, &foregroundOffset)) {
|
| 62 |
+
foreground.reset();
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
SkIRect bounds, foregroundBounds;
|
| 66 |
+
if (!applyCropRect(ctx, foreground, foregroundOffset, &foregroundBounds)) {
|
| 67 |
+
foregroundBounds.setEmpty();
|
| 68 |
+
foreground.reset();
|
| 69 |
+
}
|
| 70 |
+
if (!applyCropRect(ctx, background, backgroundOffset, &bounds)) {
|
| 71 |
+
bounds.setEmpty();
|
| 72 |
+
background.reset();
|
| 73 |
+
}
|
| 74 |
+
bounds.join(foregroundBounds);
|
| 75 |
+
if (bounds.isEmpty()) {
|
| 76 |
+
return false;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
|
| 80 |
+
if (NULL == device.get()) {
|
| 81 |
+
return false;
|
| 82 |
+
}
|
| 83 |
+
SkCanvas canvas(device);
|
| 84 |
+
canvas.translate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
|
| 85 |
+
SkPaint paint;
|
| 86 |
+
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
| 87 |
+
canvas.drawBitmap(background, SkIntToScalar(backgroundOffset.fX),
|
| 88 |
+
SkIntToScalar(backgroundOffset.fY), &paint);
|
| 89 |
+
paint.setXfermode(fMode);
|
| 90 |
+
canvas.drawBitmap(foreground, SkIntToScalar(foregroundOffset.fX),
|
| 91 |
+
SkIntToScalar(foregroundOffset.fY), &paint);
|
| 92 |
+
canvas.clipRect(SkRect::Make(foregroundBounds), SkRegion::kDifference_Op);
|
| 93 |
+
paint.setColor(SK_ColorTRANSPARENT);
|
| 94 |
+
canvas.drawPaint(paint);
|
| 95 |
+
*dst = device->accessBitmap(false);
|
| 96 |
+
offset->fX = bounds.left();
|
| 97 |
+
offset->fY = bounds.top();
|
| 98 |
+
return true;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
#ifndef SK_IGNORE_TO_STRING
|
| 102 |
+
void SkXfermodeImageFilter::toString(SkString* str) const {
|
| 103 |
+
str->appendf("SkXfermodeImageFilter: (");
|
| 104 |
+
str->appendf("xfermode: (");
|
| 105 |
+
if (fMode) {
|
| 106 |
+
fMode->toString(str);
|
| 107 |
+
}
|
| 108 |
+
str->append(")");
|
| 109 |
+
if (this->getInput(0)) {
|
| 110 |
+
str->appendf("foreground: (");
|
| 111 |
+
this->getInput(0)->toString(str);
|
| 112 |
+
str->appendf(")");
|
| 113 |
+
}
|
| 114 |
+
if (this->getInput(1)) {
|
| 115 |
+
str->appendf("background: (");
|
| 116 |
+
this->getInput(1)->toString(str);
|
| 117 |
+
str->appendf(")");
|
| 118 |
+
}
|
| 119 |
+
str->append(")");
|
| 120 |
+
}
|
| 121 |
+
#endif
|
| 122 |
+
|
| 123 |
+
#if SK_SUPPORT_GPU
|
| 124 |
+
|
| 125 |
+
bool SkXfermodeImageFilter::canFilterImageGPU() const {
|
| 126 |
+
return fMode && fMode->asFragmentProcessor(NULL, NULL, NULL) && !cropRectIsSet();
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
|
| 130 |
+
const SkBitmap& src,
|
| 131 |
+
const Context& ctx,
|
| 132 |
+
SkBitmap* result,
|
| 133 |
+
SkIPoint* offset) const {
|
| 134 |
+
SkBitmap background = src;
|
| 135 |
+
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
|
| 136 |
+
if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &background,
|
| 137 |
+
&backgroundOffset)) {
|
| 138 |
+
return onFilterImage(proxy, src, ctx, result, offset);
|
| 139 |
+
}
|
| 140 |
+
GrTexture* backgroundTex = background.getTexture();
|
| 141 |
+
|
| 142 |
+
if (NULL == backgroundTex) {
|
| 143 |
+
SkASSERT(false);
|
| 144 |
+
return false;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
SkBitmap foreground = src;
|
| 148 |
+
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
|
| 149 |
+
if (getInput(1) && !getInput(1)->getInputResultGPU(proxy, src, ctx, &foreground,
|
| 150 |
+
&foregroundOffset)) {
|
| 151 |
+
return onFilterImage(proxy, src, ctx, result, offset);
|
| 152 |
+
}
|
| 153 |
+
GrTexture* foregroundTex = foreground.getTexture();
|
| 154 |
+
GrContext* context = foregroundTex->getContext();
|
| 155 |
+
|
| 156 |
+
GrFragmentProcessor* xferProcessor = NULL;
|
| 157 |
+
|
| 158 |
+
GrSurfaceDesc desc;
|
| 159 |
+
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
| 160 |
+
desc.fWidth = src.width();
|
| 161 |
+
desc.fHeight = src.height();
|
| 162 |
+
desc.fConfig = kSkia8888_GrPixelConfig;
|
| 163 |
+
SkAutoTUnref<GrTexture> dst(context->textureProvider()->refScratchTexture(
|
| 164 |
+
desc, GrTextureProvider::kApprox_ScratchTexMatch));
|
| 165 |
+
if (!dst) {
|
| 166 |
+
return false;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
GrPaint paint;
|
| 170 |
+
if (!fMode || !fMode->asFragmentProcessor(&xferProcessor, paint.getProcessorDataManager(),
|
| 171 |
+
backgroundTex)) {
|
| 172 |
+
// canFilterImageGPU() should've taken care of this
|
| 173 |
+
SkASSERT(false);
|
| 174 |
+
return false;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foregroundTex);
|
| 178 |
+
foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOffset.fX),
|
| 179 |
+
SkIntToScalar(backgroundOffset.fY-foregroundOffset.fY));
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
SkRect srcRect;
|
| 183 |
+
src.getBounds(&srcRect);
|
| 184 |
+
|
| 185 |
+
SkAutoTUnref<GrFragmentProcessor> foregroundDomain(GrTextureDomainEffect::Create(
|
| 186 |
+
paint.getProcessorDataManager(),
|
| 187 |
+
foregroundTex, foregroundMatrix,
|
| 188 |
+
GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()),
|
| 189 |
+
GrTextureDomain::kDecal_Mode,
|
| 190 |
+
GrTextureParams::kNone_FilterMode)
|
| 191 |
+
);
|
| 192 |
+
|
| 193 |
+
paint.addColorProcessor(foregroundDomain.get());
|
| 194 |
+
paint.addColorProcessor(xferProcessor)->unref();
|
| 195 |
+
|
| 196 |
+
GrDrawContext* drawContext = context->drawContext();
|
| 197 |
+
if (!drawContext) {
|
| 198 |
+
return false;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint,
|
| 202 |
+
SkMatrix::I(), srcRect);
|
| 203 |
+
|
| 204 |
+
offset->fX = backgroundOffset.fX;
|
| 205 |
+
offset->fY = backgroundOffset.fY;
|
| 206 |
+
WrapTexture(dst, src.width(), src.height(), result);
|
| 207 |
+
return true;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
#endif
|
| 211 |
+
|
pool/shard008/C++/0096710_version_tests.cpp
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 3 |
+
* you may not use this file except in compliance with the License.
|
| 4 |
+
* You may obtain a copy of the License at
|
| 5 |
+
*
|
| 6 |
+
* http://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,
|
| 10 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 11 |
+
* See the License for the specific language governing permissions and
|
| 12 |
+
* limitations under the License.
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
#include <gtest/gtest.h>
|
| 16 |
+
|
| 17 |
+
#include <stout/gtest.hpp>
|
| 18 |
+
#include <stout/stringify.hpp>
|
| 19 |
+
#include <stout/version.hpp>
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
// Verify version comparison operations.
|
| 23 |
+
TEST(VersionTest, Comparison)
|
| 24 |
+
{
|
| 25 |
+
Version version1(0, 10, 4);
|
| 26 |
+
Version version2(0, 20, 3);
|
| 27 |
+
Try<Version> version3 = Version::parse("0.20.3");
|
| 28 |
+
|
| 29 |
+
EXPECT_EQ(version2, version3.get());
|
| 30 |
+
EXPECT_NE(version1, version2);
|
| 31 |
+
EXPECT_LT(version1, version2);
|
| 32 |
+
EXPECT_LE(version1, version2);
|
| 33 |
+
EXPECT_LE(version2, version3.get());
|
| 34 |
+
EXPECT_GT(version2, version1);
|
| 35 |
+
EXPECT_GE(version2, version1);
|
| 36 |
+
EXPECT_GE(version3.get(), version1);
|
| 37 |
+
|
| 38 |
+
EXPECT_EQ(stringify(version2), "0.20.3");
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
// Verify version parser.
|
| 43 |
+
TEST(VersionTest, Parse)
|
| 44 |
+
{
|
| 45 |
+
Try<Version> version1 = Version::parse("1.20.3");
|
| 46 |
+
Try<Version> version2 = Version::parse("1.20");
|
| 47 |
+
Try<Version> version3 = Version::parse("1");
|
| 48 |
+
|
| 49 |
+
EXPECT_GT(version1.get(), version2.get());
|
| 50 |
+
EXPECT_GT(version2.get(), version3.get());
|
| 51 |
+
EXPECT_EQ(stringify(version2.get()), "1.20.0");
|
| 52 |
+
EXPECT_EQ(stringify(version3.get()), "1.0.0");
|
| 53 |
+
|
| 54 |
+
// Verify that tagged/labeled versions work.
|
| 55 |
+
Try<Version> version4 = Version::parse("1.20.3-rc1");
|
| 56 |
+
EXPECT_SOME(version4);
|
| 57 |
+
EXPECT_EQ(version4.get(), version1.get());
|
| 58 |
+
EXPECT_EQ(stringify(version4.get()), "1.20.3");
|
| 59 |
+
|
| 60 |
+
EXPECT_ERROR(Version::parse("0.a.b"));
|
| 61 |
+
EXPECT_ERROR(Version::parse(""));
|
| 62 |
+
EXPECT_ERROR(Version::parse("a"));
|
| 63 |
+
EXPECT_ERROR(Version::parse("1."));
|
| 64 |
+
EXPECT_ERROR(Version::parse(".1.2"));
|
| 65 |
+
EXPECT_ERROR(Version::parse("0.1.2.3"));
|
| 66 |
+
}
|
pool/shard008/C++/0096711_ContactPublisher.cc
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "ContactPublisher.hh"
|
| 2 |
+
// Declaration of the objects used from standard libraries
|
| 3 |
+
using std::string;
|
| 4 |
+
using std::cout;
|
| 5 |
+
|
| 6 |
+
namespace gazebo{
|
| 7 |
+
ContactSensor::ContactSensor() : SensorPlugin()
|
| 8 |
+
{
|
| 9 |
+
} // ContactSensor::ContactSensor
|
| 10 |
+
ContactSensor::~ContactSensor()
|
| 11 |
+
{
|
| 12 |
+
parentSensor.reset();
|
| 13 |
+
updateConnection.reset();
|
| 14 |
+
collisionPub.reset();
|
| 15 |
+
} // ContactSensor::~ContactSensor
|
| 16 |
+
void ContactSensor::Load(sensors::SensorPtr _sensor, sdf::ElementPtr /*_sdf*/)
|
| 17 |
+
{
|
| 18 |
+
// Get the parent sensor. This code from gazebo wiki.
|
| 19 |
+
this->parentSensor =
|
| 20 |
+
boost::dynamic_pointer_cast<sensors::ContactSensor>(_sensor);
|
| 21 |
+
// Make sure the parent sensor is valid.
|
| 22 |
+
if (!this->parentSensor)
|
| 23 |
+
{
|
| 24 |
+
gzerr << "ContactSensor requires a ContactSensor.\n";
|
| 25 |
+
return;
|
| 26 |
+
}
|
| 27 |
+
// Connect to the sensor update event.
|
| 28 |
+
this->updateConnection = this->parentSensor->ConnectUpdated(
|
| 29 |
+
boost::bind(&ContactSensor::OnUpdate, this));
|
| 30 |
+
// Make sure the parent sensor is active.
|
| 31 |
+
this->parentSensor->SetActive(true);
|
| 32 |
+
// Create a new transport node
|
| 33 |
+
transport::NodePtr node(new transport::Node());
|
| 34 |
+
// Get the parent model name
|
| 35 |
+
string parent_model_name =
|
| 36 |
+
parentSensor->GetParentName()
|
| 37 |
+
.substr(0,(parentSensor->GetParentName()).find("::"));
|
| 38 |
+
// Initialize the node with the model name
|
| 39 |
+
node->Init(parent_model_name);
|
| 40 |
+
// Setting up the publisher
|
| 41 |
+
string topic_name =
|
| 42 |
+
"~/" + parentSensor->GetParentName() + "::" + parentSensor->GetName();
|
| 43 |
+
this->collisionPub = node->Advertise<msgs::GzString>(topic_name);
|
| 44 |
+
} // ContactSensor::Load
|
| 45 |
+
void ContactSensor::OnUpdate()
|
| 46 |
+
{
|
| 47 |
+
// Get all the contacts.
|
| 48 |
+
msgs::Contacts contacts = this->parentSensor->GetContacts();
|
| 49 |
+
for (unsigned int i = 0; i < contacts.contact_size(); ++i)
|
| 50 |
+
{
|
| 51 |
+
if (contacts.contact(i).collision1().find("ground_plane") == string::npos
|
| 52 |
+
&& contacts.contact(i).collision2().find("ground_plane") == string::npos)
|
| 53 |
+
// Get rid of the collision with ground plane
|
| 54 |
+
{
|
| 55 |
+
// Publish the topic to model
|
| 56 |
+
string collision_msgs =
|
| 57 |
+
contacts.contact(i).collision1() + "," + contacts.contact(i).collision2();
|
| 58 |
+
msgs::GzString gzstr_collision_message;
|
| 59 |
+
gzstr_collision_message.set_data(collision_msgs);
|
| 60 |
+
collisionPub->Publish(gzstr_collision_message);
|
| 61 |
+
|
| 62 |
+
//+++++++++++++++ Showing the position of the contact points +++++++++++++++
|
| 63 |
+
// for (unsigned int j = 0; j < contacts.contact(i).position_size(); ++j)
|
| 64 |
+
// {
|
| 65 |
+
// cout << j << " Position:"
|
| 66 |
+
// << contacts.contact(i).position(j).x() << " "
|
| 67 |
+
// << contacts.contact(i).position(j).y() << " "
|
| 68 |
+
// << contacts.contact(i).position(j).z() << "\n";
|
| 69 |
+
// cout << " Normal:"
|
| 70 |
+
// << contacts.contact(i).normal(j).x() << " "
|
| 71 |
+
// << contacts.contact(i).normal(j).y() << " "
|
| 72 |
+
// << contacts.contact(i).normal(j).z() << "\n";
|
| 73 |
+
// cout << " Depth:" << contacts.contact(i).depth(j) << "\n";
|
| 74 |
+
// }
|
| 75 |
+
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| 76 |
+
break;
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
} // ContactSensor::OnUpdate
|
| 80 |
+
|
| 81 |
+
GZ_REGISTER_SENSOR_PLUGIN(ContactSensor)
|
| 82 |
+
} // namespace gazebo
|
pool/shard008/C++/0096712_ash_touch_exploration_manager_chromeos.cc
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "ash/ash_touch_exploration_manager_chromeos.h"
|
| 6 |
+
|
| 7 |
+
#include "ash/accessibility_delegate.h"
|
| 8 |
+
#include "ash/audio/sounds.h"
|
| 9 |
+
#include "ash/root_window_controller.h"
|
| 10 |
+
#include "ash/shell.h"
|
| 11 |
+
#include "ash/system/tray/system_tray_notifier.h"
|
| 12 |
+
#include "ash/wm/window_util.h"
|
| 13 |
+
#include "base/command_line.h"
|
| 14 |
+
#include "chromeos/audio/chromeos_sounds.h"
|
| 15 |
+
#include "chromeos/audio/cras_audio_handler.h"
|
| 16 |
+
#include "chromeos/chromeos_switches.h"
|
| 17 |
+
#include "ui/chromeos/touch_exploration_controller.h"
|
| 18 |
+
#include "ui/wm/public/activation_client.h"
|
| 19 |
+
|
| 20 |
+
namespace ash {
|
| 21 |
+
|
| 22 |
+
AshTouchExplorationManager::AshTouchExplorationManager(
|
| 23 |
+
RootWindowController* root_window_controller)
|
| 24 |
+
: root_window_controller_(root_window_controller),
|
| 25 |
+
audio_handler_(chromeos::CrasAudioHandler::Get()) {
|
| 26 |
+
Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this);
|
| 27 |
+
ash::Shell::GetInstance()->activation_client()->AddObserver(this);
|
| 28 |
+
UpdateTouchExplorationState();
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
AshTouchExplorationManager::~AshTouchExplorationManager() {
|
| 32 |
+
SystemTrayNotifier* system_tray_notifier =
|
| 33 |
+
Shell::GetInstance()->system_tray_notifier();
|
| 34 |
+
if (system_tray_notifier)
|
| 35 |
+
system_tray_notifier->RemoveAccessibilityObserver(this);
|
| 36 |
+
ash::Shell::GetInstance()->activation_client()->RemoveObserver(this);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
void AshTouchExplorationManager::OnAccessibilityModeChanged(
|
| 40 |
+
ui::AccessibilityNotificationVisibility notify) {
|
| 41 |
+
UpdateTouchExplorationState();
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void AshTouchExplorationManager::SetOutputLevel(int volume) {
|
| 45 |
+
if (volume > 0) {
|
| 46 |
+
if (audio_handler_->IsOutputMuted()) {
|
| 47 |
+
audio_handler_->SetOutputMute(false);
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
audio_handler_->SetOutputVolumePercent(volume);
|
| 51 |
+
// Avoid negative volume.
|
| 52 |
+
if (audio_handler_->IsOutputVolumeBelowDefaultMuteLevel())
|
| 53 |
+
audio_handler_->SetOutputMute(true);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
void AshTouchExplorationManager::SilenceSpokenFeedback() {
|
| 57 |
+
AccessibilityDelegate* delegate =
|
| 58 |
+
Shell::GetInstance()->accessibility_delegate();
|
| 59 |
+
if (!delegate->IsSpokenFeedbackEnabled())
|
| 60 |
+
return;
|
| 61 |
+
delegate->SilenceSpokenFeedback();
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
void AshTouchExplorationManager::PlayVolumeAdjustEarcon() {
|
| 65 |
+
if (!VolumeAdjustSoundEnabled())
|
| 66 |
+
return;
|
| 67 |
+
if (!audio_handler_->IsOutputMuted() &&
|
| 68 |
+
audio_handler_->GetOutputVolumePercent() != 100)
|
| 69 |
+
PlaySystemSoundIfSpokenFeedback(chromeos::SOUND_VOLUME_ADJUST);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
void AshTouchExplorationManager::PlayPassthroughEarcon() {
|
| 73 |
+
Shell::GetInstance()->accessibility_delegate()->PlayEarcon(
|
| 74 |
+
chromeos::SOUND_PASSTHROUGH);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
void AshTouchExplorationManager::PlayExitScreenEarcon() {
|
| 78 |
+
Shell::GetInstance()->accessibility_delegate()->PlayEarcon(
|
| 79 |
+
chromeos::SOUND_EXIT_SCREEN);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
void AshTouchExplorationManager::PlayEnterScreenEarcon() {
|
| 83 |
+
Shell::GetInstance()->accessibility_delegate()->PlayEarcon(
|
| 84 |
+
chromeos::SOUND_ENTER_SCREEN);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
void AshTouchExplorationManager::HandleAccessibilityGesture(
|
| 88 |
+
ui::AXGesture gesture) {
|
| 89 |
+
Shell::GetInstance()->accessibility_delegate()->HandleAccessibilityGesture(
|
| 90 |
+
gesture);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
void AshTouchExplorationManager::OnWindowActivated(
|
| 94 |
+
aura::client::ActivationChangeObserver::ActivationReason reason,
|
| 95 |
+
aura::Window* gained_active,
|
| 96 |
+
aura::Window* lost_active) {
|
| 97 |
+
UpdateTouchExplorationState();
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
void AshTouchExplorationManager::UpdateTouchExplorationState() {
|
| 101 |
+
// Comes from components/exo/shell_surface.cc.
|
| 102 |
+
const char kExoShellSurfaceWindowName[] = "ExoShellSurface";
|
| 103 |
+
|
| 104 |
+
// See crbug.com/603745 for more details.
|
| 105 |
+
bool pass_through_surface =
|
| 106 |
+
wm::GetActiveWindow() &&
|
| 107 |
+
wm::GetActiveWindow()->name() == kExoShellSurfaceWindowName;
|
| 108 |
+
|
| 109 |
+
AccessibilityDelegate* delegate =
|
| 110 |
+
Shell::GetInstance()->accessibility_delegate();
|
| 111 |
+
bool enabled = delegate->IsSpokenFeedbackEnabled();
|
| 112 |
+
|
| 113 |
+
if (!pass_through_surface && enabled &&
|
| 114 |
+
!touch_exploration_controller_.get()) {
|
| 115 |
+
touch_exploration_controller_.reset(new ui::TouchExplorationController(
|
| 116 |
+
root_window_controller_->GetRootWindow(), this));
|
| 117 |
+
} else if (!enabled || pass_through_surface) {
|
| 118 |
+
touch_exploration_controller_.reset();
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
bool AshTouchExplorationManager::VolumeAdjustSoundEnabled() {
|
| 123 |
+
return !base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| 124 |
+
chromeos::switches::kDisableVolumeAdjustSound);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
} // namespace ash
|
pool/shard008/C++/0096713_TillageParameter.cpp
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "TillageParameter.h"
|
| 2 |
+
#include "stdlib.h"
|
| 3 |
+
|
| 4 |
+
using namespace MainBMP;
|
| 5 |
+
using namespace BMPParameter;
|
| 6 |
+
|
| 7 |
+
#define TILLAGE_PARAMETER_COUNT 5
|
| 8 |
+
|
| 9 |
+
#define TILLAGE_PARAMETER_INDEX_EFFMIX 3
|
| 10 |
+
#define TILLAGE_PARAMETER_INDEX_DEPTIL 4
|
| 11 |
+
|
| 12 |
+
TillageParameter::TillageParameter(vector<string> *oneRow):ArealParameter(oneRow)
|
| 13 |
+
{
|
| 14 |
+
if(int(oneRow->size()) < TILLAGE_PARAMETER_COUNT) throw ModelException("TillageParameter","TillageParameter","oneRow should have 5 parameters at least!");
|
| 15 |
+
|
| 16 |
+
this->m_mixingEfficiency = (float)atof(oneRow->at(TILLAGE_PARAMETER_INDEX_EFFMIX).c_str());
|
| 17 |
+
this->m_mixingDepth = (float)atof(oneRow->at(TILLAGE_PARAMETER_INDEX_DEPTIL).c_str());
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
TillageParameter::~TillageParameter(void)
|
| 22 |
+
{
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
void TillageParameter::Dump(ostream* fs)
|
| 26 |
+
{
|
| 27 |
+
if(fs == NULL) return;
|
| 28 |
+
|
| 29 |
+
ArealParameter::Dump(fs);
|
| 30 |
+
|
| 31 |
+
*fs << "EFFMIX:" << this->m_mixingEfficiency << endl;
|
| 32 |
+
*fs << "DEPTIL:" << this->m_mixingDepth << endl;
|
| 33 |
+
}
|
pool/shard008/C++/0096715_ast.cpp
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "llvm/ADT/APFloat.h"
|
| 2 |
+
#include "llvm/ADT/STLExtras.h"
|
| 3 |
+
#include "llvm/IR/BasicBlock.h"
|
| 4 |
+
#include "llvm/IR/Constants.h"
|
| 5 |
+
#include "llvm/IR/DerivedTypes.h"
|
| 6 |
+
#include "llvm/IR/Function.h"
|
| 7 |
+
#include "llvm/IR/IRBuilder.h"
|
| 8 |
+
#include "llvm/IR/LLVMContext.h"
|
| 9 |
+
#include "llvm/IR/Module.h"
|
| 10 |
+
#include "llvm/IR/Type.h"
|
| 11 |
+
#include "llvm/IR/Constant.h"
|
| 12 |
+
#include "llvm/IR/Verifier.h"
|
| 13 |
+
#include "ast.hpp"
|
| 14 |
+
#include <iostream>
|
| 15 |
+
|
| 16 |
+
using namespace llvm;
|
| 17 |
+
|
| 18 |
+
NumericLiteralAST::NumericLiteralAST(double v) {
|
| 19 |
+
std::cout << "Numeric value " << v << std::endl;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
Value *NumericLiteralAST::codegen(LLVMContext context) {
|
| 23 |
+
return ConstantFP::get(context, APFloat(value));
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
VariableDeclarationAST::VariableDeclarationAST(std::map<std::string, double> symbolTable, std::string identifier, double val) {
|
| 27 |
+
variableIdentifier = identifier;
|
| 28 |
+
table = symbolTable;
|
| 29 |
+
symbolTable[identifier] = ConstantFP::get(Type::TypeID::FloatTyID, APFloat(val));;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
Value *VariableDeclarationAST::codegen(LLVMContext context) {
|
| 33 |
+
return table[variableIdentifier];
|
| 34 |
+
}
|
pool/shard008/C++/0096717_database.cpp
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "database.h"
|
| 2 |
+
|
| 3 |
+
#include <QCoreApplication>
|
| 4 |
+
#include <QDebug>
|
| 5 |
+
#include <QSqlError>
|
| 6 |
+
#include <QStandardPaths>
|
| 7 |
+
#include <QVariant>
|
| 8 |
+
|
| 9 |
+
Database::Database(QObject *parent)
|
| 10 |
+
: QObject(parent),
|
| 11 |
+
m_path(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)),
|
| 12 |
+
m_database(QSqlDatabase::addDatabase("QSQLITE")), m_query(),
|
| 13 |
+
m_database_name("/wordflow.sqlite3") {
|
| 14 |
+
openDatabase();
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
Database::~Database() { m_database.close(); }
|
| 18 |
+
|
| 19 |
+
void Database::openDatabase() {
|
| 20 |
+
if (!m_path.mkpath("."))
|
| 21 |
+
qFatal("Failed to create writable directory at %s",
|
| 22 |
+
qPrintable(m_path.absolutePath()));
|
| 23 |
+
const QString fileName = m_path.absolutePath() + m_database_name;
|
| 24 |
+
m_database.setDatabaseName(fileName);
|
| 25 |
+
if (!m_database.open()) {
|
| 26 |
+
qFatal("No database connection: %s",
|
| 27 |
+
qPrintable(m_database.lastError().text()));
|
| 28 |
+
QFile::remove(fileName);
|
| 29 |
+
QCoreApplication::quit();
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
bool Database::createVocabulary(QString vocabulary, QString description) {
|
| 34 |
+
m_query.prepare(
|
| 35 |
+
"INSERT INTO vocabularies (vocabulary_name, vocabulary_description) "
|
| 36 |
+
"VALUES (:vocabulary, :description)");
|
| 37 |
+
m_query.bindValue(":vocabulary", vocabulary);
|
| 38 |
+
m_query.bindValue(":description", description);
|
| 39 |
+
return m_query.exec();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
bool Database::createWord(QString origin, QString translated,
|
| 43 |
+
int vocabulary_id) {
|
| 44 |
+
m_query.prepare("INSERT INTO words (vocabulary, origin, translated) "
|
| 45 |
+
"VALUES (:vocabulary, :origin, :translated)");
|
| 46 |
+
m_query.bindValue(":vocabulary", vocabulary_id);
|
| 47 |
+
m_query.bindValue(":origin", origin);
|
| 48 |
+
m_query.bindValue(":translated", translated);
|
| 49 |
+
return m_query.exec();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
bool Database::updateWord(int word_id, QString origin, QString translated) {
|
| 53 |
+
m_query.prepare("UPDATE words SET origin = :origin, translated = :translated "
|
| 54 |
+
"WHERE id = :word_id");
|
| 55 |
+
m_query.bindValue(":origin", origin);
|
| 56 |
+
m_query.bindValue(":translated", translated);
|
| 57 |
+
m_query.bindValue(":word_id", word_id);
|
| 58 |
+
return m_query.exec();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
bool Database::deleteWord(int word_id) {
|
| 62 |
+
m_query.prepare("DELETE FROM words WHERE id = :word_id");
|
| 63 |
+
m_query.bindValue(":word_id", word_id);
|
| 64 |
+
return m_query.exec();
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
bool Database::deleteAll(int vocabulary_id) {
|
| 68 |
+
m_query.prepare("DELETE FROM words WHERE vocabulary = :vocabulary_id");
|
| 69 |
+
m_query.bindValue(":vocabulary_id", vocabulary_id);
|
| 70 |
+
return m_query.exec();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
bool Database::updateProgress(int word_id, int progress) {
|
| 74 |
+
m_query.prepare("UPDATE words SET progress = :progress "
|
| 75 |
+
"WHERE id = :word_id");
|
| 76 |
+
m_query.bindValue(":progress", progress);
|
| 77 |
+
m_query.bindValue(":word_id", word_id);
|
| 78 |
+
return m_query.exec();
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
bool Database::resetProgresses(int vocabulary_id) {
|
| 82 |
+
m_query.prepare("UPDATE words SET progress = 0 "
|
| 83 |
+
"WHERE vocabulary = :vocabulary_id");
|
| 84 |
+
m_query.bindValue(":vocabulary_id", vocabulary_id);
|
| 85 |
+
return m_query.exec();
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
int Database::countWords(int vocabulary_id) {
|
| 89 |
+
QString query =
|
| 90 |
+
"SELECT COUNT(*) FROM words WHERE vocabulary = :vocabulary_id";
|
| 91 |
+
m_query.prepare(query);
|
| 92 |
+
m_query.bindValue(":vocabulary_id", vocabulary_id);
|
| 93 |
+
m_query.exec();
|
| 94 |
+
m_query.next();
|
| 95 |
+
return m_query.value(0).toInt();
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
QVariantList Database::listWords(int vocabulary, int limit, bool sort,
|
| 99 |
+
bool onlyNotCompleted) {
|
| 100 |
+
QString query = "SELECT id, origin, translated, progress FROM words WHERE "
|
| 101 |
+
"vocabulary = :vocabulary ";
|
| 102 |
+
if (onlyNotCompleted)
|
| 103 |
+
query += "AND progress < 100 ";
|
| 104 |
+
if (sort)
|
| 105 |
+
query += "ORDER BY progress ASC ";
|
| 106 |
+
if (limit != std::numeric_limits<int>::max())
|
| 107 |
+
query += "LIMIT :limit";
|
| 108 |
+
|
| 109 |
+
m_query.prepare(query);
|
| 110 |
+
m_query.bindValue(":vocabulary", vocabulary);
|
| 111 |
+
if (limit != std::numeric_limits<int>::max())
|
| 112 |
+
m_query.bindValue(":limit", limit);
|
| 113 |
+
m_query.exec();
|
| 114 |
+
QVariantList word_list;
|
| 115 |
+
while (m_query.next()) {
|
| 116 |
+
int id = m_query.value(0).toInt();
|
| 117 |
+
QString origin = m_query.value(1).toString();
|
| 118 |
+
QString translated = m_query.value(2).toString();
|
| 119 |
+
int progress = m_query.value(3).toInt();
|
| 120 |
+
QVariantMap map = {{"id", id},
|
| 121 |
+
{"origin", origin},
|
| 122 |
+
{"translated", translated},
|
| 123 |
+
{"progress", progress}};
|
| 124 |
+
word_list << QVariant::fromValue(map);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
return word_list;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
QString Database::path() const {
|
| 131 |
+
return m_path.absolutePath() + m_database_name;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
void Database::cleanTables() {
|
| 135 |
+
m_query.exec("SELECT name FROM sqlite_master WHERE type='table'");
|
| 136 |
+
while (m_query.next()) {
|
| 137 |
+
m_query.exec("DROP TABLE " + m_query.value(0).toString());
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
void Database::removeDatabase() {
|
| 142 |
+
m_database.close();
|
| 143 |
+
QFile file(m_path.absolutePath() + m_database_name);
|
| 144 |
+
if (file.exists())
|
| 145 |
+
file.remove();
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
QVariantList Database::listVocabularies() {
|
| 149 |
+
QVariantList vocabulary_list;
|
| 150 |
+
m_query.exec(
|
| 151 |
+
"SELECT id, vocabulary_name, vocabulary_description FROM vocabularies");
|
| 152 |
+
while (m_query.next()) {
|
| 153 |
+
int id = m_query.value(0).toInt();
|
| 154 |
+
QString name = m_query.value(1).toString();
|
| 155 |
+
QString description = m_query.value(2).toString();
|
| 156 |
+
QVariantMap map = {
|
| 157 |
+
{"id", id}, {"name", name}, {"description", description}};
|
| 158 |
+
vocabulary_list << QVariant::fromValue(map);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
return vocabulary_list;
|
| 162 |
+
}
|
pool/shard008/C++/0096720_data_encryption_win_unittest.cc
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "sync/util/data_encryption_win.h"
|
| 6 |
+
|
| 7 |
+
#include <string>
|
| 8 |
+
#include <vector>
|
| 9 |
+
|
| 10 |
+
#include "testing/gtest/include/gtest/gtest.h"
|
| 11 |
+
|
| 12 |
+
using std::string;
|
| 13 |
+
using std::vector;
|
| 14 |
+
|
| 15 |
+
namespace {
|
| 16 |
+
|
| 17 |
+
TEST(SyncDataEncryption, TestEncryptDecryptOfSampleString) {
|
| 18 |
+
vector<uint8> example(EncryptData("example"));
|
| 19 |
+
ASSERT_FALSE(example.empty());
|
| 20 |
+
string result;
|
| 21 |
+
ASSERT_TRUE(DecryptData(example, &result));
|
| 22 |
+
ASSERT_TRUE(result == "example");
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
TEST(SyncDataEncryption, TestDecryptFailure) {
|
| 26 |
+
vector<uint8> example(0, 0);
|
| 27 |
+
string result;
|
| 28 |
+
ASSERT_FALSE(DecryptData(example, &result));
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
} // namespace
|
pool/shard008/C++/0096721_mitkGetSimulationDataNode.cpp
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*===================================================================
|
| 2 |
+
|
| 3 |
+
The Medical Imaging Interaction Toolkit (MITK)
|
| 4 |
+
|
| 5 |
+
Copyright (c) German Cancer Research Center,
|
| 6 |
+
Division of Medical and Biological Informatics.
|
| 7 |
+
All rights reserved.
|
| 8 |
+
|
| 9 |
+
This software is distributed WITHOUT ANY WARRANTY; without
|
| 10 |
+
even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
| 11 |
+
A PARTICULAR PURPOSE.
|
| 12 |
+
|
| 13 |
+
See LICENSE.txt or http://www.mitk.org for details.
|
| 14 |
+
|
| 15 |
+
===================================================================*/
|
| 16 |
+
|
| 17 |
+
#include "mitkGetDataStorage.h"
|
| 18 |
+
#include "mitkGetSimulationDataNode.h"
|
| 19 |
+
#include <mitkNodePredicateDataType.h>
|
| 20 |
+
#include <mitkSimulation.h>
|
| 21 |
+
|
| 22 |
+
mitk::DataNode::Pointer mitk::GetSimulationDataNode(sofa::core::objectmodel::BaseNode::SPtr rootNode)
|
| 23 |
+
{
|
| 24 |
+
if (!rootNode)
|
| 25 |
+
return NULL;
|
| 26 |
+
|
| 27 |
+
DataStorage::Pointer dataStorage = GetDataStorage();
|
| 28 |
+
|
| 29 |
+
if (dataStorage.IsNull())
|
| 30 |
+
return NULL;
|
| 31 |
+
|
| 32 |
+
TNodePredicateDataType<Simulation>::Pointer predicate = TNodePredicateDataType<Simulation>::New();
|
| 33 |
+
DataStorage::SetOfObjects::ConstPointer subset = dataStorage->GetSubset(predicate);
|
| 34 |
+
|
| 35 |
+
for (DataStorage::SetOfObjects::ConstIterator it = subset->Begin(); it != subset->End(); ++it)
|
| 36 |
+
{
|
| 37 |
+
DataNode::Pointer dataNode = it.Value();
|
| 38 |
+
Simulation::Pointer simulation = static_cast<Simulation*>(dataNode->GetData());
|
| 39 |
+
|
| 40 |
+
if (simulation->GetRootNode() == rootNode)
|
| 41 |
+
return dataNode;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
return NULL;
|
| 45 |
+
}
|
pool/shard008/C++/0096722_CWE124_Buffer_Underwrite__malloc_char_ncpy_33.cpp
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE124_Buffer_Underwrite__malloc_char_ncpy_33.cpp
|
| 3 |
+
Label Definition File: CWE124_Buffer_Underwrite__malloc.label.xml
|
| 4 |
+
Template File: sources-sink-33.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 124 Buffer Underwrite
|
| 9 |
+
* BadSource: Set data pointer to before the allocated memory buffer
|
| 10 |
+
* GoodSource: Set data pointer to the allocated memory buffer
|
| 11 |
+
* Sinks: ncpy
|
| 12 |
+
* BadSink : Copy string to data using strncpy
|
| 13 |
+
* Flow Variant: 33 Data flow: use of a C++ reference to data within the same function
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
|
| 17 |
+
#include "std_testcase.h"
|
| 18 |
+
|
| 19 |
+
#include <wchar.h>
|
| 20 |
+
|
| 21 |
+
namespace CWE124_Buffer_Underwrite__malloc_char_ncpy_33
|
| 22 |
+
{
|
| 23 |
+
|
| 24 |
+
#ifndef OMITBAD
|
| 25 |
+
|
| 26 |
+
void bad()
|
| 27 |
+
{
|
| 28 |
+
char * data;
|
| 29 |
+
char * &dataRef = data;
|
| 30 |
+
data = NULL;
|
| 31 |
+
{
|
| 32 |
+
char * dataBuffer = (char *)malloc(100*sizeof(char));
|
| 33 |
+
memset(dataBuffer, 'A', 100-1);
|
| 34 |
+
dataBuffer[100-1] = '\0';
|
| 35 |
+
/* FLAW: Set data pointer to before the allocated memory buffer */
|
| 36 |
+
data = dataBuffer - 8;
|
| 37 |
+
}
|
| 38 |
+
{
|
| 39 |
+
char * data = dataRef;
|
| 40 |
+
{
|
| 41 |
+
char source[100];
|
| 42 |
+
memset(source, 'C', 100-1); /* fill with 'C's */
|
| 43 |
+
source[100-1] = '\0'; /* null terminate */
|
| 44 |
+
/* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
|
| 45 |
+
strncpy(data, source, 100-1);
|
| 46 |
+
/* Ensure the destination buffer is null terminated */
|
| 47 |
+
data[100-1] = '\0';
|
| 48 |
+
printLine(data);
|
| 49 |
+
/* INCIDENTAL CWE-401: Memory Leak - data may not point to location
|
| 50 |
+
* returned by malloc() so can't safely call free() on it */
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
#endif /* OMITBAD */
|
| 56 |
+
|
| 57 |
+
#ifndef OMITGOOD
|
| 58 |
+
|
| 59 |
+
/* goodG2B() uses the GoodSource with the BadSink */
|
| 60 |
+
static void goodG2B()
|
| 61 |
+
{
|
| 62 |
+
char * data;
|
| 63 |
+
char * &dataRef = data;
|
| 64 |
+
data = NULL;
|
| 65 |
+
{
|
| 66 |
+
char * dataBuffer = (char *)malloc(100*sizeof(char));
|
| 67 |
+
memset(dataBuffer, 'A', 100-1);
|
| 68 |
+
dataBuffer[100-1] = '\0';
|
| 69 |
+
/* FIX: Set data pointer to the allocated memory buffer */
|
| 70 |
+
data = dataBuffer;
|
| 71 |
+
}
|
| 72 |
+
{
|
| 73 |
+
char * data = dataRef;
|
| 74 |
+
{
|
| 75 |
+
char source[100];
|
| 76 |
+
memset(source, 'C', 100-1); /* fill with 'C's */
|
| 77 |
+
source[100-1] = '\0'; /* null terminate */
|
| 78 |
+
/* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
|
| 79 |
+
strncpy(data, source, 100-1);
|
| 80 |
+
/* Ensure the destination buffer is null terminated */
|
| 81 |
+
data[100-1] = '\0';
|
| 82 |
+
printLine(data);
|
| 83 |
+
/* INCIDENTAL CWE-401: Memory Leak - data may not point to location
|
| 84 |
+
* returned by malloc() so can't safely call free() on it */
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void good()
|
| 90 |
+
{
|
| 91 |
+
goodG2B();
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
#endif /* OMITGOOD */
|
| 95 |
+
|
| 96 |
+
} /* close namespace */
|
| 97 |
+
|
| 98 |
+
/* Below is the main(). It is only used when building this testcase on
|
| 99 |
+
* its own for testing or for building a binary to use in testing binary
|
| 100 |
+
* analysis tools. It is not used when compiling all the testcases as one
|
| 101 |
+
* application, which is how source code analysis tools are tested.
|
| 102 |
+
*/
|
| 103 |
+
#ifdef INCLUDEMAIN
|
| 104 |
+
|
| 105 |
+
using namespace CWE124_Buffer_Underwrite__malloc_char_ncpy_33; /* so that we can use good and bad easily */
|
| 106 |
+
|
| 107 |
+
int main(int argc, char * argv[])
|
| 108 |
+
{
|
| 109 |
+
/* seed randomness */
|
| 110 |
+
srand( (unsigned)time(NULL) );
|
| 111 |
+
#ifndef OMITGOOD
|
| 112 |
+
printLine("Calling good()...");
|
| 113 |
+
good();
|
| 114 |
+
printLine("Finished good()");
|
| 115 |
+
#endif /* OMITGOOD */
|
| 116 |
+
#ifndef OMITBAD
|
| 117 |
+
printLine("Calling bad()...");
|
| 118 |
+
bad();
|
| 119 |
+
printLine("Finished bad()");
|
| 120 |
+
#endif /* OMITBAD */
|
| 121 |
+
return 0;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
#endif
|
pool/shard008/C++/0096727_correctiq_swapiq_impl.cc
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- c++ -*- */
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2020 Free Software Foundation, Inc.
|
| 4 |
+
*
|
| 5 |
+
* This file is part of GNU Radio
|
| 6 |
+
*
|
| 7 |
+
* SPDX-License-Identifier: GPL-3.0-or-later
|
| 8 |
+
*
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#ifdef HAVE_CONFIG_H
|
| 12 |
+
#include "config.h"
|
| 13 |
+
#endif
|
| 14 |
+
|
| 15 |
+
#include "correctiq_swapiq_impl.h"
|
| 16 |
+
#include <gnuradio/io_signature.h>
|
| 17 |
+
|
| 18 |
+
namespace gr {
|
| 19 |
+
namespace blocks {
|
| 20 |
+
|
| 21 |
+
swap_iq::sptr swap_iq::make(int datatype, int datasize)
|
| 22 |
+
{
|
| 23 |
+
return gnuradio::get_initial_sptr(new swap_iq_impl(datatype, datasize));
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/*
|
| 27 |
+
* The private constructor
|
| 28 |
+
*/
|
| 29 |
+
swap_iq_impl::swap_iq_impl(int datatype, int datasize)
|
| 30 |
+
: gr::sync_block("swap_iq",
|
| 31 |
+
gr::io_signature::make(1, 1, datasize),
|
| 32 |
+
gr::io_signature::make(1, 1, datasize)),
|
| 33 |
+
d_datatype(datatype)
|
| 34 |
+
{
|
| 35 |
+
if (d_datatype != SWAPTYPE_FLOATCOMPLEX) {
|
| 36 |
+
gr::block::set_output_multiple(2); // Make sure we work with pairs
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
/*
|
| 41 |
+
* Our virtual destructor.
|
| 42 |
+
*/
|
| 43 |
+
swap_iq_impl::~swap_iq_impl() {}
|
| 44 |
+
|
| 45 |
+
int swap_iq_impl::work(int noutput_items,
|
| 46 |
+
gr_vector_const_void_star& input_items,
|
| 47 |
+
gr_vector_void_star& output_items)
|
| 48 |
+
{
|
| 49 |
+
// Constructor guarantees we'll have pairs.
|
| 50 |
+
|
| 51 |
+
long i;
|
| 52 |
+
long noi;
|
| 53 |
+
|
| 54 |
+
switch (d_datatype) {
|
| 55 |
+
case SWAPTYPE_FLOATCOMPLEX: {
|
| 56 |
+
noi = noutput_items * 2; // Each complex is 2 floats
|
| 57 |
+
const float* in_float = (const float*)input_items[0];
|
| 58 |
+
float* out_float = (float*)output_items[0];
|
| 59 |
+
|
| 60 |
+
for (i = 0; i < noi; i += 2) {
|
| 61 |
+
*out_float++ = in_float[i + 1];
|
| 62 |
+
*out_float++ = in_float[i];
|
| 63 |
+
}
|
| 64 |
+
} break;
|
| 65 |
+
case SWAPTYPE_SHORTCOMPLEX: {
|
| 66 |
+
noi = noutput_items;
|
| 67 |
+
const int16_t* in_short = (const int16_t*)input_items[0];
|
| 68 |
+
int16_t* out_short = (int16_t*)output_items[0];
|
| 69 |
+
|
| 70 |
+
for (i = 0; i < noi; i += 2) {
|
| 71 |
+
*out_short++ = in_short[i + 1];
|
| 72 |
+
*out_short++ = in_short[i];
|
| 73 |
+
}
|
| 74 |
+
} break;
|
| 75 |
+
case SWAPTYPE_BYTECOMPLEX: {
|
| 76 |
+
noi = noutput_items;
|
| 77 |
+
const char* in_byte = (const char*)input_items[0];
|
| 78 |
+
char* out_byte = (char*)output_items[0];
|
| 79 |
+
|
| 80 |
+
for (i = 0; i < noi; i += 2) {
|
| 81 |
+
*out_byte++ = in_byte[i + 1];
|
| 82 |
+
*out_byte++ = in_byte[i];
|
| 83 |
+
}
|
| 84 |
+
} break;
|
| 85 |
+
default: {
|
| 86 |
+
GR_LOG_ERROR(d_logger, "Unknown data type. Bytes not swapped.");
|
| 87 |
+
return WORK_DONE;
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// Tell runtime system how many output items we produced.
|
| 92 |
+
return noutput_items;
|
| 93 |
+
}
|
| 94 |
+
} /* namespace blocks */
|
| 95 |
+
} /* namespace gr */
|
pool/shard008/C++/0096731_LinkParserImpl.cpp
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "stdafx.h"
|
| 2 |
+
#include "LinkParserImpl.h"
|
| 3 |
+
|
| 4 |
+
#include "ParserUtil.h"
|
| 5 |
+
#include "../../ui/NLink.h"
|
| 6 |
+
|
| 7 |
+
IMPLEMENT_REFLECTION(LinkParserImpl);
|
| 8 |
+
|
| 9 |
+
using namespace nui;
|
| 10 |
+
using namespace Ui;
|
| 11 |
+
using namespace Base;
|
| 12 |
+
using namespace Data;
|
| 13 |
+
|
| 14 |
+
LinkParserImpl::LinkParserImpl()
|
| 15 |
+
{
|
| 16 |
+
creator_ = &NBaseParser::BaseCreator<NLink>;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
bool LinkParserImpl::IsCorrectObj(nui::Base::NBaseObj* targetObj)
|
| 20 |
+
{
|
| 21 |
+
return targetObj != NULL && dynamic_cast<NLink*>(targetObj) != NULL;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
void LinkParserImpl::FillAttr(nui::Base::NBaseObj* targetObj, nui::Data::NDataReader* styleNode)
|
| 25 |
+
{
|
| 26 |
+
__super::FillAttr(targetObj, styleNode);
|
| 27 |
+
|
| 28 |
+
NString tmpString;
|
| 29 |
+
NLink* targetLink = dynamic_cast<NLink*>(targetObj);
|
| 30 |
+
|
| 31 |
+
if(styleNode->ReadValue(_T("url"), tmpString))
|
| 32 |
+
targetLink->SetUrl(tmpString);
|
| 33 |
+
}
|
pool/shard008/C++/0096738_zhtmllistmodel.cpp
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/******************************************************************************
|
| 2 |
+
* This file is part of Zee.
|
| 3 |
+
*
|
| 4 |
+
* Zee 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 3 of the License, or
|
| 7 |
+
* (at your option) any later version.
|
| 8 |
+
*
|
| 9 |
+
* Zee 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 Zee. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
+
******************************************************************************/
|
| 17 |
+
|
| 18 |
+
#include "zhtmllistmodel.h"
|
| 19 |
+
|
| 20 |
+
ZHTMLListModel::ZHTMLListModel(QObject *parent)
|
| 21 |
+
: QAbstractListModel(parent)
|
| 22 |
+
{
|
| 23 |
+
init();
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
ZHTMLListModel::ZHTMLListModel(QUrl base, QObject *parent)
|
| 27 |
+
: QAbstractListModel(parent){
|
| 28 |
+
setBaseUrl(base);
|
| 29 |
+
init();
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void ZHTMLListModel::init(){
|
| 33 |
+
_matchRx.setPattern(ZHTML_LIST_DEFAULT_MATCH_RX);
|
| 34 |
+
_excludeRx.setPattern(ZHTML_LIST_DEFAULT_EXCLD_RX);
|
| 35 |
+
|
| 36 |
+
connect(&_net, SIGNAL(finished(QNetworkReply*)),
|
| 37 |
+
this, SLOT(_finished(QNetworkReply*)));
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
void ZHTMLListModel::setBaseUrl(QUrl base){
|
| 41 |
+
_base = base;
|
| 42 |
+
fetchBase();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void ZHTMLListModel::setMatchExpression(QRegExp rx){
|
| 46 |
+
if(rx.isValid())
|
| 47 |
+
_matchRx = rx;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
void ZHTMLListModel::setMatchExpression(QString rx){
|
| 51 |
+
QRegExp trx(rx);
|
| 52 |
+
if(trx.isValid())
|
| 53 |
+
_matchRx = trx;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
void ZHTMLListModel::setExcludeExpression(QRegExp rx){
|
| 57 |
+
if(rx.isValid())
|
| 58 |
+
_excludeRx = rx;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void ZHTMLListModel::setExcludeExpression(QString rx){
|
| 62 |
+
QRegExp erx(rx);
|
| 63 |
+
if(erx.isValid())
|
| 64 |
+
_excludeRx = erx;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
int ZHTMLListModel::rowCount(const QModelIndex &parent) const{
|
| 69 |
+
return _data.size();
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
QVariant ZHTMLListModel::data(const QModelIndex &index, int role) const{
|
| 73 |
+
if(!index.isValid())
|
| 74 |
+
return QVariant();
|
| 75 |
+
if(index.row() >= _data.size())
|
| 76 |
+
return QVariant();
|
| 77 |
+
|
| 78 |
+
switch(role){
|
| 79 |
+
case Qt::DisplayRole:
|
| 80 |
+
return _labels.value(_data.at(index.row()));
|
| 81 |
+
case Qt::UserRole+1:
|
| 82 |
+
return _data.at(index.row());
|
| 83 |
+
default:
|
| 84 |
+
return QVariant();
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
QVariant ZHTMLListModel::headerData(int section,
|
| 89 |
+
Qt::Orientation orientation,
|
| 90 |
+
int role) const{
|
| 91 |
+
return QVariant("__HEADER__");
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
void ZHTMLListModel::fetchBase(){
|
| 95 |
+
if(_base.isValid()){
|
| 96 |
+
_data.clear();
|
| 97 |
+
_labels.clear();
|
| 98 |
+
|
| 99 |
+
if(_cache.contains(_base.toString())){
|
| 100 |
+
_processReplyData(_cache.value(_base.toString()));
|
| 101 |
+
}else{
|
| 102 |
+
QNetworkRequest req;
|
| 103 |
+
req.setUrl(_base);
|
| 104 |
+
downloadStarted();
|
| 105 |
+
_net.get(req);
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
void ZHTMLListModel::_finished(QNetworkReply *r){
|
| 111 |
+
|
| 112 |
+
if(!r->error()){
|
| 113 |
+
QString data(r->readAll());
|
| 114 |
+
_cache.insert(_base.toString(), data);
|
| 115 |
+
_processReplyData(data);
|
| 116 |
+
}else{
|
| 117 |
+
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
r->deleteLater();
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
void ZHTMLListModel::_downloadProgress(qint64 in, qint64 total){
|
| 124 |
+
qreal perc = (100.0 / total) * in;
|
| 125 |
+
emit downloadProgress(perc);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
void ZHTMLListModel::_processReplyData(QString data){
|
| 129 |
+
int pos = 0;
|
| 130 |
+
while( (pos = _matchRx.indexIn(data,pos)) != -1){
|
| 131 |
+
QString d = _matchRx.cap(1);
|
| 132 |
+
QUrl du;
|
| 133 |
+
|
| 134 |
+
if(_excludeRx.isValid() && _excludeRx.indexIn(d) == -1){
|
| 135 |
+
du.setUrl(d);
|
| 136 |
+
if(d[0]=='/')
|
| 137 |
+
du = _base.scheme()+"://"+_base.authority()+d;
|
| 138 |
+
else if(QUrl(d).isRelative())
|
| 139 |
+
du = _base.toString()+d;
|
| 140 |
+
|
| 141 |
+
qDebug() << "URL: " << du.toString();
|
| 142 |
+
_data.append(du.toString());
|
| 143 |
+
_labels.insert(du.toString(), du.toString());
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
pos += _matchRx.matchedLength();
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
reset();
|
| 150 |
+
downloadFinished();
|
| 151 |
+
}
|
pool/shard008/C++/0096740_examples.cpp
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2015-2019 The Bitcoin Core developers
|
| 2 |
+
// Distributed under the MIT software license, see the accompanying
|
| 3 |
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 4 |
+
|
| 5 |
+
#include <bench/bench.h>
|
| 6 |
+
#include <util/time.h>
|
| 7 |
+
|
| 8 |
+
// Sanity test: this should loop ten times, and
|
| 9 |
+
// min/max/average should be close to 100ms.
|
| 10 |
+
static void Sleep100ms(benchmark::State& state)
|
| 11 |
+
{
|
| 12 |
+
while (state.KeepRunning()) {
|
| 13 |
+
MilliSleep(100);
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
BENCHMARK(Sleep100ms, 10);
|
| 18 |
+
|
| 19 |
+
// Extremely fast-running benchmark:
|
| 20 |
+
#include <math.h>
|
| 21 |
+
|
| 22 |
+
volatile double sum = 0.0; // volatile, global so not optimized away
|
| 23 |
+
|
| 24 |
+
static void Trig(benchmark::State& state)
|
| 25 |
+
{
|
| 26 |
+
double d = 0.01;
|
| 27 |
+
while (state.KeepRunning()) {
|
| 28 |
+
sum += sin(d);
|
| 29 |
+
d += 0.000001;
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
BENCHMARK(Trig, 12 * 1000 * 1000);
|
pool/shard008/C++/0096741_SignatureBuilder.cpp
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <QCryptographicHash>
|
| 2 |
+
|
| 3 |
+
#include "SignatureBuilder.h"
|
| 4 |
+
|
| 5 |
+
SignatureBuilder::SignatureBuilder(const QByteArray &secret)
|
| 6 |
+
: m_secret(secret)
|
| 7 |
+
{
|
| 8 |
+
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
void SignatureBuilder::setParameters(const QList<as::KeyValue> &values)
|
| 12 |
+
{
|
| 13 |
+
for(const as::KeyValue &value : values)
|
| 14 |
+
{
|
| 15 |
+
m_parameters << value.asJoined();
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
QString SignatureBuilder::signature() const
|
| 20 |
+
{
|
| 21 |
+
const QByteArray &joined = m_parameters
|
| 22 |
+
.join(QString::null)
|
| 23 |
+
.toUtf8();
|
| 24 |
+
|
| 25 |
+
const QByteArray &hash = QCryptographicHash::hash(joined + m_secret, QCryptographicHash::Md5);
|
| 26 |
+
const QByteArray &hex = hash.toHex();
|
| 27 |
+
|
| 28 |
+
return hex;
|
| 29 |
+
}
|
pool/shard008/C++/0096747_CPStringTools.cpp
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "CPStringTools.hpp"
|
| 2 |
+
#include <string>
|
| 3 |
+
#include <vector>
|
| 4 |
+
#include <stdio.h>
|
| 5 |
+
#include <string.h>
|
| 6 |
+
|
| 7 |
+
#include <stdarg.h>
|
| 8 |
+
#include <stdlib.h>
|
| 9 |
+
|
| 10 |
+
#include "wiiu/types.h"
|
| 11 |
+
|
| 12 |
+
bool CPStringTools::EndsWith(const std::string& a, const std::string& b) {
|
| 13 |
+
if (b.size() > a.size()) return false;
|
| 14 |
+
return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
std::vector<std::string> CPStringTools::StringSplit(const std::string & inValue, const std::string & splitter){
|
| 18 |
+
std::string value = inValue;
|
| 19 |
+
std::vector<std::string> result;
|
| 20 |
+
while (true) {
|
| 21 |
+
u32 index = value.find(splitter);
|
| 22 |
+
if (index == std::string::npos) {
|
| 23 |
+
result.push_back(value);
|
| 24 |
+
break;
|
| 25 |
+
}
|
| 26 |
+
std::string first = value.substr(0, index);
|
| 27 |
+
result.push_back(first);
|
| 28 |
+
if (index + splitter.size() == value.length()) {
|
| 29 |
+
result.push_back("");
|
| 30 |
+
break;
|
| 31 |
+
}
|
| 32 |
+
if(index + splitter.size() > value.length()) {
|
| 33 |
+
break;
|
| 34 |
+
}
|
| 35 |
+
value = value.substr(index + splitter.size(), value.length());
|
| 36 |
+
}
|
| 37 |
+
return result;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
const char * CPStringTools::byte_to_binary(s32 x){
|
| 41 |
+
static char b[9];
|
| 42 |
+
b[0] = '\0';
|
| 43 |
+
|
| 44 |
+
s32 z;
|
| 45 |
+
for (z = 128; z > 0; z >>= 1)
|
| 46 |
+
{
|
| 47 |
+
strcat(b, ((x & z) == z) ? "1" : "0");
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
return b;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
std::string CPStringTools::removeCharFromString(std::string& input,char toBeRemoved){
|
| 54 |
+
std::string output = input;
|
| 55 |
+
size_t position;
|
| 56 |
+
while(1){
|
| 57 |
+
position = output.find(toBeRemoved);
|
| 58 |
+
if(position == std::string::npos)
|
| 59 |
+
break;
|
| 60 |
+
output.erase(position, 1);
|
| 61 |
+
}
|
| 62 |
+
return output;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
std::string CPStringTools::strfmt(const char * format, ...){
|
| 67 |
+
std::string str;
|
| 68 |
+
char * tmp = NULL;
|
| 69 |
+
|
| 70 |
+
va_list va;
|
| 71 |
+
va_start(va, format);
|
| 72 |
+
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
| 73 |
+
{
|
| 74 |
+
str = tmp;
|
| 75 |
+
}
|
| 76 |
+
va_end(va);
|
| 77 |
+
|
| 78 |
+
if(tmp){
|
| 79 |
+
free(tmp);
|
| 80 |
+
tmp = NULL;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
return str;
|
| 84 |
+
}
|
| 85 |
+
//CPStringTools
|
pool/shard008/C++/0096748_chordsdescriptors.cpp
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2006-2021 Music Technology Group - Universitat Pompeu Fabra
|
| 3 |
+
*
|
| 4 |
+
* This file is part of Essentia
|
| 5 |
+
*
|
| 6 |
+
* Essentia is free software: you can redistribute it and/or modify it under
|
| 7 |
+
* the terms of the GNU Affero General Public License as published by the Free
|
| 8 |
+
* Software Foundation (FSF), either version 3 of the License, or (at your
|
| 9 |
+
* option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* This program is distributed in the hope that it will be useful, but WITHOUT
|
| 12 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
| 13 |
+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
| 14 |
+
* details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the Affero GNU General Public License
|
| 17 |
+
* version 3 along with this program. If not, see http://www.gnu.org/licenses/
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "chordsdescriptors.h"
|
| 21 |
+
#include "stringutil.h"
|
| 22 |
+
|
| 23 |
+
using namespace std;
|
| 24 |
+
|
| 25 |
+
namespace essentia {
|
| 26 |
+
namespace standard {
|
| 27 |
+
|
| 28 |
+
const char* ChordsDescriptors::name = "ChordsDescriptors";
|
| 29 |
+
const char* ChordsDescriptors::category = "Tonal";
|
| 30 |
+
const char* ChordsDescriptors::description = DOC("Given a chord progression this algorithm describes it by means of key, scale, histogram, and rate of change.\n"
|
| 31 |
+
"Note:\n"
|
| 32 |
+
" - chordsHistogram indexes follow the circle of fifths order, while being shifted to the input key and scale\n"
|
| 33 |
+
" - key and scale are taken from the most frequent chord. In the case where multiple chords are equally frequent, the chord is hierarchically chosen from the circle of fifths.\n"
|
| 34 |
+
" - chords should follow this name convention `<A-G>[<#/b><m>]` (i.e. C, C# or C#m are valid chords). Chord names not fitting this convention will throw an exception.\n"
|
| 35 |
+
"\n"
|
| 36 |
+
"Input chords vector may not be empty, otherwise an exception is thrown.\n"
|
| 37 |
+
"\n"
|
| 38 |
+
"References:\n"
|
| 39 |
+
" [1] Chord progression - Wikipedia, the free encyclopedia,\n"
|
| 40 |
+
" http://en.wikipedia.org/wiki/Chord_progression\n\n"
|
| 41 |
+
" [2] Circle of fifths - Wikipedia, the free encyclopedia,\n"
|
| 42 |
+
" http://en.wikipedia.org/wiki/Circle_of_fifths");
|
| 43 |
+
|
| 44 |
+
const char* ChordsDescriptors::circleOfFifth[] = { "C", "Em", "G", "Bm", "D", "F#m", "A", "C#m", "E", "Abm", "B", "Ebm", "F#", "Bbm", "C#", "Fm", "Ab", "Cm", "Eb", "Gm", "Bb", "Dm", "F", "Am"};
|
| 45 |
+
const char* ChordsDescriptors::circleOfFifthAlternativeNames[] = { "C", "Em", "G", "Bm", "D", "Gbm", "A", "Dbm", "E", "G#m", "B", "D#m", "Gb", "A#m", "Db", "Fm", "G#", "Cm", "D#", "Gm", "A#", "Dm", "F", "Am"};
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
int ChordsDescriptors::chordIndex(const string& chord) {
|
| 50 |
+
for (int i=0; i<int(ARRAY_SIZE(circleOfFifth)); ++i) {
|
| 51 |
+
if (chord == circleOfFifth[i] || chord == circleOfFifthAlternativeNames[i]) {
|
| 52 |
+
return i;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
throw EssentiaException("ChordsDescriptors: Invalid chord: ", chord);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
map<int, Real> ChordsDescriptors::chordsHistogram(const vector<string>& chords) {
|
| 60 |
+
map<int, Real> histogram;
|
| 61 |
+
|
| 62 |
+
// Initialize
|
| 63 |
+
for (int i=0; i<int(ARRAY_SIZE(circleOfFifth)); ++i) {
|
| 64 |
+
histogram[i] = 0.0;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// Increment
|
| 68 |
+
for (int i=0; i<int(chords.size()); ++i) {
|
| 69 |
+
histogram[chordIndex(chords[i])] += 1.0;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
// Normalize
|
| 73 |
+
for (int i=0; i<int(histogram.size()); ++i) {
|
| 74 |
+
histogram[i] *= 100.0 / (Real)chords.size();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
return histogram;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
// offset the list of indices making key as the root index (or 0-index)
|
| 82 |
+
map<int, Real> ChordsDescriptors::chordsHistogramNorm(map<int, Real>& histogram, const string& key) {
|
| 83 |
+
int keyIndex = chordIndex(key);
|
| 84 |
+
map<int, Real> histogramNorm = histogram;
|
| 85 |
+
|
| 86 |
+
for (int i=0; i<int(histogramNorm.size()); ++i) {
|
| 87 |
+
int chordIndex = i - keyIndex;
|
| 88 |
+
if (chordIndex < 0) {
|
| 89 |
+
chordIndex += ARRAY_SIZE(circleOfFifth);
|
| 90 |
+
}
|
| 91 |
+
histogramNorm[chordIndex] = histogram[i];
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
return histogramNorm;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
void ChordsDescriptors::compute() {
|
| 99 |
+
const vector<string>& chords = _chords.get();
|
| 100 |
+
|
| 101 |
+
if (chords.empty()) {
|
| 102 |
+
throw EssentiaException("ChordsDescriptors: Chords input empty");
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
string key = _key.get();
|
| 106 |
+
|
| 107 |
+
if (key.empty()) {
|
| 108 |
+
throw EssentiaException("ChordsDescriptors: Key input empty");
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
key[0] = toUpper(string(1, key[0]))[0];
|
| 112 |
+
|
| 113 |
+
string scale = toLower(_scale.get());
|
| 114 |
+
|
| 115 |
+
if (scale.empty()) {
|
| 116 |
+
throw EssentiaException("ChordsDescriptors: Scale input empty");
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
if (_scale.get() == "minor") {
|
| 120 |
+
key += "m";
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// Chords Histogram
|
| 124 |
+
map<int, Real> chordsHist = chordsHistogram(chords);
|
| 125 |
+
map<int, Real> chordsHistNorm = chordsHistogramNorm(chordsHist, key);
|
| 126 |
+
|
| 127 |
+
vector<Real>& chordsHistNormVect = _chordsHistogram.get();
|
| 128 |
+
chordsHistNormVect.resize(0); // erase anything that was in there
|
| 129 |
+
for (int i=0; i<int(ARRAY_SIZE(circleOfFifth)); ++i) {
|
| 130 |
+
chordsHistNormVect.push_back(chordsHistNorm[i]);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
// Chords Number Rate
|
| 134 |
+
Real& chordNumberRate = _chordsNumberRate.get();
|
| 135 |
+
chordNumberRate = 0.0;
|
| 136 |
+
for (int i=0; i<int(chordsHistNormVect.size()); ++i) {
|
| 137 |
+
if (chordsHistNormVect[i] > 1.0) {
|
| 138 |
+
chordNumberRate += 1.0;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
chordNumberRate /= (Real)chords.size();
|
| 142 |
+
|
| 143 |
+
// Chords Changes Rate
|
| 144 |
+
Real& chordChangesRate = _chordsChangesRate.get();
|
| 145 |
+
chordChangesRate = 0.0;
|
| 146 |
+
for (int i=1; i<int(chords.size()); ++i) {
|
| 147 |
+
if (chords[i] != chords[i-1]) {
|
| 148 |
+
chordChangesRate += 1.0;
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
chordChangesRate /= (Real)chords.size();
|
| 152 |
+
|
| 153 |
+
// Chords Key and Scale = most frequent chord
|
| 154 |
+
string& chordsKey = _chordsKey.get();
|
| 155 |
+
string& chordsScale = _chordsScale.get();
|
| 156 |
+
chordsKey = "A";
|
| 157 |
+
Real maxValue = 0.0;
|
| 158 |
+
|
| 159 |
+
for (int i=0; i<int(ARRAY_SIZE(circleOfFifth)); ++i) {
|
| 160 |
+
if (chordsHist[i] > maxValue) {
|
| 161 |
+
maxValue = chordsHist[i];
|
| 162 |
+
chordsKey = circleOfFifth[i];
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
bool major = true;
|
| 167 |
+
string::size_type position = chordsKey.find("m");
|
| 168 |
+
|
| 169 |
+
if ((position == 1) || (position == 2)) {
|
| 170 |
+
major = false;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
if (major) {
|
| 174 |
+
chordsKey = chordsKey;
|
| 175 |
+
chordsScale = "major";
|
| 176 |
+
}
|
| 177 |
+
else {
|
| 178 |
+
chordsKey = chordsKey.substr(0, position);
|
| 179 |
+
chordsScale = "minor";
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
} // namespace standard
|
| 184 |
+
} // namespace essentia
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
namespace essentia {
|
| 189 |
+
namespace streaming {
|
| 190 |
+
|
| 191 |
+
const char* ChordsDescriptors::name = standard::ChordsDescriptors::name;
|
| 192 |
+
const char* ChordsDescriptors::description = standard::ChordsDescriptors::description;
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
AlgorithmStatus ChordsDescriptors::process() {
|
| 196 |
+
// this could be implemented as a composite, but it is kept like this for
|
| 197 |
+
// historical and demonstrations reasons
|
| 198 |
+
while (_chords.acquire(1)) {
|
| 199 |
+
_accu.push_back(*(std::string*)_chords.getFirstToken());
|
| 200 |
+
_chords.release(1);
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
if (!shouldStop()) return PASS;
|
| 204 |
+
|
| 205 |
+
// make sure we have one value for key and scale
|
| 206 |
+
if (!_key.acquire(1) || !_scale.acquire(1)) {
|
| 207 |
+
return NO_INPUT;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
standard::Algorithm* algo = _chordsAlgo;
|
| 211 |
+
string key = *(string*)_key.getFirstToken();
|
| 212 |
+
string scale = *(string*)_scale.getFirstToken();
|
| 213 |
+
vector<Real> chordsHist;
|
| 214 |
+
Real cnr, ccr;
|
| 215 |
+
string ckey, cscale;
|
| 216 |
+
|
| 217 |
+
algo->input("chords").set(_accu);
|
| 218 |
+
algo->input("key").set(key);
|
| 219 |
+
algo->input("scale").set(scale);
|
| 220 |
+
algo->output("chordsHistogram").set(chordsHist);
|
| 221 |
+
algo->output("chordsNumberRate").set(cnr);
|
| 222 |
+
algo->output("chordsChangesRate").set(ccr);
|
| 223 |
+
algo->output("chordsKey").set(ckey);
|
| 224 |
+
algo->output("chordsScale").set(cscale);
|
| 225 |
+
algo->compute();
|
| 226 |
+
|
| 227 |
+
_chordsHistogram.push(chordsHist);
|
| 228 |
+
_chordsNumberRate.push(cnr);
|
| 229 |
+
_chordsChangesRate.push(ccr);
|
| 230 |
+
_chordsKey.push(ckey);
|
| 231 |
+
_chordsScale.push(cscale);
|
| 232 |
+
|
| 233 |
+
return FINISHED;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
void ChordsDescriptors::reset() {
|
| 237 |
+
Algorithm::reset();
|
| 238 |
+
_accu.clear();
|
| 239 |
+
if (_chordsAlgo) _chordsAlgo->reset();
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
} // namespace streaming
|
| 244 |
+
} // namespace essentia
|
pool/shard008/C++/0096750_web_task_runner_impl.cc
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "components/scheduler/child/web_task_runner_impl.h"
|
| 6 |
+
|
| 7 |
+
#include "base/bind.h"
|
| 8 |
+
#include "base/location.h"
|
| 9 |
+
#include "components/scheduler/base/task_queue.h"
|
| 10 |
+
#include "components/scheduler/base/time_domain.h"
|
| 11 |
+
#include "third_party/WebKit/public/platform/WebTraceLocation.h"
|
| 12 |
+
|
| 13 |
+
namespace scheduler {
|
| 14 |
+
|
| 15 |
+
WebTaskRunnerImpl::WebTaskRunnerImpl(scoped_refptr<TaskQueue> task_queue)
|
| 16 |
+
: task_queue_(task_queue) {}
|
| 17 |
+
|
| 18 |
+
WebTaskRunnerImpl::~WebTaskRunnerImpl() {}
|
| 19 |
+
|
| 20 |
+
void WebTaskRunnerImpl::postTask(const blink::WebTraceLocation& web_location,
|
| 21 |
+
blink::WebTaskRunner::Task* task) {
|
| 22 |
+
tracked_objects::Location location(web_location.functionName(),
|
| 23 |
+
web_location.fileName(), -1, nullptr);
|
| 24 |
+
task_queue_->PostTask(
|
| 25 |
+
location,
|
| 26 |
+
base::Bind(
|
| 27 |
+
&WebTaskRunnerImpl::runTask,
|
| 28 |
+
base::Passed(std::unique_ptr<blink::WebTaskRunner::Task>(task))));
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
void WebTaskRunnerImpl::postDelayedTask(
|
| 32 |
+
const blink::WebTraceLocation& web_location,
|
| 33 |
+
blink::WebTaskRunner::Task* task,
|
| 34 |
+
double delayMs) {
|
| 35 |
+
DCHECK_GE(delayMs, 0.0);
|
| 36 |
+
tracked_objects::Location location(web_location.functionName(),
|
| 37 |
+
web_location.fileName(), -1, nullptr);
|
| 38 |
+
task_queue_->PostDelayedTask(
|
| 39 |
+
location,
|
| 40 |
+
base::Bind(
|
| 41 |
+
&WebTaskRunnerImpl::runTask,
|
| 42 |
+
base::Passed(std::unique_ptr<blink::WebTaskRunner::Task>(task))),
|
| 43 |
+
base::TimeDelta::FromMillisecondsD(delayMs));
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
double WebTaskRunnerImpl::virtualTimeSeconds() const {
|
| 47 |
+
return (Now() - base::TimeTicks::UnixEpoch()).InSecondsF();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
double WebTaskRunnerImpl::monotonicallyIncreasingVirtualTimeSeconds() const {
|
| 51 |
+
return Now().ToInternalValue() /
|
| 52 |
+
static_cast<double>(base::Time::kMicrosecondsPerSecond);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
base::TimeTicks WebTaskRunnerImpl::Now() const {
|
| 56 |
+
TimeDomain* time_domain = task_queue_->GetTimeDomain();
|
| 57 |
+
// It's possible task_queue_ has been Unregistered which can lead to a null
|
| 58 |
+
// TimeDomain. If that happens just return the current real time.
|
| 59 |
+
if (!time_domain)
|
| 60 |
+
return base::TimeTicks::Now();
|
| 61 |
+
return time_domain->Now();
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
blink::WebTaskRunner* WebTaskRunnerImpl::clone() {
|
| 65 |
+
return new WebTaskRunnerImpl(task_queue_);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
void WebTaskRunnerImpl::runTask(
|
| 69 |
+
std::unique_ptr<blink::WebTaskRunner::Task> task) {
|
| 70 |
+
task->run();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
} // namespace scheduler
|
pool/shard008/C++/0096756_stylemodel.cpp
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* <one line to give the program's name and a brief idea of what it does.>
|
| 3 |
+
* Copyright (C) 2016 Arek <arek@ag.de1.cc>
|
| 4 |
+
*
|
| 5 |
+
* This program is free software: you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "stylemodel.h"
|
| 21 |
+
#include <QDebug>
|
| 22 |
+
#include <QFile>
|
| 23 |
+
#include <QDir>
|
| 24 |
+
|
| 25 |
+
StyleModel *StyleModel::model;
|
| 26 |
+
|
| 27 |
+
StyleModel::StyleModel()
|
| 28 |
+
{
|
| 29 |
+
loadColors();
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
StyleModel::~StyleModel()
|
| 33 |
+
{
|
| 34 |
+
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void StyleModel::loadColors()
|
| 38 |
+
{
|
| 39 |
+
QFile f(QDir::currentPath() + "/defaultstyles.xml");
|
| 40 |
+
if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
|
| 41 |
+
{
|
| 42 |
+
surpressSignals = true;
|
| 43 |
+
addStyle("default", Qt::black, Qt::white);
|
| 44 |
+
addStyle("black", Qt::white, Qt::black);
|
| 45 |
+
addStyle("lightgray", Qt::black, Qt::lightGray);
|
| 46 |
+
addStyle("darkgray", Qt::white, Qt::darkGray);
|
| 47 |
+
addStyle("brownish", Qt::black, Qt::darkYellow);
|
| 48 |
+
addStyle("cyan", Qt::black, Qt::cyan);
|
| 49 |
+
addStyle("red", Qt::white, Qt::darkRed);
|
| 50 |
+
//addColor("", Qt::, Qt::);
|
| 51 |
+
surpressSignals = false;
|
| 52 |
+
return;
|
| 53 |
+
}
|
| 54 |
+
QXmlStreamReader reader(&f);
|
| 55 |
+
QXmlStreamAttributes attr;
|
| 56 |
+
|
| 57 |
+
while (!reader.atEnd()) {
|
| 58 |
+
reader.readNext();
|
| 59 |
+
if (reader.isStartElement() && reader.name() == "styles")
|
| 60 |
+
loadStyles(reader);
|
| 61 |
+
}
|
| 62 |
+
f.close();
|
| 63 |
+
surpressSignals = false;
|
| 64 |
+
emit stylesChanged(All, nullptr);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
void StyleModel::addStyle(QString name, QColor fg, QColor bg)
|
| 68 |
+
{
|
| 69 |
+
while (styles.contains(name))
|
| 70 |
+
name += "_";
|
| 71 |
+
Style *newStyle = new Style(name, fg, bg);
|
| 72 |
+
styles.insert(name, newStyle);
|
| 73 |
+
stylesByPointer[newStyle] = name;
|
| 74 |
+
if (!surpressSignals)
|
| 75 |
+
emit stylesChanged(StyleModel::New, newStyle);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
void StyleModel::addStyle(Style* style)
|
| 79 |
+
{
|
| 80 |
+
while (styles.contains(style->name))
|
| 81 |
+
style->name += "_";
|
| 82 |
+
styles.insert(style->name, style);
|
| 83 |
+
stylesByPointer[style] = style->name;
|
| 84 |
+
if (!surpressSignals)
|
| 85 |
+
emit stylesChanged(StyleModel::New, style);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
QVariant StyleModel::getBrushV(QString name, int role) const
|
| 90 |
+
{
|
| 91 |
+
if (name == "")
|
| 92 |
+
return getBrushV("default", role);
|
| 93 |
+
QBrush brush;
|
| 94 |
+
if (role == Qt::ForegroundRole)
|
| 95 |
+
brush.setColor(styles[name]->fg.color());
|
| 96 |
+
else
|
| 97 |
+
brush = styles[name]->bg;
|
| 98 |
+
return QVariant(brush);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
QColor StyleModel::getColor(QString name, int role)
|
| 102 |
+
{
|
| 103 |
+
if (name == "")
|
| 104 |
+
return getColor("default", role);
|
| 105 |
+
if (!styles.contains(name)) {
|
| 106 |
+
qDebug() << "no style named " << name;
|
| 107 |
+
return QColor();
|
| 108 |
+
}
|
| 109 |
+
if (role == Qt::ForegroundRole)
|
| 110 |
+
return styles[name]->fg.color();
|
| 111 |
+
else if (role == Qt::BackgroundRole)
|
| 112 |
+
return styles[name]->bg.color();
|
| 113 |
+
else
|
| 114 |
+
qDebug() << "WTF???";
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
void StyleModel::deleteStyle(Style* style)
|
| 118 |
+
{
|
| 119 |
+
if (style->name == "default")
|
| 120 |
+
return;
|
| 121 |
+
if (styles[style->name] == style)
|
| 122 |
+
delete styles.take(style->name);
|
| 123 |
+
else {
|
| 124 |
+
QString name = stylesByPointer[style];
|
| 125 |
+
delete styles.take(name);
|
| 126 |
+
}
|
| 127 |
+
stylesByPointer.remove(style);
|
| 128 |
+
if (!surpressSignals)
|
| 129 |
+
emit stylesChanged(StyleModel::Delete, style);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
void StyleModel::deleteStyle(QString style)
|
| 133 |
+
{
|
| 134 |
+
deleteStyle(styles[style]);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
bool StyleModel::styleChangedOk(Style* style)
|
| 139 |
+
{
|
| 140 |
+
if (styles.value(style->name) == style) {
|
| 141 |
+
if (!surpressSignals)
|
| 142 |
+
emit stylesChanged(StyleModel::Edit, style);
|
| 143 |
+
return true;
|
| 144 |
+
}
|
| 145 |
+
bool result = true;
|
| 146 |
+
while (styles.contains(style->name)) {
|
| 147 |
+
result = false;
|
| 148 |
+
style->name += "_";
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
QString name = stylesByPointer.take(style);
|
| 152 |
+
styles.remove(name);
|
| 153 |
+
styles[style->name] = style;
|
| 154 |
+
stylesByPointer[style] = name;
|
| 155 |
+
if (!surpressSignals)
|
| 156 |
+
emit stylesChanged(StyleModel::Name, style);
|
| 157 |
+
return result;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
QFont StyleModel::getFont(QString name) const
|
| 161 |
+
{
|
| 162 |
+
if (styles.contains(name))
|
| 163 |
+
return styles[name]->font;
|
| 164 |
+
return QFont();
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
bool StyleModel::loadStyles(QXmlStreamReader& reader)
|
| 168 |
+
{
|
| 169 |
+
surpressSignals = true;
|
| 170 |
+
foreach (Style *style, stylesByPointer.keys())
|
| 171 |
+
delete style;
|
| 172 |
+
stylesByPointer.clear();
|
| 173 |
+
styles.clear();
|
| 174 |
+
|
| 175 |
+
QXmlStreamAttributes attr;
|
| 176 |
+
while (!reader.atEnd()) {
|
| 177 |
+
reader.readNext();
|
| 178 |
+
|
| 179 |
+
if (reader.isEndElement() && reader.name() == "styles" )
|
| 180 |
+
break;
|
| 181 |
+
if ( (reader.isEndElement() && reader.name() != "style" )
|
| 182 |
+
|| reader.isEndDocument()) {
|
| 183 |
+
qDebug() << "not ok";
|
| 184 |
+
surpressSignals = false;
|
| 185 |
+
return false;
|
| 186 |
+
}
|
| 187 |
+
if (!reader.isStartElement() || reader.name() != "style")
|
| 188 |
+
continue;
|
| 189 |
+
|
| 190 |
+
attr = reader.attributes();
|
| 191 |
+
Style *style = new Style(
|
| 192 |
+
attr.value("name").toString(),
|
| 193 |
+
QColor(attr.value("fg").toString()),
|
| 194 |
+
QColor(attr.value("bg").toString())
|
| 195 |
+
);
|
| 196 |
+
style->setFont(attr.value("font").toString());
|
| 197 |
+
style->setSize(attr.value("maxFontSize").toDouble());
|
| 198 |
+
addStyle(style);
|
| 199 |
+
}
|
| 200 |
+
surpressSignals = false;
|
| 201 |
+
emit stylesChanged(All, nullptr);
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
void StyleModel::saveStyles(QXmlStreamWriter& writer)
|
| 205 |
+
{
|
| 206 |
+
writer.writeStartElement("styles");
|
| 207 |
+
foreach(Style *style, stylesByPointer.keys()) {
|
| 208 |
+
writer.writeStartElement("style");
|
| 209 |
+
writer.writeAttribute("name", style->name);
|
| 210 |
+
writer.writeAttribute("fg", style->fg.color().name());
|
| 211 |
+
writer.writeAttribute("bg", style->bg.color().name());
|
| 212 |
+
writer.writeAttribute("font", style->font.family());
|
| 213 |
+
writer.writeAttribute("maxFontSize", QString::number(style->font.pointSizeF()));
|
| 214 |
+
writer.writeEndElement();
|
| 215 |
+
}
|
| 216 |
+
writer.writeEndElement();
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
void StyleModel::saveDefaultStyles()
|
| 220 |
+
{
|
| 221 |
+
QFile f(QDir::currentPath() + "/defaultstyles.xml");
|
| 222 |
+
if (!f.open(QIODevice::WriteOnly | QIODevice::Text))
|
| 223 |
+
{
|
| 224 |
+
qDebug() << "could not open \"defaultstyles.xml\" for writing";
|
| 225 |
+
return;
|
| 226 |
+
}
|
| 227 |
+
QXmlStreamWriter writer(&f);
|
| 228 |
+
writer.setAutoFormatting(true);
|
| 229 |
+
writer.writeStartDocument();
|
| 230 |
+
saveStyles(writer);
|
| 231 |
+
writer.writeEndDocument();
|
| 232 |
+
f.close();
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
|
pool/shard008/C++/0096760_Wizard.cc
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "Wizard.hh"
|
| 2 |
+
|
| 3 |
+
Wizard::Wizard(string alias, int wisdom) : Character(alias){
|
| 4 |
+
this->wisdom = wisdom;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
int Wizard::getDefensePts(){
|
| 8 |
+
return (int)Character::getDefensePts()+(wisdom/2);
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
void Wizard::addWisdom(int w){
|
| 12 |
+
wisdom += w;
|
| 13 |
+
if(wisdom>100){wisdom = 100;}
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
bool Wizard::special(Team* team){
|
| 17 |
+
if(MP < 100){return false;}
|
| 18 |
+
MP -= 100-wisdom;
|
| 19 |
+
int i=0;
|
| 20 |
+
while(!team->getChar(i)->isAlive()){i++;}
|
| 21 |
+
team->getChar(i)->receiveDamage(100);
|
| 22 |
+
return true;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
string Wizard::specialDesc(){
|
| 26 |
+
|
| 27 |
+
return "2 - Necromancia: Retira a alma de um oponente. (aprox. -100MP)\n";
|
| 28 |
+
|
| 29 |
+
}
|