Upload folder using huggingface_hub (part 50)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard004/C++/0048478_tlkreplace.cpp +54 -0
- pool/shard004/C++/0048484_VerticalSlotExtension.cpp +86 -0
- pool/shard004/C++/0048491_UnwindTable.cpp +207 -0
- pool/shard004/C++/0048497_editaddressdialog.cpp +128 -0
- pool/shard004/C++/0048506_animation.cpp +195 -0
- pool/shard004/C++/0048517_apps_promo_unittest.cc +166 -0
- pool/shard004/C++/0048520_GetTemplateResult.cpp +65 -0
- pool/shard004/C++/0048522_Addon.cpp +201 -0
- pool/shard004/C++/0048527_valuenode.cpp +63 -0
- pool/shard004/C++/0048531_crypter.cpp +134 -0
- pool/shard004/C++/0048555_AndroidJNIBridge.cc +141 -0
- pool/shard004/C++/0048558_containsintegerpoint1.cc +131 -0
- pool/shard004/C++/0048564_MayaPlugin.cpp +82 -0
- pool/shard004/C++/0048565_demo_ballDEM.cpp +184 -0
- pool/shard004/C++/0048580_signals_unittest.cc +222 -0
- pool/shard004/C++/0048581_fpcoptionsplugin.cpp +126 -0
- pool/shard004/C++/0048582_main.cpp +169 -0
- pool/shard004/C++/0048594_synth_noise_impl.cc +63 -0
- pool/shard004/C++/0048599_ulinks.cpp +102 -0
- pool/shard004/C++/0048604_CWE78_OS_Command_Injection__wchar_t_environment_w32_spawnv_73a.cpp +139 -0
- pool/shard004/C++/0048612_util_test.cc +89 -0
- pool/shard004/C++/0048615_RtclRw11Unit.cpp +141 -0
- pool/shard004/C++/0048616_ConfigDialog.cpp +236 -0
- pool/shard004/C++/0048623_RedisCommand.cc +68 -0
- pool/shard004/C++/0048632_bitcoin.cpp +304 -0
- pool/shard004/C++/0048637_qgspointclusterrendererwidget.cpp +235 -0
- pool/shard004/C++/0048638_plasma.cc +127 -0
- pool/shard004/C++/0048649_Snapshot.cpp +72 -0
- pool/shard004/C++/0048653_XDisplay.cpp +102 -0
- pool/shard004/C++/0048657_NamedParameter.cpp +79 -0
- pool/shard004/C++/0048660_suppression_gain_unittest.cc +135 -0
- pool/shard004/C++/0048662_satcommon.cc +198 -0
- pool/shard004/C++/0048664_main_tests.cpp +76 -0
- pool/shard004/C++/0048670_time.cc +208 -0
- pool/shard004/C++/0048689_userdata.cpp +44 -0
- pool/shard004/C++/0048699_StringServer.cpp +95 -0
- pool/shard004/C++/0048708_load_jpeg.cpp +163 -0
- pool/shard004/C++/0048718_DragCaretController.cpp +120 -0
- pool/shard004/C++/0048719_LoanCalculator.cpp +212 -0
- pool/shard004/C++/0048722_Mixer.cpp +118 -0
- pool/shard004/C++/0048730_ItemNameUtils.cpp +59 -0
- pool/shard004/C++/0048732_GuiVSpace.cpp +175 -0
- pool/shard004/C++/0048733_ShippingOption.cpp +84 -0
- pool/shard004/C++/0048734_undirected.cpp +109 -0
- pool/shard004/C++/0048738_test.cpp +34 -0
- pool/shard004/C++/0048739_checkpoints.cpp +66 -0
- pool/shard004/C++/0048740_monotonic_clock.cc +42 -0
- pool/shard004/C++/0048755_callbacknepomukresourceretriever.cpp +51 -0
- pool/shard004/C++/0048761_ComponentManager.cpp +55 -0
- pool/shard004/C++/0048764_log.cpp +168 -0
pool/shard004/C++/0048478_tlkreplace.cpp
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// MIT License
|
| 2 |
+
//
|
| 3 |
+
// Copyright (c) 2017 sylt
|
| 4 |
+
//
|
| 5 |
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
// of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
// in the Software without restriction, including without limitation the rights
|
| 8 |
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
// copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
// furnished to do so, subject to the following conditions:
|
| 11 |
+
//
|
| 12 |
+
// The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
// copies or substantial portions of the Software.
|
| 14 |
+
//
|
| 15 |
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
// SOFTWARE.
|
| 22 |
+
|
| 23 |
+
#include <algorithm>
|
| 24 |
+
#include <iostream>
|
| 25 |
+
#include <sstream>
|
| 26 |
+
#include <fstream>
|
| 27 |
+
#include <string>
|
| 28 |
+
|
| 29 |
+
#include "libtlk.h"
|
| 30 |
+
|
| 31 |
+
static std::string ReadFileContents(const char* path)
|
| 32 |
+
{
|
| 33 |
+
std::ifstream file(path);
|
| 34 |
+
std::string newText((std::istreambuf_iterator<char>(file)),
|
| 35 |
+
std::istreambuf_iterator<char>());
|
| 36 |
+
return newText;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
int main(int argc, char* argv[])
|
| 40 |
+
{
|
| 41 |
+
if (argc != 4) {
|
| 42 |
+
fprintf(stderr,
|
| 43 |
+
"Usage: %s tlkfile index-to-replace file-with-new-text\n",
|
| 44 |
+
argv[0]);
|
| 45 |
+
return -1;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
tlk::Builder builder(argv[1]);
|
| 49 |
+
auto index = std::stoul(argv[2]);
|
| 50 |
+
builder.ReplaceLine(index, ReadFileContents(argv[3]));
|
| 51 |
+
builder.WriteFile(argv[1]);
|
| 52 |
+
|
| 53 |
+
printf("Line updated! Ensure update was correct by using tlkview.\n");
|
| 54 |
+
}
|
pool/shard004/C++/0048484_VerticalSlotExtension.cpp
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
| 2 |
+
|
| 3 |
+
#include "UMGEditorPrivatePCH.h"
|
| 4 |
+
#include "Components/VerticalBox.h"
|
| 5 |
+
#include "Components/VerticalBoxSlot.h"
|
| 6 |
+
#include "Extensions/VerticalSlotExtension.h"
|
| 7 |
+
#include "Kismet2/BlueprintEditorUtils.h"
|
| 8 |
+
#include "WidgetBlueprint.h"
|
| 9 |
+
|
| 10 |
+
#define LOCTEXT_NAMESPACE "UMG"
|
| 11 |
+
|
| 12 |
+
FVerticalSlotExtension::FVerticalSlotExtension()
|
| 13 |
+
{
|
| 14 |
+
ExtensionId = FName(TEXT("VerticalSlot"));
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
bool FVerticalSlotExtension::CanExtendSelection(const TArray< FWidgetReference >& Selection) const
|
| 18 |
+
{
|
| 19 |
+
for ( const FWidgetReference& Widget : Selection )
|
| 20 |
+
{
|
| 21 |
+
if ( !Widget.GetTemplate()->Slot || !Widget.GetTemplate()->Slot->IsA(UVerticalBoxSlot::StaticClass()) )
|
| 22 |
+
{
|
| 23 |
+
return false;
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
return Selection.Num() == 1;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void FVerticalSlotExtension::ExtendSelection(const TArray< FWidgetReference >& Selection, TArray< TSharedRef<FDesignerSurfaceElement> >& SurfaceElements)
|
| 31 |
+
{
|
| 32 |
+
SelectionCache = Selection;
|
| 33 |
+
|
| 34 |
+
TSharedRef<SButton> UpArrow = SNew(SButton)
|
| 35 |
+
.Text(LOCTEXT("UpArrow", "↑"))
|
| 36 |
+
.ContentPadding(FMargin(6, 2))
|
| 37 |
+
.IsEnabled(this, &FVerticalSlotExtension::CanShift, -1)
|
| 38 |
+
.OnClicked(this, &FVerticalSlotExtension::HandleShiftVertical, -1);
|
| 39 |
+
|
| 40 |
+
TSharedRef<SButton> DownArrow = SNew(SButton)
|
| 41 |
+
.Text(LOCTEXT("DownArrow", "↓"))
|
| 42 |
+
.ContentPadding(FMargin(6, 2))
|
| 43 |
+
.IsEnabled(this, &FVerticalSlotExtension::CanShift, 1)
|
| 44 |
+
.OnClicked(this, &FVerticalSlotExtension::HandleShiftVertical, 1);
|
| 45 |
+
|
| 46 |
+
UpArrow->SlatePrepass();
|
| 47 |
+
DownArrow->SlatePrepass();
|
| 48 |
+
|
| 49 |
+
SurfaceElements.Add(MakeShareable(new FDesignerSurfaceElement(UpArrow, EExtensionLayoutLocation::TopCenter, FVector2D(UpArrow->GetDesiredSize().X * -0.5f, -UpArrow->GetDesiredSize().Y))));
|
| 50 |
+
SurfaceElements.Add(MakeShareable(new FDesignerSurfaceElement(DownArrow, EExtensionLayoutLocation::BottomCenter, FVector2D(DownArrow->GetDesiredSize().X * -0.5f, 0))));
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
bool FVerticalSlotExtension::CanShift(int32 ShiftAmount) const
|
| 54 |
+
{
|
| 55 |
+
//TODO UMG Provide feedback if shifting is possible. Tricky with multiple items selected, if we ever support that.
|
| 56 |
+
return true;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
FReply FVerticalSlotExtension::HandleShiftVertical(int32 ShiftAmount)
|
| 60 |
+
{
|
| 61 |
+
BeginTransaction(LOCTEXT("MoveWidget", "Move Widget"));
|
| 62 |
+
|
| 63 |
+
for ( FWidgetReference& Selection : SelectionCache )
|
| 64 |
+
{
|
| 65 |
+
ShiftVertical(Selection.GetPreview(), ShiftAmount);
|
| 66 |
+
ShiftVertical(Selection.GetTemplate(), ShiftAmount);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
EndTransaction();
|
| 70 |
+
|
| 71 |
+
//TODO UMG Reorder the live slot without rebuilding the structure
|
| 72 |
+
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(Blueprint);
|
| 73 |
+
|
| 74 |
+
return FReply::Handled();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
void FVerticalSlotExtension::ShiftVertical(UWidget* Widget, int32 ShiftAmount)
|
| 78 |
+
{
|
| 79 |
+
UVerticalBox* Parent = CastChecked<UVerticalBox>(Widget->GetParent());
|
| 80 |
+
|
| 81 |
+
Parent->Modify();
|
| 82 |
+
int32 CurrentIndex = Parent->GetChildIndex(Widget);
|
| 83 |
+
Parent->ShiftChild(CurrentIndex + ShiftAmount, Widget);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
#undef LOCTEXT_NAMESPACE
|
pool/shard004/C++/0048491_UnwindTable.cpp
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- UnwindTable.cpp -----------------------------------------*- C++ -*-===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
|
| 9 |
+
#include "lldb/Symbol/UnwindTable.h"
|
| 10 |
+
|
| 11 |
+
#include <stdio.h>
|
| 12 |
+
|
| 13 |
+
#include "lldb/Core/Module.h"
|
| 14 |
+
#include "lldb/Core/Section.h"
|
| 15 |
+
#include "lldb/Symbol/ArmUnwindInfo.h"
|
| 16 |
+
#include "lldb/Symbol/CallFrameInfo.h"
|
| 17 |
+
#include "lldb/Symbol/CompactUnwindInfo.h"
|
| 18 |
+
#include "lldb/Symbol/DWARFCallFrameInfo.h"
|
| 19 |
+
#include "lldb/Symbol/FuncUnwinders.h"
|
| 20 |
+
#include "lldb/Symbol/ObjectFile.h"
|
| 21 |
+
#include "lldb/Symbol/SymbolContext.h"
|
| 22 |
+
#include "lldb/Symbol/SymbolVendor.h"
|
| 23 |
+
|
| 24 |
+
// There is one UnwindTable object per ObjectFile. It contains a list of Unwind
|
| 25 |
+
// objects -- one per function, populated lazily -- for the ObjectFile. Each
|
| 26 |
+
// Unwind object has multiple UnwindPlans for different scenarios.
|
| 27 |
+
|
| 28 |
+
using namespace lldb;
|
| 29 |
+
using namespace lldb_private;
|
| 30 |
+
|
| 31 |
+
UnwindTable::UnwindTable(Module &module)
|
| 32 |
+
: m_module(module), m_unwinds(), m_initialized(false), m_mutex(),
|
| 33 |
+
m_object_file_unwind_up(), m_eh_frame_up(), m_compact_unwind_up(),
|
| 34 |
+
m_arm_unwind_up() {}
|
| 35 |
+
|
| 36 |
+
// We can't do some of this initialization when the ObjectFile is running its
|
| 37 |
+
// ctor; delay doing it until needed for something.
|
| 38 |
+
|
| 39 |
+
void UnwindTable::Initialize() {
|
| 40 |
+
if (m_initialized)
|
| 41 |
+
return;
|
| 42 |
+
|
| 43 |
+
std::lock_guard<std::mutex> guard(m_mutex);
|
| 44 |
+
|
| 45 |
+
if (m_initialized) // check again once we've acquired the lock
|
| 46 |
+
return;
|
| 47 |
+
m_initialized = true;
|
| 48 |
+
ObjectFile *object_file = m_module.GetObjectFile();
|
| 49 |
+
if (!object_file)
|
| 50 |
+
return;
|
| 51 |
+
|
| 52 |
+
m_object_file_unwind_up = object_file->CreateCallFrameInfo();
|
| 53 |
+
|
| 54 |
+
SectionList *sl = m_module.GetSectionList();
|
| 55 |
+
if (!sl)
|
| 56 |
+
return;
|
| 57 |
+
|
| 58 |
+
SectionSP sect = sl->FindSectionByType(eSectionTypeEHFrame, true);
|
| 59 |
+
if (sect.get()) {
|
| 60 |
+
m_eh_frame_up.reset(
|
| 61 |
+
new DWARFCallFrameInfo(*object_file, sect, DWARFCallFrameInfo::EH));
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
sect = sl->FindSectionByType(eSectionTypeDWARFDebugFrame, true);
|
| 65 |
+
if (sect) {
|
| 66 |
+
m_debug_frame_up.reset(
|
| 67 |
+
new DWARFCallFrameInfo(*object_file, sect, DWARFCallFrameInfo::DWARF));
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
sect = sl->FindSectionByType(eSectionTypeCompactUnwind, true);
|
| 71 |
+
if (sect) {
|
| 72 |
+
m_compact_unwind_up.reset(new CompactUnwindInfo(*object_file, sect));
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
sect = sl->FindSectionByType(eSectionTypeARMexidx, true);
|
| 76 |
+
if (sect) {
|
| 77 |
+
SectionSP sect_extab = sl->FindSectionByType(eSectionTypeARMextab, true);
|
| 78 |
+
if (sect_extab.get()) {
|
| 79 |
+
m_arm_unwind_up.reset(new ArmUnwindInfo(*object_file, sect, sect_extab));
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
UnwindTable::~UnwindTable() {}
|
| 85 |
+
|
| 86 |
+
llvm::Optional<AddressRange> UnwindTable::GetAddressRange(const Address &addr,
|
| 87 |
+
SymbolContext &sc) {
|
| 88 |
+
AddressRange range;
|
| 89 |
+
|
| 90 |
+
// First check the unwind info from the object file plugin
|
| 91 |
+
if (m_object_file_unwind_up &&
|
| 92 |
+
m_object_file_unwind_up->GetAddressRange(addr, range))
|
| 93 |
+
return range;
|
| 94 |
+
|
| 95 |
+
// Check the symbol context
|
| 96 |
+
if (sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
|
| 97 |
+
false, range) &&
|
| 98 |
+
range.GetBaseAddress().IsValid())
|
| 99 |
+
return range;
|
| 100 |
+
|
| 101 |
+
// Does the eh_frame unwind info has a function bounds for this addr?
|
| 102 |
+
if (m_eh_frame_up && m_eh_frame_up->GetAddressRange(addr, range))
|
| 103 |
+
return range;
|
| 104 |
+
|
| 105 |
+
// Try debug_frame as well
|
| 106 |
+
if (m_debug_frame_up && m_debug_frame_up->GetAddressRange(addr, range))
|
| 107 |
+
return range;
|
| 108 |
+
|
| 109 |
+
return llvm::None;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
FuncUnwindersSP
|
| 113 |
+
UnwindTable::GetFuncUnwindersContainingAddress(const Address &addr,
|
| 114 |
+
SymbolContext &sc) {
|
| 115 |
+
Initialize();
|
| 116 |
+
|
| 117 |
+
std::lock_guard<std::mutex> guard(m_mutex);
|
| 118 |
+
|
| 119 |
+
// There is an UnwindTable per object file, so we can safely use file handles
|
| 120 |
+
addr_t file_addr = addr.GetFileAddress();
|
| 121 |
+
iterator end = m_unwinds.end();
|
| 122 |
+
iterator insert_pos = end;
|
| 123 |
+
if (!m_unwinds.empty()) {
|
| 124 |
+
insert_pos = m_unwinds.lower_bound(file_addr);
|
| 125 |
+
iterator pos = insert_pos;
|
| 126 |
+
if ((pos == m_unwinds.end()) ||
|
| 127 |
+
(pos != m_unwinds.begin() &&
|
| 128 |
+
pos->second->GetFunctionStartAddress() != addr))
|
| 129 |
+
--pos;
|
| 130 |
+
|
| 131 |
+
if (pos->second->ContainsAddress(addr))
|
| 132 |
+
return pos->second;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
auto range_or = GetAddressRange(addr, sc);
|
| 136 |
+
if (!range_or)
|
| 137 |
+
return nullptr;
|
| 138 |
+
|
| 139 |
+
FuncUnwindersSP func_unwinder_sp(new FuncUnwinders(*this, *range_or));
|
| 140 |
+
m_unwinds.insert(insert_pos,
|
| 141 |
+
std::make_pair(range_or->GetBaseAddress().GetFileAddress(),
|
| 142 |
+
func_unwinder_sp));
|
| 143 |
+
return func_unwinder_sp;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// Ignore any existing FuncUnwinders for this function, create a new one and
|
| 147 |
+
// don't add it to the UnwindTable. This is intended for use by target modules
|
| 148 |
+
// show-unwind where we want to create new UnwindPlans, not re-use existing
|
| 149 |
+
// ones.
|
| 150 |
+
FuncUnwindersSP
|
| 151 |
+
UnwindTable::GetUncachedFuncUnwindersContainingAddress(const Address &addr,
|
| 152 |
+
SymbolContext &sc) {
|
| 153 |
+
Initialize();
|
| 154 |
+
|
| 155 |
+
auto range_or = GetAddressRange(addr, sc);
|
| 156 |
+
if (!range_or)
|
| 157 |
+
return nullptr;
|
| 158 |
+
|
| 159 |
+
return std::make_shared<FuncUnwinders>(*this, *range_or);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
void UnwindTable::Dump(Stream &s) {
|
| 163 |
+
std::lock_guard<std::mutex> guard(m_mutex);
|
| 164 |
+
s.Format("UnwindTable for '{0}':\n", m_module.GetFileSpec());
|
| 165 |
+
const_iterator begin = m_unwinds.begin();
|
| 166 |
+
const_iterator end = m_unwinds.end();
|
| 167 |
+
for (const_iterator pos = begin; pos != end; ++pos) {
|
| 168 |
+
s.Printf("[%u] 0x%16.16" PRIx64 "\n", (unsigned)std::distance(begin, pos),
|
| 169 |
+
pos->first);
|
| 170 |
+
}
|
| 171 |
+
s.EOL();
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
lldb_private::CallFrameInfo *UnwindTable::GetObjectFileUnwindInfo() {
|
| 175 |
+
Initialize();
|
| 176 |
+
return m_object_file_unwind_up.get();
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
DWARFCallFrameInfo *UnwindTable::GetEHFrameInfo() {
|
| 180 |
+
Initialize();
|
| 181 |
+
return m_eh_frame_up.get();
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
DWARFCallFrameInfo *UnwindTable::GetDebugFrameInfo() {
|
| 185 |
+
Initialize();
|
| 186 |
+
return m_debug_frame_up.get();
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
CompactUnwindInfo *UnwindTable::GetCompactUnwindInfo() {
|
| 190 |
+
Initialize();
|
| 191 |
+
return m_compact_unwind_up.get();
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
ArmUnwindInfo *UnwindTable::GetArmUnwindInfo() {
|
| 195 |
+
Initialize();
|
| 196 |
+
return m_arm_unwind_up.get();
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
SymbolFile *UnwindTable::GetSymbolFile() { return m_module.GetSymbolFile(); }
|
| 200 |
+
|
| 201 |
+
ArchSpec UnwindTable::GetArchitecture() { return m_module.GetArchitecture(); }
|
| 202 |
+
|
| 203 |
+
bool UnwindTable::GetAllowAssemblyEmulationUnwindPlans() {
|
| 204 |
+
if (ObjectFile *object_file = m_module.GetObjectFile())
|
| 205 |
+
return object_file->AllowAssemblyEmulationUnwindPlans();
|
| 206 |
+
return false;
|
| 207 |
+
}
|
pool/shard004/C++/0048497_editaddressdialog.cpp
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "editaddressdialog.h"
|
| 2 |
+
#include "ui_editaddressdialog.h"
|
| 3 |
+
#include "addresstablemodel.h"
|
| 4 |
+
#include "guiutil.h"
|
| 5 |
+
|
| 6 |
+
#include <QDataWidgetMapper>
|
| 7 |
+
#include <QMessageBox>
|
| 8 |
+
|
| 9 |
+
EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
|
| 10 |
+
QDialog(parent),
|
| 11 |
+
ui(new Ui::EditAddressDialog), mapper(0), mode(mode), model(0)
|
| 12 |
+
{
|
| 13 |
+
ui->setupUi(this);
|
| 14 |
+
|
| 15 |
+
GUIUtil::setupAddressWidget(ui->addressEdit, this);
|
| 16 |
+
|
| 17 |
+
switch(mode)
|
| 18 |
+
{
|
| 19 |
+
case NewReceivingAddress:
|
| 20 |
+
setWindowTitle(tr("New receiving address"));
|
| 21 |
+
ui->addressEdit->setEnabled(false);
|
| 22 |
+
break;
|
| 23 |
+
case NewSendingAddress:
|
| 24 |
+
setWindowTitle(tr("New sending address"));
|
| 25 |
+
break;
|
| 26 |
+
case EditReceivingAddress:
|
| 27 |
+
setWindowTitle(tr("Edit receiving address"));
|
| 28 |
+
ui->addressEdit->setDisabled(true);
|
| 29 |
+
break;
|
| 30 |
+
case EditSendingAddress:
|
| 31 |
+
setWindowTitle(tr("Edit sending address"));
|
| 32 |
+
break;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
mapper = new QDataWidgetMapper(this);
|
| 36 |
+
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
EditAddressDialog::~EditAddressDialog()
|
| 40 |
+
{
|
| 41 |
+
delete ui;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void EditAddressDialog::setModel(AddressTableModel *model)
|
| 45 |
+
{
|
| 46 |
+
this->model = model;
|
| 47 |
+
mapper->setModel(model);
|
| 48 |
+
mapper->addMapping(ui->labelEdit, AddressTableModel::Label);
|
| 49 |
+
mapper->addMapping(ui->addressEdit, AddressTableModel::Address);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
void EditAddressDialog::loadRow(int row)
|
| 53 |
+
{
|
| 54 |
+
mapper->setCurrentIndex(row);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
bool EditAddressDialog::saveCurrentRow()
|
| 58 |
+
{
|
| 59 |
+
if(!model)
|
| 60 |
+
return false;
|
| 61 |
+
switch(mode)
|
| 62 |
+
{
|
| 63 |
+
case NewReceivingAddress:
|
| 64 |
+
case NewSendingAddress:
|
| 65 |
+
address = model->addRow(
|
| 66 |
+
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
|
| 67 |
+
ui->labelEdit->text(),
|
| 68 |
+
ui->addressEdit->text());
|
| 69 |
+
break;
|
| 70 |
+
case EditReceivingAddress:
|
| 71 |
+
case EditSendingAddress:
|
| 72 |
+
if(mapper->submit())
|
| 73 |
+
{
|
| 74 |
+
address = ui->addressEdit->text();
|
| 75 |
+
}
|
| 76 |
+
break;
|
| 77 |
+
}
|
| 78 |
+
return !address.isEmpty();
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void EditAddressDialog::accept()
|
| 82 |
+
{
|
| 83 |
+
if(!model)
|
| 84 |
+
return;
|
| 85 |
+
if(!saveCurrentRow())
|
| 86 |
+
{
|
| 87 |
+
switch(model->getEditStatus())
|
| 88 |
+
{
|
| 89 |
+
case AddressTableModel::DUPLICATE_ADDRESS:
|
| 90 |
+
QMessageBox::warning(this, windowTitle(),
|
| 91 |
+
tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
|
| 92 |
+
QMessageBox::Ok, QMessageBox::Ok);
|
| 93 |
+
break;
|
| 94 |
+
case AddressTableModel::INVALID_ADDRESS:
|
| 95 |
+
QMessageBox::warning(this, windowTitle(),
|
| 96 |
+
tr("The entered address \"%1\" is not a valid SafariCoin address.").arg(ui->addressEdit->text()),
|
| 97 |
+
QMessageBox::Ok, QMessageBox::Ok);
|
| 98 |
+
return;
|
| 99 |
+
case AddressTableModel::WALLET_UNLOCK_FAILURE:
|
| 100 |
+
QMessageBox::critical(this, windowTitle(),
|
| 101 |
+
tr("Could not unlock wallet."),
|
| 102 |
+
QMessageBox::Ok, QMessageBox::Ok);
|
| 103 |
+
return;
|
| 104 |
+
case AddressTableModel::KEY_GENERATION_FAILURE:
|
| 105 |
+
QMessageBox::critical(this, windowTitle(),
|
| 106 |
+
tr("New key generation failed."),
|
| 107 |
+
QMessageBox::Ok, QMessageBox::Ok);
|
| 108 |
+
return;
|
| 109 |
+
case AddressTableModel::OK:
|
| 110 |
+
// Failed with unknown reason. Just reject.
|
| 111 |
+
break;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
return;
|
| 115 |
+
}
|
| 116 |
+
QDialog::accept();
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
QString EditAddressDialog::getAddress() const
|
| 120 |
+
{
|
| 121 |
+
return address;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
void EditAddressDialog::setAddress(const QString &address)
|
| 125 |
+
{
|
| 126 |
+
this->address = address;
|
| 127 |
+
ui->addressEdit->setText(address);
|
| 128 |
+
}
|
pool/shard004/C++/0048506_animation.cpp
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
This file is part of Telegram Desktop,
|
| 3 |
+
the official desktop version of Telegram messaging app, see https://telegram.org
|
| 4 |
+
|
| 5 |
+
Telegram Desktop 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 |
+
It 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 |
+
In addition, as a special exception, the copyright holders give permission
|
| 16 |
+
to link the code of portions of this program with the OpenSSL library.
|
| 17 |
+
|
| 18 |
+
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
| 19 |
+
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
| 20 |
+
*/
|
| 21 |
+
#include "animation.h"
|
| 22 |
+
|
| 23 |
+
#include "media/media_clip_reader.h"
|
| 24 |
+
|
| 25 |
+
namespace Media {
|
| 26 |
+
namespace Clip {
|
| 27 |
+
|
| 28 |
+
Reader *const ReaderPointer::BadPointer = SharedMemoryLocation<Reader, 0>();
|
| 29 |
+
|
| 30 |
+
ReaderPointer::~ReaderPointer() {
|
| 31 |
+
if (valid()) {
|
| 32 |
+
delete _pointer;
|
| 33 |
+
}
|
| 34 |
+
_pointer = nullptr;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
} // namespace Clip
|
| 38 |
+
} // namespace Media
|
| 39 |
+
|
| 40 |
+
namespace {
|
| 41 |
+
|
| 42 |
+
AnimationManager *_manager = nullptr;
|
| 43 |
+
|
| 44 |
+
} // namespace
|
| 45 |
+
|
| 46 |
+
namespace anim {
|
| 47 |
+
|
| 48 |
+
transition linear = [](const float64 &delta, const float64 &dt) {
|
| 49 |
+
return delta * dt;
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
transition sineInOut = [](const float64 &delta, const float64 &dt) {
|
| 53 |
+
return -(delta / 2) * (cos(M_PI * dt) - 1);
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
transition halfSine = [](const float64 &delta, const float64 &dt) {
|
| 57 |
+
return delta * sin(M_PI * dt / 2);
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
transition easeOutBack = [](const float64 &delta, const float64 &dt) {
|
| 61 |
+
static constexpr auto s = 1.70158;
|
| 62 |
+
|
| 63 |
+
const float64 t = dt - 1;
|
| 64 |
+
return delta * (t * t * ((s + 1) * t + s) + 1);
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
transition easeInCirc = [](const float64 &delta, const float64 &dt) {
|
| 68 |
+
return -delta * (sqrt(1 - dt * dt) - 1);
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
transition easeOutCirc = [](const float64 &delta, const float64 &dt) {
|
| 72 |
+
const float64 t = dt - 1;
|
| 73 |
+
return delta * sqrt(1 - t * t);
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
transition easeInCubic = [](const float64 &delta, const float64 &dt) {
|
| 77 |
+
return delta * dt * dt * dt;
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
transition easeOutCubic = [](const float64 &delta, const float64 &dt) {
|
| 81 |
+
const float64 t = dt - 1;
|
| 82 |
+
return delta * (t * t * t + 1);
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
transition easeInQuint = [](const float64 &delta, const float64 &dt) {
|
| 86 |
+
const float64 t2 = dt * dt;
|
| 87 |
+
return delta * t2 * t2 * dt;
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
transition easeOutQuint = [](const float64 &delta, const float64 &dt) {
|
| 91 |
+
const float64 t = dt - 1, t2 = t * t;
|
| 92 |
+
return delta * (t2 * t2 * t + 1);
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
void startManager() {
|
| 96 |
+
stopManager();
|
| 97 |
+
|
| 98 |
+
_manager = new AnimationManager();
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
void stopManager() {
|
| 102 |
+
delete _manager;
|
| 103 |
+
_manager = nullptr;
|
| 104 |
+
|
| 105 |
+
Media::Clip::Finish();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
void registerClipManager(Media::Clip::Manager *manager) {
|
| 109 |
+
manager->connect(manager, SIGNAL(callback(Media::Clip::Reader*,qint32,qint32)), _manager, SLOT(clipCallback(Media::Clip::Reader*,qint32,qint32)));
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
} // anim
|
| 113 |
+
|
| 114 |
+
void BasicAnimation::start() {
|
| 115 |
+
if (!_manager) return;
|
| 116 |
+
|
| 117 |
+
_callbacks.start();
|
| 118 |
+
_manager->start(this);
|
| 119 |
+
_animating = true;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
void BasicAnimation::stop() {
|
| 123 |
+
if (!_manager) return;
|
| 124 |
+
|
| 125 |
+
_animating = false;
|
| 126 |
+
_manager->stop(this);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
AnimationManager::AnimationManager() : _timer(this), _iterating(false) {
|
| 130 |
+
_timer.setSingleShot(false);
|
| 131 |
+
connect(&_timer, SIGNAL(timeout()), this, SLOT(timeout()));
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
void AnimationManager::start(BasicAnimation *obj) {
|
| 135 |
+
if (_iterating) {
|
| 136 |
+
_starting.insert(obj);
|
| 137 |
+
if (!_stopping.isEmpty()) {
|
| 138 |
+
_stopping.remove(obj);
|
| 139 |
+
}
|
| 140 |
+
} else {
|
| 141 |
+
if (_objects.isEmpty()) {
|
| 142 |
+
_timer.start(AnimationTimerDelta);
|
| 143 |
+
}
|
| 144 |
+
_objects.insert(obj);
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
void AnimationManager::stop(BasicAnimation *obj) {
|
| 149 |
+
if (_iterating) {
|
| 150 |
+
_stopping.insert(obj);
|
| 151 |
+
if (!_starting.isEmpty()) {
|
| 152 |
+
_starting.remove(obj);
|
| 153 |
+
}
|
| 154 |
+
} else {
|
| 155 |
+
auto i = _objects.find(obj);
|
| 156 |
+
if (i != _objects.cend()) {
|
| 157 |
+
_objects.erase(i);
|
| 158 |
+
if (_objects.empty()) {
|
| 159 |
+
_timer.stop();
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
void AnimationManager::timeout() {
|
| 166 |
+
_iterating = true;
|
| 167 |
+
auto ms = getms();
|
| 168 |
+
for_const (auto object, _objects) {
|
| 169 |
+
if (!_stopping.contains(object)) {
|
| 170 |
+
object->step(ms, true);
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
_iterating = false;
|
| 174 |
+
|
| 175 |
+
if (!_starting.isEmpty()) {
|
| 176 |
+
for_const (auto object, _starting) {
|
| 177 |
+
_objects.insert(object);
|
| 178 |
+
}
|
| 179 |
+
_starting.clear();
|
| 180 |
+
}
|
| 181 |
+
if (!_stopping.isEmpty()) {
|
| 182 |
+
for_const (auto object, _stopping) {
|
| 183 |
+
_objects.remove(object);
|
| 184 |
+
}
|
| 185 |
+
_stopping.clear();
|
| 186 |
+
}
|
| 187 |
+
if (_objects.empty()) {
|
| 188 |
+
_timer.stop();
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
void AnimationManager::clipCallback(Media::Clip::Reader *reader, qint32 threadIndex, qint32 notification) {
|
| 193 |
+
Media::Clip::Reader::callback(reader, threadIndex, Media::Clip::Notification(notification));
|
| 194 |
+
}
|
| 195 |
+
|
pool/shard004/C++/0048517_apps_promo_unittest.cc
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2011 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/logging.h"
|
| 6 |
+
#include "chrome/browser/extensions/apps_promo.h"
|
| 7 |
+
#include "chrome/browser/prefs/browser_prefs.h"
|
| 8 |
+
#include "chrome/browser/ui/webui/ntp/shown_sections_handler.h"
|
| 9 |
+
#include "chrome/common/extensions/extension.h"
|
| 10 |
+
#include "chrome/common/pref_names.h"
|
| 11 |
+
#include "chrome/test/testing_browser_process_test.h"
|
| 12 |
+
#include "chrome/test/testing_pref_service.h"
|
| 13 |
+
#include "googleurl/src/gurl.h"
|
| 14 |
+
#include "testing/gtest/include/gtest/gtest.h"
|
| 15 |
+
|
| 16 |
+
namespace {
|
| 17 |
+
|
| 18 |
+
const char kPromoId[] = "23123123";
|
| 19 |
+
const char kPromoHeader[] = "Get great apps!";
|
| 20 |
+
const char kPromoButton[] = "Click for apps!";
|
| 21 |
+
const char kPromoLink[] = "http://apps.com";
|
| 22 |
+
const char kPromoExpire[] = "No thanks.";
|
| 23 |
+
|
| 24 |
+
} // namespace
|
| 25 |
+
|
| 26 |
+
class ExtensionAppsPromo : public TestingBrowserProcessTest {
|
| 27 |
+
public:
|
| 28 |
+
TestingPrefService* prefs() { return &prefs_; }
|
| 29 |
+
AppsPromo* apps_promo() { return &apps_promo_; }
|
| 30 |
+
|
| 31 |
+
protected:
|
| 32 |
+
explicit ExtensionAppsPromo();
|
| 33 |
+
|
| 34 |
+
// testing::Test
|
| 35 |
+
virtual void SetUp();
|
| 36 |
+
|
| 37 |
+
private:
|
| 38 |
+
TestingPrefService prefs_;
|
| 39 |
+
ScopedTestingLocalState local_state_;
|
| 40 |
+
AppsPromo apps_promo_;
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
ExtensionAppsPromo::ExtensionAppsPromo()
|
| 44 |
+
: local_state_(testing_browser_process_.get()),
|
| 45 |
+
apps_promo_(&prefs_) {
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void ExtensionAppsPromo::SetUp() {
|
| 49 |
+
browser::RegisterUserPrefs(&prefs_);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// TODO(dpolukhin): On Chrome OS all apps are installed via external extensions,
|
| 53 |
+
// and the web store promo is never shown.
|
| 54 |
+
#if !defined(OS_CHROMEOS)
|
| 55 |
+
TEST_F(ExtensionAppsPromo, HappyPath) {
|
| 56 |
+
const ExtensionIdSet& default_app_ids = apps_promo()->old_default_apps();
|
| 57 |
+
|
| 58 |
+
EXPECT_GT(default_app_ids.size(), 0u);
|
| 59 |
+
|
| 60 |
+
// The promo counter should default to the max, since we only use the counter
|
| 61 |
+
// if they were installed from older versions of Chrome.
|
| 62 |
+
EXPECT_EQ(AppsPromo::kDefaultAppsCounterMax + 1,
|
| 63 |
+
apps_promo()->GetPromoCounter());
|
| 64 |
+
|
| 65 |
+
// The app launcher and promo should not be shown if there are no extensions
|
| 66 |
+
// installed and no promo is set.
|
| 67 |
+
ExtensionIdSet installed_ids;
|
| 68 |
+
bool promo_just_expired = false;
|
| 69 |
+
EXPECT_FALSE(AppsPromo::IsPromoSupportedForLocale());
|
| 70 |
+
EXPECT_FALSE(apps_promo()->ShouldShowAppLauncher(installed_ids));
|
| 71 |
+
EXPECT_FALSE(apps_promo()->ShouldShowPromo(installed_ids,
|
| 72 |
+
&promo_just_expired));
|
| 73 |
+
EXPECT_FALSE(promo_just_expired);
|
| 74 |
+
|
| 75 |
+
// Once the promo is set, we show both the promo and app launcher.
|
| 76 |
+
AppsPromo::SetPromo(
|
| 77 |
+
kPromoId, kPromoHeader, kPromoButton, GURL(kPromoLink), kPromoExpire);
|
| 78 |
+
|
| 79 |
+
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
|
| 80 |
+
EXPECT_TRUE(apps_promo()->ShouldShowAppLauncher(installed_ids));
|
| 81 |
+
EXPECT_TRUE(apps_promo()->ShouldShowPromo(installed_ids,
|
| 82 |
+
&promo_just_expired));
|
| 83 |
+
EXPECT_FALSE(promo_just_expired);
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
// Now install an app and the promo should not be shown.
|
| 87 |
+
installed_ids.insert(*(default_app_ids.begin()));
|
| 88 |
+
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
|
| 89 |
+
EXPECT_TRUE(apps_promo()->ShouldShowAppLauncher(installed_ids));
|
| 90 |
+
EXPECT_FALSE(apps_promo()->ShouldShowPromo(installed_ids,
|
| 91 |
+
&promo_just_expired));
|
| 92 |
+
EXPECT_FALSE(promo_just_expired);
|
| 93 |
+
|
| 94 |
+
// Even if the user installs the exact set of default apps, we still don't
|
| 95 |
+
// show the promo.
|
| 96 |
+
installed_ids = default_app_ids;
|
| 97 |
+
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
|
| 98 |
+
EXPECT_TRUE(apps_promo()->ShouldShowAppLauncher(installed_ids));
|
| 99 |
+
EXPECT_FALSE(apps_promo()->ShouldShowPromo(installed_ids,
|
| 100 |
+
&promo_just_expired));
|
| 101 |
+
EXPECT_FALSE(promo_just_expired);
|
| 102 |
+
|
| 103 |
+
// If the user then uninstalls the apps, the app launcher should remain
|
| 104 |
+
// and the promo should return.
|
| 105 |
+
installed_ids.clear();
|
| 106 |
+
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
|
| 107 |
+
EXPECT_TRUE(apps_promo()->ShouldShowAppLauncher(installed_ids));
|
| 108 |
+
EXPECT_TRUE(apps_promo()->ShouldShowPromo(installed_ids,
|
| 109 |
+
&promo_just_expired));
|
| 110 |
+
EXPECT_FALSE(promo_just_expired);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// Tests get and set of promo content.
|
| 114 |
+
TEST_F(ExtensionAppsPromo, PromoPrefs) {
|
| 115 |
+
// Store a promo....
|
| 116 |
+
AppsPromo::SetPromo(
|
| 117 |
+
kPromoId, kPromoHeader, kPromoButton, GURL(kPromoLink), kPromoExpire);
|
| 118 |
+
|
| 119 |
+
// ... then make sure AppsPromo can access it.
|
| 120 |
+
EXPECT_EQ(kPromoId, AppsPromo::GetPromoId());
|
| 121 |
+
EXPECT_EQ(kPromoHeader, AppsPromo::GetPromoHeaderText());
|
| 122 |
+
EXPECT_EQ(kPromoButton, AppsPromo::GetPromoButtonText());
|
| 123 |
+
EXPECT_EQ(GURL(kPromoLink), AppsPromo::GetPromoLink());
|
| 124 |
+
EXPECT_EQ(kPromoExpire, AppsPromo::GetPromoExpireText());
|
| 125 |
+
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
|
| 126 |
+
|
| 127 |
+
AppsPromo::ClearPromo();
|
| 128 |
+
EXPECT_EQ("", AppsPromo::GetPromoId());
|
| 129 |
+
EXPECT_EQ("", AppsPromo::GetPromoHeaderText());
|
| 130 |
+
EXPECT_EQ("", AppsPromo::GetPromoButtonText());
|
| 131 |
+
EXPECT_EQ(GURL(""), AppsPromo::GetPromoLink());
|
| 132 |
+
EXPECT_EQ("", AppsPromo::GetPromoExpireText());
|
| 133 |
+
EXPECT_FALSE(AppsPromo::IsPromoSupportedForLocale());
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
// Tests that the apps section is maxmized when showing a promo for the first
|
| 137 |
+
// time.
|
| 138 |
+
TEST_F(ExtensionAppsPromo, UpdatePromoFocus) {
|
| 139 |
+
ExtensionIdSet installed_ids;
|
| 140 |
+
|
| 141 |
+
bool promo_just_expired = false;
|
| 142 |
+
EXPECT_FALSE(apps_promo()->ShouldShowPromo(installed_ids,
|
| 143 |
+
&promo_just_expired));
|
| 144 |
+
EXPECT_FALSE(promo_just_expired);
|
| 145 |
+
|
| 146 |
+
// Set the promo content.
|
| 147 |
+
AppsPromo::SetPromo(
|
| 148 |
+
kPromoId, kPromoHeader, kPromoButton, GURL(kPromoLink), kPromoExpire);
|
| 149 |
+
|
| 150 |
+
// After asking if we should show the promo, the
|
| 151 |
+
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
|
| 152 |
+
EXPECT_TRUE(apps_promo()->ShouldShowPromo(installed_ids,
|
| 153 |
+
&promo_just_expired));
|
| 154 |
+
apps_promo()->MaximizeAppsIfFirstView();
|
| 155 |
+
|
| 156 |
+
EXPECT_TRUE(
|
| 157 |
+
(ShownSectionsHandler::GetShownSections(prefs()) & APPS) != 0);
|
| 158 |
+
EXPECT_FALSE(
|
| 159 |
+
(ShownSectionsHandler::GetShownSections(prefs()) & THUMB) != 0);
|
| 160 |
+
|
| 161 |
+
apps_promo()->HidePromo();
|
| 162 |
+
|
| 163 |
+
EXPECT_TRUE((ShownSectionsHandler::GetShownSections(prefs()) &
|
| 164 |
+
(MENU_APPS | THUMB)) != 0);
|
| 165 |
+
}
|
| 166 |
+
#endif // OS_CHROMEOS
|
pool/shard004/C++/0048520_GetTemplateResult.cpp
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
| 3 |
+
* SPDX-License-Identifier: Apache-2.0.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#include <aws/cloudformation/model/GetTemplateResult.h>
|
| 7 |
+
#include <aws/core/utils/xml/XmlSerializer.h>
|
| 8 |
+
#include <aws/core/AmazonWebServiceResult.h>
|
| 9 |
+
#include <aws/core/utils/StringUtils.h>
|
| 10 |
+
#include <aws/core/utils/logging/LogMacros.h>
|
| 11 |
+
|
| 12 |
+
#include <utility>
|
| 13 |
+
|
| 14 |
+
using namespace Aws::CloudFormation::Model;
|
| 15 |
+
using namespace Aws::Utils::Xml;
|
| 16 |
+
using namespace Aws::Utils::Logging;
|
| 17 |
+
using namespace Aws::Utils;
|
| 18 |
+
using namespace Aws;
|
| 19 |
+
|
| 20 |
+
GetTemplateResult::GetTemplateResult()
|
| 21 |
+
{
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
GetTemplateResult::GetTemplateResult(const Aws::AmazonWebServiceResult<XmlDocument>& result)
|
| 25 |
+
{
|
| 26 |
+
*this = result;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
GetTemplateResult& GetTemplateResult::operator =(const Aws::AmazonWebServiceResult<XmlDocument>& result)
|
| 30 |
+
{
|
| 31 |
+
const XmlDocument& xmlDocument = result.GetPayload();
|
| 32 |
+
XmlNode rootNode = xmlDocument.GetRootElement();
|
| 33 |
+
XmlNode resultNode = rootNode;
|
| 34 |
+
if (!rootNode.IsNull() && (rootNode.GetName() != "GetTemplateResult"))
|
| 35 |
+
{
|
| 36 |
+
resultNode = rootNode.FirstChild("GetTemplateResult");
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
if(!resultNode.IsNull())
|
| 40 |
+
{
|
| 41 |
+
XmlNode templateBodyNode = resultNode.FirstChild("TemplateBody");
|
| 42 |
+
if(!templateBodyNode.IsNull())
|
| 43 |
+
{
|
| 44 |
+
m_templateBody = Aws::Utils::Xml::DecodeEscapedXmlText(templateBodyNode.GetText());
|
| 45 |
+
}
|
| 46 |
+
XmlNode stagesAvailableNode = resultNode.FirstChild("StagesAvailable");
|
| 47 |
+
if(!stagesAvailableNode.IsNull())
|
| 48 |
+
{
|
| 49 |
+
XmlNode stagesAvailableMember = stagesAvailableNode.FirstChild("member");
|
| 50 |
+
while(!stagesAvailableMember.IsNull())
|
| 51 |
+
{
|
| 52 |
+
m_stagesAvailable.push_back(TemplateStageMapper::GetTemplateStageForName(StringUtils::Trim(stagesAvailableMember.GetText().c_str())));
|
| 53 |
+
stagesAvailableMember = stagesAvailableMember.NextNode("member");
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (!rootNode.IsNull()) {
|
| 60 |
+
XmlNode responseMetadataNode = rootNode.FirstChild("ResponseMetadata");
|
| 61 |
+
m_responseMetadata = responseMetadataNode;
|
| 62 |
+
AWS_LOGSTREAM_DEBUG("Aws::CloudFormation::Model::GetTemplateResult", "x-amzn-request-id: " << m_responseMetadata.GetRequestId() );
|
| 63 |
+
}
|
| 64 |
+
return *this;
|
| 65 |
+
}
|
pool/shard004/C++/0048522_Addon.cpp
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
| 3 |
+
* SPDX-License-Identifier: Apache-2.0.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#include <aws/eks/model/Addon.h>
|
| 7 |
+
#include <aws/core/utils/json/JsonSerializer.h>
|
| 8 |
+
|
| 9 |
+
#include <utility>
|
| 10 |
+
|
| 11 |
+
using namespace Aws::Utils::Json;
|
| 12 |
+
using namespace Aws::Utils;
|
| 13 |
+
|
| 14 |
+
namespace Aws
|
| 15 |
+
{
|
| 16 |
+
namespace EKS
|
| 17 |
+
{
|
| 18 |
+
namespace Model
|
| 19 |
+
{
|
| 20 |
+
|
| 21 |
+
Addon::Addon() :
|
| 22 |
+
m_addonNameHasBeenSet(false),
|
| 23 |
+
m_clusterNameHasBeenSet(false),
|
| 24 |
+
m_status(AddonStatus::NOT_SET),
|
| 25 |
+
m_statusHasBeenSet(false),
|
| 26 |
+
m_addonVersionHasBeenSet(false),
|
| 27 |
+
m_healthHasBeenSet(false),
|
| 28 |
+
m_addonArnHasBeenSet(false),
|
| 29 |
+
m_createdAtHasBeenSet(false),
|
| 30 |
+
m_modifiedAtHasBeenSet(false),
|
| 31 |
+
m_serviceAccountRoleArnHasBeenSet(false),
|
| 32 |
+
m_tagsHasBeenSet(false)
|
| 33 |
+
{
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
Addon::Addon(JsonView jsonValue) :
|
| 37 |
+
m_addonNameHasBeenSet(false),
|
| 38 |
+
m_clusterNameHasBeenSet(false),
|
| 39 |
+
m_status(AddonStatus::NOT_SET),
|
| 40 |
+
m_statusHasBeenSet(false),
|
| 41 |
+
m_addonVersionHasBeenSet(false),
|
| 42 |
+
m_healthHasBeenSet(false),
|
| 43 |
+
m_addonArnHasBeenSet(false),
|
| 44 |
+
m_createdAtHasBeenSet(false),
|
| 45 |
+
m_modifiedAtHasBeenSet(false),
|
| 46 |
+
m_serviceAccountRoleArnHasBeenSet(false),
|
| 47 |
+
m_tagsHasBeenSet(false)
|
| 48 |
+
{
|
| 49 |
+
*this = jsonValue;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
Addon& Addon::operator =(JsonView jsonValue)
|
| 53 |
+
{
|
| 54 |
+
if(jsonValue.ValueExists("addonName"))
|
| 55 |
+
{
|
| 56 |
+
m_addonName = jsonValue.GetString("addonName");
|
| 57 |
+
|
| 58 |
+
m_addonNameHasBeenSet = true;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
if(jsonValue.ValueExists("clusterName"))
|
| 62 |
+
{
|
| 63 |
+
m_clusterName = jsonValue.GetString("clusterName");
|
| 64 |
+
|
| 65 |
+
m_clusterNameHasBeenSet = true;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
if(jsonValue.ValueExists("status"))
|
| 69 |
+
{
|
| 70 |
+
m_status = AddonStatusMapper::GetAddonStatusForName(jsonValue.GetString("status"));
|
| 71 |
+
|
| 72 |
+
m_statusHasBeenSet = true;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
if(jsonValue.ValueExists("addonVersion"))
|
| 76 |
+
{
|
| 77 |
+
m_addonVersion = jsonValue.GetString("addonVersion");
|
| 78 |
+
|
| 79 |
+
m_addonVersionHasBeenSet = true;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
if(jsonValue.ValueExists("health"))
|
| 83 |
+
{
|
| 84 |
+
m_health = jsonValue.GetObject("health");
|
| 85 |
+
|
| 86 |
+
m_healthHasBeenSet = true;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
if(jsonValue.ValueExists("addonArn"))
|
| 90 |
+
{
|
| 91 |
+
m_addonArn = jsonValue.GetString("addonArn");
|
| 92 |
+
|
| 93 |
+
m_addonArnHasBeenSet = true;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
if(jsonValue.ValueExists("createdAt"))
|
| 97 |
+
{
|
| 98 |
+
m_createdAt = jsonValue.GetDouble("createdAt");
|
| 99 |
+
|
| 100 |
+
m_createdAtHasBeenSet = true;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
if(jsonValue.ValueExists("modifiedAt"))
|
| 104 |
+
{
|
| 105 |
+
m_modifiedAt = jsonValue.GetDouble("modifiedAt");
|
| 106 |
+
|
| 107 |
+
m_modifiedAtHasBeenSet = true;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
if(jsonValue.ValueExists("serviceAccountRoleArn"))
|
| 111 |
+
{
|
| 112 |
+
m_serviceAccountRoleArn = jsonValue.GetString("serviceAccountRoleArn");
|
| 113 |
+
|
| 114 |
+
m_serviceAccountRoleArnHasBeenSet = true;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
if(jsonValue.ValueExists("tags"))
|
| 118 |
+
{
|
| 119 |
+
Aws::Map<Aws::String, JsonView> tagsJsonMap = jsonValue.GetObject("tags").GetAllObjects();
|
| 120 |
+
for(auto& tagsItem : tagsJsonMap)
|
| 121 |
+
{
|
| 122 |
+
m_tags[tagsItem.first] = tagsItem.second.AsString();
|
| 123 |
+
}
|
| 124 |
+
m_tagsHasBeenSet = true;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
return *this;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
JsonValue Addon::Jsonize() const
|
| 131 |
+
{
|
| 132 |
+
JsonValue payload;
|
| 133 |
+
|
| 134 |
+
if(m_addonNameHasBeenSet)
|
| 135 |
+
{
|
| 136 |
+
payload.WithString("addonName", m_addonName);
|
| 137 |
+
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
if(m_clusterNameHasBeenSet)
|
| 141 |
+
{
|
| 142 |
+
payload.WithString("clusterName", m_clusterName);
|
| 143 |
+
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
if(m_statusHasBeenSet)
|
| 147 |
+
{
|
| 148 |
+
payload.WithString("status", AddonStatusMapper::GetNameForAddonStatus(m_status));
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
if(m_addonVersionHasBeenSet)
|
| 152 |
+
{
|
| 153 |
+
payload.WithString("addonVersion", m_addonVersion);
|
| 154 |
+
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
if(m_healthHasBeenSet)
|
| 158 |
+
{
|
| 159 |
+
payload.WithObject("health", m_health.Jsonize());
|
| 160 |
+
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
if(m_addonArnHasBeenSet)
|
| 164 |
+
{
|
| 165 |
+
payload.WithString("addonArn", m_addonArn);
|
| 166 |
+
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
if(m_createdAtHasBeenSet)
|
| 170 |
+
{
|
| 171 |
+
payload.WithDouble("createdAt", m_createdAt.SecondsWithMSPrecision());
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
if(m_modifiedAtHasBeenSet)
|
| 175 |
+
{
|
| 176 |
+
payload.WithDouble("modifiedAt", m_modifiedAt.SecondsWithMSPrecision());
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
if(m_serviceAccountRoleArnHasBeenSet)
|
| 180 |
+
{
|
| 181 |
+
payload.WithString("serviceAccountRoleArn", m_serviceAccountRoleArn);
|
| 182 |
+
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
if(m_tagsHasBeenSet)
|
| 186 |
+
{
|
| 187 |
+
JsonValue tagsJsonMap;
|
| 188 |
+
for(auto& tagsItem : m_tags)
|
| 189 |
+
{
|
| 190 |
+
tagsJsonMap.WithString(tagsItem.first, tagsItem.second);
|
| 191 |
+
}
|
| 192 |
+
payload.WithObject("tags", std::move(tagsJsonMap));
|
| 193 |
+
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
return payload;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
} // namespace Model
|
| 200 |
+
} // namespace EKS
|
| 201 |
+
} // namespace Aws
|
pool/shard004/C++/0048527_valuenode.cpp
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "valuenode.h"
|
| 2 |
+
#include <QDebug>
|
| 3 |
+
ValueNode::ValueNode(ValueTypeEnum typeValue, QVariant value)
|
| 4 |
+
: AbstractValueASTNode(NT_NumericConstant)
|
| 5 |
+
{
|
| 6 |
+
|
| 7 |
+
_typeValue = typeValue;
|
| 8 |
+
if(_typeValue == typeString){
|
| 9 |
+
_value = value.toString()
|
| 10 |
+
.replace("\\t", "\t")
|
| 11 |
+
.replace("\\n", "\n");
|
| 12 |
+
}
|
| 13 |
+
else {
|
| 14 |
+
_value = value;
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
void ValueNode::printNode(int level)
|
| 19 |
+
{
|
| 20 |
+
treeStream << QString().fill(' ',level*2)
|
| 21 |
+
<< QString("Value: %1, type: %2\n").arg(_value.toString())
|
| 22 |
+
.arg(typeName.at(_typeValue));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
QString ValueNode::printTripleCode()
|
| 26 |
+
{
|
| 27 |
+
if(getValueType() == typeString) {
|
| 28 |
+
QString value = _value.toString();
|
| 29 |
+
QString result = "";
|
| 30 |
+
int i;
|
| 31 |
+
for(i = 0; i < _value.toByteArray().length(); i++) {
|
| 32 |
+
wchar_t c = value.toStdString().at(i);
|
| 33 |
+
if(c > 0x00ff || c < 0x000f){
|
| 34 |
+
|
| 35 |
+
result.append(QString("\\%1")
|
| 36 |
+
.arg(value.toStdString().at(i), 2 , 16, QChar('0')));
|
| 37 |
+
}
|
| 38 |
+
else
|
| 39 |
+
result.append(c);
|
| 40 |
+
}
|
| 41 |
+
result.replace("ffffffffffffff","");
|
| 42 |
+
return ir.addUnnamedVariable(
|
| 43 |
+
QString("private unnamed_addr constant [%1 x i8] c\"%2\\00\"")
|
| 44 |
+
.arg(_value.toByteArray().length()+1)
|
| 45 |
+
.arg(result
|
| 46 |
+
/*.replace("\n","\\0A")
|
| 47 |
+
.replace("\t", "\\09")*/));
|
| 48 |
+
}
|
| 49 |
+
if(getValueType() == typeDouble || getValueType() == typeFloat)
|
| 50 |
+
return QString("%1").arg(_value.toDouble(), 0, 'e', 6);
|
| 51 |
+
|
| 52 |
+
return _value.toString();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
QVariant ValueNode::getValue()
|
| 56 |
+
{
|
| 57 |
+
return _value;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
ValueNode::~ValueNode()
|
| 61 |
+
{
|
| 62 |
+
|
| 63 |
+
}
|
pool/shard004/C++/0048531_crypter.cpp
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2009-2012 The Bitcoin Developers
|
| 2 |
+
// Copyright (c) 2011-2012 Harucoin Developers
|
| 3 |
+
// Distributed under the MIT/X11 software license, see the accompanying
|
| 4 |
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 5 |
+
|
| 6 |
+
#include <openssl/aes.h>
|
| 7 |
+
#include <openssl/evp.h>
|
| 8 |
+
#include <vector>
|
| 9 |
+
#include <string>
|
| 10 |
+
#ifdef WIN32
|
| 11 |
+
#include <windows.h>
|
| 12 |
+
#endif
|
| 13 |
+
|
| 14 |
+
#include "crypter.h"
|
| 15 |
+
|
| 16 |
+
bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector<unsigned char>& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
|
| 17 |
+
{
|
| 18 |
+
if (nRounds < 1 || chSalt.size() != WALLET_CRYPTO_SALT_SIZE)
|
| 19 |
+
return false;
|
| 20 |
+
|
| 21 |
+
// Try to keep the keydata out of swap (and be a bit over-careful to keep the IV that we don't even use out of swap)
|
| 22 |
+
// Note that this does nothing about suspend-to-disk (which will put all our key data on disk)
|
| 23 |
+
// Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process.
|
| 24 |
+
mlock(&chKey[0], sizeof chKey);
|
| 25 |
+
mlock(&chIV[0], sizeof chIV);
|
| 26 |
+
|
| 27 |
+
int i = 0;
|
| 28 |
+
if (nDerivationMethod == 0)
|
| 29 |
+
i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha512(), &chSalt[0],
|
| 30 |
+
(unsigned char *)&strKeyData[0], strKeyData.size(), nRounds, chKey, chIV);
|
| 31 |
+
|
| 32 |
+
if (i != (int)WALLET_CRYPTO_KEY_SIZE)
|
| 33 |
+
{
|
| 34 |
+
memset(&chKey, 0, sizeof chKey);
|
| 35 |
+
memset(&chIV, 0, sizeof chIV);
|
| 36 |
+
return false;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
fKeySet = true;
|
| 40 |
+
return true;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const std::vector<unsigned char>& chNewIV)
|
| 44 |
+
{
|
| 45 |
+
if (chNewKey.size() != WALLET_CRYPTO_KEY_SIZE || chNewIV.size() != WALLET_CRYPTO_KEY_SIZE)
|
| 46 |
+
return false;
|
| 47 |
+
|
| 48 |
+
// Try to keep the keydata out of swap
|
| 49 |
+
// Note that this does nothing about suspend-to-disk (which will put all our key data on disk)
|
| 50 |
+
// Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process.
|
| 51 |
+
mlock(&chKey[0], sizeof chKey);
|
| 52 |
+
mlock(&chIV[0], sizeof chIV);
|
| 53 |
+
|
| 54 |
+
memcpy(&chKey[0], &chNewKey[0], sizeof chKey);
|
| 55 |
+
memcpy(&chIV[0], &chNewIV[0], sizeof chIV);
|
| 56 |
+
|
| 57 |
+
fKeySet = true;
|
| 58 |
+
return true;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned char> &vchCiphertext)
|
| 62 |
+
{
|
| 63 |
+
if (!fKeySet)
|
| 64 |
+
return false;
|
| 65 |
+
|
| 66 |
+
// max ciphertext len for a n bytes of plaintext is
|
| 67 |
+
// n + AES_BLOCK_SIZE - 1 bytes
|
| 68 |
+
int nLen = vchPlaintext.size();
|
| 69 |
+
int nCLen = nLen + AES_BLOCK_SIZE, nFLen = 0;
|
| 70 |
+
vchCiphertext = std::vector<unsigned char> (nCLen);
|
| 71 |
+
|
| 72 |
+
EVP_CIPHER_CTX ctx;
|
| 73 |
+
|
| 74 |
+
bool fOk = true;
|
| 75 |
+
|
| 76 |
+
EVP_CIPHER_CTX_init(&ctx);
|
| 77 |
+
if (fOk) fOk = EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
|
| 78 |
+
if (fOk) fOk = EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen);
|
| 79 |
+
if (fOk) fOk = EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0])+nCLen, &nFLen);
|
| 80 |
+
EVP_CIPHER_CTX_cleanup(&ctx);
|
| 81 |
+
|
| 82 |
+
if (!fOk) return false;
|
| 83 |
+
|
| 84 |
+
vchCiphertext.resize(nCLen + nFLen);
|
| 85 |
+
return true;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext)
|
| 89 |
+
{
|
| 90 |
+
if (!fKeySet)
|
| 91 |
+
return false;
|
| 92 |
+
|
| 93 |
+
// plaintext will always be equal to or lesser than length of ciphertext
|
| 94 |
+
int nLen = vchCiphertext.size();
|
| 95 |
+
int nPLen = nLen, nFLen = 0;
|
| 96 |
+
|
| 97 |
+
vchPlaintext = CKeyingMaterial(nPLen);
|
| 98 |
+
|
| 99 |
+
EVP_CIPHER_CTX ctx;
|
| 100 |
+
|
| 101 |
+
bool fOk = true;
|
| 102 |
+
|
| 103 |
+
EVP_CIPHER_CTX_init(&ctx);
|
| 104 |
+
if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
|
| 105 |
+
if (fOk) fOk = EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
|
| 106 |
+
if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0])+nPLen, &nFLen);
|
| 107 |
+
EVP_CIPHER_CTX_cleanup(&ctx);
|
| 108 |
+
|
| 109 |
+
if (!fOk) return false;
|
| 110 |
+
|
| 111 |
+
vchPlaintext.resize(nPLen + nFLen);
|
| 112 |
+
return true;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
bool EncryptSecret(CKeyingMaterial& vMasterKey, const CSecret &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext)
|
| 117 |
+
{
|
| 118 |
+
CCrypter cKeyCrypter;
|
| 119 |
+
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE);
|
| 120 |
+
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE);
|
| 121 |
+
if(!cKeyCrypter.SetKey(vMasterKey, chIV))
|
| 122 |
+
return false;
|
| 123 |
+
return cKeyCrypter.Encrypt((CKeyingMaterial)vchPlaintext, vchCiphertext);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CSecret& vchPlaintext)
|
| 127 |
+
{
|
| 128 |
+
CCrypter cKeyCrypter;
|
| 129 |
+
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE);
|
| 130 |
+
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE);
|
| 131 |
+
if(!cKeyCrypter.SetKey(vMasterKey, chIV))
|
| 132 |
+
return false;
|
| 133 |
+
return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext));
|
| 134 |
+
}
|
pool/shard004/C++/0048555_AndroidJNIBridge.cc
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/******************************************************************************
|
| 2 |
+
* Copyright (c) 2014, AllSeen Alliance. All rights reserved.
|
| 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 <jni.h>
|
| 18 |
+
#include <string.h>
|
| 19 |
+
#include <alljoyn/BusAttachment.h>
|
| 20 |
+
#include <alljoyn/ProxyBusObject.h>
|
| 21 |
+
#include <alljoyn/DBusStd.h>
|
| 22 |
+
#include <alljoyn/AllJoynStd.h>
|
| 23 |
+
#include "MyEventCode.h"
|
| 24 |
+
|
| 25 |
+
/* Static data */
|
| 26 |
+
static MyEventCode* myEventCode = NULL;
|
| 27 |
+
|
| 28 |
+
#ifdef __cplusplus
|
| 29 |
+
extern "C" {
|
| 30 |
+
#endif
|
| 31 |
+
/*
|
| 32 |
+
* Class: org_allseen_sample_event_tester_BusHandler
|
| 33 |
+
* Method: initialize
|
| 34 |
+
* Signature: (Ljava/lang/String;)V
|
| 35 |
+
*/
|
| 36 |
+
JNIEXPORT void JNICALL Java_org_allseen_sample_event_tester_BusHandler_initialize(JNIEnv* env, jobject jobj, jstring packageNameStrObj) {
|
| 37 |
+
if (myEventCode == NULL) {
|
| 38 |
+
JavaVM* vm;
|
| 39 |
+
env->GetJavaVM(&vm);
|
| 40 |
+
jobject gjobj = env->NewGlobalRef(jobj);
|
| 41 |
+
myEventCode = new MyEventCode(vm, gjobj);
|
| 42 |
+
}
|
| 43 |
+
jboolean iscopy;
|
| 44 |
+
const char* packageNameStr = env->GetStringUTFChars(packageNameStrObj, &iscopy);
|
| 45 |
+
myEventCode->initialize(packageNameStr);
|
| 46 |
+
env->ReleaseStringUTFChars(packageNameStrObj, packageNameStr);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/*
|
| 50 |
+
* Class: org_allseen_sample_event_tester_BusHandler
|
| 51 |
+
* Method: dointrospection
|
| 52 |
+
* Signature: (Ljava/lang/String;Ljava/lang/String;I)Ljava/langString;
|
| 53 |
+
*/
|
| 54 |
+
JNIEXPORT jstring JNICALL Java_org_allseen_sample_event_tester_BusHandler_doIntrospection(JNIEnv* env, jobject jobj, jstring jname, jstring jpath, jint sessionId) {
|
| 55 |
+
jboolean iscopy;
|
| 56 |
+
jboolean iscopy2;
|
| 57 |
+
const char* sessionName = env->GetStringUTFChars(jname, &iscopy);
|
| 58 |
+
const char* path = env->GetStringUTFChars(jpath, &iscopy2);
|
| 59 |
+
char* xml = myEventCode->introspectWithDescriptions(sessionName, path, sessionId);
|
| 60 |
+
env->ReleaseStringUTFChars(jname, sessionName);
|
| 61 |
+
env->ReleaseStringUTFChars(jpath, path);
|
| 62 |
+
jstring ret = env->NewStringUTF(xml);
|
| 63 |
+
delete xml;
|
| 64 |
+
return ret;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
JNIEXPORT void JNICALL Java_org_allseen_sample_event_tester_BusHandler_introspectionDone(JNIEnv* env, jobject jobj, jint sessionId) {
|
| 68 |
+
myEventCode->leaveSession(sessionId);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
JNIEXPORT jboolean JNICALL Java_org_allseen_sample_event_tester_BusHandler_enableEvent(JNIEnv*env, jobject jobj,
|
| 73 |
+
//event
|
| 74 |
+
jstring jEUniqueName, jstring jEPath,
|
| 75 |
+
jstring jEIface, jstring jEMember, jstring jESig)
|
| 76 |
+
{
|
| 77 |
+
jboolean iscopy;
|
| 78 |
+
|
| 79 |
+
const char* eUniqueName = env->GetStringUTFChars(jEUniqueName, &iscopy);
|
| 80 |
+
const char* ePath = env->GetStringUTFChars(jEPath, &iscopy);
|
| 81 |
+
const char* eIface = env->GetStringUTFChars(jEIface, &iscopy);
|
| 82 |
+
const char* eMember = env->GetStringUTFChars(jEMember, &iscopy);
|
| 83 |
+
const char* eSig = env->GetStringUTFChars(jESig, &iscopy);
|
| 84 |
+
EventInfo* event = new EventInfo(eUniqueName, ePath, eIface, eMember, eSig);
|
| 85 |
+
|
| 86 |
+
LOGTHIS("enabling an event on %s::%s", eIface, eMember);
|
| 87 |
+
bool ret = myEventCode->enableEvent(event);
|
| 88 |
+
|
| 89 |
+
delete event;
|
| 90 |
+
|
| 91 |
+
env->ReleaseStringUTFChars(jEUniqueName, eUniqueName);
|
| 92 |
+
env->ReleaseStringUTFChars(jEPath, ePath);
|
| 93 |
+
env->ReleaseStringUTFChars(jEIface, eIface);
|
| 94 |
+
env->ReleaseStringUTFChars(jEMember, eMember);
|
| 95 |
+
env->ReleaseStringUTFChars(jESig, eSig);
|
| 96 |
+
|
| 97 |
+
return ret == true ? JNI_TRUE : JNI_FALSE;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
JNIEXPORT void JNICALL Java_org_allseen_sample_event_tester_BusHandler_callAction(JNIEnv*env, jobject jobj,
|
| 101 |
+
//action
|
| 102 |
+
jstring jAUniqueName, jstring jAPath,
|
| 103 |
+
jstring jAIface, jstring jAMember, jstring jASig)
|
| 104 |
+
{
|
| 105 |
+
jboolean iscopy;
|
| 106 |
+
|
| 107 |
+
const char* aUniqueName = env->GetStringUTFChars(jAUniqueName, &iscopy);
|
| 108 |
+
const char* aPath = env->GetStringUTFChars(jAPath, &iscopy);
|
| 109 |
+
const char* aIface = env->GetStringUTFChars(jAIface, &iscopy);
|
| 110 |
+
const char* aMember = env->GetStringUTFChars(jAMember, &iscopy);
|
| 111 |
+
const char* aSig = env->GetStringUTFChars(jASig, &iscopy);
|
| 112 |
+
ActionInfo* action = new ActionInfo(aUniqueName, aPath, aIface, aMember, aSig);
|
| 113 |
+
|
| 114 |
+
LOGTHIS("Calling an action on %s", aUniqueName);
|
| 115 |
+
myEventCode->callAction(action);
|
| 116 |
+
|
| 117 |
+
delete action;
|
| 118 |
+
|
| 119 |
+
env->ReleaseStringUTFChars(jAUniqueName, aUniqueName);
|
| 120 |
+
env->ReleaseStringUTFChars(jAPath, aPath);
|
| 121 |
+
env->ReleaseStringUTFChars(jAIface, aIface);
|
| 122 |
+
env->ReleaseStringUTFChars(jAMember, aMember);
|
| 123 |
+
env->ReleaseStringUTFChars(jASig, aSig);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/*
|
| 127 |
+
* Class: org_allseen_sample_event_tester_BusHandler
|
| 128 |
+
* Method: shutdown
|
| 129 |
+
* Signature: ()V
|
| 130 |
+
*/
|
| 131 |
+
JNIEXPORT void JNICALL Java_org_allseen_sample_event_tester_BusHandler_shutdown(JNIEnv* env, jobject jobj) {
|
| 132 |
+
// if(myEventCode)
|
| 133 |
+
// myEventCode->shutdown();
|
| 134 |
+
// delete MyEventCode;
|
| 135 |
+
// MyEventCode = NULL;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
#ifdef __cplusplus
|
| 139 |
+
}
|
| 140 |
+
#endif
|
| 141 |
+
|
pool/shard004/C++/0048558_containsintegerpoint1.cc
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Test Pointset_Powerset<PH>::contains_integer_point(),
|
| 2 |
+
Copyright (C) 2001-2009 Roberto Bagnara <bagnara@cs.unipr.it>
|
| 3 |
+
|
| 4 |
+
This file is part of the Parma Polyhedra Library (PPL).
|
| 5 |
+
|
| 6 |
+
The PPL is free software; you can redistribute it and/or modify it
|
| 7 |
+
under the terms of the GNU General Public License as published by the
|
| 8 |
+
Free Software Foundation; either version 3 of the License, or (at your
|
| 9 |
+
option) any later version.
|
| 10 |
+
|
| 11 |
+
The PPL is distributed in the hope that it will be useful, but WITHOUT
|
| 12 |
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 13 |
+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 14 |
+
for more details.
|
| 15 |
+
|
| 16 |
+
You should have received a copy of the GNU General Public License
|
| 17 |
+
along with this program; if not, write to the Free Software Foundation,
|
| 18 |
+
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
|
| 19 |
+
|
| 20 |
+
For the most up-to-date information see the Parma Polyhedra Library
|
| 21 |
+
site: http://www.cs.unipr.it/ppl/ . */
|
| 22 |
+
|
| 23 |
+
#include "ppl_test.hh"
|
| 24 |
+
|
| 25 |
+
namespace {
|
| 26 |
+
|
| 27 |
+
// Powerset of C polyhedra: contains_integer_point() returns false.
|
| 28 |
+
bool
|
| 29 |
+
test01() {
|
| 30 |
+
Variable x(0);
|
| 31 |
+
Variable y(1);
|
| 32 |
+
|
| 33 |
+
Pointset_Powerset<C_Polyhedron> ps(2);
|
| 34 |
+
Constraint_System cs;
|
| 35 |
+
cs.insert(x >= 0);
|
| 36 |
+
cs.insert(x <= 1);
|
| 37 |
+
cs.insert(4*y <= 3);
|
| 38 |
+
cs.insert(4*y >= 1);
|
| 39 |
+
|
| 40 |
+
ps.refine_with_constraints(cs);
|
| 41 |
+
|
| 42 |
+
bool contains = ps.contains_integer_point();
|
| 43 |
+
|
| 44 |
+
print_constraints(ps, "*** ps ***");
|
| 45 |
+
nout << "ps.contains_integer_point() == "
|
| 46 |
+
<< (contains ? "true" : "false") << endl;
|
| 47 |
+
|
| 48 |
+
return !contains;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
// Powerset of C polyhedra: contains_integer_point() returns true.
|
| 52 |
+
bool
|
| 53 |
+
test02() {
|
| 54 |
+
Variable x(0);
|
| 55 |
+
Variable y(1);
|
| 56 |
+
Variable z(2);
|
| 57 |
+
|
| 58 |
+
Pointset_Powerset<C_Polyhedron> ps(3);
|
| 59 |
+
Constraint_System cs;
|
| 60 |
+
cs.insert(x >= 0);
|
| 61 |
+
cs.insert(x <= 1);
|
| 62 |
+
cs.insert(4*z - 4*y >= 3);
|
| 63 |
+
|
| 64 |
+
ps.refine_with_constraints(cs);
|
| 65 |
+
|
| 66 |
+
print_constraints(ps, "*** ps ***");
|
| 67 |
+
|
| 68 |
+
bool contains = ps.contains_integer_point();
|
| 69 |
+
|
| 70 |
+
nout << "ps.contains_integer_point() == "
|
| 71 |
+
<< (contains ? "true" : "false") << endl;
|
| 72 |
+
|
| 73 |
+
return contains;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
// Empty 0-dimensional powerset of C polyhedra: contains_integer_point().
|
| 77 |
+
bool
|
| 78 |
+
test03() {
|
| 79 |
+
Pointset_Powerset<C_Polyhedron> ps(0, EMPTY);
|
| 80 |
+
|
| 81 |
+
print_constraints(ps, "*** ps ***");
|
| 82 |
+
|
| 83 |
+
bool contains = ps.contains_integer_point();
|
| 84 |
+
|
| 85 |
+
nout << "ps.contains_integer_point() == "
|
| 86 |
+
<< (contains ? "true" : "false") << endl;
|
| 87 |
+
|
| 88 |
+
return !contains;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// Universe 0-dimensional powerset of C polyhedra: contains_integer_point().
|
| 92 |
+
bool
|
| 93 |
+
test04() {
|
| 94 |
+
Pointset_Powerset<C_Polyhedron> ps(0);
|
| 95 |
+
|
| 96 |
+
bool contains = ps.contains_integer_point();
|
| 97 |
+
|
| 98 |
+
print_constraints(ps, "*** ps ***");
|
| 99 |
+
|
| 100 |
+
nout << "ps.contains_integer_point() == "
|
| 101 |
+
<< (contains ? "true" : "false") << endl;
|
| 102 |
+
|
| 103 |
+
return contains;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
// Empty 1-dimensional powerset of C polyhedra: contains_integer_point().
|
| 107 |
+
bool
|
| 108 |
+
test05() {
|
| 109 |
+
Pointset_Powerset<C_Polyhedron> ps(1);
|
| 110 |
+
|
| 111 |
+
ps.refine_with_constraint(Linear_Expression(0) == 1);
|
| 112 |
+
|
| 113 |
+
bool contains = ps.contains_integer_point();
|
| 114 |
+
|
| 115 |
+
print_constraints(ps, "*** ps ***");
|
| 116 |
+
|
| 117 |
+
nout << "ps.contains_integer_point() == "
|
| 118 |
+
<< (contains ? "true" : "false") << endl;
|
| 119 |
+
|
| 120 |
+
return !contains;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
} // namespace
|
| 124 |
+
|
| 125 |
+
BEGIN_MAIN
|
| 126 |
+
DO_TEST(test01);
|
| 127 |
+
DO_TEST(test02);
|
| 128 |
+
DO_TEST(test03);
|
| 129 |
+
DO_TEST(test04);
|
| 130 |
+
DO_TEST(test05);
|
| 131 |
+
END_MAIN
|
pool/shard004/C++/0048564_MayaPlugin.cpp
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// UVAutoRatio Maya Plugin Source Code
|
| 3 |
+
// Copyright (C) 2007-2014 RenderHeads Ltd.
|
| 4 |
+
//
|
| 5 |
+
// This source is available for distribution and/or modification
|
| 6 |
+
// only under the terms of the MIT license. All rights reserved.
|
| 7 |
+
//
|
| 8 |
+
// The source is distributed in the hope that it will be useful,
|
| 9 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 10 |
+
// FITNESS FOR A PARTICULAR PURPOSE. See the MIT license
|
| 11 |
+
// for more details.
|
| 12 |
+
//
|
| 13 |
+
|
| 14 |
+
#include "MayaPCH.h"
|
| 15 |
+
#include "MayaUtility.h"
|
| 16 |
+
#include "MayaPlugin.h"
|
| 17 |
+
|
| 18 |
+
MayaPlugin::MayaPlugin(const MayaPluginParams& params)
|
| 19 |
+
{
|
| 20 |
+
m_productName = params.productName;
|
| 21 |
+
m_productShortName = params.productShortName;
|
| 22 |
+
m_authorString = params.authorString;
|
| 23 |
+
m_versionString = params.versionString;
|
| 24 |
+
|
| 25 |
+
#ifdef _DEBUG
|
| 26 |
+
MGlobal::startErrorLogging();
|
| 27 |
+
#endif
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
MayaPlugin::~MayaPlugin()
|
| 31 |
+
{
|
| 32 |
+
#ifdef _DEBUG
|
| 33 |
+
MGlobal::stopErrorLogging();
|
| 34 |
+
MGlobal::closeErrorLog();
|
| 35 |
+
#endif
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
void
|
| 39 |
+
MayaPlugin::Load(MObject& pluginObject)
|
| 40 |
+
{
|
| 41 |
+
char finalVersionStr[256];
|
| 42 |
+
#ifdef WIN32
|
| 43 |
+
sprintf_s(finalVersionStr, sizeof(finalVersionStr), "%s, %s @ %s", m_versionString.asChar(), __DATE__, __TIME__);
|
| 44 |
+
#else
|
| 45 |
+
sprintf(finalVersionStr, "%s, | %s @ %s", m_versionString.asChar(), __DATE__, __TIME__);
|
| 46 |
+
#endif
|
| 47 |
+
|
| 48 |
+
MFnPlugin plugin(pluginObject, m_authorString.asChar(), finalVersionStr, "Any");
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
LoadFeatures(plugin);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
void
|
| 55 |
+
MayaPlugin::Unload(MObject& pluginObject)
|
| 56 |
+
{
|
| 57 |
+
MStatus status;
|
| 58 |
+
MFnPlugin plugin(pluginObject);
|
| 59 |
+
|
| 60 |
+
UnloadUserPlugins(plugin);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
void
|
| 64 |
+
MayaPlugin::LoadFeatures(MFnPlugin& plugin)
|
| 65 |
+
{
|
| 66 |
+
LoadUserPlugins(plugin);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
void
|
| 70 |
+
MayaPlugin::DisplayInfo(const MString& text) const
|
| 71 |
+
{
|
| 72 |
+
MGlobal::displayInfo(m_productShortName + ": " + text);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
void
|
| 76 |
+
MayaPlugin::DisplayWarning(const MString& text) const
|
| 77 |
+
{
|
| 78 |
+
MGlobal::displayWarning(m_productShortName + ": " + text);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
///////////////////////////////////////////////////////////////////////////////
|
| 82 |
+
///////////////////////////////////////////////////////////////////////////////
|
pool/shard004/C++/0048565_demo_ballDEM.cpp
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// PROJECT CHRONO - http://projectchrono.org
|
| 3 |
+
//
|
| 4 |
+
// Copyright (c) 2013 Project Chrono
|
| 5 |
+
// All rights reserved.
|
| 6 |
+
//
|
| 7 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 8 |
+
// found in the LICENSE file at the top level of the distribution
|
| 9 |
+
// and at http://projectchrono.org/license-chrono.txt.
|
| 10 |
+
//
|
| 11 |
+
|
| 12 |
+
///////////////////////////////////////////////////
|
| 13 |
+
//
|
| 14 |
+
// Demo code about
|
| 15 |
+
//
|
| 16 |
+
// - collisions and contacts with DEM
|
| 17 |
+
//
|
| 18 |
+
// CHRONO
|
| 19 |
+
// ------
|
| 20 |
+
// Multibody dinamics engine
|
| 21 |
+
//
|
| 22 |
+
///////////////////////////////////////////////////
|
| 23 |
+
|
| 24 |
+
#include "chrono/physics/ChSystemDEM.h"
|
| 25 |
+
#include "chrono/physics/ChContactContainerDEM.h"
|
| 26 |
+
#include "chrono/lcp/ChLcpSolverDEM.h"
|
| 27 |
+
|
| 28 |
+
#include "chrono_irrlicht/ChIrrApp.h"
|
| 29 |
+
|
| 30 |
+
#include <irrlicht.h>
|
| 31 |
+
|
| 32 |
+
// Use the namespaces of Chrono
|
| 33 |
+
using namespace chrono;
|
| 34 |
+
using namespace chrono::irrlicht;
|
| 35 |
+
|
| 36 |
+
// Use the main namespaces of Irrlicht
|
| 37 |
+
using namespace irr;
|
| 38 |
+
using namespace irr::core;
|
| 39 |
+
using namespace irr::scene;
|
| 40 |
+
using namespace irr::video;
|
| 41 |
+
using namespace irr::io;
|
| 42 |
+
using namespace irr::gui;
|
| 43 |
+
|
| 44 |
+
void AddWall(ChSharedPtr<ChBody> body, const ChVector<>& dim, const ChVector<>& loc) {
|
| 45 |
+
body->GetCollisionModel()->AddBox(dim.x, dim.y, dim.z, loc);
|
| 46 |
+
|
| 47 |
+
ChSharedPtr<ChBoxShape> box(new ChBoxShape);
|
| 48 |
+
box->GetBoxGeometry().Size = dim;
|
| 49 |
+
box->GetBoxGeometry().Pos = loc;
|
| 50 |
+
box->SetColor(ChColor(1, 0, 0));
|
| 51 |
+
box->SetFading(0.6f);
|
| 52 |
+
body->AddAsset(box);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
int main(int argc, char* argv[]) {
|
| 56 |
+
// Simulation parameters
|
| 57 |
+
double gravity = -9.81;
|
| 58 |
+
double time_step = 0.00001;
|
| 59 |
+
double out_step = 2000 * time_step;
|
| 60 |
+
|
| 61 |
+
// Parameters for the falling ball
|
| 62 |
+
int ballId = 100;
|
| 63 |
+
double radius = 1;
|
| 64 |
+
double mass = 1000;
|
| 65 |
+
ChVector<> pos(0, 2, 0);
|
| 66 |
+
ChQuaternion<> rot(1, 0, 0, 0);
|
| 67 |
+
ChVector<> init_vel(0, 0, 0);
|
| 68 |
+
|
| 69 |
+
// Parameters for the containing bin
|
| 70 |
+
int binId = 200;
|
| 71 |
+
double width = 2;
|
| 72 |
+
double length = 2;
|
| 73 |
+
double height = 1;
|
| 74 |
+
double thickness = 0.1;
|
| 75 |
+
|
| 76 |
+
// Create the system
|
| 77 |
+
ChSystemDEM msystem;
|
| 78 |
+
|
| 79 |
+
// The following two lines are optional, since they are the default options. They are added for future reference,
|
| 80 |
+
// i.e. when needed to change those models.
|
| 81 |
+
msystem.SetContactForceModel(ChSystemDEM::ContactForceModel::Hertz);
|
| 82 |
+
msystem.SetAdhesionForceModel(ChSystemDEM::AdhesionForceModel::Constant);
|
| 83 |
+
|
| 84 |
+
msystem.Set_G_acc(ChVector<>(0, gravity, 0));
|
| 85 |
+
|
| 86 |
+
// Create the Irrlicht visualization
|
| 87 |
+
ChIrrApp application(&msystem, L"DEM demo", core::dimension2d<u32>(800, 600), false, true);
|
| 88 |
+
|
| 89 |
+
// Easy shortcuts to add camera, lights, logo and sky in Irrlicht scene
|
| 90 |
+
application.AddTypicalLogo();
|
| 91 |
+
application.AddTypicalSky();
|
| 92 |
+
application.AddTypicalLights();
|
| 93 |
+
application.AddTypicalCamera(core::vector3df(0, 3, -6));
|
| 94 |
+
|
| 95 |
+
// This means that contactforces will be shown in Irrlicht application
|
| 96 |
+
application.SetSymbolscale(1e-4);
|
| 97 |
+
application.SetContactsDrawMode(ChIrrTools::eCh_ContactsDrawMode::CONTACT_FORCES);
|
| 98 |
+
|
| 99 |
+
// Create a material (will be used by both objects)
|
| 100 |
+
ChSharedPtr<ChMaterialSurfaceDEM> material;
|
| 101 |
+
material = ChSharedPtr<ChMaterialSurfaceDEM>(new ChMaterialSurfaceDEM);
|
| 102 |
+
material->SetRestitution(0.1f);
|
| 103 |
+
material->SetFriction(0.4f);
|
| 104 |
+
material->SetAdhesion(0); // Magnitude of the adhesion in Constant adhesion model
|
| 105 |
+
|
| 106 |
+
// Create the falling ball
|
| 107 |
+
ChSharedPtr<ChBody> ball(new ChBody(ChMaterialSurfaceBase::DEM));
|
| 108 |
+
|
| 109 |
+
ball->SetIdentifier(ballId);
|
| 110 |
+
ball->SetMass(mass);
|
| 111 |
+
ball->SetPos(pos);
|
| 112 |
+
ball->SetRot(rot);
|
| 113 |
+
ball->SetPos_dt(init_vel);
|
| 114 |
+
// ball->SetWvel_par(ChVector<>(0,0,3));
|
| 115 |
+
ball->SetBodyFixed(false);
|
| 116 |
+
ball->SetMaterialSurface(material);
|
| 117 |
+
|
| 118 |
+
ball->SetCollide(true);
|
| 119 |
+
|
| 120 |
+
ball->GetCollisionModel()->ClearModel();
|
| 121 |
+
ball->GetCollisionModel()->AddSphere(radius);
|
| 122 |
+
ball->GetCollisionModel()->BuildModel();
|
| 123 |
+
|
| 124 |
+
ball->SetInertiaXX(0.4 * mass * radius * radius * ChVector<>(1, 1, 1));
|
| 125 |
+
|
| 126 |
+
ChSharedPtr<ChSphereShape> sphere(new ChSphereShape);
|
| 127 |
+
sphere->GetSphereGeometry().rad = radius;
|
| 128 |
+
ball->AddAsset(sphere);
|
| 129 |
+
|
| 130 |
+
ChSharedPtr<ChTexture> mtexture(new ChTexture);
|
| 131 |
+
mtexture->SetTextureFilename(GetChronoDataFile("bluwhite.png"));
|
| 132 |
+
ball->AddAsset(mtexture);
|
| 133 |
+
|
| 134 |
+
msystem.AddBody(ball);
|
| 135 |
+
|
| 136 |
+
// Create container
|
| 137 |
+
ChSharedPtr<ChBody> bin(new ChBody(ChMaterialSurfaceBase::DEM));
|
| 138 |
+
|
| 139 |
+
bin->SetIdentifier(binId);
|
| 140 |
+
bin->SetMass(1);
|
| 141 |
+
bin->SetPos(ChVector<>(0, 0, 0));
|
| 142 |
+
bin->SetRot(ChQuaternion<>(1, 0, 0, 0));
|
| 143 |
+
bin->SetCollide(true);
|
| 144 |
+
bin->SetBodyFixed(true);
|
| 145 |
+
bin->SetMaterialSurface(material);
|
| 146 |
+
|
| 147 |
+
bin->GetCollisionModel()->ClearModel();
|
| 148 |
+
AddWall(bin, ChVector<>(width, thickness, length), ChVector<>(0, 0, 0));
|
| 149 |
+
// AddWall(bin, ChVector<>(thickness, height, length), ChVector<>(-width + thickness, height, 0));
|
| 150 |
+
// AddWall(bin, ChVector<>(thickness, height, length), ChVector<>(width - thickness, height, 0));
|
| 151 |
+
// AddWall(bin, ChVector<>(width, height, thickness), ChVector<>(0, height, -length + thickness));
|
| 152 |
+
// AddWall(bin, ChVector<>(width, height, thickness), ChVector<>(0, height, length - thickness));
|
| 153 |
+
bin->GetCollisionModel()->BuildModel();
|
| 154 |
+
|
| 155 |
+
msystem.AddBody(bin);
|
| 156 |
+
|
| 157 |
+
// Complete asset construction
|
| 158 |
+
application.AssetBindAll();
|
| 159 |
+
application.AssetUpdateAll();
|
| 160 |
+
|
| 161 |
+
// The soft-real-time cycle
|
| 162 |
+
double time = 0.0;
|
| 163 |
+
double out_time = 0.0;
|
| 164 |
+
|
| 165 |
+
while (application.GetDevice()->run()) {
|
| 166 |
+
application.BeginScene();
|
| 167 |
+
|
| 168 |
+
application.DrawAll();
|
| 169 |
+
|
| 170 |
+
ChIrrTools::drawGrid(application.GetVideoDriver(), 0.2, 0.2, 20, 20,
|
| 171 |
+
ChCoordsys<>(ChVector<>(0, 0, 0), Q_from_AngX(CH_C_PI_2)),
|
| 172 |
+
video::SColor(255, 80, 100, 100), true);
|
| 173 |
+
|
| 174 |
+
while (time < out_time) {
|
| 175 |
+
msystem.DoStepDynamics(time_step);
|
| 176 |
+
time += time_step;
|
| 177 |
+
}
|
| 178 |
+
out_time += out_step;
|
| 179 |
+
|
| 180 |
+
application.EndScene();
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
return 0;
|
| 184 |
+
}
|
pool/shard004/C++/0048580_signals_unittest.cc
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 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 "build/build_config.h"
|
| 6 |
+
#include "mojo/core/test/mojo_test_base.h"
|
| 7 |
+
#include "mojo/public/c/system/buffer.h"
|
| 8 |
+
#include "mojo/public/c/system/data_pipe.h"
|
| 9 |
+
#include "mojo/public/c/system/functions.h"
|
| 10 |
+
#include "mojo/public/c/system/message_pipe.h"
|
| 11 |
+
#include "mojo/public/c/system/trap.h"
|
| 12 |
+
#include "mojo/public/c/system/types.h"
|
| 13 |
+
|
| 14 |
+
namespace mojo {
|
| 15 |
+
namespace core {
|
| 16 |
+
namespace {
|
| 17 |
+
|
| 18 |
+
using SignalsTest = test::MojoTestBase;
|
| 19 |
+
|
| 20 |
+
TEST_F(SignalsTest, QueryInvalidArguments) {
|
| 21 |
+
MojoHandleSignalsState state = {0, 0};
|
| 22 |
+
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
|
| 23 |
+
MojoQueryHandleSignalsState(MOJO_HANDLE_INVALID, &state));
|
| 24 |
+
|
| 25 |
+
MojoHandle a, b;
|
| 26 |
+
CreateMessagePipe(&a, &b);
|
| 27 |
+
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
|
| 28 |
+
MojoQueryHandleSignalsState(a, nullptr));
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
TEST_F(SignalsTest, QueryMessagePipeSignals) {
|
| 32 |
+
MojoHandleSignalsState state = {0, 0};
|
| 33 |
+
|
| 34 |
+
MojoHandle a, b;
|
| 35 |
+
CreateMessagePipe(&a, &b);
|
| 36 |
+
|
| 37 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(a, &state));
|
| 38 |
+
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, state.satisfied_signals);
|
| 39 |
+
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE |
|
| 40 |
+
MOJO_HANDLE_SIGNAL_PEER_CLOSED |
|
| 41 |
+
MOJO_HANDLE_SIGNAL_PEER_REMOTE |
|
| 42 |
+
MOJO_HANDLE_SIGNAL_QUOTA_EXCEEDED,
|
| 43 |
+
state.satisfiable_signals);
|
| 44 |
+
|
| 45 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(b, &state));
|
| 46 |
+
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, state.satisfied_signals);
|
| 47 |
+
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE |
|
| 48 |
+
MOJO_HANDLE_SIGNAL_PEER_CLOSED |
|
| 49 |
+
MOJO_HANDLE_SIGNAL_PEER_REMOTE |
|
| 50 |
+
MOJO_HANDLE_SIGNAL_QUOTA_EXCEEDED,
|
| 51 |
+
state.satisfiable_signals);
|
| 52 |
+
|
| 53 |
+
WriteMessage(a, "ok");
|
| 54 |
+
EXPECT_EQ(MOJO_RESULT_OK, WaitForSignals(b, MOJO_HANDLE_SIGNAL_READABLE));
|
| 55 |
+
|
| 56 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(b, &state));
|
| 57 |
+
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
|
| 58 |
+
state.satisfied_signals);
|
| 59 |
+
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE |
|
| 60 |
+
MOJO_HANDLE_SIGNAL_PEER_CLOSED |
|
| 61 |
+
MOJO_HANDLE_SIGNAL_PEER_REMOTE |
|
| 62 |
+
MOJO_HANDLE_SIGNAL_QUOTA_EXCEEDED,
|
| 63 |
+
state.satisfiable_signals);
|
| 64 |
+
|
| 65 |
+
EXPECT_EQ("ok", ReadMessage(b));
|
| 66 |
+
|
| 67 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(b, &state));
|
| 68 |
+
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, state.satisfied_signals);
|
| 69 |
+
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE |
|
| 70 |
+
MOJO_HANDLE_SIGNAL_PEER_CLOSED |
|
| 71 |
+
MOJO_HANDLE_SIGNAL_PEER_REMOTE |
|
| 72 |
+
MOJO_HANDLE_SIGNAL_QUOTA_EXCEEDED,
|
| 73 |
+
state.satisfiable_signals);
|
| 74 |
+
|
| 75 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(a));
|
| 76 |
+
|
| 77 |
+
EXPECT_EQ(MOJO_RESULT_OK, WaitForSignals(b, MOJO_HANDLE_SIGNAL_PEER_CLOSED));
|
| 78 |
+
|
| 79 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(b, &state));
|
| 80 |
+
EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfied_signals);
|
| 81 |
+
EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED | MOJO_HANDLE_SIGNAL_QUOTA_EXCEEDED,
|
| 82 |
+
state.satisfiable_signals);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
TEST_F(SignalsTest, LocalPeers) {
|
| 86 |
+
MojoHandleSignalsState state = {0, 0};
|
| 87 |
+
MojoHandle a, b, c, d;
|
| 88 |
+
CreateMessagePipe(&a, &b);
|
| 89 |
+
CreateMessagePipe(&c, &d);
|
| 90 |
+
|
| 91 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(a, &state));
|
| 92 |
+
EXPECT_TRUE(state.satisfiable_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 93 |
+
EXPECT_FALSE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 94 |
+
|
| 95 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(b, &state));
|
| 96 |
+
EXPECT_TRUE(state.satisfiable_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 97 |
+
EXPECT_FALSE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 98 |
+
|
| 99 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(c, &state));
|
| 100 |
+
EXPECT_TRUE(state.satisfiable_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 101 |
+
EXPECT_FALSE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 102 |
+
|
| 103 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(d, &state));
|
| 104 |
+
EXPECT_TRUE(state.satisfiable_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 105 |
+
EXPECT_FALSE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 106 |
+
|
| 107 |
+
// Verify that sending a local pipe over a local pipe doesn't change the
|
| 108 |
+
// perceived locality of the peer.
|
| 109 |
+
const char kMessage[] = "ayyy";
|
| 110 |
+
WriteMessageWithHandles(a, kMessage, &c, 1);
|
| 111 |
+
EXPECT_EQ(kMessage, ReadMessageWithHandles(b, &c, 1));
|
| 112 |
+
|
| 113 |
+
WriteMessage(c, kMessage);
|
| 114 |
+
EXPECT_EQ(kMessage, ReadMessage(d));
|
| 115 |
+
|
| 116 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(c, &state));
|
| 117 |
+
EXPECT_TRUE(state.satisfiable_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 118 |
+
EXPECT_FALSE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 119 |
+
|
| 120 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(d, &state));
|
| 121 |
+
EXPECT_TRUE(state.satisfiable_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 122 |
+
EXPECT_FALSE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 123 |
+
|
| 124 |
+
// Sanity check: a closed peer can never signal remoteness.
|
| 125 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(c));
|
| 126 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(d, &state));
|
| 127 |
+
EXPECT_FALSE(state.satisfiable_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 128 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(d));
|
| 129 |
+
|
| 130 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(a));
|
| 131 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(b));
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
#if !BUILDFLAG(IS_IOS)
|
| 135 |
+
|
| 136 |
+
TEST_F(SignalsTest, RemotePeers) {
|
| 137 |
+
MojoHandleSignalsState state = {0, 0};
|
| 138 |
+
MojoHandle a, b;
|
| 139 |
+
CreateMessagePipe(&a, &b);
|
| 140 |
+
|
| 141 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(a, &state));
|
| 142 |
+
EXPECT_TRUE(state.satisfiable_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 143 |
+
EXPECT_FALSE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 144 |
+
EXPECT_EQ(MOJO_RESULT_OK,
|
| 145 |
+
WaitForSignals(a, MOJO_HANDLE_SIGNAL_PEER_REMOTE,
|
| 146 |
+
MOJO_TRIGGER_CONDITION_SIGNALS_UNSATISFIED));
|
| 147 |
+
|
| 148 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(b, &state));
|
| 149 |
+
EXPECT_TRUE(state.satisfiable_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 150 |
+
EXPECT_FALSE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 151 |
+
EXPECT_EQ(MOJO_RESULT_OK,
|
| 152 |
+
WaitForSignals(b, MOJO_HANDLE_SIGNAL_PEER_REMOTE,
|
| 153 |
+
MOJO_TRIGGER_CONDITION_SIGNALS_UNSATISFIED));
|
| 154 |
+
|
| 155 |
+
RunTestClient("RemotePeersClient", [&](MojoHandle h) {
|
| 156 |
+
// The bootstrap pipe should eventually signal remoteness.
|
| 157 |
+
EXPECT_EQ(MOJO_RESULT_OK,
|
| 158 |
+
WaitForSignals(h, MOJO_HANDLE_SIGNAL_PEER_REMOTE,
|
| 159 |
+
MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED));
|
| 160 |
+
|
| 161 |
+
// And so should |a| after we send its peer.
|
| 162 |
+
WriteMessageWithHandles(h, ":)", &b, 1);
|
| 163 |
+
EXPECT_EQ(MOJO_RESULT_OK,
|
| 164 |
+
WaitForSignals(a, MOJO_HANDLE_SIGNAL_PEER_REMOTE,
|
| 165 |
+
MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED));
|
| 166 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(a, &state));
|
| 167 |
+
EXPECT_TRUE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 168 |
+
|
| 169 |
+
// And so should |c| after we fuse |d| to |a|.
|
| 170 |
+
MojoHandle c, d;
|
| 171 |
+
CreateMessagePipe(&c, &d);
|
| 172 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoFuseMessagePipes(d, a, nullptr));
|
| 173 |
+
EXPECT_EQ(MOJO_RESULT_OK,
|
| 174 |
+
WaitForSignals(c, MOJO_HANDLE_SIGNAL_PEER_REMOTE,
|
| 175 |
+
MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED));
|
| 176 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(c, &state));
|
| 177 |
+
EXPECT_TRUE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 178 |
+
|
| 179 |
+
// We fused c-d to a-b, so we'll just sort of "rename" |c| back to |a| so
|
| 180 |
+
// the system resembles the state it was in before we did that.
|
| 181 |
+
a = c;
|
| 182 |
+
|
| 183 |
+
WriteMessage(h, "OK!");
|
| 184 |
+
|
| 185 |
+
// Read |b| back before joining the client.
|
| 186 |
+
EXPECT_EQ("O_O", ReadMessageWithHandles(h, &b, 1));
|
| 187 |
+
|
| 188 |
+
// Wait for |a| to see its peer as local again.
|
| 189 |
+
EXPECT_EQ(MOJO_RESULT_OK,
|
| 190 |
+
WaitForSignals(a, MOJO_HANDLE_SIGNAL_PEER_REMOTE,
|
| 191 |
+
MOJO_TRIGGER_CONDITION_SIGNALS_UNSATISFIED));
|
| 192 |
+
EXPECT_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(a, &state));
|
| 193 |
+
EXPECT_FALSE(state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_REMOTE);
|
| 194 |
+
});
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
DEFINE_TEST_CLIENT_TEST_WITH_PIPE(RemotePeersClient, SignalsTest, h) {
|
| 198 |
+
// The bootstrap pipe should eventually signal remoteness.
|
| 199 |
+
EXPECT_EQ(MOJO_RESULT_OK,
|
| 200 |
+
WaitForSignals(h, MOJO_HANDLE_SIGNAL_PEER_REMOTE,
|
| 201 |
+
MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED));
|
| 202 |
+
|
| 203 |
+
MojoHandle b;
|
| 204 |
+
EXPECT_EQ(":)", ReadMessageWithHandles(h, &b, 1));
|
| 205 |
+
|
| 206 |
+
// And so should |b|.
|
| 207 |
+
EXPECT_EQ(MOJO_RESULT_OK,
|
| 208 |
+
WaitForSignals(b, MOJO_HANDLE_SIGNAL_PEER_REMOTE,
|
| 209 |
+
MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED));
|
| 210 |
+
|
| 211 |
+
// Wait for the test to signal that it's ready to read |b| back.
|
| 212 |
+
EXPECT_EQ("OK!", ReadMessage(h));
|
| 213 |
+
|
| 214 |
+
// Now send |b| back home.
|
| 215 |
+
WriteMessageWithHandles(h, "O_O", &b, 1);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
#endif // !BUILDFLAG(IS_IOS)
|
| 219 |
+
|
| 220 |
+
} // namespace
|
| 221 |
+
} // namespace core
|
| 222 |
+
} // namespace mojo
|
pool/shard004/C++/0048581_fpcoptionsplugin.cpp
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
* Copyright (C) 2003 Alexander Dymo *
|
| 3 |
+
* cloudtemple@mksat.net *
|
| 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 |
+
***************************************************************************/
|
| 11 |
+
#include <qvbox.h>
|
| 12 |
+
|
| 13 |
+
#include <klocale.h>
|
| 14 |
+
#include <kgenericfactory.h>
|
| 15 |
+
|
| 16 |
+
#include "optiontabs.h"
|
| 17 |
+
#include "fpcoptionsplugin.h"
|
| 18 |
+
|
| 19 |
+
K_EXPORT_COMPONENT_FACTORY( libkdevfpcoptions, KGenericFactory<FpcOptionsPlugin>( "kdevfpcoptions" ) )
|
| 20 |
+
|
| 21 |
+
FpcOptionsPlugin::FpcOptionsPlugin(QObject *parent, const char *name, const QStringList& /*args*/)
|
| 22 |
+
: KDevCompilerOptions(parent, name)
|
| 23 |
+
{
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
FpcOptionsPlugin::~FpcOptionsPlugin()
|
| 27 |
+
{
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
QString FpcOptionsPlugin::exec(QWidget *parent, const QString &flags)
|
| 31 |
+
{
|
| 32 |
+
FpcOptionsDialog *dlg = new FpcOptionsDialog(parent, "fpc options dialog");
|
| 33 |
+
QString newFlags = flags;
|
| 34 |
+
dlg->setFlags(flags);
|
| 35 |
+
if (dlg->exec() == QDialog::Accepted)
|
| 36 |
+
newFlags = dlg->flags();
|
| 37 |
+
delete dlg;
|
| 38 |
+
return newFlags;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
FpcOptionsDialog::FpcOptionsDialog( QWidget *parent, const char *name )
|
| 44 |
+
: KDialogBase(Tabbed, i18n("Free Pascal Compiler Options"), Ok|Cancel, Ok, parent, name, true)
|
| 45 |
+
{
|
| 46 |
+
QVBox *vbox;
|
| 47 |
+
|
| 48 |
+
vbox = addVBoxPage(i18n("Language"));
|
| 49 |
+
language = new LanguageTab(vbox, "language tab");
|
| 50 |
+
|
| 51 |
+
vbox = addVBoxPage(i18n("Locations I"));
|
| 52 |
+
directories = new FilesAndDirectoriesTab(vbox, "directories tab");
|
| 53 |
+
|
| 54 |
+
vbox = addVBoxPage(i18n("Locations II"));
|
| 55 |
+
directories2 = new FilesAndDirectoriesTab2(vbox, "directories2 tab");
|
| 56 |
+
|
| 57 |
+
vbox = addVBoxPage(i18n("Debug && Optimization"));
|
| 58 |
+
debug_optim = new DebugOptimTab(vbox, "debug_optim tab");
|
| 59 |
+
|
| 60 |
+
vbox = addVBoxPage(i18n("Code Generation"));
|
| 61 |
+
codegen = new CodegenTab(vbox, "codegen tab");
|
| 62 |
+
|
| 63 |
+
vbox = addVBoxPage(i18n("Assembler"));
|
| 64 |
+
assembler = new AssemblerTab(vbox, "assembler tab");
|
| 65 |
+
|
| 66 |
+
vbox = addVBoxPage(i18n("Linker"));
|
| 67 |
+
linker = new LinkerTab(vbox, "linker tab");
|
| 68 |
+
|
| 69 |
+
vbox = addVBoxPage(i18n("Feedback"));
|
| 70 |
+
feedback = new FeedbackTab(vbox, "feedback tab");
|
| 71 |
+
|
| 72 |
+
vbox = addVBoxPage(i18n("Miscellaneous"));
|
| 73 |
+
misc = new MiscTab(vbox, "miscellaneous tab");
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
FpcOptionsDialog::~FpcOptionsDialog()
|
| 77 |
+
{
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
void FpcOptionsDialog::setFlags(const QString &flags)
|
| 81 |
+
{
|
| 82 |
+
QStringList flaglist = QStringList::split(" ", flags);
|
| 83 |
+
|
| 84 |
+
feedback->readFlags(&flaglist);
|
| 85 |
+
language->readFlags(&flaglist);
|
| 86 |
+
assembler->readFlags(&flaglist);
|
| 87 |
+
linker->readFlags(&flaglist);
|
| 88 |
+
codegen->readFlags(&flaglist);
|
| 89 |
+
debug_optim->readFlags(&flaglist);
|
| 90 |
+
directories->readFlags(&flaglist);
|
| 91 |
+
directories2->readFlags(&flaglist);
|
| 92 |
+
misc->readFlags(&flaglist);
|
| 93 |
+
unrecognizedFlags = flaglist;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
QString FpcOptionsDialog::flags() const
|
| 97 |
+
{
|
| 98 |
+
QStringList flaglist;
|
| 99 |
+
|
| 100 |
+
language->writeFlags(&flaglist);
|
| 101 |
+
directories->writeFlags(&flaglist);
|
| 102 |
+
directories2->writeFlags(&flaglist);
|
| 103 |
+
debug_optim->writeFlags(&flaglist);
|
| 104 |
+
codegen->writeFlags(&flaglist);
|
| 105 |
+
assembler->writeFlags(&flaglist);
|
| 106 |
+
linker->writeFlags(&flaglist);
|
| 107 |
+
feedback->writeFlags(&flaglist);
|
| 108 |
+
misc->writeFlags(&flaglist);
|
| 109 |
+
|
| 110 |
+
QString flags;
|
| 111 |
+
QStringList::ConstIterator li;
|
| 112 |
+
for (li = flaglist.begin(); li != flaglist.end(); ++li) {
|
| 113 |
+
flags += (*li);
|
| 114 |
+
flags += " ";
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
for (li = unrecognizedFlags.begin(); li != unrecognizedFlags.end(); ++li) {
|
| 118 |
+
flags += (*li);
|
| 119 |
+
flags += " ";
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
flags.truncate(flags.length()-1);
|
| 123 |
+
return flags;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
#include "fpcoptionsplugin.moc"
|
pool/shard004/C++/0048582_main.cpp
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// main.cpp
|
| 3 |
+
// c-steg
|
| 4 |
+
//
|
| 5 |
+
|
| 6 |
+
#include "CStegApi.h"
|
| 7 |
+
#include <string.h>
|
| 8 |
+
#include <iostream>
|
| 9 |
+
|
| 10 |
+
void print_help() {
|
| 11 |
+
std::cout << "this is the c-steg command line utility" << std::endl
|
| 12 |
+
<< std::endl;
|
| 13 |
+
|
| 14 |
+
std::cout << "\tto encode a lossless jpeg image with text" << std::endl;
|
| 15 |
+
std::cout << "\t\t--encode-lossless" << std::endl;
|
| 16 |
+
std::cout << "\t\t--input-file\t\t<required string (path to input image)>"
|
| 17 |
+
<< std::endl;
|
| 18 |
+
std::cout << "\t\t--output-file\t\t<required string (path to output image)>"
|
| 19 |
+
<< std::endl;
|
| 20 |
+
std::cout << "\t\t--text\t\t\t<required string>" << std::endl;
|
| 21 |
+
std::cout << "\t\t--quality\t\t<optional int defaults to 71>" << std::endl;
|
| 22 |
+
std::cout << "\t\t--bits-to-steal\t\t<optional int defaults to 2>"
|
| 23 |
+
<< std::endl;
|
| 24 |
+
std::cout << "" << std::endl;
|
| 25 |
+
|
| 26 |
+
std::cout << "\tto decode a lossless jpeg" << std::endl;
|
| 27 |
+
std::cout << "\t\t--decode-lossless" << std::endl;
|
| 28 |
+
std::cout << "\t\t--input-file\t\t<required string (path to input image)>"
|
| 29 |
+
<< std::endl;
|
| 30 |
+
std::cout << "" << std::endl;
|
| 31 |
+
|
| 32 |
+
std::cout << "\tto encode a lossy jpeg image with text" << std::endl;
|
| 33 |
+
std::cout << "\t\t--encode-lossy" << std::endl;
|
| 34 |
+
std::cout << "\t\t--input-file\t\t<required string (path to input image)>"
|
| 35 |
+
<< std::endl;
|
| 36 |
+
std::cout << "\t\t--output-file\t\t<required string (path to output image)>"
|
| 37 |
+
<< std::endl;
|
| 38 |
+
std::cout << "\t\t--text\t\t\t<required string>" << std::endl;
|
| 39 |
+
std::cout << "\t\t--quality\t\t<optional int defaults to 71>" << std::endl;
|
| 40 |
+
std::cout
|
| 41 |
+
<< "\t\t--compressions\t\t<optional int defaults to 5 (number of times "
|
| 42 |
+
<< std::endl
|
| 43 |
+
<< "\t\t\t\t\t to uncompress/recompress the image before "
|
| 44 |
+
<< std::endl << "\t\t\t\t\t encoding the payload)>" << std::endl;
|
| 45 |
+
std::cout << "" << std::endl;
|
| 46 |
+
|
| 47 |
+
std::cout << "\tto decode a lossy jpeg" << std::endl;
|
| 48 |
+
std::cout << "\t\t--decode-lossy" << std::endl;
|
| 49 |
+
std::cout << "\t\t--input-file\t\t<required string (path to input image)>"
|
| 50 |
+
<< std::endl;
|
| 51 |
+
std::cout << "" << std::endl;
|
| 52 |
+
|
| 53 |
+
std::cout << "\tto get the number of usable coefficients in a file"
|
| 54 |
+
<< std::endl;
|
| 55 |
+
std::cout << "\t\t--coefficients" << std::endl;
|
| 56 |
+
std::cout << "\t\t--input-file\t\t<required string (path to input image)>"
|
| 57 |
+
<< std::endl;
|
| 58 |
+
std::cout << "" << std::endl;
|
| 59 |
+
|
| 60 |
+
std::cout << "\tto do a coefficient diff for two jpeg images" << std::endl;
|
| 61 |
+
std::cout << "\t\t--diff" << std::endl;
|
| 62 |
+
std::cout << "\t\t--input-file-1\t\t<required string (path to an image)>"
|
| 63 |
+
<< std::endl;
|
| 64 |
+
std::cout << "\t\t--input-file-2\t\t<required string (path to an image)>"
|
| 65 |
+
<< std::endl;
|
| 66 |
+
std::cout << "" << std::endl;
|
| 67 |
+
std::cout << "" << std::endl;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
int main(int argc, const char* argv[]) {
|
| 71 |
+
const char* input_file = NULL;
|
| 72 |
+
const char* output_file = NULL;
|
| 73 |
+
const char* input_file_1 = NULL;
|
| 74 |
+
const char* input_file_2 = NULL;
|
| 75 |
+
const char* text = NULL;
|
| 76 |
+
bool encode_lossy = false;
|
| 77 |
+
bool encode_lossless = false;
|
| 78 |
+
bool decode_lossless = false;
|
| 79 |
+
bool decode_lossy = false;
|
| 80 |
+
bool number_of_coefficients = false;
|
| 81 |
+
bool diff = false;
|
| 82 |
+
int quality = 71;
|
| 83 |
+
int number_of_compressions = 5;
|
| 84 |
+
int bits_to_steal = 2;
|
| 85 |
+
|
| 86 |
+
if (argc <= 1) {
|
| 87 |
+
std::cout << "***********************" << std::endl;
|
| 88 |
+
std::cout
|
| 89 |
+
<< "you need to pass in some command line flags, here is the help documentation"
|
| 90 |
+
<< std::endl;
|
| 91 |
+
std::cout << "***********************" << std::endl << std::endl;
|
| 92 |
+
print_help();
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
try {
|
| 96 |
+
for (int i = 1; i < argc; ++i) {
|
| 97 |
+
if (strcmp("--help", argv[i]) == 0) {
|
| 98 |
+
print_help();
|
| 99 |
+
return 0;
|
| 100 |
+
} else if (strcmp("--input-file", argv[i]) == 0) {
|
| 101 |
+
input_file = argv[++i];
|
| 102 |
+
} else if (strcmp("--input-file-1", argv[i]) == 0) {
|
| 103 |
+
input_file_1 = argv[++i];
|
| 104 |
+
} else if (strcmp("--input-file-2", argv[i]) == 0) {
|
| 105 |
+
input_file_2 = argv[++i];
|
| 106 |
+
} else if (strcmp("--output-file", argv[i]) == 0) {
|
| 107 |
+
output_file = argv[++i];
|
| 108 |
+
} else if (strcmp("--text", argv[i]) == 0) {
|
| 109 |
+
text = argv[++i];
|
| 110 |
+
} else if (strcmp("--encode-lossy", argv[i]) == 0) {
|
| 111 |
+
encode_lossy = true;
|
| 112 |
+
} else if (strcmp("--coefficients", argv[i]) == 0) {
|
| 113 |
+
number_of_coefficients = true;
|
| 114 |
+
} else if (strcmp("--encode-lossless", argv[i]) == 0) {
|
| 115 |
+
encode_lossless = true;
|
| 116 |
+
} else if (strcmp("--decode-lossless", argv[i]) == 0) {
|
| 117 |
+
decode_lossless = true;
|
| 118 |
+
} else if (strcmp("--quality", argv[i]) == 0) {
|
| 119 |
+
sscanf(argv[++i], "%d", &quality);
|
| 120 |
+
} else if (strcmp("--bits-to-steal", argv[i]) == 0) {
|
| 121 |
+
sscanf(argv[++i], "%d", &bits_to_steal);
|
| 122 |
+
} else if (strcmp("--compressions", argv[i]) == 0) {
|
| 123 |
+
sscanf(argv[++i], "%d", &number_of_compressions);
|
| 124 |
+
} else if (strcmp("--decode-lossy", argv[i]) == 0) {
|
| 125 |
+
decode_lossy = true;
|
| 126 |
+
} else if (strcmp("--diff", argv[i]) == 0) {
|
| 127 |
+
diff = true;
|
| 128 |
+
} else {
|
| 129 |
+
std::cout << "invalid command line arg, use --help to see what commands are valid" << std::endl;
|
| 130 |
+
exit(1);
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
} catch (...) {
|
| 134 |
+
std::cout << "error parsing command line parameters, use --help to see what commands are valid" << std::endl;
|
| 135 |
+
exit(1);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
if (encode_lossy) {
|
| 139 |
+
unsigned int length = strlen(text);
|
| 140 |
+
CSteg::encodeLossyJpeg(input_file, output_file, text, length, quality, number_of_compressions);
|
| 141 |
+
} else if (decode_lossy) {
|
| 142 |
+
DecodeResponse decodeResponse;
|
| 143 |
+
CSteg::decodeLossyJpeg(input_file, decodeResponse);
|
| 144 |
+
std::cout << "data out length: " << decodeResponse.getLength() << std::endl;
|
| 145 |
+
|
| 146 |
+
std::string printString;
|
| 147 |
+
printString.assign(decodeResponse.getData(), decodeResponse.getData() + decodeResponse.getLength());
|
| 148 |
+
std::cout << printString << std::endl;
|
| 149 |
+
} else if (diff) {
|
| 150 |
+
CSteg::doCoefficientDiff(input_file_1, input_file_2);
|
| 151 |
+
} else if (encode_lossless) {
|
| 152 |
+
unsigned int length = strlen(text);
|
| 153 |
+
CSteg::encodeLosslessJpeg(input_file, output_file, (unsigned char*) text, length, bits_to_steal, quality);
|
| 154 |
+
std::cout << std::endl;
|
| 155 |
+
} else if (decode_lossless) {
|
| 156 |
+
DecodeResponse decodeResponse;
|
| 157 |
+
CSteg::decodeLosslessJpeg(input_file, decodeResponse);
|
| 158 |
+
std::cout << "data out length: " << decodeResponse.getLength() << std::endl;
|
| 159 |
+
|
| 160 |
+
std::string printString;
|
| 161 |
+
printString.assign(decodeResponse.getData(), decodeResponse.getData() + decodeResponse.getLength());
|
| 162 |
+
std::cout << printString << std::endl;
|
| 163 |
+
} else if (number_of_coefficients) {
|
| 164 |
+
std::cout << "number of coefficients in file: " << CSteg::getNumberOfCoefficients(input_file) << std::endl;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
return 0;
|
| 168 |
+
}
|
| 169 |
+
|
pool/shard004/C++/0048594_synth_noise_impl.cc
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
|
| 3 |
+
Copyright (C) 2000 Stefan Westerfeld
|
| 4 |
+
stefan@space.twc.de
|
| 5 |
+
|
| 6 |
+
This library is free software; you can redistribute it and/or
|
| 7 |
+
modify it under the terms of the GNU Library General Public
|
| 8 |
+
License as published by the Free Software Foundation; either
|
| 9 |
+
version 2 of the License, or (at your option) any later version.
|
| 10 |
+
|
| 11 |
+
This library is distributed in the hope that it will be useful,
|
| 12 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
+
Library General Public License for more details.
|
| 15 |
+
|
| 16 |
+
You should have received a copy of the GNU Library General Public License
|
| 17 |
+
along with this library; see the file COPYING.LIB. If not, write to
|
| 18 |
+
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
| 19 |
+
Boston, MA 02111-1307, USA.
|
| 20 |
+
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <stdlib.h>
|
| 24 |
+
|
| 25 |
+
#include "artsmodulessynth.h"
|
| 26 |
+
#include "stdsynthmodule.h"
|
| 27 |
+
|
| 28 |
+
using namespace Arts;
|
| 29 |
+
|
| 30 |
+
namespace Arts {
|
| 31 |
+
|
| 32 |
+
#define NOISE_SIZE 8192
|
| 33 |
+
|
| 34 |
+
class Synth_NOISE_impl : virtual public Synth_NOISE_skel,
|
| 35 |
+
virtual public StdSynthModule
|
| 36 |
+
{
|
| 37 |
+
static float noise[NOISE_SIZE];
|
| 38 |
+
static bool noiseInit;
|
| 39 |
+
unsigned long pos;
|
| 40 |
+
public:
|
| 41 |
+
Synth_NOISE_impl()
|
| 42 |
+
{
|
| 43 |
+
if(!noiseInit)
|
| 44 |
+
{
|
| 45 |
+
for(unsigned long i=0;i<NOISE_SIZE;i++)
|
| 46 |
+
noise[i] = ((float)rand()/(float)RAND_MAX)*2.0-1.0;
|
| 47 |
+
noiseInit = true;
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
void calculateBlock(unsigned long samples)
|
| 51 |
+
{
|
| 52 |
+
unsigned long i;
|
| 53 |
+
pos = rand();
|
| 54 |
+
for(i=0;i<samples;i++) outvalue[i] = noise[pos++ & (NOISE_SIZE-1)];
|
| 55 |
+
}
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
float Synth_NOISE_impl::noise[8192];
|
| 59 |
+
bool Synth_NOISE_impl::noiseInit = false;
|
| 60 |
+
|
| 61 |
+
REGISTER_IMPLEMENTATION(Synth_NOISE_impl);
|
| 62 |
+
|
| 63 |
+
}
|
pool/shard004/C++/0048599_ulinks.cpp
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
static bool UnixSymlink(const char *Target,const wchar *LinkName,RarTime *ftm,RarTime *fta)
|
| 4 |
+
{
|
| 5 |
+
CreatePath(LinkName,true);
|
| 6 |
+
DelFile(LinkName);
|
| 7 |
+
char LinkNameA[NM];
|
| 8 |
+
WideToChar(LinkName,LinkNameA,ASIZE(LinkNameA));
|
| 9 |
+
if (symlink(Target,LinkNameA)==-1) // Error.
|
| 10 |
+
{
|
| 11 |
+
if (errno==EEXIST)
|
| 12 |
+
uiMsg(UIERROR_ULINKEXIST,LinkName);
|
| 13 |
+
else
|
| 14 |
+
{
|
| 15 |
+
uiMsg(UIERROR_SLINKCREATE,UINULL,LinkName);
|
| 16 |
+
ErrHandler.SetErrorCode(RARX_WARNING);
|
| 17 |
+
}
|
| 18 |
+
return false;
|
| 19 |
+
}
|
| 20 |
+
#ifdef USE_LUTIMES
|
| 21 |
+
#ifdef UNIX_TIME_NS
|
| 22 |
+
timespec times[2];
|
| 23 |
+
times[0].tv_sec=fta->GetUnix();
|
| 24 |
+
times[0].tv_nsec=fta->IsSet() ? long(fta->GetUnixNS()%1000000000) : UTIME_NOW;
|
| 25 |
+
times[1].tv_sec=ftm->GetUnix();
|
| 26 |
+
times[1].tv_nsec=ftm->IsSet() ? long(ftm->GetUnixNS()%1000000000) : UTIME_NOW;
|
| 27 |
+
utimensat(AT_FDCWD,LinkNameA,times,AT_SYMLINK_NOFOLLOW);
|
| 28 |
+
#else
|
| 29 |
+
struct timeval tv[2];
|
| 30 |
+
tv[0].tv_sec=fta->GetUnix();
|
| 31 |
+
tv[0].tv_usec=long(fta->GetUnixNS()%1000000000/1000);
|
| 32 |
+
tv[1].tv_sec=ftm->GetUnix();
|
| 33 |
+
tv[1].tv_usec=long(ftm->GetUnixNS()%1000000000/1000);
|
| 34 |
+
lutimes(LinkNameA,tv);
|
| 35 |
+
#endif
|
| 36 |
+
#endif
|
| 37 |
+
|
| 38 |
+
return true;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
static bool IsFullPath(const char *PathA) // Unix ASCII version.
|
| 43 |
+
{
|
| 44 |
+
return *PathA==CPATHDIVIDER;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
bool ExtractUnixLink30(CommandData *Cmd,ComprDataIO &DataIO,Archive &Arc,const wchar *LinkName)
|
| 49 |
+
{
|
| 50 |
+
char Target[NM];
|
| 51 |
+
if (IsLink(Arc.FileHead.FileAttr))
|
| 52 |
+
{
|
| 53 |
+
size_t DataSize=Min(Arc.FileHead.PackSize,ASIZE(Target)-1);
|
| 54 |
+
DataIO.UnpRead((byte *)Target,DataSize);
|
| 55 |
+
Target[DataSize]=0;
|
| 56 |
+
|
| 57 |
+
DataIO.UnpHash.Init(Arc.FileHead.FileHash.Type,1);
|
| 58 |
+
DataIO.UnpHash.Update(Target,strlen(Target));
|
| 59 |
+
DataIO.UnpHash.Result(&Arc.FileHead.FileHash);
|
| 60 |
+
|
| 61 |
+
// Return true in case of bad checksum, so link will be processed further
|
| 62 |
+
// and extraction routine will report the checksum error.
|
| 63 |
+
if (!DataIO.UnpHash.Cmp(&Arc.FileHead.FileHash,Arc.FileHead.UseHashKey ? Arc.FileHead.HashKey:NULL))
|
| 64 |
+
return true;
|
| 65 |
+
|
| 66 |
+
wchar TargetW[NM];
|
| 67 |
+
CharToWide(Target,TargetW,ASIZE(TargetW));
|
| 68 |
+
// Check for *TargetW==0 to catch CharToWide failure.
|
| 69 |
+
// Use Arc.FileHead.FileName instead of LinkName, since LinkName
|
| 70 |
+
// can include the destination path as a prefix, which can
|
| 71 |
+
// confuse IsRelativeSymlinkSafe algorithm.
|
| 72 |
+
if (!Cmd->AbsoluteLinks && (*TargetW==0 || IsFullPath(TargetW) ||
|
| 73 |
+
!IsRelativeSymlinkSafe(Cmd,Arc.FileHead.FileName,LinkName,TargetW)))
|
| 74 |
+
return false;
|
| 75 |
+
return UnixSymlink(Target,LinkName,&Arc.FileHead.mtime,&Arc.FileHead.atime);
|
| 76 |
+
}
|
| 77 |
+
return false;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
bool ExtractUnixLink50(CommandData *Cmd,const wchar *Name,FileHeader *hd)
|
| 82 |
+
{
|
| 83 |
+
char Target[NM];
|
| 84 |
+
WideToChar(hd->RedirName,Target,ASIZE(Target));
|
| 85 |
+
if (hd->RedirType==FSREDIR_WINSYMLINK || hd->RedirType==FSREDIR_JUNCTION)
|
| 86 |
+
{
|
| 87 |
+
// Cannot create Windows absolute path symlinks in Unix. Only relative path
|
| 88 |
+
// Windows symlinks can be created here. RAR 5.0 used \??\ prefix
|
| 89 |
+
// for Windows absolute symlinks, since RAR 5.1 /??/ is used.
|
| 90 |
+
// We escape ? as \? to avoid "trigraph" warning
|
| 91 |
+
if (strncmp(Target,"\\??\\",4)==0 || strncmp(Target,"/\?\?/",4)==0)
|
| 92 |
+
return false;
|
| 93 |
+
DosSlashToUnix(Target,Target,ASIZE(Target));
|
| 94 |
+
}
|
| 95 |
+
// Use hd->FileName instead of LinkName, since LinkName can include
|
| 96 |
+
// the destination path as a prefix, which can confuse
|
| 97 |
+
// IsRelativeSymlinkSafe algorithm.
|
| 98 |
+
if (!Cmd->AbsoluteLinks && (IsFullPath(Target) ||
|
| 99 |
+
!IsRelativeSymlinkSafe(Cmd,hd->FileName,Name,hd->RedirName)))
|
| 100 |
+
return false;
|
| 101 |
+
return UnixSymlink(Target,Name,&hd->mtime,&hd->atime);
|
| 102 |
+
}
|
pool/shard004/C++/0048604_CWE78_OS_Command_Injection__wchar_t_environment_w32_spawnv_73a.cpp
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE78_OS_Command_Injection__wchar_t_environment_w32_spawnv_73a.cpp
|
| 3 |
+
Label Definition File: CWE78_OS_Command_Injection.strings.label.xml
|
| 4 |
+
Template File: sources-sink-73a.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 78 OS Command Injection
|
| 9 |
+
* BadSource: environment Read input from an environment variable
|
| 10 |
+
* GoodSource: Fixed string
|
| 11 |
+
* Sinks: w32_spawnv
|
| 12 |
+
* BadSink : execute command with wspawnv
|
| 13 |
+
* Flow Variant: 73 Data flow: data passed in a list from one function to another in different source files
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
|
| 17 |
+
#include "std_testcase.h"
|
| 18 |
+
#include <list>
|
| 19 |
+
|
| 20 |
+
#include <wchar.h>
|
| 21 |
+
|
| 22 |
+
#ifdef _WIN32
|
| 23 |
+
#define COMMAND_INT_PATH L"%WINDIR%\\system32\\cmd.exe"
|
| 24 |
+
#define COMMAND_INT L"cmd.exe"
|
| 25 |
+
#define COMMAND_ARG1 L"/c"
|
| 26 |
+
#define COMMAND_ARG2 L"dir "
|
| 27 |
+
#define COMMAND_ARG3 data
|
| 28 |
+
#else /* NOT _WIN32 */
|
| 29 |
+
#include <unistd.h>
|
| 30 |
+
#define COMMAND_INT_PATH L"/bin/sh"
|
| 31 |
+
#define COMMAND_INT L"sh"
|
| 32 |
+
#define COMMAND_ARG1 L"-c"
|
| 33 |
+
#define COMMAND_ARG2 L"ls "
|
| 34 |
+
#define COMMAND_ARG3 data
|
| 35 |
+
#endif
|
| 36 |
+
|
| 37 |
+
#define ENV_VARIABLE L"ADD"
|
| 38 |
+
|
| 39 |
+
#ifdef _WIN32
|
| 40 |
+
#define GETENV _wgetenv
|
| 41 |
+
#else
|
| 42 |
+
#define GETENV getenv
|
| 43 |
+
#endif
|
| 44 |
+
|
| 45 |
+
using namespace std;
|
| 46 |
+
|
| 47 |
+
namespace CWE78_OS_Command_Injection__wchar_t_environment_w32_spawnv_73
|
| 48 |
+
{
|
| 49 |
+
|
| 50 |
+
#ifndef OMITBAD
|
| 51 |
+
|
| 52 |
+
/* bad function declaration */
|
| 53 |
+
void badSink(list<wchar_t *> dataList);
|
| 54 |
+
|
| 55 |
+
void bad()
|
| 56 |
+
{
|
| 57 |
+
wchar_t * data;
|
| 58 |
+
list<wchar_t *> dataList;
|
| 59 |
+
wchar_t dataBuffer[100] = COMMAND_ARG2;
|
| 60 |
+
data = dataBuffer;
|
| 61 |
+
{
|
| 62 |
+
/* Append input from an environment variable to data */
|
| 63 |
+
size_t dataLen = wcslen(data);
|
| 64 |
+
wchar_t * environment = GETENV(ENV_VARIABLE);
|
| 65 |
+
/* If there is data in the environment variable */
|
| 66 |
+
if (environment != NULL)
|
| 67 |
+
{
|
| 68 |
+
/* POTENTIAL FLAW: Read data from an environment variable */
|
| 69 |
+
wcsncat(data+dataLen, environment, 100-dataLen-1);
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
/* Put data in a list */
|
| 73 |
+
dataList.push_back(data);
|
| 74 |
+
dataList.push_back(data);
|
| 75 |
+
dataList.push_back(data);
|
| 76 |
+
badSink(dataList);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
#endif /* OMITBAD */
|
| 80 |
+
|
| 81 |
+
#ifndef OMITGOOD
|
| 82 |
+
|
| 83 |
+
/* good function declarations */
|
| 84 |
+
|
| 85 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 86 |
+
void goodG2BSink(list<wchar_t *> dataList);
|
| 87 |
+
|
| 88 |
+
static void goodG2B()
|
| 89 |
+
{
|
| 90 |
+
wchar_t * data;
|
| 91 |
+
list<wchar_t *> dataList;
|
| 92 |
+
wchar_t dataBuffer[100] = COMMAND_ARG2;
|
| 93 |
+
data = dataBuffer;
|
| 94 |
+
/* FIX: Append a fixed string to data (not user / external input) */
|
| 95 |
+
wcscat(data, L"*.*");
|
| 96 |
+
/* Put data in a list */
|
| 97 |
+
dataList.push_back(data);
|
| 98 |
+
dataList.push_back(data);
|
| 99 |
+
dataList.push_back(data);
|
| 100 |
+
goodG2BSink(dataList);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
void good()
|
| 104 |
+
{
|
| 105 |
+
goodG2B();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
#endif /* OMITGOOD */
|
| 109 |
+
|
| 110 |
+
} /* close namespace */
|
| 111 |
+
|
| 112 |
+
/* Below is the main(). It is only used when building this testcase on
|
| 113 |
+
* its own for testing or for building a binary to use in testing binary
|
| 114 |
+
* analysis tools. It is not used when compiling all the testcases as one
|
| 115 |
+
* application, which is how source code analysis tools are tested.
|
| 116 |
+
*/
|
| 117 |
+
|
| 118 |
+
#ifdef INCLUDEMAIN
|
| 119 |
+
|
| 120 |
+
using namespace CWE78_OS_Command_Injection__wchar_t_environment_w32_spawnv_73; /* so that we can use good and bad easily */
|
| 121 |
+
|
| 122 |
+
int main(int argc, char * argv[])
|
| 123 |
+
{
|
| 124 |
+
/* seed randomness */
|
| 125 |
+
srand( (unsigned)time(NULL) );
|
| 126 |
+
#ifndef OMITGOOD
|
| 127 |
+
printLine("Calling good()...");
|
| 128 |
+
good();
|
| 129 |
+
printLine("Finished good()");
|
| 130 |
+
#endif /* OMITGOOD */
|
| 131 |
+
#ifndef OMITBAD
|
| 132 |
+
printLine("Calling bad()...");
|
| 133 |
+
bad();
|
| 134 |
+
printLine("Finished bad()");
|
| 135 |
+
#endif /* OMITBAD */
|
| 136 |
+
return 0;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
#endif
|
pool/shard004/C++/0048612_util_test.cc
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/******************************************************************************
|
| 2 |
+
* Copyright 2017 The Apollo Authors. All Rights Reserved.
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*****************************************************************************/
|
| 16 |
+
|
| 17 |
+
#include "modules/common/util/util.h"
|
| 18 |
+
|
| 19 |
+
#include <vector>
|
| 20 |
+
|
| 21 |
+
#include "gtest/gtest.h"
|
| 22 |
+
#include "modules/common/util/testdata/simple.pb.h"
|
| 23 |
+
|
| 24 |
+
namespace apollo {
|
| 25 |
+
namespace common {
|
| 26 |
+
namespace util {
|
| 27 |
+
|
| 28 |
+
TEST(Util, IsProtoEqual) {
|
| 29 |
+
test::SimpleRepeatedMessage sim1;
|
| 30 |
+
for (int i = 0; i < 10; ++i) {
|
| 31 |
+
auto* t = sim1.add_message();
|
| 32 |
+
t->set_integer(i);
|
| 33 |
+
t->set_text(std::to_string(i));
|
| 34 |
+
}
|
| 35 |
+
auto sim2 = sim1;
|
| 36 |
+
EXPECT_TRUE(IsProtoEqual(sim1, sim2));
|
| 37 |
+
sim2.mutable_message(0)->set_integer(-1);
|
| 38 |
+
EXPECT_FALSE(IsProtoEqual(sim1, sim2));
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
TEST(Util, DistanceXY) {
|
| 42 |
+
class TestPoint {
|
| 43 |
+
public:
|
| 44 |
+
TestPoint(double x, double y) : x_(x), y_(y) {}
|
| 45 |
+
double x() const { return x_; }
|
| 46 |
+
double y() const { return y_; }
|
| 47 |
+
|
| 48 |
+
private:
|
| 49 |
+
double x_ = 0.0;
|
| 50 |
+
double y_ = 0.0;
|
| 51 |
+
};
|
| 52 |
+
EXPECT_DOUBLE_EQ(0.0, DistanceXY(TestPoint(0, 0), TestPoint(0, 0)));
|
| 53 |
+
EXPECT_DOUBLE_EQ(1.0, DistanceXY(TestPoint(1, 0), TestPoint(0, 0)));
|
| 54 |
+
EXPECT_DOUBLE_EQ(1.0, DistanceXY(TestPoint(0, 0), TestPoint(1, 0)));
|
| 55 |
+
EXPECT_DOUBLE_EQ(0.0, DistanceXY(TestPoint(1, 0), TestPoint(1, 0)));
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
TEST(Util, uniform_slice) {
|
| 59 |
+
std::vector<double> result;
|
| 60 |
+
uniform_slice(0.0, 10.0, 3, &result);
|
| 61 |
+
ASSERT_EQ(4, result.size());
|
| 62 |
+
EXPECT_DOUBLE_EQ(0.0, result[0]);
|
| 63 |
+
EXPECT_DOUBLE_EQ(3.3333333333333335, result[1]);
|
| 64 |
+
EXPECT_DOUBLE_EQ(6.666666666666667, result[2]);
|
| 65 |
+
EXPECT_DOUBLE_EQ(10.0, result[3]);
|
| 66 |
+
|
| 67 |
+
uniform_slice(0.0, -10.0, 3, &result);
|
| 68 |
+
ASSERT_EQ(4, result.size());
|
| 69 |
+
EXPECT_DOUBLE_EQ(0.0, result[0]);
|
| 70 |
+
EXPECT_DOUBLE_EQ(-3.3333333333333335, result[1]);
|
| 71 |
+
EXPECT_DOUBLE_EQ(-6.666666666666667, result[2]);
|
| 72 |
+
EXPECT_DOUBLE_EQ(-10.0, result[3]);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
TEST(Util, IsFloatEqual) {
|
| 76 |
+
double d1 = 0.2;
|
| 77 |
+
double d2 = 1 / std::sqrt(5) / std::sqrt(5);
|
| 78 |
+
EXPECT_TRUE(IsFloatEqual(d1, d2));
|
| 79 |
+
double d3 = 0.999999999999999999;
|
| 80 |
+
double d4 = 0.999999999999999998;
|
| 81 |
+
EXPECT_TRUE(IsFloatEqual(d3, d4));
|
| 82 |
+
double d5 = 0.11;
|
| 83 |
+
double d6 = 0.12;
|
| 84 |
+
EXPECT_FALSE(IsFloatEqual(d5, d6));
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
} // namespace util
|
| 88 |
+
} // namespace common
|
| 89 |
+
} // namespace apollo
|
pool/shard004/C++/0048615_RtclRw11Unit.cpp
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// $Id: RtclRw11Unit.cpp 504 2013-04-13 15:37:24Z mueller $
|
| 2 |
+
//
|
| 3 |
+
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
| 4 |
+
//
|
| 5 |
+
// This program is free software; you may redistribute and/or modify it under
|
| 6 |
+
// the terms of the GNU General Public License as published by the Free
|
| 7 |
+
// Software Foundation, either version 2, or at your option any later version.
|
| 8 |
+
//
|
| 9 |
+
// This program is distributed in the hope that it will be useful, but
|
| 10 |
+
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
| 11 |
+
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 12 |
+
// for complete details.
|
| 13 |
+
//
|
| 14 |
+
// Revision History:
|
| 15 |
+
// Date Rev Version Comment
|
| 16 |
+
// 2013-03-03 494 1.0 Initial version
|
| 17 |
+
// 2013-02-16 488 0.1 First draft
|
| 18 |
+
// ---------------------------------------------------------------------------
|
| 19 |
+
|
| 20 |
+
/*!
|
| 21 |
+
\file
|
| 22 |
+
\version $Id: RtclRw11Unit.cpp 504 2013-04-13 15:37:24Z mueller $
|
| 23 |
+
\brief Implemenation of RtclRw11Unit.
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
#include "boost/thread/locks.hpp"
|
| 27 |
+
#include "boost/bind.hpp"
|
| 28 |
+
|
| 29 |
+
#include "librtcltools/RtclStats.hpp"
|
| 30 |
+
|
| 31 |
+
#include "RtclRw11Unit.hpp"
|
| 32 |
+
|
| 33 |
+
using namespace std;
|
| 34 |
+
|
| 35 |
+
/*!
|
| 36 |
+
\class Retro::RtclRw11Unit
|
| 37 |
+
\brief FIXME_docs
|
| 38 |
+
*/
|
| 39 |
+
|
| 40 |
+
// all method definitions in namespace Retro
|
| 41 |
+
namespace Retro {
|
| 42 |
+
|
| 43 |
+
//------------------------------------------+-----------------------------------
|
| 44 |
+
//! Default constructor
|
| 45 |
+
|
| 46 |
+
RtclRw11Unit::RtclRw11Unit(const std::string& type, Rw11Cpu* pcpu)
|
| 47 |
+
: RtclProxyBase(type),
|
| 48 |
+
fpCpu(pcpu),
|
| 49 |
+
fGets(),
|
| 50 |
+
fSets()
|
| 51 |
+
{
|
| 52 |
+
AddMeth("get", boost::bind(&RtclRw11Unit::M_get, this, _1));
|
| 53 |
+
AddMeth("set", boost::bind(&RtclRw11Unit::M_set, this, _1));
|
| 54 |
+
AddMeth("attach", boost::bind(&RtclRw11Unit::M_attach, this, _1));
|
| 55 |
+
AddMeth("detach", boost::bind(&RtclRw11Unit::M_detach, this, _1));
|
| 56 |
+
AddMeth("dump", boost::bind(&RtclRw11Unit::M_dump, this, _1));
|
| 57 |
+
AddMeth("$default", boost::bind(&RtclRw11Unit::M_default, this, _1));
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
//------------------------------------------+-----------------------------------
|
| 61 |
+
//! Destructor
|
| 62 |
+
|
| 63 |
+
RtclRw11Unit::~RtclRw11Unit()
|
| 64 |
+
{}
|
| 65 |
+
|
| 66 |
+
//------------------------------------------+-----------------------------------
|
| 67 |
+
//! FIXME_docs
|
| 68 |
+
|
| 69 |
+
int RtclRw11Unit::M_get(RtclArgs& args)
|
| 70 |
+
{
|
| 71 |
+
// synchronize with server thread
|
| 72 |
+
boost::lock_guard<RlinkConnect> lock(fpCpu->Connect());
|
| 73 |
+
return fGets.M_get(args);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
//------------------------------------------+-----------------------------------
|
| 77 |
+
//! FIXME_docs
|
| 78 |
+
|
| 79 |
+
int RtclRw11Unit::M_set(RtclArgs& args)
|
| 80 |
+
{
|
| 81 |
+
// synchronize with server thread
|
| 82 |
+
boost::lock_guard<RlinkConnect> lock(fpCpu->Connect());
|
| 83 |
+
return fSets.M_set(args);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
//------------------------------------------+-----------------------------------
|
| 87 |
+
//! FIXME_docs
|
| 88 |
+
|
| 89 |
+
int RtclRw11Unit::M_attach(RtclArgs& args)
|
| 90 |
+
{
|
| 91 |
+
string url;
|
| 92 |
+
if (!args.GetArg("url", url)) return kERR;
|
| 93 |
+
|
| 94 |
+
if (!args.AllDone()) return kERR;
|
| 95 |
+
|
| 96 |
+
RerrMsg emsg;
|
| 97 |
+
// synchronize with server thread
|
| 98 |
+
boost::lock_guard<RlinkConnect> lock(fpCpu->Connect());
|
| 99 |
+
if (!Obj().Attach(url, emsg)) return args.Quit(emsg);
|
| 100 |
+
return kOK;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
//------------------------------------------+-----------------------------------
|
| 104 |
+
//! FIXME_docs
|
| 105 |
+
|
| 106 |
+
int RtclRw11Unit::M_detach(RtclArgs& args)
|
| 107 |
+
{
|
| 108 |
+
if (!args.AllDone()) return kERR;
|
| 109 |
+
|
| 110 |
+
// synchronize with server thread
|
| 111 |
+
boost::lock_guard<RlinkConnect> lock(fpCpu->Connect());
|
| 112 |
+
Obj().Detach();
|
| 113 |
+
return kOK;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
//------------------------------------------+-----------------------------------
|
| 117 |
+
//! FIXME_docs
|
| 118 |
+
|
| 119 |
+
int RtclRw11Unit::M_dump(RtclArgs& args)
|
| 120 |
+
{
|
| 121 |
+
if (!args.AllDone()) return kERR;
|
| 122 |
+
|
| 123 |
+
ostringstream sos;
|
| 124 |
+
Obj().Dump(sos, 0);
|
| 125 |
+
args.SetResult(sos);
|
| 126 |
+
return kOK;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
//------------------------------------------+-----------------------------------
|
| 130 |
+
//! FIXME_docs
|
| 131 |
+
|
| 132 |
+
int RtclRw11Unit::M_default(RtclArgs& args)
|
| 133 |
+
{
|
| 134 |
+
if (!args.AllDone()) return kERR;
|
| 135 |
+
ostringstream sos;
|
| 136 |
+
sos << "no default output defined yet...\n";
|
| 137 |
+
args.AppendResultLines(sos);
|
| 138 |
+
return kOK;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
} // end namespace Retro
|
pool/shard004/C++/0048616_ConfigDialog.cpp
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright (C) 2005-2011, Thorvald Natvig <thorvald@natvig.com>
|
| 2 |
+
|
| 3 |
+
All rights reserved.
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without
|
| 6 |
+
modification, are permitted provided that the following conditions
|
| 7 |
+
are met:
|
| 8 |
+
|
| 9 |
+
- Redistributions of source code must retain the above copyright notice,
|
| 10 |
+
this list of conditions and the following disclaimer.
|
| 11 |
+
- Redistributions in binary form must reproduce the above copyright notice,
|
| 12 |
+
this list of conditions and the following disclaimer in the documentation
|
| 13 |
+
and/or other materials provided with the distribution.
|
| 14 |
+
- Neither the name of the Mumble Developers nor the names of its
|
| 15 |
+
contributors may be used to endorse or promote products derived from this
|
| 16 |
+
software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 19 |
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 20 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 21 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
| 22 |
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 23 |
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| 24 |
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 25 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 26 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 27 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 28 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
#include "mumble_pch.hpp"
|
| 32 |
+
|
| 33 |
+
#include "ConfigDialog.h"
|
| 34 |
+
|
| 35 |
+
#include "AudioInput.h"
|
| 36 |
+
#include "AudioOutput.h"
|
| 37 |
+
#include "Global.h"
|
| 38 |
+
#include "Overlay.h"
|
| 39 |
+
|
| 40 |
+
ConfigDialog::ConfigDialog(QWidget *p) : QDialog(p) {
|
| 41 |
+
setupUi(this);
|
| 42 |
+
|
| 43 |
+
s = g.s;
|
| 44 |
+
|
| 45 |
+
unsigned int idx = 0;
|
| 46 |
+
ConfigWidgetNew cwn;
|
| 47 |
+
foreach(cwn, *ConfigRegistrar::c_qmNew) {
|
| 48 |
+
addPage(cwn(s), ++idx);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
qcbExpert->setChecked(g.s.bExpert);
|
| 52 |
+
on_qcbExpert_clicked(g.s.bExpert);
|
| 53 |
+
|
| 54 |
+
QPushButton *okButton = dialogButtonBox->button(QDialogButtonBox::Ok);
|
| 55 |
+
okButton->setToolTip(tr("Accept changes"));
|
| 56 |
+
okButton->setWhatsThis(tr("This button will accept current settings and return to the application.<br />"
|
| 57 |
+
"The settings will be stored to disk when you leave the application."));
|
| 58 |
+
|
| 59 |
+
QPushButton *cancelButton = dialogButtonBox->button(QDialogButtonBox::Cancel);
|
| 60 |
+
cancelButton->setToolTip(tr("Reject changes"));
|
| 61 |
+
cancelButton->setWhatsThis(tr("This button will reject all changes and return to the application.<br />"
|
| 62 |
+
"The settings will be reset to the previous positions."));
|
| 63 |
+
|
| 64 |
+
QPushButton *applyButton = dialogButtonBox->button(QDialogButtonBox::Apply);
|
| 65 |
+
applyButton->setToolTip(tr("Apply changes"));
|
| 66 |
+
applyButton->setWhatsThis(tr("This button will immediately apply all changes."));
|
| 67 |
+
|
| 68 |
+
QPushButton *resetButton = pageButtonBox->button(QDialogButtonBox::Reset);
|
| 69 |
+
resetButton->setToolTip(tr("Undo changes for current page"));
|
| 70 |
+
resetButton->setWhatsThis(tr("This button will revert any changes done on the current page to the most recent applied settings."));
|
| 71 |
+
|
| 72 |
+
QPushButton *restoreButton = pageButtonBox->button(QDialogButtonBox::RestoreDefaults);
|
| 73 |
+
restoreButton->setToolTip(tr("Restore defaults for current page"));
|
| 74 |
+
restoreButton->setWhatsThis(tr("This button will restore the defaults for the settings on the current page. Other pages will not be changed.<br />"
|
| 75 |
+
"To restore all settings to their defaults, you will have to use this button on every page."
|
| 76 |
+
));
|
| 77 |
+
|
| 78 |
+
if (! g.s.qbaConfigGeometry.isEmpty()) {
|
| 79 |
+
if (! g.ocIntercept)
|
| 80 |
+
restoreGeometry(g.s.qbaConfigGeometry);
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
void ConfigDialog::addPage(ConfigWidget *cw, unsigned int idx) {
|
| 85 |
+
QDesktopWidget dw;
|
| 86 |
+
|
| 87 |
+
int w = INT_MAX, h = INT_MAX;
|
| 88 |
+
|
| 89 |
+
for (int i=0;i<dw.numScreens();++i) {
|
| 90 |
+
QRect ds=dw.availableGeometry(i);
|
| 91 |
+
if (ds.isValid()) {
|
| 92 |
+
w = qMin(w, ds.width());
|
| 93 |
+
h = qMin(h, ds.height());
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
QSize ms=cw->minimumSizeHint();
|
| 98 |
+
cw->resize(ms);
|
| 99 |
+
cw->setMinimumSize(ms);
|
| 100 |
+
|
| 101 |
+
ms.rwidth() += 128;
|
| 102 |
+
ms.rheight() += 192;
|
| 103 |
+
if ((ms.width() > w) || (ms.height() > h)) {
|
| 104 |
+
QScrollArea *qsa=new QScrollArea();
|
| 105 |
+
qsa->setFrameShape(QFrame::NoFrame);
|
| 106 |
+
qsa->setWidgetResizable(true);
|
| 107 |
+
qsa->setWidget(cw);
|
| 108 |
+
qhPages.insert(cw, qsa);
|
| 109 |
+
qswPages->addWidget(qsa);
|
| 110 |
+
} else {
|
| 111 |
+
qhPages.insert(cw, cw);
|
| 112 |
+
qswPages->addWidget(cw);
|
| 113 |
+
}
|
| 114 |
+
qmWidgets.insert(idx, cw);
|
| 115 |
+
cw->load(g.s);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
ConfigDialog::~ConfigDialog() {
|
| 119 |
+
foreach(QWidget *qw, qhPages)
|
| 120 |
+
delete qw;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
void ConfigDialog::on_pageButtonBox_clicked(QAbstractButton *b) {
|
| 124 |
+
ConfigWidget *conf = qobject_cast<ConfigWidget *>(qswPages->currentWidget());
|
| 125 |
+
if (! conf) {
|
| 126 |
+
QScrollArea *qsa = qobject_cast<QScrollArea *>(qswPages->currentWidget());
|
| 127 |
+
if (qsa)
|
| 128 |
+
conf = qobject_cast<ConfigWidget *>(qsa->widget());
|
| 129 |
+
}
|
| 130 |
+
if (! conf)
|
| 131 |
+
return;
|
| 132 |
+
switch (pageButtonBox->standardButton(b)) {
|
| 133 |
+
case QDialogButtonBox::RestoreDefaults: {
|
| 134 |
+
Settings def;
|
| 135 |
+
def.bExpert = g.s.bExpert;
|
| 136 |
+
conf->load(def);
|
| 137 |
+
break;
|
| 138 |
+
}
|
| 139 |
+
case QDialogButtonBox::Reset: {
|
| 140 |
+
conf->load(g.s);
|
| 141 |
+
break;
|
| 142 |
+
}
|
| 143 |
+
default:
|
| 144 |
+
break;
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
void ConfigDialog::on_dialogButtonBox_clicked(QAbstractButton *b) {
|
| 149 |
+
switch (dialogButtonBox->standardButton(b)) {
|
| 150 |
+
case QDialogButtonBox::Apply: {
|
| 151 |
+
apply();
|
| 152 |
+
break;
|
| 153 |
+
}
|
| 154 |
+
default:
|
| 155 |
+
break;
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
void ConfigDialog::on_qlwIcons_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) {
|
| 160 |
+
if (!current)
|
| 161 |
+
current = previous;
|
| 162 |
+
|
| 163 |
+
if (current) {
|
| 164 |
+
QWidget *w = qhPages.value(qmIconWidgets.value(current));
|
| 165 |
+
if (w)
|
| 166 |
+
qswPages->setCurrentWidget(w);
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
void ConfigDialog::on_qcbExpert_clicked(bool b) {
|
| 171 |
+
QWidget *ccw = qmIconWidgets.value(qlwIcons->currentItem());
|
| 172 |
+
QListWidgetItem *sel = NULL;
|
| 173 |
+
|
| 174 |
+
qmIconWidgets.clear();
|
| 175 |
+
qlwIcons->clear();
|
| 176 |
+
|
| 177 |
+
QFontMetrics qfm(qlwIcons->font());
|
| 178 |
+
int width = 0;
|
| 179 |
+
|
| 180 |
+
foreach(ConfigWidget *cw, qmWidgets) {
|
| 181 |
+
bool showit = cw->expert(b);
|
| 182 |
+
width = qMax(width, qfm.width(cw->title()));
|
| 183 |
+
if (showit || b) {
|
| 184 |
+
QListWidgetItem *i = new QListWidgetItem(qlwIcons);
|
| 185 |
+
i->setIcon(cw->icon());
|
| 186 |
+
i->setText(cw->title());
|
| 187 |
+
i->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
qmIconWidgets.insert(i, cw);
|
| 191 |
+
if (cw == ccw)
|
| 192 |
+
sel = i;
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
// Add space for icon and some padding.
|
| 197 |
+
width += qlwIcons->iconSize().width() + 25;
|
| 198 |
+
|
| 199 |
+
qlwIcons->setMinimumWidth(width);
|
| 200 |
+
qlwIcons->setMaximumWidth(width);
|
| 201 |
+
|
| 202 |
+
if (sel)
|
| 203 |
+
qlwIcons->setCurrentItem(sel);
|
| 204 |
+
else
|
| 205 |
+
qlwIcons->setCurrentRow(0);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
void ConfigDialog::apply() {
|
| 209 |
+
Audio::stop();
|
| 210 |
+
|
| 211 |
+
foreach(ConfigWidget *cw, qmWidgets)
|
| 212 |
+
cw->save();
|
| 213 |
+
|
| 214 |
+
g.s = s;
|
| 215 |
+
|
| 216 |
+
foreach(ConfigWidget *cw, qmWidgets)
|
| 217 |
+
cw->accept();
|
| 218 |
+
|
| 219 |
+
if (!g.s.bAttenuateOthersOnTalk)
|
| 220 |
+
g.bAttenuateOthers = false;
|
| 221 |
+
|
| 222 |
+
// They might have changed their keys.
|
| 223 |
+
g.iPushToTalk = 0;
|
| 224 |
+
g.s.bExpert = qcbExpert->isChecked();
|
| 225 |
+
|
| 226 |
+
Audio::start();
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
void ConfigDialog::accept() {
|
| 230 |
+
apply();
|
| 231 |
+
|
| 232 |
+
if (! g.ocIntercept)
|
| 233 |
+
g.s.qbaConfigGeometry=saveGeometry();
|
| 234 |
+
|
| 235 |
+
QDialog::accept();
|
| 236 |
+
}
|
pool/shard004/C++/0048623_RedisCommand.cc
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "core/RedisCommand.h"
|
| 2 |
+
#include "core/RedisConnection.h"
|
| 3 |
+
#include "core/TritonSortAssert.h"
|
| 4 |
+
|
| 5 |
+
RedisCommand::RedisCommand(const char* format ...) {
|
| 6 |
+
// Write command string so we can print debug messages.
|
| 7 |
+
va_list ap;
|
| 8 |
+
va_start(ap, format);
|
| 9 |
+
int charactersWritten = vsnprintf(_command, 1024, format, ap);
|
| 10 |
+
ABORT_IF(charactersWritten == -1, "vsnprintf(%s, ...) failed; either memory "
|
| 11 |
+
"allocation failed, or some other error occurred", format);
|
| 12 |
+
ABORT_IF(charactersWritten >= 1024,
|
| 13 |
+
"Redis command must be less than 1024 characters");
|
| 14 |
+
va_end(ap);
|
| 15 |
+
|
| 16 |
+
// Issue redis command.
|
| 17 |
+
va_start(ap, format);
|
| 18 |
+
_reply = RedisConnection::getReply(_command, format, ap);
|
| 19 |
+
va_end(ap);
|
| 20 |
+
|
| 21 |
+
if (_reply->type == REDIS_REPLY_ERROR) {
|
| 22 |
+
std::string errorString;
|
| 23 |
+
errorString.assign(_reply->str, _reply->len);
|
| 24 |
+
|
| 25 |
+
ABORT("Redis command (%s) returned error from server : %s",
|
| 26 |
+
_command, errorString.c_str());
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
RedisCommand::~RedisCommand() {
|
| 31 |
+
if (_reply != NULL) {
|
| 32 |
+
freeReplyObject(_reply);
|
| 33 |
+
_reply = NULL;
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
const char* RedisCommand::replyTypeString(int replyType) {
|
| 38 |
+
switch (replyType) {
|
| 39 |
+
case REDIS_REPLY_STRING:
|
| 40 |
+
return "string";
|
| 41 |
+
break;
|
| 42 |
+
case REDIS_REPLY_ARRAY:
|
| 43 |
+
return "array";
|
| 44 |
+
break;
|
| 45 |
+
case REDIS_REPLY_INTEGER:
|
| 46 |
+
return "integer";
|
| 47 |
+
break;
|
| 48 |
+
case REDIS_REPLY_NIL:
|
| 49 |
+
return "nil";
|
| 50 |
+
break;
|
| 51 |
+
case REDIS_REPLY_STATUS:
|
| 52 |
+
return "status";
|
| 53 |
+
break;
|
| 54 |
+
case REDIS_REPLY_ERROR:
|
| 55 |
+
return "error";
|
| 56 |
+
break;
|
| 57 |
+
default:
|
| 58 |
+
return "unknown";
|
| 59 |
+
break;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
void RedisCommand::assertReplyType(
|
| 64 |
+
redisReply& reply, int expectedReplyType) {
|
| 65 |
+
ABORT_IF(reply.type != expectedReplyType, "Expected %s reply but got %s "
|
| 66 |
+
"reply", replyTypeString(expectedReplyType),
|
| 67 |
+
replyTypeString(reply.type));
|
| 68 |
+
}
|
pool/shard004/C++/0048632_bitcoin.cpp
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* W.J. van der Laan 2011-2012
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
#include <QApplication>
|
| 6 |
+
|
| 7 |
+
#include "bitcoingui.h"
|
| 8 |
+
#include "clientmodel.h"
|
| 9 |
+
#include "walletmodel.h"
|
| 10 |
+
#include "optionsmodel.h"
|
| 11 |
+
#include "guiutil.h"
|
| 12 |
+
#include "guiconstants.h"
|
| 13 |
+
#include "init.h"
|
| 14 |
+
#include "util.h"
|
| 15 |
+
#include "ui_interface.h"
|
| 16 |
+
#include "paymentserver.h"
|
| 17 |
+
#include "splashscreen.h"
|
| 18 |
+
|
| 19 |
+
#include <QMessageBox>
|
| 20 |
+
#if QT_VERSION < 0x050000
|
| 21 |
+
#include <QTextCodec>
|
| 22 |
+
#endif
|
| 23 |
+
#include <QLocale>
|
| 24 |
+
#include <QTimer>
|
| 25 |
+
#include <QTranslator>
|
| 26 |
+
#include <QLibraryInfo>
|
| 27 |
+
|
| 28 |
+
#ifdef Q_OS_MAC
|
| 29 |
+
#include "macdockiconhandler.h"
|
| 30 |
+
#endif
|
| 31 |
+
|
| 32 |
+
#if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)
|
| 33 |
+
#define _BITCOIN_QT_PLUGINS_INCLUDED
|
| 34 |
+
#define __INSURE__
|
| 35 |
+
#include <QtPlugin>
|
| 36 |
+
Q_IMPORT_PLUGIN(qcncodecs)
|
| 37 |
+
Q_IMPORT_PLUGIN(qjpcodecs)
|
| 38 |
+
Q_IMPORT_PLUGIN(qtwcodecs)
|
| 39 |
+
Q_IMPORT_PLUGIN(qkrcodecs)
|
| 40 |
+
Q_IMPORT_PLUGIN(qtaccessiblewidgets)
|
| 41 |
+
#endif
|
| 42 |
+
|
| 43 |
+
// Declare meta types used for QMetaObject::invokeMethod
|
| 44 |
+
Q_DECLARE_METATYPE(bool*)
|
| 45 |
+
|
| 46 |
+
// Need a global reference for the notifications to find the GUI
|
| 47 |
+
static BitcoinGUI *guiref;
|
| 48 |
+
static SplashScreen *splashref;
|
| 49 |
+
|
| 50 |
+
static bool ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style)
|
| 51 |
+
{
|
| 52 |
+
// Message from network thread
|
| 53 |
+
if(guiref)
|
| 54 |
+
{
|
| 55 |
+
bool modal = (style & CClientUIInterface::MODAL);
|
| 56 |
+
bool ret = false;
|
| 57 |
+
// In case of modal message, use blocking connection to wait for user to click a button
|
| 58 |
+
QMetaObject::invokeMethod(guiref, "message",
|
| 59 |
+
modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
|
| 60 |
+
Q_ARG(QString, QString::fromStdString(caption)),
|
| 61 |
+
Q_ARG(QString, QString::fromStdString(message)),
|
| 62 |
+
Q_ARG(unsigned int, style),
|
| 63 |
+
Q_ARG(bool*, &ret));
|
| 64 |
+
return ret;
|
| 65 |
+
}
|
| 66 |
+
else
|
| 67 |
+
{
|
| 68 |
+
printf("%s: %s\n", caption.c_str(), message.c_str());
|
| 69 |
+
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
|
| 70 |
+
return false;
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
static bool ThreadSafeAskFee(int64 nFeeRequired)
|
| 75 |
+
{
|
| 76 |
+
if(!guiref)
|
| 77 |
+
return false;
|
| 78 |
+
if(nFeeRequired < CTransaction::nMinTxFee || nFeeRequired <= nTransactionFee || fDaemon)
|
| 79 |
+
return true;
|
| 80 |
+
|
| 81 |
+
bool payFee = false;
|
| 82 |
+
|
| 83 |
+
QMetaObject::invokeMethod(guiref, "askFee", GUIUtil::blockingGUIThreadConnection(),
|
| 84 |
+
Q_ARG(qint64, nFeeRequired),
|
| 85 |
+
Q_ARG(bool*, &payFee));
|
| 86 |
+
|
| 87 |
+
return payFee;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
static void InitMessage(const std::string &message)
|
| 91 |
+
{
|
| 92 |
+
if(splashref)
|
| 93 |
+
{
|
| 94 |
+
splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(55,55,55));
|
| 95 |
+
qApp->processEvents();
|
| 96 |
+
}
|
| 97 |
+
printf("init message: %s\n", message.c_str());
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/*
|
| 101 |
+
Translate string to current locale using Qt.
|
| 102 |
+
*/
|
| 103 |
+
static std::string Translate(const char* psz)
|
| 104 |
+
{
|
| 105 |
+
return QCoreApplication::translate("bitcoin-core", psz).toStdString();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/* Handle runaway exceptions. Shows a message box with the problem and quits the program.
|
| 109 |
+
*/
|
| 110 |
+
static void handleRunawayException(std::exception *e)
|
| 111 |
+
{
|
| 112 |
+
PrintExceptionContinue(e, "Runaway exception");
|
| 113 |
+
QMessageBox::critical(0, "Runaway exception", BitcoinGUI::tr("A fatal error occurred. Leadcoin can no longer continue safely and will quit.") + QString("\n\n") + QString::fromStdString(strMiscWarning));
|
| 114 |
+
exit(1);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
#ifndef BITCOIN_QT_TEST
|
| 118 |
+
int main(int argc, char *argv[])
|
| 119 |
+
{
|
| 120 |
+
// Command-line options take precedence:
|
| 121 |
+
ParseParameters(argc, argv);
|
| 122 |
+
|
| 123 |
+
#if QT_VERSION < 0x050000
|
| 124 |
+
// Internal string conversion is all UTF-8
|
| 125 |
+
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
|
| 126 |
+
QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
|
| 127 |
+
#endif
|
| 128 |
+
|
| 129 |
+
Q_INIT_RESOURCE(bitcoin);
|
| 130 |
+
QApplication app(argc, argv);
|
| 131 |
+
|
| 132 |
+
// Register meta types used for QMetaObject::invokeMethod
|
| 133 |
+
qRegisterMetaType< bool* >();
|
| 134 |
+
|
| 135 |
+
// Do this early as we don't want to bother initializing if we are just calling IPC
|
| 136 |
+
// ... but do it after creating app, so QCoreApplication::arguments is initialized:
|
| 137 |
+
if (PaymentServer::ipcSendCommandLine())
|
| 138 |
+
exit(0);
|
| 139 |
+
PaymentServer* paymentServer = new PaymentServer(&app);
|
| 140 |
+
|
| 141 |
+
// Install global event filter that makes sure that long tooltips can be word-wrapped
|
| 142 |
+
app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
|
| 143 |
+
|
| 144 |
+
// ... then bitcoin.conf:
|
| 145 |
+
if (!boost::filesystem::is_directory(GetDataDir(false)))
|
| 146 |
+
{
|
| 147 |
+
// This message can not be translated, as translation is not initialized yet
|
| 148 |
+
// (which not yet possible because lang=XX can be overridden in bitcoin.conf in the data directory)
|
| 149 |
+
QMessageBox::critical(0, "Leadcoin",
|
| 150 |
+
QString("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(mapArgs["-datadir"])));
|
| 151 |
+
return 1;
|
| 152 |
+
}
|
| 153 |
+
ReadConfigFile(mapArgs, mapMultiArgs);
|
| 154 |
+
|
| 155 |
+
// Application identification (must be set before OptionsModel is initialized,
|
| 156 |
+
// as it is used to locate QSettings)
|
| 157 |
+
QApplication::setOrganizationName("Leadcoin");
|
| 158 |
+
QApplication::setOrganizationDomain("leadcoin.org");
|
| 159 |
+
if(GetBoolArg("-testnet")) // Separate UI settings for testnet
|
| 160 |
+
QApplication::setApplicationName("Leadcoin-Qt-testnet");
|
| 161 |
+
else
|
| 162 |
+
QApplication::setApplicationName("Leadcoin-Qt");
|
| 163 |
+
|
| 164 |
+
// ... then GUI settings:
|
| 165 |
+
OptionsModel optionsModel;
|
| 166 |
+
|
| 167 |
+
// Get desired locale (e.g. "de_DE") from command line or use system locale
|
| 168 |
+
QString lang_territory = QString::fromStdString(GetArg("-lang", QLocale::system().name().toStdString()));
|
| 169 |
+
QString lang = lang_territory;
|
| 170 |
+
// Convert to "de" only by truncating "_DE"
|
| 171 |
+
lang.truncate(lang_territory.lastIndexOf('_'));
|
| 172 |
+
|
| 173 |
+
QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
|
| 174 |
+
// Load language files for configured locale:
|
| 175 |
+
// - First load the translator for the base language, without territory
|
| 176 |
+
// - Then load the more specific locale translator
|
| 177 |
+
|
| 178 |
+
// Load e.g. qt_de.qm
|
| 179 |
+
if (qtTranslatorBase.load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
| 180 |
+
app.installTranslator(&qtTranslatorBase);
|
| 181 |
+
|
| 182 |
+
// Load e.g. qt_de_DE.qm
|
| 183 |
+
if (qtTranslator.load("qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
| 184 |
+
app.installTranslator(&qtTranslator);
|
| 185 |
+
|
| 186 |
+
// Load e.g. bitcoin_de.qm (shortcut "de" needs to be defined in bitcoin.qrc)
|
| 187 |
+
if (translatorBase.load(lang, ":/translations/"))
|
| 188 |
+
app.installTranslator(&translatorBase);
|
| 189 |
+
|
| 190 |
+
// Load e.g. bitcoin_de_DE.qm (shortcut "de_DE" needs to be defined in bitcoin.qrc)
|
| 191 |
+
if (translator.load(lang_territory, ":/translations/"))
|
| 192 |
+
app.installTranslator(&translator);
|
| 193 |
+
|
| 194 |
+
// Subscribe to global signals from core
|
| 195 |
+
uiInterface.ThreadSafeMessageBox.connect(ThreadSafeMessageBox);
|
| 196 |
+
uiInterface.ThreadSafeAskFee.connect(ThreadSafeAskFee);
|
| 197 |
+
uiInterface.InitMessage.connect(InitMessage);
|
| 198 |
+
uiInterface.Translate.connect(Translate);
|
| 199 |
+
|
| 200 |
+
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
|
| 201 |
+
// but before showing splash screen.
|
| 202 |
+
if (mapArgs.count("-?") || mapArgs.count("--help"))
|
| 203 |
+
{
|
| 204 |
+
GUIUtil::HelpMessageBox help;
|
| 205 |
+
help.showOrPrint();
|
| 206 |
+
return 1;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
#ifdef Q_OS_MAC
|
| 210 |
+
// on mac, also change the icon now because it would look strange to have a testnet splash (green) and a std app icon (orange)
|
| 211 |
+
if(GetBoolArg("-testnet")) {
|
| 212 |
+
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
|
| 213 |
+
}
|
| 214 |
+
#endif
|
| 215 |
+
|
| 216 |
+
SplashScreen splash(QPixmap(), 0);
|
| 217 |
+
if (GetBoolArg("-splash", true) && !GetBoolArg("-min"))
|
| 218 |
+
{
|
| 219 |
+
splash.show();
|
| 220 |
+
splash.setAutoFillBackground(true);
|
| 221 |
+
splashref = &splash;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
app.processEvents();
|
| 225 |
+
app.setQuitOnLastWindowClosed(false);
|
| 226 |
+
|
| 227 |
+
try
|
| 228 |
+
{
|
| 229 |
+
#ifndef Q_OS_MAC
|
| 230 |
+
// Regenerate startup link, to fix links to old versions
|
| 231 |
+
// OSX: makes no sense on mac and might also scan/mount external (and sleeping) volumes (can take up some secs)
|
| 232 |
+
if (GUIUtil::GetStartOnSystemStartup())
|
| 233 |
+
GUIUtil::SetStartOnSystemStartup(true);
|
| 234 |
+
#endif
|
| 235 |
+
|
| 236 |
+
boost::thread_group threadGroup;
|
| 237 |
+
|
| 238 |
+
BitcoinGUI window;
|
| 239 |
+
guiref = &window;
|
| 240 |
+
|
| 241 |
+
QTimer* pollShutdownTimer = new QTimer(guiref);
|
| 242 |
+
QObject::connect(pollShutdownTimer, SIGNAL(timeout()), guiref, SLOT(detectShutdown()));
|
| 243 |
+
pollShutdownTimer->start(200);
|
| 244 |
+
|
| 245 |
+
if(AppInit2(threadGroup))
|
| 246 |
+
{
|
| 247 |
+
{
|
| 248 |
+
// Put this in a block, so that the Model objects are cleaned up before
|
| 249 |
+
// calling Shutdown().
|
| 250 |
+
|
| 251 |
+
optionsModel.Upgrade(); // Must be done after AppInit2
|
| 252 |
+
|
| 253 |
+
if (splashref)
|
| 254 |
+
splash.finish(&window);
|
| 255 |
+
|
| 256 |
+
ClientModel clientModel(&optionsModel);
|
| 257 |
+
WalletModel walletModel(pwalletMain, &optionsModel);
|
| 258 |
+
|
| 259 |
+
window.setClientModel(&clientModel);
|
| 260 |
+
window.addWallet("~Default", &walletModel);
|
| 261 |
+
window.setCurrentWallet("~Default");
|
| 262 |
+
|
| 263 |
+
// If -min option passed, start window minimized.
|
| 264 |
+
if(GetBoolArg("-min"))
|
| 265 |
+
{
|
| 266 |
+
window.showMinimized();
|
| 267 |
+
}
|
| 268 |
+
else
|
| 269 |
+
{
|
| 270 |
+
window.show();
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
// Now that initialization/startup is done, process any command-line
|
| 274 |
+
// bitcoin: URIs
|
| 275 |
+
QObject::connect(paymentServer, SIGNAL(receivedURI(QString)), &window, SLOT(handleURI(QString)));
|
| 276 |
+
QTimer::singleShot(100, paymentServer, SLOT(uiReady()));
|
| 277 |
+
|
| 278 |
+
app.exec();
|
| 279 |
+
|
| 280 |
+
window.hide();
|
| 281 |
+
window.setClientModel(0);
|
| 282 |
+
window.removeAllWallets();
|
| 283 |
+
guiref = 0;
|
| 284 |
+
}
|
| 285 |
+
// Shutdown the core and its threads, but don't exit Bitcoin-Qt here
|
| 286 |
+
threadGroup.interrupt_all();
|
| 287 |
+
threadGroup.join_all();
|
| 288 |
+
Shutdown();
|
| 289 |
+
}
|
| 290 |
+
else
|
| 291 |
+
{
|
| 292 |
+
threadGroup.interrupt_all();
|
| 293 |
+
threadGroup.join_all();
|
| 294 |
+
Shutdown();
|
| 295 |
+
return 1;
|
| 296 |
+
}
|
| 297 |
+
} catch (std::exception& e) {
|
| 298 |
+
handleRunawayException(&e);
|
| 299 |
+
} catch (...) {
|
| 300 |
+
handleRunawayException(NULL);
|
| 301 |
+
}
|
| 302 |
+
return 0;
|
| 303 |
+
}
|
| 304 |
+
#endif // BITCOIN_QT_TEST
|
pool/shard004/C++/0048637_qgspointclusterrendererwidget.cpp
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
qgspointclusterrendererwidget.cpp
|
| 3 |
+
---------------------------------
|
| 4 |
+
begin : February 2016
|
| 5 |
+
copyright : (C) 2016 by Nyall Dawson
|
| 6 |
+
email : nyall dot dawson at gmail dot 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 "qgspointclusterrendererwidget.h"
|
| 19 |
+
#include "qgspointclusterrenderer.h"
|
| 20 |
+
#include "qgsrendererregistry.h"
|
| 21 |
+
#include "qgsfield.h"
|
| 22 |
+
#include "qgsstyle.h"
|
| 23 |
+
#include "qgssymbolselectordialog.h"
|
| 24 |
+
#include "qgssymbollayerutils.h"
|
| 25 |
+
#include "qgsvectorlayer.h"
|
| 26 |
+
#include "qgsguiutils.h"
|
| 27 |
+
|
| 28 |
+
QgsRendererWidget *QgsPointClusterRendererWidget::create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer )
|
| 29 |
+
{
|
| 30 |
+
return new QgsPointClusterRendererWidget( layer, style, renderer );
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
QgsPointClusterRendererWidget::QgsPointClusterRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer )
|
| 34 |
+
: QgsRendererWidget( layer, style )
|
| 35 |
+
|
| 36 |
+
{
|
| 37 |
+
if ( !layer )
|
| 38 |
+
{
|
| 39 |
+
return;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
//the renderer only applies to point vector layers
|
| 43 |
+
if ( QgsWkbTypes::flatType( layer->wkbType() ) != QgsWkbTypes::Point )
|
| 44 |
+
{
|
| 45 |
+
//setup blank dialog
|
| 46 |
+
mRenderer = nullptr;
|
| 47 |
+
setupBlankUi( layer->name() );
|
| 48 |
+
return;
|
| 49 |
+
}
|
| 50 |
+
setupUi( this );
|
| 51 |
+
connect( mRendererComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPointClusterRendererWidget::mRendererComboBox_currentIndexChanged );
|
| 52 |
+
connect( mDistanceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsPointClusterRendererWidget::mDistanceSpinBox_valueChanged );
|
| 53 |
+
connect( mDistanceUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsPointClusterRendererWidget::mDistanceUnitWidget_changed );
|
| 54 |
+
connect( mRendererSettingsButton, &QPushButton::clicked, this, &QgsPointClusterRendererWidget::mRendererSettingsButton_clicked );
|
| 55 |
+
this->layout()->setContentsMargins( 0, 0, 0, 0 );
|
| 56 |
+
|
| 57 |
+
mDistanceUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
|
| 58 |
+
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
|
| 59 |
+
|
| 60 |
+
mCenterSymbolToolButton->setSymbolType( QgsSymbol::Marker );
|
| 61 |
+
|
| 62 |
+
if ( renderer )
|
| 63 |
+
{
|
| 64 |
+
mRenderer = QgsPointClusterRenderer::convertFromRenderer( renderer );
|
| 65 |
+
}
|
| 66 |
+
if ( !mRenderer )
|
| 67 |
+
{
|
| 68 |
+
mRenderer = new QgsPointClusterRenderer();
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
blockAllSignals( true );
|
| 72 |
+
|
| 73 |
+
//insert possible renderer types
|
| 74 |
+
QStringList rendererList = QgsApplication::rendererRegistry()->renderersList( QgsRendererAbstractMetadata::PointLayer );
|
| 75 |
+
QStringList::const_iterator it = rendererList.constBegin();
|
| 76 |
+
for ( ; it != rendererList.constEnd(); ++it )
|
| 77 |
+
{
|
| 78 |
+
if ( *it != QLatin1String( "pointDisplacement" ) && *it != QLatin1String( "pointCluster" ) && *it != QLatin1String( "heatmapRenderer" ) )
|
| 79 |
+
{
|
| 80 |
+
QgsRendererAbstractMetadata *m = QgsApplication::rendererRegistry()->rendererMetadata( *it );
|
| 81 |
+
mRendererComboBox->addItem( m->icon(), m->visibleName(), *it );
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
mDistanceSpinBox->setValue( mRenderer->tolerance() );
|
| 86 |
+
mDistanceUnitWidget->setUnit( mRenderer->toleranceUnit() );
|
| 87 |
+
mDistanceUnitWidget->setMapUnitScale( mRenderer->toleranceMapUnitScale() );
|
| 88 |
+
mCenterSymbolToolButton->setSymbol( mRenderer->clusterSymbol()->clone() );
|
| 89 |
+
|
| 90 |
+
blockAllSignals( false );
|
| 91 |
+
|
| 92 |
+
//set the appropriate renderer dialog
|
| 93 |
+
if ( mRenderer->embeddedRenderer() )
|
| 94 |
+
{
|
| 95 |
+
QString rendererName = mRenderer->embeddedRenderer()->type();
|
| 96 |
+
int rendererIndex = mRendererComboBox->findData( rendererName );
|
| 97 |
+
if ( rendererIndex != -1 )
|
| 98 |
+
{
|
| 99 |
+
mRendererComboBox->setCurrentIndex( rendererIndex );
|
| 100 |
+
mRendererComboBox_currentIndexChanged( rendererIndex );
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
connect( mCenterSymbolToolButton, &QgsSymbolButton::changed, this, &QgsPointClusterRendererWidget::centerSymbolChanged );
|
| 105 |
+
mCenterSymbolToolButton->setDialogTitle( tr( "Cluster symbol" ) );
|
| 106 |
+
mCenterSymbolToolButton->setLayer( mLayer );
|
| 107 |
+
mCenterSymbolToolButton->registerExpressionContextGenerator( this );
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
QgsPointClusterRendererWidget::~QgsPointClusterRendererWidget()
|
| 111 |
+
{
|
| 112 |
+
delete mRenderer;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
QgsFeatureRenderer *QgsPointClusterRendererWidget::renderer()
|
| 116 |
+
{
|
| 117 |
+
return mRenderer;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
void QgsPointClusterRendererWidget::setContext( const QgsSymbolWidgetContext &context )
|
| 121 |
+
{
|
| 122 |
+
QgsRendererWidget::setContext( context );
|
| 123 |
+
if ( mDistanceUnitWidget )
|
| 124 |
+
mDistanceUnitWidget->setMapCanvas( context.mapCanvas() );
|
| 125 |
+
if ( mCenterSymbolToolButton )
|
| 126 |
+
mCenterSymbolToolButton->setMapCanvas( context.mapCanvas() );
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
void QgsPointClusterRendererWidget::mRendererComboBox_currentIndexChanged( int index )
|
| 130 |
+
{
|
| 131 |
+
QString rendererId = mRendererComboBox->itemData( index ).toString();
|
| 132 |
+
QgsRendererAbstractMetadata *m = QgsApplication::rendererRegistry()->rendererMetadata( rendererId );
|
| 133 |
+
if ( m )
|
| 134 |
+
{
|
| 135 |
+
// unfortunately renderer conversion is only available through the creation of a widget...
|
| 136 |
+
QgsRendererWidget *tempRenderWidget = m->createRendererWidget( mLayer, mStyle, mRenderer->embeddedRenderer()->clone() );
|
| 137 |
+
mRenderer->setEmbeddedRenderer( tempRenderWidget->renderer()->clone() );
|
| 138 |
+
delete tempRenderWidget;
|
| 139 |
+
}
|
| 140 |
+
emit widgetChanged();
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
void QgsPointClusterRendererWidget::mRendererSettingsButton_clicked()
|
| 144 |
+
{
|
| 145 |
+
if ( !mRenderer )
|
| 146 |
+
return;
|
| 147 |
+
|
| 148 |
+
QgsRendererAbstractMetadata *m = QgsApplication::rendererRegistry()->rendererMetadata( mRenderer->embeddedRenderer()->type() );
|
| 149 |
+
if ( m )
|
| 150 |
+
{
|
| 151 |
+
QgsRendererWidget *w = m->createRendererWidget( mLayer, mStyle, mRenderer->embeddedRenderer()->clone() );
|
| 152 |
+
w->setPanelTitle( tr( "Renderer settings" ) );
|
| 153 |
+
|
| 154 |
+
QgsExpressionContextScope scope;
|
| 155 |
+
scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "", true ) );
|
| 156 |
+
scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0, true ) );
|
| 157 |
+
QList< QgsExpressionContextScope > scopes = mContext.additionalExpressionContextScopes();
|
| 158 |
+
scopes << scope;
|
| 159 |
+
QgsSymbolWidgetContext context = mContext;
|
| 160 |
+
context.setAdditionalExpressionContextScopes( scopes );
|
| 161 |
+
w->setContext( context );
|
| 162 |
+
connect( w, &QgsPanelWidget::widgetChanged, this, &QgsPointClusterRendererWidget::updateRendererFromWidget );
|
| 163 |
+
w->setDockMode( this->dockMode() );
|
| 164 |
+
openPanel( w );
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
void QgsPointClusterRendererWidget::mDistanceSpinBox_valueChanged( double d )
|
| 169 |
+
{
|
| 170 |
+
if ( mRenderer )
|
| 171 |
+
{
|
| 172 |
+
mRenderer->setTolerance( d );
|
| 173 |
+
}
|
| 174 |
+
emit widgetChanged();
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
void QgsPointClusterRendererWidget::mDistanceUnitWidget_changed()
|
| 178 |
+
{
|
| 179 |
+
if ( mRenderer )
|
| 180 |
+
{
|
| 181 |
+
mRenderer->setToleranceUnit( mDistanceUnitWidget->unit() );
|
| 182 |
+
mRenderer->setToleranceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
|
| 183 |
+
}
|
| 184 |
+
emit widgetChanged();
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
void QgsPointClusterRendererWidget::blockAllSignals( bool block )
|
| 188 |
+
{
|
| 189 |
+
mRendererComboBox->blockSignals( block );
|
| 190 |
+
mCenterSymbolToolButton->blockSignals( block );
|
| 191 |
+
mDistanceSpinBox->blockSignals( block );
|
| 192 |
+
mDistanceUnitWidget->blockSignals( block );
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
QgsExpressionContext QgsPointClusterRendererWidget::createExpressionContext() const
|
| 196 |
+
{
|
| 197 |
+
QgsExpressionContext context;
|
| 198 |
+
if ( mContext.expressionContext() )
|
| 199 |
+
context = *mContext.expressionContext();
|
| 200 |
+
else
|
| 201 |
+
context.appendScopes( mContext.globalProjectAtlasMapLayerScopes( mLayer ) );
|
| 202 |
+
QgsExpressionContextScope scope;
|
| 203 |
+
scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "", true ) );
|
| 204 |
+
scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0, true ) );
|
| 205 |
+
QList< QgsExpressionContextScope > scopes = mContext.additionalExpressionContextScopes();
|
| 206 |
+
scopes << scope;
|
| 207 |
+
Q_FOREACH ( const QgsExpressionContextScope &s, scopes )
|
| 208 |
+
{
|
| 209 |
+
context << new QgsExpressionContextScope( s );
|
| 210 |
+
}
|
| 211 |
+
return context;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
void QgsPointClusterRendererWidget::centerSymbolChanged()
|
| 215 |
+
{
|
| 216 |
+
mRenderer->setClusterSymbol( mCenterSymbolToolButton->clonedSymbol< QgsMarkerSymbol >() );
|
| 217 |
+
emit widgetChanged();
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
void QgsPointClusterRendererWidget::updateRendererFromWidget()
|
| 221 |
+
{
|
| 222 |
+
QgsRendererWidget *w = qobject_cast<QgsRendererWidget *>( sender() );
|
| 223 |
+
if ( !w )
|
| 224 |
+
return;
|
| 225 |
+
|
| 226 |
+
mRenderer->setEmbeddedRenderer( w->renderer()->clone() );
|
| 227 |
+
emit widgetChanged();
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
void QgsPointClusterRendererWidget::setupBlankUi( const QString &layerName )
|
| 231 |
+
{
|
| 232 |
+
QGridLayout *layout = new QGridLayout( this );
|
| 233 |
+
QLabel *label = new QLabel( tr( "The point cluster renderer only applies to (single) point layers. \n'%1' is not a point layer and cannot be displayed by the point cluster renderer" ).arg( layerName ), this );
|
| 234 |
+
layout->addWidget( label );
|
| 235 |
+
}
|
pool/shard004/C++/0048638_plasma.cc
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/******************************************************************************
|
| 2 |
+
|
| 3 |
+
URBAN
|
| 4 |
+
Copyright (C) 1999 Thomas Nyberg and Jonas Borgström
|
| 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, write to the Free Software
|
| 18 |
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 19 |
+
|
| 20 |
+
Contact the authors:
|
| 21 |
+
Snailmail:
|
| 22 |
+
Thomas Nyberg Jonas Borgström
|
| 23 |
+
Brännbergsvägen 21b Bondevägen 6
|
| 24 |
+
92136 Lycksele 92332 Storuman
|
| 25 |
+
Sweden Sweden
|
| 26 |
+
|
| 27 |
+
or email:
|
| 28 |
+
|
| 29 |
+
thomas.nyberg@usa.net jonas_b@bitsmart.com
|
| 30 |
+
*****************************************************************************/
|
| 31 |
+
#include <string.h>
|
| 32 |
+
#include <allegro.h>
|
| 33 |
+
#include "engine.h"
|
| 34 |
+
#include "object2.h"
|
| 35 |
+
/***************************************************************************/
|
| 36 |
+
#define PLASMA_SPEED 10
|
| 37 |
+
|
| 38 |
+
/***************************************************************************/
|
| 39 |
+
Plasma_o::Plasma_o(int X, int Y, int Z, int Dir, int friendship, int Damage) : Object(X, Y, Z) {
|
| 40 |
+
char filename[512];
|
| 41 |
+
RGB pal[256];
|
| 42 |
+
|
| 43 |
+
width = 1;
|
| 44 |
+
height = 1;
|
| 45 |
+
strength = Damage;
|
| 46 |
+
energy = 1;
|
| 47 |
+
direction = Dir;
|
| 48 |
+
coll_x = 0;
|
| 49 |
+
coll_y = 0;
|
| 50 |
+
coll_width = width;
|
| 51 |
+
coll_height = height;
|
| 52 |
+
counter = 0;
|
| 53 |
+
|
| 54 |
+
images = new BITMAP *;
|
| 55 |
+
|
| 56 |
+
switch (Dir) {
|
| 57 |
+
case LEFT_DIR:
|
| 58 |
+
sprintf(filename, "plasmal/skottv.pcx");
|
| 59 |
+
break;
|
| 60 |
+
case RIGHT_DIR:
|
| 61 |
+
default:
|
| 62 |
+
sprintf(filename, "plasmal/skotth.pcx");
|
| 63 |
+
break;
|
| 64 |
+
}
|
| 65 |
+
images[0] = icache.GetImage(filename, pal);
|
| 66 |
+
if (images[0])
|
| 67 |
+
num_images++;
|
| 68 |
+
|
| 69 |
+
// rect(images[0], 0, 0, images[0]->w - 1, images[0]->h - 1, 15);
|
| 70 |
+
|
| 71 |
+
current_image = 0;
|
| 72 |
+
me = FRIEND_PLASMA;
|
| 73 |
+
friends = (friendship | me | FRIEND_DOOR | FRIEND_FIREBALL | FRIEND_ICEBALL | FRIEND_DEKOR) & ~ENEMY_SCIENTIST;
|
| 74 |
+
enemies = ~friends;
|
| 75 |
+
speed_x = (direction == RIGHT_DIR) ? PLASMA_SPEED : -PLASMA_SPEED;
|
| 76 |
+
|
| 77 |
+
// SOUND.PlaySFX(FIRE_SAMPLE);
|
| 78 |
+
}
|
| 79 |
+
/****************************************************************************/
|
| 80 |
+
int Plasma_o::update() {
|
| 81 |
+
|
| 82 |
+
if (!energy)
|
| 83 |
+
return -1;
|
| 84 |
+
/* if (direction == LEFT_DIR)
|
| 85 |
+
while (ENGINE.check_wall(x + 1, y, z) && speed_x)
|
| 86 |
+
x++;
|
| 87 |
+
else if (direction == RIGHT_DIR)
|
| 88 |
+
while (ENGINE.check_wall(x + coll_width - 1, y, z) && speed_x)
|
| 89 |
+
x--;
|
| 90 |
+
*/
|
| 91 |
+
/* if (direction == LEFT_DIR)
|
| 92 |
+
while (ENGINE.check_wall(x + speed_x, y, z) && speed_x < -1)
|
| 93 |
+
speed_x++;
|
| 94 |
+
else if (direction == RIGHT_DIR)
|
| 95 |
+
while (ENGINE.check_wall(x + coll_width + speed_x, y, z) && speed_x > 1)
|
| 96 |
+
speed_x--;
|
| 97 |
+
*/
|
| 98 |
+
|
| 99 |
+
x += speed_x;
|
| 100 |
+
counter += PLASMA_SPEED;
|
| 101 |
+
|
| 102 |
+
if(counter > 600)
|
| 103 |
+
return -1;
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
/* if (!speed_x) {
|
| 107 |
+
ENGINE.create_effect(new gnistor_o(x, y + height, z, direction));
|
| 108 |
+
energy = 0;
|
| 109 |
+
}*/
|
| 110 |
+
// Check collision with walls
|
| 111 |
+
if(ENGINE.check_wall((direction == LEFT_DIR) ? x : x + coll_width, y, z)) {
|
| 112 |
+
// ENGINE.create_effect(new gnistor_o(x, y + height, z, direction));
|
| 113 |
+
energy = 0;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return 0;
|
| 117 |
+
}
|
| 118 |
+
/****************************************************************************/
|
| 119 |
+
void Plasma_o::Collision(Object *o) {
|
| 120 |
+
|
| 121 |
+
if (o->GetWho() & enemies)
|
| 122 |
+
energy = 0;
|
| 123 |
+
}
|
| 124 |
+
/****************************************************************************/
|
| 125 |
+
Plasma_o::~Plasma_o() {
|
| 126 |
+
}
|
| 127 |
+
/****************************************************************************/
|
pool/shard004/C++/0048649_Snapshot.cpp
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <cassert>
|
| 2 |
+
#include <leveldb/db.h>
|
| 3 |
+
|
| 4 |
+
#include "easylogging++.h"
|
| 5 |
+
#include "Snapshot.h"
|
| 6 |
+
|
| 7 |
+
namespace DataBase
|
| 8 |
+
{
|
| 9 |
+
using namespace leveldb;
|
| 10 |
+
|
| 11 |
+
Snapshot::Snapshot()
|
| 12 |
+
: m_shapshot(nullptr)
|
| 13 |
+
{
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
Snapshot::Snapshot(const std::weak_ptr<leveldb::DB> &backend, const leveldb::Snapshot *snapshot)
|
| 17 |
+
: m_backend(backend), m_shapshot(snapshot)
|
| 18 |
+
{
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
Snapshot::~Snapshot()
|
| 22 |
+
{
|
| 23 |
+
if (auto spt = m_backend.lock()) {
|
| 24 |
+
spt->ReleaseSnapshot(m_shapshot);
|
| 25 |
+
m_shapshot = nullptr;
|
| 26 |
+
}
|
| 27 |
+
else {
|
| 28 |
+
LOG(ERROR) << "The database is deleted. Dangling reference on snapshot!";
|
| 29 |
+
assert(0);
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
ByteArray Snapshot::get(const std::string &key)
|
| 34 |
+
{
|
| 35 |
+
if (auto spt = m_backend.lock()) {
|
| 36 |
+
ReadOptions options;
|
| 37 |
+
options.snapshot = m_shapshot;
|
| 38 |
+
|
| 39 |
+
ByteArray value;
|
| 40 |
+
const auto status = spt->Get(options, Slice(key), &value);
|
| 41 |
+
if (!status.ok()) {
|
| 42 |
+
LOG(ERROR)
|
| 43 |
+
<< "Error reading data from snapshot"
|
| 44 |
+
<< status.ToString();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
return value;
|
| 48 |
+
|
| 49 |
+
}
|
| 50 |
+
else {
|
| 51 |
+
LOG(ERROR) << "The database is deleted. Dangling reference on snapshot!";
|
| 52 |
+
return ByteArray();
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
Iterator Snapshot::iterator()
|
| 57 |
+
{
|
| 58 |
+
if (auto spt = m_backend.lock()) {
|
| 59 |
+
ReadOptions options;
|
| 60 |
+
options.snapshot = m_shapshot;
|
| 61 |
+
std::unique_ptr<leveldb::Iterator> rawIterator(spt->NewIterator(options));
|
| 62 |
+
|
| 63 |
+
return Iterator(std::move(rawIterator));
|
| 64 |
+
|
| 65 |
+
}
|
| 66 |
+
else {
|
| 67 |
+
LOG(ERROR) << "The database is deleted. Dangling reference on snapshot!";
|
| 68 |
+
return Iterator();
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
}
|
pool/shard004/C++/0048653_XDisplay.cpp
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "XDisplay.h"
|
| 2 |
+
|
| 3 |
+
#include "../Graphics/Render.h"
|
| 4 |
+
|
| 5 |
+
using namespace Render;
|
| 6 |
+
|
| 7 |
+
CXDisplay::CXDisplay(const int p_ciWidth, const int p_ciHeight)
|
| 8 |
+
{
|
| 9 |
+
GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
|
| 10 |
+
XSetWindowAttributes swa;
|
| 11 |
+
|
| 12 |
+
m_Display = XOpenDisplay(NULL);
|
| 13 |
+
Window root = DefaultRootWindow(m_Display);
|
| 14 |
+
|
| 15 |
+
XVisualInfo* vi = glXChooseVisual(m_Display, 0, att);
|
| 16 |
+
Colormap cmap = XCreateColormap(m_Display, root, vi->visual, AllocNone);
|
| 17 |
+
|
| 18 |
+
swa.colormap = cmap;
|
| 19 |
+
swa.event_mask = ExposureMask;
|
| 20 |
+
|
| 21 |
+
m_Window = XCreateWindow(m_Display, root, 0, 0, p_ciWidth, p_ciHeight, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa);
|
| 22 |
+
|
| 23 |
+
XMapWindow(m_Display, m_Window);
|
| 24 |
+
XStoreName(m_Display, m_Window, "Damned Quest");
|
| 25 |
+
|
| 26 |
+
m_Context = glXCreateContext(m_Display, vi, NULL, GL_TRUE);
|
| 27 |
+
glXMakeCurrent(m_Display, m_Window, m_Context);
|
| 28 |
+
|
| 29 |
+
XSelectInput(m_Display, m_Window, KeyPressMask | KeyReleaseMask);
|
| 30 |
+
|
| 31 |
+
Graphics::CRender::Prepare();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
CXDisplay::~CXDisplay()
|
| 35 |
+
{
|
| 36 |
+
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
void CXDisplay::Close()
|
| 40 |
+
{
|
| 41 |
+
glXMakeCurrent(m_Display, None, NULL);
|
| 42 |
+
glXDestroyContext(m_Display, m_Context);
|
| 43 |
+
XDestroyWindow(m_Display, m_Window);
|
| 44 |
+
XCloseDisplay(m_Display);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
void CXDisplay::HandleEvents()
|
| 48 |
+
{
|
| 49 |
+
XWindowAttributes gwa;
|
| 50 |
+
|
| 51 |
+
if(XCheckWindowEvent(m_Display, m_Window, ExposureMask | KeyPressMask | KeyReleaseMask, &m_Event)){
|
| 52 |
+
switch(m_Event.type)
|
| 53 |
+
{
|
| 54 |
+
case Expose:
|
| 55 |
+
XGetWindowAttributes(m_Display, m_Window, &gwa);
|
| 56 |
+
glViewport(0, 0, gwa.width, gwa.height);
|
| 57 |
+
m_fnRedraw();
|
| 58 |
+
SwapBuffers();
|
| 59 |
+
break;
|
| 60 |
+
case KeyPress:
|
| 61 |
+
{
|
| 62 |
+
XKeyEvent* pKey = reinterpret_cast<XKeyEvent*>(&m_Event);
|
| 63 |
+
m_fnKeyPress(pKey->keycode);
|
| 64 |
+
}
|
| 65 |
+
break;
|
| 66 |
+
case KeyRelease:
|
| 67 |
+
{
|
| 68 |
+
XKeyEvent* pKey = reinterpret_cast<XKeyEvent*>(&m_Event);
|
| 69 |
+
m_fnKeyRelease(pKey->keycode);
|
| 70 |
+
}
|
| 71 |
+
break;
|
| 72 |
+
default:
|
| 73 |
+
DEBUG(1, __FUNCTION__, m_Event.type);
|
| 74 |
+
break;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
void CXDisplay::SwapBuffers()
|
| 80 |
+
{
|
| 81 |
+
glXSwapBuffers(m_Display, m_Window);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
void CXDisplay::ListenKeyPress(std::function<void(int)> p_fnEvent)
|
| 85 |
+
{
|
| 86 |
+
m_fnKeyPress = p_fnEvent;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void CXDisplay::ListenKeyRelease(std::function<void(int)> p_fnEvent)
|
| 90 |
+
{
|
| 91 |
+
m_fnKeyRelease = p_fnEvent;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
void CXDisplay::ListenRedraw(std::function<void()> p_fnEvent)
|
| 95 |
+
{
|
| 96 |
+
m_fnRedraw = p_fnEvent;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
void CXDisplay::Clear()
|
| 100 |
+
{
|
| 101 |
+
Graphics::CRender::Clear();
|
| 102 |
+
}
|
pool/shard004/C++/0048657_NamedParameter.cpp
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#define BBCDEBUG_LEVEL 1
|
| 3 |
+
#include "NamedParameter.h"
|
| 4 |
+
|
| 5 |
+
BBC_AUDIOTOOLBOX_START
|
| 6 |
+
|
| 7 |
+
#if ENABLE_JSON
|
| 8 |
+
namespace json
|
| 9 |
+
{
|
| 10 |
+
/*--------------------------------------------------------------------------------*/
|
| 11 |
+
/** Convert from list of NamedParameter objects to a JSON object
|
| 12 |
+
*
|
| 13 |
+
* @param list of NamedParameter objects
|
| 14 |
+
* @param obj JSON object to be populated
|
| 15 |
+
* @param all true to include parameters that are at their default
|
| 16 |
+
*/
|
| 17 |
+
/*--------------------------------------------------------------------------------*/
|
| 18 |
+
void ToJSON(const INamedParameter * const *list, uint_t n, JSONValue& obj, bool all)
|
| 19 |
+
{
|
| 20 |
+
uint_t i;
|
| 21 |
+
|
| 22 |
+
// iterate through each parameter
|
| 23 |
+
for (i = 0; i < n; i++)
|
| 24 |
+
{
|
| 25 |
+
const INamedParameter *parameter = list[i];
|
| 26 |
+
|
| 27 |
+
// only add to object if parameter has been set or 'all' as been set
|
| 28 |
+
if (all || parameter->IsSet()) parameter->ToJSON(obj[parameter->GetName()]);
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
void ToJSON(const std::vector<INamedParameter *>& list, JSONValue& obj, bool all)
|
| 32 |
+
{
|
| 33 |
+
ToJSON(&list[0], list.size(), obj, all);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/*--------------------------------------------------------------------------------*/
|
| 37 |
+
/** Convert from a JSON object to a set of NamedParameters
|
| 38 |
+
*
|
| 39 |
+
* @param obj JSON object to be as the source
|
| 40 |
+
* @param list of NamedParameter objects to extract
|
| 41 |
+
* @param reset true to reset parameters that are not specified
|
| 42 |
+
*
|
| 43 |
+
* @return true if all [found] parameters were evaluated properly
|
| 44 |
+
*/
|
| 45 |
+
/*--------------------------------------------------------------------------------*/
|
| 46 |
+
bool FromJSON(const JSONValue& obj, INamedParameter * const *list, uint_t n, bool reset)
|
| 47 |
+
{
|
| 48 |
+
uint_t i;
|
| 49 |
+
bool success = true;
|
| 50 |
+
|
| 51 |
+
// iterate through each parameter
|
| 52 |
+
for (i = 0; i < n; i++)
|
| 53 |
+
{
|
| 54 |
+
INamedParameter *parameter = list[i];
|
| 55 |
+
|
| 56 |
+
if (obj.isMember(parameter->GetName()))
|
| 57 |
+
{
|
| 58 |
+
// if parameter exists, set it
|
| 59 |
+
BBCDEBUG3(("Member '%s' found in '%s'", parameter->GetName(), ToJSONString(obj, true).c_str()));
|
| 60 |
+
success &= parameter->FromJSON(obj[parameter->GetName()]);
|
| 61 |
+
}
|
| 62 |
+
else if (reset)
|
| 63 |
+
{
|
| 64 |
+
// else reset parameter to its default
|
| 65 |
+
BBCDEBUG2(("Member '%s' *not* found in '%s'", parameter->GetName(), ToJSONString(obj, true).c_str()));
|
| 66 |
+
parameter->Reset();
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
return success;
|
| 71 |
+
}
|
| 72 |
+
bool FromJSON(const JSONValue& obj, const std::vector<INamedParameter *>& list, bool reset)
|
| 73 |
+
{
|
| 74 |
+
return FromJSON(obj, &list[0], list.size(), reset);
|
| 75 |
+
}
|
| 76 |
+
};
|
| 77 |
+
#endif
|
| 78 |
+
|
| 79 |
+
BBC_AUDIOTOOLBOX_END
|
pool/shard004/C++/0048660_suppression_gain_unittest.cc
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
| 3 |
+
*
|
| 4 |
+
* Use of this source code is governed by a BSD-style license
|
| 5 |
+
* that can be found in the LICENSE file in the root of the source
|
| 6 |
+
* tree. An additional intellectual property rights grant can be found
|
| 7 |
+
* in the file PATENTS. All contributing project authors may
|
| 8 |
+
* be found in the AUTHORS file in the root of the source tree.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include "modules/audio_processing/aec3/suppression_gain.h"
|
| 12 |
+
|
| 13 |
+
#include "modules/audio_processing/aec3/aec_state.h"
|
| 14 |
+
#include "modules/audio_processing/aec3/render_delay_buffer.h"
|
| 15 |
+
#include "modules/audio_processing/aec3/subtractor.h"
|
| 16 |
+
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
| 17 |
+
#include BOSS_WEBRTC_U_rtc_base__checks_h //original-code:"rtc_base/checks.h"
|
| 18 |
+
#include BOSS_WEBRTC_U_system_wrappers__include__cpu_features_wrapper_h //original-code:"system_wrappers/include/cpu_features_wrapper.h"
|
| 19 |
+
#include BOSS_WEBRTC_U_test__gtest_h //original-code:"test/gtest.h"
|
| 20 |
+
#include BOSS_WEBRTC_U_typedefs_h //original-code:"typedefs.h" // NOLINT(build/include)
|
| 21 |
+
|
| 22 |
+
namespace webrtc {
|
| 23 |
+
namespace aec3 {
|
| 24 |
+
|
| 25 |
+
#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
|
| 26 |
+
|
| 27 |
+
// Verifies that the check for non-null output gains works.
|
| 28 |
+
TEST(SuppressionGain, NullOutputGains) {
|
| 29 |
+
std::array<float, kFftLengthBy2Plus1> E2;
|
| 30 |
+
std::array<float, kFftLengthBy2Plus1> R2;
|
| 31 |
+
std::array<float, kFftLengthBy2Plus1> N2;
|
| 32 |
+
E2.fill(0.f);
|
| 33 |
+
R2.fill(0.f);
|
| 34 |
+
N2.fill(0.f);
|
| 35 |
+
float high_bands_gain;
|
| 36 |
+
AecState aec_state(EchoCanceller3Config{});
|
| 37 |
+
EXPECT_DEATH(SuppressionGain(EchoCanceller3Config{}, DetectOptimization())
|
| 38 |
+
.GetGain(E2, R2, N2, RenderSignalAnalyzer(), aec_state,
|
| 39 |
+
std::vector<std::vector<float>>(
|
| 40 |
+
3, std::vector<float>(kBlockSize, 0.f)),
|
| 41 |
+
&high_bands_gain, nullptr),
|
| 42 |
+
"");
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
#endif
|
| 46 |
+
|
| 47 |
+
// Does a sanity check that the gains are correctly computed.
|
| 48 |
+
TEST(SuppressionGain, BasicGainComputation) {
|
| 49 |
+
SuppressionGain suppression_gain(EchoCanceller3Config(),
|
| 50 |
+
DetectOptimization());
|
| 51 |
+
RenderSignalAnalyzer analyzer;
|
| 52 |
+
float high_bands_gain;
|
| 53 |
+
std::array<float, kFftLengthBy2Plus1> E2;
|
| 54 |
+
std::array<float, kFftLengthBy2Plus1> Y2;
|
| 55 |
+
std::array<float, kFftLengthBy2Plus1> R2;
|
| 56 |
+
std::array<float, kFftLengthBy2Plus1> N2;
|
| 57 |
+
std::array<float, kFftLengthBy2Plus1> g;
|
| 58 |
+
std::array<float, kBlockSize> s;
|
| 59 |
+
std::vector<std::vector<float>> x(1, std::vector<float>(kBlockSize, 0.f));
|
| 60 |
+
EchoCanceller3Config config;
|
| 61 |
+
AecState aec_state(config);
|
| 62 |
+
ApmDataDumper data_dumper(42);
|
| 63 |
+
Subtractor subtractor(config, &data_dumper, DetectOptimization());
|
| 64 |
+
std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
|
| 65 |
+
RenderDelayBuffer::Create(config, 3));
|
| 66 |
+
|
| 67 |
+
// Verify the functionality for forcing a zero gain.
|
| 68 |
+
E2.fill(1000000000.f);
|
| 69 |
+
R2.fill(10000000000000.f);
|
| 70 |
+
N2.fill(0.f);
|
| 71 |
+
s.fill(10.f);
|
| 72 |
+
aec_state.Update(subtractor.FilterFrequencyResponse(),
|
| 73 |
+
subtractor.FilterImpulseResponse(),
|
| 74 |
+
subtractor.ConvergedFilter(),
|
| 75 |
+
*render_delay_buffer->GetRenderBuffer(), E2, Y2, s, false);
|
| 76 |
+
suppression_gain.GetGain(E2, R2, N2, analyzer, aec_state, x, &high_bands_gain,
|
| 77 |
+
&g);
|
| 78 |
+
std::for_each(g.begin(), g.end(), [](float a) { EXPECT_FLOAT_EQ(0.f, a); });
|
| 79 |
+
EXPECT_FLOAT_EQ(0.f, high_bands_gain);
|
| 80 |
+
|
| 81 |
+
// Ensure that a strong noise is detected to mask any echoes.
|
| 82 |
+
E2.fill(10.f);
|
| 83 |
+
Y2.fill(10.f);
|
| 84 |
+
R2.fill(0.1f);
|
| 85 |
+
N2.fill(100.f);
|
| 86 |
+
// Ensure that the gain is no longer forced to zero.
|
| 87 |
+
for (int k = 0; k <= kNumBlocksPerSecond / 5 + 1; ++k) {
|
| 88 |
+
aec_state.Update(subtractor.FilterFrequencyResponse(),
|
| 89 |
+
subtractor.FilterImpulseResponse(),
|
| 90 |
+
subtractor.ConvergedFilter(),
|
| 91 |
+
*render_delay_buffer->GetRenderBuffer(), E2, Y2, s, false);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
for (int k = 0; k < 100; ++k) {
|
| 95 |
+
aec_state.Update(subtractor.FilterFrequencyResponse(),
|
| 96 |
+
subtractor.FilterImpulseResponse(),
|
| 97 |
+
subtractor.ConvergedFilter(),
|
| 98 |
+
*render_delay_buffer->GetRenderBuffer(), E2, Y2, s, false);
|
| 99 |
+
suppression_gain.GetGain(E2, R2, N2, analyzer, aec_state, x,
|
| 100 |
+
&high_bands_gain, &g);
|
| 101 |
+
}
|
| 102 |
+
std::for_each(g.begin(), g.end(),
|
| 103 |
+
[](float a) { EXPECT_NEAR(1.f, a, 0.001); });
|
| 104 |
+
|
| 105 |
+
// Ensure that a strong nearend is detected to mask any echoes.
|
| 106 |
+
E2.fill(100.f);
|
| 107 |
+
Y2.fill(100.f);
|
| 108 |
+
R2.fill(0.1f);
|
| 109 |
+
N2.fill(0.f);
|
| 110 |
+
for (int k = 0; k < 100; ++k) {
|
| 111 |
+
aec_state.Update(subtractor.FilterFrequencyResponse(),
|
| 112 |
+
subtractor.FilterImpulseResponse(),
|
| 113 |
+
subtractor.ConvergedFilter(),
|
| 114 |
+
*render_delay_buffer->GetRenderBuffer(), E2, Y2, s, false);
|
| 115 |
+
suppression_gain.GetGain(E2, R2, N2, analyzer, aec_state, x,
|
| 116 |
+
&high_bands_gain, &g);
|
| 117 |
+
}
|
| 118 |
+
std::for_each(g.begin(), g.end(),
|
| 119 |
+
[](float a) { EXPECT_NEAR(1.f, a, 0.001); });
|
| 120 |
+
|
| 121 |
+
// Ensure that a strong echo is suppressed.
|
| 122 |
+
E2.fill(1000000000.f);
|
| 123 |
+
R2.fill(10000000000000.f);
|
| 124 |
+
N2.fill(0.f);
|
| 125 |
+
for (int k = 0; k < 10; ++k) {
|
| 126 |
+
suppression_gain.GetGain(E2, R2, N2, analyzer, aec_state, x,
|
| 127 |
+
&high_bands_gain, &g);
|
| 128 |
+
}
|
| 129 |
+
std::for_each(g.begin(), g.end(),
|
| 130 |
+
[](float a) { EXPECT_NEAR(0.f, a, 0.001); });
|
| 131 |
+
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
} // namespace aec3
|
| 135 |
+
} // namespace webrtc
|
pool/shard004/C++/0048662_satcommon.cc
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// -*- coding: utf-8 -*-
|
| 2 |
+
// Copyright (C) 2013-2017 Laboratoire de Recherche et Développement
|
| 3 |
+
// de l'Epita (LRDE).
|
| 4 |
+
//
|
| 5 |
+
// This file is part of Spot, a model checking library.
|
| 6 |
+
//
|
| 7 |
+
// Spot is free software; you can redistribute it and/or modify it
|
| 8 |
+
// under the terms of the GNU General Public License as published by
|
| 9 |
+
// the Free Software Foundation; either version 3 of the License, or
|
| 10 |
+
// (at your option) any later version.
|
| 11 |
+
//
|
| 12 |
+
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
| 13 |
+
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
| 14 |
+
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
| 15 |
+
// License for more details.
|
| 16 |
+
//
|
| 17 |
+
// You should have received a copy of the GNU General Public License
|
| 18 |
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
#include <fstream>
|
| 22 |
+
#include <set>
|
| 23 |
+
#include <cassert>
|
| 24 |
+
#include <spot/misc/escape.hh>
|
| 25 |
+
#include <spot/priv/satcommon.hh>
|
| 26 |
+
#include <spot/twa/bddprint.hh>
|
| 27 |
+
#include <spot/twaalgos/hoa.hh>
|
| 28 |
+
#include <spot/twaalgos/stats.hh>
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
#if DEBUG_CMN
|
| 32 |
+
#define print_debug std::cerr
|
| 33 |
+
#else
|
| 34 |
+
#define print_debug while (0) std::cout
|
| 35 |
+
#endif
|
| 36 |
+
|
| 37 |
+
namespace spot
|
| 38 |
+
{
|
| 39 |
+
void
|
| 40 |
+
vars_helper::init(unsigned size_src, unsigned size_cond, unsigned size_dst,
|
| 41 |
+
unsigned size_nacc, unsigned size_path, bool state_based, bool dtbasat)
|
| 42 |
+
{
|
| 43 |
+
print_debug << "init(" << size_src << ',' << size_cond << ',' << size_dst
|
| 44 |
+
<< ',' << size_nacc << ',' << size_path << ',' << state_based << ")\n";
|
| 45 |
+
|
| 46 |
+
size_src_ = size_src;
|
| 47 |
+
size_cond_ = size_cond;
|
| 48 |
+
size_dst_ = size_dst;
|
| 49 |
+
size_nacc_ = size_nacc;
|
| 50 |
+
size_path_ = size_path;
|
| 51 |
+
state_based_ = state_based;
|
| 52 |
+
dtbasat_ = dtbasat;
|
| 53 |
+
|
| 54 |
+
sn_mult_ = size_src * size_nacc;
|
| 55 |
+
cd_mult_ = size_cond * size_dst;
|
| 56 |
+
dn_mult_ = size_dst * size_nacc;
|
| 57 |
+
sd_mult_ = size_src * size_dst;
|
| 58 |
+
dr_mult_ = size_dst * 2;
|
| 59 |
+
sdr_mult_ = sd_mult_ * 2;
|
| 60 |
+
cdn_mult_ = size_cond * size_dst * size_nacc;
|
| 61 |
+
scd_mult_ = size_src * size_cond * size_dst;
|
| 62 |
+
psd_mult_ = size_path * size_src * size_dst;
|
| 63 |
+
scdn_mult_ = scd_mult_ * size_nacc;
|
| 64 |
+
scdnp_mult_ = scdn_mult_ * size_path;
|
| 65 |
+
|
| 66 |
+
assert(scdnp_mult_ != 0);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
void
|
| 70 |
+
vars_helper::declare_all_vars(int& min_t)
|
| 71 |
+
{
|
| 72 |
+
min_t_ = min_t;
|
| 73 |
+
min_ta_ = min_t_ + scd_mult_;
|
| 74 |
+
if (!state_based_)
|
| 75 |
+
min_p_ = min_ta_ + scdn_mult_;
|
| 76 |
+
else
|
| 77 |
+
min_p_ = min_ta_ + sn_mult_;
|
| 78 |
+
|
| 79 |
+
if (!dtbasat_)
|
| 80 |
+
max_p_ = min_p_ + psd_mult_ - 1;
|
| 81 |
+
else
|
| 82 |
+
max_p_ = min_p_ + psd_mult_ * 2 - 1;
|
| 83 |
+
|
| 84 |
+
print_debug << "declare_all_trans(" << min_t << ") --> min_t_<"
|
| 85 |
+
<< min_t_ << ">, min_ta_<" << min_ta_ << ">, min_p<"
|
| 86 |
+
<< min_p_ << ">, max_p<" << max_p_ << ">\n";
|
| 87 |
+
|
| 88 |
+
// Update satdict.nvars.
|
| 89 |
+
// max_p_ - 1 was added after noticing that in some cases in dtbasat, the
|
| 90 |
+
// last variable is not used and some sat solver can complain about the
|
| 91 |
+
// wong number of variable in cnf mode. No worries, if it turns out to be
|
| 92 |
+
// used somewhere, it will be taken into account.
|
| 93 |
+
min_t = dtbasat_ ? max_p_ - 1 : max_p_;
|
| 94 |
+
assert(min_t != min_t_);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
std::string
|
| 98 |
+
vars_helper::format_t(bdd_dict_ptr& debug_dict, unsigned src, bdd& cond,
|
| 99 |
+
unsigned dst)
|
| 100 |
+
{
|
| 101 |
+
std::ostringstream buffer;
|
| 102 |
+
buffer << '<' << src << ',' << bdd_format_formula(debug_dict, cond)
|
| 103 |
+
<< ',' << dst << '>';
|
| 104 |
+
return buffer.str();
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
std::string
|
| 108 |
+
vars_helper::format_ta(bdd_dict_ptr& debug_dict,
|
| 109 |
+
const acc_cond* debug_cand_acc, unsigned src, bdd& cond, unsigned dst,
|
| 110 |
+
const acc_cond::mark_t& acc)
|
| 111 |
+
{
|
| 112 |
+
std::ostringstream buffer;
|
| 113 |
+
buffer << '<' << src << ',' << bdd_format_formula(debug_dict, cond)
|
| 114 |
+
<< ',' << debug_cand_acc->format(acc) << ',' << dst << '>';
|
| 115 |
+
return buffer.str();
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
std::string
|
| 119 |
+
vars_helper::format_p(const acc_cond* debug_cand_acc,
|
| 120 |
+
const acc_cond* debug_ref_acc, unsigned src_cand, unsigned src_ref,
|
| 121 |
+
unsigned dst_cand, unsigned dst_ref, acc_cond::mark_t acc_cand,
|
| 122 |
+
acc_cond::mark_t acc_ref)
|
| 123 |
+
{
|
| 124 |
+
std::ostringstream buffer;
|
| 125 |
+
buffer << '<' << src_cand << ',' << src_ref << ',' << dst_cand << ','
|
| 126 |
+
<< dst_ref << ", " << debug_cand_acc->format(acc_cand) << ", "
|
| 127 |
+
<< debug_ref_acc->format(acc_ref) << '>';
|
| 128 |
+
return buffer.str();
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
std::string
|
| 132 |
+
vars_helper::format_p(unsigned src_cand, unsigned src_ref, unsigned dst_cand,
|
| 133 |
+
unsigned dst_ref)
|
| 134 |
+
{
|
| 135 |
+
std::ostringstream buffer;
|
| 136 |
+
buffer << '<' << src_cand << ',' << src_ref;
|
| 137 |
+
if (src_cand == dst_cand && src_ref == dst_ref)
|
| 138 |
+
buffer << '>';
|
| 139 |
+
else
|
| 140 |
+
buffer << ',' << dst_cand << ',' << dst_ref << '>';
|
| 141 |
+
return buffer.str();
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
void
|
| 145 |
+
print_log(timer_map& t, int target_state_number,
|
| 146 |
+
twa_graph_ptr& res, satsolver& solver)
|
| 147 |
+
{
|
| 148 |
+
// Always copy the environment variable into a static string,
|
| 149 |
+
// so that we (1) look it up once, but (2) won't crash if the
|
| 150 |
+
// environment is changed.
|
| 151 |
+
static std::string log = []()
|
| 152 |
+
{
|
| 153 |
+
auto s = getenv("SPOT_SATLOG");
|
| 154 |
+
return s ? s : "";
|
| 155 |
+
}();
|
| 156 |
+
if (!log.empty())
|
| 157 |
+
{
|
| 158 |
+
std::fstream out(log,
|
| 159 |
+
std::ios_base::app | std::ios_base::out);
|
| 160 |
+
out.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
| 161 |
+
const timer& te = t.timer("encode");
|
| 162 |
+
const timer& ts = t.timer("solve");
|
| 163 |
+
out << target_state_number << ',';
|
| 164 |
+
if (res)
|
| 165 |
+
{
|
| 166 |
+
twa_sub_statistics st = sub_stats_reachable(res);
|
| 167 |
+
out << st.states << ',' << st.edges << ',' << st.transitions;
|
| 168 |
+
}
|
| 169 |
+
else
|
| 170 |
+
{
|
| 171 |
+
out << ",,";
|
| 172 |
+
}
|
| 173 |
+
std::pair<int, int> s = solver.stats(); // sat_stats
|
| 174 |
+
out << ','
|
| 175 |
+
<< s.first << ',' << s.second << ','
|
| 176 |
+
<< te.utime() + te.cutime() << ','
|
| 177 |
+
<< te.stime() + te.cstime() << ','
|
| 178 |
+
<< ts.utime() + ts.cutime() << ','
|
| 179 |
+
<< ts.stime() + ts.cstime() << ",\"";
|
| 180 |
+
if (res)
|
| 181 |
+
{
|
| 182 |
+
std::ostringstream f;
|
| 183 |
+
print_hoa(f, res, "l");
|
| 184 |
+
escape_rfc4180(out, f.str());
|
| 185 |
+
}
|
| 186 |
+
out << "\"\n";
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
int
|
| 191 |
+
get_number_of_distinct_vals(std::vector<unsigned> v)
|
| 192 |
+
{
|
| 193 |
+
std::set<unsigned> distinct;
|
| 194 |
+
for (auto it = v.begin(); it != v.end(); ++it)
|
| 195 |
+
distinct.insert(*it);
|
| 196 |
+
return distinct.size();
|
| 197 |
+
}
|
| 198 |
+
}
|
pool/shard004/C++/0048664_main_tests.cpp
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2014-2016 The nealcoin 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 "chainparams.h"
|
| 6 |
+
#include "validation.h"
|
| 7 |
+
#include "net.h"
|
| 8 |
+
|
| 9 |
+
#include "test/test_nealcoin.h"
|
| 10 |
+
|
| 11 |
+
#include <boost/signals2/signal.hpp>
|
| 12 |
+
#include <boost/test/unit_test.hpp>
|
| 13 |
+
|
| 14 |
+
BOOST_FIXTURE_TEST_SUITE(main_tests, TestingSetup)
|
| 15 |
+
|
| 16 |
+
static void TestBlockSubsidyHalvings(const Consensus::Params& consensusParams)
|
| 17 |
+
{
|
| 18 |
+
int maxHalvings = 64;
|
| 19 |
+
CAmount nInitialSubsidy = 50 * COIN;
|
| 20 |
+
|
| 21 |
+
CAmount nPreviousSubsidy = nInitialSubsidy * 2; // for height == 0
|
| 22 |
+
BOOST_CHECK_EQUAL(nPreviousSubsidy, nInitialSubsidy * 2);
|
| 23 |
+
for (int nHalvings = 0; nHalvings < maxHalvings; nHalvings++) {
|
| 24 |
+
int nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval;
|
| 25 |
+
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
|
| 26 |
+
BOOST_CHECK(nSubsidy <= nInitialSubsidy);
|
| 27 |
+
BOOST_CHECK_EQUAL(nSubsidy, nPreviousSubsidy / 2);
|
| 28 |
+
nPreviousSubsidy = nSubsidy;
|
| 29 |
+
}
|
| 30 |
+
BOOST_CHECK_EQUAL(GetBlockSubsidy(maxHalvings * consensusParams.nSubsidyHalvingInterval, consensusParams), 0);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval)
|
| 34 |
+
{
|
| 35 |
+
Consensus::Params consensusParams;
|
| 36 |
+
consensusParams.nSubsidyHalvingInterval = nSubsidyHalvingInterval;
|
| 37 |
+
TestBlockSubsidyHalvings(consensusParams);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
BOOST_AUTO_TEST_CASE(block_subsidy_test)
|
| 41 |
+
{
|
| 42 |
+
TestBlockSubsidyHalvings(Params(CBaseChainParams::MAIN).GetConsensus()); // As in main
|
| 43 |
+
TestBlockSubsidyHalvings(150); // As in regtest
|
| 44 |
+
TestBlockSubsidyHalvings(1000); // Just another interval
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
BOOST_AUTO_TEST_CASE(subsidy_limit_test)
|
| 48 |
+
{
|
| 49 |
+
const Consensus::Params& consensusParams = Params(CBaseChainParams::MAIN).GetConsensus();
|
| 50 |
+
CAmount nSum = 0;
|
| 51 |
+
for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
|
| 52 |
+
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
|
| 53 |
+
BOOST_CHECK(nSubsidy <= 50 * COIN);
|
| 54 |
+
nSum += nSubsidy * 1000;
|
| 55 |
+
BOOST_CHECK(MoneyRange(nSum));
|
| 56 |
+
}
|
| 57 |
+
BOOST_CHECK_EQUAL(nSum, 2099999997690000ULL);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
bool ReturnFalse() { return false; }
|
| 61 |
+
bool ReturnTrue() { return true; }
|
| 62 |
+
|
| 63 |
+
BOOST_AUTO_TEST_CASE(test_combiner_all)
|
| 64 |
+
{
|
| 65 |
+
boost::signals2::signal<bool (), CombinerAll> Test;
|
| 66 |
+
BOOST_CHECK(Test());
|
| 67 |
+
Test.connect(&ReturnFalse);
|
| 68 |
+
BOOST_CHECK(!Test());
|
| 69 |
+
Test.connect(&ReturnTrue);
|
| 70 |
+
BOOST_CHECK(!Test());
|
| 71 |
+
Test.disconnect(&ReturnFalse);
|
| 72 |
+
BOOST_CHECK(Test());
|
| 73 |
+
Test.disconnect(&ReturnTrue);
|
| 74 |
+
BOOST_CHECK(Test());
|
| 75 |
+
}
|
| 76 |
+
BOOST_AUTO_TEST_SUITE_END()
|
pool/shard004/C++/0048670_time.cc
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/time/time.h"
|
| 6 |
+
|
| 7 |
+
#include <limits>
|
| 8 |
+
#include <ostream>
|
| 9 |
+
|
| 10 |
+
#include "base/float_util.h"
|
| 11 |
+
#include "base/logging.h"
|
| 12 |
+
#include "base/third_party/nspr/prtime.h"
|
| 13 |
+
#include "base/third_party/nspr/prtypes.h"
|
| 14 |
+
|
| 15 |
+
namespace base {
|
| 16 |
+
|
| 17 |
+
// TimeDelta ------------------------------------------------------------------
|
| 18 |
+
|
| 19 |
+
int TimeDelta::InDays() const {
|
| 20 |
+
return static_cast<int>(delta_ / Time::kMicrosecondsPerDay);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
int TimeDelta::InHours() const {
|
| 24 |
+
return static_cast<int>(delta_ / Time::kMicrosecondsPerHour);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
int TimeDelta::InMinutes() const {
|
| 28 |
+
return static_cast<int>(delta_ / Time::kMicrosecondsPerMinute);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
double TimeDelta::InSecondsF() const {
|
| 32 |
+
return static_cast<double>(delta_) / Time::kMicrosecondsPerSecond;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
int64 TimeDelta::InSeconds() const {
|
| 36 |
+
return delta_ / Time::kMicrosecondsPerSecond;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
double TimeDelta::InMillisecondsF() const {
|
| 40 |
+
return static_cast<double>(delta_) / Time::kMicrosecondsPerMillisecond;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
int64 TimeDelta::InMilliseconds() const {
|
| 44 |
+
return delta_ / Time::kMicrosecondsPerMillisecond;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
int64 TimeDelta::InMillisecondsRoundedUp() const {
|
| 48 |
+
return (delta_ + Time::kMicrosecondsPerMillisecond - 1) /
|
| 49 |
+
Time::kMicrosecondsPerMillisecond;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
int64 TimeDelta::InMicroseconds() const {
|
| 53 |
+
return delta_;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// Time -----------------------------------------------------------------------
|
| 57 |
+
|
| 58 |
+
// static
|
| 59 |
+
Time Time::Max() {
|
| 60 |
+
return Time(std::numeric_limits<int64>::max());
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// static
|
| 64 |
+
Time Time::FromTimeT(time_t tt) {
|
| 65 |
+
if (tt == 0)
|
| 66 |
+
return Time(); // Preserve 0 so we can tell it doesn't exist.
|
| 67 |
+
if (tt == std::numeric_limits<time_t>::max())
|
| 68 |
+
return Max();
|
| 69 |
+
return Time((tt * kMicrosecondsPerSecond) + kTimeTToMicrosecondsOffset);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
time_t Time::ToTimeT() const {
|
| 73 |
+
if (is_null())
|
| 74 |
+
return 0; // Preserve 0 so we can tell it doesn't exist.
|
| 75 |
+
if (is_max()) {
|
| 76 |
+
// Preserve max without offset to prevent overflow.
|
| 77 |
+
return std::numeric_limits<time_t>::max();
|
| 78 |
+
}
|
| 79 |
+
if (std::numeric_limits<int64>::max() - kTimeTToMicrosecondsOffset <= us_) {
|
| 80 |
+
DLOG(WARNING) << "Overflow when converting base::Time with internal " <<
|
| 81 |
+
"value " << us_ << " to time_t.";
|
| 82 |
+
return std::numeric_limits<time_t>::max();
|
| 83 |
+
}
|
| 84 |
+
return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
// static
|
| 88 |
+
Time Time::FromDoubleT(double dt) {
|
| 89 |
+
if (dt == 0 || IsNaN(dt))
|
| 90 |
+
return Time(); // Preserve 0 so we can tell it doesn't exist.
|
| 91 |
+
if (dt == std::numeric_limits<double>::max())
|
| 92 |
+
return Max();
|
| 93 |
+
return Time(static_cast<int64>((dt *
|
| 94 |
+
static_cast<double>(kMicrosecondsPerSecond)) +
|
| 95 |
+
kTimeTToMicrosecondsOffset));
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
double Time::ToDoubleT() const {
|
| 99 |
+
if (is_null())
|
| 100 |
+
return 0; // Preserve 0 so we can tell it doesn't exist.
|
| 101 |
+
if (is_max()) {
|
| 102 |
+
// Preserve max without offset to prevent overflow.
|
| 103 |
+
return std::numeric_limits<double>::max();
|
| 104 |
+
}
|
| 105 |
+
return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) /
|
| 106 |
+
static_cast<double>(kMicrosecondsPerSecond));
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
#if defined(OS_POSIX)
|
| 110 |
+
// static
|
| 111 |
+
Time Time::FromTimeSpec(const timespec& ts) {
|
| 112 |
+
return FromDoubleT(ts.tv_sec +
|
| 113 |
+
static_cast<double>(ts.tv_nsec) /
|
| 114 |
+
base::Time::kNanosecondsPerSecond);
|
| 115 |
+
}
|
| 116 |
+
#endif
|
| 117 |
+
|
| 118 |
+
// static
|
| 119 |
+
Time Time::FromJsTime(double ms_since_epoch) {
|
| 120 |
+
// The epoch is a valid time, so this constructor doesn't interpret
|
| 121 |
+
// 0 as the null time.
|
| 122 |
+
if (ms_since_epoch == std::numeric_limits<double>::max())
|
| 123 |
+
return Max();
|
| 124 |
+
return Time(static_cast<int64>(ms_since_epoch * kMicrosecondsPerMillisecond) +
|
| 125 |
+
kTimeTToMicrosecondsOffset);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
double Time::ToJsTime() const {
|
| 129 |
+
if (is_null()) {
|
| 130 |
+
// Preserve 0 so the invalid result doesn't depend on the platform.
|
| 131 |
+
return 0;
|
| 132 |
+
}
|
| 133 |
+
if (is_max()) {
|
| 134 |
+
// Preserve max without offset to prevent overflow.
|
| 135 |
+
return std::numeric_limits<double>::max();
|
| 136 |
+
}
|
| 137 |
+
return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) /
|
| 138 |
+
kMicrosecondsPerMillisecond);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
int64 Time::ToJavaTime() const {
|
| 142 |
+
if (is_null()) {
|
| 143 |
+
// Preserve 0 so the invalid result doesn't depend on the platform.
|
| 144 |
+
return 0;
|
| 145 |
+
}
|
| 146 |
+
if (is_max()) {
|
| 147 |
+
// Preserve max without offset to prevent overflow.
|
| 148 |
+
return std::numeric_limits<int64>::max();
|
| 149 |
+
}
|
| 150 |
+
return ((us_ - kTimeTToMicrosecondsOffset) /
|
| 151 |
+
kMicrosecondsPerMillisecond);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
// static
|
| 155 |
+
Time Time::UnixEpoch() {
|
| 156 |
+
Time time;
|
| 157 |
+
time.us_ = kTimeTToMicrosecondsOffset;
|
| 158 |
+
return time;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
Time Time::LocalMidnight() const {
|
| 162 |
+
Exploded exploded;
|
| 163 |
+
LocalExplode(&exploded);
|
| 164 |
+
exploded.hour = 0;
|
| 165 |
+
exploded.minute = 0;
|
| 166 |
+
exploded.second = 0;
|
| 167 |
+
exploded.millisecond = 0;
|
| 168 |
+
return FromLocalExploded(exploded);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
// static
|
| 172 |
+
bool Time::FromStringInternal(const char* time_string,
|
| 173 |
+
bool is_local,
|
| 174 |
+
Time* parsed_time) {
|
| 175 |
+
DCHECK((time_string != NULL) && (parsed_time != NULL));
|
| 176 |
+
|
| 177 |
+
if (time_string[0] == '\0')
|
| 178 |
+
return false;
|
| 179 |
+
|
| 180 |
+
PRTime result_time = 0;
|
| 181 |
+
PRStatus result = PR_ParseTimeString(time_string,
|
| 182 |
+
is_local ? PR_FALSE : PR_TRUE,
|
| 183 |
+
&result_time);
|
| 184 |
+
if (PR_SUCCESS != result)
|
| 185 |
+
return false;
|
| 186 |
+
|
| 187 |
+
result_time += kTimeTToMicrosecondsOffset;
|
| 188 |
+
*parsed_time = Time(result_time);
|
| 189 |
+
return true;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
// Time::Exploded -------------------------------------------------------------
|
| 193 |
+
|
| 194 |
+
inline bool is_in_range(int value, int lo, int hi) {
|
| 195 |
+
return lo <= value && value <= hi;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
bool Time::Exploded::HasValidValues() const {
|
| 199 |
+
return is_in_range(month, 1, 12) &&
|
| 200 |
+
is_in_range(day_of_week, 0, 6) &&
|
| 201 |
+
is_in_range(day_of_month, 1, 31) &&
|
| 202 |
+
is_in_range(hour, 0, 23) &&
|
| 203 |
+
is_in_range(minute, 0, 59) &&
|
| 204 |
+
is_in_range(second, 0, 60) &&
|
| 205 |
+
is_in_range(millisecond, 0, 999);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
} // namespace base
|
pool/shard004/C++/0048689_userdata.cpp
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//-------------------------------------------------------------------------
|
| 2 |
+
// Copyright (c) 1997-1998 Great Hill Corporation
|
| 3 |
+
// All Rights Reserved.
|
| 4 |
+
//-------------------------------------------------------------------------
|
| 5 |
+
#include "Kramer.h"
|
| 6 |
+
|
| 7 |
+
#include "UserData.h"
|
| 8 |
+
|
| 9 |
+
vrUserDataList::~vrUserDataList(void)
|
| 10 |
+
{
|
| 11 |
+
LISTPOS pos = GetHeadPosition();
|
| 12 |
+
while (pos)
|
| 13 |
+
{
|
| 14 |
+
vrUserDataItem *item = GetNext(pos);
|
| 15 |
+
delete item;
|
| 16 |
+
}
|
| 17 |
+
RemoveAll();
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
vrUserDataItem::vrUserDataItem(const SFString& id, vrUserData *data)
|
| 21 |
+
{
|
| 22 |
+
m_Data = data;
|
| 23 |
+
m_ID = id;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
vrUserDataItem::~vrUserDataItem()
|
| 27 |
+
{
|
| 28 |
+
if (m_Data)
|
| 29 |
+
delete m_Data;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
vrUserDataItem *vrUserDataList::FindItem(const SFString& id)
|
| 33 |
+
{
|
| 34 |
+
LISTPOS pos = GetHeadPosition();
|
| 35 |
+
while (pos)
|
| 36 |
+
{
|
| 37 |
+
vrUserDataItem *item = GetNext(pos);
|
| 38 |
+
ASSERT(item);
|
| 39 |
+
if (item->m_ID == id)
|
| 40 |
+
return item;
|
| 41 |
+
}
|
| 42 |
+
return NULL;
|
| 43 |
+
}
|
| 44 |
+
|
pool/shard004/C++/0048699_StringServer.cpp
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// --------------------------------------------------------------------------------------------------
|
| 2 |
+
// Copyright (c) 2016 Microsoft Corporation
|
| 3 |
+
//
|
| 4 |
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
| 5 |
+
// associated documentation files (the "Software"), to deal in the Software without restriction,
|
| 6 |
+
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
| 7 |
+
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
// furnished to do so, subject to the following conditions:
|
| 9 |
+
//
|
| 10 |
+
// The above copyright notice and this permission notice shall be included in all copies or
|
| 11 |
+
// substantial portions of the Software.
|
| 12 |
+
//
|
| 13 |
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
| 14 |
+
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 15 |
+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
| 16 |
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 17 |
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 18 |
+
// --------------------------------------------------------------------------------------------------
|
| 19 |
+
|
| 20 |
+
// Local:
|
| 21 |
+
#include "StringServer.h"
|
| 22 |
+
|
| 23 |
+
// Boost:
|
| 24 |
+
#include <boost/bind.hpp>
|
| 25 |
+
#include <boost/date_time/posix_time/posix_time.hpp>
|
| 26 |
+
|
| 27 |
+
namespace malmo {
|
| 28 |
+
StringServer::StringServer(boost::asio::io_service& io_service, int port, const boost::function<void(const TimestampedString string_message)> handle_string)
|
| 29 |
+
: handle_string(handle_string)
|
| 30 |
+
, server(io_service, port, boost::bind(&StringServer::handleMessage, this, _1))
|
| 31 |
+
{
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
void StringServer::start()
|
| 35 |
+
{
|
| 36 |
+
this->server.start();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
StringServer& StringServer::record(std::string path)
|
| 40 |
+
{
|
| 41 |
+
if (this->writer.is_open()){
|
| 42 |
+
this->writer.close();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
this->writer.open(path, std::ofstream::out | std::ofstream::app);
|
| 46 |
+
|
| 47 |
+
return *this;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
StringServer& StringServer::confirmWithFixedReply(std::string reply)
|
| 51 |
+
{
|
| 52 |
+
this->server.confirmWithFixedReply(reply);
|
| 53 |
+
return *this;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
StringServer& StringServer::expectSizeHeader(bool expect_size_header)
|
| 57 |
+
{
|
| 58 |
+
this->server.expectSizeHeader(expect_size_header);
|
| 59 |
+
return *this;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
void StringServer::handleMessage(const TimestampedUnsignedCharVector message)
|
| 63 |
+
{
|
| 64 |
+
TimestampedString string_message(message);
|
| 65 |
+
|
| 66 |
+
this->handle_string(string_message);
|
| 67 |
+
|
| 68 |
+
this->recordMessage(string_message);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
void StringServer::stopRecording()
|
| 72 |
+
{
|
| 73 |
+
if (this->writer.is_open())
|
| 74 |
+
{
|
| 75 |
+
boost::lock_guard<boost::mutex> scope_guard(this->write_mutex);
|
| 76 |
+
|
| 77 |
+
this->writer.close();
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
int StringServer::getPort() const
|
| 82 |
+
{
|
| 83 |
+
return this->server.getPort();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
void StringServer::recordMessage(const TimestampedString string_message)
|
| 87 |
+
{
|
| 88 |
+
if (this->writer.is_open())
|
| 89 |
+
{
|
| 90 |
+
boost::lock_guard<boost::mutex> scope_guard(this->write_mutex);
|
| 91 |
+
|
| 92 |
+
this->writer << boost::posix_time::to_iso_string(string_message.timestamp) << " " << string_message.text << std::endl;
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
}
|
pool/shard004/C++/0048708_load_jpeg.cpp
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***********************************************************************
|
| 2 |
+
load_jpeg.cpp - Example showing how to insert BLOB data into the
|
| 3 |
+
database from a file.
|
| 4 |
+
|
| 5 |
+
Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
|
| 6 |
+
(c) 2004-2009 by Educational Technology Resources, Inc. Others may
|
| 7 |
+
also hold copyrights on code in this file. See the CREDITS.txt file
|
| 8 |
+
in the top directory of the distribution for details.
|
| 9 |
+
|
| 10 |
+
This file is part of MySQL++.
|
| 11 |
+
|
| 12 |
+
MySQL++ is free software; you can redistribute it and/or modify it
|
| 13 |
+
under the terms of the GNU Lesser General Public License as published
|
| 14 |
+
by the Free Software Foundation; either version 2.1 of the License, or
|
| 15 |
+
(at your option) any later version.
|
| 16 |
+
|
| 17 |
+
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
|
| 18 |
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 19 |
+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
| 20 |
+
License for more details.
|
| 21 |
+
|
| 22 |
+
You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
License along with MySQL++; if not, write to the Free Software
|
| 24 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
| 25 |
+
USA
|
| 26 |
+
***********************************************************************/
|
| 27 |
+
|
| 28 |
+
#include "cmdline.h"
|
| 29 |
+
#include "images.h"
|
| 30 |
+
#include "printdata.h"
|
| 31 |
+
|
| 32 |
+
#include <fstream>
|
| 33 |
+
|
| 34 |
+
using namespace std;
|
| 35 |
+
using namespace mysqlpp;
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
// This is just an implementation detail for the example. Skip down to
|
| 39 |
+
// main() for the concept this example is trying to demonstrate. You
|
| 40 |
+
// can simply assume that, given a BLOB containing a valid JPEG, it
|
| 41 |
+
// returns true.
|
| 42 |
+
static bool
|
| 43 |
+
is_jpeg(const mysqlpp::sql_blob& img, const char** whynot)
|
| 44 |
+
{
|
| 45 |
+
// See http://stackoverflow.com/questions/2253404/ for
|
| 46 |
+
// justification for the various tests.
|
| 47 |
+
const unsigned char* idp =
|
| 48 |
+
reinterpret_cast<const unsigned char*>(img.data());
|
| 49 |
+
if (img.size() < 125) {
|
| 50 |
+
*whynot = "a valid JPEG must be at least 125 bytes";
|
| 51 |
+
}
|
| 52 |
+
else if ((idp[0] != 0xFF) || (idp[1] != 0xD8)) {
|
| 53 |
+
*whynot = "file does not begin with JPEG sigil bytes";
|
| 54 |
+
}
|
| 55 |
+
else if ((memcmp(idp + 6, "JFIF", 4) != 0) &&
|
| 56 |
+
(memcmp(idp + 6, "Exif", 4) != 0)) {
|
| 57 |
+
*whynot = "file does not contain JPEG type word";
|
| 58 |
+
}
|
| 59 |
+
else {
|
| 60 |
+
*whynot = 0;
|
| 61 |
+
return true;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
return false;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
// Skip to main() before studying this. This is a little too
|
| 69 |
+
// low-level to bother with on your first pass thru the code.
|
| 70 |
+
static bool
|
| 71 |
+
load_jpeg_file(const mysqlpp::examples::CommandLine& cmdline,
|
| 72 |
+
images& img, string& img_name)
|
| 73 |
+
{
|
| 74 |
+
if (cmdline.extra_args().size() == 0) {
|
| 75 |
+
// Nothing for us to do here. Caller will insert NULL BLOB.
|
| 76 |
+
return true;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// Got a file's name on the command line, so open it.
|
| 80 |
+
img_name = cmdline.extra_args()[0];
|
| 81 |
+
ifstream img_file(img_name.c_str(), ios::binary);
|
| 82 |
+
if (img_file) {
|
| 83 |
+
// Slurp file contents into RAM with minimum copying. (Idiom
|
| 84 |
+
// explained here: http://stackoverflow.com/questions/116038/)
|
| 85 |
+
//
|
| 86 |
+
// By loading the file into a C++ string (stringstream::str())
|
| 87 |
+
// and assigning that directly to a mysqlpp::sql_blob, we avoid
|
| 88 |
+
// truncating the binary data at the first null character.
|
| 89 |
+
img.data.data = static_cast<const stringstream*>(
|
| 90 |
+
&(stringstream() << img_file.rdbuf()))->str();
|
| 91 |
+
|
| 92 |
+
// Check JPEG data for sanity.
|
| 93 |
+
const char* error;
|
| 94 |
+
if (is_jpeg(img.data.data, &error)) {
|
| 95 |
+
return true;
|
| 96 |
+
}
|
| 97 |
+
else {
|
| 98 |
+
cerr << '"' << img_name << "\" isn't a JPEG: " <<
|
| 99 |
+
error << '!' << endl;
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
cmdline.print_usage("[jpeg_file]");
|
| 104 |
+
return false;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
int
|
| 109 |
+
main(int argc, char *argv[])
|
| 110 |
+
{
|
| 111 |
+
// Get database access parameters from command line
|
| 112 |
+
mysqlpp::examples::CommandLine cmdline(argc, argv);
|
| 113 |
+
if (!cmdline) {
|
| 114 |
+
return 1;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
try {
|
| 118 |
+
// Establish the connection to the database server.
|
| 119 |
+
mysqlpp::Connection con(mysqlpp::examples::db_name,
|
| 120 |
+
cmdline.server(), cmdline.user(), cmdline.pass());
|
| 121 |
+
|
| 122 |
+
// Load the file named on the command line
|
| 123 |
+
images img(mysqlpp::null, mysqlpp::null);
|
| 124 |
+
string img_name("NULL");
|
| 125 |
+
if (load_jpeg_file(cmdline, img, img_name)) {
|
| 126 |
+
// Insert image data or SQL NULL into the images.data BLOB
|
| 127 |
+
// column. The key here is that we're holding the raw
|
| 128 |
+
// binary data in a mysqlpp::sql_blob, which avoids data
|
| 129 |
+
// conversion problems that can lead to treating BLOB data
|
| 130 |
+
// as C strings, thus causing null-truncation. The fact
|
| 131 |
+
// that we're using SSQLS here is a side issue, simply
|
| 132 |
+
// demonstrating that mysqlpp::Null<mysqlpp::sql_blob> is
|
| 133 |
+
// now legal in SSQLS, as of MySQL++ 3.0.7.
|
| 134 |
+
Query query = con.query();
|
| 135 |
+
query.insert(img);
|
| 136 |
+
SimpleResult res = query.execute();
|
| 137 |
+
|
| 138 |
+
// Report successful insertion
|
| 139 |
+
cout << "Inserted \"" << img_name <<
|
| 140 |
+
"\" into images table, " << img.data.data.size() <<
|
| 141 |
+
" bytes, ID " << res.insert_id() << endl;
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
catch (const BadQuery& er) {
|
| 145 |
+
// Handle any query errors
|
| 146 |
+
cerr << "Query error: " << er.what() << endl;
|
| 147 |
+
return -1;
|
| 148 |
+
}
|
| 149 |
+
catch (const BadConversion& er) {
|
| 150 |
+
// Handle bad conversions
|
| 151 |
+
cerr << "Conversion error: " << er.what() << endl <<
|
| 152 |
+
"\tretrieved data size: " << er.retrieved <<
|
| 153 |
+
", actual size: " << er.actual_size << endl;
|
| 154 |
+
return -1;
|
| 155 |
+
}
|
| 156 |
+
catch (const Exception& er) {
|
| 157 |
+
// Catch-all for any other MySQL++ exceptions
|
| 158 |
+
cerr << "Error: " << er.what() << endl;
|
| 159 |
+
return -1;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
return 0;
|
| 163 |
+
}
|
pool/shard004/C++/0048718_DragCaretController.cpp
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved.
|
| 3 |
+
*
|
| 4 |
+
* Redistribution and use in source and binary forms, with or without
|
| 5 |
+
* modification, are permitted provided that the following conditions
|
| 6 |
+
* are met:
|
| 7 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 8 |
+
* notice, this list of conditions and the following disclaimer.
|
| 9 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 10 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 11 |
+
* documentation and/or other materials provided with the distribution.
|
| 12 |
+
*
|
| 13 |
+
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
| 14 |
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 16 |
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
| 17 |
+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 18 |
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| 19 |
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 20 |
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
| 21 |
+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 22 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 23 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
#include "core/editing/DragCaretController.h"
|
| 27 |
+
|
| 28 |
+
#include "core/editing/EditingUtilities.h"
|
| 29 |
+
#include "core/layout/api/LayoutViewItem.h"
|
| 30 |
+
#include "core/paint/PaintLayer.h"
|
| 31 |
+
|
| 32 |
+
namespace blink {
|
| 33 |
+
|
| 34 |
+
DragCaretController::DragCaretController()
|
| 35 |
+
: m_caretBase(new CaretBase(CaretVisibility::Visible))
|
| 36 |
+
{
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
DragCaretController* DragCaretController::create()
|
| 40 |
+
{
|
| 41 |
+
return new DragCaretController;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
bool DragCaretController::isContentRichlyEditable() const
|
| 45 |
+
{
|
| 46 |
+
return isRichlyEditablePosition(m_position.deepEquivalent());
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void DragCaretController::setCaretPosition(const PositionWithAffinity& position)
|
| 50 |
+
{
|
| 51 |
+
// for querying Layer::compositingState()
|
| 52 |
+
// This code is probably correct, since it doesn't occur in a stack that
|
| 53 |
+
// involves updating compositing state.
|
| 54 |
+
DisableCompositingQueryAsserts disabler;
|
| 55 |
+
|
| 56 |
+
if (Node* node = m_position.deepEquivalent().anchorNode())
|
| 57 |
+
m_caretBase->invalidateCaretRect(node);
|
| 58 |
+
m_position = createVisiblePosition(position);
|
| 59 |
+
Document* document = nullptr;
|
| 60 |
+
if (Node* node = m_position.deepEquivalent().anchorNode()) {
|
| 61 |
+
m_caretBase->invalidateCaretRect(node);
|
| 62 |
+
document = &node->document();
|
| 63 |
+
}
|
| 64 |
+
if (m_position.isNull() || m_position.isOrphan()) {
|
| 65 |
+
m_caretBase->clearCaretRect();
|
| 66 |
+
} else {
|
| 67 |
+
document->updateStyleAndLayoutTree();
|
| 68 |
+
m_caretBase->updateCaretRect(m_position);
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
static bool removingNodeRemovesPosition(Node& node, const Position& position)
|
| 73 |
+
{
|
| 74 |
+
if (!position.anchorNode())
|
| 75 |
+
return false;
|
| 76 |
+
|
| 77 |
+
if (position.anchorNode() == node)
|
| 78 |
+
return true;
|
| 79 |
+
|
| 80 |
+
if (!node.isElementNode())
|
| 81 |
+
return false;
|
| 82 |
+
|
| 83 |
+
Element& element = toElement(node);
|
| 84 |
+
return element.isShadowIncludingInclusiveAncestorOf(position.anchorNode());
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
void DragCaretController::nodeWillBeRemoved(Node& node)
|
| 88 |
+
{
|
| 89 |
+
if (!hasCaret() || !node.inActiveDocument())
|
| 90 |
+
return;
|
| 91 |
+
|
| 92 |
+
if (!removingNodeRemovesPosition(node, m_position.deepEquivalent()))
|
| 93 |
+
return;
|
| 94 |
+
|
| 95 |
+
m_position.deepEquivalent().document()->layoutViewItem().clearSelection();
|
| 96 |
+
clear();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
DEFINE_TRACE(DragCaretController)
|
| 100 |
+
{
|
| 101 |
+
visitor->trace(m_position);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
LayoutBlock* DragCaretController::caretLayoutObject() const
|
| 105 |
+
{
|
| 106 |
+
return CaretBase::caretLayoutObject(m_position.deepEquivalent().anchorNode());
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
bool DragCaretController::isContentEditable() const
|
| 110 |
+
{
|
| 111 |
+
return rootEditableElementOf(m_position);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext& context, const LayoutPoint& paintOffset) const
|
| 115 |
+
{
|
| 116 |
+
if (m_position.deepEquivalent().anchorNode()->document().frame() == frame)
|
| 117 |
+
m_caretBase->paintCaret(m_position.deepEquivalent().anchorNode(), context, paintOffset);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
} // namespace blink
|
pool/shard004/C++/0048719_LoanCalculator.cpp
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// LoanCalculator.cpp
|
| 3 |
+
// Kata.LoanPrediction.C++
|
| 4 |
+
//
|
| 5 |
+
// Created by retroburst [Andrew D] on 3/09/2015.
|
| 6 |
+
// Copyright (c) 2015 retroburst [Andrew D]. All rights reserved.
|
| 7 |
+
//
|
| 8 |
+
|
| 9 |
+
#include "LoanCalculator.h"
|
| 10 |
+
#include "Global.h"
|
| 11 |
+
|
| 12 |
+
/*
|
| 13 |
+
***************************************
|
| 14 |
+
** Default constructor.
|
| 15 |
+
***************************************
|
| 16 |
+
*/
|
| 17 |
+
LoanCalculator::LoanCalculator(LoanContext context)
|
| 18 |
+
{
|
| 19 |
+
this->context = context;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/*
|
| 23 |
+
***************************************
|
| 24 |
+
** Calculates the transactions on the
|
| 25 |
+
** loan from now to the time it will be
|
| 26 |
+
** paid off.
|
| 27 |
+
***************************************
|
| 28 |
+
*/
|
| 29 |
+
LoanCalculationOutput LoanCalculator::calculateLoan()
|
| 30 |
+
{
|
| 31 |
+
LoanCalculationOutput output;
|
| 32 |
+
bool firstIteration = true;
|
| 33 |
+
double balance = context.getBalance();
|
| 34 |
+
double monthlyInterest = 0.0;
|
| 35 |
+
dateTime currentDate = context.getStartDate();
|
| 36 |
+
currentDate.tm_isdst = 0;
|
| 37 |
+
// we will calculate interest from the first of the month
|
| 38 |
+
dateTime calcInterestStartDate = currentDate;
|
| 39 |
+
calcInterestStartDate.tm_mday = 1;
|
| 40 |
+
output.setInterestStartDate(calcInterestStartDate);
|
| 41 |
+
// loop through dates, caculating interest daily etc
|
| 42 |
+
while (true)
|
| 43 |
+
{
|
| 44 |
+
// if min repay day
|
| 45 |
+
if (currentDate.tm_mday == context.getMinRepaymentDay() && balance > 0.0)
|
| 46 |
+
{
|
| 47 |
+
processMinRepayment(balance, context.getMinRepaymentAmount(), currentDate, monthlyInterest, output);
|
| 48 |
+
}
|
| 49 |
+
// if extra repay day
|
| 50 |
+
if (currentDate.tm_mday == context.getExtraRepaymentDay() && context.getExtraRepaymentAmount() > 0.0 && balance > 0.0)
|
| 51 |
+
{
|
| 52 |
+
processExtraRepayment(balance, context.getExtraRepaymentAmount(), currentDate, output);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// if balance is zero or less - we are done!
|
| 56 |
+
if (balance <= 0.0)
|
| 57 |
+
{
|
| 58 |
+
output.setLoanEndsDate(currentDate);
|
| 59 |
+
break;
|
| 60 |
+
}
|
| 61 |
+
// calculate the daily interest
|
| 62 |
+
monthlyInterest += calculateDailyInterest(balance, context.getInterestRate());
|
| 63 |
+
// if this is the first iteration and we did not start on the first of the month
|
| 64 |
+
// let's calculate the interest for the days back to the first
|
| 65 |
+
if (firstIteration && context.getStartDate().tm_mday != 1)
|
| 66 |
+
{
|
| 67 |
+
int daysToMonthStart = currentDate.tm_mday - 1;
|
| 68 |
+
monthlyInterest += (monthlyInterest * daysToMonthStart);
|
| 69 |
+
firstIteration = false;
|
| 70 |
+
}
|
| 71 |
+
// move date forward
|
| 72 |
+
dateTime nextDate = currentDate;
|
| 73 |
+
nextDate.tm_isdst = 0;
|
| 74 |
+
addDay(&nextDate);
|
| 75 |
+
// if end of month
|
| 76 |
+
if (currentDate.tm_mon != nextDate.tm_mon)
|
| 77 |
+
{
|
| 78 |
+
processEndOfMonth(currentDate, monthlyInterest, balance, output);
|
| 79 |
+
}
|
| 80 |
+
currentDate = nextDate;
|
| 81 |
+
}
|
| 82 |
+
setTargetEndDateAccuracy(output.getLoanEndsDate(), context.getTargetEndDate(), output);
|
| 83 |
+
return(output);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/*
|
| 87 |
+
***************************************
|
| 88 |
+
** Processes the end of month, adds
|
| 89 |
+
** interest to the balance.
|
| 90 |
+
***************************************
|
| 91 |
+
*/
|
| 92 |
+
void LoanCalculator::processEndOfMonth(dateTime currentDate, double &monthlyInterest, double &balance, LoanCalculationOutput &output)
|
| 93 |
+
{
|
| 94 |
+
// add interest charged transaction
|
| 95 |
+
balance += monthlyInterest;
|
| 96 |
+
// calculate the total interest paid
|
| 97 |
+
output.setTotalInterestPaid(output.getTotalInterestPaid() + monthlyInterest);
|
| 98 |
+
output.addTransaction(createTransaction(TX_TYPE_INTEREST_CHARGED, currentDate, 0.0, monthlyInterest, balance));
|
| 99 |
+
// reset for new month
|
| 100 |
+
monthlyInterest = 0.0;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/*
|
| 104 |
+
***************************************
|
| 105 |
+
** Processes the extra repayment for the
|
| 106 |
+
** current date if applicable.
|
| 107 |
+
***************************************
|
| 108 |
+
*/
|
| 109 |
+
void LoanCalculator::processExtraRepayment(double &balance, double extraRepaymentAmount, dateTime currentDate, LoanCalculationOutput &output)
|
| 110 |
+
{
|
| 111 |
+
// add extra repay transaction (if amount is more than 0)
|
| 112 |
+
balance -= extraRepaymentAmount;
|
| 113 |
+
output.addTransaction(createTransaction(TX_TYPE_EXTRA_REPAYMENT, currentDate, extraRepaymentAmount, 0.0, balance));
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/*
|
| 117 |
+
***************************************
|
| 118 |
+
** Processes the min repayment for the
|
| 119 |
+
** current date if applicable.
|
| 120 |
+
***************************************
|
| 121 |
+
*/
|
| 122 |
+
void LoanCalculator::processMinRepayment(double &balance, double minRepaymentAmount, dateTime ¤tDate, double monthlyInterest, LoanCalculationOutput &output)
|
| 123 |
+
{
|
| 124 |
+
// add min repay transaction
|
| 125 |
+
if ((balance + monthlyInterest) <= minRepaymentAmount)
|
| 126 |
+
{
|
| 127 |
+
double finalRepayment = 0.0;
|
| 128 |
+
balance += monthlyInterest;
|
| 129 |
+
finalRepayment = balance;
|
| 130 |
+
balance -= finalRepayment;
|
| 131 |
+
output.addTransaction(createTransaction(TX_FINAL_REPAYMENT, currentDate, finalRepayment, monthlyInterest, balance));
|
| 132 |
+
}
|
| 133 |
+
else
|
| 134 |
+
{
|
| 135 |
+
balance -= context.getMinRepaymentAmount();
|
| 136 |
+
output.addTransaction(createTransaction(TX_TYPE_MIN_REPAYMENT, currentDate, minRepaymentAmount, 0.0, balance));
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/*
|
| 141 |
+
***************************************
|
| 142 |
+
** Calculates the interest for a day.
|
| 143 |
+
***************************************
|
| 144 |
+
*/
|
| 145 |
+
double LoanCalculator::calculateDailyInterest(double balance, double interestRate)
|
| 146 |
+
{
|
| 147 |
+
double result = 0.0;
|
| 148 |
+
result = (balance * (interestRate / 100)) / NUM_DAYS_IN_YEAR;
|
| 149 |
+
return(result);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/*
|
| 153 |
+
***************************************
|
| 154 |
+
** Creates a transaction using the
|
| 155 |
+
** provided values.
|
| 156 |
+
***************************************
|
| 157 |
+
*/
|
| 158 |
+
LoanTransaction LoanCalculator::createTransaction(string type, dateTime date, double repayment, double charge, double balance)
|
| 159 |
+
{
|
| 160 |
+
LoanTransaction transaction;
|
| 161 |
+
transaction.setType(type);
|
| 162 |
+
transaction.setDate(date);
|
| 163 |
+
transaction.setCredit(repayment);
|
| 164 |
+
transaction.setDebit(charge);
|
| 165 |
+
transaction.setBalance(balance);
|
| 166 |
+
return(transaction);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/*
|
| 170 |
+
***************************************
|
| 171 |
+
** Sets the accuracy of the target end
|
| 172 |
+
** end date with respect to the actual
|
| 173 |
+
** end date.
|
| 174 |
+
***************************************
|
| 175 |
+
*/
|
| 176 |
+
void LoanCalculator::setTargetEndDateAccuracy(dateTime actualEndDate, dateTime targetEndDate, LoanCalculationOutput &output)
|
| 177 |
+
{
|
| 178 |
+
int daysMissed = 0;
|
| 179 |
+
bool searchForwards = false;
|
| 180 |
+
output.setTargetEndDateHit(false);
|
| 181 |
+
dateTime *search = new dateTime(actualEndDate);
|
| 182 |
+
int compareResult = compareDates(actualEndDate, targetEndDate);
|
| 183 |
+
if (compareResult == 0)
|
| 184 |
+
{
|
| 185 |
+
output.setTargetEndDateHit(true);
|
| 186 |
+
return;
|
| 187 |
+
}
|
| 188 |
+
if (compareResult == 1)
|
| 189 |
+
{
|
| 190 |
+
searchForwards = false;
|
| 191 |
+
}
|
| 192 |
+
else if (compareResult == -1)
|
| 193 |
+
{
|
| 194 |
+
searchForwards = true;
|
| 195 |
+
}
|
| 196 |
+
while (compareDates(*search, targetEndDate) != 0)
|
| 197 |
+
{
|
| 198 |
+
if (searchForwards)
|
| 199 |
+
{
|
| 200 |
+
addDay(search);
|
| 201 |
+
daysMissed--;
|
| 202 |
+
}
|
| 203 |
+
else
|
| 204 |
+
{
|
| 205 |
+
minusDay(search);
|
| 206 |
+
daysMissed++;
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
output.setTargetEndDateMissedInDays(daysMissed);
|
| 210 |
+
delete(search);
|
| 211 |
+
}
|
| 212 |
+
|
pool/shard004/C++/0048722_Mixer.cpp
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*******************************************************************************
|
| 2 |
+
* Copyright 2009-2016 Jörg Müller
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
******************************************************************************/
|
| 16 |
+
|
| 17 |
+
#include "respec/Mixer.h"
|
| 18 |
+
|
| 19 |
+
#include <algorithm>
|
| 20 |
+
#include <cstring>
|
| 21 |
+
|
| 22 |
+
AUD_NAMESPACE_BEGIN
|
| 23 |
+
|
| 24 |
+
Mixer::Mixer(DeviceSpecs specs)
|
| 25 |
+
{
|
| 26 |
+
setSpecs(specs);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
DeviceSpecs Mixer::getSpecs() const
|
| 30 |
+
{
|
| 31 |
+
return m_specs;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
void Mixer::setSpecs(Specs specs)
|
| 35 |
+
{
|
| 36 |
+
m_specs.specs = specs;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
void Mixer::setSpecs(DeviceSpecs specs)
|
| 40 |
+
{
|
| 41 |
+
m_specs = specs;
|
| 42 |
+
|
| 43 |
+
switch(m_specs.format)
|
| 44 |
+
{
|
| 45 |
+
case FORMAT_U8:
|
| 46 |
+
m_convert = convert_float_u8;
|
| 47 |
+
break;
|
| 48 |
+
case FORMAT_S16:
|
| 49 |
+
m_convert = convert_float_s16;
|
| 50 |
+
break;
|
| 51 |
+
case FORMAT_S24:
|
| 52 |
+
|
| 53 |
+
#ifdef __BIG_ENDIAN__
|
| 54 |
+
m_convert = convert_float_s24_be;
|
| 55 |
+
#else
|
| 56 |
+
m_convert = convert_float_s24_le;
|
| 57 |
+
#endif
|
| 58 |
+
break;
|
| 59 |
+
case FORMAT_S32:
|
| 60 |
+
m_convert = convert_float_s32;
|
| 61 |
+
break;
|
| 62 |
+
case FORMAT_FLOAT32:
|
| 63 |
+
m_convert = convert_copy<float>;
|
| 64 |
+
break;
|
| 65 |
+
case FORMAT_FLOAT64:
|
| 66 |
+
m_convert = convert_float_double;
|
| 67 |
+
break;
|
| 68 |
+
default:
|
| 69 |
+
break;
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
void Mixer::clear(int length)
|
| 74 |
+
{
|
| 75 |
+
m_buffer.assureSize(length * AUD_SAMPLE_SIZE(m_specs));
|
| 76 |
+
|
| 77 |
+
m_length = length;
|
| 78 |
+
|
| 79 |
+
std::memset(m_buffer.getBuffer(), 0, length * AUD_SAMPLE_SIZE(m_specs));
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
void Mixer::mix(sample_t* buffer, int start, int length, float volume)
|
| 83 |
+
{
|
| 84 |
+
sample_t* out = m_buffer.getBuffer();
|
| 85 |
+
|
| 86 |
+
length = (std::min(m_length, length + start) - start) * m_specs.channels;
|
| 87 |
+
start *= m_specs.channels;
|
| 88 |
+
|
| 89 |
+
for(int i = 0; i < length; i++)
|
| 90 |
+
out[i + start] += buffer[i] * volume;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
void Mixer::mix(sample_t* buffer, int start, int length, float volume_to, float volume_from)
|
| 94 |
+
{
|
| 95 |
+
sample_t* out = m_buffer.getBuffer();
|
| 96 |
+
|
| 97 |
+
length = (std::min(m_length, length + start) - start);
|
| 98 |
+
|
| 99 |
+
for(int i = 0; i < length; i++)
|
| 100 |
+
{
|
| 101 |
+
float volume = volume_from * (1.0f - i / float(length)) + volume_to * (i / float(length));
|
| 102 |
+
|
| 103 |
+
for(int c = 0; c < m_specs.channels; c++)
|
| 104 |
+
out[(i + start) * m_specs.channels + c] += buffer[i * m_specs.channels + c] * volume;
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
void Mixer::read(data_t* buffer, float volume)
|
| 109 |
+
{
|
| 110 |
+
sample_t* out = m_buffer.getBuffer();
|
| 111 |
+
|
| 112 |
+
for(int i = 0; i < m_length * m_specs.channels; i++)
|
| 113 |
+
out[i] *= volume;
|
| 114 |
+
|
| 115 |
+
m_convert(buffer, (data_t*) out, m_length * m_specs.channels);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
AUD_NAMESPACE_END
|
pool/shard004/C++/0048730_ItemNameUtils.cpp
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Archive/Common/ItemNameUtils.cpp
|
| 2 |
+
|
| 3 |
+
#include "StdAfx.h"
|
| 4 |
+
|
| 5 |
+
#include "ItemNameUtils.h"
|
| 6 |
+
|
| 7 |
+
namespace NArchive {
|
| 8 |
+
namespace NItemName {
|
| 9 |
+
|
| 10 |
+
static const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;
|
| 11 |
+
static const wchar_t kDirDelimiter = L'/';
|
| 12 |
+
|
| 13 |
+
UString MakeLegalName(const UString &name)
|
| 14 |
+
{
|
| 15 |
+
UString zipName = name;
|
| 16 |
+
zipName.Replace(kOSDirDelimiter, kDirDelimiter);
|
| 17 |
+
return zipName;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
UString GetOSName(const UString &name)
|
| 21 |
+
{
|
| 22 |
+
UString newName = name;
|
| 23 |
+
newName.Replace(kDirDelimiter, kOSDirDelimiter);
|
| 24 |
+
return newName;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
UString GetOSName2(const UString &name)
|
| 28 |
+
{
|
| 29 |
+
if (name.IsEmpty())
|
| 30 |
+
return UString();
|
| 31 |
+
UString newName = GetOSName(name);
|
| 32 |
+
if (newName[newName.Length() - 1] == kOSDirDelimiter)
|
| 33 |
+
newName.Delete(newName.Length() - 1);
|
| 34 |
+
return newName;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
bool HasTailSlash(const AString &name, UINT codePage)
|
| 38 |
+
{
|
| 39 |
+
if (name.IsEmpty())
|
| 40 |
+
return false;
|
| 41 |
+
LPCSTR prev =
|
| 42 |
+
#ifdef _WIN32
|
| 43 |
+
CharPrevExA(codePage, name, &name[name.Length()], 0);
|
| 44 |
+
#else
|
| 45 |
+
(LPCSTR)(name) + (name.Length() - 1);
|
| 46 |
+
#endif
|
| 47 |
+
return (*prev == '/');
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
#ifndef _WIN32
|
| 51 |
+
UString WinNameToOSName(const UString &name)
|
| 52 |
+
{
|
| 53 |
+
UString newName = name;
|
| 54 |
+
newName.Replace(L'\\', kOSDirDelimiter);
|
| 55 |
+
return newName;
|
| 56 |
+
}
|
| 57 |
+
#endif
|
| 58 |
+
|
| 59 |
+
}}
|
pool/shard004/C++/0048732_GuiVSpace.cpp
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* \file GuiVSpace.cpp
|
| 3 |
+
* This file is part of LyX, the document processor.
|
| 4 |
+
* Licence details can be found in the file COPYING.
|
| 5 |
+
*
|
| 6 |
+
* \author André Pönitz
|
| 7 |
+
* \author Jürgen Vigna
|
| 8 |
+
* \author Rob Lahaye
|
| 9 |
+
* \author Angus Leeming
|
| 10 |
+
* \author Edwin Leuven
|
| 11 |
+
* \author Jürgen Spitzmüller
|
| 12 |
+
*
|
| 13 |
+
* Full author contact details are available in file CREDITS.
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
#include <config.h>
|
| 17 |
+
|
| 18 |
+
#include "GuiVSpace.h"
|
| 19 |
+
|
| 20 |
+
#include "LengthCombo.h"
|
| 21 |
+
#include "qt_helpers.h"
|
| 22 |
+
#include "Validator.h"
|
| 23 |
+
|
| 24 |
+
#include "Spacing.h"
|
| 25 |
+
#include "VSpace.h"
|
| 26 |
+
|
| 27 |
+
#include "insets/InsetVSpace.h"
|
| 28 |
+
|
| 29 |
+
#include "support/gettext.h"
|
| 30 |
+
#include "support/lstrings.h"
|
| 31 |
+
|
| 32 |
+
#include <QCheckBox>
|
| 33 |
+
#include <QLineEdit>
|
| 34 |
+
#include <QPushButton>
|
| 35 |
+
#include <QValidator>
|
| 36 |
+
|
| 37 |
+
using namespace std;
|
| 38 |
+
|
| 39 |
+
namespace lyx {
|
| 40 |
+
namespace frontend {
|
| 41 |
+
|
| 42 |
+
GuiVSpace::GuiVSpace(QWidget * parent) : InsetParamsWidget(parent)
|
| 43 |
+
{
|
| 44 |
+
setupUi(this);
|
| 45 |
+
|
| 46 |
+
connect(valueLE, SIGNAL(textChanged(QString)),
|
| 47 |
+
this, SIGNAL(changed()));
|
| 48 |
+
connect(keepCB, SIGNAL(clicked()),
|
| 49 |
+
this, SIGNAL(changed()));
|
| 50 |
+
connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
| 51 |
+
this, SIGNAL(changed()));
|
| 52 |
+
|
| 53 |
+
connect(spacingCO, SIGNAL(activated(int)),
|
| 54 |
+
this, SLOT(enableCustom(int)));
|
| 55 |
+
|
| 56 |
+
// Set up a signed glue length validator
|
| 57 |
+
LengthValidator * v = new LengthValidator(valueLE);
|
| 58 |
+
v->setBottom(GlueLength());
|
| 59 |
+
valueLE->setValidator(v);
|
| 60 |
+
|
| 61 |
+
// initialize the length validator
|
| 62 |
+
addCheckedWidget(valueLE, valueL);
|
| 63 |
+
enableCustom(spacingCO->currentIndex());
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
void GuiVSpace::enableCustom(int selection)
|
| 68 |
+
{
|
| 69 |
+
bool const enable = selection == 5;
|
| 70 |
+
valueLE->setEnabled(enable);
|
| 71 |
+
if (enable)
|
| 72 |
+
valueLE->setFocus();
|
| 73 |
+
valueL->setEnabled(enable);
|
| 74 |
+
unitCO->setEnabled(enable);
|
| 75 |
+
changed();
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
static void setWidgetsFromVSpace(VSpace const & space,
|
| 80 |
+
QComboBox * spacing,
|
| 81 |
+
QLineEdit * value,
|
| 82 |
+
LengthCombo * unit,
|
| 83 |
+
QCheckBox * keep)
|
| 84 |
+
{
|
| 85 |
+
int item = 0;
|
| 86 |
+
switch (space.kind()) {
|
| 87 |
+
case VSpace::DEFSKIP: item = 0; break;
|
| 88 |
+
case VSpace::SMALLSKIP: item = 1; break;
|
| 89 |
+
case VSpace::MEDSKIP: item = 2; break;
|
| 90 |
+
case VSpace::BIGSKIP: item = 3; break;
|
| 91 |
+
case VSpace::VFILL: item = 4; break;
|
| 92 |
+
case VSpace::LENGTH: item = 5; break;
|
| 93 |
+
}
|
| 94 |
+
spacing->setCurrentIndex(item);
|
| 95 |
+
keep->setChecked(space.keep());
|
| 96 |
+
|
| 97 |
+
Length::UNIT const default_unit = Length::defaultUnit();
|
| 98 |
+
bool const custom_vspace = space.kind() == VSpace::LENGTH;
|
| 99 |
+
if (custom_vspace) {
|
| 100 |
+
value->setEnabled(true);
|
| 101 |
+
unit->setEnabled(true);
|
| 102 |
+
string length = space.length().asString();
|
| 103 |
+
lengthToWidgets(value, unit, length, default_unit);
|
| 104 |
+
} else {
|
| 105 |
+
lengthToWidgets(value, unit, "", default_unit);
|
| 106 |
+
value->setEnabled(false);
|
| 107 |
+
unit->setEnabled(false);
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
static VSpace setVSpaceFromWidgets(int spacing,
|
| 113 |
+
QLineEdit * value, LengthCombo * unit, bool keep)
|
| 114 |
+
{
|
| 115 |
+
VSpace space;
|
| 116 |
+
|
| 117 |
+
switch (spacing) {
|
| 118 |
+
case 0: space = VSpace(VSpace::DEFSKIP); break;
|
| 119 |
+
case 1: space = VSpace(VSpace::SMALLSKIP); break;
|
| 120 |
+
case 2: space = VSpace(VSpace::MEDSKIP); break;
|
| 121 |
+
case 3: space = VSpace(VSpace::BIGSKIP); break;
|
| 122 |
+
case 4: space = VSpace(VSpace::VFILL); break;
|
| 123 |
+
case 5: space = VSpace(GlueLength(widgetsToLength(value, unit))); break;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
space.setKeep(keep);
|
| 127 |
+
return space;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
docstring GuiVSpace::dialogToParams() const
|
| 132 |
+
{
|
| 133 |
+
// If a vspace choice is "Length" but there's no text in
|
| 134 |
+
// the input field, do not insert a vspace at all.
|
| 135 |
+
if (spacingCO->currentIndex() == 5 && valueLE->text().isEmpty())
|
| 136 |
+
return docstring();
|
| 137 |
+
|
| 138 |
+
VSpace const params = setVSpaceFromWidgets(spacingCO->currentIndex(),
|
| 139 |
+
valueLE, unitCO, keepCB->isChecked());
|
| 140 |
+
return from_ascii(InsetVSpace::params2string(params));
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
void GuiVSpace::paramsToDialog(Inset const * inset)
|
| 145 |
+
{
|
| 146 |
+
InsetVSpace const * vs = static_cast<InsetVSpace const *>(inset);
|
| 147 |
+
VSpace const & params = vs->space();
|
| 148 |
+
setWidgetsFromVSpace(params, spacingCO, valueLE, unitCO, keepCB);
|
| 149 |
+
enableCustom(spacingCO->currentIndex());
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
bool GuiVSpace::checkWidgets(bool readonly) const
|
| 154 |
+
{
|
| 155 |
+
valueLE->setReadOnly(readonly);
|
| 156 |
+
keepCB->setEnabled(!readonly);
|
| 157 |
+
|
| 158 |
+
if (readonly) {
|
| 159 |
+
spacingCO->setEnabled(false);
|
| 160 |
+
unitCO->setEnabled(false);
|
| 161 |
+
} else {
|
| 162 |
+
bool const enable = (spacingCO->currentIndex() == 5);
|
| 163 |
+
valueLE->setEnabled(enable);
|
| 164 |
+
valueL->setEnabled(enable);
|
| 165 |
+
unitCO->setEnabled(enable);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
return InsetParamsWidget::checkWidgets();
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
} // namespace frontend
|
| 172 |
+
} // namespace lyx
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
#include "moc_GuiVSpace.cpp"
|
pool/shard004/C++/0048733_ShippingOption.cpp
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
| 3 |
+
* SPDX-License-Identifier: Apache-2.0.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#include <aws/snowball/model/ShippingOption.h>
|
| 7 |
+
#include <aws/core/utils/HashingUtils.h>
|
| 8 |
+
#include <aws/core/Globals.h>
|
| 9 |
+
#include <aws/core/utils/EnumParseOverflowContainer.h>
|
| 10 |
+
|
| 11 |
+
using namespace Aws::Utils;
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
namespace Aws
|
| 15 |
+
{
|
| 16 |
+
namespace Snowball
|
| 17 |
+
{
|
| 18 |
+
namespace Model
|
| 19 |
+
{
|
| 20 |
+
namespace ShippingOptionMapper
|
| 21 |
+
{
|
| 22 |
+
|
| 23 |
+
static const int SECOND_DAY_HASH = HashingUtils::HashString("SECOND_DAY");
|
| 24 |
+
static const int NEXT_DAY_HASH = HashingUtils::HashString("NEXT_DAY");
|
| 25 |
+
static const int EXPRESS_HASH = HashingUtils::HashString("EXPRESS");
|
| 26 |
+
static const int STANDARD_HASH = HashingUtils::HashString("STANDARD");
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
ShippingOption GetShippingOptionForName(const Aws::String& name)
|
| 30 |
+
{
|
| 31 |
+
int hashCode = HashingUtils::HashString(name.c_str());
|
| 32 |
+
if (hashCode == SECOND_DAY_HASH)
|
| 33 |
+
{
|
| 34 |
+
return ShippingOption::SECOND_DAY;
|
| 35 |
+
}
|
| 36 |
+
else if (hashCode == NEXT_DAY_HASH)
|
| 37 |
+
{
|
| 38 |
+
return ShippingOption::NEXT_DAY;
|
| 39 |
+
}
|
| 40 |
+
else if (hashCode == EXPRESS_HASH)
|
| 41 |
+
{
|
| 42 |
+
return ShippingOption::EXPRESS;
|
| 43 |
+
}
|
| 44 |
+
else if (hashCode == STANDARD_HASH)
|
| 45 |
+
{
|
| 46 |
+
return ShippingOption::STANDARD;
|
| 47 |
+
}
|
| 48 |
+
EnumParseOverflowContainer* overflowContainer = Aws::GetEnumOverflowContainer();
|
| 49 |
+
if(overflowContainer)
|
| 50 |
+
{
|
| 51 |
+
overflowContainer->StoreOverflow(hashCode, name);
|
| 52 |
+
return static_cast<ShippingOption>(hashCode);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
return ShippingOption::NOT_SET;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
Aws::String GetNameForShippingOption(ShippingOption enumValue)
|
| 59 |
+
{
|
| 60 |
+
switch(enumValue)
|
| 61 |
+
{
|
| 62 |
+
case ShippingOption::SECOND_DAY:
|
| 63 |
+
return "SECOND_DAY";
|
| 64 |
+
case ShippingOption::NEXT_DAY:
|
| 65 |
+
return "NEXT_DAY";
|
| 66 |
+
case ShippingOption::EXPRESS:
|
| 67 |
+
return "EXPRESS";
|
| 68 |
+
case ShippingOption::STANDARD:
|
| 69 |
+
return "STANDARD";
|
| 70 |
+
default:
|
| 71 |
+
EnumParseOverflowContainer* overflowContainer = Aws::GetEnumOverflowContainer();
|
| 72 |
+
if(overflowContainer)
|
| 73 |
+
{
|
| 74 |
+
return overflowContainer->RetrieveOverflow(static_cast<int>(enumValue));
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
return {};
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
} // namespace ShippingOptionMapper
|
| 82 |
+
} // namespace Model
|
| 83 |
+
} // namespace Snowball
|
| 84 |
+
} // namespace Aws
|
pool/shard004/C++/0048734_undirected.cpp
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//=======================================================================
|
| 2 |
+
// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
|
| 3 |
+
//
|
| 4 |
+
// Distributed under the Boost Software License, Version 1.0. (See
|
| 5 |
+
// accompanying file LICENSE_1_0.txt or copy at
|
| 6 |
+
// http://www.boost.org/LICENSE_1_0.txt)
|
| 7 |
+
//=======================================================================
|
| 8 |
+
#include <boost/config.hpp>
|
| 9 |
+
#include <iostream>
|
| 10 |
+
#include <boost/graph/adjacency_list.hpp>
|
| 11 |
+
using namespace boost;
|
| 12 |
+
|
| 13 |
+
template < typename UndirectedGraph > void
|
| 14 |
+
undirected_graph_demo1()
|
| 15 |
+
{
|
| 16 |
+
const int V = 3;
|
| 17 |
+
UndirectedGraph undigraph(V);
|
| 18 |
+
typename graph_traits < UndirectedGraph >::vertex_descriptor zero, one, two;
|
| 19 |
+
typename graph_traits < UndirectedGraph >::out_edge_iterator out, out_end;
|
| 20 |
+
typename graph_traits < UndirectedGraph >::in_edge_iterator in, in_end;
|
| 21 |
+
|
| 22 |
+
zero = vertex(0, undigraph);
|
| 23 |
+
one = vertex(1, undigraph);
|
| 24 |
+
two = vertex(2, undigraph);
|
| 25 |
+
add_edge(zero, one, undigraph);
|
| 26 |
+
add_edge(zero, two, undigraph);
|
| 27 |
+
add_edge(one, two, undigraph);
|
| 28 |
+
|
| 29 |
+
std::cout << "out_edges(0): ";
|
| 30 |
+
for (tie(out, out_end) = out_edges(zero, undigraph); out != out_end; ++out)
|
| 31 |
+
std::cout << *out;
|
| 32 |
+
std::cout << std::endl << "in_edges(0): ";
|
| 33 |
+
for (tie(in, in_end) = in_edges(zero, undigraph); in != in_end; ++in)
|
| 34 |
+
std::cout << *in;
|
| 35 |
+
std::cout << std::endl;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
template < typename DirectedGraph > void
|
| 39 |
+
directed_graph_demo()
|
| 40 |
+
{
|
| 41 |
+
const int V = 2;
|
| 42 |
+
DirectedGraph digraph(V);
|
| 43 |
+
typename graph_traits < DirectedGraph >::vertex_descriptor u, v;
|
| 44 |
+
typedef typename DirectedGraph::edge_property_type Weight;
|
| 45 |
+
typename property_map < DirectedGraph, edge_weight_t >::type
|
| 46 |
+
weight = get(edge_weight, digraph);
|
| 47 |
+
typename graph_traits < DirectedGraph >::edge_descriptor e1, e2;
|
| 48 |
+
bool found;
|
| 49 |
+
|
| 50 |
+
u = vertex(0, digraph);
|
| 51 |
+
v = vertex(1, digraph);
|
| 52 |
+
add_edge(u, v, Weight(1.2), digraph);
|
| 53 |
+
add_edge(v, u, Weight(2.4), digraph);
|
| 54 |
+
tie(e1, found) = edge(u, v, digraph);
|
| 55 |
+
tie(e2, found) = edge(v, u, digraph);
|
| 56 |
+
std::cout << "in a directed graph is ";
|
| 57 |
+
#ifdef __GNUC__
|
| 58 |
+
// no boolalpha
|
| 59 |
+
std::cout << "(u,v) == (v,u) ? " << (e1 == e2) << std::endl;
|
| 60 |
+
#else
|
| 61 |
+
std::cout << "(u,v) == (v,u) ? "
|
| 62 |
+
<< std::boolalpha << (e1 == e2) << std::endl;
|
| 63 |
+
#endif
|
| 64 |
+
std::cout << "weight[(u,v)] = " << get(weight, e1) << std::endl;
|
| 65 |
+
std::cout << "weight[(v,u)] = " << get(weight, e2) << std::endl;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
template < typename UndirectedGraph > void
|
| 69 |
+
undirected_graph_demo2()
|
| 70 |
+
{
|
| 71 |
+
const int V = 2;
|
| 72 |
+
UndirectedGraph undigraph(V);
|
| 73 |
+
typename graph_traits < UndirectedGraph >::vertex_descriptor u, v;
|
| 74 |
+
typedef typename UndirectedGraph::edge_property_type Weight;
|
| 75 |
+
typename property_map < UndirectedGraph, edge_weight_t >::type
|
| 76 |
+
weight = get(edge_weight, undigraph);
|
| 77 |
+
typename graph_traits < UndirectedGraph >::edge_descriptor e1, e2;
|
| 78 |
+
bool found;
|
| 79 |
+
|
| 80 |
+
u = vertex(0, undigraph);
|
| 81 |
+
v = vertex(1, undigraph);
|
| 82 |
+
add_edge(u, v, Weight(3.1), undigraph);
|
| 83 |
+
tie(e1, found) = edge(u, v, undigraph);
|
| 84 |
+
tie(e2, found) = edge(v, u, undigraph);
|
| 85 |
+
std::cout << "in an undirected graph is ";
|
| 86 |
+
#ifdef __GNUC__
|
| 87 |
+
std::cout << "(u,v) == (v,u) ? " << (e1 == e2) << std::endl;
|
| 88 |
+
#else
|
| 89 |
+
std::cout << "(u,v) == (v,u) ? "
|
| 90 |
+
<< std::boolalpha << (e1 == e2) << std::endl;
|
| 91 |
+
#endif
|
| 92 |
+
std::cout << "weight[(u,v)] = " << get(weight, e1) << std::endl;
|
| 93 |
+
std::cout << "weight[(v,u)] = " << get(weight, e2) << std::endl;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
int
|
| 98 |
+
main()
|
| 99 |
+
{
|
| 100 |
+
typedef property < edge_weight_t, double >Weight;
|
| 101 |
+
typedef adjacency_list < vecS, vecS, undirectedS,
|
| 102 |
+
no_property, Weight > UndirectedGraph;
|
| 103 |
+
typedef adjacency_list < vecS, vecS, directedS,
|
| 104 |
+
no_property, Weight > DirectedGraph;
|
| 105 |
+
undirected_graph_demo1 < UndirectedGraph > ();
|
| 106 |
+
undirected_graph_demo2 < UndirectedGraph > ();
|
| 107 |
+
directed_graph_demo < DirectedGraph > ();
|
| 108 |
+
return 0;
|
| 109 |
+
}
|
pool/shard004/C++/0048738_test.cpp
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "hail/format.hpp"
|
| 2 |
+
#include "hail/test.hpp"
|
| 3 |
+
|
| 4 |
+
namespace hail {
|
| 5 |
+
|
| 6 |
+
Test::Test(std::string name, TestFunction *function)
|
| 7 |
+
: name(std::move(name)), function(function), next(Tests::head) {
|
| 8 |
+
Tests::head = this;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
int
|
| 12 |
+
Test::run() const {
|
| 13 |
+
format(errs, "RUN ", name, "\n");
|
| 14 |
+
function();
|
| 15 |
+
format(errs, "RUN ", name, " OK\n");
|
| 16 |
+
return 0;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
Test *Tests::head = nullptr;
|
| 20 |
+
|
| 21 |
+
int
|
| 22 |
+
Tests::run_tests() {
|
| 23 |
+
for (const Test *t = head; t; t = t->next) {
|
| 24 |
+
t->run();
|
| 25 |
+
}
|
| 26 |
+
return 0;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
int
|
| 32 |
+
main() {
|
| 33 |
+
hail::Tests::run_tests();
|
| 34 |
+
}
|
pool/shard004/C++/0048739_checkpoints.cpp
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2009-2012 The Bitcoin developers
|
| 2 |
+
// Copyright (c) 2011-2012 Litecoin Developers
|
| 3 |
+
// Copyright (c) 2013 Feathercoin Developers
|
| 4 |
+
|
| 5 |
+
// Distributed under the MIT/X11 software license, see the accompanying
|
| 6 |
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 7 |
+
|
| 8 |
+
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
|
| 9 |
+
#include <boost/foreach.hpp>
|
| 10 |
+
|
| 11 |
+
#include "checkpoints.h"
|
| 12 |
+
|
| 13 |
+
#include "main.h"
|
| 14 |
+
#include "uint256.h"
|
| 15 |
+
|
| 16 |
+
namespace Checkpoints
|
| 17 |
+
{
|
| 18 |
+
typedef std::map<int, uint256> MapCheckpoints;
|
| 19 |
+
|
| 20 |
+
//
|
| 21 |
+
// What makes a good checkpoint block?
|
| 22 |
+
// + Is surrounded by blocks with reasonable timestamps
|
| 23 |
+
// (no blocks before with a timestamp after, none after with
|
| 24 |
+
// timestamp before)
|
| 25 |
+
// + Contains no strange transactions
|
| 26 |
+
//
|
| 27 |
+
static MapCheckpoints mapCheckpoints =
|
| 28 |
+
boost::assign::map_list_of
|
| 29 |
+
( 1, uint256("0xfdbe99b90c90bae7505796461471d89ae8388ab953997aa06a355bbda8d915cb"))
|
| 30 |
+
( 22267, uint256("0x23dc7d871fc2a9b994112e978019f6370bab0b8979f557afe77a7ab620224b70"))
|
| 31 |
+
( 22847, uint256("0x1450b80c150fee1e657ee8309819276342c021fab5e6a20ccf5407f5e2218d0f"))
|
| 32 |
+
( 23453, uint256("0x7c25d3f9671e1d9400c9a1be2ff68e68db561ab85ae6b7020062d8d26da81e4c"))
|
| 33 |
+
( 28230, uint256("0xd3feb71f92c63c682f994d7c615adc425226c669a83d46012b32fc8d518b08bb"))
|
| 34 |
+
( 31846, uint256("0xba7d5c0e6d46f6448253290ce037e13975c13ca9c375ae854b6b2f85044fc0f9"))
|
| 35 |
+
;
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
bool CheckBlock(int nHeight, const uint256& hash)
|
| 39 |
+
{
|
| 40 |
+
if (fTestNet) return true; // Testnet has no checkpoints
|
| 41 |
+
|
| 42 |
+
MapCheckpoints::const_iterator i = mapCheckpoints.find(nHeight);
|
| 43 |
+
if (i == mapCheckpoints.end()) return true;
|
| 44 |
+
return hash == i->second;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
int GetTotalBlocksEstimate()
|
| 48 |
+
{
|
| 49 |
+
if (fTestNet) return 0;
|
| 50 |
+
return mapCheckpoints.rbegin()->first;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
|
| 54 |
+
{
|
| 55 |
+
if (fTestNet) return NULL;
|
| 56 |
+
|
| 57 |
+
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, mapCheckpoints)
|
| 58 |
+
{
|
| 59 |
+
const uint256& hash = i.second;
|
| 60 |
+
std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
|
| 61 |
+
if (t != mapBlockIndex.end())
|
| 62 |
+
return t->second;
|
| 63 |
+
}
|
| 64 |
+
return NULL;
|
| 65 |
+
}
|
| 66 |
+
}
|
pool/shard004/C++/0048740_monotonic_clock.cc
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "mojo/apps/js/bindings/monotonic_clock.h"
|
| 6 |
+
|
| 7 |
+
#include "gin/object_template_builder.h"
|
| 8 |
+
#include "gin/per_isolate_data.h"
|
| 9 |
+
#include "gin/public/wrapper_info.h"
|
| 10 |
+
#include "mojo/public/system/core_cpp.h"
|
| 11 |
+
|
| 12 |
+
namespace mojo {
|
| 13 |
+
namespace apps {
|
| 14 |
+
|
| 15 |
+
namespace {
|
| 16 |
+
|
| 17 |
+
gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
|
| 18 |
+
|
| 19 |
+
double GetMonotonicSeconds() {
|
| 20 |
+
const double kMicrosecondsPerSecond = 1000000;
|
| 21 |
+
return static_cast<double>(mojo::GetTimeTicksNow()) / kMicrosecondsPerSecond;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
} // namespace
|
| 25 |
+
|
| 26 |
+
const char MonotonicClock::kModuleName[] = "monotonic_clock";
|
| 27 |
+
|
| 28 |
+
v8::Local<v8::Value> MonotonicClock::GetModule(v8::Isolate* isolate) {
|
| 29 |
+
gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
|
| 30 |
+
v8::Local<v8::ObjectTemplate> templ =
|
| 31 |
+
data->GetObjectTemplate(&g_wrapper_info);
|
| 32 |
+
if (templ.IsEmpty()) {
|
| 33 |
+
templ = gin::ObjectTemplateBuilder(isolate)
|
| 34 |
+
.SetMethod("seconds", GetMonotonicSeconds)
|
| 35 |
+
.Build();
|
| 36 |
+
data->SetObjectTemplate(&g_wrapper_info, templ);
|
| 37 |
+
}
|
| 38 |
+
return templ->NewInstance();
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
} // namespace apps
|
| 42 |
+
} // namespace mojo
|
pool/shard004/C++/0048755_callbacknepomukresourceretriever.cpp
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (c) 2011 Volker Krause <vkrause@kde.org>
|
| 3 |
+
|
| 4 |
+
This library is free software; you can redistribute it and/or modify it
|
| 5 |
+
under the terms of the GNU Library General Public License as published by
|
| 6 |
+
the Free Software Foundation; either version 2 of the License, or (at your
|
| 7 |
+
option) any later version.
|
| 8 |
+
|
| 9 |
+
This library 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 Library General Public
|
| 12 |
+
License for more details.
|
| 13 |
+
|
| 14 |
+
You should have received a copy of the GNU Library General Public License
|
| 15 |
+
along with this library; see the file COPYING.LIB. If not, write to the
|
| 16 |
+
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
| 17 |
+
02110-1301, USA.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "callbacknepomukresourceretriever.h"
|
| 21 |
+
#include <Soprano/Vocabulary/NAO>
|
| 22 |
+
|
| 23 |
+
using namespace MessageList;
|
| 24 |
+
|
| 25 |
+
CallbackNepomukResourceRetriever::CallbackNepomukResourceRetriever(QObject* parent)
|
| 26 |
+
: AsyncNepomukResourceRetriever( QVector<QUrl>() << Soprano::Vocabulary::NAO::hasTag().toString()
|
| 27 |
+
<< Soprano::Vocabulary::NAO::annotation().toString()
|
| 28 |
+
<< Soprano::Vocabulary::NAO::description().toString(), parent )
|
| 29 |
+
{
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void CallbackNepomukResourceRetriever::requestResource(Core::MessageItemPrivate* item, const QUrl& url)
|
| 33 |
+
{
|
| 34 |
+
m_pendingCallbacks.insert( url, item );
|
| 35 |
+
AsyncNepomukResourceRetriever::requestResource( url );
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
void CallbackNepomukResourceRetriever::cancelCallbackRequest(const QUrl& url)
|
| 39 |
+
{
|
| 40 |
+
m_pendingCallbacks.remove( url );
|
| 41 |
+
AsyncNepomukResourceRetriever::cancelRequest( url );
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void CallbackNepomukResourceRetriever::resourceAvailable(const QUrl& url, const Nepomuk2::Resource& resource)
|
| 45 |
+
{
|
| 46 |
+
Core::MessageItemPrivate* item = m_pendingCallbacks.take( url );
|
| 47 |
+
if ( item )
|
| 48 |
+
item->resourceReceived( resource );
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
#include "callbacknepomukresourceretriever.moc"
|
pool/shard004/C++/0048761_ComponentManager.cpp
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.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 "ComponentManager.h"
|
| 19 |
+
#include "DatabaseEnv.h"
|
| 20 |
+
|
| 21 |
+
Battlenet::ComponentMgr::~ComponentMgr()
|
| 22 |
+
{
|
| 23 |
+
for (Component* component : _components)
|
| 24 |
+
delete component;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
void Battlenet::ComponentMgr::Load()
|
| 28 |
+
{
|
| 29 |
+
QueryResult result = LoginDatabase.Query("SELECT Program, Platform, Build FROM battlenet_components");
|
| 30 |
+
if (result)
|
| 31 |
+
{
|
| 32 |
+
do
|
| 33 |
+
{
|
| 34 |
+
Field* fields = result->Fetch();
|
| 35 |
+
Component* component = new Component();
|
| 36 |
+
component->Program = fields[0].GetString();
|
| 37 |
+
component->Platform = fields[1].GetString();
|
| 38 |
+
component->Build = fields[2].GetUInt32();
|
| 39 |
+
|
| 40 |
+
_components.insert(component);
|
| 41 |
+
_programs.insert(component->Program);
|
| 42 |
+
_platforms.insert(component->Platform);
|
| 43 |
+
|
| 44 |
+
} while (result->NextRow());
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
bool Battlenet::ComponentMgr::HasComponent(Battlenet::Component const* component) const
|
| 49 |
+
{
|
| 50 |
+
for (Component const* c : _components)
|
| 51 |
+
if (component->Program == c->Program && component->Platform == c->Platform && component->Build == c->Build)
|
| 52 |
+
return true;
|
| 53 |
+
|
| 54 |
+
return false;
|
| 55 |
+
}
|
pool/shard004/C++/0048764_log.cpp
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2012 Carl Leonardsson
|
| 3 |
+
*
|
| 4 |
+
* This file is part of Memorax.
|
| 5 |
+
*
|
| 6 |
+
* Memorax is free software: you can redistribute it and/or modify it
|
| 7 |
+
* 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 |
+
* Memorax is distributed in the hope that it will be useful, but WITHOUT
|
| 12 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
| 13 |
+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
| 14 |
+
* 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 |
+
#include "log.h"
|
| 22 |
+
|
| 23 |
+
#include <fstream>
|
| 24 |
+
|
| 25 |
+
namespace Log{
|
| 26 |
+
|
| 27 |
+
std::ostream *primary_stream = &std::cout;
|
| 28 |
+
bool own_primary_stream = false; // True if Log has ownership of *primary_stream
|
| 29 |
+
std::ostream *secondary_stream = 0;
|
| 30 |
+
bool own_secondary_stream = false; // True if Log has ownership of *secondary_stream
|
| 31 |
+
std::ostream *tertiary_stream = 0;
|
| 32 |
+
bool own_tertiary_stream = false; // True if Log has ownership of *tertiary_stream
|
| 33 |
+
std::ostream *warning_stream = &std::cerr;
|
| 34 |
+
std::ostream *json_stream = 0; // By default, do not print json directives
|
| 35 |
+
std::ostream *null_stream = 0;
|
| 36 |
+
|
| 37 |
+
class StreamLiberator{
|
| 38 |
+
public:
|
| 39 |
+
StreamLiberator(std::ostream **os, bool *own) : os(os), own(own) {};
|
| 40 |
+
~StreamLiberator(){
|
| 41 |
+
if(*own){
|
| 42 |
+
delete *os;
|
| 43 |
+
}
|
| 44 |
+
};
|
| 45 |
+
private:
|
| 46 |
+
std::ostream **os;
|
| 47 |
+
bool *own;
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
StreamLiberator sl_primary(&primary_stream,&own_primary_stream);
|
| 51 |
+
StreamLiberator sl_secondary(&secondary_stream,&own_secondary_stream);
|
| 52 |
+
StreamLiberator sl_tertiary(&tertiary_stream,&own_tertiary_stream);
|
| 53 |
+
|
| 54 |
+
redirection_stream result(&primary_stream);
|
| 55 |
+
redirection_stream msg(&secondary_stream);
|
| 56 |
+
redirection_stream debug(&secondary_stream);
|
| 57 |
+
redirection_stream extreme(&secondary_stream);
|
| 58 |
+
redirection_stream warning(&warning_stream);
|
| 59 |
+
redirection_stream json(&json_stream);
|
| 60 |
+
redirection_stream null(&null_stream);
|
| 61 |
+
|
| 62 |
+
void set_primary_stream(std::ostream *os){
|
| 63 |
+
if(own_primary_stream){
|
| 64 |
+
delete primary_stream;
|
| 65 |
+
own_primary_stream = false;
|
| 66 |
+
}
|
| 67 |
+
primary_stream = os;
|
| 68 |
+
};
|
| 69 |
+
void set_secondary_stream(std::ostream *os){
|
| 70 |
+
if(own_secondary_stream){
|
| 71 |
+
delete secondary_stream;
|
| 72 |
+
own_secondary_stream = false;
|
| 73 |
+
}
|
| 74 |
+
secondary_stream = os;
|
| 75 |
+
};
|
| 76 |
+
void set_tertiary_stream(std::ostream *os){
|
| 77 |
+
if(own_tertiary_stream){
|
| 78 |
+
delete tertiary_stream;
|
| 79 |
+
own_tertiary_stream = false;
|
| 80 |
+
}
|
| 81 |
+
tertiary_stream = os;
|
| 82 |
+
};
|
| 83 |
+
void set_warning_stream(std::ostream *os){
|
| 84 |
+
warning_stream = os;
|
| 85 |
+
};
|
| 86 |
+
void set_json_stream(std::ostream *os){
|
| 87 |
+
json_stream = os;
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
loglevel_t primary_loglevel = RESULTS;
|
| 91 |
+
loglevel_t secondary_loglevel = DEBUG;
|
| 92 |
+
|
| 93 |
+
void update_redirections(){
|
| 94 |
+
result.os = &tertiary_stream;
|
| 95 |
+
msg.os = &tertiary_stream;
|
| 96 |
+
debug.os = &tertiary_stream;
|
| 97 |
+
extreme.os = &tertiary_stream;
|
| 98 |
+
|
| 99 |
+
switch(secondary_loglevel){ // Note that there should be no breaks in this switch
|
| 100 |
+
case EXTREME: extreme.os = &secondary_stream;
|
| 101 |
+
case DEBUG: debug.os = &secondary_stream;
|
| 102 |
+
case MSG: msg.os = &secondary_stream;
|
| 103 |
+
case RESULTS: result.os = &secondary_stream;
|
| 104 |
+
case SILENT:
|
| 105 |
+
break;
|
| 106 |
+
}
|
| 107 |
+
switch(primary_loglevel){ // Note that there should be no breaks in this switch
|
| 108 |
+
case EXTREME: extreme.os = &primary_stream;
|
| 109 |
+
case DEBUG: debug.os = &primary_stream;
|
| 110 |
+
case MSG: msg.os = &primary_stream;
|
| 111 |
+
case RESULTS: result.os = &primary_stream;
|
| 112 |
+
case SILENT:
|
| 113 |
+
break;
|
| 114 |
+
};
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
loglevel_t get_primary_loglevel(){
|
| 118 |
+
return primary_loglevel;
|
| 119 |
+
};
|
| 120 |
+
void set_primary_loglevel(loglevel_t lv){
|
| 121 |
+
primary_loglevel = lv;
|
| 122 |
+
update_redirections();
|
| 123 |
+
};
|
| 124 |
+
loglevel_t get_secondary_loglevel(){
|
| 125 |
+
return secondary_loglevel;
|
| 126 |
+
};
|
| 127 |
+
void set_secondary_loglevel(loglevel_t lv){
|
| 128 |
+
secondary_loglevel = lv;
|
| 129 |
+
update_redirections();
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
class clofstream : public std::ofstream{
|
| 133 |
+
public:
|
| 134 |
+
clofstream(std::string filename) : std::ofstream(filename.c_str()) {};
|
| 135 |
+
~clofstream(){
|
| 136 |
+
close();
|
| 137 |
+
};
|
| 138 |
+
};
|
| 139 |
+
|
| 140 |
+
bool set_stream_file(std::string filename, std::ostream **os, bool *own){
|
| 141 |
+
if(*own){
|
| 142 |
+
delete *os;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
*os = new clofstream(filename);
|
| 146 |
+
if(**os){
|
| 147 |
+
*own = true;
|
| 148 |
+
return true;
|
| 149 |
+
}else{
|
| 150 |
+
std::cerr << "wtf?\n";
|
| 151 |
+
delete *os;
|
| 152 |
+
*os = 0;
|
| 153 |
+
*own = false;
|
| 154 |
+
return false;
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
bool set_primary_stream_file(std::string filename){
|
| 159 |
+
return set_stream_file(filename,&primary_stream,&own_primary_stream);
|
| 160 |
+
};
|
| 161 |
+
bool set_secondary_stream_file(std::string filename){
|
| 162 |
+
return set_stream_file(filename,&secondary_stream,&own_secondary_stream);
|
| 163 |
+
};
|
| 164 |
+
bool set_tertiary_stream_file(std::string filename){
|
| 165 |
+
return set_stream_file(filename,&tertiary_stream,&own_tertiary_stream);
|
| 166 |
+
};
|
| 167 |
+
|
| 168 |
+
};
|