Upload folder using huggingface_hub (part 33)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard002/C++/0034609_web_apps.cc +57 -0
- pool/shard002/C++/0034610_ServicePortCollection.cpp +176 -0
- pool/shard002/C++/0034611_qxtpushbutton.cpp +323 -0
- pool/shard002/C++/0034619_http_client.cpp +216 -0
- pool/shard002/C++/0034623_PGLoader.cpp +198 -0
- pool/shard002/C++/0034625_boss_cyanigosa.cpp +188 -0
- pool/shard002/C++/0034631_encoder_containers.cpp +84 -0
- pool/shard002/C++/0034634_AppDefaultIconElement.cpp +93 -0
- pool/shard002/C++/0034638_standalone_example_docs1.cpp +87 -0
- pool/shard002/C++/0034641_main.cc +83 -0
- pool/shard002/C++/0034642_ColourUtils.cpp +76 -0
- pool/shard002/C++/0034643_BigNumber.cpp +206 -0
- pool/shard002/C++/0034649_Process_test.cpp +141 -0
- pool/shard002/C++/0034658_PhyloTree.cpp +326 -0
- pool/shard002/C++/0034662_BitmapWindow.cpp +60 -0
- pool/shard002/C++/0034663_task_scheduler_impl_unittest.cc +263 -0
- pool/shard002/C++/0034682_updategeomatchsetresponse.cpp +121 -0
- pool/shard002/C++/0034688_output_m001u006.cpp +29 -0
- pool/shard002/C++/0034689_emi2.cpp +140 -0
- pool/shard002/C++/0034691_memoryagent.cpp +317 -0
- pool/shard002/C++/0034694_ProcessStartInfoUnitTests.cpp +82 -0
- pool/shard002/C++/0034699_ioutil_test.cpp +20 -0
- pool/shard002/C++/0034704_coincontroltreewidget.cpp +33 -0
- pool/shard002/C++/0034707_CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193_char_memmove_65b.cpp +62 -0
- pool/shard002/C++/0034708_QxSqlLimit.cpp +110 -0
- pool/shard002/C++/0034717_ThirdPartyUtil.cpp +288 -0
- pool/shard002/C++/0034720_juce_ValueWithDefault.cpp +100 -0
- pool/shard002/C++/0034721_file_cache_migrator.cc +148 -0
- pool/shard002/C++/0034728_service_main.cc +46 -0
- pool/shard002/C++/0034732_threadpool.cpp +143 -0
- pool/shard002/C++/0034736_average_of_levels_in_binary_tree.cpp +82 -0
- pool/shard002/C++/0034737_CountVariances.cpp +41 -0
- pool/shard002/C++/0034745_B.cpp +30 -0
- pool/shard002/C++/0034746_flash_pkg.cpp +69 -0
- pool/shard002/C++/0034750_decoder_selector.cc +246 -0
- pool/shard002/C++/0034753_CommandMoveCounterClockwise.cpp +135 -0
- pool/shard002/C++/0034760_DocumentResource.cpp +91 -0
- pool/shard002/C++/0034768_cinteger.cpp +179 -0
- pool/shard002/C++/0034771_WVSShader.cpp +44 -0
- pool/shard002/C++/0034776_77.cpp +61 -0
- pool/shard002/C++/0034779_heapdump.cc +154 -0
- pool/shard002/C++/0034783_qgsmessageviewer.cpp +118 -0
- pool/shard002/C++/0034789_prssrnot.cpp +96 -0
- pool/shard002/C++/0034790_CWE122_Heap_Based_Buffer_Overflow__cpp_dest_wchar_t_cat_72b.cpp +65 -0
- pool/shard002/C++/0034794_TBOX_PREFIX_App.cpp +64 -0
- pool/shard002/C++/0034812_2.17a.cpp +28 -0
- pool/shard002/C++/0034813_sp-canvas-util.cpp +110 -0
- pool/shard002/C++/0034818_high_resolution_timer.cpp +39 -0
- pool/shard002/C++/0034820_suggestions_service_factory.cc +58 -0
- pool/shard002/C++/0034822_SoundRecorder.cpp +203 -0
pool/shard002/C++/0034609_web_apps.cc
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/apps/app_service/web_apps.h"
|
| 6 |
+
|
| 7 |
+
#include "base/bind_helpers.h"
|
| 8 |
+
#include "chrome/browser/profiles/profile.h"
|
| 9 |
+
#include "chrome/browser/ui/web_applications/web_app_dialog_manager.h"
|
| 10 |
+
#include "chrome/browser/ui/web_applications/web_app_ui_manager_impl.h"
|
| 11 |
+
#include "chrome/browser/web_applications/system_web_app_manager.h"
|
| 12 |
+
#include "chrome/browser/web_applications/web_app_provider.h"
|
| 13 |
+
|
| 14 |
+
namespace apps {
|
| 15 |
+
|
| 16 |
+
WebApps::WebApps(const mojo::Remote<apps::mojom::AppService>& app_service,
|
| 17 |
+
Profile* profile)
|
| 18 |
+
: WebAppsBase(app_service, profile) {}
|
| 19 |
+
|
| 20 |
+
WebApps::~WebApps() = default;
|
| 21 |
+
|
| 22 |
+
// static
|
| 23 |
+
void WebApps::UninstallImpl(Profile* profile,
|
| 24 |
+
const std::string& app_id,
|
| 25 |
+
gfx::NativeWindow parent_window) {
|
| 26 |
+
web_app::WebAppUiManagerImpl* web_app_ui_manager =
|
| 27 |
+
web_app::WebAppUiManagerImpl::Get(profile);
|
| 28 |
+
if (!web_app_ui_manager) {
|
| 29 |
+
return;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
web_app::WebAppDialogManager& web_app_dialog_manager =
|
| 33 |
+
web_app_ui_manager->dialog_manager();
|
| 34 |
+
if (web_app_dialog_manager.CanUninstallWebApp(app_id)) {
|
| 35 |
+
web_app_dialog_manager.UninstallWebApp(
|
| 36 |
+
app_id, web_app::WebAppDialogManager::UninstallSource::kAppMenu,
|
| 37 |
+
parent_window, base::DoNothing());
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
apps::mojom::AppPtr WebApps::Convert(const web_app::WebApp* web_app,
|
| 42 |
+
apps::mojom::Readiness readiness) {
|
| 43 |
+
apps::mojom::AppPtr app = ConvertImpl(web_app, readiness);
|
| 44 |
+
|
| 45 |
+
app->icon_key = icon_key_factory().MakeIconKey(GetIconEffects(web_app));
|
| 46 |
+
|
| 47 |
+
app->has_badge = apps::mojom::OptionalBool::kFalse;
|
| 48 |
+
app->paused = apps::mojom::OptionalBool::kFalse;
|
| 49 |
+
|
| 50 |
+
return app;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
bool WebApps::Accepts(const std::string& app_id) {
|
| 54 |
+
return true;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
} // namespace apps
|
pool/shard002/C++/0034610_ServicePortCollection.cpp
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2015 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "config.h"
|
| 6 |
+
#include "modules/navigatorconnect/ServicePortCollection.h"
|
| 7 |
+
|
| 8 |
+
#include "bindings/core/v8/ScriptPromiseResolver.h"
|
| 9 |
+
#include "bindings/core/v8/SerializedScriptValueFactory.h"
|
| 10 |
+
#include "core/dom/DOMException.h"
|
| 11 |
+
#include "core/dom/ExceptionCode.h"
|
| 12 |
+
#include "core/dom/MessagePort.h"
|
| 13 |
+
#include "core/events/MessageEvent.h"
|
| 14 |
+
#include "modules/EventTargetModules.h"
|
| 15 |
+
#include "modules/navigatorconnect/AcceptConnectionObserver.h"
|
| 16 |
+
#include "modules/navigatorconnect/ServicePort.h"
|
| 17 |
+
#include "modules/navigatorconnect/ServicePortConnectEvent.h"
|
| 18 |
+
#include "modules/navigatorconnect/ServicePortConnectEventInit.h"
|
| 19 |
+
#include "modules/navigatorconnect/ServicePortConnectOptions.h"
|
| 20 |
+
#include "public/platform/Platform.h"
|
| 21 |
+
#include "public/platform/modules/navigator_services/WebServicePortProvider.h"
|
| 22 |
+
|
| 23 |
+
namespace blink {
|
| 24 |
+
|
| 25 |
+
namespace {
|
| 26 |
+
|
| 27 |
+
class ConnectCallbacks : public WebServicePortConnectCallbacks {
|
| 28 |
+
public:
|
| 29 |
+
ConnectCallbacks(ScriptPromiseResolver* resolver, ServicePortCollection* collection, const KURL& targetUrl, const String& portName, const String& serializedPortData)
|
| 30 |
+
: m_resolver(resolver), m_collection(collection), m_targetUrl(targetUrl), m_portName(portName), m_serializedPortData(serializedPortData)
|
| 31 |
+
{
|
| 32 |
+
ASSERT(m_resolver);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
~ConnectCallbacks() override { }
|
| 36 |
+
|
| 37 |
+
void onSuccess(WebServicePortID* portIdRaw) override
|
| 38 |
+
{
|
| 39 |
+
OwnPtr<WebServicePortID> webPortId = adoptPtr(portIdRaw);
|
| 40 |
+
if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) {
|
| 41 |
+
return;
|
| 42 |
+
}
|
| 43 |
+
WebServicePort webPort;
|
| 44 |
+
webPort.id = *webPortId;
|
| 45 |
+
webPort.targetUrl = m_targetUrl;
|
| 46 |
+
webPort.name = m_portName;
|
| 47 |
+
webPort.data = m_serializedPortData;
|
| 48 |
+
ServicePort* port = ServicePort::create(m_collection, webPort);
|
| 49 |
+
m_collection->addPort(port);
|
| 50 |
+
m_resolver->resolve(port);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
void onError() override
|
| 54 |
+
{
|
| 55 |
+
// TODO(mek): Pass actual error code back.
|
| 56 |
+
if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) {
|
| 57 |
+
return;
|
| 58 |
+
}
|
| 59 |
+
m_resolver->reject(DOMException::create(AbortError));
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
private:
|
| 63 |
+
Persistent<ScriptPromiseResolver> m_resolver;
|
| 64 |
+
Persistent<ServicePortCollection> m_collection;
|
| 65 |
+
KURL m_targetUrl;
|
| 66 |
+
String m_portName;
|
| 67 |
+
String m_serializedPortData;
|
| 68 |
+
|
| 69 |
+
WTF_MAKE_NONCOPYABLE(ConnectCallbacks);
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
} // namespace
|
| 73 |
+
|
| 74 |
+
ServicePortCollection* ServicePortCollection::create(ExecutionContext* context)
|
| 75 |
+
{
|
| 76 |
+
return new ServicePortCollection(context);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
ServicePortCollection::~ServicePortCollection()
|
| 80 |
+
{
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
void ServicePortCollection::addPort(ServicePort* port)
|
| 84 |
+
{
|
| 85 |
+
m_ports.append(port);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
void ServicePortCollection::closePort(ServicePort* port)
|
| 89 |
+
{
|
| 90 |
+
m_ports.remove(m_ports.find(port));
|
| 91 |
+
if (m_provider)
|
| 92 |
+
m_provider->closePort(port->id());
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
ScriptPromise ServicePortCollection::connect(ScriptState* scriptState, const String& url, const ServicePortConnectOptions& options, ExceptionState& exceptionState)
|
| 96 |
+
{
|
| 97 |
+
if (!m_provider)
|
| 98 |
+
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));
|
| 99 |
+
|
| 100 |
+
RefPtr<SerializedScriptValue> portData;
|
| 101 |
+
if (options.hasData()) {
|
| 102 |
+
portData = SerializedScriptValueFactory::instance().create(options.data().isolate(), options.data(), nullptr, exceptionState);
|
| 103 |
+
if (exceptionState.hadException())
|
| 104 |
+
return exceptionState.reject(scriptState);
|
| 105 |
+
}
|
| 106 |
+
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
|
| 107 |
+
ScriptPromise promise = resolver->promise();
|
| 108 |
+
KURL targetUrl = scriptState->executionContext()->completeURL(url);
|
| 109 |
+
m_provider->connect(
|
| 110 |
+
targetUrl,
|
| 111 |
+
scriptState->executionContext()->securityOrigin()->toString(),
|
| 112 |
+
new ConnectCallbacks(resolver, this, targetUrl, options.name(), portData ? portData->toWireString() : String()));
|
| 113 |
+
return promise;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
ScriptPromise ServicePortCollection::match(ScriptState* scriptState, const ServicePortMatchOptions& options)
|
| 117 |
+
{
|
| 118 |
+
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
ScriptPromise ServicePortCollection::matchAll(ScriptState* scriptState, const ServicePortMatchOptions& options)
|
| 122 |
+
{
|
| 123 |
+
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
const AtomicString& ServicePortCollection::interfaceName() const
|
| 127 |
+
{
|
| 128 |
+
return EventTargetNames::ServicePortCollection;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
ExecutionContext* ServicePortCollection::executionContext() const
|
| 132 |
+
{
|
| 133 |
+
return ContextLifecycleObserver::executionContext();
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
void ServicePortCollection::postMessage(WebServicePortID portId, const WebString& messageString, const WebMessagePortChannelArray& webChannels)
|
| 137 |
+
{
|
| 138 |
+
OwnPtr<MessagePortChannelArray> channels;
|
| 139 |
+
if (webChannels.size()) {
|
| 140 |
+
channels = adoptPtr(new MessagePortChannelArray(webChannels.size()));
|
| 141 |
+
for (size_t i = 0; i < webChannels.size(); ++i)
|
| 142 |
+
(*channels)[i] = adoptPtr(webChannels[i]);
|
| 143 |
+
}
|
| 144 |
+
RefPtr<SerializedScriptValue> message = SerializedScriptValueFactory::instance().createFromWire(messageString);
|
| 145 |
+
|
| 146 |
+
MessagePortArray* ports = MessagePort::entanglePorts(*executionContext(), channels.release());
|
| 147 |
+
RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports, message.release());
|
| 148 |
+
// TODO(mek): Lookup ServicePort and set events source attribute.
|
| 149 |
+
dispatchEvent(evt.release());
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
void ServicePortCollection::dispatchConnectEvent(PassOwnPtr<WebServicePortConnectEventCallbacks> callbacks, const WebURL& targetURL, const WebString& origin, WebServicePortID portID)
|
| 153 |
+
{
|
| 154 |
+
AcceptConnectionObserver* observer = AcceptConnectionObserver::create(this, callbacks, portID, targetURL);
|
| 155 |
+
ServicePortConnectEventInit init;
|
| 156 |
+
init.setTargetURL(targetURL.string());
|
| 157 |
+
init.setOrigin(origin);
|
| 158 |
+
RefPtrWillBeRawPtr<Event> event = ServicePortConnectEvent::create(EventTypeNames::connect, init, observer);
|
| 159 |
+
dispatchEvent(event.release());
|
| 160 |
+
observer->didDispatchEvent();
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
DEFINE_TRACE(ServicePortCollection)
|
| 164 |
+
{
|
| 165 |
+
visitor->trace(m_ports);
|
| 166 |
+
RefCountedGarbageCollectedEventTargetWithInlineData<ServicePortCollection>::trace(visitor);
|
| 167 |
+
ContextLifecycleObserver::trace(visitor);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
ServicePortCollection::ServicePortCollection(ExecutionContext* context)
|
| 171 |
+
: ContextLifecycleObserver(context)
|
| 172 |
+
, m_provider(adoptPtr(Platform::current()->createServicePortProvider(this)))
|
| 173 |
+
{
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
} // namespace blink
|
pool/shard002/C++/0034611_qxtpushbutton.cpp
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "qxtpushbutton.h"
|
| 2 |
+
/****************************************************************************
|
| 3 |
+
** Copyright (c) 2006 - 2011, the LibQxt project.
|
| 4 |
+
** See the Qxt AUTHORS file for a list of authors and copyright holders.
|
| 5 |
+
** All rights reserved.
|
| 6 |
+
**
|
| 7 |
+
** Redistribution and use in source and binary forms, with or without
|
| 8 |
+
** modification, are permitted provided that the following conditions are met:
|
| 9 |
+
** * Redistributions of source code must retain the above copyright
|
| 10 |
+
** notice, this list of conditions and the following disclaimer.
|
| 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 |
+
** * Neither the name of the LibQxt project nor the
|
| 15 |
+
** names of its contributors may be used to endorse or promote products
|
| 16 |
+
** derived from this software without specific prior written permission.
|
| 17 |
+
**
|
| 18 |
+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 19 |
+
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 20 |
+
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 21 |
+
** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
| 22 |
+
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 23 |
+
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 25 |
+
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 26 |
+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 27 |
+
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 28 |
+
**
|
| 29 |
+
** <http://libqxt.org> <foundation@libqxt.org>
|
| 30 |
+
*****************************************************************************/
|
| 31 |
+
|
| 32 |
+
#include <QAbstractTextDocumentLayout>
|
| 33 |
+
#include <QStyleOptionButton>
|
| 34 |
+
#include <QTextDocument>
|
| 35 |
+
#include <QStylePainter>
|
| 36 |
+
#include <QStyle>
|
| 37 |
+
#include <QMenu>
|
| 38 |
+
|
| 39 |
+
static const int Vertical_Mask = 0x02;
|
| 40 |
+
|
| 41 |
+
class QxtPushButtonPrivate : public QxtPrivate<QxtPushButton>
|
| 42 |
+
{
|
| 43 |
+
public:
|
| 44 |
+
QXT_DECLARE_PUBLIC(QxtPushButton)
|
| 45 |
+
QxtPushButtonPrivate();
|
| 46 |
+
|
| 47 |
+
bool isRichText() const;
|
| 48 |
+
QStyleOptionButton getStyleOption() const;
|
| 49 |
+
|
| 50 |
+
QString text;
|
| 51 |
+
Qxt::Rotation rot;
|
| 52 |
+
Qt::TextFormat format;
|
| 53 |
+
mutable QTextDocument* doc;
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
QxtPushButtonPrivate::QxtPushButtonPrivate() :
|
| 57 |
+
rot(Qxt::NoRotation), format(Qt::PlainText), doc(0)
|
| 58 |
+
{
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
bool QxtPushButtonPrivate::isRichText() const
|
| 62 |
+
{
|
| 63 |
+
bool rich = (format == Qt::RichText) || (format == Qt::AutoText && Qt::mightBeRichText(qxt_p().text()));
|
| 64 |
+
if (rich && !doc)
|
| 65 |
+
{
|
| 66 |
+
doc = new QTextDocument(const_cast<QxtPushButton*>(&qxt_p()));
|
| 67 |
+
doc->setUndoRedoEnabled(false);
|
| 68 |
+
}
|
| 69 |
+
return rich;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
QStyleOptionButton QxtPushButtonPrivate::getStyleOption() const
|
| 73 |
+
{
|
| 74 |
+
QStyleOptionButton option;
|
| 75 |
+
option.initFrom(&qxt_p());
|
| 76 |
+
if (rot & Vertical_Mask)
|
| 77 |
+
{
|
| 78 |
+
QSize size = option.rect.size();
|
| 79 |
+
size.transpose();
|
| 80 |
+
option.rect.setSize(size);
|
| 81 |
+
}
|
| 82 |
+
option.features = QStyleOptionButton::None;
|
| 83 |
+
if (qxt_p().isFlat())
|
| 84 |
+
option.features |= QStyleOptionButton::Flat;
|
| 85 |
+
if (qxt_p().menu())
|
| 86 |
+
option.features |= QStyleOptionButton::HasMenu;
|
| 87 |
+
if (qxt_p().autoDefault() || qxt_p().isDefault())
|
| 88 |
+
option.features |= QStyleOptionButton::AutoDefaultButton;
|
| 89 |
+
if (qxt_p().isDefault())
|
| 90 |
+
option.features |= QStyleOptionButton::DefaultButton;
|
| 91 |
+
if (qxt_p().isDown() || (qxt_p().menu() && qxt_p().menu()->isVisible()))
|
| 92 |
+
option.state |= QStyle::State_Sunken;
|
| 93 |
+
if (qxt_p().isChecked())
|
| 94 |
+
option.state |= QStyle::State_On;
|
| 95 |
+
if (!qxt_p().isFlat() && !qxt_p().isDown())
|
| 96 |
+
option.state |= QStyle::State_Raised;
|
| 97 |
+
if (!isRichText())
|
| 98 |
+
{
|
| 99 |
+
option.text = qxt_p().text();
|
| 100 |
+
option.icon = qxt_p().icon();
|
| 101 |
+
option.iconSize = qxt_p().iconSize();
|
| 102 |
+
}
|
| 103 |
+
return option;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/*!
|
| 107 |
+
\class QxtPushButton
|
| 108 |
+
\inmodule QxtWidgets
|
| 109 |
+
\brief The QxtPushButton widget is an extended QPushButton with rotation and rich text support.
|
| 110 |
+
|
| 111 |
+
QxtPushButton is a QPushButton which can be rotated. In addition, QxtPushButton
|
| 112 |
+
provides rich text support.
|
| 113 |
+
|
| 114 |
+
\image qxtpushbutton.png "QxtPushButton in action."
|
| 115 |
+
*/
|
| 116 |
+
|
| 117 |
+
/*!
|
| 118 |
+
Constructs a new QxtPushButton with \a parent.
|
| 119 |
+
*/
|
| 120 |
+
QxtPushButton::QxtPushButton(QWidget* parent) : QPushButton(parent)
|
| 121 |
+
{
|
| 122 |
+
QXT_INIT_PRIVATE(QxtPushButton);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/*!
|
| 126 |
+
Constructs a new QxtPushButton with \a text and \a parent.
|
| 127 |
+
*/
|
| 128 |
+
QxtPushButton::QxtPushButton(const QString& text, QWidget* parent) : QPushButton(text, parent)
|
| 129 |
+
{
|
| 130 |
+
QXT_INIT_PRIVATE(QxtPushButton);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/*!
|
| 134 |
+
Constructs a new QxtPushButton with \a icon, \a text and \a parent.
|
| 135 |
+
|
| 136 |
+
\bold {Note:} An icon is not rendered when using rich text.
|
| 137 |
+
*/
|
| 138 |
+
QxtPushButton::QxtPushButton(const QIcon& icon, const QString& text, QWidget* parent) : QPushButton(icon, text, parent)
|
| 139 |
+
{
|
| 140 |
+
QXT_INIT_PRIVATE(QxtPushButton);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/*!
|
| 144 |
+
Constructs a new QxtPushButton with \a rotation, \a text and \a parent.
|
| 145 |
+
*/
|
| 146 |
+
QxtPushButton::QxtPushButton(Qxt::Rotation rotation, const QString& text, QWidget* parent) : QPushButton(text, parent)
|
| 147 |
+
{
|
| 148 |
+
QXT_INIT_PRIVATE(QxtPushButton);
|
| 149 |
+
setRotation(rotation);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/*!
|
| 153 |
+
Destructs the button.
|
| 154 |
+
*/
|
| 155 |
+
QxtPushButton::~QxtPushButton()
|
| 156 |
+
{}
|
| 157 |
+
|
| 158 |
+
/*!
|
| 159 |
+
\property QxtPushButton::rotation
|
| 160 |
+
\brief the rotation of the button
|
| 161 |
+
|
| 162 |
+
The button is rotated according to this property.
|
| 163 |
+
The default value is Qxt::NoRotation.
|
| 164 |
+
|
| 165 |
+
\sa Qxt::Rotation
|
| 166 |
+
*/
|
| 167 |
+
Qxt::Rotation QxtPushButton::rotation() const
|
| 168 |
+
{
|
| 169 |
+
return qxt_d().rot;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
void QxtPushButton::setRotation(Qxt::Rotation rotation)
|
| 173 |
+
{
|
| 174 |
+
if (qxt_d().rot != rotation)
|
| 175 |
+
{
|
| 176 |
+
qxt_d().rot = rotation;
|
| 177 |
+
switch (rotation)
|
| 178 |
+
{
|
| 179 |
+
case Qxt::NoRotation:
|
| 180 |
+
case Qxt::UpsideDown:
|
| 181 |
+
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
| 182 |
+
break;
|
| 183 |
+
|
| 184 |
+
case Qxt::Clockwise:
|
| 185 |
+
case Qxt::CounterClockwise:
|
| 186 |
+
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
|
| 187 |
+
break;
|
| 188 |
+
|
| 189 |
+
default:
|
| 190 |
+
// nothing to do
|
| 191 |
+
break;
|
| 192 |
+
}
|
| 193 |
+
updateGeometry();
|
| 194 |
+
update();
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/*!
|
| 199 |
+
\property QxtPushButton::textFormat
|
| 200 |
+
\brief the text format of the button
|
| 201 |
+
|
| 202 |
+
Supported formats are Qt::PlainText, Qt::RichText and Qt::AutoText.
|
| 203 |
+
|
| 204 |
+
The default format is Qt::PlainText.
|
| 205 |
+
|
| 206 |
+
\sa Qt::TextFormat
|
| 207 |
+
*/
|
| 208 |
+
Qt::TextFormat QxtPushButton::textFormat() const
|
| 209 |
+
{
|
| 210 |
+
return qxt_d().format;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
void QxtPushButton::setTextFormat(Qt::TextFormat format)
|
| 214 |
+
{
|
| 215 |
+
if (qxt_d().format != format)
|
| 216 |
+
{
|
| 217 |
+
qxt_d().format = format;
|
| 218 |
+
if (!qxt_d().isRichText())
|
| 219 |
+
{
|
| 220 |
+
delete qxt_d().doc;
|
| 221 |
+
qxt_d().doc = 0;
|
| 222 |
+
}
|
| 223 |
+
qxt_d().text.clear();
|
| 224 |
+
update();
|
| 225 |
+
updateGeometry();
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
/*!
|
| 230 |
+
\reimp
|
| 231 |
+
*/
|
| 232 |
+
QSize QxtPushButton::sizeHint() const
|
| 233 |
+
{
|
| 234 |
+
QSize size;
|
| 235 |
+
if (qxt_d().isRichText())
|
| 236 |
+
size = qxt_d().doc->documentLayout()->documentSize().toSize();
|
| 237 |
+
else
|
| 238 |
+
size = QPushButton::sizeHint();
|
| 239 |
+
|
| 240 |
+
if (qxt_d().rot & Vertical_Mask)
|
| 241 |
+
size.transpose();
|
| 242 |
+
return size;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
/*!
|
| 246 |
+
\reimp
|
| 247 |
+
*/
|
| 248 |
+
QSize QxtPushButton::minimumSizeHint() const
|
| 249 |
+
{
|
| 250 |
+
return sizeHint();
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
/*!
|
| 254 |
+
\reimp
|
| 255 |
+
*/
|
| 256 |
+
void QxtPushButton::paintEvent(QPaintEvent* event)
|
| 257 |
+
{
|
| 258 |
+
Q_UNUSED(event);
|
| 259 |
+
|
| 260 |
+
// the only reliable way to detect text changes
|
| 261 |
+
if (text() != qxt_d().text)
|
| 262 |
+
{
|
| 263 |
+
qxt_d().text = text();
|
| 264 |
+
if (qxt_d().isRichText())
|
| 265 |
+
qxt_d().doc->setHtml(qxt_d().text);
|
| 266 |
+
updateGeometry();
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
QStylePainter painter(this);
|
| 270 |
+
painter.rotate(qxt_d().rot);
|
| 271 |
+
switch (qxt_d().rot)
|
| 272 |
+
{
|
| 273 |
+
case Qxt::UpsideDown:
|
| 274 |
+
painter.translate(-width(), -height());
|
| 275 |
+
break;
|
| 276 |
+
|
| 277 |
+
case Qxt::Clockwise:
|
| 278 |
+
painter.translate(0, -width());
|
| 279 |
+
break;
|
| 280 |
+
|
| 281 |
+
case Qxt::CounterClockwise:
|
| 282 |
+
painter.translate(-height(), 0);
|
| 283 |
+
break;
|
| 284 |
+
|
| 285 |
+
default:
|
| 286 |
+
// nothing to do
|
| 287 |
+
break;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
const QStyleOptionButton option = qxt_d().getStyleOption();
|
| 291 |
+
painter.drawControl(QStyle::CE_PushButton, option);
|
| 292 |
+
|
| 293 |
+
if (qxt_d().isRichText())
|
| 294 |
+
{
|
| 295 |
+
int dx = 0;
|
| 296 |
+
int dy = 0;
|
| 297 |
+
if (option.state & (QStyle::State_On | QStyle::State_Sunken))
|
| 298 |
+
{
|
| 299 |
+
dx += style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal, &option, this);
|
| 300 |
+
dy += style()->pixelMetric(QStyle::PM_ButtonShiftVertical, &option, this);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
QRect area = rect();
|
| 304 |
+
const QSizeF docSize = qxt_d().doc->documentLayout()->documentSize();
|
| 305 |
+
if (qxt_d().rot & Vertical_Mask)
|
| 306 |
+
{
|
| 307 |
+
dx += static_cast<int>((height() - docSize.width()) / 2);
|
| 308 |
+
dy += static_cast<int>((width() - docSize.height()) / 2);
|
| 309 |
+
painter.translate(dx, dy);
|
| 310 |
+
|
| 311 |
+
QSize size = area.size();
|
| 312 |
+
size.transpose();
|
| 313 |
+
area.setSize(size);
|
| 314 |
+
}
|
| 315 |
+
else
|
| 316 |
+
{
|
| 317 |
+
dx += static_cast<int>((width() - docSize.width()) / 2);
|
| 318 |
+
dy += static_cast<int>((height() - docSize.height()) / 2);
|
| 319 |
+
painter.translate(dx, dy);
|
| 320 |
+
}
|
| 321 |
+
qxt_d().doc->drawContents(&painter, area);
|
| 322 |
+
}
|
| 323 |
+
}
|
pool/shard002/C++/0034619_http_client.cpp
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "platform/http_client.hpp"
|
| 2 |
+
|
| 3 |
+
#include "coding/base64.hpp"
|
| 4 |
+
|
| 5 |
+
#include "base/string_utils.hpp"
|
| 6 |
+
|
| 7 |
+
#include <sstream>
|
| 8 |
+
|
| 9 |
+
using namespace std;
|
| 10 |
+
|
| 11 |
+
namespace platform
|
| 12 |
+
{
|
| 13 |
+
HttpClient::HttpClient(string const & url) : m_urlRequested(url)
|
| 14 |
+
{
|
| 15 |
+
// Http client for linux supports only "deflate" encoding, but osrm server cannot
|
| 16 |
+
// correctly process "Accept-Encoding: deflate" header, so do not encode data on linux.
|
| 17 |
+
#if !defined(OMIM_OS_LINUX)
|
| 18 |
+
m_headers.emplace("Accept-Encoding", "gzip, deflate");
|
| 19 |
+
#endif
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
bool HttpClient::RunHttpRequest(string & response, SuccessChecker checker /* = nullptr */)
|
| 23 |
+
{
|
| 24 |
+
static auto const simpleChecker = [](HttpClient const & request)
|
| 25 |
+
{
|
| 26 |
+
return request.ErrorCode() == 200;
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
if (checker == nullptr)
|
| 30 |
+
checker = simpleChecker;
|
| 31 |
+
|
| 32 |
+
if (RunHttpRequest() && checker(*this))
|
| 33 |
+
{
|
| 34 |
+
response = ServerResponse();
|
| 35 |
+
return true;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
return false;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
HttpClient & HttpClient::SetUrlRequested(string const & url)
|
| 42 |
+
{
|
| 43 |
+
m_urlRequested = url;
|
| 44 |
+
return *this;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
HttpClient & HttpClient::SetHttpMethod(string const & method)
|
| 48 |
+
{
|
| 49 |
+
m_httpMethod = method;
|
| 50 |
+
return *this;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
HttpClient & HttpClient::SetBodyFile(string const & body_file, string const & content_type,
|
| 54 |
+
string const & http_method /* = "POST" */,
|
| 55 |
+
string const & content_encoding /* = "" */)
|
| 56 |
+
{
|
| 57 |
+
m_inputFile = body_file;
|
| 58 |
+
m_bodyData.clear();
|
| 59 |
+
m_headers.emplace("Content-Type", content_type);
|
| 60 |
+
m_httpMethod = http_method;
|
| 61 |
+
m_headers.emplace("Content-Encoding", content_encoding);
|
| 62 |
+
return *this;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
HttpClient & HttpClient::SetReceivedFile(string const & received_file)
|
| 66 |
+
{
|
| 67 |
+
m_outputFile = received_file;
|
| 68 |
+
return *this;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
HttpClient & HttpClient::SetUserAndPassword(string const & user, string const & password)
|
| 72 |
+
{
|
| 73 |
+
m_headers.emplace("Authorization", "Basic " + base64::Encode(user + ":" + password));
|
| 74 |
+
return *this;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
HttpClient & HttpClient::SetCookies(string const & cookies)
|
| 78 |
+
{
|
| 79 |
+
m_cookies = cookies;
|
| 80 |
+
return *this;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
HttpClient & HttpClient::SetHandleRedirects(bool handle_redirects)
|
| 84 |
+
{
|
| 85 |
+
m_handleRedirects = handle_redirects;
|
| 86 |
+
return *this;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
HttpClient & HttpClient::SetRawHeader(string const & key, string const & value)
|
| 90 |
+
{
|
| 91 |
+
m_headers.emplace(key, value);
|
| 92 |
+
return *this;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
HttpClient & HttpClient::SetRawHeaders(Headers const & headers)
|
| 96 |
+
{
|
| 97 |
+
m_headers.insert(headers.begin(), headers.end());
|
| 98 |
+
return *this;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
void HttpClient::SetTimeout(double timeoutSec)
|
| 102 |
+
{
|
| 103 |
+
m_timeoutSec = timeoutSec;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
string const & HttpClient::UrlRequested() const
|
| 107 |
+
{
|
| 108 |
+
return m_urlRequested;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
string const & HttpClient::UrlReceived() const
|
| 112 |
+
{
|
| 113 |
+
return m_urlReceived;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
bool HttpClient::WasRedirected() const
|
| 117 |
+
{
|
| 118 |
+
return m_urlRequested != m_urlReceived;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
int HttpClient::ErrorCode() const
|
| 122 |
+
{
|
| 123 |
+
return m_errorCode;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
string const & HttpClient::ServerResponse() const
|
| 127 |
+
{
|
| 128 |
+
return m_serverResponse;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
string const & HttpClient::HttpMethod() const
|
| 132 |
+
{
|
| 133 |
+
return m_httpMethod;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
string HttpClient::CombinedCookies() const
|
| 137 |
+
{
|
| 138 |
+
string serverCookies;
|
| 139 |
+
auto const it = m_headers.find("Set-Cookie");
|
| 140 |
+
if (it != m_headers.end())
|
| 141 |
+
serverCookies = it->second;
|
| 142 |
+
|
| 143 |
+
if (serverCookies.empty())
|
| 144 |
+
return m_cookies;
|
| 145 |
+
|
| 146 |
+
if (m_cookies.empty())
|
| 147 |
+
return serverCookies;
|
| 148 |
+
|
| 149 |
+
return serverCookies + "; " + m_cookies;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
string HttpClient::CookieByName(string name) const
|
| 153 |
+
{
|
| 154 |
+
string const str = CombinedCookies();
|
| 155 |
+
name += "=";
|
| 156 |
+
auto const cookie = str.find(name);
|
| 157 |
+
auto const eq = cookie + name.size();
|
| 158 |
+
if (cookie != string::npos && str.size() > eq)
|
| 159 |
+
return str.substr(eq, str.find(';', eq) - eq);
|
| 160 |
+
|
| 161 |
+
return {};
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
void HttpClient::LoadHeaders(bool loadHeaders)
|
| 165 |
+
{
|
| 166 |
+
m_loadHeaders = loadHeaders;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
HttpClient::Headers const & HttpClient::GetHeaders() const
|
| 170 |
+
{
|
| 171 |
+
return m_headers;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
// static
|
| 175 |
+
string HttpClient::NormalizeServerCookies(string && cookies)
|
| 176 |
+
{
|
| 177 |
+
istringstream is(cookies);
|
| 178 |
+
string str, result;
|
| 179 |
+
|
| 180 |
+
// Split by ", ". Can have invalid tokens here, expires= can also contain a comma.
|
| 181 |
+
while (getline(is, str, ','))
|
| 182 |
+
{
|
| 183 |
+
size_t const leading = str.find_first_not_of(" ");
|
| 184 |
+
if (leading != string::npos)
|
| 185 |
+
str.substr(leading).swap(str);
|
| 186 |
+
|
| 187 |
+
// In the good case, we have '=' and it goes before any ' '.
|
| 188 |
+
auto const eq = str.find('=');
|
| 189 |
+
if (eq == string::npos)
|
| 190 |
+
continue; // It's not a cookie: no valid key value pair.
|
| 191 |
+
|
| 192 |
+
auto const sp = str.find(' ');
|
| 193 |
+
if (sp != string::npos && eq > sp)
|
| 194 |
+
continue; // It's not a cookie: comma in expires date.
|
| 195 |
+
|
| 196 |
+
// Insert delimiter.
|
| 197 |
+
if (!result.empty())
|
| 198 |
+
result.append("; ");
|
| 199 |
+
|
| 200 |
+
// Read cookie itself.
|
| 201 |
+
result.append(str, 0, str.find(";"));
|
| 202 |
+
}
|
| 203 |
+
return result;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
string DebugPrint(HttpClient const & request)
|
| 207 |
+
{
|
| 208 |
+
ostringstream ostr;
|
| 209 |
+
ostr << "HTTP " << request.ErrorCode() << " url [" << request.UrlRequested() << "]";
|
| 210 |
+
if (request.WasRedirected())
|
| 211 |
+
ostr << " was redirected to [" << request.UrlReceived() << "]";
|
| 212 |
+
if (!request.ServerResponse().empty())
|
| 213 |
+
ostr << " response: " << request.ServerResponse();
|
| 214 |
+
return ostr.str();
|
| 215 |
+
}
|
| 216 |
+
} // namespace platform
|
pool/shard002/C++/0034623_PGLoader.cpp
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2011-2021 FlylinkDC++ Team http://flylinkdc.com
|
| 3 |
+
*
|
| 4 |
+
* This program is free software; you can redistribute it and/or modify
|
| 5 |
+
* it under the terms of the GNU General Public License as published by
|
| 6 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 7 |
+
* (at your option) any later version.
|
| 8 |
+
*
|
| 9 |
+
* This program is distributed in the hope that it will be useful,
|
| 10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
* GNU General Public License for more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License
|
| 15 |
+
* along with this program; if not, write to the Free Software
|
| 16 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
#include "stdinc.h"
|
| 20 |
+
|
| 21 |
+
#include "PGLoader.h"
|
| 22 |
+
#include "ResourceManager.h"
|
| 23 |
+
#include "File.h"
|
| 24 |
+
#include "IpGuard.h"
|
| 25 |
+
#include "SettingsManager.h"
|
| 26 |
+
#include "../windows/resource.h"
|
| 27 |
+
|
| 28 |
+
#ifdef FLYLINKDC_USE_IPFILTER
|
| 29 |
+
|
| 30 |
+
FastCriticalSection PGLoader::g_cs;
|
| 31 |
+
IPList PGLoader::g_ipTrustListAllow;
|
| 32 |
+
IPList PGLoader::g_ipTrustListBlock;
|
| 33 |
+
|
| 34 |
+
void PGLoader::load(const string& p_data /*= BaseUtil::emptyString*/)
|
| 35 |
+
{
|
| 36 |
+
string l_data;
|
| 37 |
+
const string l_url = SETTING(URL_IPTRUST);
|
| 38 |
+
bool l_is_download = false;
|
| 39 |
+
CFlyLog l_IPTrust_log("[IPTrust]");
|
| 40 |
+
if (p_data.empty())
|
| 41 |
+
{
|
| 42 |
+
if (!l_url.empty())
|
| 43 |
+
{
|
| 44 |
+
try
|
| 45 |
+
{
|
| 46 |
+
const string l_log_message = STRING(DOWNLOAD) + ": " + l_url;
|
| 47 |
+
if (Util::getDataFromInet(true, l_url, l_data, 0) == 0)
|
| 48 |
+
{
|
| 49 |
+
l_IPTrust_log.step(l_log_message + " [" + STRING(ERROR_STRING) + ']');
|
| 50 |
+
}
|
| 51 |
+
else
|
| 52 |
+
{
|
| 53 |
+
l_IPTrust_log.step(l_log_message + " [OK]");
|
| 54 |
+
// "ðàñïàðñèì" îòâåò (TODO - ïåðåéòè íà regexp)
|
| 55 |
+
{
|
| 56 |
+
string::size_type linestart = 0;
|
| 57 |
+
string::size_type lineend = 0;
|
| 58 |
+
for (;;)
|
| 59 |
+
{
|
| 60 |
+
lineend = l_data.find('\n', linestart);
|
| 61 |
+
if (lineend == string::npos)
|
| 62 |
+
break;
|
| 63 |
+
const string line = l_data.substr(linestart, lineend - linestart - 1);
|
| 64 |
+
int u1, u2, u3, u4, u5, u6, u7, u8;
|
| 65 |
+
int iItems = sscanf_s(line.c_str(), "%u.%u.%u.%u - %u.%u.%u.%u", &u1, &u2, &u3, &u4, &u5, &u6, &u7, &u8);
|
| 66 |
+
if (iItems == 8 || iItems == 4)
|
| 67 |
+
{
|
| 68 |
+
l_is_download = true;
|
| 69 |
+
break;
|
| 70 |
+
}
|
| 71 |
+
iItems = sscanf_s(line.c_str(), "#%u.%u.%u.%u - %u.%u.%u.%u", &u1, &u2, &u3, &u4, &u5, &u6, &u7, &u8);
|
| 72 |
+
if (iItems == 8 || iItems == 4)
|
| 73 |
+
{
|
| 74 |
+
l_is_download = true;
|
| 75 |
+
break;
|
| 76 |
+
}
|
| 77 |
+
linestart = lineend + 1;
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
if (l_is_download)
|
| 81 |
+
{
|
| 82 |
+
const auto l_IPTrust_ini = getConfigFileName();
|
| 83 |
+
File(l_IPTrust_ini, File::WRITE, File::CREATE | File::TRUNCATE).write(l_data);
|
| 84 |
+
l_IPTrust_log.step(l_IPTrust_ini + " [" + STRING(SAVE) + ']');
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
catch (const FileException& e)
|
| 89 |
+
{
|
| 90 |
+
l_IPTrust_log.step("Can't write IPTrust.ini file: " + e.getError());
|
| 91 |
+
dcdebug("IPTrust::save: %s\n", e.getError().c_str());
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
if (l_data.empty())
|
| 95 |
+
{
|
| 96 |
+
const string l_IPTrust_ini = getConfigFileName();
|
| 97 |
+
if (File::isExist(l_IPTrust_ini))
|
| 98 |
+
{
|
| 99 |
+
try
|
| 100 |
+
{
|
| 101 |
+
l_data = File(l_IPTrust_ini, File::READ, File::OPEN).read();
|
| 102 |
+
}
|
| 103 |
+
catch (const FileException& e)
|
| 104 |
+
{
|
| 105 |
+
l_IPTrust_log.step("Can't read IPTrust.ini file: " + e.getError());
|
| 106 |
+
dcdebug("IPTrust::load: %s\n", e.getError().c_str());
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
else
|
| 110 |
+
{
|
| 111 |
+
Util::WriteTextResourceToFile(IDR_IPTRUST_EXAMPLE, Text::toT(l_IPTrust_ini));
|
| 112 |
+
l_IPTrust_log.step("IPTrust.ini restored from internal resources");
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
else
|
| 117 |
+
{
|
| 118 |
+
l_data = p_data;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
CFlyFastLock(g_cs);
|
| 122 |
+
l_IPTrust_log.step("parse IPTrust.ini");
|
| 123 |
+
g_ipTrustListAllow.clear();
|
| 124 |
+
g_ipTrustListBlock.clear();
|
| 125 |
+
|
| 126 |
+
if (!l_data.empty())
|
| 127 |
+
{
|
| 128 |
+
string::size_type linestart = 0;
|
| 129 |
+
string::size_type lineend = 0;
|
| 130 |
+
for (;;)
|
| 131 |
+
{
|
| 132 |
+
lineend = l_data.find('\n', linestart);
|
| 133 |
+
if (lineend == string::npos)
|
| 134 |
+
{
|
| 135 |
+
string l_line = l_data.substr(linestart);
|
| 136 |
+
addLine(l_line, l_IPTrust_log);
|
| 137 |
+
break;
|
| 138 |
+
}
|
| 139 |
+
else
|
| 140 |
+
{
|
| 141 |
+
string l_line = l_data.substr(linestart, lineend - linestart - 1);
|
| 142 |
+
addLine(l_line, l_IPTrust_log);
|
| 143 |
+
linestart = lineend + 1;
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
l_IPTrust_log.step("parse IPTrust.ini done");
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
bool PGLoader::check(uint32_t p_ip4)
|
| 151 |
+
{
|
| 152 |
+
if (BOOLSETTING(ENABLE_IPTRUST))
|
| 153 |
+
{
|
| 154 |
+
CFlyFastLock(g_cs);
|
| 155 |
+
if (!g_ipTrustListBlock.empty())
|
| 156 |
+
{
|
| 157 |
+
if (g_ipTrustListBlock.checkIp(p_ip4))
|
| 158 |
+
{
|
| 159 |
+
return true;
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
if (!g_ipTrustListAllow.empty())
|
| 163 |
+
{
|
| 164 |
+
const auto l_ipguard = g_ipTrustListAllow.checkIp(p_ip4);
|
| 165 |
+
return !l_ipguard;
|
| 166 |
+
}
|
| 167 |
+
else
|
| 168 |
+
{
|
| 169 |
+
return false;
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
else
|
| 173 |
+
{
|
| 174 |
+
return false;
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
void PGLoader::addLine(string& p_Line, CFlyLog& p_log)
|
| 179 |
+
{
|
| 180 |
+
Text::replace_all(p_Line, " ", "");
|
| 181 |
+
if (p_Line.empty())
|
| 182 |
+
return;
|
| 183 |
+
|
| 184 |
+
if (p_Line[0] == '#')
|
| 185 |
+
return;
|
| 186 |
+
|
| 187 |
+
if (p_Line[0] == '-')
|
| 188 |
+
{
|
| 189 |
+
p_Line.erase(0, 1);
|
| 190 |
+
g_ipTrustListBlock.addLine(p_Line, p_log);
|
| 191 |
+
}
|
| 192 |
+
else
|
| 193 |
+
{
|
| 194 |
+
g_ipTrustListAllow.addLine(p_Line, p_log);
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
#endif // FLYLINKDC_USE_IPFILTER
|
pool/shard002/C++/0034625_boss_cyanigosa.cpp
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2008-2011 WCloudCore <http://www.wcloudcore.org/>
|
| 3 |
+
*
|
| 4 |
+
* This program is free software; you can redistribute it and/or modify it
|
| 5 |
+
* under the terms of the GNU General Public License as published by the
|
| 6 |
+
* Free Software Foundation; either version 2 of the License, or (at your
|
| 7 |
+
* option) any later version.
|
| 8 |
+
*
|
| 9 |
+
* This program is distributed in the hope that it will be useful, but WITHOUT
|
| 10 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 11 |
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 12 |
+
* more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License along
|
| 15 |
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include "ScriptPCH.h"
|
| 19 |
+
#include "violet_hold.h"
|
| 20 |
+
|
| 21 |
+
enum Spells
|
| 22 |
+
{
|
| 23 |
+
SPELL_ARCANE_VACUUM = 58694,
|
| 24 |
+
SPELL_BLIZZARD = 58693,
|
| 25 |
+
H_SPELL_BLIZZARD = 59369,
|
| 26 |
+
SPELL_MANA_DESTRUCTION = 59374,
|
| 27 |
+
SPELL_TAIL_SWEEP = 58690,
|
| 28 |
+
H_SPELL_TAIL_SWEEP = 59283,
|
| 29 |
+
SPELL_UNCONTROLLABLE_ENERGY = 58688,
|
| 30 |
+
H_SPELL_UNCONTROLLABLE_ENERGY = 59281,
|
| 31 |
+
SPELL_TRANSFORM = 58668
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
enum Yells
|
| 35 |
+
{
|
| 36 |
+
SAY_AGGRO = -1608000,
|
| 37 |
+
SAY_SLAY_1 = -1608001,
|
| 38 |
+
SAY_SLAY_2 = -1608002,
|
| 39 |
+
SAY_SLAY_3 = -1608003,
|
| 40 |
+
SAY_DEATH = -1608004,
|
| 41 |
+
SAY_SPAWN = -1608005,
|
| 42 |
+
SAY_DISRUPTION = -1608006,
|
| 43 |
+
SAY_BREATH_ATTACK = -1608007,
|
| 44 |
+
SAY_SPECIAL_ATTACK_1 = -1608008,
|
| 45 |
+
SAY_SPECIAL_ATTACK_2 = -1608009
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
class boss_cyanigosa : public CreatureScript
|
| 49 |
+
{
|
| 50 |
+
public:
|
| 51 |
+
boss_cyanigosa() : CreatureScript("boss_cyanigosa") { }
|
| 52 |
+
|
| 53 |
+
CreatureAI* GetAI(Creature* creature) const
|
| 54 |
+
{
|
| 55 |
+
return new boss_cyanigosaAI (creature);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
struct boss_cyanigosaAI : public ScriptedAI
|
| 59 |
+
{
|
| 60 |
+
boss_cyanigosaAI(Creature* c) : ScriptedAI(c)
|
| 61 |
+
{
|
| 62 |
+
instance = c->GetInstanceScript();
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
uint32 uiArcaneVacuumTimer;
|
| 66 |
+
uint32 uiBlizzardTimer;
|
| 67 |
+
uint32 uiManaDestructionTimer;
|
| 68 |
+
uint32 uiTailSweepTimer;
|
| 69 |
+
uint32 uiUncontrollableEnergyTimer;
|
| 70 |
+
|
| 71 |
+
InstanceScript* instance;
|
| 72 |
+
|
| 73 |
+
void Reset()
|
| 74 |
+
{
|
| 75 |
+
uiArcaneVacuumTimer = 10000;
|
| 76 |
+
uiBlizzardTimer = 15000;
|
| 77 |
+
uiManaDestructionTimer = 30000;
|
| 78 |
+
uiTailSweepTimer = 20000;
|
| 79 |
+
uiUncontrollableEnergyTimer = 25000;
|
| 80 |
+
if (instance)
|
| 81 |
+
instance->SetData(DATA_CYANIGOSA_EVENT, NOT_STARTED);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
void EnterCombat(Unit* /*who*/)
|
| 85 |
+
{
|
| 86 |
+
DoScriptText(SAY_AGGRO, me);
|
| 87 |
+
|
| 88 |
+
if (instance)
|
| 89 |
+
instance->SetData(DATA_CYANIGOSA_EVENT, IN_PROGRESS);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
void MoveInLineOfSight(Unit* /*who*/) {}
|
| 93 |
+
|
| 94 |
+
void UpdateAI(const uint32 diff)
|
| 95 |
+
{
|
| 96 |
+
if (instance && instance->GetData(DATA_REMOVE_NPC) == 1)
|
| 97 |
+
{
|
| 98 |
+
me->DespawnOrUnsummon();
|
| 99 |
+
instance->SetData(DATA_REMOVE_NPC, 0);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
//Return since we have no target
|
| 103 |
+
if (!UpdateVictim())
|
| 104 |
+
return;
|
| 105 |
+
|
| 106 |
+
if (uiArcaneVacuumTimer <= diff)
|
| 107 |
+
{
|
| 108 |
+
DoCast(SPELL_ARCANE_VACUUM);
|
| 109 |
+
uiArcaneVacuumTimer = 10000;
|
| 110 |
+
} else uiArcaneVacuumTimer -= diff;
|
| 111 |
+
|
| 112 |
+
if (uiBlizzardTimer <= diff)
|
| 113 |
+
{
|
| 114 |
+
if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true))
|
| 115 |
+
DoCast(target, SPELL_BLIZZARD);
|
| 116 |
+
uiBlizzardTimer = 15000;
|
| 117 |
+
} else uiBlizzardTimer -= diff;
|
| 118 |
+
|
| 119 |
+
if (uiTailSweepTimer <= diff)
|
| 120 |
+
{
|
| 121 |
+
DoCast(SPELL_TAIL_SWEEP);
|
| 122 |
+
uiTailSweepTimer = 20000;
|
| 123 |
+
} else uiTailSweepTimer -= diff;
|
| 124 |
+
|
| 125 |
+
if (uiUncontrollableEnergyTimer <= diff)
|
| 126 |
+
{
|
| 127 |
+
DoCastVictim(SPELL_UNCONTROLLABLE_ENERGY);
|
| 128 |
+
uiUncontrollableEnergyTimer = 25000;
|
| 129 |
+
} else uiUncontrollableEnergyTimer -= diff;
|
| 130 |
+
|
| 131 |
+
if (IsHeroic())
|
| 132 |
+
{
|
| 133 |
+
if (uiManaDestructionTimer <= diff)
|
| 134 |
+
{
|
| 135 |
+
if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true))
|
| 136 |
+
DoCast(target, SPELL_MANA_DESTRUCTION);
|
| 137 |
+
uiManaDestructionTimer = 30000;
|
| 138 |
+
} else uiManaDestructionTimer -= diff;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
DoMeleeAttackIfReady();
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
void JustDied(Unit* /*killer*/)
|
| 145 |
+
{
|
| 146 |
+
DoScriptText(SAY_DEATH, me);
|
| 147 |
+
|
| 148 |
+
if (instance)
|
| 149 |
+
instance->SetData(DATA_CYANIGOSA_EVENT, DONE);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
void KilledUnit(Unit* victim)
|
| 153 |
+
{
|
| 154 |
+
if (victim == me)
|
| 155 |
+
return;
|
| 156 |
+
DoScriptText(RAND(SAY_SLAY_1, SAY_SLAY_2, SAY_SLAY_3), me);
|
| 157 |
+
}
|
| 158 |
+
};
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
class achievement_defenseless : public AchievementCriteriaScript
|
| 162 |
+
{
|
| 163 |
+
public:
|
| 164 |
+
achievement_defenseless() : AchievementCriteriaScript("achievement_defenseless")
|
| 165 |
+
{
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
bool OnCheck(Player* /*player*/, Unit* target)
|
| 169 |
+
{
|
| 170 |
+
if(!target)
|
| 171 |
+
return false;
|
| 172 |
+
|
| 173 |
+
InstanceScript* instance = target->GetInstanceScript();
|
| 174 |
+
if (!instance)
|
| 175 |
+
return false;
|
| 176 |
+
|
| 177 |
+
if (!instance->GetData(DATA_DEFENSELESS))
|
| 178 |
+
return false;
|
| 179 |
+
|
| 180 |
+
return true;
|
| 181 |
+
}
|
| 182 |
+
};
|
| 183 |
+
|
| 184 |
+
void AddSC_boss_cyanigosa()
|
| 185 |
+
{
|
| 186 |
+
new boss_cyanigosa();
|
| 187 |
+
new achievement_defenseless();
|
| 188 |
+
}
|
pool/shard002/C++/0034631_encoder_containers.cpp
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*-----------------------------------------------------------------------------
|
| 2 |
+
cboreli - CBOR library
|
| 3 |
+
|
| 4 |
+
encoder_containers.cpp
|
| 5 |
+
|
| 6 |
+
The MIT License (MIT)
|
| 7 |
+
|
| 8 |
+
Copyright (c) 2016 Elisha Kendagor kendagor@live.com
|
| 9 |
+
|
| 10 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 11 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 12 |
+
in the Software without restriction, including without limitation the rights
|
| 13 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 14 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 15 |
+
furnished to do so, subject to the following conditions:
|
| 16 |
+
|
| 17 |
+
The above copyright notice and this permission notice shall be included in all
|
| 18 |
+
copies or substantial portions of the Software.
|
| 19 |
+
|
| 20 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 21 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 22 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 23 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 24 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 25 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 26 |
+
SOFTWARE.
|
| 27 |
+
-----------------------------------------------------------------------------*/
|
| 28 |
+
|
| 29 |
+
#include "encoder.h"
|
| 30 |
+
#include "random_number.h"
|
| 31 |
+
|
| 32 |
+
using namespace std;
|
| 33 |
+
using namespace cboreli;
|
| 34 |
+
|
| 35 |
+
codec_res_ptr encoder::add_byte_array(const_str key, vector<uint8_t>& value,
|
| 36 |
+
item_ptr container){
|
| 37 |
+
item_ptr p = make_shared<data_item>();
|
| 38 |
+
p->value_type = t_byte_string;
|
| 39 |
+
new(&(p->p_byte_string)) arr_uint8_ptr();
|
| 40 |
+
p->p_byte_string = make_shared<arr_uint8>(value);
|
| 41 |
+
return make_result(codec_result::status::ok, codec_result::res_comment_ok,
|
| 42 |
+
key, p, container);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
codec_res_ptr encoder::add_byte_array(const_str key, arr_uint8& value,
|
| 46 |
+
item_ptr container){
|
| 47 |
+
item_ptr p = make_shared<data_item>();
|
| 48 |
+
p->value_type = t_byte_string;
|
| 49 |
+
new(&(p->p_byte_string)) arr_uint8_ptr();
|
| 50 |
+
p->p_byte_string = make_shared<arr_uint8>(value);
|
| 51 |
+
return make_result(codec_result::status::ok, codec_result::res_comment_ok,
|
| 52 |
+
key, p, container);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
codec_res_ptr encoder::add_byte_array(const_str key, arr_uint8&& value,
|
| 56 |
+
item_ptr container){
|
| 57 |
+
item_ptr p = make_shared<data_item>();
|
| 58 |
+
p->value_type = t_byte_string;
|
| 59 |
+
new(&(p->p_byte_string)) arr_uint8_ptr();
|
| 60 |
+
p->p_byte_string = make_shared<arr_uint8>(value);
|
| 61 |
+
return make_result(codec_result::status::ok, codec_result::res_comment_ok,
|
| 62 |
+
key, p, container);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
codec_res_ptr encoder::add_items_array(const_str key, vector_items& value,
|
| 66 |
+
item_ptr container){
|
| 67 |
+
item_ptr p = make_shared<data_item>();
|
| 68 |
+
p->value_type = t_array;
|
| 69 |
+
new(&(p->p_array_items)) vector_items_ptr();
|
| 70 |
+
p->p_array_items = make_shared<vector_items>(value);
|
| 71 |
+
return make_result(codec_result::status::ok, codec_result::res_comment_ok,
|
| 72 |
+
key, p, container);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
codec_res_ptr encoder::add_items_map(const_str key, map_items& value,
|
| 76 |
+
item_ptr container){
|
| 77 |
+
item_ptr p = make_shared<data_item>();
|
| 78 |
+
p->value_type = t_map;
|
| 79 |
+
new(&(p->p_map_items)) map_items_ptr();
|
| 80 |
+
p->p_map_items = make_shared<map_items>(value);
|
| 81 |
+
return make_result(codec_result::status::ok, codec_result::res_comment_ok,
|
| 82 |
+
key, p, container);
|
| 83 |
+
}
|
| 84 |
+
|
pool/shard002/C++/0034634_AppDefaultIconElement.cpp
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* UOL Messenger
|
| 2 |
+
* Copyright (c) 2005 Universo Online S/A
|
| 3 |
+
*
|
| 4 |
+
* Direitos Autorais Reservados
|
| 5 |
+
* All rights reserved
|
| 6 |
+
*
|
| 7 |
+
* Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo
|
| 8 |
+
* sob os termos da Licença Pública Geral GNU conforme publicada pela Free
|
| 9 |
+
* Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
|
| 10 |
+
* qualquer versão posterior.
|
| 11 |
+
* Este programa é distribuído na expectativa de que seja útil, porém,
|
| 12 |
+
* SEM NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE
|
| 13 |
+
* OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral
|
| 14 |
+
* do GNU para mais detalhes.
|
| 15 |
+
* Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
|
| 16 |
+
* com este programa; se não, escreva para a Free Software Foundation, Inc.,
|
| 17 |
+
* no endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
|
| 18 |
+
*
|
| 19 |
+
* This program is free software; you can redistribute it and/or
|
| 20 |
+
* modify it under the terms of the GNU General Public License
|
| 21 |
+
* as published by the Free Software Foundation; either version 2
|
| 22 |
+
* of the License, or (at your option) any later version.
|
| 23 |
+
* This program is distributed in the hope that it will be useful,
|
| 24 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 25 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 26 |
+
* GNU General Public License for more details.
|
| 27 |
+
* You should have received a copy of the GNU General Public License
|
| 28 |
+
* along with this program; if not, write to the Free Software
|
| 29 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 30 |
+
*
|
| 31 |
+
* Universo Online S/A - A/C: UOL Messenger 5o. Andar
|
| 32 |
+
* Avenida Brigadeiro Faria Lima, 1.384 - Jardim Paulistano
|
| 33 |
+
* São Paulo SP - CEP 01452-002 - BRASIL */
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
#include "stdafx.h"
|
| 37 |
+
#include "AppDefaultIconElement.h"
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
CAppDefaultIconElement::CAppDefaultIconElement()
|
| 41 |
+
{
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
CAppDefaultIconElement::~CAppDefaultIconElement()
|
| 46 |
+
{
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
CString CAppDefaultIconElement::GetName() const
|
| 51 |
+
{
|
| 52 |
+
return _T("__AppDefaultIconInstance");
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
void CAppDefaultIconElement::SetParameters(CString2StringMapPtr& pMapParams, IElementTable* pElementTable)
|
| 57 |
+
{
|
| 58 |
+
try
|
| 59 |
+
{
|
| 60 |
+
CString strIconSmall;
|
| 61 |
+
GetParameterValue(strIconSmall, pMapParams, "smallicon");
|
| 62 |
+
|
| 63 |
+
m_pIconSmall = ap_dynamic_cast<CIconElementPtr>(pElementTable->GetElement(strIconSmall));
|
| 64 |
+
}
|
| 65 |
+
catch (const CSkinException&)
|
| 66 |
+
{
|
| 67 |
+
m_pIconSmall = CIconElementPtr();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
try
|
| 71 |
+
{
|
| 72 |
+
CString strIconLarge;
|
| 73 |
+
GetParameterValue(strIconLarge, pMapParams, "largeicon");
|
| 74 |
+
|
| 75 |
+
m_pIconLarge = ap_dynamic_cast<CIconElementPtr>(pElementTable->GetElement(strIconLarge));
|
| 76 |
+
}
|
| 77 |
+
catch (const CSkinException&)
|
| 78 |
+
{
|
| 79 |
+
m_pIconLarge = CIconElementPtr();
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
CIconElementPtr CAppDefaultIconElement::GetSmallIcon() const
|
| 85 |
+
{
|
| 86 |
+
return m_pIconSmall;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
CIconElementPtr CAppDefaultIconElement::GetLargeIcon() const
|
| 91 |
+
{
|
| 92 |
+
return m_pIconLarge;
|
| 93 |
+
}
|
pool/shard002/C++/0034638_standalone_example_docs1.cpp
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
|
| 3 |
+
|
| 4 |
+
The MySQL Connector/C++ is licensed under the terms of the GPLv2
|
| 5 |
+
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
|
| 6 |
+
MySQL Connectors. There are special exceptions to the terms and
|
| 7 |
+
conditions of the GPLv2 as it is applied to this software, see the
|
| 8 |
+
FLOSS License Exception
|
| 9 |
+
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
|
| 10 |
+
|
| 11 |
+
This program is free software; you can redistribute it and/or modify
|
| 12 |
+
it under the terms of the GNU General Public License as published
|
| 13 |
+
by the Free Software Foundation; version 2 of the License.
|
| 14 |
+
|
| 15 |
+
This program is distributed in the hope that it will be useful, but
|
| 16 |
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
| 17 |
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 18 |
+
for more details.
|
| 19 |
+
|
| 20 |
+
You should have received a copy of the GNU General Public License along
|
| 21 |
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
| 22 |
+
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
/* Standard C++ includes */
|
| 28 |
+
#include <stdlib.h>
|
| 29 |
+
#include <iostream>
|
| 30 |
+
|
| 31 |
+
/*
|
| 32 |
+
Include directly the different
|
| 33 |
+
headers from cppconn/ and mysql_driver.h + mysql_util.h
|
| 34 |
+
(and mysql_connection.h). This will reduce your build time!
|
| 35 |
+
*/
|
| 36 |
+
#include "mysql_connection.h"
|
| 37 |
+
|
| 38 |
+
#include <cppconn/driver.h>
|
| 39 |
+
#include <cppconn/exception.h>
|
| 40 |
+
#include <cppconn/resultset.h>
|
| 41 |
+
#include <cppconn/statement.h>
|
| 42 |
+
|
| 43 |
+
using namespace std;
|
| 44 |
+
|
| 45 |
+
int main(void)
|
| 46 |
+
{
|
| 47 |
+
cout << endl;
|
| 48 |
+
cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl;
|
| 49 |
+
|
| 50 |
+
try {
|
| 51 |
+
sql::Driver *driver;
|
| 52 |
+
sql::Connection *con;
|
| 53 |
+
sql::Statement *stmt;
|
| 54 |
+
sql::ResultSet *res;
|
| 55 |
+
|
| 56 |
+
/* Create a connection */
|
| 57 |
+
driver = sql::mysql::get_driver_instance();
|
| 58 |
+
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
|
| 59 |
+
/* Connect to the MySQL test database */
|
| 60 |
+
con->setSchema("test");
|
| 61 |
+
|
| 62 |
+
stmt = con->createStatement();
|
| 63 |
+
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
|
| 64 |
+
while (res->next()) {
|
| 65 |
+
cout << "\t... MySQL replies: ";
|
| 66 |
+
/* Access column data by alias or column name */
|
| 67 |
+
cout << res->getString("_message") << endl;
|
| 68 |
+
cout << "\t... MySQL says it again: ";
|
| 69 |
+
/* Access column fata by numeric offset, 1 is the first column */
|
| 70 |
+
cout << res->getString(1) << endl;
|
| 71 |
+
}
|
| 72 |
+
delete res;
|
| 73 |
+
delete stmt;
|
| 74 |
+
delete con;
|
| 75 |
+
|
| 76 |
+
} catch (sql::SQLException &e) {
|
| 77 |
+
cout << "# ERR: SQLException in " << __FILE__;
|
| 78 |
+
cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
|
| 79 |
+
cout << "# ERR: " << e.what();
|
| 80 |
+
cout << " (MySQL error code: " << e.getErrorCode();
|
| 81 |
+
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
cout << endl;
|
| 85 |
+
|
| 86 |
+
return EXIT_SUCCESS;
|
| 87 |
+
}
|
pool/shard002/C++/0034641_main.cc
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdexcept>
|
| 2 |
+
#include <iostream>
|
| 3 |
+
#include <string>
|
| 4 |
+
|
| 5 |
+
#include "find.h"
|
| 6 |
+
#include "parse.h"
|
| 7 |
+
#include "argpc.h"
|
| 8 |
+
#include "build.h"
|
| 9 |
+
#include "plotter.h"
|
| 10 |
+
#include "debug.h"
|
| 11 |
+
#include "dependencies.h"
|
| 12 |
+
#include "argpcoption.h"
|
| 13 |
+
|
| 14 |
+
using namespace std;
|
| 15 |
+
|
| 16 |
+
bool makefile_specified = false;
|
| 17 |
+
string plotfile = "";
|
| 18 |
+
std::string makefile;
|
| 19 |
+
extern std::string depfile;
|
| 20 |
+
|
| 21 |
+
void set_makefile( std::string file )
|
| 22 |
+
{
|
| 23 |
+
makefile_specified = true;
|
| 24 |
+
makefile = file;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
void set_depfile( std::string file )
|
| 28 |
+
{
|
| 29 |
+
depfile = file;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void plot( std::string file )
|
| 33 |
+
{
|
| 34 |
+
plotfile = file;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
int main(int argc, char *argv[])
|
| 38 |
+
{
|
| 39 |
+
Plotter p;
|
| 40 |
+
int ret;
|
| 41 |
+
|
| 42 |
+
try {
|
| 43 |
+
Argpc *options = Argpc::getInstance( );
|
| 44 |
+
|
| 45 |
+
// Set up the standard argument options
|
| 46 |
+
options->addHelp( );
|
| 47 |
+
options->addUsage( );
|
| 48 |
+
options->addVersion( );
|
| 49 |
+
options->setVersion( "0.1" );
|
| 50 |
+
options->setBugAddress( "Aaron Small <a.small@unb.ca>" );
|
| 51 |
+
options->setDoc( "Yet another make clone" );
|
| 52 |
+
options->setArgumentDescription( "..." );
|
| 53 |
+
options->addOption( ArgpcOption( "file", 'f', "file", "Read FILE as a makefile.", set_makefile ) );
|
| 54 |
+
options->addOption( ArgpcOption( "depfile", 'b', "depfile", "Use specified file as dependency database.", set_depfile ) );
|
| 55 |
+
options->addOption( ArgpcOption( "plot", 'p', "graphfile", "Draw the cached dependency information", plot ) );
|
| 56 |
+
|
| 57 |
+
debug_init( );
|
| 58 |
+
|
| 59 |
+
options->parse( &argc, argv );
|
| 60 |
+
|
| 61 |
+
dependencies_init();
|
| 62 |
+
|
| 63 |
+
if( !makefile_specified ) {
|
| 64 |
+
makefile = find_makefile( );
|
| 65 |
+
}
|
| 66 |
+
parse_makefile( makefile );
|
| 67 |
+
for( int i = 1; i < argc; i ++ ) {
|
| 68 |
+
set_target( argv[i] );
|
| 69 |
+
}
|
| 70 |
+
set_default_target();
|
| 71 |
+
if( plotfile != "" ) {
|
| 72 |
+
p.open( plotfile );
|
| 73 |
+
set_plotter( &p );
|
| 74 |
+
}
|
| 75 |
+
ret = build_targets();
|
| 76 |
+
} catch ( const std::exception &e ) {
|
| 77 |
+
cerr << "make: " << e.what() << endl;
|
| 78 |
+
dependencies_deinit();
|
| 79 |
+
return 1;
|
| 80 |
+
}
|
| 81 |
+
dependencies_deinit();
|
| 82 |
+
return ret;
|
| 83 |
+
}
|
pool/shard002/C++/0034642_ColourUtils.cpp
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// ColourUtils.cpp
|
| 3 |
+
// Chilli Source
|
| 4 |
+
// Created by Scott Downie on 03/04/2014.
|
| 5 |
+
//
|
| 6 |
+
// The MIT License (MIT)
|
| 7 |
+
//
|
| 8 |
+
// Copyright (c) 2014 Tag Games Limited
|
| 9 |
+
//
|
| 10 |
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 11 |
+
// of this software and associated documentation files (the "Software"), to deal
|
| 12 |
+
// in the Software without restriction, including without limitation the rights
|
| 13 |
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 14 |
+
// copies of the Software, and to permit persons to whom the Software is
|
| 15 |
+
// furnished to do so, subject to the following conditions:
|
| 16 |
+
//
|
| 17 |
+
// The above copyright notice and this permission notice shall be included in
|
| 18 |
+
// all copies or substantial portions of the Software.
|
| 19 |
+
//
|
| 20 |
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 21 |
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 22 |
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 23 |
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 24 |
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 25 |
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 26 |
+
// THE SOFTWARE.
|
| 27 |
+
//
|
| 28 |
+
|
| 29 |
+
#include <ChilliSource/Core/Base/ColourUtils.h>
|
| 30 |
+
|
| 31 |
+
#include <ChilliSource/Core/Math/MathUtils.h>
|
| 32 |
+
|
| 33 |
+
namespace ChilliSource
|
| 34 |
+
{
|
| 35 |
+
namespace Core
|
| 36 |
+
{
|
| 37 |
+
namespace ColourUtils
|
| 38 |
+
{
|
| 39 |
+
//-----------------------------------------------------------
|
| 40 |
+
//-----------------------------------------------------------
|
| 41 |
+
ByteColour ColourToByteColour(const Colour& in_colour)
|
| 42 |
+
{
|
| 43 |
+
return ColourToByteColour(in_colour.r, in_colour.g, in_colour.b, in_colour.a);
|
| 44 |
+
}
|
| 45 |
+
//-----------------------------------------------------------
|
| 46 |
+
//-----------------------------------------------------------
|
| 47 |
+
ByteColour ColourToByteColour(f32 in_red, f32 in_green, f32 in_blue, f32 in_alpha)
|
| 48 |
+
{
|
| 49 |
+
CS_ASSERT(in_red >= 0.0f && in_red <= 1.0f, "Colour must be in range 0.0 - 1.0");
|
| 50 |
+
CS_ASSERT(in_green >= 0.0f && in_green <= 1.0f, "Colour must be in range 0.0 - 1.0");
|
| 51 |
+
CS_ASSERT(in_blue >= 0.0f && in_blue <= 1.0f, "Colour must be in range 0.0 - 1.0");
|
| 52 |
+
CS_ASSERT(in_alpha >= 0.0f && in_alpha <= 1.0f, "Colour must be in range 0.0 - 1.0");
|
| 53 |
+
|
| 54 |
+
ByteColour result;
|
| 55 |
+
|
| 56 |
+
result.r = (u8)MathUtils::Round(in_red * 255.0f);
|
| 57 |
+
result.g = (u8)MathUtils::Round(in_green * 255.0f);
|
| 58 |
+
result.b = (u8)MathUtils::Round(in_blue * 255.0f);
|
| 59 |
+
result.a = (u8)MathUtils::Round(in_alpha * 255.0f);
|
| 60 |
+
|
| 61 |
+
return result;
|
| 62 |
+
}
|
| 63 |
+
//-----------------------------------------------------------
|
| 64 |
+
//-----------------------------------------------------------
|
| 65 |
+
Colour PackedRGBAToColour(u32 in_rgba)
|
| 66 |
+
{
|
| 67 |
+
u8 byteR = (in_rgba >> 24) & 255;
|
| 68 |
+
u8 byteG = (in_rgba >> 16) & 255;
|
| 69 |
+
u8 byteB = (in_rgba >> 8) & 255;
|
| 70 |
+
u8 byteA = (in_rgba) & 255;
|
| 71 |
+
|
| 72 |
+
return Colour((f32)byteR/255.0f, (f32)byteG/255.0f, (f32)byteB/255.0f, (f32)byteA/255.0f);
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
}
|
pool/shard002/C++/0034643_BigNumber.cpp
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
*
|
| 3 |
+
* Copyright (C) 2011-2013 ArkCORE <http://www.arkania.net/>
|
| 4 |
+
*
|
| 5 |
+
* Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
|
| 6 |
+
*
|
| 7 |
+
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
| 8 |
+
*
|
| 9 |
+
* This program is free software; you can redistribute it and/or modify it
|
| 10 |
+
* under the terms of the GNU General Public License as published by the
|
| 11 |
+
* Free Software Foundation; either version 2 of the License, or (at your
|
| 12 |
+
* option) any later version.
|
| 13 |
+
*
|
| 14 |
+
* This program is distributed in the hope that it will be useful, but WITHOUT
|
| 15 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 17 |
+
* more details.
|
| 18 |
+
*
|
| 19 |
+
* You should have received a copy of the GNU General Public License along
|
| 20 |
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <ace/Guard_T.h>
|
| 24 |
+
|
| 25 |
+
#include "Cryptography/BigNumber.h"
|
| 26 |
+
#include <openssl/bn.h>
|
| 27 |
+
#include <openssl/crypto.h>
|
| 28 |
+
#include <algorithm>
|
| 29 |
+
|
| 30 |
+
BigNumber::BigNumber()
|
| 31 |
+
: _bn(BN_new()), _array(NULL)
|
| 32 |
+
{ }
|
| 33 |
+
|
| 34 |
+
BigNumber::BigNumber(BigNumber const& bn)
|
| 35 |
+
: _bn(BN_dup(bn._bn)), _array(NULL)
|
| 36 |
+
{ }
|
| 37 |
+
|
| 38 |
+
BigNumber::BigNumber(uint32 val)
|
| 39 |
+
: _bn(BN_new()), _array(NULL)
|
| 40 |
+
{
|
| 41 |
+
BN_set_word(_bn, val);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
BigNumber::~BigNumber()
|
| 45 |
+
{
|
| 46 |
+
BN_free(_bn);
|
| 47 |
+
delete[] _array;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
void BigNumber::SetDword(uint32 val)
|
| 51 |
+
{
|
| 52 |
+
BN_set_word(_bn, val);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
void BigNumber::SetQword(uint64 val)
|
| 56 |
+
{
|
| 57 |
+
BN_add_word(_bn, (uint32)(val >> 32));
|
| 58 |
+
BN_lshift(_bn, _bn, 32);
|
| 59 |
+
BN_add_word(_bn, (uint32)(val & 0xFFFFFFFF));
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
void BigNumber::SetBinary(uint8 const* bytes, int32 len)
|
| 63 |
+
{
|
| 64 |
+
uint8 t[1000];
|
| 65 |
+
for (int i = 0; i < len; i++) t[i] = bytes[len - 1 - i];
|
| 66 |
+
BN_bin2bn(t, len, _bn);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
void BigNumber::SetHexStr(char const* str)
|
| 70 |
+
{
|
| 71 |
+
BN_hex2bn(&_bn, str);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
void BigNumber::SetRand(int32 numbits)
|
| 75 |
+
{
|
| 76 |
+
BN_rand(_bn, numbits, 0, 1);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
BigNumber& BigNumber::operator=(BigNumber const& bn)
|
| 80 |
+
{
|
| 81 |
+
if (this == &bn)
|
| 82 |
+
return *this;
|
| 83 |
+
|
| 84 |
+
BN_copy(_bn, bn._bn);
|
| 85 |
+
return *this;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
BigNumber BigNumber::operator+=(BigNumber const& bn)
|
| 89 |
+
{
|
| 90 |
+
BN_add(_bn, _bn, bn._bn);
|
| 91 |
+
return *this;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
BigNumber BigNumber::operator-=(BigNumber const& bn)
|
| 95 |
+
{
|
| 96 |
+
BN_sub(_bn, _bn, bn._bn);
|
| 97 |
+
return *this;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
BigNumber BigNumber::operator*=(BigNumber const& bn)
|
| 101 |
+
{
|
| 102 |
+
BN_CTX *bnctx;
|
| 103 |
+
|
| 104 |
+
bnctx = BN_CTX_new();
|
| 105 |
+
BN_mul(_bn, _bn, bn._bn, bnctx);
|
| 106 |
+
BN_CTX_free(bnctx);
|
| 107 |
+
|
| 108 |
+
return *this;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
BigNumber BigNumber::operator/=(BigNumber const& bn)
|
| 112 |
+
{
|
| 113 |
+
BN_CTX *bnctx;
|
| 114 |
+
|
| 115 |
+
bnctx = BN_CTX_new();
|
| 116 |
+
BN_div(_bn, NULL, _bn, bn._bn, bnctx);
|
| 117 |
+
BN_CTX_free(bnctx);
|
| 118 |
+
|
| 119 |
+
return *this;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
BigNumber BigNumber::operator%=(BigNumber const& bn)
|
| 123 |
+
{
|
| 124 |
+
BN_CTX *bnctx;
|
| 125 |
+
|
| 126 |
+
bnctx = BN_CTX_new();
|
| 127 |
+
BN_mod(_bn, _bn, bn._bn, bnctx);
|
| 128 |
+
BN_CTX_free(bnctx);
|
| 129 |
+
|
| 130 |
+
return *this;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
BigNumber BigNumber::Exp(BigNumber const& bn)
|
| 134 |
+
{
|
| 135 |
+
BigNumber ret;
|
| 136 |
+
BN_CTX *bnctx;
|
| 137 |
+
|
| 138 |
+
bnctx = BN_CTX_new();
|
| 139 |
+
BN_exp(ret._bn, _bn, bn._bn, bnctx);
|
| 140 |
+
BN_CTX_free(bnctx);
|
| 141 |
+
|
| 142 |
+
return ret;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
BigNumber BigNumber::ModExp(BigNumber const& bn1, BigNumber const& bn2)
|
| 146 |
+
{
|
| 147 |
+
BigNumber ret;
|
| 148 |
+
BN_CTX *bnctx;
|
| 149 |
+
|
| 150 |
+
bnctx = BN_CTX_new();
|
| 151 |
+
BN_mod_exp(ret._bn, _bn, bn1._bn, bn2._bn, bnctx);
|
| 152 |
+
BN_CTX_free(bnctx);
|
| 153 |
+
|
| 154 |
+
return ret;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
int32 BigNumber::GetNumBytes(void)
|
| 158 |
+
{
|
| 159 |
+
return BN_num_bytes(_bn);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
uint32 BigNumber::AsDword()
|
| 163 |
+
{
|
| 164 |
+
return (uint32)BN_get_word(_bn);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
bool BigNumber::isZero() const
|
| 168 |
+
{
|
| 169 |
+
return BN_is_zero(_bn);
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
uint8* BigNumber::AsByteArray(int32 minSize, bool reverse)
|
| 173 |
+
{
|
| 174 |
+
int length = (minSize >= GetNumBytes()) ? minSize : GetNumBytes();
|
| 175 |
+
|
| 176 |
+
ACE_GUARD_RETURN(ACE_Mutex, g, _lock, 0);
|
| 177 |
+
|
| 178 |
+
if (_array)
|
| 179 |
+
{
|
| 180 |
+
delete[] _array;
|
| 181 |
+
_array = NULL;
|
| 182 |
+
}
|
| 183 |
+
_array = new uint8[length];
|
| 184 |
+
|
| 185 |
+
// If we need more bytes than length of BigNumber set the rest to 0
|
| 186 |
+
if (length > GetNumBytes())
|
| 187 |
+
memset((void*)_array, 0, length);
|
| 188 |
+
|
| 189 |
+
BN_bn2bin(_bn, (unsigned char *)_array);
|
| 190 |
+
|
| 191 |
+
if (reverse)
|
| 192 |
+
std::reverse(_array, _array + length);
|
| 193 |
+
|
| 194 |
+
return _array;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
char * BigNumber::AsHexStr() const
|
| 198 |
+
{
|
| 199 |
+
return BN_bn2hex(_bn);
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
char * BigNumber::AsDecStr() const
|
| 203 |
+
{
|
| 204 |
+
return BN_bn2dec(_bn);
|
| 205 |
+
}
|
| 206 |
+
|
pool/shard002/C++/0034649_Process_test.cpp
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/*
|
| 3 |
+
* Copyright (C) 2017 Anoop Chandran
|
| 4 |
+
*
|
| 5 |
+
* This library is free software; you can redistribute it and/or
|
| 6 |
+
* modify it under the terms of the GNU Lesser General Public
|
| 7 |
+
* License as published by the Free Software Foundation; either
|
| 8 |
+
* version 2.1 of the License, or (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This library 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 GNU
|
| 13 |
+
* Lesser General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU Lesser General Public
|
| 16 |
+
* License along with this library; if not, write to the Free Software
|
| 17 |
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 |
+
* or see <http://www.gnu.org/licenses/>
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include"Process_test.h"
|
| 22 |
+
|
| 23 |
+
Process_test::Process_test()
|
| 24 |
+
{}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Process_test::~Process_test()
|
| 28 |
+
{}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
void Process_test::run_sleep()
|
| 32 |
+
{
|
| 33 |
+
char* args[] = {"/bin/sleep", "2", NULL};
|
| 34 |
+
process.create("/bin/sleep",args,NULL);
|
| 35 |
+
process.requester.Connect(this,&Process_test::process_exit);
|
| 36 |
+
process.run();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
void Process_test::run_ls()
|
| 40 |
+
{
|
| 41 |
+
char* args[] = {"/bin/ls", "-ls", NULL};
|
| 42 |
+
process.create("/bin/ls",args,NULL);
|
| 43 |
+
process.requester.Connect(this,&Process_test::process_exit);
|
| 44 |
+
process.run();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
void Process_test::run_a_disable_test()
|
| 49 |
+
{
|
| 50 |
+
char* args[] = {"/home/neo/build/OSAL/Process/unit_test/process_test","--gtest_filter=Process_test.print_test",NULL};
|
| 51 |
+
process.create("/home/neo/build/OSAL/Process/unit_test/process_test",args,NULL);
|
| 52 |
+
process.requester.Connect(this,&Process_test::process_exit);
|
| 53 |
+
process.run();
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
void Process_test::process_exit(uint64_t exit_code, uint32_t exit_signal)
|
| 58 |
+
{
|
| 59 |
+
printf("Process_test::process_exit exit_code = %d exit_signal = %d\n", exit_code, exit_signal);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
void Process_test::SetUp()
|
| 64 |
+
{
|
| 65 |
+
osal_test_base::SetUp();
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
void Process_test::TearDown()
|
| 70 |
+
{
|
| 71 |
+
osal_test_base::TearDown();
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
TEST_F(Process_test, run_sleep )
|
| 76 |
+
{
|
| 77 |
+
printf("start test");
|
| 78 |
+
run_sleep();
|
| 79 |
+
run();
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
TEST_F(Process_test, run_ls )
|
| 84 |
+
{
|
| 85 |
+
printf("start test");
|
| 86 |
+
run_ls();
|
| 87 |
+
run();
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
TEST_F(Process_test, run_a_disable_test )
|
| 92 |
+
{
|
| 93 |
+
printf("start test");
|
| 94 |
+
run_a_disable_test();
|
| 95 |
+
run();
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
TEST_F(Process_test, DISABLED_run_ls )
|
| 100 |
+
{
|
| 101 |
+
printf("start ls test");
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
TEST_F(Process_test, print_test )
|
| 105 |
+
{
|
| 106 |
+
fprintf(stderr,"start ls test");
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
#if 0
|
| 111 |
+
|
| 112 |
+
void on_exit(uv_process_t *req, int exit_status, int term_signal) {
|
| 113 |
+
fprintf(stderr, "Process exited with status %d, signal %d\n", exit_status, term_signal);
|
| 114 |
+
uv_close((uv_handle_t*)req, NULL);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
uv_process_options_t options;
|
| 118 |
+
TEST_F(Process_test, run_ls_test)
|
| 119 |
+
{
|
| 120 |
+
uv_loop_t *loop;
|
| 121 |
+
loop = uv_default_loop();
|
| 122 |
+
uv_process_t child_req;
|
| 123 |
+
|
| 124 |
+
char *args[] = { "/bin/sleep", "2", NULL };
|
| 125 |
+
|
| 126 |
+
options.exit_cb = NULL;
|
| 127 |
+
options.file = "/bin/sleep";
|
| 128 |
+
options.args = args;
|
| 129 |
+
options.flags = UV_PROCESS_DETACHED;
|
| 130 |
+
fprintf(stderr,"loop %d\n",loop);
|
| 131 |
+
int error = uv_spawn(loop, &child_req, &options);
|
| 132 |
+
if (error) {
|
| 133 |
+
fprintf(stderr, "Error = %s!\n",uv_err_name(error));
|
| 134 |
+
}
|
| 135 |
+
fprintf(stderr, "Launched sleep with PID %d\n", child_req.pid);
|
| 136 |
+
// uv_unref((uv_handle_t*) &child_req);
|
| 137 |
+
|
| 138 |
+
uv_run(loop, UV_RUN_DEFAULT);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
#endif
|
pool/shard002/C++/0034658_PhyloTree.cpp
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright (C) 2014 University of Southern California and
|
| 2 |
+
* Andrew D. Smith
|
| 3 |
+
*
|
| 4 |
+
* Authors: Andrew D. Smith and Jenny Qu
|
| 5 |
+
*
|
| 6 |
+
* This program is free software: you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License as published by
|
| 8 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
* (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* This program is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
/*
|
| 22 |
+
|
| 23 |
+
ABOUT NEWICK FORMAT
|
| 24 |
+
-------------------
|
| 25 |
+
|
| 26 |
+
The following should all be legal, according to wikipedia.
|
| 27 |
+
|
| 28 |
+
(,,(,)); no nodes are named
|
| 29 |
+
(A,B,(C,D)); leaf nodes are named
|
| 30 |
+
(A,B,(C,D)E)F; all nodes are named
|
| 31 |
+
(:0.1,:0.2,(:0.3,:0.4):0.5); all but root node have a distance to parent
|
| 32 |
+
(:0.1,:0.2,(:0.3,:0.4):0.5):0.0; all have a distance to parent
|
| 33 |
+
(A:0.1,B:0.2,(C:0.3,D:0.4):0.5); distances and leaf names (popular)
|
| 34 |
+
(A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5)F; distances and all names
|
| 35 |
+
((B:0.2,(C:0.3,D:0.4)E:0.5)F:0.1)A; a tree rooted on a leaf node (rare)
|
| 36 |
+
|
| 37 |
+
========================================================================
|
| 38 |
+
|
| 39 |
+
(1) It seems like a tree always ends in a semicolon
|
| 40 |
+
(2) Trees need not be binary, but usually are ***
|
| 41 |
+
(3) Since the code needs to have uniform nodes, we will always have
|
| 42 |
+
a distance, even for the root, but this will be 0.0
|
| 43 |
+
(4) The parsing will look for commas, but not within parentheses
|
| 44 |
+
(5) No whitespace will be allowed. It will be removed initially
|
| 45 |
+
(6) There is a question of whether to allow commas or colons inside
|
| 46 |
+
names, for example by using quotes around the names or trying to
|
| 47 |
+
parse intelligently
|
| 48 |
+
*/
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
#include "PhyloTree.hpp"
|
| 52 |
+
|
| 53 |
+
#include <string>
|
| 54 |
+
#include <vector>
|
| 55 |
+
#include <iostream>
|
| 56 |
+
#include <fstream>
|
| 57 |
+
#include <algorithm>
|
| 58 |
+
#include <sstream>
|
| 59 |
+
#include <unordered_set>
|
| 60 |
+
|
| 61 |
+
#include <cctype> // for isspace
|
| 62 |
+
|
| 63 |
+
#include "smithlab_utils.hpp"
|
| 64 |
+
|
| 65 |
+
using std::string;
|
| 66 |
+
using std::vector;
|
| 67 |
+
using std::endl;
|
| 68 |
+
using std::cerr;
|
| 69 |
+
using std::cout;
|
| 70 |
+
using std::unordered_set;
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
static bool
|
| 74 |
+
check_balanced_parentheses(const string &s) {
|
| 75 |
+
int count = 0;
|
| 76 |
+
for (size_t i = 0; i < s.length(); ++i) {
|
| 77 |
+
if (s[i] == '(') ++count;
|
| 78 |
+
if (s[i] == ')') --count;
|
| 79 |
+
}
|
| 80 |
+
return count == 0;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
// static bool
|
| 85 |
+
// check_unique_names(const string &s) {
|
| 86 |
+
// /// ADS: this function is really poorly coded
|
| 87 |
+
// bool is_unique=true;
|
| 88 |
+
// string s_copy =s;
|
| 89 |
+
// unordered_set<string> names;
|
| 90 |
+
// size_t f1, f2;
|
| 91 |
+
// while (!s_copy.empty()) {
|
| 92 |
+
// f1 = s_copy.find_first_not_of("()0123456789:,;");
|
| 93 |
+
// s_copy.erase(0,f1);
|
| 94 |
+
// if (s_copy.empty()) break;
|
| 95 |
+
// f2 = s_copy.find_first_of("()0123456789:,;");
|
| 96 |
+
// string name=s_copy.substr(0,f2);
|
| 97 |
+
// if (names.find(name)== names.end()){
|
| 98 |
+
// names.insert(name);
|
| 99 |
+
// }
|
| 100 |
+
// else {
|
| 101 |
+
// is_unique=false;
|
| 102 |
+
// break;
|
| 103 |
+
// }
|
| 104 |
+
// }
|
| 105 |
+
// return is_unique;
|
| 106 |
+
// }
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
void
|
| 110 |
+
PhyloTree::PTNode::swap(PTNode &other) {
|
| 111 |
+
std::swap(child, other.child);
|
| 112 |
+
std::swap(name, other.name);
|
| 113 |
+
std::swap(branch_length, other.branch_length);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
size_t
|
| 117 |
+
PhyloTree::PTNode::get_size() const {
|
| 118 |
+
size_t sz = 1;
|
| 119 |
+
for (size_t i = 0; i < child.size(); ++i)
|
| 120 |
+
sz += child[i].get_size();
|
| 121 |
+
return sz;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
string
|
| 126 |
+
PhyloTree::PTNode::tostring(const size_t depth) const {
|
| 127 |
+
std::ostringstream oss;
|
| 128 |
+
oss << string(depth, '\t') << branch_length << ':' << name;
|
| 129 |
+
for (size_t i = 0; i < child.size(); ++i)
|
| 130 |
+
oss << endl << child[i].tostring(depth + 1);
|
| 131 |
+
return oss.str();
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
string
|
| 136 |
+
PhyloTree::PTNode::Newick_format() const {
|
| 137 |
+
std::ostringstream oss;
|
| 138 |
+
if (!child.empty()) {
|
| 139 |
+
oss << '(';
|
| 140 |
+
oss << child.front().Newick_format();
|
| 141 |
+
for (size_t i = 1; i < child.size(); ++i)
|
| 142 |
+
oss << ',' << child[i].Newick_format();
|
| 143 |
+
oss << ')';
|
| 144 |
+
}
|
| 145 |
+
oss << name << ':' << branch_length;
|
| 146 |
+
return oss.str();
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
static bool
|
| 151 |
+
represents_leaf(const string &tree_rep) {
|
| 152 |
+
return (tree_rep.find_first_of(',') == string::npos);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
static string
|
| 157 |
+
extract_name(const string &tree_rep) {
|
| 158 |
+
const size_t final_parenthesis = tree_rep.find_last_of(")");
|
| 159 |
+
const size_t possible_name_start =
|
| 160 |
+
(final_parenthesis == string::npos) ? 0 : final_parenthesis + 1;
|
| 161 |
+
const size_t branch_len_start =
|
| 162 |
+
std::min(tree_rep.find_first_of(":", possible_name_start),
|
| 163 |
+
tree_rep.length());
|
| 164 |
+
return string(tree_rep.begin() + possible_name_start,
|
| 165 |
+
tree_rep.begin() + branch_len_start);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
static double
|
| 170 |
+
extract_branch_length(const string &tree_rep) {
|
| 171 |
+
const size_t final_parenthesis = tree_rep.find_last_of(")");
|
| 172 |
+
const size_t colon_pos = tree_rep.find_first_of(":", final_parenthesis + 1);
|
| 173 |
+
if (colon_pos == string::npos)
|
| 174 |
+
return 0.0;
|
| 175 |
+
const size_t non_numeric =
|
| 176 |
+
tree_rep.find_first_not_of("0123456789.", colon_pos + 1);
|
| 177 |
+
if (non_numeric == 0)
|
| 178 |
+
return 0.0;
|
| 179 |
+
return atof(tree_rep.substr(colon_pos + 1).c_str());
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
static bool
|
| 184 |
+
root_has_name(const string &tree_rep) {
|
| 185 |
+
const size_t final_parenthesis = tree_rep.find_last_of(")");
|
| 186 |
+
const size_t possible_name_start =
|
| 187 |
+
(final_parenthesis == string::npos) ? 0 : final_parenthesis;
|
| 188 |
+
return (tree_rep[possible_name_start] != ':');
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
static void
|
| 193 |
+
extract_subtrees(const string &tree_rep,
|
| 194 |
+
vector<string> &subtree_reps) {
|
| 195 |
+
const size_t offset = (tree_rep[0] == '(') ? 1 : 0;
|
| 196 |
+
const string tmp(tree_rep.begin() + offset,
|
| 197 |
+
tree_rep.begin() + tree_rep.find_last_of(")"));
|
| 198 |
+
vector<size_t> split_points;
|
| 199 |
+
size_t p_count = 0;
|
| 200 |
+
for (size_t i = 0; i < tmp.length(); ++i) {
|
| 201 |
+
if (p_count == 0 && tmp[i] == ',')
|
| 202 |
+
split_points.push_back(i);
|
| 203 |
+
if (tmp[i] == '(') ++p_count;
|
| 204 |
+
if (tmp[i] == ')') --p_count;
|
| 205 |
+
}
|
| 206 |
+
split_points.push_back(tmp.length());
|
| 207 |
+
subtree_reps.push_back(tmp.substr(0, split_points[0]));
|
| 208 |
+
for (size_t i = 0; i < split_points.size() - 1; ++i)
|
| 209 |
+
subtree_reps.push_back(string(tmp.begin() + split_points[i] + 1,
|
| 210 |
+
tmp.begin() + split_points[i + 1]));
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
PhyloTree::PTNode::PTNode(const string &tree_rep) {
|
| 215 |
+
// This function needs to test the various ways that a string can be
|
| 216 |
+
// passed in to represent a subtree at the current node
|
| 217 |
+
|
| 218 |
+
branch_length = extract_branch_length(tree_rep);
|
| 219 |
+
if (root_has_name(tree_rep))
|
| 220 |
+
name = extract_name(tree_rep);
|
| 221 |
+
|
| 222 |
+
if (!represents_leaf(tree_rep)) {
|
| 223 |
+
vector<string> subtree_reps;
|
| 224 |
+
extract_subtrees(tree_rep, subtree_reps);
|
| 225 |
+
for (size_t i = 0; i < subtree_reps.size(); ++i)
|
| 226 |
+
child.push_back(PTNode(subtree_reps[i]));
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
void
|
| 231 |
+
PhyloTree::PTNode::copy_subtree_with_species(const PTNode &t,
|
| 232 |
+
const
|
| 233 |
+
unordered_set<string> &species,
|
| 234 |
+
PTNode &u) {
|
| 235 |
+
if (t.is_leaf()) {
|
| 236 |
+
if (species.find(t.name) != species.end()) {
|
| 237 |
+
u.name = t.name;
|
| 238 |
+
u.branch_length = t.branch_length;
|
| 239 |
+
}
|
| 240 |
+
}
|
| 241 |
+
else {
|
| 242 |
+
|
| 243 |
+
vector<PTNode> children;
|
| 244 |
+
for (size_t i = 0; i < t.child.size(); ++i) {
|
| 245 |
+
PTNode v;
|
| 246 |
+
copy_subtree_with_species(t.child[i], species, v);
|
| 247 |
+
if (v.has_children() || !v.name.empty()) {
|
| 248 |
+
children.push_back(PTNode());
|
| 249 |
+
children.back().swap(v);
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
if (children.size() > 0) {
|
| 254 |
+
if (children.size() == 1) {
|
| 255 |
+
u.swap(children.front());
|
| 256 |
+
u.branch_length += t.branch_length;
|
| 257 |
+
}
|
| 258 |
+
else {
|
| 259 |
+
u.name = t.name;
|
| 260 |
+
u.branch_length = t.branch_length;
|
| 261 |
+
u.child.swap(children);
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
////////////////////////////////////////////////////////////////////////
|
| 270 |
+
////////////////////////////////////////////////////////////////////////
|
| 271 |
+
//// PHYLO TREE CLASS BELOW HERE ////
|
| 272 |
+
////////////////////////////////////////////////////////////////////////
|
| 273 |
+
////////////////////////////////////////////////////////////////////////
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
PhyloTree::PhyloTree(string tree_rep) {
|
| 277 |
+
if (!check_balanced_parentheses(tree_rep))
|
| 278 |
+
throw SMITHLABException("Unbalanced parentheses in Newick format: " +
|
| 279 |
+
tree_rep);
|
| 280 |
+
// remove whitespace
|
| 281 |
+
string::iterator w =
|
| 282 |
+
std::remove_copy_if(tree_rep.begin(), tree_rep.end(),
|
| 283 |
+
tree_rep.begin(), &isspace);
|
| 284 |
+
assert(w != tree_rep.begin());
|
| 285 |
+
if (*(w - 1) == ';')
|
| 286 |
+
tree_rep.erase(--w, tree_rep.end()); // The "--w" is for the ";"
|
| 287 |
+
|
| 288 |
+
/* ADS: requirement for unique names should only apply to leafs
|
| 289 |
+
*/
|
| 290 |
+
// if (!check_unique_names(tree_rep))
|
| 291 |
+
// throw SMITHLABException("duplicate names in: " + tree_rep);
|
| 292 |
+
|
| 293 |
+
root = PTNode(tree_rep);
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
void
|
| 298 |
+
PhyloTree::copy_subtree_with_species(const PhyloTree &t,
|
| 299 |
+
const unordered_set<string> &species,
|
| 300 |
+
PhyloTree &u) {
|
| 301 |
+
PTNode::copy_subtree_with_species(t.root, species, u.root);
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
std::istream&
|
| 306 |
+
operator>>(std::istream &in, PhyloTree &t) {
|
| 307 |
+
/* doing it this way to just get one tree at a time */
|
| 308 |
+
string r;
|
| 309 |
+
char c;
|
| 310 |
+
bool found_end = false;
|
| 311 |
+
while (!found_end && in >> c) {
|
| 312 |
+
r += c;
|
| 313 |
+
if (c == ';')
|
| 314 |
+
found_end = true;
|
| 315 |
+
}
|
| 316 |
+
if (!found_end)
|
| 317 |
+
throw SMITHLABException("bad tree format");
|
| 318 |
+
t = PhyloTree(r);
|
| 319 |
+
return in;
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
std::ostream&
|
| 324 |
+
operator<<(std::ostream &out, const PhyloTree &t) {
|
| 325 |
+
return out << t.Newick_format();
|
| 326 |
+
}
|
pool/shard002/C++/0034662_BitmapWindow.cpp
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/////////////////////////////////////////////////////////////////////////////
|
| 2 |
+
// The GaugeWorks project is released under the GNU Lesser Public License
|
| 3 |
+
// with modifications. See the License.txt file for the full text
|
| 4 |
+
// Copyright (c) 2007 Brent Picasso http://picasso.org
|
| 5 |
+
// Name: BitmapWindow
|
| 6 |
+
// Purpose: wxLed implementation
|
| 7 |
+
/////////////////////////////////////////////////////////////////////////////
|
| 8 |
+
#include "BitmapWindow.h"
|
| 9 |
+
|
| 10 |
+
BEGIN_EVENT_TABLE(BitmapWindow,wxWindow)
|
| 11 |
+
EVT_PAINT(BitmapWindow::OnPaint)
|
| 12 |
+
EVT_SIZE(BitmapWindow::OnSize)
|
| 13 |
+
|
| 14 |
+
END_EVENT_TABLE()
|
| 15 |
+
|
| 16 |
+
//BitmapWindow::BitmapWindow() : _imageXpm(NULL){}
|
| 17 |
+
|
| 18 |
+
BitmapWindow::BitmapWindow( wxWindow *parent,
|
| 19 |
+
wxWindowID id,
|
| 20 |
+
const char ** xpm_bitmap,
|
| 21 |
+
const wxPoint &pos,
|
| 22 |
+
const wxSize &size )
|
| 23 |
+
: wxWindow(parent, id, pos, size, 0)
|
| 24 |
+
{
|
| 25 |
+
_imageXpm = new wxBitmap(xpm_bitmap);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
BitmapWindow::~BitmapWindow(){
|
| 29 |
+
delete (_imageXpm);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void BitmapWindow::SetBitmap(const char ** newXpm){
|
| 33 |
+
if (_imageXpm) delete (_imageXpm);
|
| 34 |
+
_imageXpm = new wxBitmap(newXpm);
|
| 35 |
+
Refresh();
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
void BitmapWindow::OnSize(wxSizeEvent &event){
|
| 40 |
+
Refresh();
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
wxSize BitmapWindow::GetMinSize() const{
|
| 44 |
+
return wxSize(_imageXpm->GetWidth(), _imageXpm->GetHeight());
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
void BitmapWindow::OnPaint(wxPaintEvent &event){
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
int w,h ;
|
| 51 |
+
GetClientSize(&w,&h);
|
| 52 |
+
|
| 53 |
+
wxPaintDC dc( this );
|
| 54 |
+
PrepareDC( dc );
|
| 55 |
+
dc.SetBackground(*wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(),wxSOLID));
|
| 56 |
+
dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(),wxSOLID));
|
| 57 |
+
dc.Clear();
|
| 58 |
+
|
| 59 |
+
dc.DrawBitmap(*_imageXpm, w -_imageXpm->GetWidth(),0,true);
|
| 60 |
+
}
|
pool/shard002/C++/0034663_task_scheduler_impl_unittest.cc
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 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 "base/task_scheduler/task_scheduler_impl.h"
|
| 6 |
+
|
| 7 |
+
#include <stddef.h>
|
| 8 |
+
|
| 9 |
+
#include <string>
|
| 10 |
+
#include <utility>
|
| 11 |
+
#include <vector>
|
| 12 |
+
|
| 13 |
+
#include "base/bind.h"
|
| 14 |
+
#include "base/bind_helpers.h"
|
| 15 |
+
#include "base/callback.h"
|
| 16 |
+
#include "base/macros.h"
|
| 17 |
+
#include "base/memory/ptr_util.h"
|
| 18 |
+
#include "base/synchronization/lock.h"
|
| 19 |
+
#include "base/synchronization/waitable_event.h"
|
| 20 |
+
#include "base/task_scheduler/scheduler_worker_pool_params.h"
|
| 21 |
+
#include "base/task_scheduler/task_traits.h"
|
| 22 |
+
#include "base/task_scheduler/test_task_factory.h"
|
| 23 |
+
#include "base/threading/platform_thread.h"
|
| 24 |
+
#include "base/threading/simple_thread.h"
|
| 25 |
+
#include "base/threading/thread.h"
|
| 26 |
+
#include "base/threading/thread_restrictions.h"
|
| 27 |
+
#include "base/time/time.h"
|
| 28 |
+
#include "testing/gtest/include/gtest/gtest.h"
|
| 29 |
+
|
| 30 |
+
namespace base {
|
| 31 |
+
namespace internal {
|
| 32 |
+
|
| 33 |
+
namespace {
|
| 34 |
+
|
| 35 |
+
struct TraitsExecutionModePair {
|
| 36 |
+
TraitsExecutionModePair(const TaskTraits& traits,
|
| 37 |
+
ExecutionMode execution_mode)
|
| 38 |
+
: traits(traits), execution_mode(execution_mode) {}
|
| 39 |
+
|
| 40 |
+
TaskTraits traits;
|
| 41 |
+
ExecutionMode execution_mode;
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
#if DCHECK_IS_ON()
|
| 45 |
+
// Returns whether I/O calls are allowed on the current thread.
|
| 46 |
+
bool GetIOAllowed() {
|
| 47 |
+
const bool previous_value = ThreadRestrictions::SetIOAllowed(true);
|
| 48 |
+
ThreadRestrictions::SetIOAllowed(previous_value);
|
| 49 |
+
return previous_value;
|
| 50 |
+
}
|
| 51 |
+
#endif
|
| 52 |
+
|
| 53 |
+
// Verify that the current thread priority and I/O restrictions are appropriate
|
| 54 |
+
// to run a Task with |traits|.
|
| 55 |
+
// Note: ExecutionMode is verified inside TestTaskFactory.
|
| 56 |
+
void VerifyTaskEnvironement(const TaskTraits& traits) {
|
| 57 |
+
const bool supports_background_priority =
|
| 58 |
+
Lock::HandlesMultipleThreadPriorities() &&
|
| 59 |
+
PlatformThread::CanIncreaseCurrentThreadPriority();
|
| 60 |
+
|
| 61 |
+
EXPECT_EQ(supports_background_priority &&
|
| 62 |
+
traits.priority() == TaskPriority::BACKGROUND
|
| 63 |
+
? ThreadPriority::BACKGROUND
|
| 64 |
+
: ThreadPriority::NORMAL,
|
| 65 |
+
PlatformThread::GetCurrentThreadPriority());
|
| 66 |
+
|
| 67 |
+
#if DCHECK_IS_ON()
|
| 68 |
+
// The #if above is required because GetIOAllowed() always returns true when
|
| 69 |
+
// !DCHECK_IS_ON(), even when |traits| don't allow file I/O.
|
| 70 |
+
EXPECT_EQ(traits.with_file_io(), GetIOAllowed());
|
| 71 |
+
#endif
|
| 72 |
+
|
| 73 |
+
// Verify that the thread the task is running on is named as expected.
|
| 74 |
+
const std::string current_thread_name(PlatformThread::GetName());
|
| 75 |
+
EXPECT_NE(std::string::npos, current_thread_name.find("TaskScheduler"));
|
| 76 |
+
EXPECT_NE(std::string::npos,
|
| 77 |
+
current_thread_name.find(
|
| 78 |
+
traits.priority() == TaskPriority::BACKGROUND ? "Background"
|
| 79 |
+
: "Foreground"));
|
| 80 |
+
EXPECT_EQ(traits.with_file_io(),
|
| 81 |
+
current_thread_name.find("FileIO") != std::string::npos);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
void VerifyTaskEnvironementAndSignalEvent(const TaskTraits& traits,
|
| 85 |
+
WaitableEvent* event) {
|
| 86 |
+
DCHECK(event);
|
| 87 |
+
VerifyTaskEnvironement(traits);
|
| 88 |
+
event->Signal();
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
class ThreadPostingTasks : public SimpleThread {
|
| 92 |
+
public:
|
| 93 |
+
// Creates a thread that posts Tasks to |scheduler| with |traits| and
|
| 94 |
+
// |execution_mode|.
|
| 95 |
+
ThreadPostingTasks(TaskSchedulerImpl* scheduler,
|
| 96 |
+
const TaskTraits& traits,
|
| 97 |
+
ExecutionMode execution_mode)
|
| 98 |
+
: SimpleThread("ThreadPostingTasks"),
|
| 99 |
+
traits_(traits),
|
| 100 |
+
factory_(scheduler->CreateTaskRunnerWithTraits(traits, execution_mode),
|
| 101 |
+
execution_mode) {}
|
| 102 |
+
|
| 103 |
+
void WaitForAllTasksToRun() { factory_.WaitForAllTasksToRun(); }
|
| 104 |
+
|
| 105 |
+
private:
|
| 106 |
+
void Run() override {
|
| 107 |
+
EXPECT_FALSE(factory_.task_runner()->RunsTasksOnCurrentThread());
|
| 108 |
+
|
| 109 |
+
const size_t kNumTasksPerThread = 150;
|
| 110 |
+
for (size_t i = 0; i < kNumTasksPerThread; ++i) {
|
| 111 |
+
factory_.PostTask(test::TestTaskFactory::PostNestedTask::NO,
|
| 112 |
+
Bind(&VerifyTaskEnvironement, traits_));
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
const TaskTraits traits_;
|
| 117 |
+
test::TestTaskFactory factory_;
|
| 118 |
+
|
| 119 |
+
DISALLOW_COPY_AND_ASSIGN(ThreadPostingTasks);
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
// Returns a vector with a TraitsExecutionModePair for each valid
|
| 123 |
+
// combination of {ExecutionMode, TaskPriority, WithFileIO()}.
|
| 124 |
+
std::vector<TraitsExecutionModePair> GetTraitsExecutionModePairs() {
|
| 125 |
+
std::vector<TraitsExecutionModePair> params;
|
| 126 |
+
|
| 127 |
+
const ExecutionMode execution_modes[] = {ExecutionMode::PARALLEL,
|
| 128 |
+
ExecutionMode::SEQUENCED,
|
| 129 |
+
ExecutionMode::SINGLE_THREADED};
|
| 130 |
+
|
| 131 |
+
for (ExecutionMode execution_mode : execution_modes) {
|
| 132 |
+
for (size_t priority_index = static_cast<size_t>(TaskPriority::LOWEST);
|
| 133 |
+
priority_index <= static_cast<size_t>(TaskPriority::HIGHEST);
|
| 134 |
+
++priority_index) {
|
| 135 |
+
const TaskPriority priority = static_cast<TaskPriority>(priority_index);
|
| 136 |
+
params.push_back(TraitsExecutionModePair(
|
| 137 |
+
TaskTraits().WithPriority(priority), execution_mode));
|
| 138 |
+
params.push_back(TraitsExecutionModePair(
|
| 139 |
+
TaskTraits().WithPriority(priority).WithFileIO(), execution_mode));
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
return params;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
enum WorkerPoolType {
|
| 147 |
+
BACKGROUND_WORKER_POOL = 0,
|
| 148 |
+
BACKGROUND_FILE_IO_WORKER_POOL,
|
| 149 |
+
FOREGROUND_WORKER_POOL,
|
| 150 |
+
FOREGROUND_FILE_IO_WORKER_POOL,
|
| 151 |
+
};
|
| 152 |
+
|
| 153 |
+
size_t GetThreadPoolIndexForTraits(const TaskTraits& traits) {
|
| 154 |
+
if (traits.with_file_io()) {
|
| 155 |
+
return traits.priority() == TaskPriority::BACKGROUND
|
| 156 |
+
? BACKGROUND_FILE_IO_WORKER_POOL
|
| 157 |
+
: FOREGROUND_FILE_IO_WORKER_POOL;
|
| 158 |
+
}
|
| 159 |
+
return traits.priority() == TaskPriority::BACKGROUND ? BACKGROUND_WORKER_POOL
|
| 160 |
+
: FOREGROUND_WORKER_POOL;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
class TaskSchedulerImplTest
|
| 164 |
+
: public testing::TestWithParam<TraitsExecutionModePair> {
|
| 165 |
+
protected:
|
| 166 |
+
TaskSchedulerImplTest() = default;
|
| 167 |
+
|
| 168 |
+
void SetUp() override {
|
| 169 |
+
using IORestriction = SchedulerWorkerPoolParams::IORestriction;
|
| 170 |
+
|
| 171 |
+
std::vector<SchedulerWorkerPoolParams> params_vector;
|
| 172 |
+
|
| 173 |
+
ASSERT_EQ(BACKGROUND_WORKER_POOL, params_vector.size());
|
| 174 |
+
params_vector.emplace_back("Background", ThreadPriority::BACKGROUND,
|
| 175 |
+
IORestriction::DISALLOWED, 1U, TimeDelta::Max());
|
| 176 |
+
|
| 177 |
+
ASSERT_EQ(BACKGROUND_FILE_IO_WORKER_POOL, params_vector.size());
|
| 178 |
+
params_vector.emplace_back("BackgroundFileIO", ThreadPriority::BACKGROUND,
|
| 179 |
+
IORestriction::ALLOWED, 3U, TimeDelta::Max());
|
| 180 |
+
|
| 181 |
+
ASSERT_EQ(FOREGROUND_WORKER_POOL, params_vector.size());
|
| 182 |
+
params_vector.emplace_back("Foreground", ThreadPriority::NORMAL,
|
| 183 |
+
IORestriction::DISALLOWED, 4U, TimeDelta::Max());
|
| 184 |
+
|
| 185 |
+
ASSERT_EQ(FOREGROUND_FILE_IO_WORKER_POOL, params_vector.size());
|
| 186 |
+
params_vector.emplace_back("ForegroundFileIO", ThreadPriority::NORMAL,
|
| 187 |
+
IORestriction::ALLOWED, 12U, TimeDelta::Max());
|
| 188 |
+
|
| 189 |
+
scheduler_ = TaskSchedulerImpl::Create(params_vector,
|
| 190 |
+
Bind(&GetThreadPoolIndexForTraits));
|
| 191 |
+
ASSERT_TRUE(scheduler_);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
void TearDown() override { scheduler_->JoinForTesting(); }
|
| 195 |
+
|
| 196 |
+
std::unique_ptr<TaskSchedulerImpl> scheduler_;
|
| 197 |
+
|
| 198 |
+
private:
|
| 199 |
+
DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImplTest);
|
| 200 |
+
};
|
| 201 |
+
|
| 202 |
+
} // namespace
|
| 203 |
+
|
| 204 |
+
// Verifies that a Task posted via PostTaskWithTraits with parameterized
|
| 205 |
+
// TaskTraits runs on a thread with the expected priority and I/O restrictions.
|
| 206 |
+
// The ExecutionMode parameter is ignored by this test.
|
| 207 |
+
TEST_P(TaskSchedulerImplTest, PostTaskWithTraits) {
|
| 208 |
+
WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL,
|
| 209 |
+
WaitableEvent::InitialState::NOT_SIGNALED);
|
| 210 |
+
scheduler_->PostTaskWithTraits(
|
| 211 |
+
FROM_HERE, GetParam().traits,
|
| 212 |
+
Bind(&VerifyTaskEnvironementAndSignalEvent, GetParam().traits,
|
| 213 |
+
Unretained(&task_ran)));
|
| 214 |
+
task_ran.Wait();
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
// Verifies that Tasks posted via a TaskRunner with parameterized TaskTraits and
|
| 218 |
+
// ExecutionMode run on a thread with the expected priority and I/O restrictions
|
| 219 |
+
// and respect the characteristics of their ExecutionMode.
|
| 220 |
+
TEST_P(TaskSchedulerImplTest, PostTasksViaTaskRunner) {
|
| 221 |
+
test::TestTaskFactory factory(
|
| 222 |
+
scheduler_->CreateTaskRunnerWithTraits(GetParam().traits,
|
| 223 |
+
GetParam().execution_mode),
|
| 224 |
+
GetParam().execution_mode);
|
| 225 |
+
EXPECT_FALSE(factory.task_runner()->RunsTasksOnCurrentThread());
|
| 226 |
+
|
| 227 |
+
const size_t kNumTasksPerTest = 150;
|
| 228 |
+
for (size_t i = 0; i < kNumTasksPerTest; ++i) {
|
| 229 |
+
factory.PostTask(test::TestTaskFactory::PostNestedTask::NO,
|
| 230 |
+
Bind(&VerifyTaskEnvironement, GetParam().traits));
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
factory.WaitForAllTasksToRun();
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
INSTANTIATE_TEST_CASE_P(OneTraitsExecutionModePair,
|
| 237 |
+
TaskSchedulerImplTest,
|
| 238 |
+
::testing::ValuesIn(GetTraitsExecutionModePairs()));
|
| 239 |
+
|
| 240 |
+
// Spawns threads that simultaneously post Tasks to TaskRunners with various
|
| 241 |
+
// TaskTraits and ExecutionModes. Verifies that each Task runs on a thread with
|
| 242 |
+
// the expected priority and I/O restrictions and respects the characteristics
|
| 243 |
+
// of its ExecutionMode.
|
| 244 |
+
TEST_F(TaskSchedulerImplTest, MultipleTraitsExecutionModePairs) {
|
| 245 |
+
std::vector<std::unique_ptr<ThreadPostingTasks>> threads_posting_tasks;
|
| 246 |
+
for (const auto& traits_execution_mode_pair : GetTraitsExecutionModePairs()) {
|
| 247 |
+
threads_posting_tasks.push_back(WrapUnique(new ThreadPostingTasks(
|
| 248 |
+
scheduler_.get(), traits_execution_mode_pair.traits,
|
| 249 |
+
traits_execution_mode_pair.execution_mode)));
|
| 250 |
+
threads_posting_tasks.back()->Start();
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
for (const auto& thread : threads_posting_tasks) {
|
| 254 |
+
thread->WaitForAllTasksToRun();
|
| 255 |
+
thread->Join();
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
// TODO(fdoray): Add tests with Sequences that move around worker pools once
|
| 260 |
+
// child TaskRunners are supported.
|
| 261 |
+
|
| 262 |
+
} // namespace internal
|
| 263 |
+
} // namespace base
|
pool/shard002/C++/0034682_updategeomatchsetresponse.cpp
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright 2013-2021 Paul Colby
|
| 3 |
+
|
| 4 |
+
This file is part of QtAws.
|
| 5 |
+
|
| 6 |
+
QtAws is free software: you can redistribute it and/or modify
|
| 7 |
+
it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
(at your option) any later version.
|
| 10 |
+
|
| 11 |
+
QtAws 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 Lesser General Public License for more details.
|
| 15 |
+
|
| 16 |
+
You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
along with the QtAws. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "updategeomatchsetresponse.h"
|
| 21 |
+
#include "updategeomatchsetresponse_p.h"
|
| 22 |
+
|
| 23 |
+
#include <QDebug>
|
| 24 |
+
#include <QNetworkReply>
|
| 25 |
+
#include <QXmlStreamReader>
|
| 26 |
+
|
| 27 |
+
namespace QtAws {
|
| 28 |
+
namespace WAF {
|
| 29 |
+
|
| 30 |
+
/*!
|
| 31 |
+
* \class QtAws::WAF::UpdateGeoMatchSetResponse
|
| 32 |
+
* \brief The UpdateGeoMatchSetResponse class provides an interace for WAF UpdateGeoMatchSet responses.
|
| 33 |
+
*
|
| 34 |
+
* \inmodule QtAwsWAF
|
| 35 |
+
*
|
| 36 |
+
* <note>
|
| 37 |
+
*
|
| 38 |
+
* This is <b>AWS WAF Classic</b> documentation. For more information, see <a
|
| 39 |
+
* href="https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html">AWS WAF Classic</a> in the
|
| 40 |
+
* developer
|
| 41 |
+
*
|
| 42 |
+
* guide>
|
| 43 |
+
*
|
| 44 |
+
* <b>For the latest version of AWS WAF</b>, use the AWS WAFV2 API and see the <a
|
| 45 |
+
* href="https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html">AWS WAF Developer Guide</a>. With the
|
| 46 |
+
* latest version, AWS WAF has a single set of endpoints for regional and global use.
|
| 47 |
+
*
|
| 48 |
+
* </p </note>
|
| 49 |
+
*
|
| 50 |
+
* This is the <i>AWS WAF Classic API Reference</i> for using AWS WAF Classic with Amazon CloudFront. The AWS WAF Classic
|
| 51 |
+
* actions and data types listed in the reference are available for protecting Amazon CloudFront distributions. You can use
|
| 52 |
+
* these actions and data types via the endpoint <i>waf.amazonaws.com</i>. This guide is for developers who need detailed
|
| 53 |
+
* information about the AWS WAF Classic API actions, data types, and errors. For detailed information about AWS WAF
|
| 54 |
+
* Classic features and an overview of how to use the AWS WAF Classic API, see the <a
|
| 55 |
+
* href="https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html">AWS WAF Classic</a> in the
|
| 56 |
+
* developer
|
| 57 |
+
*
|
| 58 |
+
* \sa WafClient::updateGeoMatchSet
|
| 59 |
+
*/
|
| 60 |
+
|
| 61 |
+
/*!
|
| 62 |
+
* Constructs a UpdateGeoMatchSetResponse object for \a reply to \a request, with parent \a parent.
|
| 63 |
+
*/
|
| 64 |
+
UpdateGeoMatchSetResponse::UpdateGeoMatchSetResponse(
|
| 65 |
+
const UpdateGeoMatchSetRequest &request,
|
| 66 |
+
QNetworkReply * const reply,
|
| 67 |
+
QObject * const parent)
|
| 68 |
+
: WafResponse(new UpdateGeoMatchSetResponsePrivate(this), parent)
|
| 69 |
+
{
|
| 70 |
+
setRequest(new UpdateGeoMatchSetRequest(request));
|
| 71 |
+
setReply(reply);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/*!
|
| 75 |
+
* \reimp
|
| 76 |
+
*/
|
| 77 |
+
const UpdateGeoMatchSetRequest * UpdateGeoMatchSetResponse::request() const
|
| 78 |
+
{
|
| 79 |
+
Q_D(const UpdateGeoMatchSetResponse);
|
| 80 |
+
return static_cast<const UpdateGeoMatchSetRequest *>(d->request);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/*!
|
| 84 |
+
* \reimp
|
| 85 |
+
* Parses a successful WAF UpdateGeoMatchSet \a response.
|
| 86 |
+
*/
|
| 87 |
+
void UpdateGeoMatchSetResponse::parseSuccess(QIODevice &response)
|
| 88 |
+
{
|
| 89 |
+
//Q_D(UpdateGeoMatchSetResponse);
|
| 90 |
+
QXmlStreamReader xml(&response);
|
| 91 |
+
/// @todo
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/*!
|
| 95 |
+
* \class QtAws::WAF::UpdateGeoMatchSetResponsePrivate
|
| 96 |
+
* \brief The UpdateGeoMatchSetResponsePrivate class provides private implementation for UpdateGeoMatchSetResponse.
|
| 97 |
+
* \internal
|
| 98 |
+
*
|
| 99 |
+
* \inmodule QtAwsWAF
|
| 100 |
+
*/
|
| 101 |
+
|
| 102 |
+
/*!
|
| 103 |
+
* Constructs a UpdateGeoMatchSetResponsePrivate object with public implementation \a q.
|
| 104 |
+
*/
|
| 105 |
+
UpdateGeoMatchSetResponsePrivate::UpdateGeoMatchSetResponsePrivate(
|
| 106 |
+
UpdateGeoMatchSetResponse * const q) : WafResponsePrivate(q)
|
| 107 |
+
{
|
| 108 |
+
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/*!
|
| 112 |
+
* Parses a WAF UpdateGeoMatchSet response element from \a xml.
|
| 113 |
+
*/
|
| 114 |
+
void UpdateGeoMatchSetResponsePrivate::parseUpdateGeoMatchSetResponse(QXmlStreamReader &xml)
|
| 115 |
+
{
|
| 116 |
+
Q_ASSERT(xml.name() == QLatin1String("UpdateGeoMatchSetResponse"));
|
| 117 |
+
Q_UNUSED(xml) ///< @todo
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
} // namespace WAF
|
| 121 |
+
} // namespace QtAws
|
pool/shard002/C++/0034688_output_m001u006.cpp
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <iostream>
|
| 2 |
+
#include "gtest/gtest.h"
|
| 3 |
+
#include "test_miranda.hpp"
|
| 4 |
+
|
| 5 |
+
namespace {
|
| 6 |
+
|
| 7 |
+
class OM001U006 : public TestIOBase {
|
| 8 |
+
protected:
|
| 9 |
+
OM001U006() {
|
| 10 |
+
IFNAME1 = (char *) "mir_001.fasta";
|
| 11 |
+
IFNAME2 = (char *) "utr3_006.fasta";
|
| 12 |
+
O1FNAME1 = (char *) "test_output1_site_6.txt";
|
| 13 |
+
O1FNAME2 = (char *) "test_output1_mrna_6.txt";
|
| 14 |
+
O2FNAME1 = (char *) "test_output2_site_6.txt";
|
| 15 |
+
O2FNAME2 = (char *) "test_output2_mrna_6.txt";
|
| 16 |
+
OMPATH = (char *) "mk_miranda/";
|
| 17 |
+
}
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
TEST_F(OM001U006, comp_site) {
|
| 21 |
+
(void) mikan::MKCoreMain<mr3as::MR3Options, mr3as::MR3Core >(argc, (const char **) argv);
|
| 22 |
+
gtest_compare_two_files(o1file1, o2file1);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
TEST_F(OM001U006, comp_mrna) {
|
| 26 |
+
(void) mikan::MKCoreMain<mr3as::MR3Options, mr3as::MR3Core >(argc, (const char **) argv);
|
| 27 |
+
gtest_compare_two_files(o1file2, o2file2);
|
| 28 |
+
}
|
| 29 |
+
}
|
pool/shard002/C++/0034689_emi2.cpp
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
EIBD eib bus access and management daemon
|
| 3 |
+
Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
|
| 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
|
| 16 |
+
along with this program; if not, write to the Free Software
|
| 17 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "emi2.h"
|
| 21 |
+
|
| 22 |
+
#include "emi.h"
|
| 23 |
+
|
| 24 |
+
EMI2Driver::EMI2Driver (LowLevelIface* c, IniSectionPtr& s, LowLevelDriver *i) : EMI_Common(c,s,i)
|
| 25 |
+
{
|
| 26 |
+
t->setAuxName("EMI2");
|
| 27 |
+
sendLocal_done.set<EMI2Driver,&EMI2Driver::sendLocal_done_cb>(this);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void
|
| 31 |
+
EMI2Driver::sendLocal_done_cb(bool success)
|
| 32 |
+
{
|
| 33 |
+
if (!success || sendLocal_done_next == N_bad)
|
| 34 |
+
{
|
| 35 |
+
errored();
|
| 36 |
+
LowLevelFilter::stopped();
|
| 37 |
+
}
|
| 38 |
+
else if (sendLocal_done_next == N_down)
|
| 39 |
+
LowLevelFilter::stop();
|
| 40 |
+
else if (sendLocal_done_next == N_up)
|
| 41 |
+
LowLevelFilter::started();
|
| 42 |
+
else if (sendLocal_done_next == N_open)
|
| 43 |
+
{
|
| 44 |
+
sendLocal_done_next = N_up;
|
| 45 |
+
const uint8_t t2[] = { 0xa9, 0x00, 0x18, 0x34, 0x56, 0x78, 0x0a };
|
| 46 |
+
send_Local (CArray (t2, sizeof (t2)),1);
|
| 47 |
+
}
|
| 48 |
+
else if (sendLocal_done_next == N_enter)
|
| 49 |
+
{
|
| 50 |
+
sendLocal_done_next = N_up;
|
| 51 |
+
const uint8_t t2[] = { 0xa9, 0x90, 0x18, 0x34, 0x45, 0x67, 0x8a };
|
| 52 |
+
send_Local (CArray (t2, sizeof (t2)),1);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void
|
| 58 |
+
EMI2Driver::cmdEnterMonitor ()
|
| 59 |
+
{
|
| 60 |
+
sendLocal_done_next = N_enter;
|
| 61 |
+
const uint8_t t1[] = { 0xa9, 0x1E, 0x12, 0x34, 0x56, 0x78, 0x9a };
|
| 62 |
+
send_Local (CArray (t1, sizeof (t1)),1);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
void
|
| 66 |
+
EMI2Driver::cmdLeaveMonitor ()
|
| 67 |
+
{
|
| 68 |
+
if (wait_confirm_low)
|
| 69 |
+
{
|
| 70 |
+
sendLocal_done_next = N_want_leave;
|
| 71 |
+
return;
|
| 72 |
+
}
|
| 73 |
+
sendLocal_done_next = N_down;
|
| 74 |
+
uint8_t t[] = { 0xa9, 0x1E, 0x12, 0x34, 0x56, 0x78, 0x9a };
|
| 75 |
+
send_Local (CArray (t, sizeof (t)),1);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
void
|
| 79 |
+
EMI2Driver::cmdOpen ()
|
| 80 |
+
{
|
| 81 |
+
sendLocal_done_next = N_open;
|
| 82 |
+
const uint8_t t1[] = { 0xa9, 0x1E, 0x12, 0x34, 0x56, 0x78, 0x9a };
|
| 83 |
+
send_Local (CArray (t1, sizeof (t1)),1);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
void
|
| 87 |
+
EMI2Driver::cmdClose ()
|
| 88 |
+
{
|
| 89 |
+
if (wait_confirm_low)
|
| 90 |
+
{
|
| 91 |
+
sendLocal_done_next = N_want_close;
|
| 92 |
+
return;
|
| 93 |
+
}
|
| 94 |
+
sendLocal_done_next = N_down;
|
| 95 |
+
uint8_t t[] = { 0xa9, 0x1E, 0x12, 0x34, 0x56, 0x78, 0x9a };
|
| 96 |
+
send_Local (CArray (t, sizeof (t)),1);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
void EMI2Driver::started()
|
| 100 |
+
{
|
| 101 |
+
reset_ack_wait = true;
|
| 102 |
+
reset_timer.start(0.5, 0);
|
| 103 |
+
sendReset();
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
void EMI2Driver::reset_timer_cb(ev::timer&, int)
|
| 107 |
+
{
|
| 108 |
+
ERRORPRINTF(t, E_ERROR | 57, "reset timed out");
|
| 109 |
+
errored();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
void EMI2Driver::do_send_Next()
|
| 113 |
+
{
|
| 114 |
+
if (reset_ack_wait)
|
| 115 |
+
{
|
| 116 |
+
reset_ack_wait = false;
|
| 117 |
+
reset_timer.stop();
|
| 118 |
+
EMI_Common::started();
|
| 119 |
+
}
|
| 120 |
+
else if (sendLocal_done_next == N_want_close)
|
| 121 |
+
{
|
| 122 |
+
wait_confirm_low = false;
|
| 123 |
+
cmdClose();
|
| 124 |
+
}
|
| 125 |
+
else if (sendLocal_done_next == N_want_leave)
|
| 126 |
+
{
|
| 127 |
+
wait_confirm_low = false;
|
| 128 |
+
cmdLeaveMonitor();
|
| 129 |
+
}
|
| 130 |
+
else
|
| 131 |
+
EMI_Common::do_send_Next();
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
const uint8_t *
|
| 135 |
+
EMI2Driver::getIndTypes() const
|
| 136 |
+
{
|
| 137 |
+
static const uint8_t indTypes[] = { 0x2E, 0x29, 0x2B };
|
| 138 |
+
return indTypes;
|
| 139 |
+
}
|
| 140 |
+
|
pool/shard002/C++/0034691_memoryagent.cpp
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/****************************************************************************
|
| 2 |
+
**
|
| 3 |
+
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
| 4 |
+
** Contact: http://www.qt-project.org/legal
|
| 5 |
+
**
|
| 6 |
+
** This file is part of Qt Creator.
|
| 7 |
+
**
|
| 8 |
+
** Commercial License Usage
|
| 9 |
+
** Licensees holding valid commercial Qt licenses may use this file in
|
| 10 |
+
** accordance with the commercial license agreement provided with the
|
| 11 |
+
** Software or, alternatively, in accordance with the terms contained in
|
| 12 |
+
** a written agreement between you and Digia. For licensing terms and
|
| 13 |
+
** conditions see http://qt.digia.com/licensing. For further information
|
| 14 |
+
** use the contact form at http://qt.digia.com/contact-us.
|
| 15 |
+
**
|
| 16 |
+
** GNU Lesser General Public License Usage
|
| 17 |
+
** Alternatively, this file may be used under the terms of the GNU Lesser
|
| 18 |
+
** General Public License version 2.1 as published by the Free Software
|
| 19 |
+
** Foundation and appearing in the file LICENSE.LGPL included in the
|
| 20 |
+
** packaging of this file. Please review the following information to
|
| 21 |
+
** ensure the GNU Lesser General Public License version 2.1 requirements
|
| 22 |
+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
| 23 |
+
**
|
| 24 |
+
** In addition, as a special exception, Digia gives you certain additional
|
| 25 |
+
** rights. These rights are described in the Digia Qt LGPL Exception
|
| 26 |
+
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
| 27 |
+
**
|
| 28 |
+
****************************************************************************/
|
| 29 |
+
|
| 30 |
+
#include "memoryagent.h"
|
| 31 |
+
#include "memoryview.h"
|
| 32 |
+
|
| 33 |
+
#include "breakhandler.h"
|
| 34 |
+
#include "debuggerengine.h"
|
| 35 |
+
#include "debuggerstartparameters.h"
|
| 36 |
+
#include "debuggercore.h"
|
| 37 |
+
#include "debuggerinternalconstants.h"
|
| 38 |
+
|
| 39 |
+
#include <coreplugin/coreconstants.h>
|
| 40 |
+
#include <coreplugin/editormanager/ieditor.h>
|
| 41 |
+
#include <coreplugin/editormanager/editormanager.h>
|
| 42 |
+
|
| 43 |
+
#include <utils/qtcassert.h>
|
| 44 |
+
#include <extensionsystem/pluginmanager.h>
|
| 45 |
+
#include <extensionsystem/invoker.h>
|
| 46 |
+
|
| 47 |
+
#include <QMessageBox>
|
| 48 |
+
|
| 49 |
+
#include <cstring>
|
| 50 |
+
|
| 51 |
+
using namespace Core;
|
| 52 |
+
|
| 53 |
+
namespace Debugger {
|
| 54 |
+
namespace Internal {
|
| 55 |
+
|
| 56 |
+
///////////////////////////////////////////////////////////////////////
|
| 57 |
+
//
|
| 58 |
+
// MemoryAgent
|
| 59 |
+
//
|
| 60 |
+
///////////////////////////////////////////////////////////////////////
|
| 61 |
+
|
| 62 |
+
/*!
|
| 63 |
+
\class Debugger::Internal::MemoryAgent
|
| 64 |
+
|
| 65 |
+
Objects form this class are created in response to user actions in
|
| 66 |
+
the Gui for showing raw memory from the inferior. After creation
|
| 67 |
+
it handles communication between the engine and the bineditor.
|
| 68 |
+
|
| 69 |
+
Memory can be shown as
|
| 70 |
+
\list
|
| 71 |
+
\li Editor: Create an IEditor using the normal editor factory
|
| 72 |
+
interface (m_editors)
|
| 73 |
+
\li View: Separate top-level view consisting of a Bin Editor widget
|
| 74 |
+
(m_view).
|
| 75 |
+
\endlist
|
| 76 |
+
|
| 77 |
+
Views are updated on the DebuggerEngine::stackFrameCompleted signal.
|
| 78 |
+
An exception are views of class Debugger::RegisterMemoryView tracking the
|
| 79 |
+
content pointed to by a register (eg stack pointer, instruction pointer).
|
| 80 |
+
They are connected to the set/changed signals of
|
| 81 |
+
the engine's register handler.
|
| 82 |
+
|
| 83 |
+
\sa Debugger::MemoryView, Debugger::RegisterMemoryView
|
| 84 |
+
*/
|
| 85 |
+
|
| 86 |
+
MemoryAgent::MemoryAgent(DebuggerEngine *engine)
|
| 87 |
+
: QObject(engine), m_engine(engine)
|
| 88 |
+
{
|
| 89 |
+
QTC_CHECK(engine);
|
| 90 |
+
connect(engine, SIGNAL(stateChanged(Debugger::DebuggerState)),
|
| 91 |
+
this, SLOT(engineStateChanged(Debugger::DebuggerState)));
|
| 92 |
+
connect(engine, SIGNAL(stackFrameCompleted()), this,
|
| 93 |
+
SLOT(updateContents()));
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
MemoryAgent::~MemoryAgent()
|
| 97 |
+
{
|
| 98 |
+
closeEditors();
|
| 99 |
+
closeViews();
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
void MemoryAgent::closeEditors()
|
| 103 |
+
{
|
| 104 |
+
if (m_editors.isEmpty())
|
| 105 |
+
return;
|
| 106 |
+
|
| 107 |
+
QSet<IDocument *> documents;
|
| 108 |
+
foreach (QPointer<IEditor> editor, m_editors)
|
| 109 |
+
if (editor)
|
| 110 |
+
documents.insert(editor->document());
|
| 111 |
+
EditorManager::closeDocuments(documents.toList());
|
| 112 |
+
m_editors.clear();
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
void MemoryAgent::closeViews()
|
| 116 |
+
{
|
| 117 |
+
foreach (const QPointer<MemoryView> &w, m_views)
|
| 118 |
+
if (w)
|
| 119 |
+
w->close();
|
| 120 |
+
m_views.clear();
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
void MemoryAgent::updateMemoryView(quint64 address, quint64 length)
|
| 124 |
+
{
|
| 125 |
+
m_engine->fetchMemory(this, sender(), address, length);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
void MemoryAgent::connectBinEditorWidget(QWidget *w)
|
| 129 |
+
{
|
| 130 |
+
connect(w, SIGNAL(dataRequested(quint64)), SLOT(fetchLazyData(quint64)));
|
| 131 |
+
connect(w, SIGNAL(newWindowRequested(quint64)), SLOT(createBinEditor(quint64)));
|
| 132 |
+
connect(w, SIGNAL(newRangeRequested(quint64)), SLOT(provideNewRange(quint64)));
|
| 133 |
+
connect(w, SIGNAL(dataChanged(quint64,QByteArray)), SLOT(handleDataChanged(quint64,QByteArray)));
|
| 134 |
+
connect(w, SIGNAL(dataChanged(quint64,QByteArray)), SLOT(handleDataChanged(quint64,QByteArray)));
|
| 135 |
+
connect(w, SIGNAL(addWatchpointRequested(quint64,uint)), SLOT(handleWatchpointRequest(quint64,uint)));
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
bool MemoryAgent::doCreateBinEditor(quint64 addr, unsigned flags,
|
| 139 |
+
const QList<MemoryMarkup> &ml, const QPoint &pos,
|
| 140 |
+
QString title, QWidget *parent)
|
| 141 |
+
{
|
| 142 |
+
const bool readOnly = (flags & DebuggerEngine::MemoryReadOnly) != 0;
|
| 143 |
+
if (title.isEmpty())
|
| 144 |
+
title = tr("Memory at 0x%1").arg(addr, 0, 16);
|
| 145 |
+
// Separate view?
|
| 146 |
+
if (flags & DebuggerEngine::MemoryView) {
|
| 147 |
+
// Ask BIN editor plugin for factory service and have it create a bin editor widget.
|
| 148 |
+
QWidget *binEditor = 0;
|
| 149 |
+
if (QObject *factory = ExtensionSystem::PluginManager::getObjectByClassName(QLatin1String("BinEditor::BinEditorWidgetFactory")))
|
| 150 |
+
binEditor = ExtensionSystem::invoke<QWidget *>(factory, "createWidget", (QWidget *)0);
|
| 151 |
+
if (!binEditor)
|
| 152 |
+
return false;
|
| 153 |
+
connectBinEditorWidget(binEditor);
|
| 154 |
+
MemoryView::setBinEditorReadOnly(binEditor, readOnly);
|
| 155 |
+
MemoryView::setBinEditorNewWindowRequestAllowed(binEditor, true);
|
| 156 |
+
MemoryView *topLevel = 0;
|
| 157 |
+
// Memory view tracking register value, providing its own updating mechanism.
|
| 158 |
+
if (flags & DebuggerEngine::MemoryTrackRegister) {
|
| 159 |
+
RegisterMemoryView *rmv = new RegisterMemoryView(binEditor, parent);
|
| 160 |
+
rmv->init(m_engine->registerHandler(), int(addr));
|
| 161 |
+
topLevel = rmv;
|
| 162 |
+
} else {
|
| 163 |
+
// Ordinary memory view
|
| 164 |
+
MemoryView::setBinEditorMarkup(binEditor, ml);
|
| 165 |
+
MemoryView::setBinEditorRange(binEditor, addr, MemoryAgent::DataRange, MemoryAgent::BinBlockSize);
|
| 166 |
+
topLevel = new MemoryView(binEditor, parent);
|
| 167 |
+
topLevel->setWindowTitle(title);
|
| 168 |
+
}
|
| 169 |
+
m_views << topLevel;
|
| 170 |
+
topLevel->move(pos);
|
| 171 |
+
topLevel->show();
|
| 172 |
+
return true;
|
| 173 |
+
}
|
| 174 |
+
// Editor: Register tracking not supported.
|
| 175 |
+
QTC_ASSERT(!(flags & DebuggerEngine::MemoryTrackRegister), return false);
|
| 176 |
+
if (!title.endsWith(QLatin1Char('$')))
|
| 177 |
+
title.append(QLatin1String(" $"));
|
| 178 |
+
IEditor *editor = EditorManager::openEditorWithContents(
|
| 179 |
+
Core::Constants::K_DEFAULT_BINARY_EDITOR_ID, &title);
|
| 180 |
+
if (!editor)
|
| 181 |
+
return false;
|
| 182 |
+
editor->document()->setProperty(Constants::OPENED_BY_DEBUGGER, QVariant(true));
|
| 183 |
+
editor->document()->setTemporary(true);
|
| 184 |
+
QWidget *editorBinEditor = editor->widget();
|
| 185 |
+
connectBinEditorWidget(editorBinEditor);
|
| 186 |
+
MemoryView::setBinEditorReadOnly(editorBinEditor, readOnly);
|
| 187 |
+
MemoryView::setBinEditorNewWindowRequestAllowed(editorBinEditor, true);
|
| 188 |
+
MemoryView::setBinEditorRange(editorBinEditor, addr, MemoryAgent::DataRange, MemoryAgent::BinBlockSize);
|
| 189 |
+
MemoryView::setBinEditorMarkup(editorBinEditor, ml);
|
| 190 |
+
m_editors << editor;
|
| 191 |
+
return true;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
void MemoryAgent::createBinEditor(quint64 addr, unsigned flags,
|
| 195 |
+
const QList<MemoryMarkup> &ml, const QPoint &pos,
|
| 196 |
+
const QString &title, QWidget *parent)
|
| 197 |
+
{
|
| 198 |
+
if (!doCreateBinEditor(addr, flags, ml, pos, title, parent))
|
| 199 |
+
showMessageBox(QMessageBox::Warning,
|
| 200 |
+
tr("No Memory Viewer Available"),
|
| 201 |
+
tr("The memory contents cannot be shown as no viewer plugin "
|
| 202 |
+
"for binary data has been loaded."));
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
void MemoryAgent::createBinEditor(quint64 addr)
|
| 206 |
+
{
|
| 207 |
+
createBinEditor(addr, 0, QList<MemoryMarkup>(), QPoint(), QString(), 0);
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
void MemoryAgent::fetchLazyData(quint64 block)
|
| 211 |
+
{
|
| 212 |
+
m_engine->fetchMemory(this, sender(), BinBlockSize * block, BinBlockSize);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
void MemoryAgent::addLazyData(QObject *editorToken, quint64 addr,
|
| 216 |
+
const QByteArray &ba)
|
| 217 |
+
{
|
| 218 |
+
QWidget *w = qobject_cast<QWidget *>(editorToken);
|
| 219 |
+
QTC_ASSERT(w, return);
|
| 220 |
+
MemoryView::binEditorAddData(w, addr, ba);
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
void MemoryAgent::provideNewRange(quint64 address)
|
| 224 |
+
{
|
| 225 |
+
QWidget *w = qobject_cast<QWidget *>(sender());
|
| 226 |
+
QTC_ASSERT(w, return);
|
| 227 |
+
MemoryView::setBinEditorRange(w, address, DataRange, BinBlockSize);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
void MemoryAgent::handleDataChanged(quint64 addr, const QByteArray &data)
|
| 231 |
+
{
|
| 232 |
+
m_engine->changeMemory(this, sender(), addr, data);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
void MemoryAgent::handleWatchpointRequest(quint64 address, uint size)
|
| 236 |
+
{
|
| 237 |
+
m_engine->breakHandler()->setWatchpointAtAddress(address, size);
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
void MemoryAgent::updateContents()
|
| 241 |
+
{
|
| 242 |
+
foreach (const QPointer<Core::IEditor> &e, m_editors)
|
| 243 |
+
if (e)
|
| 244 |
+
MemoryView::binEditorUpdateContents(e->widget());
|
| 245 |
+
// Update all views except register views, which trigger on
|
| 246 |
+
// register value set/changed.
|
| 247 |
+
foreach (const QPointer<MemoryView> &w, m_views)
|
| 248 |
+
if (w && !qobject_cast<RegisterMemoryView *>(w.data()))
|
| 249 |
+
w->updateContents();
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
bool MemoryAgent::hasVisibleEditor() const
|
| 253 |
+
{
|
| 254 |
+
QList<IEditor *> visible = EditorManager::visibleEditors();
|
| 255 |
+
foreach (QPointer<IEditor> editor, m_editors)
|
| 256 |
+
if (visible.contains(editor.data()))
|
| 257 |
+
return true;
|
| 258 |
+
return false;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
void MemoryAgent::engineStateChanged(Debugger::DebuggerState s)
|
| 262 |
+
{
|
| 263 |
+
switch (s) {
|
| 264 |
+
case DebuggerFinished:
|
| 265 |
+
closeViews();
|
| 266 |
+
foreach (const QPointer<IEditor> &editor, m_editors)
|
| 267 |
+
if (editor) { // Prevent triggering updates, etc.
|
| 268 |
+
MemoryView::setBinEditorReadOnly(editor->widget(), true);
|
| 269 |
+
editor->widget()->disconnect(this);
|
| 270 |
+
}
|
| 271 |
+
break;
|
| 272 |
+
default:
|
| 273 |
+
break;
|
| 274 |
+
}
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
bool MemoryAgent::isBigEndian(const ProjectExplorer::Abi &a)
|
| 278 |
+
{
|
| 279 |
+
switch (a.architecture()) {
|
| 280 |
+
case ProjectExplorer::Abi::UnknownArchitecture:
|
| 281 |
+
case ProjectExplorer::Abi::X86Architecture:
|
| 282 |
+
case ProjectExplorer::Abi::ItaniumArchitecture: // Configureable
|
| 283 |
+
case ProjectExplorer::Abi::ArmArchitecture: // Configureable
|
| 284 |
+
case ProjectExplorer::Abi::ShArchitecture: // Configureable
|
| 285 |
+
break;
|
| 286 |
+
case ProjectExplorer::Abi::MipsArchitecture: // Configureable
|
| 287 |
+
case ProjectExplorer::Abi::PowerPCArchitecture: // Configureable
|
| 288 |
+
return true;
|
| 289 |
+
}
|
| 290 |
+
return false;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
// Read a POD variable from a memory location. Swap bytes if endianness differs
|
| 294 |
+
template <class POD> POD readPod(const unsigned char *data, bool swapByteOrder)
|
| 295 |
+
{
|
| 296 |
+
POD pod = 0;
|
| 297 |
+
if (swapByteOrder) {
|
| 298 |
+
unsigned char *target = reinterpret_cast<unsigned char *>(&pod) + sizeof(POD) - 1;
|
| 299 |
+
for (size_t i = 0; i < sizeof(POD); i++)
|
| 300 |
+
*target-- = data[i];
|
| 301 |
+
} else {
|
| 302 |
+
std::memcpy(&pod, data, sizeof(POD));
|
| 303 |
+
}
|
| 304 |
+
return pod;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
// Read memory from debuggee
|
| 308 |
+
quint64 MemoryAgent::readInferiorPointerValue(const unsigned char *data, const ProjectExplorer::Abi &a)
|
| 309 |
+
{
|
| 310 |
+
const bool swapByteOrder = isBigEndian(a) != isBigEndian(ProjectExplorer::Abi::hostAbi());
|
| 311 |
+
return a.wordWidth() == 32 ? readPod<quint32>(data, swapByteOrder) :
|
| 312 |
+
readPod<quint64>(data, swapByteOrder);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
} // namespace Internal
|
| 316 |
+
} // namespace Debugger
|
| 317 |
+
;
|
pool/shard002/C++/0034694_ProcessStartInfoUnitTests.cpp
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <Switch/System/Diagnostics/ProcessStartInfo.hpp>
|
| 2 |
+
#include <Switch/System/Console.hpp>
|
| 3 |
+
#include <gtest/gtest.h>
|
| 4 |
+
|
| 5 |
+
using namespace System;
|
| 6 |
+
using namespace System::Diagnostics;
|
| 7 |
+
|
| 8 |
+
namespace UnitTests {
|
| 9 |
+
TEST(ProcessStartInfoUnitTest, Constructor) {
|
| 10 |
+
ProcessStartInfo psi;
|
| 11 |
+
ASSERT_EQ(string::Empty, psi.Arguments);
|
| 12 |
+
ASSERT_FALSE(psi.CreateNoWindow);
|
| 13 |
+
ASSERT_EQ(string::Empty, psi.Domain);
|
| 14 |
+
ASSERT_EQ(0, psi.EnvironmentVariables().Count);
|
| 15 |
+
ASSERT_FALSE(psi.ErrorDialog);
|
| 16 |
+
ASSERT_EQ(0, psi.ErrorDialogParamHandle());
|
| 17 |
+
ASSERT_EQ(string::Empty, psi.FileName);
|
| 18 |
+
ASSERT_FALSE(psi.LoadUserProfile);
|
| 19 |
+
ASSERT_EQ(string::Empty, psi.PasswordInClearText);
|
| 20 |
+
ASSERT_FALSE(psi.RedirectStandardError);
|
| 21 |
+
ASSERT_FALSE(psi.RedirectStandardInput);
|
| 22 |
+
ASSERT_FALSE(psi.RedirectStandardOutput);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
TEST(ProcessStartInfoUnitTest, ConstructorWithFileName) {
|
| 26 |
+
ProcessStartInfo psi("FileName");
|
| 27 |
+
ASSERT_EQ(string::Empty, psi.Arguments);
|
| 28 |
+
ASSERT_FALSE(psi.CreateNoWindow);
|
| 29 |
+
ASSERT_EQ(string::Empty, psi.Domain);
|
| 30 |
+
ASSERT_EQ(0, psi.EnvironmentVariables().Count);
|
| 31 |
+
ASSERT_FALSE(psi.ErrorDialog);
|
| 32 |
+
ASSERT_EQ(0, psi.ErrorDialogParamHandle());
|
| 33 |
+
ASSERT_EQ("FileName", psi.FileName);
|
| 34 |
+
ASSERT_FALSE(psi.LoadUserProfile);
|
| 35 |
+
ASSERT_EQ(string::Empty, psi.PasswordInClearText);
|
| 36 |
+
ASSERT_FALSE(psi.RedirectStandardError);
|
| 37 |
+
ASSERT_FALSE(psi.RedirectStandardInput);
|
| 38 |
+
ASSERT_FALSE(psi.RedirectStandardOutput);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
TEST(ProcessStartInfoUnitTest, ConstructorWithFileNameAndArgument) {
|
| 42 |
+
ProcessStartInfo psi("FileName", "Arguments");
|
| 43 |
+
ASSERT_EQ("Arguments", psi.Arguments);
|
| 44 |
+
ASSERT_FALSE(psi.CreateNoWindow);
|
| 45 |
+
ASSERT_EQ(string::Empty, psi.Domain);
|
| 46 |
+
ASSERT_EQ(0, psi.EnvironmentVariables().Count);
|
| 47 |
+
ASSERT_FALSE(psi.ErrorDialog);
|
| 48 |
+
ASSERT_EQ(0, psi.ErrorDialogParamHandle());
|
| 49 |
+
ASSERT_EQ("FileName", psi.FileName);
|
| 50 |
+
ASSERT_FALSE(psi.LoadUserProfile);
|
| 51 |
+
ASSERT_EQ(string::Empty, psi.PasswordInClearText);
|
| 52 |
+
ASSERT_FALSE(psi.RedirectStandardError);
|
| 53 |
+
ASSERT_FALSE(psi.RedirectStandardInput);
|
| 54 |
+
ASSERT_FALSE(psi.RedirectStandardOutput);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
TEST(ProcessStartInfoUnitTest, ConstructorByCopy) {
|
| 58 |
+
ProcessStartInfo psiOriginal("FileName", "Arguments");
|
| 59 |
+
ProcessStartInfo psi = psiOriginal;
|
| 60 |
+
ASSERT_EQ(psiOriginal.Arguments, psi.Arguments);
|
| 61 |
+
ASSERT_EQ(psiOriginal.CreateNoWindow, psi.CreateNoWindow);
|
| 62 |
+
ASSERT_EQ(psiOriginal.Domain, psi.Domain);
|
| 63 |
+
ASSERT_EQ(psiOriginal.EnvironmentVariables, psi.EnvironmentVariables);
|
| 64 |
+
ASSERT_EQ(psiOriginal.ErrorDialog, psi.ErrorDialog);
|
| 65 |
+
ASSERT_EQ(psiOriginal.ErrorDialogParamHandle, psi.ErrorDialogParamHandle);
|
| 66 |
+
ASSERT_EQ(psiOriginal.FileName, psi.FileName);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
TEST(ProcessStartInfoUnitTest, SetPasswordThenCheckPasswordInClearText) {
|
| 70 |
+
ProcessStartInfo psi;
|
| 71 |
+
char32 password[] = {'M', 'y', ' ', 'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
|
| 72 |
+
psi.Pasword = System::Security::SecureString(password, 11);
|
| 73 |
+
ASSERT_EQ("My password", psi.PasswordInClearText);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
TEST(ProcessStartInfoUnitTest, SetPasswordInClearTextThenCheckPasswordInClearText) {
|
| 77 |
+
ProcessStartInfo psi;
|
| 78 |
+
psi.PasswordInClearText = "My password";
|
| 79 |
+
ASSERT_EQ("My password", psi.PasswordInClearText);
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
pool/shard002/C++/0034699_ioutil_test.cpp
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "libreactor/ioutil.h"
|
| 2 |
+
#include "libreactor/misc.h"
|
| 3 |
+
#include <iostream>
|
| 4 |
+
|
| 5 |
+
int main() {
|
| 6 |
+
Reactor reactor;
|
| 7 |
+
|
| 8 |
+
std::vector<FDPtr> fds = fd_pair(reactor);
|
| 9 |
+
|
| 10 |
+
ioutil::write(fds[0], ByteString::copy_from("hello")).wait(reactor);
|
| 11 |
+
ioutil::read(fds[1], 4).then<ByteString>([&](ByteString ret) {
|
| 12 |
+
std::cerr << ret << std::endl;
|
| 13 |
+
return ioutil::read(fds[1], 1);
|
| 14 |
+
}).then<unit>([](ByteString ret) {
|
| 15 |
+
std::cerr << ret << std::endl;
|
| 16 |
+
return unit();
|
| 17 |
+
}).wait(reactor);
|
| 18 |
+
|
| 19 |
+
exit(0);
|
| 20 |
+
}
|
pool/shard002/C++/0034704_coincontroltreewidget.cpp
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2011-2015 The Oakcoin 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 "coincontroltreewidget.h"
|
| 6 |
+
#include "coincontroldialog.h"
|
| 7 |
+
|
| 8 |
+
CoinControlTreeWidget::CoinControlTreeWidget(QWidget *parent) :
|
| 9 |
+
QTreeWidget(parent)
|
| 10 |
+
{
|
| 11 |
+
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
void CoinControlTreeWidget::keyPressEvent(QKeyEvent *event)
|
| 15 |
+
{
|
| 16 |
+
if (event->key() == Qt::Key_Space) // press spacebar -> select checkbox
|
| 17 |
+
{
|
| 18 |
+
event->ignore();
|
| 19 |
+
int COLUMN_CHECKBOX = 0;
|
| 20 |
+
if(this->currentItem())
|
| 21 |
+
this->currentItem()->setCheckState(COLUMN_CHECKBOX, ((this->currentItem()->checkState(COLUMN_CHECKBOX) == Qt::Checked) ? Qt::Unchecked : Qt::Checked));
|
| 22 |
+
}
|
| 23 |
+
else if (event->key() == Qt::Key_Escape) // press esc -> close dialog
|
| 24 |
+
{
|
| 25 |
+
event->ignore();
|
| 26 |
+
CoinControlDialog *coinControlDialog = (CoinControlDialog*)this->parentWidget();
|
| 27 |
+
coinControlDialog->done(QDialog::Accepted);
|
| 28 |
+
}
|
| 29 |
+
else
|
| 30 |
+
{
|
| 31 |
+
this->QTreeWidget::keyPressEvent(event);
|
| 32 |
+
}
|
| 33 |
+
}
|
pool/shard002/C++/0034707_CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193_char_memmove_65b.cpp
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193_char_memmove_65b.cpp
|
| 3 |
+
Label Definition File: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193.label.xml
|
| 4 |
+
Template File: sources-sink-65b.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 122 Heap Based Buffer Overflow
|
| 9 |
+
* BadSource: Allocate memory for a string, but do not allocate space for NULL terminator
|
| 10 |
+
* GoodSource: Allocate enough memory for a string and the NULL terminator
|
| 11 |
+
* Sinks: memmove
|
| 12 |
+
* BadSink : Copy string to data using memmove()
|
| 13 |
+
* Flow Variant: 65 Data/control flow: data passed as an argument from one function to a function in a different source file called via a function pointer
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
|
| 17 |
+
#include "std_testcase.h"
|
| 18 |
+
|
| 19 |
+
#ifndef _WIN32
|
| 20 |
+
#include <wchar.h>
|
| 21 |
+
#endif
|
| 22 |
+
|
| 23 |
+
/* MAINTENANCE NOTE: The length of this string should equal the 10 */
|
| 24 |
+
#define SRC_STRING "AAAAAAAAAA"
|
| 25 |
+
|
| 26 |
+
namespace CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193_char_memmove_65
|
| 27 |
+
{
|
| 28 |
+
|
| 29 |
+
#ifndef OMITBAD
|
| 30 |
+
|
| 31 |
+
void badSink(char * data)
|
| 32 |
+
{
|
| 33 |
+
{
|
| 34 |
+
char source[10+1] = SRC_STRING;
|
| 35 |
+
/* Copy length + 1 to include NUL terminator from source */
|
| 36 |
+
/* POTENTIAL FLAW: data may not have enough space to hold source */
|
| 37 |
+
memmove(data, source, (strlen(source) + 1) * sizeof(char));
|
| 38 |
+
printLine(data);
|
| 39 |
+
delete [] data;
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
#endif /* OMITBAD */
|
| 44 |
+
|
| 45 |
+
#ifndef OMITGOOD
|
| 46 |
+
|
| 47 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 48 |
+
void goodG2BSink(char * data)
|
| 49 |
+
{
|
| 50 |
+
{
|
| 51 |
+
char source[10+1] = SRC_STRING;
|
| 52 |
+
/* Copy length + 1 to include NUL terminator from source */
|
| 53 |
+
/* POTENTIAL FLAW: data may not have enough space to hold source */
|
| 54 |
+
memmove(data, source, (strlen(source) + 1) * sizeof(char));
|
| 55 |
+
printLine(data);
|
| 56 |
+
delete [] data;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
#endif /* OMITGOOD */
|
| 61 |
+
|
| 62 |
+
} /* close namespace */
|
pool/shard002/C++/0034708_QxSqlLimit.cpp
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/****************************************************************************
|
| 2 |
+
**
|
| 3 |
+
** http://www.qxorm.com/
|
| 4 |
+
** http://sourceforge.net/projects/qxorm/
|
| 5 |
+
** Original file by Lionel Marty
|
| 6 |
+
**
|
| 7 |
+
** This file is part of the QxOrm library
|
| 8 |
+
**
|
| 9 |
+
** This software is provided 'as-is', without any express or implied
|
| 10 |
+
** warranty. In no event will the authors be held liable for any
|
| 11 |
+
** damages arising from the use of this software.
|
| 12 |
+
**
|
| 13 |
+
** GNU Lesser General Public License Usage
|
| 14 |
+
** This file must be used under the terms of the GNU Lesser
|
| 15 |
+
** General Public License version 2.1 as published by the Free Software
|
| 16 |
+
** Foundation and appearing in the file 'license.lgpl.txt' included in the
|
| 17 |
+
** packaging of this file. Please review the following information to
|
| 18 |
+
** ensure the GNU Lesser General Public License version 2.1 requirements
|
| 19 |
+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
| 20 |
+
**
|
| 21 |
+
** If you have questions regarding the use of this file, please contact :
|
| 22 |
+
** contact@qxorm.com
|
| 23 |
+
**
|
| 24 |
+
****************************************************************************/
|
| 25 |
+
|
| 26 |
+
#include <QxPrecompiled.h>
|
| 27 |
+
|
| 28 |
+
#include <QxDao/QxSqlElement/QxSqlLimit.h>
|
| 29 |
+
|
| 30 |
+
#include <QxDao/QxSqlDatabase.h>
|
| 31 |
+
|
| 32 |
+
#include <QxMemLeak/mem_leak.h>
|
| 33 |
+
|
| 34 |
+
namespace qx {
|
| 35 |
+
namespace dao {
|
| 36 |
+
namespace detail {
|
| 37 |
+
|
| 38 |
+
QxSqlLimit::QxSqlLimit(int index) : IxSqlElement(index) { ; }
|
| 39 |
+
|
| 40 |
+
QxSqlLimit::~QxSqlLimit() { ; }
|
| 41 |
+
|
| 42 |
+
QString QxSqlLimit::toString() const
|
| 43 |
+
{
|
| 44 |
+
if (! m_pSqlGenerator) { qAssert(false); return ""; }
|
| 45 |
+
return m_pSqlGenerator->getLimit(this);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void QxSqlLimit::resolve(QSqlQuery & query) const
|
| 49 |
+
{
|
| 50 |
+
if (! m_pSqlGenerator) { qAssert(false); return; }
|
| 51 |
+
m_pSqlGenerator->resolveLimit(query, this);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
void QxSqlLimit::postProcess(QString & sql) const
|
| 55 |
+
{
|
| 56 |
+
if (! m_pSqlGenerator) { qAssert(false); return; }
|
| 57 |
+
m_pSqlGenerator->postProcess(sql, this);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
int QxSqlLimit::getStartRow() const
|
| 61 |
+
{
|
| 62 |
+
qAssert(m_lstValues.count() == 2);
|
| 63 |
+
return ((m_lstValues.count() > 0) ? m_lstValues.at(0).toInt() : 0);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
int QxSqlLimit::getRowsCount() const
|
| 67 |
+
{
|
| 68 |
+
qAssert(m_lstValues.count() == 2);
|
| 69 |
+
return ((m_lstValues.count() > 1) ? m_lstValues.at(1).toInt() : 0);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
int QxSqlLimit::getMaxRow() const
|
| 73 |
+
{
|
| 74 |
+
qAssert(m_lstValues.count() == 2);
|
| 75 |
+
return ((m_lstValues.count() > 1) ? (m_lstValues.at(0).toInt() + m_lstValues.at(1).toInt()) : 0);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
QString QxSqlLimit::getStartRow_ParamKey() const
|
| 79 |
+
{
|
| 80 |
+
QString sStartRow("offset_start_row");
|
| 81 |
+
sStartRow += "_" + QString::number(m_iIndex) + "_0";
|
| 82 |
+
if (qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle() == qx::QxSqlDatabase::ph_style_question_mark) { sStartRow = "?"; }
|
| 83 |
+
else if (qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle() == qx::QxSqlDatabase::ph_style_at_name) { sStartRow = "@" + sStartRow; }
|
| 84 |
+
else { sStartRow = ":" + sStartRow; }
|
| 85 |
+
return sStartRow;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
QString QxSqlLimit::getRowsCount_ParamKey() const
|
| 89 |
+
{
|
| 90 |
+
QString sRowsCount("limit_rows_count");
|
| 91 |
+
sRowsCount += "_" + QString::number(m_iIndex) + "_0";
|
| 92 |
+
if (qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle() == qx::QxSqlDatabase::ph_style_question_mark) { sRowsCount = "?"; }
|
| 93 |
+
else if (qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle() == qx::QxSqlDatabase::ph_style_at_name) { sRowsCount = "@" + sRowsCount; }
|
| 94 |
+
else { sRowsCount = ":" + sRowsCount; }
|
| 95 |
+
return sRowsCount;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
QString QxSqlLimit::getMaxRow_ParamKey() const
|
| 99 |
+
{
|
| 100 |
+
QString sMaxRow("offset_max_row");
|
| 101 |
+
sMaxRow += "_" + QString::number(m_iIndex) + "_0";
|
| 102 |
+
if (qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle() == qx::QxSqlDatabase::ph_style_question_mark) { sMaxRow = "?"; }
|
| 103 |
+
else if (qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle() == qx::QxSqlDatabase::ph_style_at_name) { sMaxRow = "@" + sMaxRow; }
|
| 104 |
+
else { sMaxRow = ":" + sMaxRow; }
|
| 105 |
+
return sMaxRow;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
} // namespace detail
|
| 109 |
+
} // namespace dao
|
| 110 |
+
} // namespace qx
|
pool/shard002/C++/0034717_ThirdPartyUtil.cpp
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
| 2 |
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
| 3 |
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
| 4 |
+
|
| 5 |
+
#include "ThirdPartyUtil.h"
|
| 6 |
+
#include "nsNetUtil.h"
|
| 7 |
+
#include "nsIServiceManager.h"
|
| 8 |
+
#include "nsIHttpChannelInternal.h"
|
| 9 |
+
#include "nsIDOMWindow.h"
|
| 10 |
+
#include "nsILoadContext.h"
|
| 11 |
+
#include "nsIPrincipal.h"
|
| 12 |
+
#include "nsIScriptObjectPrincipal.h"
|
| 13 |
+
#include "nsThreadUtils.h"
|
| 14 |
+
|
| 15 |
+
NS_IMPL_ISUPPORTS1(ThirdPartyUtil, mozIThirdPartyUtil)
|
| 16 |
+
|
| 17 |
+
nsresult
|
| 18 |
+
ThirdPartyUtil::Init()
|
| 19 |
+
{
|
| 20 |
+
NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_NOT_AVAILABLE);
|
| 21 |
+
|
| 22 |
+
nsresult rv;
|
| 23 |
+
mTLDService = do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID, &rv);
|
| 24 |
+
return rv;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
// Determine if aFirstDomain is a different base domain to aSecondURI; or, if
|
| 28 |
+
// the concept of base domain does not apply, determine if the two hosts are not
|
| 29 |
+
// string-identical.
|
| 30 |
+
nsresult
|
| 31 |
+
ThirdPartyUtil::IsThirdPartyInternal(const nsCString& aFirstDomain,
|
| 32 |
+
nsIURI* aSecondURI,
|
| 33 |
+
bool* aResult)
|
| 34 |
+
{
|
| 35 |
+
NS_ASSERTION(aSecondURI, "null URI!");
|
| 36 |
+
|
| 37 |
+
// Get the base domain for aSecondURI.
|
| 38 |
+
nsCString secondDomain;
|
| 39 |
+
nsresult rv = GetBaseDomain(aSecondURI, secondDomain);
|
| 40 |
+
if (NS_FAILED(rv))
|
| 41 |
+
return rv;
|
| 42 |
+
|
| 43 |
+
// Check strict equality.
|
| 44 |
+
*aResult = aFirstDomain != secondDomain;
|
| 45 |
+
return NS_OK;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
// Get the URI associated with a window.
|
| 49 |
+
already_AddRefed<nsIURI>
|
| 50 |
+
ThirdPartyUtil::GetURIFromWindow(nsIDOMWindow* aWin)
|
| 51 |
+
{
|
| 52 |
+
nsCOMPtr<nsIScriptObjectPrincipal> scriptObjPrin = do_QueryInterface(aWin);
|
| 53 |
+
NS_ENSURE_TRUE(scriptObjPrin, NULL);
|
| 54 |
+
|
| 55 |
+
nsIPrincipal* prin = scriptObjPrin->GetPrincipal();
|
| 56 |
+
NS_ENSURE_TRUE(prin, NULL);
|
| 57 |
+
|
| 58 |
+
nsCOMPtr<nsIURI> result;
|
| 59 |
+
prin->GetURI(getter_AddRefs(result));
|
| 60 |
+
return result.forget();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Determine if aFirstURI is third party with respect to aSecondURI. See docs
|
| 64 |
+
// for mozIThirdPartyUtil.
|
| 65 |
+
NS_IMETHODIMP
|
| 66 |
+
ThirdPartyUtil::IsThirdPartyURI(nsIURI* aFirstURI,
|
| 67 |
+
nsIURI* aSecondURI,
|
| 68 |
+
bool* aResult)
|
| 69 |
+
{
|
| 70 |
+
NS_ENSURE_ARG(aFirstURI);
|
| 71 |
+
NS_ENSURE_ARG(aSecondURI);
|
| 72 |
+
NS_ASSERTION(aResult, "null outparam pointer");
|
| 73 |
+
|
| 74 |
+
nsCString firstHost;
|
| 75 |
+
nsresult rv = GetBaseDomain(aFirstURI, firstHost);
|
| 76 |
+
if (NS_FAILED(rv))
|
| 77 |
+
return rv;
|
| 78 |
+
|
| 79 |
+
return IsThirdPartyInternal(firstHost, aSecondURI, aResult);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// Determine if any URI of the window hierarchy of aWindow is foreign with
|
| 83 |
+
// respect to aSecondURI. See docs for mozIThirdPartyUtil.
|
| 84 |
+
NS_IMETHODIMP
|
| 85 |
+
ThirdPartyUtil::IsThirdPartyWindow(nsIDOMWindow* aWindow,
|
| 86 |
+
nsIURI* aURI,
|
| 87 |
+
bool* aResult)
|
| 88 |
+
{
|
| 89 |
+
NS_ENSURE_ARG(aWindow);
|
| 90 |
+
NS_ASSERTION(aResult, "null outparam pointer");
|
| 91 |
+
|
| 92 |
+
bool result;
|
| 93 |
+
|
| 94 |
+
// Get the URI of the window, and its base domain.
|
| 95 |
+
nsCOMPtr<nsIURI> currentURI = GetURIFromWindow(aWindow);
|
| 96 |
+
NS_ENSURE_TRUE(currentURI, NS_ERROR_INVALID_ARG);
|
| 97 |
+
|
| 98 |
+
nsCString bottomDomain;
|
| 99 |
+
nsresult rv = GetBaseDomain(currentURI, bottomDomain);
|
| 100 |
+
if (NS_FAILED(rv))
|
| 101 |
+
return rv;
|
| 102 |
+
|
| 103 |
+
if (aURI) {
|
| 104 |
+
// Determine whether aURI is foreign with respect to currentURI.
|
| 105 |
+
rv = IsThirdPartyInternal(bottomDomain, aURI, &result);
|
| 106 |
+
if (NS_FAILED(rv))
|
| 107 |
+
return rv;
|
| 108 |
+
|
| 109 |
+
if (result) {
|
| 110 |
+
*aResult = true;
|
| 111 |
+
return NS_OK;
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
nsCOMPtr<nsIDOMWindow> current = aWindow, parent;
|
| 116 |
+
nsCOMPtr<nsIURI> parentURI;
|
| 117 |
+
do {
|
| 118 |
+
// We use GetScriptableParent rather than GetParent because we consider
|
| 119 |
+
// <iframe mozbrowser/mozapp> to be a top-level frame.
|
| 120 |
+
rv = current->GetScriptableParent(getter_AddRefs(parent));
|
| 121 |
+
NS_ENSURE_SUCCESS(rv, rv);
|
| 122 |
+
|
| 123 |
+
if (SameCOMIdentity(parent, current)) {
|
| 124 |
+
// We're at the topmost content window. We already know the answer.
|
| 125 |
+
*aResult = false;
|
| 126 |
+
return NS_OK;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
parentURI = GetURIFromWindow(parent);
|
| 130 |
+
NS_ENSURE_TRUE(parentURI, NS_ERROR_INVALID_ARG);
|
| 131 |
+
|
| 132 |
+
rv = IsThirdPartyInternal(bottomDomain, parentURI, &result);
|
| 133 |
+
if (NS_FAILED(rv))
|
| 134 |
+
return rv;
|
| 135 |
+
|
| 136 |
+
if (result) {
|
| 137 |
+
*aResult = true;
|
| 138 |
+
return NS_OK;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
current = parent;
|
| 142 |
+
currentURI = parentURI;
|
| 143 |
+
} while (1);
|
| 144 |
+
|
| 145 |
+
NS_NOTREACHED("should've returned");
|
| 146 |
+
return NS_ERROR_UNEXPECTED;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
// Determine if the URI associated with aChannel or any URI of the window
|
| 150 |
+
// hierarchy associated with the channel is foreign with respect to aSecondURI.
|
| 151 |
+
// See docs for mozIThirdPartyUtil.
|
| 152 |
+
NS_IMETHODIMP
|
| 153 |
+
ThirdPartyUtil::IsThirdPartyChannel(nsIChannel* aChannel,
|
| 154 |
+
nsIURI* aURI,
|
| 155 |
+
bool* aResult)
|
| 156 |
+
{
|
| 157 |
+
NS_ENSURE_ARG(aChannel);
|
| 158 |
+
NS_ASSERTION(aResult, "null outparam pointer");
|
| 159 |
+
|
| 160 |
+
nsresult rv;
|
| 161 |
+
bool doForce = false;
|
| 162 |
+
nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal =
|
| 163 |
+
do_QueryInterface(aChannel);
|
| 164 |
+
if (httpChannelInternal) {
|
| 165 |
+
rv = httpChannelInternal->GetForceAllowThirdPartyCookie(&doForce);
|
| 166 |
+
NS_ENSURE_SUCCESS(rv, rv);
|
| 167 |
+
|
| 168 |
+
// If aURI was not supplied, and we're forcing, then we're by definition
|
| 169 |
+
// not foreign. If aURI was supplied, we still want to check whether it's
|
| 170 |
+
// foreign with respect to the channel URI. (The forcing only applies to
|
| 171 |
+
// whatever window hierarchy exists above the channel.)
|
| 172 |
+
if (doForce && !aURI) {
|
| 173 |
+
*aResult = false;
|
| 174 |
+
return NS_OK;
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
// Obtain the URI from the channel, and its base domain.
|
| 179 |
+
nsCOMPtr<nsIURI> channelURI;
|
| 180 |
+
aChannel->GetURI(getter_AddRefs(channelURI));
|
| 181 |
+
NS_ENSURE_TRUE(channelURI, NS_ERROR_INVALID_ARG);
|
| 182 |
+
|
| 183 |
+
nsCString channelDomain;
|
| 184 |
+
rv = GetBaseDomain(channelURI, channelDomain);
|
| 185 |
+
if (NS_FAILED(rv))
|
| 186 |
+
return rv;
|
| 187 |
+
|
| 188 |
+
if (aURI) {
|
| 189 |
+
// Determine whether aURI is foreign with respect to channelURI.
|
| 190 |
+
bool result;
|
| 191 |
+
rv = IsThirdPartyInternal(channelDomain, aURI, &result);
|
| 192 |
+
if (NS_FAILED(rv))
|
| 193 |
+
return rv;
|
| 194 |
+
|
| 195 |
+
// If it's foreign, or we're forcing, we're done.
|
| 196 |
+
if (result || doForce) {
|
| 197 |
+
*aResult = result;
|
| 198 |
+
return NS_OK;
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
// Find the associated window and its parent window.
|
| 203 |
+
nsCOMPtr<nsILoadContext> ctx;
|
| 204 |
+
NS_QueryNotificationCallbacks(aChannel, ctx);
|
| 205 |
+
if (!ctx) return NS_ERROR_INVALID_ARG;
|
| 206 |
+
|
| 207 |
+
// If there is no window, the consumer kicking off the load didn't provide one
|
| 208 |
+
// to the channel. This is limited to loads of certain types of resources. If
|
| 209 |
+
// those loads require cookies, the forceAllowThirdPartyCookie property should
|
| 210 |
+
// be set on the channel.
|
| 211 |
+
nsCOMPtr<nsIDOMWindow> ourWin, parentWin;
|
| 212 |
+
ctx->GetAssociatedWindow(getter_AddRefs(ourWin));
|
| 213 |
+
if (!ourWin) return NS_ERROR_INVALID_ARG;
|
| 214 |
+
|
| 215 |
+
// We use GetScriptableParent rather than GetParent because we consider
|
| 216 |
+
// <iframe mozbrowser/mozapp> to be a top-level frame.
|
| 217 |
+
ourWin->GetScriptableParent(getter_AddRefs(parentWin));
|
| 218 |
+
NS_ENSURE_TRUE(parentWin, NS_ERROR_INVALID_ARG);
|
| 219 |
+
|
| 220 |
+
// Check whether this is the document channel for this window (representing a
|
| 221 |
+
// load of a new page). In that situation we want to avoid comparing
|
| 222 |
+
// channelURI to ourWin, since what's in ourWin right now will be replaced as
|
| 223 |
+
// the channel loads. This covers the case of a freshly kicked-off load
|
| 224 |
+
// (e.g. the user typing something in the location bar, or clicking on a
|
| 225 |
+
// bookmark), where the window's URI hasn't yet been set, and will be bogus.
|
| 226 |
+
// It also covers situations where a subframe is navigated to someting that
|
| 227 |
+
// is same-origin with all its ancestors. This is a bit of a nasty hack, but
|
| 228 |
+
// we will hopefully flag these channels better later.
|
| 229 |
+
nsLoadFlags flags;
|
| 230 |
+
rv = aChannel->GetLoadFlags(&flags);
|
| 231 |
+
NS_ENSURE_SUCCESS(rv, rv);
|
| 232 |
+
|
| 233 |
+
if (flags & nsIChannel::LOAD_DOCUMENT_URI) {
|
| 234 |
+
if (SameCOMIdentity(ourWin, parentWin)) {
|
| 235 |
+
// We only need to compare aURI to the channel URI -- the window's will be
|
| 236 |
+
// bogus. We already know the answer.
|
| 237 |
+
*aResult = false;
|
| 238 |
+
return NS_OK;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
// Make sure to still compare to ourWin's ancestors
|
| 242 |
+
ourWin = parentWin;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
// Check the window hierarchy. This covers most cases for an ordinary page
|
| 246 |
+
// load from the location bar.
|
| 247 |
+
return IsThirdPartyWindow(ourWin, channelURI, aResult);
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
// Get the base domain for aHostURI; e.g. for "www.bbc.co.uk", this would be
|
| 251 |
+
// "bbc.co.uk". Only properly-formed URI's are tolerated, though a trailing
|
| 252 |
+
// dot may be present. If aHostURI is an IP address, an alias such as
|
| 253 |
+
// 'localhost', an eTLD such as 'co.uk', or the empty string, aBaseDomain will
|
| 254 |
+
// be the exact host. The result of this function should only be used in exact
|
| 255 |
+
// string comparisons, since substring comparisons will not be valid for the
|
| 256 |
+
// special cases elided above.
|
| 257 |
+
NS_IMETHODIMP
|
| 258 |
+
ThirdPartyUtil::GetBaseDomain(nsIURI* aHostURI,
|
| 259 |
+
nsACString& aBaseDomain)
|
| 260 |
+
{
|
| 261 |
+
// Get the base domain. this will fail if the host contains a leading dot,
|
| 262 |
+
// more than one trailing dot, or is otherwise malformed.
|
| 263 |
+
nsresult rv = mTLDService->GetBaseDomain(aHostURI, 0, aBaseDomain);
|
| 264 |
+
if (rv == NS_ERROR_HOST_IS_IP_ADDRESS ||
|
| 265 |
+
rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
|
| 266 |
+
// aHostURI is either an IP address, an alias such as 'localhost', an eTLD
|
| 267 |
+
// such as 'co.uk', or the empty string. Uses the normalized host in such
|
| 268 |
+
// cases.
|
| 269 |
+
rv = aHostURI->GetAsciiHost(aBaseDomain);
|
| 270 |
+
}
|
| 271 |
+
NS_ENSURE_SUCCESS(rv, rv);
|
| 272 |
+
|
| 273 |
+
// aHostURI (and thus aBaseDomain) may be the string '.'. If so, fail.
|
| 274 |
+
if (aBaseDomain.Length() == 1 && aBaseDomain.Last() == '.')
|
| 275 |
+
return NS_ERROR_INVALID_ARG;
|
| 276 |
+
|
| 277 |
+
// Reject any URIs without a host that aren't file:// URIs. This makes it the
|
| 278 |
+
// only way we can get a base domain consisting of the empty string, which
|
| 279 |
+
// means we can safely perform foreign tests on such URIs where "not foreign"
|
| 280 |
+
// means "the involved URIs are all file://".
|
| 281 |
+
if (aBaseDomain.IsEmpty()) {
|
| 282 |
+
bool isFileURI = false;
|
| 283 |
+
aHostURI->SchemeIs("file", &isFileURI);
|
| 284 |
+
NS_ENSURE_TRUE(isFileURI, NS_ERROR_INVALID_ARG);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
return NS_OK;
|
| 288 |
+
}
|
pool/shard002/C++/0034720_juce_ValueWithDefault.cpp
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
==============================================================================
|
| 3 |
+
|
| 4 |
+
This file is part of the JUCE library.
|
| 5 |
+
Copyright (c) 2017 - ROLI Ltd.
|
| 6 |
+
|
| 7 |
+
JUCE is an open source library subject to commercial or open-source
|
| 8 |
+
licensing.
|
| 9 |
+
|
| 10 |
+
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
|
| 11 |
+
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
|
| 12 |
+
27th April 2017).
|
| 13 |
+
|
| 14 |
+
End User License Agreement: www.juce.com/juce-5-licence
|
| 15 |
+
Privacy Policy: www.juce.com/juce-5-privacy-policy
|
| 16 |
+
|
| 17 |
+
Or: You may also use this code under the terms of the GPL v3 (see
|
| 18 |
+
www.gnu.org/licenses).
|
| 19 |
+
|
| 20 |
+
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
| 21 |
+
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
| 22 |
+
DISCLAIMED.
|
| 23 |
+
|
| 24 |
+
==============================================================================
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
namespace juce
|
| 28 |
+
{
|
| 29 |
+
|
| 30 |
+
#if JUCE_UNIT_TESTS
|
| 31 |
+
|
| 32 |
+
class ValueWithDefaultTests : public UnitTest
|
| 33 |
+
{
|
| 34 |
+
public:
|
| 35 |
+
ValueWithDefaultTests() : UnitTest ("ValueWithDefault", "Values") {}
|
| 36 |
+
|
| 37 |
+
void runTest() override
|
| 38 |
+
{
|
| 39 |
+
beginTest ("default constructor");
|
| 40 |
+
{
|
| 41 |
+
ValueWithDefault vwd;
|
| 42 |
+
expect (vwd.isUsingDefault());
|
| 43 |
+
expect (vwd.get() == var());
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
beginTest ("missing property");
|
| 47 |
+
{
|
| 48 |
+
ValueTree t ("root");
|
| 49 |
+
ValueWithDefault vwd (t, "testKey", nullptr, "default");
|
| 50 |
+
|
| 51 |
+
expect (vwd.isUsingDefault());
|
| 52 |
+
expectEquals (vwd.get().toString(), String ("default"));
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
beginTest ("non-empty property");
|
| 56 |
+
{
|
| 57 |
+
ValueTree t ("root");
|
| 58 |
+
t.setProperty ("testKey", "non-default", nullptr);
|
| 59 |
+
|
| 60 |
+
ValueWithDefault vwd (t, "testKey", nullptr, "default");
|
| 61 |
+
|
| 62 |
+
expect (! vwd.isUsingDefault());
|
| 63 |
+
expectEquals (vwd.get().toString(), String ("non-default"));
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
beginTest ("set default");
|
| 67 |
+
{
|
| 68 |
+
ValueTree t ("root");
|
| 69 |
+
|
| 70 |
+
ValueWithDefault vwd (t, "testkey", nullptr);
|
| 71 |
+
vwd.setDefault ("default");
|
| 72 |
+
|
| 73 |
+
expect (vwd.isUsingDefault());
|
| 74 |
+
expectEquals (vwd.get().toString(), String ("default"));
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
beginTest ("set value");
|
| 78 |
+
{
|
| 79 |
+
ValueTree t ("root");
|
| 80 |
+
t.setProperty ("testkey", "testvalue", nullptr);
|
| 81 |
+
|
| 82 |
+
ValueWithDefault vwd (t, "testkey", nullptr, "default");
|
| 83 |
+
vwd = "newvalue";
|
| 84 |
+
|
| 85 |
+
expect (! vwd.isUsingDefault());
|
| 86 |
+
expectEquals (t["testkey"].toString(), String ("newvalue"));
|
| 87 |
+
|
| 88 |
+
vwd.resetToDefault();
|
| 89 |
+
|
| 90 |
+
expect (vwd.isUsingDefault());
|
| 91 |
+
expect (t["testkey"] == var());
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
static ValueWithDefaultTests valueWithDefaultTests;
|
| 97 |
+
|
| 98 |
+
#endif
|
| 99 |
+
|
| 100 |
+
} // namespace juce
|
pool/shard002/C++/0034721_file_cache_migrator.cc
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <base/file/file.h>
|
| 2 |
+
#include <base/logging.h>
|
| 3 |
+
#include <base/protobuf_utils.h>
|
| 4 |
+
#include <cache/file_cache.h>
|
| 5 |
+
#include <cache/manifest.pb.h>
|
| 6 |
+
|
| 7 |
+
#include <base/using_log.h>
|
| 8 |
+
|
| 9 |
+
namespace dist_clang {
|
| 10 |
+
namespace cache {
|
| 11 |
+
|
| 12 |
+
namespace {
|
| 13 |
+
|
| 14 |
+
bool Version_0_to_1(const String& common_path, ui32 to_version,
|
| 15 |
+
proto::Manifest& manifest, bool& modified) {
|
| 16 |
+
if (manifest.version() != 0 || to_version < 1) {
|
| 17 |
+
return true;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
DCHECK(!manifest.has_direct());
|
| 21 |
+
DCHECK(!manifest.has_v1());
|
| 22 |
+
|
| 23 |
+
if (manifest.headers_size()) {
|
| 24 |
+
manifest.mutable_direct()->mutable_headers()->Swap(
|
| 25 |
+
manifest.mutable_headers());
|
| 26 |
+
} else {
|
| 27 |
+
auto* v1 = manifest.mutable_v1();
|
| 28 |
+
ui64 size = 0;
|
| 29 |
+
|
| 30 |
+
v1->set_snappy(manifest.snappy());
|
| 31 |
+
v1->set_err(manifest.stderr());
|
| 32 |
+
v1->set_obj(manifest.object());
|
| 33 |
+
v1->set_dep(manifest.deps());
|
| 34 |
+
|
| 35 |
+
if (manifest.v1().err()) {
|
| 36 |
+
const String err_path = common_path + ".stderr";
|
| 37 |
+
if (base::File::Exists(err_path)) {
|
| 38 |
+
size += base::File::Size(err_path);
|
| 39 |
+
} else {
|
| 40 |
+
return false;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
if (manifest.v1().obj()) {
|
| 44 |
+
const String obj_path = common_path + ".o";
|
| 45 |
+
if (base::File::Exists(obj_path)) {
|
| 46 |
+
size += base::File::Size(obj_path);
|
| 47 |
+
} else {
|
| 48 |
+
return false;
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
if (manifest.v1().dep()) {
|
| 52 |
+
const String dep_path = common_path + ".d";
|
| 53 |
+
if (base::File::Exists(dep_path)) {
|
| 54 |
+
size += base::File::Size(dep_path);
|
| 55 |
+
} else {
|
| 56 |
+
return false;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
v1->set_size(size);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
manifest.clear_headers();
|
| 63 |
+
manifest.clear_snappy();
|
| 64 |
+
manifest.clear_stderr();
|
| 65 |
+
manifest.clear_object();
|
| 66 |
+
manifest.clear_deps();
|
| 67 |
+
|
| 68 |
+
manifest.set_version(1);
|
| 69 |
+
|
| 70 |
+
modified = true;
|
| 71 |
+
return true;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// Remove old direct cache entries since they contain absolute paths. And we
|
| 75 |
+
// can't distinguish which paths should shortened and which not.
|
| 76 |
+
bool Version_1_to_2(const String& common_path, ui32 to_version,
|
| 77 |
+
proto::Manifest& manifest, bool& modified) {
|
| 78 |
+
if (manifest.version() != 1 || to_version < 2) {
|
| 79 |
+
return true;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
if (manifest.has_direct()) {
|
| 83 |
+
// Expect that the entry will be removed.
|
| 84 |
+
return false;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
manifest.set_version(2);
|
| 88 |
+
return true;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
} // namespace
|
| 92 |
+
|
| 93 |
+
bool FileCache::Migrate(string::Hash hash, ui32 to_version) const {
|
| 94 |
+
DCHECK(to_version <= kManifestVersion);
|
| 95 |
+
|
| 96 |
+
const String common_path = CommonPath(hash);
|
| 97 |
+
const String manifest_path = common_path + ".manifest";
|
| 98 |
+
|
| 99 |
+
SQLite::Value entry;
|
| 100 |
+
if (entries_ && entries_->Get(hash.str, &entry) &&
|
| 101 |
+
std::get<SQLite::VERSION>(entry) == kManifestVersion) {
|
| 102 |
+
LOG(CACHE_VERBOSE) << "No migration for " << manifest_path
|
| 103 |
+
<< " required according to index";
|
| 104 |
+
return true;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
proto::Manifest manifest;
|
| 108 |
+
bool modified = false;
|
| 109 |
+
if (!base::LoadFromFile(manifest_path, &manifest)) {
|
| 110 |
+
LOG(CACHE_ERROR) << "Failed to load " << manifest_path;
|
| 111 |
+
return false;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
#define MIGRATE(from, to) \
|
| 115 |
+
if (!Version_##from##_to_##to(common_path, to_version, manifest, \
|
| 116 |
+
modified)) { \
|
| 117 |
+
LOG(CACHE_ERROR) << "Failed to migrate " << manifest_path \
|
| 118 |
+
<< " from version " #from " to " #to; \
|
| 119 |
+
return false; \
|
| 120 |
+
} else { \
|
| 121 |
+
LOG(CACHE_VERBOSE) << "Migrated " << manifest_path \
|
| 122 |
+
<< " from version " #from " to " #to; \
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
MIGRATE(0, 1);
|
| 126 |
+
MIGRATE(1, 2);
|
| 127 |
+
|
| 128 |
+
#undef MIGRATE
|
| 129 |
+
|
| 130 |
+
if (manifest.version() != to_version) {
|
| 131 |
+
LOG(CACHE_ERROR) << "Not an actual version " << manifest_path << ": "
|
| 132 |
+
<< manifest.version() << " vs. " << to_version;
|
| 133 |
+
return false;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
if (!modified) {
|
| 137 |
+
// TODO: make a unit-test that we don't rewrite manifest on disk.
|
| 138 |
+
LOG(CACHE_VERBOSE) << "No modifications for " << manifest_path;
|
| 139 |
+
return true;
|
| 140 |
+
} else if (!base::SaveToFile(manifest_path, manifest)) {
|
| 141 |
+
LOG(CACHE_ERROR) << "Failed to save " << manifest_path;
|
| 142 |
+
return false;
|
| 143 |
+
}
|
| 144 |
+
return true;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
} // namespace cache
|
| 148 |
+
} // namespace dist_clang
|
pool/shard002/C++/0034728_service_main.cc
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "base/base_switches.h"
|
| 6 |
+
#include "base/debug/debugger.h"
|
| 7 |
+
#include "base/message_loop/message_loop.h"
|
| 8 |
+
#include "base/metrics/statistics_recorder.h"
|
| 9 |
+
#include "base/run_loop.h"
|
| 10 |
+
#include "chrome/common/service_process_util.h"
|
| 11 |
+
#include "chrome/service/service_process.h"
|
| 12 |
+
#include "content/public/common/main_function_params.h"
|
| 13 |
+
#include "net/url_request/url_request.h"
|
| 14 |
+
|
| 15 |
+
// Mainline routine for running as the service process.
|
| 16 |
+
int ServiceProcessMain(const content::MainFunctionParams& parameters) {
|
| 17 |
+
// Chrome disallows cookies by default. All code paths that want to use
|
| 18 |
+
// cookies should go through the browser process.
|
| 19 |
+
net::URLRequest::SetDefaultCookiePolicyToBlock();
|
| 20 |
+
|
| 21 |
+
base::PlatformThread::SetName("CrServiceMain");
|
| 22 |
+
base::MessageLoopForUI main_message_loop;
|
| 23 |
+
if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) {
|
| 24 |
+
base::debug::WaitForDebugger(60, true);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
VLOG(1) << "Service process launched: "
|
| 28 |
+
<< parameters.command_line.GetCommandLineString();
|
| 29 |
+
|
| 30 |
+
base::StatisticsRecorder::Initialize();
|
| 31 |
+
|
| 32 |
+
// If there is already a service process running, quit now.
|
| 33 |
+
std::unique_ptr<ServiceProcessState> state(new ServiceProcessState);
|
| 34 |
+
if (!state->Initialize())
|
| 35 |
+
return 0;
|
| 36 |
+
|
| 37 |
+
ServiceProcess service_process;
|
| 38 |
+
if (service_process.Initialize(&main_message_loop,
|
| 39 |
+
parameters.command_line,
|
| 40 |
+
state.release())) {
|
| 41 |
+
base::RunLoop().Run();
|
| 42 |
+
} else {
|
| 43 |
+
LOG(ERROR) << "Service process failed to initialize";
|
| 44 |
+
}
|
| 45 |
+
return 0;
|
| 46 |
+
}
|
pool/shard002/C++/0034732_threadpool.cpp
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Thread Pool implementation for unix / linux environments
|
| 3 |
+
Copyright (C) 2008 Shobhit Gupta
|
| 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 |
+
#include <stdlib.h>
|
| 20 |
+
#include "threadpool.h"
|
| 21 |
+
|
| 22 |
+
using namespace std;
|
| 23 |
+
|
| 24 |
+
pthread_mutex_t ThreadPool::mutexSync = PTHREAD_MUTEX_INITIALIZER;
|
| 25 |
+
pthread_mutex_t ThreadPool::mutexWorkCompletion = PTHREAD_MUTEX_INITIALIZER;
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
ThreadPool::ThreadPool()
|
| 30 |
+
{
|
| 31 |
+
ThreadPool(2);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
ThreadPool::ThreadPool(int maxThreads)
|
| 35 |
+
{
|
| 36 |
+
if (maxThreads < 1) maxThreads=1;
|
| 37 |
+
|
| 38 |
+
//mutexSync = PTHREAD_MUTEX_INITIALIZER;
|
| 39 |
+
//mutexWorkCompletion = PTHREAD_MUTEX_INITIALIZER;
|
| 40 |
+
|
| 41 |
+
pthread_mutex_lock(&mutexSync);
|
| 42 |
+
this->maxThreads = maxThreads;
|
| 43 |
+
this->queueSize = maxThreads;
|
| 44 |
+
//workerQueue = new WorkerThread *[maxThreads];
|
| 45 |
+
workerQueue.resize(maxThreads, NULL);
|
| 46 |
+
topIndex = 0;
|
| 47 |
+
bottomIndex = 0;
|
| 48 |
+
incompleteWork = 0;
|
| 49 |
+
sem_init(&availableWork, 0, 0);
|
| 50 |
+
sem_init(&availableThreads, 0, queueSize);
|
| 51 |
+
pthread_mutex_unlock(&mutexSync);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
void ThreadPool::initializeThreads()
|
| 55 |
+
{
|
| 56 |
+
for(int i = 0; i<maxThreads; ++i)
|
| 57 |
+
{
|
| 58 |
+
pthread_t tempThread;
|
| 59 |
+
pthread_create(&tempThread, NULL, &ThreadPool::threadExecute, (void *) this );
|
| 60 |
+
//threadIdVec[i] = tempThread;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
ThreadPool::~ThreadPool()
|
| 66 |
+
{
|
| 67 |
+
workerQueue.clear();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
void ThreadPool::destroyPool(int maxPollSecs = 2)
|
| 73 |
+
{
|
| 74 |
+
while( incompleteWork>0 )
|
| 75 |
+
{
|
| 76 |
+
//cout << "Work is still incomplete=" << incompleteWork << endl;
|
| 77 |
+
sleep(maxPollSecs);
|
| 78 |
+
}
|
| 79 |
+
cout << "All Done!! Wow! That was a lot of work!" << endl;
|
| 80 |
+
sem_destroy(&availableWork);
|
| 81 |
+
sem_destroy(&availableThreads);
|
| 82 |
+
pthread_mutex_destroy(&mutexSync);
|
| 83 |
+
pthread_mutex_destroy(&mutexWorkCompletion);
|
| 84 |
+
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
bool ThreadPool::assignWork(WorkerThread *workerThread)
|
| 89 |
+
{
|
| 90 |
+
pthread_mutex_lock(&mutexWorkCompletion);
|
| 91 |
+
incompleteWork++;
|
| 92 |
+
//cout << "assignWork...incomapleteWork=" << incompleteWork << endl;
|
| 93 |
+
pthread_mutex_unlock(&mutexWorkCompletion);
|
| 94 |
+
|
| 95 |
+
sem_wait(&availableThreads);
|
| 96 |
+
|
| 97 |
+
pthread_mutex_lock(&mutexSync);
|
| 98 |
+
//workerVec[topIndex] = workerThread;
|
| 99 |
+
workerQueue[topIndex] = workerThread;
|
| 100 |
+
//cout << "Assigning Worker[" << workerThread->id << "] Address:[" << workerThread << "] to Queue index [" << topIndex << "]" << endl;
|
| 101 |
+
if(queueSize !=1 )
|
| 102 |
+
topIndex = (topIndex+1) % (queueSize-1);
|
| 103 |
+
sem_post(&availableWork);
|
| 104 |
+
pthread_mutex_unlock(&mutexSync);
|
| 105 |
+
return true;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
bool ThreadPool::fetchWork(WorkerThread **workerArg)
|
| 109 |
+
{
|
| 110 |
+
sem_wait(&availableWork);
|
| 111 |
+
|
| 112 |
+
pthread_mutex_lock(&mutexSync);
|
| 113 |
+
WorkerThread * workerThread = workerQueue[bottomIndex];
|
| 114 |
+
workerQueue[bottomIndex] = NULL;
|
| 115 |
+
*workerArg = workerThread;
|
| 116 |
+
if(queueSize !=1 )
|
| 117 |
+
bottomIndex = (bottomIndex+1) % (queueSize-1);
|
| 118 |
+
sem_post(&availableThreads);
|
| 119 |
+
pthread_mutex_unlock(&mutexSync);
|
| 120 |
+
return true;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
void *ThreadPool::threadExecute(void *param)
|
| 124 |
+
{
|
| 125 |
+
WorkerThread *worker = NULL;
|
| 126 |
+
|
| 127 |
+
while(((ThreadPool *)param)->fetchWork(&worker))
|
| 128 |
+
{
|
| 129 |
+
if(worker)
|
| 130 |
+
{
|
| 131 |
+
worker->executeThis();
|
| 132 |
+
//cout << "worker[" << worker->id << "]\tdelete address: [" << worker << "]" << endl;
|
| 133 |
+
delete worker;
|
| 134 |
+
worker = NULL;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
pthread_mutex_lock( &(((ThreadPool *)param)->mutexWorkCompletion) );
|
| 138 |
+
//cout << "Thread " << pthread_self() << " has completed a Job !" << endl;
|
| 139 |
+
((ThreadPool *)param)->incompleteWork--;
|
| 140 |
+
pthread_mutex_unlock( &(((ThreadPool *)param)->mutexWorkCompletion) );
|
| 141 |
+
}
|
| 142 |
+
return 0;
|
| 143 |
+
}
|
pool/shard002/C++/0034736_average_of_levels_in_binary_tree.cpp
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*******************************************************************************
|
| 2 |
+
* file name: average_of_levels_in_binary_tree.cpp
|
| 3 |
+
* author: Hui Chen. (c) 2018
|
| 4 |
+
* mail: chenhui13@baidu.com
|
| 5 |
+
* created time: 2018/08/28-19:45:22
|
| 6 |
+
* modified time: 2018/08/28-19:45:22
|
| 7 |
+
*******************************************************************************/
|
| 8 |
+
#include <iostream>
|
| 9 |
+
#include <queue>
|
| 10 |
+
#include <vector>
|
| 11 |
+
using namespace std;
|
| 12 |
+
/**
|
| 13 |
+
* Definition for a binary tree node.
|
| 14 |
+
* struct TreeNode {
|
| 15 |
+
* int val;
|
| 16 |
+
* TreeNode *left;
|
| 17 |
+
* TreeNode *right;
|
| 18 |
+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
|
| 19 |
+
* };
|
| 20 |
+
*/
|
| 21 |
+
struct TreeNode {
|
| 22 |
+
int val;
|
| 23 |
+
TreeNode *left;
|
| 24 |
+
TreeNode *right;
|
| 25 |
+
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
|
| 26 |
+
};
|
| 27 |
+
class Solution {
|
| 28 |
+
public:
|
| 29 |
+
vector<double> averageOfLevels(TreeNode* root) {
|
| 30 |
+
vector<double> res;
|
| 31 |
+
queue<TreeNode*> q1;
|
| 32 |
+
queue<TreeNode*> q2;
|
| 33 |
+
if (!root)
|
| 34 |
+
return res;
|
| 35 |
+
q1.push(root);
|
| 36 |
+
while (!q1.empty() || !q2.empty())
|
| 37 |
+
{
|
| 38 |
+
int count = 0;
|
| 39 |
+
int64_t sum = 0;
|
| 40 |
+
double avg = 0;
|
| 41 |
+
if (!q1.empty())
|
| 42 |
+
{
|
| 43 |
+
while (!q1.empty())
|
| 44 |
+
{
|
| 45 |
+
TreeNode* pnode = q1.front();
|
| 46 |
+
q1.pop();
|
| 47 |
+
sum += pnode->val;
|
| 48 |
+
count++;
|
| 49 |
+
if (pnode->left)
|
| 50 |
+
q2.push(pnode->left);
|
| 51 |
+
if (pnode->right)
|
| 52 |
+
q2.push(pnode->right);
|
| 53 |
+
}
|
| 54 |
+
avg = (double)sum/count;
|
| 55 |
+
cout<<"sum:"<<sum<<" count:"<<count<<" avg:"<<avg<<endl;
|
| 56 |
+
res.push_back(avg);
|
| 57 |
+
continue;
|
| 58 |
+
}
|
| 59 |
+
if (!q2.empty())
|
| 60 |
+
{
|
| 61 |
+
while (!q2.empty())
|
| 62 |
+
{
|
| 63 |
+
TreeNode* pnode = q2.front();
|
| 64 |
+
q2.pop();
|
| 65 |
+
sum += pnode->val;
|
| 66 |
+
count++;
|
| 67 |
+
if (pnode->left)
|
| 68 |
+
q1.push(pnode->left);
|
| 69 |
+
if (pnode->right)
|
| 70 |
+
q1.push(pnode->right);
|
| 71 |
+
}
|
| 72 |
+
avg = (double)sum/count;
|
| 73 |
+
cout<<"sum:"<<sum<<" count:"<<count<<" avg:"<<avg<<endl;
|
| 74 |
+
res.push_back(avg);
|
| 75 |
+
continue;
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
return res;
|
| 79 |
+
}
|
| 80 |
+
};
|
| 81 |
+
int main()
|
| 82 |
+
{}
|
pool/shard002/C++/0034737_CountVariances.cpp
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "MantidHistogramData/BinEdges.h"
|
| 2 |
+
#include "MantidHistogramData/CountVariances.h"
|
| 3 |
+
#include "MantidHistogramData/CountStandardDeviations.h"
|
| 4 |
+
#include "MantidHistogramData/FrequencyVariances.h"
|
| 5 |
+
#include "MantidHistogramData/FrequencyStandardDeviations.h"
|
| 6 |
+
|
| 7 |
+
namespace Mantid {
|
| 8 |
+
namespace HistogramData {
|
| 9 |
+
|
| 10 |
+
/// Constructs CountVariances from FrequencyVariances and bin width based on
|
| 11 |
+
/// BinEdges.
|
| 12 |
+
CountVariances::CountVariances(const FrequencyVariances &frequencies,
|
| 13 |
+
const BinEdges &edges)
|
| 14 |
+
: CountVariances(FrequencyVariances(frequencies), edges) {}
|
| 15 |
+
|
| 16 |
+
/// Move-constructs CountVariances from FrequencyVariances and bin width based
|
| 17 |
+
/// on BinEdges.
|
| 18 |
+
CountVariances::CountVariances(FrequencyVariances &&frequencies,
|
| 19 |
+
const BinEdges &edges) {
|
| 20 |
+
if (!frequencies)
|
| 21 |
+
return;
|
| 22 |
+
if (!edges)
|
| 23 |
+
throw std::logic_error("CountVariances: Cannot construct from "
|
| 24 |
+
"FrequencyVariances -- BinEdges are NULL.");
|
| 25 |
+
if ((frequencies.size() + 1) != edges.size())
|
| 26 |
+
if (frequencies.size() != 0 || edges.size() != 0)
|
| 27 |
+
throw std::logic_error("CountVariances: Cannot construct from "
|
| 28 |
+
"FrequencyVariances -- BinEdges size does not "
|
| 29 |
+
"match.");
|
| 30 |
+
// Cannot move frequencies private data since it is of different type.
|
| 31 |
+
m_data = frequencies.cowData();
|
| 32 |
+
frequencies = Kernel::cow_ptr<HistogramE>(nullptr);
|
| 33 |
+
auto &data = m_data.access();
|
| 34 |
+
for (size_t i = 0; i < data.size(); ++i) {
|
| 35 |
+
const auto width = edges[i + 1] - edges[i];
|
| 36 |
+
data[i] *= width * width;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
} // namespace HistogramData
|
| 41 |
+
} // namespace Mantid
|
pool/shard002/C++/0034745_B.cpp
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include<bits/stdc++.h>
|
| 2 |
+
using namespace std;
|
| 3 |
+
|
| 4 |
+
int n;
|
| 5 |
+
|
| 6 |
+
int Query(int p);
|
| 7 |
+
int main(){
|
| 8 |
+
scanf("%d",&n);
|
| 9 |
+
if (n%4){
|
| 10 |
+
puts("! -1");return 0;
|
| 11 |
+
}
|
| 12 |
+
int l=1,r=n/2,lkey=Query(l);
|
| 13 |
+
while (l+1<r){
|
| 14 |
+
int mid=(l+r)>>1;
|
| 15 |
+
//cout<<"["<<l<<" "<<r<<"]"<<mid<<endl;
|
| 16 |
+
int qk=Query(mid);
|
| 17 |
+
if (1ll*qk*lkey>0) l=mid,lkey=qk;
|
| 18 |
+
else r=mid-1;
|
| 19 |
+
}
|
| 20 |
+
Query(l);Query(r);
|
| 21 |
+
return 0;
|
| 22 |
+
}
|
| 23 |
+
int Query(int p){
|
| 24 |
+
printf("? %d\n? %d\n",p,p+n/2);fflush(stdout);
|
| 25 |
+
int a,b;scanf("%d %d",&a,&b);
|
| 26 |
+
if (a==b){
|
| 27 |
+
printf("! %d\n",p);exit(0);
|
| 28 |
+
}
|
| 29 |
+
return b-a;
|
| 30 |
+
}
|
pool/shard002/C++/0034746_flash_pkg.cpp
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// flash_pkg.cpp: ActionScript top level "flash" package.
|
| 2 |
+
//
|
| 3 |
+
// Copyright (C) 2009, 2010 Free Software Foundation, Inc.
|
| 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, write to the Free Software
|
| 17 |
+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 |
+
//
|
| 19 |
+
|
| 20 |
+
#include "flash_pkg.h"
|
| 21 |
+
|
| 22 |
+
#include "VM.h"
|
| 23 |
+
#include "fn_call.h"
|
| 24 |
+
#include "namedStrings.h"
|
| 25 |
+
#include "display/display_pkg.h"
|
| 26 |
+
#include "external/external_pkg.h"
|
| 27 |
+
#include "filters/filters_pkg.h"
|
| 28 |
+
#include "geom/geom_pkg.h"
|
| 29 |
+
#include "net/net_pkg.h"
|
| 30 |
+
#include "text/text_pkg.h"
|
| 31 |
+
#include "Global_as.h"
|
| 32 |
+
|
| 33 |
+
namespace gnash {
|
| 34 |
+
|
| 35 |
+
class as_value;
|
| 36 |
+
class as_object;
|
| 37 |
+
|
| 38 |
+
static as_value
|
| 39 |
+
get_flash_package(const fn_call& fn)
|
| 40 |
+
{
|
| 41 |
+
Global_as& gl = getGlobal(fn);
|
| 42 |
+
|
| 43 |
+
as_object* pkg = createObject(gl);
|
| 44 |
+
|
| 45 |
+
VM& vm = getVM(fn);
|
| 46 |
+
|
| 47 |
+
flash_text_package_init(*pkg, getURI(vm, "text"));
|
| 48 |
+
flash_display_package_init(*pkg, getURI(vm, "display"));
|
| 49 |
+
flash_filters_package_init(*pkg, getURI(vm, "filters"));
|
| 50 |
+
flash_geom_package_init(*pkg, getURI(vm, "geom"));
|
| 51 |
+
flash_net_package_init(*pkg, getURI(vm, "net"));
|
| 52 |
+
flash_external_package_init(*pkg, getURI(vm, "external"));
|
| 53 |
+
|
| 54 |
+
return pkg;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void
|
| 58 |
+
flash_package_init(as_object& where, const ObjectURI& uri)
|
| 59 |
+
{
|
| 60 |
+
const int flags = PropFlags::dontEnum | PropFlags::onlySWF8Up;
|
| 61 |
+
where.init_destructive_property(uri, get_flash_package, flags);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
// local Variables:
|
| 67 |
+
// mode: C++
|
| 68 |
+
// indent-tabs-mode: nil
|
| 69 |
+
// End:
|
pool/shard002/C++/0034750_decoder_selector.cc
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "media/filters/decoder_selector.h"
|
| 6 |
+
|
| 7 |
+
#include <utility>
|
| 8 |
+
|
| 9 |
+
#include "base/bind.h"
|
| 10 |
+
#include "base/callback_helpers.h"
|
| 11 |
+
#include "base/logging.h"
|
| 12 |
+
#include "base/single_thread_task_runner.h"
|
| 13 |
+
#include "build/build_config.h"
|
| 14 |
+
#include "media/base/audio_decoder.h"
|
| 15 |
+
#include "media/base/bind_to_current_loop.h"
|
| 16 |
+
#include "media/base/cdm_context.h"
|
| 17 |
+
#include "media/base/demuxer_stream.h"
|
| 18 |
+
#include "media/base/media_log.h"
|
| 19 |
+
#include "media/base/video_decoder.h"
|
| 20 |
+
#include "media/filters/decoder_stream_traits.h"
|
| 21 |
+
#include "media/filters/decrypting_demuxer_stream.h"
|
| 22 |
+
|
| 23 |
+
#if !defined(OS_ANDROID)
|
| 24 |
+
#include "media/filters/decrypting_audio_decoder.h"
|
| 25 |
+
#include "media/filters/decrypting_video_decoder.h"
|
| 26 |
+
#endif
|
| 27 |
+
|
| 28 |
+
namespace media {
|
| 29 |
+
|
| 30 |
+
static bool HasValidStreamConfig(DemuxerStream* stream) {
|
| 31 |
+
switch (stream->type()) {
|
| 32 |
+
case DemuxerStream::AUDIO:
|
| 33 |
+
return stream->audio_decoder_config().IsValidConfig();
|
| 34 |
+
case DemuxerStream::VIDEO:
|
| 35 |
+
return stream->video_decoder_config().IsValidConfig();
|
| 36 |
+
case DemuxerStream::UNKNOWN:
|
| 37 |
+
case DemuxerStream::TEXT:
|
| 38 |
+
case DemuxerStream::NUM_TYPES:
|
| 39 |
+
NOTREACHED();
|
| 40 |
+
}
|
| 41 |
+
return false;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
static bool IsStreamEncrypted(DemuxerStream* stream) {
|
| 45 |
+
switch (stream->type()) {
|
| 46 |
+
case DemuxerStream::AUDIO:
|
| 47 |
+
return stream->audio_decoder_config().is_encrypted();
|
| 48 |
+
case DemuxerStream::VIDEO:
|
| 49 |
+
return stream->video_decoder_config().is_encrypted();
|
| 50 |
+
case DemuxerStream::UNKNOWN:
|
| 51 |
+
case DemuxerStream::TEXT:
|
| 52 |
+
case DemuxerStream::NUM_TYPES:
|
| 53 |
+
NOTREACHED();
|
| 54 |
+
}
|
| 55 |
+
return false;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
template <DemuxerStream::Type StreamType>
|
| 59 |
+
DecoderSelector<StreamType>::DecoderSelector(
|
| 60 |
+
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
|
| 61 |
+
ScopedVector<Decoder> decoders,
|
| 62 |
+
const scoped_refptr<MediaLog>& media_log)
|
| 63 |
+
: task_runner_(task_runner),
|
| 64 |
+
decoders_(std::move(decoders)),
|
| 65 |
+
media_log_(media_log),
|
| 66 |
+
input_stream_(nullptr),
|
| 67 |
+
weak_ptr_factory_(this) {}
|
| 68 |
+
|
| 69 |
+
template <DemuxerStream::Type StreamType>
|
| 70 |
+
DecoderSelector<StreamType>::~DecoderSelector() {
|
| 71 |
+
DVLOG(2) << __FUNCTION__;
|
| 72 |
+
DCHECK(task_runner_->BelongsToCurrentThread());
|
| 73 |
+
|
| 74 |
+
if (!select_decoder_cb_.is_null())
|
| 75 |
+
ReturnNullDecoder();
|
| 76 |
+
|
| 77 |
+
decoder_.reset();
|
| 78 |
+
decrypted_stream_.reset();
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
template <DemuxerStream::Type StreamType>
|
| 82 |
+
void DecoderSelector<StreamType>::SelectDecoder(
|
| 83 |
+
DemuxerStream* stream,
|
| 84 |
+
CdmContext* cdm_context,
|
| 85 |
+
const SelectDecoderCB& select_decoder_cb,
|
| 86 |
+
const typename Decoder::OutputCB& output_cb,
|
| 87 |
+
const base::Closure& waiting_for_decryption_key_cb) {
|
| 88 |
+
DVLOG(2) << __FUNCTION__;
|
| 89 |
+
DCHECK(task_runner_->BelongsToCurrentThread());
|
| 90 |
+
DCHECK(stream);
|
| 91 |
+
DCHECK(select_decoder_cb_.is_null());
|
| 92 |
+
|
| 93 |
+
cdm_context_ = cdm_context;
|
| 94 |
+
waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb;
|
| 95 |
+
|
| 96 |
+
// Make sure |select_decoder_cb| runs on a different execution stack.
|
| 97 |
+
select_decoder_cb_ = BindToCurrentLoop(select_decoder_cb);
|
| 98 |
+
|
| 99 |
+
if (!HasValidStreamConfig(stream)) {
|
| 100 |
+
DLOG(ERROR) << "Invalid stream config.";
|
| 101 |
+
ReturnNullDecoder();
|
| 102 |
+
return;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
input_stream_ = stream;
|
| 106 |
+
output_cb_ = output_cb;
|
| 107 |
+
|
| 108 |
+
if (!IsStreamEncrypted(input_stream_)) {
|
| 109 |
+
InitializeDecoder();
|
| 110 |
+
return;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// This could be null during fallback after decoder reinitialization failure.
|
| 114 |
+
// See DecoderStream<StreamType>::OnDecoderReinitialized().
|
| 115 |
+
if (!cdm_context_) {
|
| 116 |
+
ReturnNullDecoder();
|
| 117 |
+
return;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
#if !defined(OS_ANDROID)
|
| 121 |
+
InitializeDecryptingDecoder();
|
| 122 |
+
#else
|
| 123 |
+
InitializeDecryptingDemuxerStream();
|
| 124 |
+
#endif
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
#if !defined(OS_ANDROID)
|
| 128 |
+
template <DemuxerStream::Type StreamType>
|
| 129 |
+
void DecoderSelector<StreamType>::InitializeDecryptingDecoder() {
|
| 130 |
+
DVLOG(2) << __FUNCTION__;
|
| 131 |
+
decoder_.reset(new typename StreamTraits::DecryptingDecoderType(
|
| 132 |
+
task_runner_, media_log_, waiting_for_decryption_key_cb_));
|
| 133 |
+
|
| 134 |
+
DecoderStreamTraits<StreamType>::InitializeDecoder(
|
| 135 |
+
decoder_.get(), input_stream_, cdm_context_,
|
| 136 |
+
base::Bind(&DecoderSelector<StreamType>::DecryptingDecoderInitDone,
|
| 137 |
+
weak_ptr_factory_.GetWeakPtr()),
|
| 138 |
+
output_cb_);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
template <DemuxerStream::Type StreamType>
|
| 142 |
+
void DecoderSelector<StreamType>::DecryptingDecoderInitDone(bool success) {
|
| 143 |
+
DVLOG(2) << __FUNCTION__;
|
| 144 |
+
DCHECK(task_runner_->BelongsToCurrentThread());
|
| 145 |
+
|
| 146 |
+
if (success) {
|
| 147 |
+
base::ResetAndReturn(&select_decoder_cb_)
|
| 148 |
+
.Run(std::move(decoder_), scoped_ptr<DecryptingDemuxerStream>());
|
| 149 |
+
return;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
decoder_.reset();
|
| 153 |
+
|
| 154 |
+
// When we get here decrypt-and-decode is not supported. Try to use
|
| 155 |
+
// DecryptingDemuxerStream to do decrypt-only.
|
| 156 |
+
InitializeDecryptingDemuxerStream();
|
| 157 |
+
}
|
| 158 |
+
#endif // !defined(OS_ANDROID)
|
| 159 |
+
|
| 160 |
+
template <DemuxerStream::Type StreamType>
|
| 161 |
+
void DecoderSelector<StreamType>::InitializeDecryptingDemuxerStream() {
|
| 162 |
+
decrypted_stream_.reset(new DecryptingDemuxerStream(
|
| 163 |
+
task_runner_, media_log_, waiting_for_decryption_key_cb_));
|
| 164 |
+
|
| 165 |
+
decrypted_stream_->Initialize(
|
| 166 |
+
input_stream_, cdm_context_,
|
| 167 |
+
base::Bind(&DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone,
|
| 168 |
+
weak_ptr_factory_.GetWeakPtr()));
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
template <DemuxerStream::Type StreamType>
|
| 172 |
+
void DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone(
|
| 173 |
+
PipelineStatus status) {
|
| 174 |
+
DVLOG(2) << __FUNCTION__;
|
| 175 |
+
DCHECK(task_runner_->BelongsToCurrentThread());
|
| 176 |
+
|
| 177 |
+
// If DecryptingDemuxerStream initialization succeeded, we'll use it to do
|
| 178 |
+
// decryption and use a decoder to decode the clear stream. Otherwise, we'll
|
| 179 |
+
// try to see whether any decoder can decrypt-and-decode the encrypted stream
|
| 180 |
+
// directly. So in both cases, we'll initialize the decoders.
|
| 181 |
+
|
| 182 |
+
if (status == PIPELINE_OK) {
|
| 183 |
+
input_stream_ = decrypted_stream_.get();
|
| 184 |
+
DCHECK(!IsStreamEncrypted(input_stream_));
|
| 185 |
+
} else {
|
| 186 |
+
decrypted_stream_.reset();
|
| 187 |
+
DCHECK(IsStreamEncrypted(input_stream_));
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
InitializeDecoder();
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
template <DemuxerStream::Type StreamType>
|
| 194 |
+
void DecoderSelector<StreamType>::InitializeDecoder() {
|
| 195 |
+
DVLOG(2) << __FUNCTION__;
|
| 196 |
+
DCHECK(task_runner_->BelongsToCurrentThread());
|
| 197 |
+
DCHECK(!decoder_);
|
| 198 |
+
|
| 199 |
+
if (decoders_.empty()) {
|
| 200 |
+
ReturnNullDecoder();
|
| 201 |
+
return;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
decoder_.reset(decoders_.front());
|
| 205 |
+
decoders_.weak_erase(decoders_.begin());
|
| 206 |
+
|
| 207 |
+
DecoderStreamTraits<StreamType>::InitializeDecoder(
|
| 208 |
+
decoder_.get(), input_stream_, cdm_context_,
|
| 209 |
+
base::Bind(&DecoderSelector<StreamType>::DecoderInitDone,
|
| 210 |
+
weak_ptr_factory_.GetWeakPtr()),
|
| 211 |
+
output_cb_);
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
template <DemuxerStream::Type StreamType>
|
| 215 |
+
void DecoderSelector<StreamType>::DecoderInitDone(bool success) {
|
| 216 |
+
DVLOG(2) << __FUNCTION__;
|
| 217 |
+
DCHECK(task_runner_->BelongsToCurrentThread());
|
| 218 |
+
|
| 219 |
+
if (!success) {
|
| 220 |
+
decoder_.reset();
|
| 221 |
+
InitializeDecoder();
|
| 222 |
+
return;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
base::ResetAndReturn(&select_decoder_cb_)
|
| 226 |
+
.Run(std::move(decoder_), std::move(decrypted_stream_));
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
template <DemuxerStream::Type StreamType>
|
| 230 |
+
void DecoderSelector<StreamType>::ReturnNullDecoder() {
|
| 231 |
+
DVLOG(2) << __FUNCTION__;
|
| 232 |
+
DCHECK(task_runner_->BelongsToCurrentThread());
|
| 233 |
+
base::ResetAndReturn(&select_decoder_cb_)
|
| 234 |
+
.Run(scoped_ptr<Decoder>(),
|
| 235 |
+
scoped_ptr<DecryptingDemuxerStream>());
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
// These forward declarations tell the compiler that we will use
|
| 239 |
+
// DecoderSelector with these arguments, allowing us to keep these definitions
|
| 240 |
+
// in our .cc without causing linker errors. This also means if anyone tries to
|
| 241 |
+
// instantiate a DecoderSelector with anything but these two specializations
|
| 242 |
+
// they'll most likely get linker errors.
|
| 243 |
+
template class DecoderSelector<DemuxerStream::AUDIO>;
|
| 244 |
+
template class DecoderSelector<DemuxerStream::VIDEO>;
|
| 245 |
+
|
| 246 |
+
} // namespace media
|
pool/shard002/C++/0034753_CommandMoveCounterClockwise.cpp
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "GameField.h"
|
| 2 |
+
#include "MainGameScene.h"
|
| 3 |
+
#include "ConstantsRegistry.h"
|
| 4 |
+
#include "CommandMoveCounterClockwise.h"
|
| 5 |
+
|
| 6 |
+
bool CommandMoveCounterClockwise::init() {
|
| 7 |
+
_isExecute = false;
|
| 8 |
+
_isRedo = false;
|
| 9 |
+
_isUndo = false;
|
| 10 |
+
|
| 11 |
+
return true;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
void moveBlock(int mainBlockY, int mainBlockX, int attachedBlockY, int attachedBlockX, Block* block) {
|
| 15 |
+
b2WeldJointDef jointDef = Block::getJointDef(); //Need to change anchors
|
| 16 |
+
jointDef.bodyA = block->getBody();
|
| 17 |
+
jointDef.bodyB = block->getAttachedBody();
|
| 18 |
+
|
| 19 |
+
//Anchor point of Sprite must be at left down corner!
|
| 20 |
+
if (attachedBlockX > mainBlockX){
|
| 21 |
+
if (mainBlockY + 1 == GameField::getSize().y)
|
| 22 |
+
return;
|
| 23 |
+
|
| 24 |
+
if (!GameField::getBlock(mainBlockY + 1, mainBlockX)) {
|
| 25 |
+
MainGameScene::getWorld()->DestroyJoint(block->getBody()->GetJointList()->joint);
|
| 26 |
+
jointDef.localAnchorA = { 0.5, ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::JOINT_BLOCK_DIST) };
|
| 27 |
+
jointDef.localAnchorB = { 0.5, 0 };
|
| 28 |
+
MainGameScene::getWorld()->CreateJoint(&jointDef);
|
| 29 |
+
|
| 30 |
+
Size size = block->getSprite()->getContentSize();
|
| 31 |
+
b2Vec2 position;
|
| 32 |
+
|
| 33 |
+
position.x = (block->getSprite()->getPositionX()
|
| 34 |
+
/ ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D))
|
| 35 |
+
+ (size.width / 2) / ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D);
|
| 36 |
+
position.y = ((block->getSprite()->getPositionY() + size.height)
|
| 37 |
+
/ ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D))
|
| 38 |
+
+ (size.height / 2) / ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D);
|
| 39 |
+
|
| 40 |
+
block->getAttachedBody()->SetTransform(position, 0);
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
else if (attachedBlockX < mainBlockX) {
|
| 44 |
+
if (mainBlockY - 1 < 0)
|
| 45 |
+
return;
|
| 46 |
+
|
| 47 |
+
if (!GameField::getBlock(mainBlockY - 1, mainBlockX)) {
|
| 48 |
+
MainGameScene::getWorld()->DestroyJoint(block->getBody()->GetJointList()->joint);
|
| 49 |
+
jointDef.localAnchorA = { 0.5, ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::JOINT_BLOCK_DIST_NEGATIVE) };
|
| 50 |
+
jointDef.localAnchorB = { 0.5, 1 };
|
| 51 |
+
MainGameScene::getWorld()->CreateJoint(&jointDef);
|
| 52 |
+
|
| 53 |
+
Size size = block->getSprite()->getContentSize();
|
| 54 |
+
b2Vec2 position;
|
| 55 |
+
|
| 56 |
+
position.x = (block->getSprite()->getPositionX()
|
| 57 |
+
/ ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D))
|
| 58 |
+
+ (size.width / 2) / ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D);
|
| 59 |
+
position.y = ((block->getSprite()->getPositionY() - size.height)
|
| 60 |
+
/ ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D))
|
| 61 |
+
+ (size.height / 2) / ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D);
|
| 62 |
+
|
| 63 |
+
block->getAttachedBody()->SetTransform(position, 0);
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
else if (attachedBlockY > mainBlockY) {
|
| 67 |
+
if (mainBlockX - 1 < 0)
|
| 68 |
+
return;
|
| 69 |
+
|
| 70 |
+
if (!GameField::getBlock(mainBlockY, mainBlockX - 1)) {
|
| 71 |
+
MainGameScene::getWorld()->DestroyJoint(block->getBody()->GetJointList()->joint);
|
| 72 |
+
jointDef.localAnchorA = { ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::JOINT_BLOCK_DIST_NEGATIVE), 0 };
|
| 73 |
+
jointDef.localAnchorB = { 1, 0 };
|
| 74 |
+
MainGameScene::getWorld()->CreateJoint(&jointDef);
|
| 75 |
+
|
| 76 |
+
Size size = block->getSprite()->getContentSize();
|
| 77 |
+
b2Vec2 position;
|
| 78 |
+
|
| 79 |
+
position.x = ((block->getSprite()->getPositionX() - size.width)
|
| 80 |
+
/ ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D))
|
| 81 |
+
+ (size.width / 2) / ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D);
|
| 82 |
+
position.y = (block->getSprite()->getPositionY()
|
| 83 |
+
/ ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D))
|
| 84 |
+
+ (size.height / 2) / ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D);
|
| 85 |
+
|
| 86 |
+
block->getAttachedBody()->SetTransform(position, 0);
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
else if (attachedBlockY < mainBlockY) {
|
| 90 |
+
if (mainBlockX + 1 == GameField::getSize().x)
|
| 91 |
+
return;
|
| 92 |
+
|
| 93 |
+
if (!GameField::getBlock(mainBlockY, mainBlockX + 1)) {
|
| 94 |
+
MainGameScene::getWorld()->DestroyJoint(block->getBody()->GetJointList()->joint);
|
| 95 |
+
jointDef.localAnchorA = { ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::JOINT_BLOCK_DIST), 0 };
|
| 96 |
+
jointDef.localAnchorB = { 0, 0 };
|
| 97 |
+
MainGameScene::getWorld()->CreateJoint(&jointDef);
|
| 98 |
+
|
| 99 |
+
Size size = block->getSprite()->getContentSize();
|
| 100 |
+
b2Vec2 position;
|
| 101 |
+
|
| 102 |
+
position.x = ((block->getSprite()->getPositionX() + size.width)
|
| 103 |
+
/ ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D))
|
| 104 |
+
+ (size.width / 2) / ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D);
|
| 105 |
+
position.y = (block->getSprite()->getPositionY()
|
| 106 |
+
/ ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D))
|
| 107 |
+
+ (size.height / 2) / ConstantsRegistry::getValueForKey(ConstantsRegistry::constants::SCALE_RATIO_BOX2D);
|
| 108 |
+
|
| 109 |
+
block->getAttachedBody()->SetTransform(position, 0);
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
void CommandMoveCounterClockwise::update(float dt) {
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
void CommandMoveCounterClockwise::execute(Block *block) {
|
| 118 |
+
const int mainBlockY = block->getPosOnField().y;
|
| 119 |
+
const int mainBlockX = block->getPosOnField().x;
|
| 120 |
+
const int attachedBlockY = block->getAttachedBlock()->getPosOnField().y;
|
| 121 |
+
const int attachedBlockX = block->getAttachedBlock()->getPosOnField().x;
|
| 122 |
+
|
| 123 |
+
_isUndo = false;
|
| 124 |
+
_isRedo = false;
|
| 125 |
+
_isExecute = true;
|
| 126 |
+
Director::getInstance()->getScheduler()->unscheduleUpdate(this);
|
| 127 |
+
moveBlock(mainBlockY, mainBlockX, attachedBlockY, attachedBlockX, block);
|
| 128 |
+
_isExecute = false;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
void CommandMoveCounterClockwise::undo() {
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
void CommandMoveCounterClockwise::redo() {
|
| 135 |
+
}
|
pool/shard002/C++/0034760_DocumentResource.cpp
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2010 Rob Buis <rwlbuis@gmail.com>
|
| 3 |
+
Copyright (C) 2011 Cosmin Truta <ctruta@gmail.com>
|
| 4 |
+
Copyright (C) 2012 University of Szeged
|
| 5 |
+
Copyright (C) 2012 Renata Hodovan <reni@webkit.org>
|
| 6 |
+
|
| 7 |
+
This library is free software; you can redistribute it and/or
|
| 8 |
+
modify it under the terms of the GNU Library General Public
|
| 9 |
+
License as published by the Free Software Foundation; either
|
| 10 |
+
version 2 of the License, or (at your option) any later version.
|
| 11 |
+
|
| 12 |
+
This library is distributed in the hope that it will be useful,
|
| 13 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 15 |
+
Library General Public License for more details.
|
| 16 |
+
|
| 17 |
+
You should have received a copy of the GNU Library General Public License
|
| 18 |
+
along with this library; see the file COPYING.LIB. If not, write to
|
| 19 |
+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
| 20 |
+
Boston, MA 02110-1301, USA.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include "core/fetch/DocumentResource.h"
|
| 24 |
+
|
| 25 |
+
#include "core/dom/XMLDocument.h"
|
| 26 |
+
#include "core/fetch/FetchRequest.h"
|
| 27 |
+
#include "core/fetch/ResourceFetcher.h"
|
| 28 |
+
#include "platform/SharedBuffer.h"
|
| 29 |
+
#include "wtf/text/StringBuilder.h"
|
| 30 |
+
|
| 31 |
+
namespace blink {
|
| 32 |
+
|
| 33 |
+
DocumentResource* DocumentResource::fetchSVGDocument(FetchRequest& request, ResourceFetcher* fetcher)
|
| 34 |
+
{
|
| 35 |
+
ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone);
|
| 36 |
+
request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestContextImage);
|
| 37 |
+
return toDocumentResource(fetcher->requestResource(request, SVGDocumentResourceFactory()));
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
DocumentResource::DocumentResource(const ResourceRequest& request, Type type, const ResourceLoaderOptions& options)
|
| 41 |
+
: TextResource(request, type, options, "application/xml", String())
|
| 42 |
+
{
|
| 43 |
+
// FIXME: We'll support more types to support HTMLImports.
|
| 44 |
+
ASSERT(type == SVGDocument);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
DocumentResource::~DocumentResource()
|
| 48 |
+
{
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
DEFINE_TRACE(DocumentResource)
|
| 52 |
+
{
|
| 53 |
+
visitor->trace(m_document);
|
| 54 |
+
Resource::trace(visitor);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void DocumentResource::checkNotify()
|
| 58 |
+
{
|
| 59 |
+
if (data() && mimeTypeAllowed()) {
|
| 60 |
+
// We don't need to create a new frame because the new document belongs to the parent UseElement.
|
| 61 |
+
m_document = createDocument(response().url());
|
| 62 |
+
m_document->setContent(decodedText());
|
| 63 |
+
}
|
| 64 |
+
Resource::checkNotify();
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
bool DocumentResource::mimeTypeAllowed() const
|
| 68 |
+
{
|
| 69 |
+
ASSERT(getType() == SVGDocument);
|
| 70 |
+
AtomicString mimeType = response().mimeType();
|
| 71 |
+
if (response().isHTTP())
|
| 72 |
+
mimeType = httpContentType();
|
| 73 |
+
return mimeType == "image/svg+xml"
|
| 74 |
+
|| mimeType == "text/xml"
|
| 75 |
+
|| mimeType == "application/xml"
|
| 76 |
+
|| mimeType == "application/xhtml+xml";
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
Document* DocumentResource::createDocument(const KURL& url)
|
| 80 |
+
{
|
| 81 |
+
switch (getType()) {
|
| 82 |
+
case SVGDocument:
|
| 83 |
+
return XMLDocument::createSVG(DocumentInit(url));
|
| 84 |
+
default:
|
| 85 |
+
// FIXME: We'll add more types to support HTMLImports.
|
| 86 |
+
ASSERT_NOT_REACHED();
|
| 87 |
+
return nullptr;
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
} // namespace blink
|
pool/shard002/C++/0034768_cinteger.cpp
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
|
| 3 |
+
Copyright (C) 2009 Gaetan Guidet
|
| 4 |
+
|
| 5 |
+
This file is part of myst.
|
| 6 |
+
|
| 7 |
+
myst is free software; you can redistribute it and/or modify it
|
| 8 |
+
under the terms of the GNU Lesser General Public License as published by
|
| 9 |
+
the Free Software Foundation; either version 2.1 of the License, or (at
|
| 10 |
+
your option) any later version.
|
| 11 |
+
|
| 12 |
+
myst is distributed in the hope that it will be useful, but
|
| 13 |
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 15 |
+
Lesser General Public License for more details.
|
| 16 |
+
|
| 17 |
+
You should have received a copy of the GNU Lesser General Public
|
| 18 |
+
License along with this library; if not, write to the Free Software
|
| 19 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
| 20 |
+
USA.
|
| 21 |
+
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
#include <myst/core/cinteger.h>
|
| 25 |
+
#include <myst/core/creal.h>
|
| 26 |
+
#include <myst/core/cstring.h>
|
| 27 |
+
#include <myst/builtins.h>
|
| 28 |
+
#include <myst/method.h>
|
| 29 |
+
|
| 30 |
+
namespace myst {
|
| 31 |
+
|
| 32 |
+
void IntegerClass::NewInstance(Context *ctx, Long n) throw(Exception) {
|
| 33 |
+
ctx->pop(n);
|
| 34 |
+
ctx->push(new Integer());
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void IntegerClass::Add(Context *ctx, Long n) throw(Exception) {
|
| 38 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 39 |
+
Integer *oRhs = (Integer*) ctx->at(-n+1)->call(ctx, "toInt");
|
| 40 |
+
ctx->pop(n);
|
| 41 |
+
ctx->push(new Integer(i->data + oRhs->data));
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void IntegerClass::Sub(Context *ctx, Long n) throw(Exception) {
|
| 45 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 46 |
+
Integer *oRhs = (Integer*) ctx->at(-n+1)->call(ctx, "toInt");
|
| 47 |
+
ctx->pop(n);
|
| 48 |
+
ctx->push(new Integer(i->data - oRhs->data));
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
void IntegerClass::Mult(Context *ctx, Long n) throw(Exception) {
|
| 52 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 53 |
+
Integer *oRhs = (Integer*) ctx->at(-n+1)->call(ctx, "toInt");
|
| 54 |
+
ctx->pop(n);
|
| 55 |
+
ctx->push(new Integer(i->data * oRhs->data));
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
void IntegerClass::Div(Context *ctx, Long n) throw(Exception) {
|
| 59 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 60 |
+
Integer *oRhs = (Integer*) ctx->at(-n+1)->call(ctx, "toInt");
|
| 61 |
+
if (oRhs->data == 0) {
|
| 62 |
+
throw ZeroDivisionError();
|
| 63 |
+
}
|
| 64 |
+
ctx->pop(n);
|
| 65 |
+
ctx->push(new Integer(i->data / oRhs->data));
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
void IntegerClass::Modulo(Context *ctx, Long n) throw(Exception) {
|
| 69 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 70 |
+
Integer *oRhs = (Integer*) ctx->at(-n+1)->call(ctx, "toInt");
|
| 71 |
+
if (oRhs->data == 0) {
|
| 72 |
+
throw ZeroDivisionError();
|
| 73 |
+
}
|
| 74 |
+
ctx->pop(n);
|
| 75 |
+
ctx->push(new Integer(i->data % oRhs->data));
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
void IntegerClass::LShift(Context *ctx, Long n) throw(Exception) {
|
| 79 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 80 |
+
Integer *oRhs = (Integer*) ctx->at(-n+1)->call(ctx, "toInt");
|
| 81 |
+
ctx->pop(n);
|
| 82 |
+
ctx->push(new Integer(i->data << oRhs->data));
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
void IntegerClass::RShift(Context *ctx, Long n) throw(Exception) {
|
| 86 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 87 |
+
Integer *oRhs = (Integer*) ctx->at(-n+1)->call(ctx, "toInt");
|
| 88 |
+
ctx->pop(n);
|
| 89 |
+
ctx->push(new Integer(i->data >> oRhs->data));
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
void IntegerClass::BitOr(Context *ctx, Long n) throw(Exception) {
|
| 93 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 94 |
+
Integer *oRhs = (Integer*) ctx->at(-n+1)->call(ctx, "toInt");
|
| 95 |
+
ctx->pop(n);
|
| 96 |
+
ctx->push(new Integer(i->data | oRhs->data));
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
void IntegerClass::BitAnd(Context *ctx, Long n) throw(Exception) {
|
| 100 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 101 |
+
Integer *oRhs = (Integer*) ctx->at(-n+1)->call(ctx, "toInt");
|
| 102 |
+
ctx->pop(n);
|
| 103 |
+
ctx->push(new Integer(i->data & oRhs->data));
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
void IntegerClass::ToStr(Context *ctx, Long n) throw(Exception) {
|
| 107 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 108 |
+
std::ostringstream oss;
|
| 109 |
+
oss << i->data;
|
| 110 |
+
ctx->pop(n);
|
| 111 |
+
ctx->push(new String(oss.str()));
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
void IntegerClass::ToInt(Context *ctx, Long n) throw(Exception) {
|
| 115 |
+
Object *self = ctx->at(-n);
|
| 116 |
+
ctx->pop(n);
|
| 117 |
+
ctx->push(self);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
void IntegerClass::ToReal(Context *ctx, Long n) throw(Exception) {
|
| 121 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 122 |
+
ctx->pop(n);
|
| 123 |
+
ctx->push(new Real(double(i->data)));
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
void IntegerClass::Abs(Context *ctx, Long n) throw(Exception) {
|
| 127 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 128 |
+
ctx->pop(n);
|
| 129 |
+
ctx->push(new Integer(i->data < 0 ? -i->data : i->data));
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
void IntegerClass::Neg(Context *ctx, Long n) throw(Exception) {
|
| 133 |
+
Integer *i = (Integer*) ctx->at(-n);
|
| 134 |
+
ctx->pop(n);
|
| 135 |
+
ctx->push(new Integer(- i->data));
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
IntegerClass::IntegerClass()
|
| 139 |
+
: Class("Integer", cObject) {
|
| 140 |
+
addMethod(new CMethod("new", 0, &NewInstance));
|
| 141 |
+
addInstanceMethod(new CMethod("add:", 1, &Add));
|
| 142 |
+
addInstanceMethod(new CMethod("+", 1, &Add));
|
| 143 |
+
addInstanceMethod(new CMethod("sub:", 1, &Sub));
|
| 144 |
+
addInstanceMethod(new CMethod("-", 1, &Sub));
|
| 145 |
+
addInstanceMethod(new CMethod("times:", 1, &Mult));
|
| 146 |
+
addInstanceMethod(new CMethod("*", 1, &Mult));
|
| 147 |
+
addInstanceMethod(new CMethod("div:", 1, &Div));
|
| 148 |
+
addInstanceMethod(new CMethod("/", 1, &Div));
|
| 149 |
+
addInstanceMethod(new CMethod("modulo:", 1, &Modulo));
|
| 150 |
+
addInstanceMethod(new CMethod("%", 1, &Modulo));
|
| 151 |
+
addInstanceMethod(new CMethod("abs", 0, &Abs));
|
| 152 |
+
addInstanceMethod(new CMethod("neg", 0, &Neg));
|
| 153 |
+
addInstanceMethod(new CMethod("lshift:", 1, &LShift));
|
| 154 |
+
addInstanceMethod(new CMethod("rshift:", 1, &RShift));
|
| 155 |
+
addInstanceMethod(new CMethod("or:", 1, &BitOr));
|
| 156 |
+
addInstanceMethod(new CMethod("|", 1, &BitOr));
|
| 157 |
+
addInstanceMethod(new CMethod("and:", 1, &BitAnd));
|
| 158 |
+
addInstanceMethod(new CMethod("&", 1, &BitAnd));
|
| 159 |
+
addInstanceMethod(new CMethod("lshift:", 1, &LShift));
|
| 160 |
+
addInstanceMethod(new CMethod("toReal", 0, &ToReal));
|
| 161 |
+
addInstanceMethod(new CMethod("toStr", 0, &ToStr));
|
| 162 |
+
addInstanceMethod(new CMethod("toInt", 0, &ToInt));
|
| 163 |
+
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
IntegerClass::~IntegerClass() {
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
// ---
|
| 170 |
+
|
| 171 |
+
Integer::Integer(Long val)
|
| 172 |
+
: TObject<Long>(cInteger) {
|
| 173 |
+
data = val;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
Integer::~Integer() {
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
}
|
pool/shard002/C++/0034771_WVSShader.cpp
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "Macro.h"
|
| 2 |
+
#include "WVSShader.h"
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
WVSShader::WVSShader(){
|
| 6 |
+
m_vertexShader = nullptr;
|
| 7 |
+
m_blob = nullptr;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
WVSShader::~WVSShader(){
|
| 12 |
+
m_vertexShader->Release();
|
| 13 |
+
m_vertexShader = nullptr;
|
| 14 |
+
m_blob->Release();
|
| 15 |
+
m_blob = nullptr;
|
| 16 |
+
m_inputLayout->Release();
|
| 17 |
+
m_inputLayout = nullptr;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
HRESULT WVSShader::Compile(WCHAR * szFileName, LPCSTR szEntryPoint){
|
| 21 |
+
ID3D11Device* pd3dDevice = DXUTGetD3D11Device();
|
| 22 |
+
DX::ThrowIfFailed(DX::CompileShaderFromFile(szFileName, szEntryPoint, "vs_4_0", &m_blob));
|
| 23 |
+
DX::ThrowIfFailed(pd3dDevice->CreateVertexShader(m_blob->GetBufferPointer(), m_blob->GetBufferSize(), nullptr, &m_vertexShader));
|
| 24 |
+
return S_OK;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
ID3D11VertexShader * WVSShader::getShader(){
|
| 28 |
+
return m_vertexShader;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
ID3DBlob * WVSShader::getBlob(){
|
| 32 |
+
return m_blob;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
HRESULT WVSShader::createInputLayout(D3D11_INPUT_ELEMENT_DESC * inputElemnt, size_t size){
|
| 36 |
+
ID3D11Device* pd3dDevice = DXUTGetD3D11Device();
|
| 37 |
+
ID3D11DeviceContext * pd3dImmediateContext = DXUTGetD3D11DeviceContext();
|
| 38 |
+
DX::ThrowIfFailed(pd3dDevice->CreateInputLayout(inputElemnt, size, m_blob->GetBufferPointer(), m_blob->GetBufferSize(), &m_inputLayout));
|
| 39 |
+
return S_OK;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
ID3D11InputLayout * WVSShader::getInputLayout(){
|
| 43 |
+
return m_inputLayout;
|
| 44 |
+
}
|
pool/shard002/C++/0034776_77.cpp
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <iostream>
|
| 2 |
+
#include <cstdlib>
|
| 3 |
+
#include <string>
|
| 4 |
+
#include <unordered_set>
|
| 5 |
+
#include <vector>
|
| 6 |
+
#include <algorithm>
|
| 7 |
+
#include <climits>
|
| 8 |
+
#include <stack>
|
| 9 |
+
#include <sstream>
|
| 10 |
+
#include <numeric>
|
| 11 |
+
#include <unordered_map>
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
using namespace std;
|
| 15 |
+
|
| 16 |
+
class Solution {
|
| 17 |
+
public:
|
| 18 |
+
vector<vector<int>> combine(int n, int k) {
|
| 19 |
+
vector<vector<int>> ans;
|
| 20 |
+
|
| 21 |
+
if (n == 0 || k == 0 || n < k)
|
| 22 |
+
return ans;
|
| 23 |
+
|
| 24 |
+
vector<int> indicators(n-k, 0);
|
| 25 |
+
|
| 26 |
+
for (int i = 1; i <= k; ++ i)
|
| 27 |
+
indicators.push_back(1);
|
| 28 |
+
|
| 29 |
+
vector<int> v;
|
| 30 |
+
|
| 31 |
+
do {
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
for (int i = 1; i <= n; ++ i)
|
| 35 |
+
if (indicators[i-1] == 1)
|
| 36 |
+
v.push_back(i);
|
| 37 |
+
|
| 38 |
+
ans.push_back(v);
|
| 39 |
+
|
| 40 |
+
// for (int i = 0; i < v.size(); ++ i)
|
| 41 |
+
// cout << v[i] << ' ';
|
| 42 |
+
|
| 43 |
+
// cout << endl;
|
| 44 |
+
|
| 45 |
+
v.clear();
|
| 46 |
+
|
| 47 |
+
} while (next_permutation(indicators.begin(), indicators.end()));
|
| 48 |
+
|
| 49 |
+
return ans;
|
| 50 |
+
|
| 51 |
+
}
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
int main() {
|
| 56 |
+
vector<vector<int>> ans = Solution().combine(4,2);
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
return 0;
|
| 61 |
+
}
|
pool/shard002/C++/0034779_heapdump.cc
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2012, Ben Noordhuis <info@bnoordhuis.nl>
|
| 3 |
+
*
|
| 4 |
+
* Permission to use, copy, modify, and/or distribute this software for any
|
| 5 |
+
* purpose with or without fee is hereby granted, provided that the above
|
| 6 |
+
* copyright notice and this permission notice appear in all copies.
|
| 7 |
+
*
|
| 8 |
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
| 9 |
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 10 |
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
| 11 |
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 12 |
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 13 |
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
| 14 |
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
#include "heapdump.h"
|
| 18 |
+
|
| 19 |
+
#include "node.h"
|
| 20 |
+
#include "uv.h"
|
| 21 |
+
#include "v8.h"
|
| 22 |
+
#include "v8-profiler.h"
|
| 23 |
+
|
| 24 |
+
#include <stdio.h>
|
| 25 |
+
#include <stdarg.h>
|
| 26 |
+
#include <stdlib.h>
|
| 27 |
+
#include <assert.h>
|
| 28 |
+
|
| 29 |
+
using v8::Arguments;
|
| 30 |
+
using v8::False;
|
| 31 |
+
using v8::FunctionTemplate;
|
| 32 |
+
using v8::Handle;
|
| 33 |
+
using v8::HandleScope;
|
| 34 |
+
using v8::HeapProfiler;
|
| 35 |
+
using v8::HeapSnapshot;
|
| 36 |
+
using v8::HeapStatistics;
|
| 37 |
+
using v8::Object;
|
| 38 |
+
using v8::OutputStream;
|
| 39 |
+
using v8::String;
|
| 40 |
+
using v8::True;
|
| 41 |
+
using v8::V8;
|
| 42 |
+
using v8::Value;
|
| 43 |
+
|
| 44 |
+
namespace
|
| 45 |
+
{
|
| 46 |
+
|
| 47 |
+
#if defined(_WIN32)
|
| 48 |
+
// Emulate snprintf() on windows, _snprintf() doesn't zero-terminate the buffer
|
| 49 |
+
// on overflow.
|
| 50 |
+
int snprintf(char* buf, unsigned int len, const char* fmt, ...) {
|
| 51 |
+
va_list ap;
|
| 52 |
+
va_start(ap, fmt);
|
| 53 |
+
int n = _vsprintf_p(buf, len, fmt, ap);
|
| 54 |
+
if (len) buf[len - 1] = '\0';
|
| 55 |
+
va_end(ap);
|
| 56 |
+
return n;
|
| 57 |
+
}
|
| 58 |
+
#endif
|
| 59 |
+
|
| 60 |
+
class FileOutputStream: public OutputStream
|
| 61 |
+
{
|
| 62 |
+
public:
|
| 63 |
+
FileOutputStream(FILE* stream): stream_(stream)
|
| 64 |
+
{
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
virtual int GetChunkSize()
|
| 68 |
+
{
|
| 69 |
+
return 65536; // big chunks == faster
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
virtual void EndOfStream()
|
| 73 |
+
{
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
virtual WriteResult WriteAsciiChunk(char* data, int size)
|
| 77 |
+
{
|
| 78 |
+
const size_t len = static_cast<size_t>(size);
|
| 79 |
+
size_t off = 0;
|
| 80 |
+
|
| 81 |
+
while (off < len && !feof(stream_) && !ferror(stream_))
|
| 82 |
+
off += fwrite(data + off, 1, len - off, stream_);
|
| 83 |
+
|
| 84 |
+
return off == len ? kContinue : kAbort;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
private:
|
| 88 |
+
FILE* stream_;
|
| 89 |
+
};
|
| 90 |
+
|
| 91 |
+
Handle<Value> WriteSnapshot(const Arguments& args)
|
| 92 |
+
{
|
| 93 |
+
bool ok;
|
| 94 |
+
if (args[0]->IsString()) {
|
| 95 |
+
String::Utf8Value filename(args[0]);
|
| 96 |
+
ok = heapdump::WriteSnapshot(*filename);
|
| 97 |
+
} else {
|
| 98 |
+
ok = heapdump::WriteSnapshot(NULL);
|
| 99 |
+
}
|
| 100 |
+
// Throwing on error is too disruptive, just return a boolean indicating
|
| 101 |
+
// success.
|
| 102 |
+
return ok ? True() : False();
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
void Init(Handle<Object> obj)
|
| 106 |
+
{
|
| 107 |
+
HandleScope scope;
|
| 108 |
+
heapdump::PlatformInit();
|
| 109 |
+
obj->Set(String::New("writeSnapshot"),
|
| 110 |
+
FunctionTemplate::New(WriteSnapshot)->GetFunction());
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
NODE_MODULE(heapdump, Init)
|
| 114 |
+
|
| 115 |
+
} // namespace anonymous
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
namespace heapdump
|
| 119 |
+
{
|
| 120 |
+
|
| 121 |
+
bool WriteSnapshotHelper(const char* filename)
|
| 122 |
+
{
|
| 123 |
+
char scratch[256];
|
| 124 |
+
if (filename == NULL) {
|
| 125 |
+
uint64_t now = uv_hrtime();
|
| 126 |
+
unsigned long sec = static_cast<unsigned long>(now / 1000000);
|
| 127 |
+
unsigned long usec = static_cast<unsigned long>(now % 1000000);
|
| 128 |
+
snprintf(scratch,
|
| 129 |
+
sizeof(scratch),
|
| 130 |
+
"heapdump-%lu.%lu.heapsnapshot",
|
| 131 |
+
sec,
|
| 132 |
+
usec);
|
| 133 |
+
filename = scratch;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
FILE* fp = fopen(filename, "w");
|
| 137 |
+
if (fp == NULL) {
|
| 138 |
+
return false;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
const HeapSnapshot* snap = HeapProfiler::TakeSnapshot(String::Empty());
|
| 142 |
+
FileOutputStream stream(fp);
|
| 143 |
+
snap->Serialize(&stream, HeapSnapshot::kJSON);
|
| 144 |
+
fclose(fp);
|
| 145 |
+
// Only necessary on Windows because the snapshot is created inside the
|
| 146 |
+
// main process. On UNIX platforms, it's created from a fork that exits
|
| 147 |
+
// after writing the snapshot to disk.
|
| 148 |
+
#if defined(_WIN32)
|
| 149 |
+
const_cast<HeapSnapshot*>(snap)->Delete();
|
| 150 |
+
#endif
|
| 151 |
+
return true;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
} // namespace heapdump
|
pool/shard002/C++/0034783_qgsmessageviewer.cpp
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
qgsmessageviewer.cpp - description
|
| 3 |
+
-------------------
|
| 4 |
+
begin : Wed Jun 4 2003
|
| 5 |
+
copyright : (C) 2002 by Gary E.Sherman
|
| 6 |
+
email : sherman at mrcc.com
|
| 7 |
+
***************************************************************************/
|
| 8 |
+
|
| 9 |
+
/***************************************************************************
|
| 10 |
+
* *
|
| 11 |
+
* This program is free software; you can redistribute it and/or modify *
|
| 12 |
+
* it under the terms of the GNU General Public License as published by *
|
| 13 |
+
* the Free Software Foundation; either version 2 of the License, or *
|
| 14 |
+
* (at your option) any later version. *
|
| 15 |
+
* *
|
| 16 |
+
***************************************************************************/
|
| 17 |
+
|
| 18 |
+
#include "qgsmessageviewer.h"
|
| 19 |
+
#include <QSettings>
|
| 20 |
+
|
| 21 |
+
QgsMessageViewer::QgsMessageViewer( QWidget *parent, Qt::WFlags fl )
|
| 22 |
+
: QDialog( parent, fl )
|
| 23 |
+
{
|
| 24 |
+
setupUi( this );
|
| 25 |
+
setAttribute( Qt::WA_DeleteOnClose );
|
| 26 |
+
|
| 27 |
+
// Default state for the checkbox
|
| 28 |
+
setCheckBoxVisible( false );
|
| 29 |
+
setCheckBoxState( Qt::Unchecked );
|
| 30 |
+
|
| 31 |
+
mCheckBoxQSettingsLabel = "";
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
QgsMessageViewer::~QgsMessageViewer()
|
| 35 |
+
{
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
void QgsMessageViewer::setMessageAsHtml( const QString &msg )
|
| 39 |
+
{
|
| 40 |
+
txtMessage->setHtml( msg );
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
void QgsMessageViewer::setMessageAsPlainText( const QString &msg )
|
| 44 |
+
{
|
| 45 |
+
txtMessage->setPlainText( msg );
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void QgsMessageViewer::appendMessage( const QString &msg )
|
| 49 |
+
{
|
| 50 |
+
txtMessage->append( msg );
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
void QgsMessageViewer::setMessage( const QString &message, MessageType msgType )
|
| 55 |
+
{
|
| 56 |
+
if ( msgType == MessageHtml )
|
| 57 |
+
setMessageAsHtml( message );
|
| 58 |
+
else
|
| 59 |
+
setMessageAsPlainText( message );
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
void QgsMessageViewer::showMessage( bool blocking )
|
| 63 |
+
{
|
| 64 |
+
if ( blocking )
|
| 65 |
+
{
|
| 66 |
+
QApplication::setOverrideCursor( Qt::ArrowCursor );
|
| 67 |
+
exec();
|
| 68 |
+
QApplication::restoreOverrideCursor();
|
| 69 |
+
}
|
| 70 |
+
else
|
| 71 |
+
{
|
| 72 |
+
show();
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
void QgsMessageViewer::setTitle( const QString& title )
|
| 77 |
+
{
|
| 78 |
+
setWindowTitle( title );
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void QgsMessageViewer::setCheckBoxText( const QString& text )
|
| 82 |
+
{
|
| 83 |
+
checkBox->setText( text );
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
void QgsMessageViewer::setCheckBoxVisible( bool visible )
|
| 87 |
+
{
|
| 88 |
+
checkBox->setVisible( visible );
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
void QgsMessageViewer::setCheckBoxState( Qt::CheckState state )
|
| 92 |
+
{
|
| 93 |
+
checkBox->setCheckState( state );
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
Qt::CheckState QgsMessageViewer::checkBoxState()
|
| 97 |
+
{
|
| 98 |
+
return checkBox->checkState();
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
void QgsMessageViewer::setCheckBoxQSettingsLabel( QString label )
|
| 102 |
+
{
|
| 103 |
+
mCheckBoxQSettingsLabel = label;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
void QgsMessageViewer::on_checkBox_toggled( bool toggled )
|
| 108 |
+
{
|
| 109 |
+
Q_UNUSED( toggled );
|
| 110 |
+
if ( !mCheckBoxQSettingsLabel.isEmpty() )
|
| 111 |
+
{
|
| 112 |
+
QSettings settings;
|
| 113 |
+
if ( checkBox->checkState() == Qt::Checked )
|
| 114 |
+
settings.setValue( mCheckBoxQSettingsLabel, false );
|
| 115 |
+
else
|
| 116 |
+
settings.setValue( mCheckBoxQSettingsLabel, true );
|
| 117 |
+
}
|
| 118 |
+
}
|
pool/shard002/C++/0034789_prssrnot.cpp
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* prssrnot.cpp : Defines the entry point for the application.
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2008 David Andrs <pda@jasnapaka.com>
|
| 5 |
+
*
|
| 6 |
+
* This program is free software: you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License as published by
|
| 8 |
+
* the Free Software Foundation, either version 2 of the License, or
|
| 9 |
+
* (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* This program is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
#include "StdAfx.h"
|
| 23 |
+
#include "../share/defs.h"
|
| 24 |
+
#include "../share/wnd.h"
|
| 25 |
+
#include "../share/reg.h"
|
| 26 |
+
#include "../share/notif.h"
|
| 27 |
+
#include "../prssr/net/Connection.h"
|
| 28 |
+
|
| 29 |
+
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
|
| 30 |
+
CRegistry reg(HKEY_CURRENT_USER, REG_KEY_APP);
|
| 31 |
+
CRegistry regConf(HKEY_CURRENT_USER, REG_KEY_CONFIGURATION);
|
| 32 |
+
|
| 33 |
+
CString strCmdLine(lpCmdLine);
|
| 34 |
+
|
| 35 |
+
if (strCmdLine.Find(_T("/daily")) != -1) {
|
| 36 |
+
SYSTEMTIME tm, updateAtTime;
|
| 37 |
+
GetLocalTime(&updateAtTime);
|
| 38 |
+
if (regConf.Read(szUpdateAtTime, &tm, sizeof(tm))) {
|
| 39 |
+
updateAtTime.wHour = tm.wHour;
|
| 40 |
+
updateAtTime.wMinute = tm.wMinute;
|
| 41 |
+
updateAtTime.wSecond = tm.wSecond;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// reschedule event
|
| 45 |
+
AddSeconds(updateAtTime, 60 * 60 * 24); // 1 day
|
| 46 |
+
|
| 47 |
+
SetupUpdateEvent(_T("/daily"), TRUE, &updateAtTime);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
if (strCmdLine.Find(_T("/periodic")) != -1) {
|
| 51 |
+
DWORD updateInterval = regConf.Read(szUpdateInterval, 0);
|
| 52 |
+
|
| 53 |
+
// reschedule event
|
| 54 |
+
if (updateInterval > 0) {
|
| 55 |
+
SYSTEMTIME st;
|
| 56 |
+
GetLocalTime(&st);
|
| 57 |
+
AddSeconds(st, 60 * updateInterval);
|
| 58 |
+
|
| 59 |
+
SetupUpdateEvent(_T("/periodic"), TRUE, &st);
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
if (strCmdLine.Find(_T("AppRunAtRs232Detected")) != -1) {
|
| 64 |
+
// wait for the connection
|
| 65 |
+
int retry = 10;
|
| 66 |
+
while (retry > 0 && Connection.IsAvailable() != S_OK) {
|
| 67 |
+
Sleep(2000);
|
| 68 |
+
retry--;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
//
|
| 73 |
+
HWND hWnd = FindPRSSRMainWindow();
|
| 74 |
+
if (hWnd == NULL) {
|
| 75 |
+
// pRSSreader is not running -> start it
|
| 76 |
+
CString sInstallDir = reg.Read(szInstallDir, _T(""));
|
| 77 |
+
|
| 78 |
+
BOOL bMinimized = regConf.Read(szBackgroundUpdate, FALSE);
|
| 79 |
+
|
| 80 |
+
CString sPars = _T("/updateall");
|
| 81 |
+
if (bMinimized)
|
| 82 |
+
sPars += CString(" /minimized");
|
| 83 |
+
|
| 84 |
+
CString sPrssrBin;
|
| 85 |
+
sPrssrBin.Format(_T("%s\\%s"), sInstallDir, PRSSREADER_BIN);
|
| 86 |
+
CreateProcess(sPrssrBin, sPars, NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL);
|
| 87 |
+
return 0;
|
| 88 |
+
}
|
| 89 |
+
else {
|
| 90 |
+
// pRSSreader is running -> send update all message
|
| 91 |
+
::PostMessage(hWnd, UWM_UPDATE_ALL, 0, 0);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
return 0;
|
| 95 |
+
}
|
| 96 |
+
|
pool/shard002/C++/0034790_CWE122_Heap_Based_Buffer_Overflow__cpp_dest_wchar_t_cat_72b.cpp
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE122_Heap_Based_Buffer_Overflow__cpp_dest_wchar_t_cat_72b.cpp
|
| 3 |
+
Label Definition File: CWE122_Heap_Based_Buffer_Overflow__cpp_dest.label.xml
|
| 4 |
+
Template File: sources-sink-72b.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 122 Heap Based Buffer Overflow
|
| 9 |
+
* BadSource: Allocate using new[] and set data pointer to a small buffer
|
| 10 |
+
* GoodSource: Allocate using new[] and set data pointer to a large buffer
|
| 11 |
+
* Sinks: cat
|
| 12 |
+
* BadSink : Copy string to data using wcscat
|
| 13 |
+
* Flow Variant: 72 Data flow: data passed in a vector from one function to another in different source files
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
|
| 17 |
+
#include "std_testcase.h"
|
| 18 |
+
#include <vector>
|
| 19 |
+
|
| 20 |
+
#include <wchar.h>
|
| 21 |
+
|
| 22 |
+
using namespace std;
|
| 23 |
+
|
| 24 |
+
namespace CWE122_Heap_Based_Buffer_Overflow__cpp_dest_wchar_t_cat_72
|
| 25 |
+
{
|
| 26 |
+
|
| 27 |
+
#ifndef OMITBAD
|
| 28 |
+
|
| 29 |
+
void badSink(vector<wchar_t *> dataVector)
|
| 30 |
+
{
|
| 31 |
+
/* copy data out of dataVector */
|
| 32 |
+
wchar_t * data = dataVector[2];
|
| 33 |
+
{
|
| 34 |
+
wchar_t source[100];
|
| 35 |
+
wmemset(source, L'C', 100-1); /* fill with L'C's */
|
| 36 |
+
source[100-1] = L'\0'; /* null terminate */
|
| 37 |
+
/* POTENTIAL FLAW: Possible buffer overflow if source is larger than sizeof(data)-strlen(data) */
|
| 38 |
+
wcscat(data, source);
|
| 39 |
+
printWLine(data);
|
| 40 |
+
delete [] data;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
#endif /* OMITBAD */
|
| 45 |
+
|
| 46 |
+
#ifndef OMITGOOD
|
| 47 |
+
|
| 48 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 49 |
+
void goodG2BSink(vector<wchar_t *> dataVector)
|
| 50 |
+
{
|
| 51 |
+
wchar_t * data = dataVector[2];
|
| 52 |
+
{
|
| 53 |
+
wchar_t source[100];
|
| 54 |
+
wmemset(source, L'C', 100-1); /* fill with L'C's */
|
| 55 |
+
source[100-1] = L'\0'; /* null terminate */
|
| 56 |
+
/* POTENTIAL FLAW: Possible buffer overflow if source is larger than sizeof(data)-strlen(data) */
|
| 57 |
+
wcscat(data, source);
|
| 58 |
+
printWLine(data);
|
| 59 |
+
delete [] data;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
#endif /* OMITGOOD */
|
| 64 |
+
|
| 65 |
+
} /* close namespace */
|
pool/shard002/C++/0034794_TBOX_PREFIX_App.cpp
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "cinder/app/AppNative.h"
|
| 2 |
+
#include "cinder/app/RendererGl.h"
|
| 3 |
+
#include "cinder/gl/gl.h"
|
| 4 |
+
#include "cinder/qtime/QuickTime.h"
|
| 5 |
+
#include "CinderLiveStreamer.h"
|
| 6 |
+
#define DEFAULT_STREAM "http://www.ustream.tv/channel/live-iss-stream"
|
| 7 |
+
using namespace ci;
|
| 8 |
+
using namespace ci::app;
|
| 9 |
+
using namespace std;
|
| 10 |
+
|
| 11 |
+
class _TBOX_PREFIX_App : public AppNative {
|
| 12 |
+
public:
|
| 13 |
+
void setup() override;
|
| 14 |
+
void mouseDown( MouseEvent event ) override;
|
| 15 |
+
void update() override;
|
| 16 |
+
void draw() override;
|
| 17 |
+
void resize() override;
|
| 18 |
+
|
| 19 |
+
private:
|
| 20 |
+
string getStreamUrl(string _link);
|
| 21 |
+
|
| 22 |
+
qtime::MovieSurfaceRef mMovieRef;
|
| 23 |
+
SurfaceRef mSurfaceRef;
|
| 24 |
+
int mWidth, mHeight;
|
| 25 |
+
string mStream;
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
void _TBOX_PREFIX_App::resize(){
|
| 29 |
+
mWidth = getWindowWidth();
|
| 30 |
+
mHeight= getWindowHeight();
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
void _TBOX_PREFIX_App::setup()
|
| 34 |
+
{
|
| 35 |
+
string mStream = CinderLiveStreamer::getStreamUrl("http://www.ustream.tv/channel/live-iss-stream");
|
| 36 |
+
if (mStream != "ERROR") {
|
| 37 |
+
mMovieRef = cinder::qtime::MovieSurface::create( Url(mStream) );
|
| 38 |
+
}
|
| 39 |
+
mWidth = getWindowWidth();
|
| 40 |
+
mHeight= getWindowHeight();
|
| 41 |
+
getWindow()->setTitle( "Cinder LiveStreamer: " + (mStream == "ERROR" ? mStream : DEFAULT_STREAM));
|
| 42 |
+
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void _TBOX_PREFIX_App::mouseDown( MouseEvent event )
|
| 46 |
+
{
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void _TBOX_PREFIX_App::update()
|
| 50 |
+
{
|
| 51 |
+
if (mMovieRef->checkNewFrame())
|
| 52 |
+
mSurfaceRef = mMovieRef->getSurface();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
void _TBOX_PREFIX_App::draw()
|
| 56 |
+
{
|
| 57 |
+
gl::clear( Color( 0, 0, 0 ) );
|
| 58 |
+
|
| 59 |
+
if (mSurfaceRef){
|
| 60 |
+
gl::draw(gl::Texture::create(*mSurfaceRef), Rectf(0,0,mWidth,mHeight));
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
CINDER_APP_NATIVE( _TBOX_PREFIX_App, RendererGl )
|
pool/shard002/C++/0034812_2.17a.cpp
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "iostream"
|
| 2 |
+
#include "fstream"
|
| 3 |
+
#include "math.h"
|
| 4 |
+
#include "vector"
|
| 5 |
+
#include "iomanip"
|
| 6 |
+
#include "string.h"
|
| 7 |
+
|
| 8 |
+
using namespace std;
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
int main()
|
| 12 |
+
{
|
| 13 |
+
string s;
|
| 14 |
+
getline(cin,s);
|
| 15 |
+
string zj = "()"; int i=0; bool tart;
|
| 16 |
+
while (i<s.length())
|
| 17 |
+
{
|
| 18 |
+
if (tart) {
|
| 19 |
+
if (s.at(i)==zj.at(1)) break;
|
| 20 |
+
cout << s.at(i);
|
| 21 |
+
}else{
|
| 22 |
+
if (s.at(i)==zj.at(0)) tart=true;
|
| 23 |
+
}
|
| 24 |
+
i++;
|
| 25 |
+
}
|
| 26 |
+
getchar();
|
| 27 |
+
return 0;
|
| 28 |
+
}
|
pool/shard002/C++/0034813_sp-canvas-util.cpp
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Helper stuff for SPCanvas
|
| 3 |
+
*
|
| 4 |
+
* Authors:
|
| 5 |
+
* Lauris Kaplinski <lauris@kaplinski.com>
|
| 6 |
+
* Jon A. Cruz <jon@joncruz.org>
|
| 7 |
+
*
|
| 8 |
+
* Copyright (C) 1999-2002 authors
|
| 9 |
+
* Copyright (C) 2001-2002 Ximian, Inc.
|
| 10 |
+
*
|
| 11 |
+
* Released under GNU GPL, read the file 'COPYING' for more information
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
#include <2geom/affine.h>
|
| 16 |
+
#include "sp-canvas-util.h"
|
| 17 |
+
#include "sp-canvas-item.h"
|
| 18 |
+
#include "sp-canvas.h"
|
| 19 |
+
|
| 20 |
+
void sp_canvas_update_bbox(SPCanvasItem *item, int x1, int y1, int x2, int y2)
|
| 21 |
+
{
|
| 22 |
+
item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
|
| 23 |
+
item->x1 = x1;
|
| 24 |
+
item->y1 = y1;
|
| 25 |
+
item->x2 = x2;
|
| 26 |
+
item->y2 = y2;
|
| 27 |
+
item->canvas->requestRedraw((int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void
|
| 31 |
+
sp_canvas_item_reset_bounds (SPCanvasItem *item)
|
| 32 |
+
{
|
| 33 |
+
item->x1 = 0.0;
|
| 34 |
+
item->y1 = 0.0;
|
| 35 |
+
item->x2 = 0.0;
|
| 36 |
+
item->y2 = 0.0;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
void sp_canvas_prepare_buffer(SPCanvasBuf *)
|
| 40 |
+
{
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
Geom::Affine sp_canvas_item_i2p_affine (SPCanvasItem * item)
|
| 44 |
+
{
|
| 45 |
+
g_assert (item != NULL); /* this may be overly zealous - it is
|
| 46 |
+
* plausible that this gets called
|
| 47 |
+
* with item == 0. */
|
| 48 |
+
|
| 49 |
+
return item->xform;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
Geom::Affine sp_canvas_item_i2i_affine (SPCanvasItem * from, SPCanvasItem * to)
|
| 53 |
+
{
|
| 54 |
+
g_assert (from != NULL);
|
| 55 |
+
g_assert (to != NULL);
|
| 56 |
+
|
| 57 |
+
return sp_canvas_item_i2w_affine(from) * sp_canvas_item_i2w_affine(to).inverse();
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
void sp_canvas_item_set_i2w_affine (SPCanvasItem * item, Geom::Affine const &i2w)
|
| 61 |
+
{
|
| 62 |
+
g_assert (item != NULL);
|
| 63 |
+
|
| 64 |
+
sp_canvas_item_affine_absolute(item, i2w * sp_canvas_item_i2w_affine(item->parent).inverse());
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
void sp_canvas_item_move_to_z (SPCanvasItem * item, gint z)
|
| 68 |
+
{
|
| 69 |
+
g_assert (item != NULL);
|
| 70 |
+
|
| 71 |
+
if (z == 0)
|
| 72 |
+
return sp_canvas_item_lower_to_bottom(item);
|
| 73 |
+
|
| 74 |
+
gint current_z = sp_canvas_item_order (item);
|
| 75 |
+
|
| 76 |
+
if (current_z == -1) // not found in its parent
|
| 77 |
+
return;
|
| 78 |
+
|
| 79 |
+
if (z == current_z)
|
| 80 |
+
return;
|
| 81 |
+
|
| 82 |
+
if (z > current_z) {
|
| 83 |
+
sp_canvas_item_raise (item, z - current_z);
|
| 84 |
+
} else {
|
| 85 |
+
sp_canvas_item_lower (item, current_z - z);
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
gint
|
| 90 |
+
sp_canvas_item_compare_z (SPCanvasItem * a, SPCanvasItem * b)
|
| 91 |
+
{
|
| 92 |
+
gint const o_a = sp_canvas_item_order (a);
|
| 93 |
+
gint const o_b = sp_canvas_item_order (b);
|
| 94 |
+
|
| 95 |
+
if (o_a > o_b) return -1;
|
| 96 |
+
if (o_a < o_b) return 1;
|
| 97 |
+
|
| 98 |
+
return 0;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/*
|
| 102 |
+
Local Variables:
|
| 103 |
+
mode:c++
|
| 104 |
+
c-file-style:"stroustrup"
|
| 105 |
+
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
|
| 106 |
+
indent-tabs-mode:nil
|
| 107 |
+
fill-column:99
|
| 108 |
+
End:
|
| 109 |
+
*/
|
| 110 |
+
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
|
pool/shard002/C++/0034818_high_resolution_timer.cpp
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// high resolution timer for use on Windows platforms
|
| 2 |
+
#include <windows.h>
|
| 3 |
+
|
| 4 |
+
#include "high_resolution_timer.h"
|
| 5 |
+
|
| 6 |
+
TUNE_NAMESPACE_BEGIN
|
| 7 |
+
|
| 8 |
+
struct high_resolution_timer::impl
|
| 9 |
+
{
|
| 10 |
+
LARGE_INTEGER start_time;
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
high_resolution_timer::high_resolution_timer()
|
| 14 |
+
{
|
| 15 |
+
pimpl = std::unique_ptr<impl>(new impl);
|
| 16 |
+
restart();
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
high_resolution_timer::~high_resolution_timer()
|
| 20 |
+
{
|
| 21 |
+
// default
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
void high_resolution_timer::restart()
|
| 25 |
+
{
|
| 26 |
+
QueryPerformanceCounter(&pimpl->start_time);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
double high_resolution_timer::elapsed()
|
| 30 |
+
{
|
| 31 |
+
LARGE_INTEGER end_time;
|
| 32 |
+
QueryPerformanceCounter(&end_time);
|
| 33 |
+
LARGE_INTEGER PerformanceFrequency_hz;
|
| 34 |
+
QueryPerformanceFrequency(&PerformanceFrequency_hz);
|
| 35 |
+
double frequency = double(PerformanceFrequency_hz.QuadPart);
|
| 36 |
+
return double(end_time.QuadPart - pimpl->start_time.QuadPart) / frequency;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
TUNE_NAMESPACE_END
|
pool/shard002/C++/0034820_suggestions_service_factory.cc
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "chrome/browser/search/suggestions/suggestions_service_factory.h"
|
| 6 |
+
|
| 7 |
+
#include "base/prefs/pref_service.h"
|
| 8 |
+
#include "chrome/browser/profiles/incognito_helpers.h"
|
| 9 |
+
#include "chrome/browser/profiles/profile.h"
|
| 10 |
+
#include "chrome/browser/search/suggestions/suggestions_service.h"
|
| 11 |
+
#include "chrome/browser/search/suggestions/suggestions_store.h"
|
| 12 |
+
#include "chrome/common/pref_names.h"
|
| 13 |
+
#include "components/keyed_service/content/browser_context_dependency_manager.h"
|
| 14 |
+
#include "components/pref_registry/pref_registry_syncable.h"
|
| 15 |
+
|
| 16 |
+
namespace suggestions {
|
| 17 |
+
|
| 18 |
+
// static
|
| 19 |
+
SuggestionsService* SuggestionsServiceFactory::GetForProfile(Profile* profile) {
|
| 20 |
+
if (!SuggestionsService::IsEnabled()) return NULL;
|
| 21 |
+
|
| 22 |
+
return static_cast<SuggestionsService*>(
|
| 23 |
+
GetInstance()->GetServiceForBrowserContext(profile, true));
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
// static
|
| 27 |
+
SuggestionsServiceFactory* SuggestionsServiceFactory::GetInstance() {
|
| 28 |
+
return Singleton<SuggestionsServiceFactory>::get();
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
SuggestionsServiceFactory::SuggestionsServiceFactory()
|
| 32 |
+
: BrowserContextKeyedServiceFactory(
|
| 33 |
+
"SuggestionsService",
|
| 34 |
+
BrowserContextDependencyManager::GetInstance()) {
|
| 35 |
+
// No dependencies.
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
SuggestionsServiceFactory::~SuggestionsServiceFactory() {}
|
| 39 |
+
|
| 40 |
+
content::BrowserContext* SuggestionsServiceFactory::GetBrowserContextToUse(
|
| 41 |
+
content::BrowserContext* context) const {
|
| 42 |
+
return chrome::GetBrowserContextRedirectedInIncognito(context);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
KeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor(
|
| 46 |
+
content::BrowserContext* profile) const {
|
| 47 |
+
Profile* the_profile = static_cast<Profile*>(profile);
|
| 48 |
+
scoped_ptr<SuggestionsStore> suggestions_store(
|
| 49 |
+
new SuggestionsStore(the_profile->GetPrefs()));
|
| 50 |
+
return new SuggestionsService(the_profile, suggestions_store.Pass());
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
void SuggestionsServiceFactory::RegisterProfilePrefs(
|
| 54 |
+
user_prefs::PrefRegistrySyncable* registry) {
|
| 55 |
+
SuggestionsService::RegisterProfilePrefs(registry);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
} // namespace suggestions
|
pool/shard002/C++/0034822_SoundRecorder.cpp
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
////////////////////////////////////////////////////////////
|
| 2 |
+
//
|
| 3 |
+
// SFML - Simple and Fast Multimedia Library
|
| 4 |
+
// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
|
| 5 |
+
//
|
| 6 |
+
// This software is provided 'as-is', without any express or implied warranty.
|
| 7 |
+
// In no event will the authors be held liable for any damages arising from the use of this software.
|
| 8 |
+
//
|
| 9 |
+
// Permission is granted to anyone to use this software for any purpose,
|
| 10 |
+
// including commercial applications, and to alter it and redistribute it freely,
|
| 11 |
+
// subject to the following restrictions:
|
| 12 |
+
//
|
| 13 |
+
// 1. The origin of this software must not be misrepresented;
|
| 14 |
+
// you must not claim that you wrote the original software.
|
| 15 |
+
// If you use this software in a product, an acknowledgment
|
| 16 |
+
// in the product documentation would be appreciated but is not required.
|
| 17 |
+
//
|
| 18 |
+
// 2. Altered source versions must be plainly marked as such,
|
| 19 |
+
// and must not be misrepresented as being the original software.
|
| 20 |
+
//
|
| 21 |
+
// 3. This notice may not be removed or altered from any source distribution.
|
| 22 |
+
//
|
| 23 |
+
////////////////////////////////////////////////////////////
|
| 24 |
+
|
| 25 |
+
////////////////////////////////////////////////////////////
|
| 26 |
+
// Headers
|
| 27 |
+
////////////////////////////////////////////////////////////
|
| 28 |
+
#include <SFML/Audio/SoundRecorder.hpp>
|
| 29 |
+
#include <SFML/Audio/AudioDevice.hpp>
|
| 30 |
+
#include <SFML/Audio/ALCheck.hpp>
|
| 31 |
+
#include <SFML/System/Sleep.hpp>
|
| 32 |
+
#include <SFML/System/Err.hpp>
|
| 33 |
+
|
| 34 |
+
#ifdef _MSC_VER
|
| 35 |
+
#pragma warning(disable : 4355) // 'this' used in base member initializer list
|
| 36 |
+
#endif
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
namespace
|
| 40 |
+
{
|
| 41 |
+
ALCdevice* captureDevice = NULL;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
namespace sf
|
| 45 |
+
{
|
| 46 |
+
////////////////////////////////////////////////////////////
|
| 47 |
+
SoundRecorder::SoundRecorder() :
|
| 48 |
+
m_thread (&SoundRecorder::record, this),
|
| 49 |
+
m_sampleRate (0),
|
| 50 |
+
m_isCapturing(false)
|
| 51 |
+
{
|
| 52 |
+
priv::ensureALInit();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
////////////////////////////////////////////////////////////
|
| 57 |
+
SoundRecorder::~SoundRecorder()
|
| 58 |
+
{
|
| 59 |
+
// Nothing to do
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
////////////////////////////////////////////////////////////
|
| 64 |
+
void SoundRecorder::start(unsigned int sampleRate)
|
| 65 |
+
{
|
| 66 |
+
// Check if the device can do audio capture
|
| 67 |
+
if (!isAvailable())
|
| 68 |
+
{
|
| 69 |
+
err() << "Failed to start capture : your system cannot capture audio data (call SoundRecorder::IsAvailable to check it)" << std::endl;
|
| 70 |
+
return;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// Check that another capture is not already running
|
| 74 |
+
if (captureDevice)
|
| 75 |
+
{
|
| 76 |
+
err() << "Trying to start audio capture, but another capture is already running" << std::endl;
|
| 77 |
+
return;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
// Open the capture device for capturing 16 bits mono samples
|
| 81 |
+
captureDevice = alcCaptureOpenDevice(NULL, sampleRate, AL_FORMAT_MONO16, sampleRate);
|
| 82 |
+
if (!captureDevice)
|
| 83 |
+
{
|
| 84 |
+
err() << "Failed to open the audio capture device" << std::endl;
|
| 85 |
+
return;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
// Clear the array of samples
|
| 89 |
+
m_samples.clear();
|
| 90 |
+
|
| 91 |
+
// Store the sample rate
|
| 92 |
+
m_sampleRate = sampleRate;
|
| 93 |
+
|
| 94 |
+
// Notify derived class
|
| 95 |
+
if (onStart())
|
| 96 |
+
{
|
| 97 |
+
// Start the capture
|
| 98 |
+
alcCaptureStart(captureDevice);
|
| 99 |
+
|
| 100 |
+
// Start the capture in a new thread, to avoid blocking the main thread
|
| 101 |
+
m_isCapturing = true;
|
| 102 |
+
m_thread.launch();
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
////////////////////////////////////////////////////////////
|
| 108 |
+
void SoundRecorder::stop()
|
| 109 |
+
{
|
| 110 |
+
// Stop the capturing thread
|
| 111 |
+
m_isCapturing = false;
|
| 112 |
+
m_thread.wait();
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
////////////////////////////////////////////////////////////
|
| 117 |
+
unsigned int SoundRecorder::getSampleRate() const
|
| 118 |
+
{
|
| 119 |
+
return m_sampleRate;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
////////////////////////////////////////////////////////////
|
| 124 |
+
bool SoundRecorder::isAvailable()
|
| 125 |
+
{
|
| 126 |
+
return (priv::AudioDevice::isExtensionSupported("ALC_EXT_CAPTURE") != AL_FALSE) ||
|
| 127 |
+
(priv::AudioDevice::isExtensionSupported("ALC_EXT_capture") != AL_FALSE); // "bug" in Mac OS X 10.5 and 10.6
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
////////////////////////////////////////////////////////////
|
| 132 |
+
bool SoundRecorder::onStart()
|
| 133 |
+
{
|
| 134 |
+
// Nothing to do
|
| 135 |
+
return true;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
////////////////////////////////////////////////////////////
|
| 140 |
+
void SoundRecorder::onStop()
|
| 141 |
+
{
|
| 142 |
+
// Nothing to do
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
////////////////////////////////////////////////////////////
|
| 147 |
+
void SoundRecorder::record()
|
| 148 |
+
{
|
| 149 |
+
while (m_isCapturing)
|
| 150 |
+
{
|
| 151 |
+
// Process available samples
|
| 152 |
+
processCapturedSamples();
|
| 153 |
+
|
| 154 |
+
// Don't bother the CPU while waiting for more captured data
|
| 155 |
+
sleep(milliseconds(100));
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
// Capture is finished : clean up everything
|
| 159 |
+
cleanup();
|
| 160 |
+
|
| 161 |
+
// Notify derived class
|
| 162 |
+
onStop();
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
////////////////////////////////////////////////////////////
|
| 167 |
+
void SoundRecorder::processCapturedSamples()
|
| 168 |
+
{
|
| 169 |
+
// Get the number of samples available
|
| 170 |
+
ALCint samplesAvailable;
|
| 171 |
+
alcGetIntegerv(captureDevice, ALC_CAPTURE_SAMPLES, 1, &samplesAvailable);
|
| 172 |
+
|
| 173 |
+
if (samplesAvailable > 0)
|
| 174 |
+
{
|
| 175 |
+
// Get the recorded samples
|
| 176 |
+
m_samples.resize(samplesAvailable);
|
| 177 |
+
alcCaptureSamples(captureDevice, &m_samples[0], samplesAvailable);
|
| 178 |
+
|
| 179 |
+
// Forward them to the derived class
|
| 180 |
+
if (!onProcessSamples(&m_samples[0], m_samples.size()))
|
| 181 |
+
{
|
| 182 |
+
// The user wants to stop the capture
|
| 183 |
+
m_isCapturing = false;
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
////////////////////////////////////////////////////////////
|
| 190 |
+
void SoundRecorder::cleanup()
|
| 191 |
+
{
|
| 192 |
+
// Stop the capture
|
| 193 |
+
alcCaptureStop(captureDevice);
|
| 194 |
+
|
| 195 |
+
// Get the samples left in the buffer
|
| 196 |
+
processCapturedSamples();
|
| 197 |
+
|
| 198 |
+
// Close the device
|
| 199 |
+
alcCaptureCloseDevice(captureDevice);
|
| 200 |
+
captureDevice = NULL;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
} // namespace sf
|