Upload folder using huggingface_hub (part 102)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard009/C++/0106823_connection_test.cpp +80 -0
- pool/shard009/C++/0106824_text_format.cpp +84 -0
- pool/shard009/C++/0106825_datetimecalc.cpp +267 -0
- pool/shard009/C++/0106831_ink_base64.cc +163 -0
- pool/shard009/C++/0106832_locfromfile.cc +91 -0
- pool/shard009/C++/0106833_ShapeArray.cpp +167 -0
- pool/shard009/C++/0106836_pow.cpp +126 -0
- pool/shard009/C++/0106841_scripthandler.cpp +60 -0
- pool/shard009/C++/0106843_ImageRotationInvariant.cpp +60 -0
- pool/shard009/C++/0106846_session_login_browsertest.cc +73 -0
- pool/shard009/C++/0106848_moc_ExtendedTableWidget.cpp +108 -0
- pool/shard009/C++/0106854_the_eye.cpp +120 -0
- pool/shard009/C++/0106858_option.cpp +164 -0
- pool/shard009/C++/0106864_push_notifications_subscribe_task_unittest.cc +62 -0
- pool/shard009/C++/0106870_main.cpp +28 -0
- pool/shard009/C++/0106872_wisp.cpp +60 -0
- pool/shard009/C++/0106879_dummyserver.cpp +73 -0
- pool/shard009/C++/0106882_jnc_ct_OperatorMgr_Closure.cpp +210 -0
- pool/shard009/C++/0106883_HostsBasedSym.cc +67 -0
- pool/shard009/C++/0106895_dsgd.cc +189 -0
- pool/shard009/C++/0106896_rinstallprogress.cc +150 -0
- pool/shard009/C++/0106902_ABI38_0_0EventEmitter.cpp +104 -0
- pool/shard009/C++/0106903_FXNode.cpp +120 -0
- pool/shard009/C++/0106904_touchSensor.cpp +76 -0
- pool/shard009/C++/0106905_glapp.cpp +48 -0
- pool/shard009/C++/0106907_FullPermutation.cc +67 -0
- pool/shard009/C++/0106908_compare.pass.cpp +47 -0
- pool/shard009/C++/0106909_Scale_dlg.cpp +58 -0
- pool/shard009/C++/0106913_ComputeWindUp.cpp +341 -0
- pool/shard009/C++/0106915_CacheTest.cpp +158 -0
- pool/shard009/C++/0106919_B.cpp +114 -0
- pool/shard009/C++/0106920_olethros.cpp +155 -0
- pool/shard009/C++/0106926_SpatialController.cpp +61 -0
- pool/shard009/C++/0106931_os_kick.cpp +84 -0
- pool/shard009/C++/0106932_transcoderoptionsflac.cpp +44 -0
- pool/shard009/C++/0106938_rpcdump.cpp +92 -0
- pool/shard009/C++/0106941_PageParser.cpp +23 -0
- pool/shard009/C++/0106946_vbucketmap.cc +201 -0
- pool/shard009/C++/0106949_qaudiopluginloader.cpp +170 -0
- pool/shard009/C++/0106950_RPLidarTest.cpp +68 -0
- pool/shard009/C++/0106952_tst_preferenciastest.cpp +50 -0
- pool/shard009/C++/0106953_MSP430RegisterInfo.cpp +162 -0
- pool/shard009/C++/0106956_helpers.cpp +328 -0
- pool/shard009/C++/0106962_keys.cpp +103 -0
- pool/shard009/C++/0106964_unit-test-semantic-actions.cpp +131 -0
- pool/shard009/C++/0106966_DNSServer.cpp +165 -0
- pool/shard009/C++/0106978_14.40.cpp +61 -0
- pool/shard009/C++/0106979_11305-3.cc +46 -0
- pool/shard009/C++/0106983_demo_main.cc +206 -0
- pool/shard009/C++/0106991_DlgFilesSetup.cpp +155 -0
pool/shard009/C++/0106823_connection_test.cpp
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <gmock/gmock.h>
|
| 2 |
+
|
| 3 |
+
#include "connection.h"
|
| 4 |
+
#include "test/fake.h"
|
| 5 |
+
|
| 6 |
+
using ::testing::_;
|
| 7 |
+
using ::testing::ElementsAreArray;
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
namespace ygg {
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class MockConnectionDelegate : public Connection::Delegate {
|
| 14 |
+
public:
|
| 15 |
+
MOCK_METHOD2(OnText, void(Connection*, const Text&));
|
| 16 |
+
MOCK_METHOD2(OnBinary, void(Connection*, const Bytes&));
|
| 17 |
+
MOCK_METHOD1(OnClosed, void(Connection*));
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
TEST(ConnectionTest, fire_text_event) {
|
| 22 |
+
|
| 23 |
+
static const Text kText("second");
|
| 24 |
+
static const Text kExpected(kText);
|
| 25 |
+
|
| 26 |
+
Connection::Ptr conn(test::FakeConnection::New());
|
| 27 |
+
|
| 28 |
+
MockConnectionDelegate mock;
|
| 29 |
+
EXPECT_CALL(mock, OnText(conn.get(), kExpected)).Times(2);
|
| 30 |
+
|
| 31 |
+
conn->FireOnTextEvent("first");
|
| 32 |
+
|
| 33 |
+
conn->BindDelegate(&mock);
|
| 34 |
+
conn->FireOnTextEvent(kText);
|
| 35 |
+
conn->FireOnTextEvent(kText);
|
| 36 |
+
conn->UnbindDelegate();
|
| 37 |
+
|
| 38 |
+
conn->FireOnTextEvent("third");
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
TEST(ConnectionTest, fire_binary_event) {
|
| 42 |
+
|
| 43 |
+
static const uint8_t kData[10] = {0,1,2,3,4,5,6,7,8,9};
|
| 44 |
+
static const Bytes kBuffer(kData, kData+10);
|
| 45 |
+
static const auto kExpected = ElementsAreArray(kData, 10);
|
| 46 |
+
|
| 47 |
+
Connection::Ptr conn(test::FakeConnection::New());
|
| 48 |
+
|
| 49 |
+
MockConnectionDelegate mock;
|
| 50 |
+
EXPECT_CALL(mock, OnBinary(conn.get(), kExpected)).Times(2);
|
| 51 |
+
|
| 52 |
+
conn->FireOnBinaryEvent(kBuffer);
|
| 53 |
+
|
| 54 |
+
conn->BindDelegate(&mock);
|
| 55 |
+
conn->FireOnBinaryEvent(kBuffer);
|
| 56 |
+
conn->FireOnBinaryEvent(kBuffer);
|
| 57 |
+
conn->UnbindDelegate();
|
| 58 |
+
|
| 59 |
+
conn->FireOnBinaryEvent(kBuffer);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
TEST(ConnectionTest, fire_close_event) {
|
| 63 |
+
|
| 64 |
+
Connection::Ptr conn(test::FakeConnection::New());
|
| 65 |
+
|
| 66 |
+
MockConnectionDelegate mock;
|
| 67 |
+
EXPECT_CALL(mock, OnClosed(conn.get())).Times(2);
|
| 68 |
+
|
| 69 |
+
conn->FireOnClosedEvent();
|
| 70 |
+
|
| 71 |
+
conn->BindDelegate(&mock);
|
| 72 |
+
conn->FireOnClosedEvent();
|
| 73 |
+
conn->FireOnClosedEvent();
|
| 74 |
+
conn->UnbindDelegate();
|
| 75 |
+
|
| 76 |
+
conn->FireOnClosedEvent();
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
} // namespace ygg
|
pool/shard009/C++/0106824_text_format.cpp
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "pch.h"
|
| 2 |
+
#include "angsys.h"
|
| 3 |
+
#include "format_parser.h"
|
| 4 |
+
|
| 5 |
+
using namespace ang;
|
| 6 |
+
using namespace ang::text;
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
text_format::text_format_flags::text_format_flags()
|
| 10 |
+
{
|
| 11 |
+
value = 0;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
text_format::text_format_flags::text_format_flags(qword val)
|
| 15 |
+
{
|
| 16 |
+
value = val;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
text_format::text_format_flags::text_format_flags(ang::text::text_format::target t)
|
| 20 |
+
{
|
| 21 |
+
value = 0;
|
| 22 |
+
target = t;
|
| 23 |
+
switch (t)
|
| 24 |
+
{
|
| 25 |
+
case bool_:
|
| 26 |
+
case_ = 3;
|
| 27 |
+
break;
|
| 28 |
+
case float_:
|
| 29 |
+
pres = 4;
|
| 30 |
+
break;
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
text_format::text_format()
|
| 35 |
+
{
|
| 36 |
+
flags.value = 0;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
text_format::text_format(castr_t format)
|
| 40 |
+
{
|
| 41 |
+
flags.value = format_parser<encoding::ascii>::parse(format);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
text_format::text_format(qword format)
|
| 45 |
+
{
|
| 46 |
+
flags.value = format;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
text_format::text_format(const text_format& val)
|
| 50 |
+
{
|
| 51 |
+
flags.value = val.flags.value;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
text_format::text_format(const text_format_flags& val)
|
| 55 |
+
{
|
| 56 |
+
flags.value = val.value;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
text_format::~text_format()
|
| 60 |
+
{
|
| 61 |
+
flags.value = 0;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
text_format::target text_format::format_target()const
|
| 65 |
+
{
|
| 66 |
+
return flags.target;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
void text_format::format(castr_t format)
|
| 70 |
+
{
|
| 71 |
+
flags.value = format_parser<encoding::ascii>::parse(format);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
qword text_format::format_flags()const
|
| 75 |
+
{
|
| 76 |
+
return flags.value;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
text_format& text_format::operator = (const text_format& val)
|
| 80 |
+
{
|
| 81 |
+
flags.value = val.flags.value;
|
| 82 |
+
return*this;
|
| 83 |
+
}
|
| 84 |
+
|
pool/shard009/C++/0106825_datetimecalc.cpp
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*******************************************************************************
|
| 2 |
+
*
|
| 3 |
+
* FILE NAME: datetimecalc.cpp
|
| 4 |
+
*
|
| 5 |
+
* DESCRIPTION:
|
| 6 |
+
* Code for time and data calculation class.
|
| 7 |
+
* This code was generated by qmake.
|
| 8 |
+
*
|
| 9 |
+
* AUTHOR: James P. Parziale
|
| 10 |
+
*
|
| 11 |
+
* DATE CREATED: 02/16/2009
|
| 12 |
+
*
|
| 13 |
+
* This file may be distributed under the terms of the GNU Public License.
|
| 14 |
+
*
|
| 15 |
+
*******************************************************************************
|
| 16 |
+
* HISTORY:
|
| 17 |
+
* 00 02/16/2009
|
| 18 |
+
* Original version
|
| 19 |
+
******************************************************************************/
|
| 20 |
+
|
| 21 |
+
#include "datetimecalc.h"
|
| 22 |
+
#include "about.h"
|
| 23 |
+
|
| 24 |
+
#include <iostream>
|
| 25 |
+
using namespace std;
|
| 26 |
+
|
| 27 |
+
//******************************************************************************
|
| 28 |
+
|
| 29 |
+
DateTimeCalc::DateTimeCalc(QWidget *parent) :
|
| 30 |
+
QMainWindow(parent)
|
| 31 |
+
{
|
| 32 |
+
ui.setupUi(this);
|
| 33 |
+
|
| 34 |
+
// Set the base time and date fields to the current time and date.
|
| 35 |
+
ui.baseTimeEdit->setTime(QTime::currentTime());
|
| 36 |
+
ui.baseDateEdit->setDate(QDate::currentDate());
|
| 37 |
+
ui.resultDateEdit->setDate(QDate::currentDate());
|
| 38 |
+
|
| 39 |
+
ui.baseDateDiffEdit->setDate(QDate::currentDate());
|
| 40 |
+
ui.targetDateDiffEdit->setDate(QDate::currentDate());
|
| 41 |
+
|
| 42 |
+
// Initialize operations
|
| 43 |
+
timeOp = GetTimeOp();
|
| 44 |
+
dateOp = GetDateOp();
|
| 45 |
+
|
| 46 |
+
// Initialize time result
|
| 47 |
+
timeResult = QTime::currentTime();
|
| 48 |
+
SetTimeResultText();
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
DateTimeCalc::~DateTimeCalc()
|
| 52 |
+
{
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
//******************************************************************************
|
| 56 |
+
|
| 57 |
+
void DateTimeCalc::on_aboutButton_clicked()
|
| 58 |
+
{
|
| 59 |
+
About about_dialog(this);
|
| 60 |
+
about_dialog.exec();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
void DateTimeCalc::on_actionAbout_triggered()
|
| 64 |
+
{
|
| 65 |
+
About about_dialog(this);
|
| 66 |
+
about_dialog.exec();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
//******************************************************************************
|
| 70 |
+
|
| 71 |
+
DateTimeCalc::TimeDateOp DateTimeCalc::GetTimeOp()
|
| 72 |
+
{
|
| 73 |
+
TimeDateOp ret;
|
| 74 |
+
if (ui.timePlusRadioButton->isChecked()) {
|
| 75 |
+
ret = Add;
|
| 76 |
+
} else if (ui.timeMinusRadioButton->isChecked()) {
|
| 77 |
+
ret = Subtract;
|
| 78 |
+
} else {
|
| 79 |
+
ret = Invalid;
|
| 80 |
+
}
|
| 81 |
+
return ret;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
DateTimeCalc::TimeDateOp DateTimeCalc::GetDateOp()
|
| 85 |
+
{
|
| 86 |
+
TimeDateOp ret;
|
| 87 |
+
if (ui.datePlusRadioButton->isChecked()) {
|
| 88 |
+
ret = Add;
|
| 89 |
+
} else if (ui.dateMinusRadioButton->isChecked()) {
|
| 90 |
+
ret = Subtract;
|
| 91 |
+
} else {
|
| 92 |
+
ret = Invalid;
|
| 93 |
+
}
|
| 94 |
+
return ret;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
void DateTimeCalc::SetTimeResultText()
|
| 98 |
+
{
|
| 99 |
+
ui.resultTimeEdit->setText(timeResult.toString(Qt::TextDate));
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
//******************************************************************************
|
| 103 |
+
|
| 104 |
+
void DateTimeCalc::on_timeNowButton_clicked()
|
| 105 |
+
{
|
| 106 |
+
ui.baseTimeEdit->setTime(QTime::currentTime());
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
void DateTimeCalc::on_timeOffsetNowButton_clicked()
|
| 110 |
+
{
|
| 111 |
+
ui.offsetTimeEdit->setTime(QTime::currentTime());
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
void DateTimeCalc::on_timePlusRadioButton_clicked()
|
| 116 |
+
{
|
| 117 |
+
timeOp = Add;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
void DateTimeCalc::on_timeMinusRadioButton_clicked()
|
| 121 |
+
{
|
| 122 |
+
timeOp = Subtract;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
//******************************************************************************
|
| 126 |
+
|
| 127 |
+
void DateTimeCalc::on_dateTodayButton_clicked()
|
| 128 |
+
{
|
| 129 |
+
ui.baseDateEdit->setDate(QDate::currentDate());
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
void DateTimeCalc::on_datePlusRadioButton_clicked()
|
| 133 |
+
{
|
| 134 |
+
dateOp = Add;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
void DateTimeCalc::on_dateMinusRadioButton_clicked()
|
| 138 |
+
{
|
| 139 |
+
dateOp = Subtract;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
//******************************************************************************
|
| 143 |
+
|
| 144 |
+
void DateTimeCalc::on_dateRefTodayButton_clicked()
|
| 145 |
+
{
|
| 146 |
+
ui.baseDateDiffEdit->setDate(QDate::currentDate());
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
void DateTimeCalc::on_dateTargetTodayButton_clicked()
|
| 150 |
+
{
|
| 151 |
+
ui.targetDateDiffEdit->setDate(QDate::currentDate());
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
//******************************************************************************
|
| 155 |
+
|
| 156 |
+
void DateTimeCalc::on_timeCalcButton_clicked()
|
| 157 |
+
{
|
| 158 |
+
QTime baseQTime = ui.baseTimeEdit->time();
|
| 159 |
+
QTime result = baseQTime;
|
| 160 |
+
|
| 161 |
+
QTime offsetQTime = ui.offsetTimeEdit->time();
|
| 162 |
+
int offset = (offsetQTime.hour() * 3600)
|
| 163 |
+
+ (offsetQTime.minute() * 60)
|
| 164 |
+
+ offsetQTime.second();
|
| 165 |
+
|
| 166 |
+
switch (timeOp) {
|
| 167 |
+
case Add:
|
| 168 |
+
result = result.addSecs(offset);
|
| 169 |
+
break;
|
| 170 |
+
|
| 171 |
+
case Subtract:
|
| 172 |
+
result = result.addSecs(-offset);
|
| 173 |
+
break;
|
| 174 |
+
|
| 175 |
+
default:
|
| 176 |
+
printf("ERROR: Invalid time operation.\n");
|
| 177 |
+
break;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
timeResult = result;
|
| 181 |
+
SetTimeResultText();
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
//******************************************************************************
|
| 185 |
+
|
| 186 |
+
void DateTimeCalc::on_dateCalcButton_clicked()
|
| 187 |
+
{
|
| 188 |
+
QDate baseQDate = ui.baseDateEdit->date();
|
| 189 |
+
QDate result = baseQDate;
|
| 190 |
+
|
| 191 |
+
QString daysText = ui.daysEdit->text();
|
| 192 |
+
QString weeksText = ui.weeksEdit->text();
|
| 193 |
+
QString yearsText = ui.yearsEdit->text();
|
| 194 |
+
|
| 195 |
+
bool ok = true;
|
| 196 |
+
int days = daysText.toInt(&ok);
|
| 197 |
+
if (!ok) {
|
| 198 |
+
printf("ERROR: Invalid number for days.\n");
|
| 199 |
+
}
|
| 200 |
+
int weeks = weeksText.toInt(&ok);
|
| 201 |
+
if (!ok) {
|
| 202 |
+
printf("ERROR: Invalid number for weeks.\n");
|
| 203 |
+
}
|
| 204 |
+
int years = yearsText.toInt(&ok);
|
| 205 |
+
if (!ok) {
|
| 206 |
+
printf("ERROR: Invalid number for years.\n");
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
switch (dateOp) {
|
| 210 |
+
case Add:
|
| 211 |
+
result = result.addDays(days);
|
| 212 |
+
result = result.addDays(weeks*7);
|
| 213 |
+
result = result.addYears(years);
|
| 214 |
+
break;
|
| 215 |
+
|
| 216 |
+
case Subtract:
|
| 217 |
+
result = result.addDays(-days);
|
| 218 |
+
result = result.addDays(-weeks*7);
|
| 219 |
+
result = result.addYears(-years);
|
| 220 |
+
break;
|
| 221 |
+
|
| 222 |
+
default:
|
| 223 |
+
printf("ERROR: Invalid date operation.\n");
|
| 224 |
+
break;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
ui.resultDateEdit->setDate(result);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
//******************************************************************************
|
| 231 |
+
|
| 232 |
+
void DateTimeCalc::on_dateDiffCalcButton_clicked()
|
| 233 |
+
{
|
| 234 |
+
QDate baseQDate = ui.baseDateDiffEdit->date();
|
| 235 |
+
QDate baseDate = baseQDate;
|
| 236 |
+
|
| 237 |
+
QDate targetQDate = ui.targetDateDiffEdit->date();
|
| 238 |
+
QDate targetDate = targetQDate;
|
| 239 |
+
|
| 240 |
+
// Calculate difference in dates
|
| 241 |
+
long result = abs(targetDate.daysTo(baseDate));
|
| 242 |
+
|
| 243 |
+
QString resultText = QString("%1").arg(result) + " days;\n";
|
| 244 |
+
|
| 245 |
+
int y = result / 365;
|
| 246 |
+
int ld = y / 4;
|
| 247 |
+
int d = result - (y * 365) - ld;
|
| 248 |
+
int wks = d / 7;
|
| 249 |
+
int remDays = d % 7;
|
| 250 |
+
|
| 251 |
+
if (remDays < 0) {
|
| 252 |
+
remDays += 7;
|
| 253 |
+
wks -= 1;
|
| 254 |
+
}
|
| 255 |
+
if (wks < 0) {
|
| 256 |
+
wks += 52;
|
| 257 |
+
y -= 1;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
resultText += " " + QString("%1").arg(y) + " years,\n"
|
| 261 |
+
+ " " + QString("%1").arg(wks) + " weeks,\n"
|
| 262 |
+
+ " " + QString("%1").arg(remDays) + " days";
|
| 263 |
+
|
| 264 |
+
ui.dateDiffResultEdit->setPlainText(resultText);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
//******************************************************************************
|
pool/shard009/C++/0106831_ink_base64.cc
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @file
|
| 2 |
+
|
| 3 |
+
A brief file description
|
| 4 |
+
|
| 5 |
+
@section license License
|
| 6 |
+
|
| 7 |
+
Licensed to the Apache Software Foundation (ASF) under one
|
| 8 |
+
or more contributor license agreements. See the NOTICE file
|
| 9 |
+
distributed with this work for additional information
|
| 10 |
+
regarding copyright ownership. The ASF licenses this file
|
| 11 |
+
to you under the Apache License, Version 2.0 (the
|
| 12 |
+
"License"); you may not use this file except in compliance
|
| 13 |
+
with the License. You may obtain a copy of the License at
|
| 14 |
+
|
| 15 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 16 |
+
|
| 17 |
+
Unless required by applicable law or agreed to in writing, software
|
| 18 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 19 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 20 |
+
See the License for the specific language governing permissions and
|
| 21 |
+
limitations under the License.
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
/*
|
| 25 |
+
* Base64 encoding and decoding as according to RFC1521. Similar to uudecode.
|
| 26 |
+
*
|
| 27 |
+
* RFC 1521 requires inserting line breaks for long lines. The basic web
|
| 28 |
+
* authentication scheme does not require them. This implementation is
|
| 29 |
+
* intended for web-related use, and line breaks are not implemented.
|
| 30 |
+
*
|
| 31 |
+
* These routines return char*'s to malloc-ed strings. The caller is
|
| 32 |
+
* responsible for freeing the strings.
|
| 33 |
+
*/
|
| 34 |
+
#include "ts/ink_platform.h"
|
| 35 |
+
#include "ts/ink_base64.h"
|
| 36 |
+
#include "ts/ink_assert.h"
|
| 37 |
+
|
| 38 |
+
// TODO: The code here seems a bit klunky, and could probably be improved a bit.
|
| 39 |
+
|
| 40 |
+
bool
|
| 41 |
+
ats_base64_encode(const unsigned char *inBuffer, size_t inBufferSize, char *outBuffer, size_t outBufSize, size_t *length)
|
| 42 |
+
{
|
| 43 |
+
static const char _codes[66] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
| 44 |
+
char *obuf = outBuffer;
|
| 45 |
+
char in_tail[4];
|
| 46 |
+
|
| 47 |
+
if (outBufSize < ATS_BASE64_ENCODE_DSTLEN(inBufferSize))
|
| 48 |
+
return false;
|
| 49 |
+
|
| 50 |
+
while (inBufferSize > 2) {
|
| 51 |
+
*obuf++ = _codes[(inBuffer[0] >> 2) & 077];
|
| 52 |
+
*obuf++ = _codes[((inBuffer[0] & 03) << 4) | ((inBuffer[1] >> 4) & 017)];
|
| 53 |
+
*obuf++ = _codes[((inBuffer[1] & 017) << 2) | ((inBuffer[2] >> 6) & 017)];
|
| 54 |
+
*obuf++ = _codes[inBuffer[2] & 077];
|
| 55 |
+
|
| 56 |
+
inBufferSize -= 3;
|
| 57 |
+
inBuffer += 3;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/*
|
| 61 |
+
* We've done all the input groups of three chars. We're left
|
| 62 |
+
* with 0, 1, or 2 input chars. We have to add zero-bits to the
|
| 63 |
+
* right if we don't have enough input chars.
|
| 64 |
+
* If 0 chars left, we're done.
|
| 65 |
+
* If 1 char left, form 2 output chars, and add 2 pad chars to output.
|
| 66 |
+
* If 2 chars left, form 3 output chars, add 1 pad char to output.
|
| 67 |
+
*/
|
| 68 |
+
if (inBufferSize == 0) {
|
| 69 |
+
*obuf = '\0';
|
| 70 |
+
if (length)
|
| 71 |
+
*length = (obuf - outBuffer);
|
| 72 |
+
} else {
|
| 73 |
+
memset(in_tail, 0, sizeof(in_tail));
|
| 74 |
+
memcpy(in_tail, inBuffer, inBufferSize);
|
| 75 |
+
|
| 76 |
+
*(obuf) = _codes[(in_tail[0] >> 2) & 077];
|
| 77 |
+
*(obuf + 1) = _codes[((in_tail[0] & 03) << 4) | ((in_tail[1] >> 4) & 017)];
|
| 78 |
+
*(obuf + 2) = _codes[((in_tail[1] & 017) << 2) | ((in_tail[2] >> 6) & 017)];
|
| 79 |
+
*(obuf + 3) = _codes[in_tail[2] & 077];
|
| 80 |
+
|
| 81 |
+
if (inBufferSize == 1)
|
| 82 |
+
*(obuf + 2) = '=';
|
| 83 |
+
*(obuf + 3) = '=';
|
| 84 |
+
*(obuf + 4) = '\0';
|
| 85 |
+
|
| 86 |
+
if (length)
|
| 87 |
+
*length = (obuf + 4) - outBuffer;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
return true;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
bool
|
| 94 |
+
ats_base64_encode(const char *inBuffer, size_t inBufferSize, char *outBuffer, size_t outBufSize, size_t *length)
|
| 95 |
+
{
|
| 96 |
+
return ats_base64_encode((const unsigned char *)inBuffer, inBufferSize, outBuffer, outBufSize, length);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/*-------------------------------------------------------------------------
|
| 100 |
+
This is a reentrant, and malloc free implemetnation of ats_base64_decode.
|
| 101 |
+
-------------------------------------------------------------------------*/
|
| 102 |
+
#ifdef DECODE
|
| 103 |
+
#undef DECODE
|
| 104 |
+
#endif
|
| 105 |
+
|
| 106 |
+
#define DECODE(x) printableToSixBit[(unsigned char)x]
|
| 107 |
+
#define MAX_PRINT_VAL 63
|
| 108 |
+
|
| 109 |
+
/* Converts a printable character to it's six bit representation */
|
| 110 |
+
const unsigned char printableToSixBit[256] = {
|
| 111 |
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
| 112 |
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 62, 64, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
|
| 113 |
+
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 63,
|
| 114 |
+
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
|
| 115 |
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
| 116 |
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
| 117 |
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
| 118 |
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64};
|
| 119 |
+
|
| 120 |
+
bool
|
| 121 |
+
ats_base64_decode(const char *inBuffer, size_t inBufferSize, unsigned char *outBuffer, size_t outBufSize, size_t *length)
|
| 122 |
+
{
|
| 123 |
+
size_t inBytes = 0;
|
| 124 |
+
size_t decodedBytes = 0;
|
| 125 |
+
unsigned char *buf = outBuffer;
|
| 126 |
+
int inputBytesDecoded = 0;
|
| 127 |
+
|
| 128 |
+
// Make sure there is sufficient space in the output buffer
|
| 129 |
+
if (outBufSize < ATS_BASE64_DECODE_DSTLEN(inBufferSize))
|
| 130 |
+
return false;
|
| 131 |
+
|
| 132 |
+
// Ignore any trailing ='s or other undecodable characters.
|
| 133 |
+
// TODO: Perhaps that ought to be an error instead?
|
| 134 |
+
while (printableToSixBit[(uint8_t)inBuffer[inBytes]] <= MAX_PRINT_VAL)
|
| 135 |
+
++inBytes;
|
| 136 |
+
|
| 137 |
+
for (size_t i = 0; i < inBytes; i += 4) {
|
| 138 |
+
buf[0] = (unsigned char)(DECODE(inBuffer[0]) << 2 | DECODE(inBuffer[1]) >> 4);
|
| 139 |
+
buf[1] = (unsigned char)(DECODE(inBuffer[1]) << 4 | DECODE(inBuffer[2]) >> 2);
|
| 140 |
+
buf[2] = (unsigned char)(DECODE(inBuffer[2]) << 6 | DECODE(inBuffer[3]));
|
| 141 |
+
|
| 142 |
+
buf += 3;
|
| 143 |
+
inBuffer += 4;
|
| 144 |
+
decodedBytes += 3;
|
| 145 |
+
inputBytesDecoded += 4;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// Check to see if we decoded a multiple of 4 four
|
| 149 |
+
// bytes
|
| 150 |
+
if ((inBytes - inputBytesDecoded) & 0x3) {
|
| 151 |
+
if (DECODE(inBuffer[-2]) > MAX_PRINT_VAL) {
|
| 152 |
+
decodedBytes -= 2;
|
| 153 |
+
} else {
|
| 154 |
+
decodedBytes -= 1;
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
outBuffer[decodedBytes] = '\0';
|
| 158 |
+
|
| 159 |
+
if (length)
|
| 160 |
+
*length = decodedBytes;
|
| 161 |
+
|
| 162 |
+
return true;
|
| 163 |
+
}
|
pool/shard009/C++/0106832_locfromfile.cc
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* locfromfile.{cc,hh} -- play a trace of locations.
|
| 3 |
+
* Robert Morris
|
| 4 |
+
*
|
| 5 |
+
* Copyright (c) 1999-2000 Massachusetts Institute of Technology
|
| 6 |
+
*
|
| 7 |
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
| 8 |
+
* copy of this software and associated documentation files (the "Software"),
|
| 9 |
+
* to deal in the Software without restriction, subject to the conditions
|
| 10 |
+
* listed in the Click LICENSE file. These conditions include: you must
|
| 11 |
+
* preserve this copyright notice, and you cannot mention the copyright
|
| 12 |
+
* holders in advertising related to the Software without their permission.
|
| 13 |
+
* The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
|
| 14 |
+
* notice is a summary of the Click LICENSE file; the license in that file is
|
| 15 |
+
* legally binding.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include <click/config.h>
|
| 19 |
+
#include "locfromfile.hh"
|
| 20 |
+
#include <click/glue.hh>
|
| 21 |
+
#include <click/confparse.hh>
|
| 22 |
+
#include <click/router.hh>
|
| 23 |
+
#include <click/error.hh>
|
| 24 |
+
CLICK_DECLS
|
| 25 |
+
|
| 26 |
+
LocFromFile::LocFromFile()
|
| 27 |
+
{
|
| 28 |
+
_next = 0;
|
| 29 |
+
_move = 1;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
LocFromFile::~LocFromFile()
|
| 33 |
+
{
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
void *
|
| 37 |
+
LocFromFile::cast(const char *name)
|
| 38 |
+
{
|
| 39 |
+
if(strcmp(name, "GridLocationInfo") == 0)
|
| 40 |
+
return(this);
|
| 41 |
+
return(GridLocationInfo::cast(name));
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
int
|
| 45 |
+
LocFromFile::configure(Vector<String> &conf, ErrorHandler *errh)
|
| 46 |
+
{
|
| 47 |
+
String filename;
|
| 48 |
+
int res = cp_va_kparse(conf, this, errh,
|
| 49 |
+
"FILENAME", cpkP+cpkM, cpFilename, &filename,
|
| 50 |
+
cpEnd);
|
| 51 |
+
if(res >= 0){
|
| 52 |
+
FILE *fp = fopen(filename.c_str(), "r");
|
| 53 |
+
if(fp == 0)
|
| 54 |
+
return(errh->error("cannot open file %s", filename.c_str()));
|
| 55 |
+
char buf[512];
|
| 56 |
+
while(fgets(buf, sizeof(buf), fp)){
|
| 57 |
+
struct delta d;
|
| 58 |
+
if(sscanf(buf, "%lf%lf%lf", &d.interval, &d.lat, &d.lon) == 3){
|
| 59 |
+
_deltas.push_back(d);
|
| 60 |
+
} else {
|
| 61 |
+
fclose(fp);
|
| 62 |
+
return(errh->error("cannot parse a line in file %s", filename.c_str()));
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
fclose(fp);
|
| 66 |
+
if(_deltas.size() < 1)
|
| 67 |
+
return(errh->error("no locations in file %s", filename.c_str()));
|
| 68 |
+
click_chatter("read %d deltas from %s",
|
| 69 |
+
_deltas.size(),
|
| 70 |
+
filename.c_str());
|
| 71 |
+
}
|
| 72 |
+
return res;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// Pick a new place to move to, and a time by which we want
|
| 76 |
+
// to arrive there.
|
| 77 |
+
void
|
| 78 |
+
LocFromFile::choose_new_leg(double *nlat, double *nlon, double *nt)
|
| 79 |
+
{
|
| 80 |
+
*nlat = _deltas[_next].lat;
|
| 81 |
+
*nlon = _deltas[_next].lon;
|
| 82 |
+
*nt = _t0 + _deltas[_next].interval;
|
| 83 |
+
|
| 84 |
+
_next += 1;
|
| 85 |
+
if(_next >= _deltas.size())
|
| 86 |
+
_next = 0;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
CLICK_ENDDECLS
|
| 90 |
+
ELEMENT_REQUIRES(userlevel GridLocationInfo)
|
| 91 |
+
EXPORT_ELEMENT(LocFromFile)
|
pool/shard009/C++/0106833_ShapeArray.cpp
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "stdafx.h"
|
| 2 |
+
#include "ShapeArray.h"
|
| 3 |
+
#include <boost/functional/hash.hpp>
|
| 4 |
+
#include "Util.h"
|
| 5 |
+
|
| 6 |
+
using namespace std;
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
size_t hash_value(const struct shpmainheader& header) {
|
| 10 |
+
size_t seed = 0;
|
| 11 |
+
boost::hash_combine(seed, header.shapetype);
|
| 12 |
+
boost::hash_combine(seed, (float)header.xmin);
|
| 13 |
+
boost::hash_combine(seed, (float)header.ymin);
|
| 14 |
+
boost::hash_combine(seed, (float)header.ymax);
|
| 15 |
+
boost::hash_combine(seed, (float)header.zmin);
|
| 16 |
+
boost::hash_combine(seed, (float)header.zmax);
|
| 17 |
+
return seed;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
size_t hash_value(const struct point3d& point) {
|
| 21 |
+
size_t seed = 0;
|
| 22 |
+
boost::hash_combine(seed, (float)point.x);
|
| 23 |
+
boost::hash_combine(seed, (float)point.y);
|
| 24 |
+
boost::hash_combine(seed, (float)point.z);
|
| 25 |
+
return seed;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
size_t hash_value(const struct shpheader& header) {
|
| 29 |
+
size_t seed = 0;
|
| 30 |
+
boost::hash_combine(seed, (float)header.xmin);
|
| 31 |
+
boost::hash_combine(seed, (float)header.ymin);
|
| 32 |
+
boost::hash_combine(seed, (float)header.xmax);
|
| 33 |
+
boost::hash_combine(seed, (float)header.ymax);
|
| 34 |
+
boost::hash_combine(seed, (float)header.zmin);
|
| 35 |
+
boost::hash_combine(seed, (float)header.zmax);
|
| 36 |
+
boost::hash_combine(seed, header.numparts);
|
| 37 |
+
boost::hash_combine(seed, header.numpoints);
|
| 38 |
+
return seed;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
size_t hash_value(const VI_Shape& shape) {
|
| 42 |
+
size_t seed = 0;
|
| 43 |
+
boost::hash_combine(seed, shape.ShapeType);
|
| 44 |
+
boost::hash_combine(seed, shape.ShapeHeader);
|
| 45 |
+
boost::hash_range(seed, shape.Parts.begin(), shape.Parts.end());
|
| 46 |
+
boost::hash_range(seed, shape.Vertices->begin(), shape.Vertices->end());
|
| 47 |
+
return seed;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
VI_ShapeArray::VI_ShapeArray(shared_ptr<vector<VI_Shape>> array,
|
| 51 |
+
struct shpmainheader header)
|
| 52 |
+
{
|
| 53 |
+
i_array = array;
|
| 54 |
+
i_shpHeader = header;
|
| 55 |
+
i_hashCode = ComputeHashCode();
|
| 56 |
+
i_numVertices = ComputeNumVertices();
|
| 57 |
+
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
bool VI_ShapeArray::HasData() const {
|
| 61 |
+
return (bool)i_array;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
unsigned VI_ShapeArray::GetNumShapes() const {
|
| 65 |
+
return i_array->size();
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
const VI_Shape& VI_ShapeArray::GetValue(unsigned index) const {
|
| 70 |
+
return i_array->at(index);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
VI_Shape& VI_ShapeArray::GetValue(unsigned index) {
|
| 74 |
+
return i_array->at(index);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
struct shpmainheader VI_ShapeArray::GetShpMainHeader() const {
|
| 78 |
+
return i_shpHeader;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
size_t VI_ShapeArray::ComputeHashCode() {
|
| 82 |
+
size_t seed = 0;
|
| 83 |
+
if (HasData()) {
|
| 84 |
+
boost::hash_range(seed, i_array->begin(), i_array->end());
|
| 85 |
+
boost::hash_combine(seed, i_shpHeader);
|
| 86 |
+
}
|
| 87 |
+
return seed;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
size_t VI_ShapeArray::GetHashCode() const {
|
| 91 |
+
return i_hashCode;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
unsigned VI_ShapeArray::GetNumVertices() const {
|
| 95 |
+
return i_numVertices;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
unsigned VI_ShapeArray::ComputeNumVertices() {
|
| 99 |
+
unsigned total = 0;
|
| 100 |
+
if (HasData()) {
|
| 101 |
+
for (const auto& it : *i_array) {
|
| 102 |
+
total += it.ShapeHeader.numpoints;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
return total;
|
| 106 |
+
}
|
| 107 |
+
VI_ShapeArray ImportFromSHPFile(const std::string& fileName) {
|
| 108 |
+
auto shapes = initVectorArray<VI_Shape>();
|
| 109 |
+
auto shpHandle = SHPOpen(fileName.c_str(), "rb");
|
| 110 |
+
int numShapes;
|
| 111 |
+
int type;
|
| 112 |
+
SHPGetInfo(shpHandle, &numShapes, &type, NULL, NULL);
|
| 113 |
+
|
| 114 |
+
shared_ptr<vector<VI_Shape>> shapeArray(new vector<VI_Shape>(numShapes));
|
| 115 |
+
for (int i = 0; i < numShapes; i++) {
|
| 116 |
+
shared_ptr<SHPObject> shpObject(SHPReadObject(shpHandle, i), [](SHPObject* obj) {
|
| 117 |
+
SHPDestroyObject(obj);
|
| 118 |
+
});
|
| 119 |
+
shapeArray->at(i).ShapeHeader.numparts = shpObject->nParts;
|
| 120 |
+
shapeArray->at(i).ShapeHeader.numpoints = shpObject->nVertices;
|
| 121 |
+
shapeArray->at(i).ShapeHeader.xmax = shpObject->dfXMax;
|
| 122 |
+
shapeArray->at(i).ShapeHeader.ymax = shpObject->dfYMax;
|
| 123 |
+
shapeArray->at(i).ShapeHeader.zmax = shpObject->dfZMax;
|
| 124 |
+
shapeArray->at(i).ShapeHeader.xmin = shpObject->dfXMin;
|
| 125 |
+
shapeArray->at(i).ShapeHeader.ymin = shpObject->dfYMin;
|
| 126 |
+
shapeArray->at(i).ShapeHeader.zmin = shpObject->dfZMin;
|
| 127 |
+
shapeArray->at(i).ShapeType = type;
|
| 128 |
+
shapeArray->at(i).Parts.insert(shapeArray->at(i).Parts.begin(),
|
| 129 |
+
shpObject->panPartStart, shpObject->panPartStart + shpObject->nParts);
|
| 130 |
+
shared_ptr<vector<struct point3d>> pointArray(new vector<struct point3d>(shpObject->nVertices));
|
| 131 |
+
for (int j = 0; j < shpObject->nVertices; j++) {
|
| 132 |
+
pointArray->at(j).x = shpObject->padfX[j];
|
| 133 |
+
pointArray->at(j).y = shpObject->padfY[j];
|
| 134 |
+
pointArray->at(j).z = shpObject->padfZ[j];
|
| 135 |
+
}
|
| 136 |
+
shapeArray->at(i).Vertices = pointArray;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
struct shpmainheader header;
|
| 140 |
+
header.filecode = -1;
|
| 141 |
+
header.filelength = -1;
|
| 142 |
+
header.mmax = -1;
|
| 143 |
+
header.mmin = -1;
|
| 144 |
+
header.pad = -1;
|
| 145 |
+
header.shapetype = type;
|
| 146 |
+
header.unused0 = -1;
|
| 147 |
+
header.unused1 = -1;
|
| 148 |
+
header.unused2 = -1;
|
| 149 |
+
header.unused3 = -1;
|
| 150 |
+
header.unused4 = -1;
|
| 151 |
+
header.version = -1;
|
| 152 |
+
double* MaxBuffer = new double[4];
|
| 153 |
+
double* MinBuffer = new double[4];
|
| 154 |
+
SHPGetInfo(shpHandle, NULL, NULL, MinBuffer, MaxBuffer);
|
| 155 |
+
header.xmin = MinBuffer[0];
|
| 156 |
+
header.ymin = MinBuffer[1];
|
| 157 |
+
header.zmin = MinBuffer[2];
|
| 158 |
+
header.xmax = MaxBuffer[0];
|
| 159 |
+
header.ymax = MaxBuffer[1];
|
| 160 |
+
header.zmax = MaxBuffer[2];
|
| 161 |
+
delete[] MaxBuffer;
|
| 162 |
+
delete[] MinBuffer;
|
| 163 |
+
|
| 164 |
+
SHPClose(shpHandle);
|
| 165 |
+
|
| 166 |
+
return VI_ShapeArray(shapeArray, header);
|
| 167 |
+
}
|
pool/shard009/C++/0106836_pow.cpp
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
| 2 |
+
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
| 3 |
+
// Distributed under the MIT software license, see the accompanying
|
| 4 |
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 5 |
+
|
| 6 |
+
#include "pow.h"
|
| 7 |
+
|
| 8 |
+
#include "arith_uint256.h"
|
| 9 |
+
#include "chain.h"
|
| 10 |
+
#include "main.h"
|
| 11 |
+
#include "primitives/block.h"
|
| 12 |
+
#include "uint256.h"
|
| 13 |
+
|
| 14 |
+
unsigned int static GetNextWorkRequired_legacy(const CBlockIndex* pindexLast, const Consensus::Params& params)
|
| 15 |
+
{
|
| 16 |
+
unsigned int nRetarget = 30;
|
| 17 |
+
int64_t nPowTargetTimespan_legacy = params.nPowTargetSpacing * nRetarget;
|
| 18 |
+
int64_t nInterval = nPowTargetTimespan_legacy / params.nPowTargetSpacing;
|
| 19 |
+
|
| 20 |
+
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
|
| 21 |
+
|
| 22 |
+
// Genesis block
|
| 23 |
+
if (pindexLast == nullptr)
|
| 24 |
+
return bnPowLimit.GetCompact();
|
| 25 |
+
|
| 26 |
+
// Only change once per interval
|
| 27 |
+
if ((pindexLast->nHeight+1) % nInterval != 0)
|
| 28 |
+
{
|
| 29 |
+
// Special difficulty rule for testnet:
|
| 30 |
+
return pindexLast->nBits;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// This fixes an issue where a 51% attack can change difficulty at will.
|
| 34 |
+
// Go back the full period unless it's the first retarget after genesis. Code courtesy of Art Forz
|
| 35 |
+
int blockstogoback = nInterval-1;
|
| 36 |
+
if ((pindexLast->nHeight+1) != nInterval)
|
| 37 |
+
blockstogoback = nInterval;
|
| 38 |
+
|
| 39 |
+
// Go back by what we want to be 14 days worth of blocks
|
| 40 |
+
const CBlockIndex* pindexFirst = pindexLast;
|
| 41 |
+
for (int i = 0; pindexFirst && i < blockstogoback; i++)
|
| 42 |
+
pindexFirst = pindexFirst->pprev;
|
| 43 |
+
assert(pindexFirst);
|
| 44 |
+
|
| 45 |
+
if (params.fPowNoRetargeting)
|
| 46 |
+
return pindexLast->nBits;
|
| 47 |
+
|
| 48 |
+
// Limit adjustment step
|
| 49 |
+
int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
|
| 50 |
+
if (nActualTimespan < params.nPowTargetTimespan/4)
|
| 51 |
+
nActualTimespan = params.nPowTargetTimespan/4;
|
| 52 |
+
if (nActualTimespan > params.nPowTargetTimespan*4)
|
| 53 |
+
nActualTimespan = params.nPowTargetTimespan*4;
|
| 54 |
+
|
| 55 |
+
// Retarget
|
| 56 |
+
arith_uint256 bnNew;
|
| 57 |
+
bnNew.SetCompact(pindexLast->nBits);
|
| 58 |
+
bnNew *= nActualTimespan;
|
| 59 |
+
bnNew /= params.nPowTargetTimespan;
|
| 60 |
+
|
| 61 |
+
if (bnNew > bnPowLimit)
|
| 62 |
+
bnNew = bnPowLimit;
|
| 63 |
+
|
| 64 |
+
return bnNew.GetCompact();
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
unsigned int GetNextWorkRequired_DGW(const CBlockIndex* pindexLast, bool fProofOfStake, const Consensus::Params& params)
|
| 68 |
+
{
|
| 69 |
+
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
|
| 70 |
+
|
| 71 |
+
if(pindexLast->nHeight < 200)
|
| 72 |
+
return bnPowLimit.GetCompact();
|
| 73 |
+
|
| 74 |
+
const CBlockIndex* pindexPrev = GetLastBlockIndex(pindexLast, fProofOfStake);
|
| 75 |
+
if (pindexPrev->pprev == nullptr)
|
| 76 |
+
return bnPowLimit.GetCompact(); // first block
|
| 77 |
+
|
| 78 |
+
const CBlockIndex* pindexPrevPrev = GetLastBlockIndex(pindexPrev->pprev, fProofOfStake);
|
| 79 |
+
if (pindexPrevPrev->pprev == nullptr)
|
| 80 |
+
return bnPowLimit.GetCompact(); // second block
|
| 81 |
+
|
| 82 |
+
if (params.fPowNoRetargeting)
|
| 83 |
+
return pindexLast->nBits;
|
| 84 |
+
|
| 85 |
+
int64_t nActualSpacing = pindexPrev->GetBlockTime() - pindexPrevPrev->GetBlockTime();
|
| 86 |
+
|
| 87 |
+
if (nActualSpacing < 0)
|
| 88 |
+
nActualSpacing = params.nPowTargetSpacing;
|
| 89 |
+
|
| 90 |
+
arith_uint256 bnNew;
|
| 91 |
+
bnNew.SetCompact(pindexPrev->nBits);
|
| 92 |
+
bnNew *= ((params.DifficultyAdjustmentInterval() - 1) * params.nPowTargetSpacing + nActualSpacing + nActualSpacing);
|
| 93 |
+
bnNew /= ((params.DifficultyAdjustmentInterval() + 1) * params.nPowTargetSpacing);
|
| 94 |
+
|
| 95 |
+
if (bnNew <= 0 || bnNew > bnPowLimit)
|
| 96 |
+
bnNew = bnPowLimit;
|
| 97 |
+
|
| 98 |
+
return bnNew.GetCompact();
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, bool fProofOfStake, const Consensus::Params& params)
|
| 102 |
+
{
|
| 103 |
+
if(pindexLast->nHeight < 200)
|
| 104 |
+
return GetNextWorkRequired_legacy(pindexLast, params);
|
| 105 |
+
|
| 106 |
+
return GetNextWorkRequired_DGW(pindexLast, fProofOfStake, params);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
|
| 110 |
+
{
|
| 111 |
+
bool fNegative;
|
| 112 |
+
bool fOverflow;
|
| 113 |
+
arith_uint256 bnTarget;
|
| 114 |
+
|
| 115 |
+
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
| 116 |
+
|
| 117 |
+
// Check range
|
| 118 |
+
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
|
| 119 |
+
return false;
|
| 120 |
+
|
| 121 |
+
// Check proof of work matches claimed amount
|
| 122 |
+
if (UintToArith256(hash) > bnTarget)
|
| 123 |
+
return false;
|
| 124 |
+
|
| 125 |
+
return true;
|
| 126 |
+
}
|
pool/shard009/C++/0106841_scripthandler.cpp
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* This file is part of Zanshin
|
| 2 |
+
|
| 3 |
+
Copyright 2015 Theo Vaucher <theo.vaucher@gmail.com>
|
| 4 |
+
|
| 5 |
+
This program is free software; you can redistribute it and/or
|
| 6 |
+
modify it under the terms of the GNU General Public License as
|
| 7 |
+
published by the Free Software Foundation; either version 2 of
|
| 8 |
+
the License or (at your option) version 3 or any later version
|
| 9 |
+
accepted by the membership of KDE e.V. (or its successor approved
|
| 10 |
+
by the membership of KDE e.V.), which shall act as a proxy
|
| 11 |
+
defined in Section 14 of version 3 of the license.
|
| 12 |
+
|
| 13 |
+
This program is distributed in the hope that it will be useful,
|
| 14 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 16 |
+
GNU General Public License for more details.
|
| 17 |
+
|
| 18 |
+
You should have received a copy of the GNU General Public License
|
| 19 |
+
along with this program; if not, write to the Free Software
|
| 20 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
| 21 |
+
USA.
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
#include "scripthandler.h"
|
| 26 |
+
#include "taskaction.h"
|
| 27 |
+
|
| 28 |
+
#include <QFile>
|
| 29 |
+
#include <QScriptEngine>
|
| 30 |
+
|
| 31 |
+
using namespace Scripting;
|
| 32 |
+
|
| 33 |
+
ScriptHandler::ScriptHandler(const Domain::TaskRepository::Ptr &taskRepository)
|
| 34 |
+
: m_taskRepository(taskRepository),
|
| 35 |
+
m_engine(new QScriptEngine(this))
|
| 36 |
+
{
|
| 37 |
+
m_engine->globalObject().setProperty("task", m_engine->newQObject(new TaskAction(m_taskRepository)));
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
QScriptValue ScriptHandler::evaluateFile(const QString &filename)
|
| 41 |
+
{
|
| 42 |
+
QFile file(filename);
|
| 43 |
+
file.open(QIODevice::ReadOnly);
|
| 44 |
+
QByteArray filecontent = file.readAll();
|
| 45 |
+
file.close();
|
| 46 |
+
|
| 47 |
+
return m_engine->evaluate(filecontent, filename);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
QScriptValue ScriptHandler::evaluateString(const QString &string)
|
| 51 |
+
{
|
| 52 |
+
return m_engine->evaluate(string);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
QScriptEngine *ScriptHandler::engine()
|
| 56 |
+
{
|
| 57 |
+
return m_engine;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
#include "scripthandler.moc"
|
pool/shard009/C++/0106843_ImageRotationInvariant.cpp
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*******************************************************************************
|
| 2 |
+
*
|
| 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 |
+
#include "ImageRotationInvariant.hpp"
|
| 17 |
+
|
| 18 |
+
namespace impact_tr4
|
| 19 |
+
{
|
| 20 |
+
|
| 21 |
+
void ImageRotationInvariant::calcIntegralInvariant(
|
| 22 |
+
const Vector2D<int> degRange /*= Vector2D<int>(1, 180)*/ )
|
| 23 |
+
{
|
| 24 |
+
GrayImage<uint8> imageBinInv;
|
| 25 |
+
ImageFilter::threshold<uint8>( *mpImage, imageBinInv );
|
| 26 |
+
imageBinInv.invert();
|
| 27 |
+
std::cout << imageBinInv << std::endl;
|
| 28 |
+
|
| 29 |
+
GrayImage<uint8> centeredImage;
|
| 30 |
+
Index centerOfMassIndex;
|
| 31 |
+
imageBinInv.computeCenterOfMassIndex(centerOfMassIndex, true);
|
| 32 |
+
// ImageMoments::centerOfMassIndex<uint8>(src1, centerOfMassIndex, true);
|
| 33 |
+
std::cout << "center of mass index = " << std::endl;
|
| 34 |
+
std::cout << centerOfMassIndex << std::endl;
|
| 35 |
+
|
| 36 |
+
const int border = std::max(mpImage->width()/2, mpImage->height()/2);
|
| 37 |
+
const uint8 extVal = 255;
|
| 38 |
+
ImageOperations::extendToCenter(imageBinInv, centeredImage, centerOfMassIndex, border, extVal);
|
| 39 |
+
|
| 40 |
+
GrayImage<uint8> rotImage = centeredImage;
|
| 41 |
+
GrayImage<uint8> resImage = centeredImage;
|
| 42 |
+
|
| 43 |
+
// for all angles in the range:
|
| 44 |
+
mResultVec.resize(degRange(1)-degRange(0)+1);
|
| 45 |
+
int c = 0;
|
| 46 |
+
for (int i = degRange(0); i<= degRange(1); ++i) {
|
| 47 |
+
ImageOperations::rotateAndScale<uint8>( centeredImage, rotImage, centerOfMassIndex, i, 1, 255);
|
| 48 |
+
|
| 49 |
+
ImageOperations::andOp(centeredImage, rotImage, resImage);
|
| 50 |
+
std::cout << resImage << std::endl;
|
| 51 |
+
|
| 52 |
+
mResultVec[c] = resImage.countNonZero();
|
| 53 |
+
++c;
|
| 54 |
+
} // end for i
|
| 55 |
+
|
| 56 |
+
return;
|
| 57 |
+
} // end calcIntegralInvariant
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
} // end of namespace impact_tr4
|
pool/shard009/C++/0106846_session_login_browsertest.cc
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2013 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "base/command_line.h"
|
| 6 |
+
#include "chrome/browser/chromeos/login/login_manager_test.h"
|
| 7 |
+
#include "chrome/browser/chromeos/login/startup_utils.h"
|
| 8 |
+
#include "chrome/browser/profiles/profile_manager.h"
|
| 9 |
+
#include "chrome/browser/ui/browser.h"
|
| 10 |
+
#include "chrome/browser/ui/browser_finder.h"
|
| 11 |
+
#include "chrome/browser/ui/browser_window.h"
|
| 12 |
+
#include "chrome/browser/ui/view_ids.h"
|
| 13 |
+
#include "chrome/common/chrome_switches.h"
|
| 14 |
+
#include "components/session_manager/core/session_manager.h"
|
| 15 |
+
#include "content/public/test/browser_test.h"
|
| 16 |
+
#include "testing/gtest/include/gtest/gtest.h"
|
| 17 |
+
#include "ui/views/focus/focus_manager.h"
|
| 18 |
+
#include "ui/views/view.h"
|
| 19 |
+
#include "ui/views/widget/widget.h"
|
| 20 |
+
|
| 21 |
+
namespace chromeos {
|
| 22 |
+
|
| 23 |
+
namespace {
|
| 24 |
+
|
| 25 |
+
constexpr char kTestUser[] = "test-user@gmail.com";
|
| 26 |
+
constexpr char kTestUserGaiaId[] = "1234567890";
|
| 27 |
+
|
| 28 |
+
} // namespace
|
| 29 |
+
|
| 30 |
+
class BrowserLoginTest : public chromeos::LoginManagerTest {
|
| 31 |
+
public:
|
| 32 |
+
BrowserLoginTest() : LoginManagerTest() { set_should_launch_browser(true); }
|
| 33 |
+
|
| 34 |
+
~BrowserLoginTest() override {}
|
| 35 |
+
|
| 36 |
+
void SetUpCommandLine(base::CommandLine* command_line) override {
|
| 37 |
+
LoginManagerTest::SetUpCommandLine(command_line);
|
| 38 |
+
command_line->AppendSwitch(::switches::kCreateBrowserOnStartupForTests);
|
| 39 |
+
}
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
IN_PROC_BROWSER_TEST_F(BrowserLoginTest, PRE_BrowserActive) {
|
| 43 |
+
RegisterUser(AccountId::FromUserEmailGaiaId(kTestUser, kTestUserGaiaId));
|
| 44 |
+
EXPECT_EQ(session_manager::SessionState::OOBE,
|
| 45 |
+
session_manager::SessionManager::Get()->session_state());
|
| 46 |
+
chromeos::StartupUtils::MarkOobeCompleted();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
IN_PROC_BROWSER_TEST_F(BrowserLoginTest, BrowserActive) {
|
| 50 |
+
base::HistogramTester histograms;
|
| 51 |
+
EXPECT_EQ(session_manager::SessionState::LOGIN_PRIMARY,
|
| 52 |
+
session_manager::SessionManager::Get()->session_state());
|
| 53 |
+
LoginUser(AccountId::FromUserEmailGaiaId(kTestUser, kTestUserGaiaId));
|
| 54 |
+
EXPECT_EQ(session_manager::SessionState::ACTIVE,
|
| 55 |
+
session_manager::SessionManager::Get()->session_state());
|
| 56 |
+
histograms.ExpectTotalCount("OOBE.BootToSignInCompleted", 1);
|
| 57 |
+
|
| 58 |
+
Browser* browser =
|
| 59 |
+
chrome::FindAnyBrowser(ProfileManager::GetActiveUserProfile(), false);
|
| 60 |
+
EXPECT_TRUE(browser != NULL);
|
| 61 |
+
EXPECT_TRUE(browser->window()->IsActive());
|
| 62 |
+
|
| 63 |
+
gfx::NativeWindow window = browser->window()->GetNativeWindow();
|
| 64 |
+
views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
|
| 65 |
+
views::FocusManager* focus_manager = widget->GetFocusManager();
|
| 66 |
+
EXPECT_TRUE(focus_manager != NULL);
|
| 67 |
+
|
| 68 |
+
const views::View* focused_view = focus_manager->GetFocusedView();
|
| 69 |
+
EXPECT_TRUE(focused_view != NULL);
|
| 70 |
+
EXPECT_EQ(VIEW_ID_OMNIBOX, focused_view->GetID());
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
} // namespace chromeos
|
pool/shard009/C++/0106848_moc_ExtendedTableWidget.cpp
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/****************************************************************************
|
| 2 |
+
** Meta object code from reading C++ file 'ExtendedTableWidget.h'
|
| 3 |
+
**
|
| 4 |
+
** Created by: The Qt Meta Object Compiler version 63 (Qt 4.8.7)
|
| 5 |
+
**
|
| 6 |
+
** WARNING! All changes made in this file will be lost!
|
| 7 |
+
*****************************************************************************/
|
| 8 |
+
|
| 9 |
+
#include "../ExtendedTableWidget.h"
|
| 10 |
+
#if !defined(Q_MOC_OUTPUT_REVISION)
|
| 11 |
+
#error "The header file 'ExtendedTableWidget.h' doesn't include <QObject>."
|
| 12 |
+
#elif Q_MOC_OUTPUT_REVISION != 63
|
| 13 |
+
#error "This file was generated using the moc from 4.8.7. It"
|
| 14 |
+
#error "cannot be used with the include files from this version of Qt."
|
| 15 |
+
#error "(The moc has changed too much.)"
|
| 16 |
+
#endif
|
| 17 |
+
|
| 18 |
+
QT_BEGIN_MOC_NAMESPACE
|
| 19 |
+
static const uint qt_meta_data_ExtendedTableWidget[] = {
|
| 20 |
+
|
| 21 |
+
// content:
|
| 22 |
+
6, // revision
|
| 23 |
+
0, // classname
|
| 24 |
+
0, 0, // classinfo
|
| 25 |
+
3, 14, // methods
|
| 26 |
+
0, 0, // properties
|
| 27 |
+
0, 0, // enums/sets
|
| 28 |
+
0, 0, // constructors
|
| 29 |
+
0, // flags
|
| 30 |
+
1, // signalCount
|
| 31 |
+
|
| 32 |
+
// signals: signature, parameters, type, tag, flags
|
| 33 |
+
20, 66, 85, 85, 0x05,
|
| 34 |
+
|
| 35 |
+
// slots: signature, parameters, type, tag, flags
|
| 36 |
+
86, 109, 85, 85, 0x08,
|
| 37 |
+
115, 140, 85, 85, 0x08,
|
| 38 |
+
|
| 39 |
+
0 // eod
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
static const char qt_meta_stringdata_ExtendedTableWidget[] = {
|
| 43 |
+
"ExtendedTableWidget\0"
|
| 44 |
+
"foreignKeyClicked(QString,QString,QByteArray)\0"
|
| 45 |
+
"table,column,value\0\0vscrollbarChanged(int)\0"
|
| 46 |
+
"value\0cellClicked(QModelIndex)\0index\0"
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
void ExtendedTableWidget::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
| 50 |
+
{
|
| 51 |
+
if (_c == QMetaObject::InvokeMetaMethod) {
|
| 52 |
+
Q_ASSERT(staticMetaObject.cast(_o));
|
| 53 |
+
ExtendedTableWidget *_t = static_cast<ExtendedTableWidget *>(_o);
|
| 54 |
+
switch (_id) {
|
| 55 |
+
case 0: _t->foreignKeyClicked((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QByteArray(*)>(_a[3]))); break;
|
| 56 |
+
case 1: _t->vscrollbarChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
|
| 57 |
+
case 2: _t->cellClicked((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break;
|
| 58 |
+
default: ;
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
const QMetaObjectExtraData ExtendedTableWidget::staticMetaObjectExtraData = {
|
| 64 |
+
0, qt_static_metacall
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
const QMetaObject ExtendedTableWidget::staticMetaObject = {
|
| 68 |
+
{ &QTableView::staticMetaObject, qt_meta_stringdata_ExtendedTableWidget,
|
| 69 |
+
qt_meta_data_ExtendedTableWidget, &staticMetaObjectExtraData }
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
#ifdef Q_NO_DATA_RELOCATION
|
| 73 |
+
const QMetaObject &ExtendedTableWidget::getStaticMetaObject() { return staticMetaObject; }
|
| 74 |
+
#endif //Q_NO_DATA_RELOCATION
|
| 75 |
+
|
| 76 |
+
const QMetaObject *ExtendedTableWidget::metaObject() const
|
| 77 |
+
{
|
| 78 |
+
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void *ExtendedTableWidget::qt_metacast(const char *_clname)
|
| 82 |
+
{
|
| 83 |
+
if (!_clname) return 0;
|
| 84 |
+
if (!strcmp(_clname, qt_meta_stringdata_ExtendedTableWidget))
|
| 85 |
+
return static_cast<void*>(const_cast< ExtendedTableWidget*>(this));
|
| 86 |
+
return QTableView::qt_metacast(_clname);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
int ExtendedTableWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
| 90 |
+
{
|
| 91 |
+
_id = QTableView::qt_metacall(_c, _id, _a);
|
| 92 |
+
if (_id < 0)
|
| 93 |
+
return _id;
|
| 94 |
+
if (_c == QMetaObject::InvokeMetaMethod) {
|
| 95 |
+
if (_id < 3)
|
| 96 |
+
qt_static_metacall(this, _c, _id, _a);
|
| 97 |
+
_id -= 3;
|
| 98 |
+
}
|
| 99 |
+
return _id;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
// SIGNAL 0
|
| 103 |
+
void ExtendedTableWidget::foreignKeyClicked(const QString & _t1, const QString & _t2, const QByteArray & _t3)
|
| 104 |
+
{
|
| 105 |
+
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)), const_cast<void*>(reinterpret_cast<const void*>(&_t2)), const_cast<void*>(reinterpret_cast<const void*>(&_t3)) };
|
| 106 |
+
QMetaObject::activate(this, &staticMetaObject, 0, _a);
|
| 107 |
+
}
|
| 108 |
+
QT_END_MOC_NAMESPACE
|
pool/shard009/C++/0106854_the_eye.cpp
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
|
| 3 |
+
* Copyright (C) 2006-2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or modify it
|
| 6 |
+
* under the terms of the GNU General Public License as published by the
|
| 7 |
+
* Free Software Foundation; either version 2 of the License, or (at your
|
| 8 |
+
* option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful, but WITHOUT
|
| 11 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 12 |
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 13 |
+
* more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License along
|
| 16 |
+
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
/* ScriptData
|
| 20 |
+
SDName: The_Eye
|
| 21 |
+
SD%Complete: 100
|
| 22 |
+
SDComment:
|
| 23 |
+
SDCategory: Tempest Keep, The Eye
|
| 24 |
+
EndScriptData */
|
| 25 |
+
|
| 26 |
+
/* ContentData
|
| 27 |
+
npc_crystalcore_devastator
|
| 28 |
+
EndContentData */
|
| 29 |
+
|
| 30 |
+
#include "ScriptMgr.h"
|
| 31 |
+
#include "ScriptedCreature.h"
|
| 32 |
+
#include "the_eye.h"
|
| 33 |
+
|
| 34 |
+
enum Spells
|
| 35 |
+
{
|
| 36 |
+
SPELL_COUNTERCHARGE = 35035,
|
| 37 |
+
SPELL_KNOCKAWAY = 22893,
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
class npc_crystalcore_devastator : public CreatureScript
|
| 41 |
+
{
|
| 42 |
+
public:
|
| 43 |
+
|
| 44 |
+
npc_crystalcore_devastator()
|
| 45 |
+
: CreatureScript("npc_crystalcore_devastator")
|
| 46 |
+
{
|
| 47 |
+
}
|
| 48 |
+
struct npc_crystalcore_devastatorAI : public ScriptedAI
|
| 49 |
+
{
|
| 50 |
+
npc_crystalcore_devastatorAI(Creature* creature) : ScriptedAI(creature)
|
| 51 |
+
{
|
| 52 |
+
Initialize();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
void Initialize()
|
| 56 |
+
{
|
| 57 |
+
Countercharge_Timer = 9000;
|
| 58 |
+
Knockaway_Timer = 25000;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
uint32 Knockaway_Timer;
|
| 62 |
+
uint32 Countercharge_Timer;
|
| 63 |
+
|
| 64 |
+
void Reset() override
|
| 65 |
+
{
|
| 66 |
+
Initialize();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
void EnterCombat(Unit* /*who*/) override
|
| 70 |
+
{
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
void UpdateAI(uint32 diff) override
|
| 74 |
+
{
|
| 75 |
+
if (!UpdateVictim())
|
| 76 |
+
return;
|
| 77 |
+
|
| 78 |
+
//Check if we have a current target
|
| 79 |
+
//Knockaway_Timer
|
| 80 |
+
if (Knockaway_Timer <= diff)
|
| 81 |
+
{
|
| 82 |
+
DoCastVictim(SPELL_KNOCKAWAY, true);
|
| 83 |
+
|
| 84 |
+
// current aggro target is knocked away pick new target
|
| 85 |
+
Unit* target = SelectTarget(SELECT_TARGET_TOPAGGRO, 0);
|
| 86 |
+
|
| 87 |
+
if (!target || target == me->GetVictim())
|
| 88 |
+
target = SelectTarget(SELECT_TARGET_TOPAGGRO, 1);
|
| 89 |
+
|
| 90 |
+
if (target)
|
| 91 |
+
me->TauntApply(target);
|
| 92 |
+
|
| 93 |
+
Knockaway_Timer = 23000;
|
| 94 |
+
}
|
| 95 |
+
else
|
| 96 |
+
Knockaway_Timer -= diff;
|
| 97 |
+
|
| 98 |
+
//Countercharge_Timer
|
| 99 |
+
if (Countercharge_Timer <= diff)
|
| 100 |
+
{
|
| 101 |
+
DoCast(me, SPELL_COUNTERCHARGE);
|
| 102 |
+
Countercharge_Timer = 45000;
|
| 103 |
+
}
|
| 104 |
+
else
|
| 105 |
+
Countercharge_Timer -= diff;
|
| 106 |
+
|
| 107 |
+
DoMeleeAttackIfReady();
|
| 108 |
+
}
|
| 109 |
+
};
|
| 110 |
+
|
| 111 |
+
CreatureAI* GetAI(Creature* creature) const override
|
| 112 |
+
{
|
| 113 |
+
return new npc_crystalcore_devastatorAI(creature);
|
| 114 |
+
}
|
| 115 |
+
};
|
| 116 |
+
void AddSC_the_eye()
|
| 117 |
+
{
|
| 118 |
+
new npc_crystalcore_devastator();
|
| 119 |
+
}
|
| 120 |
+
|
pool/shard009/C++/0106858_option.cpp
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
// option.cpp
|
| 3 |
+
|
| 4 |
+
// includes
|
| 5 |
+
|
| 6 |
+
#ifdef WINCE
|
| 7 |
+
#include <stdlib.h>
|
| 8 |
+
#else
|
| 9 |
+
#include <cstdlib>
|
| 10 |
+
#endif
|
| 11 |
+
#include <cstring>
|
| 12 |
+
|
| 13 |
+
#include "option.h"
|
| 14 |
+
#include "util.h"
|
| 15 |
+
|
| 16 |
+
// constants
|
| 17 |
+
|
| 18 |
+
static const bool UseDebug = false;
|
| 19 |
+
|
| 20 |
+
// types
|
| 21 |
+
|
| 22 |
+
struct option_t {
|
| 23 |
+
const char * var;
|
| 24 |
+
const char * val;
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
// variables
|
| 28 |
+
|
| 29 |
+
static option_t Option[] = {
|
| 30 |
+
|
| 31 |
+
{ "OptionFile", NULL, }, // string
|
| 32 |
+
|
| 33 |
+
// options
|
| 34 |
+
|
| 35 |
+
{ "EngineName", NULL, }, // string
|
| 36 |
+
{ "EngineDir", NULL, }, // string
|
| 37 |
+
{ "EngineCommand", NULL, }, // string
|
| 38 |
+
|
| 39 |
+
{ "Log", NULL, }, // true/false
|
| 40 |
+
{ "LogFile", NULL, }, // string
|
| 41 |
+
|
| 42 |
+
{ "Chess960", NULL, }, // true/false
|
| 43 |
+
|
| 44 |
+
{ "Resign", NULL, }, // true/false
|
| 45 |
+
{ "ResignMoves", NULL, }, // move number
|
| 46 |
+
{ "ResignScore", NULL, }, // centipawns
|
| 47 |
+
|
| 48 |
+
{ "MateScore", NULL, }, // centipawns
|
| 49 |
+
|
| 50 |
+
{ "Book", NULL, }, // true/false
|
| 51 |
+
{ "BookFile", NULL, }, // string
|
| 52 |
+
|
| 53 |
+
{ "BookRandom", NULL, }, // true/false
|
| 54 |
+
{ "BookLearn", NULL, }, // true/false
|
| 55 |
+
|
| 56 |
+
{ "KibitzMove", NULL, }, // true/false
|
| 57 |
+
{ "KibitzPV", NULL, }, // true/false
|
| 58 |
+
|
| 59 |
+
{ "KibitzCommand", NULL, }, // string
|
| 60 |
+
{ "KibitzDelay", NULL, }, // seconds
|
| 61 |
+
|
| 62 |
+
{ "ShowPonder", NULL, }, // true/false
|
| 63 |
+
|
| 64 |
+
// work-arounds
|
| 65 |
+
|
| 66 |
+
{ "UCIVersion", NULL, }, // 1-
|
| 67 |
+
{ "CanPonder", NULL, }, // true/false
|
| 68 |
+
{ "SyncStop", NULL, }, // true/false
|
| 69 |
+
{ "PromoteWorkAround", NULL, }, // true/false
|
| 70 |
+
|
| 71 |
+
// { "", NULL, },
|
| 72 |
+
|
| 73 |
+
{ NULL, NULL, },
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
// prototypes
|
| 77 |
+
|
| 78 |
+
static option_t * option_find (const char var[]);
|
| 79 |
+
|
| 80 |
+
// functions
|
| 81 |
+
|
| 82 |
+
// option_init()
|
| 83 |
+
|
| 84 |
+
void option_init() {
|
| 85 |
+
|
| 86 |
+
option_set("OptionFile","polyglot.ini");
|
| 87 |
+
|
| 88 |
+
// options
|
| 89 |
+
|
| 90 |
+
option_set("EngineName","<empty>");
|
| 91 |
+
option_set("EngineDir",".");
|
| 92 |
+
option_set("EngineCommand","<empty>");
|
| 93 |
+
|
| 94 |
+
option_set("Log","false");
|
| 95 |
+
option_set("LogFile","polyglot.log");
|
| 96 |
+
|
| 97 |
+
option_set("Chess960","false");
|
| 98 |
+
|
| 99 |
+
option_set("Resign","false");
|
| 100 |
+
option_set("ResignMoves","3");
|
| 101 |
+
option_set("ResignScore","600");
|
| 102 |
+
|
| 103 |
+
option_set("MateScore","10000");
|
| 104 |
+
|
| 105 |
+
option_set("Book","false");
|
| 106 |
+
option_set("BookFile","book.bin");
|
| 107 |
+
|
| 108 |
+
option_set("BookRandom","true");
|
| 109 |
+
option_set("BookLearn","false");
|
| 110 |
+
|
| 111 |
+
option_set("KibitzMove","false");
|
| 112 |
+
option_set("KibitzPV","false");
|
| 113 |
+
|
| 114 |
+
option_set("KibitzCommand","tellall");
|
| 115 |
+
option_set("KibitzDelay","5");
|
| 116 |
+
|
| 117 |
+
option_set("ShowPonder","true");
|
| 118 |
+
|
| 119 |
+
// work-arounds
|
| 120 |
+
|
| 121 |
+
option_set("UCIVersion","2");
|
| 122 |
+
option_set("CanPonder","false");
|
| 123 |
+
option_set("SyncStop","false");
|
| 124 |
+
option_set("PromoteWorkAround","false");
|
| 125 |
+
|
| 126 |
+
// option_set("","");
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// option_set()
|
| 130 |
+
|
| 131 |
+
bool option_set(const char var[], const char val[]) {
|
| 132 |
+
|
| 133 |
+
option_t * opt;
|
| 134 |
+
|
| 135 |
+
ASSERT(var!=NULL);
|
| 136 |
+
ASSERT(val!=NULL);
|
| 137 |
+
|
| 138 |
+
opt = option_find(var);
|
| 139 |
+
if (opt == NULL) return false;
|
| 140 |
+
|
| 141 |
+
my_string_set(&opt->val,val);
|
| 142 |
+
|
| 143 |
+
if (UseDebug) my_log("POLYGLOT OPTION SET \"%s\" -> \"%s\"\n",opt->var,opt->val);
|
| 144 |
+
|
| 145 |
+
return true;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// option_find()
|
| 149 |
+
|
| 150 |
+
static option_t * option_find(const char var[]) {
|
| 151 |
+
|
| 152 |
+
option_t * opt;
|
| 153 |
+
|
| 154 |
+
ASSERT(var!=NULL);
|
| 155 |
+
|
| 156 |
+
for (opt = &Option[0]; opt->var != NULL; opt++) {
|
| 157 |
+
if (my_string_case_equal(opt->var,var)) return opt;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
return NULL;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
// end of option.cpp
|
| 164 |
+
|
pool/shard009/C++/0106864_push_notifications_subscribe_task_unittest.cc
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "jingle/notifier/listener/push_notifications_subscribe_task.h"
|
| 6 |
+
|
| 7 |
+
#include "base/memory/scoped_ptr.h"
|
| 8 |
+
#include "base/strings/stringprintf.h"
|
| 9 |
+
#include "jingle/notifier/listener/xml_element_util.h"
|
| 10 |
+
#include "talk/xmpp/jid.h"
|
| 11 |
+
#include "testing/gtest/include/gtest/gtest.h"
|
| 12 |
+
|
| 13 |
+
namespace buzz {
|
| 14 |
+
class XmlElement;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
namespace notifier {
|
| 18 |
+
|
| 19 |
+
class PushNotificationsSubscribeTaskTest : public testing::Test {
|
| 20 |
+
public:
|
| 21 |
+
PushNotificationsSubscribeTaskTest()
|
| 22 |
+
: jid_("to@jid.com/test123"), task_id_("taskid") {
|
| 23 |
+
EXPECT_NE(jid_.Str(), jid_.BareJid().Str());
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
protected:
|
| 27 |
+
const buzz::Jid jid_;
|
| 28 |
+
const std::string task_id_;
|
| 29 |
+
|
| 30 |
+
private:
|
| 31 |
+
DISALLOW_COPY_AND_ASSIGN(PushNotificationsSubscribeTaskTest);
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
TEST_F(PushNotificationsSubscribeTaskTest, MakeSubscriptionMessage) {
|
| 35 |
+
SubscriptionList subscriptions;
|
| 36 |
+
|
| 37 |
+
Subscription subscription;
|
| 38 |
+
subscription.channel = "test_channel1";
|
| 39 |
+
subscription.from = "from.test.com";
|
| 40 |
+
subscriptions.push_back(subscription);
|
| 41 |
+
subscription.channel = "test_channel2";
|
| 42 |
+
subscription.from = "from.test2.com";
|
| 43 |
+
subscriptions.push_back(subscription);
|
| 44 |
+
scoped_ptr<buzz::XmlElement> message(
|
| 45 |
+
PushNotificationsSubscribeTask::MakeSubscriptionMessage(
|
| 46 |
+
subscriptions, jid_, task_id_));
|
| 47 |
+
std::string expected_xml_string =
|
| 48 |
+
base::StringPrintf(
|
| 49 |
+
"<cli:iq type=\"set\" to=\"%s\" id=\"%s\" "
|
| 50 |
+
"xmlns:cli=\"jabber:client\">"
|
| 51 |
+
"<subscribe xmlns=\"google:push\">"
|
| 52 |
+
"<item channel=\"test_channel1\" from=\"from.test.com\"/>"
|
| 53 |
+
"<item channel=\"test_channel2\" from=\"from.test2.com\"/>"
|
| 54 |
+
"</subscribe>"
|
| 55 |
+
"</cli:iq>",
|
| 56 |
+
jid_.BareJid().Str().c_str(), task_id_.c_str());
|
| 57 |
+
|
| 58 |
+
EXPECT_EQ(expected_xml_string, XmlElementToString(*message));
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
} // namespace notifier
|
| 62 |
+
|
pool/shard009/C++/0106870_main.cpp
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Created by Jean-Antoine Dupont on 11/03/2016.
|
| 3 |
+
//
|
| 4 |
+
|
| 5 |
+
#include <iostream>
|
| 6 |
+
#include "test/client/Client.h"
|
| 7 |
+
|
| 8 |
+
int main()
|
| 9 |
+
{
|
| 10 |
+
Client *client = new Client();
|
| 11 |
+
|
| 12 |
+
if (client->getConnectionManager()->connection() != -1) {
|
| 13 |
+
|
| 14 |
+
client->getMessageManager()->sendMessage(((ConnectionManager *)client->getConnectionManager())->getSockFd(), "toto", 4);
|
| 15 |
+
|
| 16 |
+
void *msg = client->getMessageManager()->receiveMessage(((ConnectionManager *)client->getConnectionManager())->getSockFd());
|
| 17 |
+
|
| 18 |
+
if (msg != nullptr) {
|
| 19 |
+
std::cout << ((char *)msg) << std::endl;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
client->getConnectionManager()->disconnection();
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
delete client;
|
| 26 |
+
|
| 27 |
+
return 0;
|
| 28 |
+
}
|
pool/shard009/C++/0106872_wisp.cpp
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "Arduino.h"
|
| 2 |
+
#include <FastLED.h>
|
| 3 |
+
#include "Wisp.h"
|
| 4 |
+
|
| 5 |
+
Wisp::Wisp(int pos, int trail, int starting_brightness, int hue) {
|
| 6 |
+
_pos = pos;
|
| 7 |
+
_trail = trail;
|
| 8 |
+
_brightness = starting_brightness;
|
| 9 |
+
_hue = hue;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
void Wisp::set_pos(int pos) {
|
| 13 |
+
_pos = pos;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
int Wisp::get_pos() {
|
| 17 |
+
return _pos;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
void Wisp::set_trail(int trail) {
|
| 21 |
+
_trail = trail;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
int Wisp::get_trail() {
|
| 25 |
+
return _trail;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
void Wisp::set_brightness(int brightness) {
|
| 29 |
+
_brightness = brightness;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
int Wisp::get_brightness() {
|
| 33 |
+
return _brightness;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
void Wisp::set_hue(int hue) {
|
| 37 |
+
_hue = hue;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
int Wisp::get_hue() {
|
| 41 |
+
return _hue;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void Wisp::update(CRGB leds[], int brightness_step, int num_leds, int hue_step) {
|
| 45 |
+
_trail_num = 0;
|
| 46 |
+
for(int i = _pos; _trail_num < _trail; i--) {
|
| 47 |
+
|
| 48 |
+
int new_hue = _hue - ((_trail_num + 1) * hue_step);
|
| 49 |
+
int new_brightness = _brightness - ((_trail_num + 1) * brightness_step);
|
| 50 |
+
if(new_hue < 0) new_hue += 255;
|
| 51 |
+
|
| 52 |
+
if(i < 0) {
|
| 53 |
+
leds[i + num_leds] = CHSV(new_hue, 255, new_brightness);
|
| 54 |
+
} else {
|
| 55 |
+
leds[i] = CHSV(new_hue, 255, new_brightness);
|
| 56 |
+
}
|
| 57 |
+
_trail_num++;
|
| 58 |
+
}
|
| 59 |
+
_pos++;
|
| 60 |
+
}
|
pool/shard009/C++/0106879_dummyserver.cpp
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright (c) 2007-2009 2009 Universidade Aveiro - Instituto de
|
| 3 |
+
// Telecomunicacoes Polo Aveiro
|
| 4 |
+
// This file is part of ODTONE - Open Dot Twenty One.
|
| 5 |
+
//
|
| 6 |
+
// This software is distributed under a license. The full license
|
| 7 |
+
// agreement can be found in the file LICENSE in this distribution.
|
| 8 |
+
// This software may not be copied, modified, sold or distributed
|
| 9 |
+
// other than expressed in the named license agreement.
|
| 10 |
+
//
|
| 11 |
+
// This software is distributed without any warranty.
|
| 12 |
+
//
|
| 13 |
+
// Author: Simao Reis <sreis@av.it.pt>
|
| 14 |
+
//
|
| 15 |
+
|
| 16 |
+
#include <odtone/debug.hpp>
|
| 17 |
+
#include <odtone/mih/message.hpp>
|
| 18 |
+
#include <odtone/mih/indication.hpp>
|
| 19 |
+
#include <odtone/mih/response.hpp>
|
| 20 |
+
#include <odtone/mih/request.hpp>
|
| 21 |
+
#include <odtone/mih/types/information.hpp>
|
| 22 |
+
#include <odtone/mih/types/capabilities.hpp>
|
| 23 |
+
#include <odtone/mih/types/capabilities.hpp>
|
| 24 |
+
#include <odtone/mih/config.hpp>
|
| 25 |
+
#include <odtone/mih/tlv.hpp>
|
| 26 |
+
#include <odtone/mih/tlv_types.hpp>
|
| 27 |
+
|
| 28 |
+
#include <cstdlib>
|
| 29 |
+
#include <cstring>
|
| 30 |
+
#include <iostream>
|
| 31 |
+
#include <boost/asio.hpp>
|
| 32 |
+
|
| 33 |
+
#include <odtone/mih/types/information_elements.hpp>
|
| 34 |
+
|
| 35 |
+
#include "../mihf/udp_listener.hpp"
|
| 36 |
+
|
| 37 |
+
using namespace odtone;
|
| 38 |
+
using boost::asio::ip::udp;
|
| 39 |
+
|
| 40 |
+
static void process_message(meta_message_ptr& msg)
|
| 41 |
+
{
|
| 42 |
+
std::cout << "MIH message: Service=" << msg->sid()
|
| 43 |
+
<< " Opcode=" << msg->opcode()
|
| 44 |
+
<< " Action=" << msg->aid()
|
| 45 |
+
<< std::endl;
|
| 46 |
+
|
| 47 |
+
if (msg->mid() == mih::response::get_information) {
|
| 48 |
+
mih::ir_bin_data_list bin_data_list;
|
| 49 |
+
|
| 50 |
+
*msg >> mih::response(mih::response::get_information)
|
| 51 |
+
& mih::tlv_info_resp_bin_data_list(bin_data_list);
|
| 52 |
+
|
| 53 |
+
mih::ir_bin_data bd = bin_data_list[0];
|
| 54 |
+
|
| 55 |
+
mih::ie_container_list_of_networks l;
|
| 56 |
+
bd.input() & mih::tlv_ie_container_list_of_networks(l);
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
int main(int argc, char **argv)
|
| 62 |
+
{
|
| 63 |
+
boost::asio::io_service io_service;
|
| 64 |
+
|
| 65 |
+
dispatch_t dispatch = boost::bind(process_message, _1);
|
| 66 |
+
mihf::udp_listener listen(io_service, boost::asio::ip::udp::v4(),
|
| 67 |
+
"127.0.0.1", 4000, dispatch);
|
| 68 |
+
|
| 69 |
+
listen.start();
|
| 70 |
+
io_service.run();
|
| 71 |
+
|
| 72 |
+
return 0;
|
| 73 |
+
}
|
pool/shard009/C++/0106882_jnc_ct_OperatorMgr_Closure.cpp
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//..............................................................................
|
| 2 |
+
//
|
| 3 |
+
// This file is part of the Jancy toolkit.
|
| 4 |
+
//
|
| 5 |
+
// Jancy is distributed under the MIT license.
|
| 6 |
+
// For details see accompanying license.txt file,
|
| 7 |
+
// the public copy of which is also available at:
|
| 8 |
+
// http://tibbo.com/downloads/archive/jancy/license.txt
|
| 9 |
+
//
|
| 10 |
+
//..............................................................................
|
| 11 |
+
|
| 12 |
+
#include "pch.h"
|
| 13 |
+
#include "jnc_ct_OperatorMgr.h"
|
| 14 |
+
#include "jnc_ct_Closure.h"
|
| 15 |
+
#include "jnc_ct_Module.h"
|
| 16 |
+
#include "jnc_ct_ClosureClassType.h"
|
| 17 |
+
|
| 18 |
+
namespace jnc {
|
| 19 |
+
namespace ct {
|
| 20 |
+
|
| 21 |
+
//..............................................................................
|
| 22 |
+
|
| 23 |
+
bool
|
| 24 |
+
OperatorMgr::createClosureObject(
|
| 25 |
+
const Value& opValue, // thin function or property ptr with closure
|
| 26 |
+
Type* thunkType, // function or property type
|
| 27 |
+
bool isWeak,
|
| 28 |
+
Value* resultValue
|
| 29 |
+
) {
|
| 30 |
+
ASSERT(thunkType->getTypeKind() == TypeKind_Function || thunkType->getTypeKind() == TypeKind_Property);
|
| 31 |
+
|
| 32 |
+
bool result;
|
| 33 |
+
|
| 34 |
+
// choose reference function type
|
| 35 |
+
|
| 36 |
+
FunctionType* srcFunctionType;
|
| 37 |
+
if (opValue.getType()->getTypeKindFlags() & TypeKindFlag_FunctionPtr) {
|
| 38 |
+
ASSERT(((FunctionPtrType*)opValue.getType())->getPtrTypeKind() == FunctionPtrTypeKind_Thin);
|
| 39 |
+
srcFunctionType = ((FunctionPtrType*)opValue.getType())->getTargetType();
|
| 40 |
+
} else {
|
| 41 |
+
ASSERT(opValue.getType()->getTypeKindFlags() & TypeKindFlag_PropertyPtr);
|
| 42 |
+
ASSERT(((PropertyPtrType*)opValue.getType())->getPtrTypeKind() == PropertyPtrTypeKind_Thin);
|
| 43 |
+
srcFunctionType = ((PropertyPtrType*)opValue.getType())->getTargetType()->getGetterType();
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
char buffer1[256];
|
| 47 |
+
char buffer2[256];
|
| 48 |
+
|
| 49 |
+
sl::Array<Type*> closureArgTypeArray(rc::BufKind_Stack, buffer1, sizeof(buffer1));
|
| 50 |
+
sl::Array<size_t> closureMap(rc::BufKind_Stack, buffer2, sizeof(buffer2));
|
| 51 |
+
size_t closureArgCount = 0;
|
| 52 |
+
size_t closureThisArgIdx = -1;
|
| 53 |
+
|
| 54 |
+
// build closure arg type array & closure map
|
| 55 |
+
|
| 56 |
+
Closure* closure = opValue.getClosure();
|
| 57 |
+
if (closure) {
|
| 58 |
+
closureArgCount = closure->getArgValueList()->getCount();
|
| 59 |
+
closureThisArgIdx = closure->getThisArgIdx();
|
| 60 |
+
|
| 61 |
+
sl::Array<FunctionArg*> srcArgArray = srcFunctionType->getArgArray();
|
| 62 |
+
size_t srcArgCount = srcArgArray.getCount();
|
| 63 |
+
|
| 64 |
+
if (closureArgCount > srcArgCount) {
|
| 65 |
+
err::setFormatStringError("closure is too big for '%s'", srcFunctionType->getTypeString().sz());
|
| 66 |
+
return false;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
closureArgTypeArray.setCount(closureArgCount);
|
| 70 |
+
closureMap.setCount(closureArgCount);
|
| 71 |
+
|
| 72 |
+
sl::BoxIterator<Value> closureArgValue = closure->getArgValueList()->getHead();
|
| 73 |
+
|
| 74 |
+
size_t j = 0;
|
| 75 |
+
|
| 76 |
+
for (size_t i = 0; i < closureArgCount; closureArgValue++, i++) {
|
| 77 |
+
if (closureArgValue->isEmpty())
|
| 78 |
+
continue;
|
| 79 |
+
|
| 80 |
+
closureArgTypeArray[j] = srcArgArray[i]->getType();
|
| 81 |
+
closureMap[j] = i;
|
| 82 |
+
j++;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
closureArgCount = j; // account for possible skipped args
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
// find or create closure class type
|
| 89 |
+
|
| 90 |
+
ClosureClassType* closureType;
|
| 91 |
+
|
| 92 |
+
if (thunkType->getTypeKind() == TypeKind_Function) {
|
| 93 |
+
closureType = m_module->m_typeMgr.getFunctionClosureClassType(
|
| 94 |
+
((FunctionPtrType*)opValue.getType())->getTargetType(),
|
| 95 |
+
(FunctionType*)thunkType,
|
| 96 |
+
closureArgTypeArray,
|
| 97 |
+
closureMap,
|
| 98 |
+
closureArgCount,
|
| 99 |
+
closureThisArgIdx
|
| 100 |
+
);
|
| 101 |
+
} else {
|
| 102 |
+
ASSERT(thunkType->getTypeKind() == TypeKind_Property);
|
| 103 |
+
|
| 104 |
+
closureType = m_module->m_typeMgr.getPropertyClosureClassType(
|
| 105 |
+
((PropertyPtrType*)opValue.getType())->getTargetType(),
|
| 106 |
+
(PropertyType*)thunkType,
|
| 107 |
+
closureArgTypeArray,
|
| 108 |
+
closureMap,
|
| 109 |
+
closureArgCount,
|
| 110 |
+
closureThisArgIdx
|
| 111 |
+
);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
if (!closureType)
|
| 115 |
+
return false;
|
| 116 |
+
|
| 117 |
+
// create instance
|
| 118 |
+
|
| 119 |
+
Value closureValue;
|
| 120 |
+
result = m_module->m_operatorMgr.newOperator(closureType, NULL, &closureValue);
|
| 121 |
+
if (!result)
|
| 122 |
+
return false;
|
| 123 |
+
|
| 124 |
+
const sl::Array<Field*>& fieldArray = closureType->getFieldArray();
|
| 125 |
+
size_t fieldIdx = 0;
|
| 126 |
+
|
| 127 |
+
// save function/property pointer
|
| 128 |
+
|
| 129 |
+
Value pfnValue = opValue;
|
| 130 |
+
pfnValue.clearClosure();
|
| 131 |
+
|
| 132 |
+
Value fieldValue;
|
| 133 |
+
result =
|
| 134 |
+
getClassField(closureValue, fieldArray[fieldIdx], NULL, &fieldValue) &&
|
| 135 |
+
binaryOperator(BinOpKind_Assign, fieldValue, pfnValue);
|
| 136 |
+
|
| 137 |
+
if (!result)
|
| 138 |
+
return false;
|
| 139 |
+
|
| 140 |
+
fieldIdx++;
|
| 141 |
+
|
| 142 |
+
// save closure arguments (if any)
|
| 143 |
+
|
| 144 |
+
if (closure) {
|
| 145 |
+
sl::BoxIterator<Value> closureArgValue = closure->getArgValueList()->getHead();
|
| 146 |
+
for (; closureArgValue; closureArgValue++) {
|
| 147 |
+
if (closureArgValue->isEmpty())
|
| 148 |
+
continue;
|
| 149 |
+
|
| 150 |
+
Value fieldValue;
|
| 151 |
+
result =
|
| 152 |
+
getClassField(closureValue, fieldArray[fieldIdx], NULL, &fieldValue) &&
|
| 153 |
+
binaryOperator(BinOpKind_Assign, fieldValue, *closureArgValue);
|
| 154 |
+
|
| 155 |
+
if (!result)
|
| 156 |
+
return false;
|
| 157 |
+
|
| 158 |
+
fieldIdx++;
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
*resultValue = closureValue;
|
| 163 |
+
return true;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
bool
|
| 167 |
+
OperatorMgr::createDataClosureObject(
|
| 168 |
+
const Value& opValue, // data ptr
|
| 169 |
+
PropertyType* thunkType, // function or property type
|
| 170 |
+
Value* resultValue
|
| 171 |
+
) {
|
| 172 |
+
ASSERT(opValue.getType()->getTypeKind() == TypeKind_DataPtr);
|
| 173 |
+
|
| 174 |
+
bool result;
|
| 175 |
+
|
| 176 |
+
// find or create closure class type
|
| 177 |
+
|
| 178 |
+
DataClosureClassType* closureType = m_module->m_typeMgr.getDataClosureClassType(
|
| 179 |
+
((DataPtrType*)opValue.getType())->getTargetType(),
|
| 180 |
+
thunkType
|
| 181 |
+
);
|
| 182 |
+
|
| 183 |
+
// create instance
|
| 184 |
+
|
| 185 |
+
Value closureValue;
|
| 186 |
+
result = m_module->m_operatorMgr.newOperator(closureType, NULL, &closureValue);
|
| 187 |
+
if (!result)
|
| 188 |
+
return false;
|
| 189 |
+
|
| 190 |
+
const sl::Array<Field*>& fieldArray = closureType->getFieldArray();
|
| 191 |
+
ASSERT(!fieldArray.isEmpty());
|
| 192 |
+
|
| 193 |
+
// save data pointer
|
| 194 |
+
|
| 195 |
+
Value fieldValue;
|
| 196 |
+
result =
|
| 197 |
+
getClassField(closureValue, fieldArray[0], NULL, &fieldValue) &&
|
| 198 |
+
binaryOperator(BinOpKind_Assign, fieldValue, opValue);
|
| 199 |
+
|
| 200 |
+
if (!result)
|
| 201 |
+
return false;
|
| 202 |
+
|
| 203 |
+
*resultValue = closureValue;
|
| 204 |
+
return true;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
//..............................................................................
|
| 208 |
+
|
| 209 |
+
} // namespace ct
|
| 210 |
+
} // namespace jnc
|
pool/shard009/C++/0106883_HostsBasedSym.cc
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/* Web Polygraph http://www.web-polygraph.org/
|
| 3 |
+
* Copyright 2003-2011 The Measurement Factory
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 */
|
| 5 |
+
|
| 6 |
+
#include "pgl/pgl.h"
|
| 7 |
+
|
| 8 |
+
#include "xstd/String.h"
|
| 9 |
+
#include "pgl/PglRec.h"
|
| 10 |
+
#include "pgl/PglArraySym.h"
|
| 11 |
+
#include "pgl/PglNetAddrSym.h"
|
| 12 |
+
#include "pgl/HostsBasedSym.h"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
String HostsBasedSym::TheType = "HostsBased";
|
| 16 |
+
|
| 17 |
+
static String strAddrArr = "addr[]";
|
| 18 |
+
static String strAddresses = "addresses";
|
| 19 |
+
static String strHosts = "hosts";
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
HostsBasedSym::HostsBasedSym(const String &aType): RecSym(aType, new PglRec) {
|
| 23 |
+
// originally, strAddresses were strHosts, and we did not want to
|
| 24 |
+
// change class name when the field name has changed
|
| 25 |
+
// to avoid renaming a bunhc of files
|
| 26 |
+
theRec->bAdd(strAddrArr, strAddresses, 0);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
HostsBasedSym::HostsBasedSym(const String &aType, PglRec *aRec): RecSym(aType, aRec) {
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
bool HostsBasedSym::isA(const String &type) const {
|
| 33 |
+
return RecSym::isA(type) || type == TheType;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
SynSym *HostsBasedSym::dupe(const String &type) const {
|
| 37 |
+
if (isA(type))
|
| 38 |
+
return new HostsBasedSym(this->type(), theRec->clone());
|
| 39 |
+
return RecSym::dupe(type);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
int HostsBasedSym::hostCount() const {
|
| 43 |
+
if (ArraySym *a = getArraySym(strAddresses))
|
| 44 |
+
return a->count();
|
| 45 |
+
else
|
| 46 |
+
return 0;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
NetAddrSym *HostsBasedSym::host(int idx) const {
|
| 50 |
+
if (ArraySym *a = getArraySym(strAddresses)) {
|
| 51 |
+
Assert(idx < a->count());
|
| 52 |
+
return &(NetAddrSym&)(*a)[idx]->cast(NetAddrSym::TheType);
|
| 53 |
+
}
|
| 54 |
+
return 0;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
const ArraySym *HostsBasedSym::addresses() const {
|
| 58 |
+
return getArraySym(strAddresses);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
bool HostsBasedSym::addresses(ArraySym &addrs) const {
|
| 62 |
+
if (const ArraySym *a = addresses()) {
|
| 63 |
+
addrs.append(*a);
|
| 64 |
+
return true;
|
| 65 |
+
}
|
| 66 |
+
return false;
|
| 67 |
+
}
|
pool/shard009/C++/0106895_dsgd.cc
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 Rainer Gemulla
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
/** \file
|
| 15 |
+
*
|
| 16 |
+
* Illustrates matrix factorization with DSGD. We first creates factors and then a data matrix
|
| 17 |
+
* from these factors. This process ensures that we know the best factorization of the input.
|
| 18 |
+
* These matrices are distributed across a cluster. We then try to reconstruct the factors
|
| 19 |
+
* using DSGD.
|
| 20 |
+
*
|
| 21 |
+
* Run with: mpirun --hosts localhost,localhost dsgd
|
| 22 |
+
* (make sure to use a production build, otherwise it will be slow)
|
| 23 |
+
*/
|
| 24 |
+
#include <iostream>
|
| 25 |
+
|
| 26 |
+
#include <boost/archive/text_oarchive.hpp>
|
| 27 |
+
#include <boost/archive/text_iarchive.hpp>
|
| 28 |
+
#include <boost/math/distributions/normal.hpp>
|
| 29 |
+
#include <boost/random/uniform_real.hpp>
|
| 30 |
+
|
| 31 |
+
#include <util/evaluation.h>
|
| 32 |
+
|
| 33 |
+
#include <mpi2/mpi2.h>
|
| 34 |
+
#include <mf/mf.h>
|
| 35 |
+
|
| 36 |
+
log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("main"));
|
| 37 |
+
|
| 38 |
+
using namespace std;
|
| 39 |
+
using namespace mf;
|
| 40 |
+
using namespace mpi2;
|
| 41 |
+
using namespace rg;
|
| 42 |
+
using namespace boost::numeric::ublas;
|
| 43 |
+
|
| 44 |
+
// type of SGD
|
| 45 |
+
typedef UpdateTruncate<UpdateNzslL2> Update;
|
| 46 |
+
//typedef UpdateTruncate<UpdateNzsl> Update;
|
| 47 |
+
typedef RegularizeNone Regularize;
|
| 48 |
+
//typedef RegularizeL2 Regularize;
|
| 49 |
+
//typedef RegularizeNzl2 Regularize;
|
| 50 |
+
typedef SumLoss<NzslLoss, L2Loss> Loss;
|
| 51 |
+
//typedef SumLoss<NzslLoss, Nzl2Loss> Loss;
|
| 52 |
+
typedef NzslLoss TestLoss;
|
| 53 |
+
|
| 54 |
+
int main(int argc, char* argv[]) {
|
| 55 |
+
// initialize mf library and mpi2
|
| 56 |
+
boost::mpi::communicator& world = mfInit(argc, argv);
|
| 57 |
+
|
| 58 |
+
// parameters for the factorization
|
| 59 |
+
mf_size_type size1 = 10000;
|
| 60 |
+
mf_size_type size2 = 10000;
|
| 61 |
+
mf_size_type nnz = 1000000;
|
| 62 |
+
double sigma = sqrt(10); // standard deviation
|
| 63 |
+
double lambda = 1/sigma/sigma;
|
| 64 |
+
mf_size_type r = 10;
|
| 65 |
+
|
| 66 |
+
// parameters for distribution
|
| 67 |
+
int tasksPerRank = 4;
|
| 68 |
+
mf_size_type blocks1 = world.size() * tasksPerRank;
|
| 69 |
+
mf_size_type blocks2 = world.size() * tasksPerRank;
|
| 70 |
+
|
| 71 |
+
// parameters for SGD
|
| 72 |
+
double eps0 = 0.01;
|
| 73 |
+
mf_size_type epochs = 10;
|
| 74 |
+
SgdOrder order = SGD_ORDER_WOR;
|
| 75 |
+
StratumOrder stratumOrder = STRATUM_ORDER_RSEQ;
|
| 76 |
+
Update update = Update(UpdateNzslL2(lambda), -10*sigma, 10*sigma); // truncate for numerical stability
|
| 77 |
+
// Update update = Update(UpdateNzsl(), -10*sigma, 10*sigma); // truncate for numerical stability
|
| 78 |
+
Regularize regularize;
|
| 79 |
+
// Regularize regularize = Regularize(lambda);
|
| 80 |
+
Loss loss((NzslLoss()), L2Loss(lambda));
|
| 81 |
+
// Loss loss((NzslLoss()), Nzl2Loss(lambda));
|
| 82 |
+
TestLoss testLoss;
|
| 83 |
+
mf_size_type testNnz = nnz/100;
|
| 84 |
+
BalanceType balanceType = BALANCE_NONE;
|
| 85 |
+
BalanceMethod balanceMethod = BALANCE_OPTIMAL;
|
| 86 |
+
bool mapReduce = false;
|
| 87 |
+
|
| 88 |
+
// start mf library
|
| 89 |
+
mfStart();
|
| 90 |
+
|
| 91 |
+
if (world.rank() == 0)
|
| 92 |
+
{
|
| 93 |
+
#ifndef NDEBUG
|
| 94 |
+
LOG4CXX_WARN(logger, "Warning: Debug mode activated (runtimes may be slow).");
|
| 95 |
+
#endif
|
| 96 |
+
|
| 97 |
+
// TODO: distribute matrix generation
|
| 98 |
+
// generate original factors by sampling from a normal(0,sigma) distribution
|
| 99 |
+
Random32 random; // note: this takes a default seed (not randomized!)
|
| 100 |
+
DenseMatrix wIn(size1, r);
|
| 101 |
+
DenseMatrixCM hIn(r, size2);
|
| 102 |
+
generateRandom(wIn, random, boost::normal_distribution<>(0, sigma));
|
| 103 |
+
generateRandom(hIn, random, boost::normal_distribution<>(0, sigma));
|
| 104 |
+
|
| 105 |
+
// generate a sparse matrix by selecting random entries from the generated factors
|
| 106 |
+
// and add small Gaussian noise
|
| 107 |
+
SparseMatrix v;
|
| 108 |
+
generateRandom(v, nnz, wIn, hIn, random);
|
| 109 |
+
addRandom(v, random, boost::normal_distribution<>(0, 0.1));
|
| 110 |
+
LOG4CXX_INFO(logger, "Data matrix: "
|
| 111 |
+
<< v.size1() << " x " << v.size2() << ", " << v.nnz() << " nonzeros");
|
| 112 |
+
LOG4CXX_INFO(logger, "Loss with original factors: " << loss((FactorizationData<>(v, wIn, hIn))));
|
| 113 |
+
|
| 114 |
+
// create a test matrix (without noise)
|
| 115 |
+
SparseMatrix vTest;
|
| 116 |
+
generateRandom(vTest, testNnz, wIn, hIn, random);
|
| 117 |
+
LOG4CXX_INFO(logger, "Test matrix: "
|
| 118 |
+
<< v.size1() << " x " << v.size2() << ", " << vTest.nnz() << " nonzeros");
|
| 119 |
+
|
| 120 |
+
// take a small sample and remove empty rows/columns
|
| 121 |
+
ProjectedSparseMatrix Vsample;
|
| 122 |
+
projectRandomSubmatrix(random, v, Vsample, v.size1()/5, v.size2()/5);
|
| 123 |
+
projectFrequent(Vsample, 0);
|
| 124 |
+
LOG4CXX_INFO(logger, "Sample matrix: "
|
| 125 |
+
<< Vsample.data.size1() << " x " << Vsample.data.size2()
|
| 126 |
+
<< ", " << Vsample.data.nnz() << " nonzeros");
|
| 127 |
+
|
| 128 |
+
// generate initial factors by sampling from a uniform[-0.5,0.5] distribution
|
| 129 |
+
DenseMatrix w(size1, r);
|
| 130 |
+
DenseMatrixCM h(r, size2);
|
| 131 |
+
generateRandom(w, random, boost::uniform_real<>(-0.5, 0.5));
|
| 132 |
+
generateRandom(h, random, boost::uniform_real<>(-0.5, 0.5));
|
| 133 |
+
|
| 134 |
+
// distribute the input matrices and test matrix (cheaper than fetching W/H)
|
| 135 |
+
DistributedSparseMatrix dv = distributeMatrix("V", blocks1, blocks2, true, v);
|
| 136 |
+
LOG4CXX_INFO(logger, "Distributed data matrix: "
|
| 137 |
+
<< dv.blocks1() << " x " << dv.blocks2() << " blocks");
|
| 138 |
+
DistributedSparseMatrix dvTest = distributeMatrix("VTest", blocks1, blocks2, true, vTest);
|
| 139 |
+
DistributedDenseMatrix dw = distributeMatrix("W", blocks1, 1, true, w);
|
| 140 |
+
DistributedDenseMatrixCM dh = distributeMatrix("H", 1, blocks2, false, h);
|
| 141 |
+
LOG4CXX_INFO(logger, "Distributed factor matrices");
|
| 142 |
+
|
| 143 |
+
// initialize the DSGD
|
| 144 |
+
Timer t;
|
| 145 |
+
DsgdRunner dsgdRunner(random);
|
| 146 |
+
DsgdJob<Update,Regularize> dsgdJob(dv, dw, dh, update, regularize, order,
|
| 147 |
+
stratumOrder, mapReduce, tasksPerRank);
|
| 148 |
+
//BoldDriver decay(eps0);
|
| 149 |
+
DistributedDecayAuto<Update,Regularize,Loss> decay(dsgdJob, loss, Vsample, "decay", eps0,
|
| 150 |
+
world.size()*tasksPerRank);
|
| 151 |
+
Trace trace;
|
| 152 |
+
|
| 153 |
+
//std::string s1("Loss"),s2("nzsl"),s3("Regularize"),s4("L2"),s5("nodes"),s6("threads");
|
| 154 |
+
|
| 155 |
+
trace.addField("Loss","nzsl");
|
| 156 |
+
trace.addField("Regularize","L2");
|
| 157 |
+
|
| 158 |
+
trace.addField("nodes",3);
|
| 159 |
+
trace.addField("threads",4);
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
// print the test loss
|
| 163 |
+
DsgdFactorizationData<> testData(dvTest,dw,dh,tasksPerRank);
|
| 164 |
+
LOG4CXX_INFO(logger, "Initial test loss: " << testLoss(testData));
|
| 165 |
+
|
| 166 |
+
// run DSGD to try to reconstruct the original factors
|
| 167 |
+
t.start();
|
| 168 |
+
dsgdRunner.run(dsgdJob, loss, epochs, decay, trace, balanceType, balanceMethod, &testData, &testLoss);
|
| 169 |
+
//dsgdRunner.run(dsgdJob, loss, epochs, decay, trace);
|
| 170 |
+
|
| 171 |
+
t.stop();
|
| 172 |
+
LOG4CXX_INFO(logger, "Total time: " << t);
|
| 173 |
+
|
| 174 |
+
// print the test loss
|
| 175 |
+
LOG4CXX_INFO(logger, "Final test loss: " << testLoss(testData));
|
| 176 |
+
|
| 177 |
+
// write trace to an R file
|
| 178 |
+
LOG4CXX_INFO(logger, "Writing trace to " << "/tmp/dsgd-trace.R");
|
| 179 |
+
trace.toRfile("/tmp/dsgd-trace.R", "dsgd");
|
| 180 |
+
|
| 181 |
+
// cout << squaredSums2(dsgdJob.dw, tasksPerRank) << endl;
|
| 182 |
+
// cout << squaredSums1(dsgdJob.dh, tasksPerRank) << endl;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
mfStop();
|
| 186 |
+
mfFinalize();
|
| 187 |
+
|
| 188 |
+
return 0;
|
| 189 |
+
}
|
pool/shard009/C++/0106896_rinstallprogress.cc
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* rinstallprogress.cc
|
| 2 |
+
*
|
| 3 |
+
* Copyright (c) 2000, 2001 Conectiva S/A
|
| 4 |
+
* 2002 Michael Vogt
|
| 5 |
+
*
|
| 6 |
+
* Author: Alfredo K. Kojima <kojima@conectiva.com.br>
|
| 7 |
+
* Michael Vogt <mvo@debian.org>
|
| 8 |
+
*
|
| 9 |
+
* This program is free software; you can redistribute it and/or
|
| 10 |
+
* modify it under the terms of the GNU General Public License as
|
| 11 |
+
* published by the Free Software Foundation; either version 2 of the
|
| 12 |
+
* License, or (at your option) any later version.
|
| 13 |
+
*
|
| 14 |
+
* This program is distributed in the hope that it will be useful,
|
| 15 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 |
+
* GNU General Public License for more details.
|
| 18 |
+
*
|
| 19 |
+
* You should have received a copy of the GNU General Public License
|
| 20 |
+
* along with this program; if not, write to the Free Software
|
| 21 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
| 22 |
+
* USA
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
#include "config.h"
|
| 26 |
+
|
| 27 |
+
#include <unistd.h>
|
| 28 |
+
#include <fcntl.h>
|
| 29 |
+
#include <sys/types.h>
|
| 30 |
+
#include <sys/wait.h>
|
| 31 |
+
#include <iostream>
|
| 32 |
+
#include <cstdio>
|
| 33 |
+
#include <apt-pkg/error.h>
|
| 34 |
+
#include <apt-pkg/install-progress.h>
|
| 35 |
+
#ifdef HAVE_RPM
|
| 36 |
+
#include <apt-pkg/configuration.h>
|
| 37 |
+
#endif
|
| 38 |
+
|
| 39 |
+
#include "rinstallprogress.h"
|
| 40 |
+
|
| 41 |
+
#include "i18n.h"
|
| 42 |
+
std::string RInstallProgress::finishMsg = _("\nSuccessfully applied all changes. You can close the window now.");
|
| 43 |
+
std::string RInstallProgress::errorMsg = _("\nNot all changes and updates succeeded. For further details of the failure, please expand the 'Details' panel below.");
|
| 44 |
+
std::string RInstallProgress::incompleteMsg =
|
| 45 |
+
_("\nSuccessfully installed all packages of the current medium. "
|
| 46 |
+
"To continue the installation with the next medium close "
|
| 47 |
+
"this window.");
|
| 48 |
+
|
| 49 |
+
const char* RInstallProgress::getResultStr(pkgPackageManager::OrderResult res)
|
| 50 |
+
{
|
| 51 |
+
int size;
|
| 52 |
+
switch( res ) {
|
| 53 |
+
case 0: // completed
|
| 54 |
+
return finishMsg.c_str();
|
| 55 |
+
break;
|
| 56 |
+
case 1: // failed
|
| 57 |
+
return errorMsg.c_str();
|
| 58 |
+
break;
|
| 59 |
+
case 2: // incomplete
|
| 60 |
+
return incompleteMsg.c_str();
|
| 61 |
+
break;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
return "Unknown install result.";
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
pkgPackageManager::OrderResult RInstallProgress::start(pkgPackageManager *pm,
|
| 69 |
+
int numPackages,
|
| 70 |
+
int numPackagesTotal)
|
| 71 |
+
{
|
| 72 |
+
void *dummy;
|
| 73 |
+
pkgPackageManager::OrderResult res;
|
| 74 |
+
int ret;
|
| 75 |
+
pid_t _child_id;
|
| 76 |
+
|
| 77 |
+
//cout << "RInstallProgress::start()" << endl;
|
| 78 |
+
|
| 79 |
+
#ifdef HAVE_RPM
|
| 80 |
+
|
| 81 |
+
_config->Set("RPM::Interactive", "false");
|
| 82 |
+
|
| 83 |
+
res = pm->DoInstallPreFork();
|
| 84 |
+
if (res == pkgPackageManager::Failed)
|
| 85 |
+
return res;
|
| 86 |
+
|
| 87 |
+
/*
|
| 88 |
+
* This will make a pipe from where we can read child's output
|
| 89 |
+
*/
|
| 90 |
+
int fd[2];
|
| 91 |
+
pipe(fd);
|
| 92 |
+
|
| 93 |
+
_child_id = fork();
|
| 94 |
+
|
| 95 |
+
if (_child_id == 0) {
|
| 96 |
+
// make the write end of the pipe to the child become the new stdout
|
| 97 |
+
// and stderr (for the child)
|
| 98 |
+
dup2(fd[1], 1);
|
| 99 |
+
dup2(1, 2);
|
| 100 |
+
close(fd[0]);
|
| 101 |
+
close(fd[1]);
|
| 102 |
+
|
| 103 |
+
APT::Progress::PackageManagerProgressFd progress(-1);
|
| 104 |
+
res = pm->DoInstallPostFork(&progress);
|
| 105 |
+
// dump errors into cerr (pass it to the parent process)
|
| 106 |
+
_error->DumpErrors();
|
| 107 |
+
_exit(res);
|
| 108 |
+
}
|
| 109 |
+
// this is where we read stuff from the child
|
| 110 |
+
_childin = fd[0];
|
| 111 |
+
close(fd[1]);
|
| 112 |
+
|
| 113 |
+
// make it nonblocking
|
| 114 |
+
fcntl(_childin, F_SETFL, O_NONBLOCK);
|
| 115 |
+
|
| 116 |
+
_donePackages = 0;
|
| 117 |
+
_numPackages = numPackages;
|
| 118 |
+
_numPackagesTotal = numPackagesTotal;
|
| 119 |
+
|
| 120 |
+
#else
|
| 121 |
+
|
| 122 |
+
res = pm->DoInstallPreFork();
|
| 123 |
+
if (res == pkgPackageManager::Failed)
|
| 124 |
+
return res;
|
| 125 |
+
|
| 126 |
+
_child_id = fork();
|
| 127 |
+
|
| 128 |
+
if (_child_id == 0) {
|
| 129 |
+
APT::Progress::PackageManagerProgressFd progress(-1);
|
| 130 |
+
res = pm->DoInstallPostFork(&progress);
|
| 131 |
+
_exit(res);
|
| 132 |
+
}
|
| 133 |
+
#endif
|
| 134 |
+
|
| 135 |
+
startUpdate();
|
| 136 |
+
while (waitpid(_child_id, &ret, WNOHANG) == 0)
|
| 137 |
+
updateInterface();
|
| 138 |
+
|
| 139 |
+
res = (pkgPackageManager::OrderResult) WEXITSTATUS(ret);
|
| 140 |
+
|
| 141 |
+
finishUpdate();
|
| 142 |
+
|
| 143 |
+
#ifdef HAVE_RPM
|
| 144 |
+
close(_childin);
|
| 145 |
+
#endif
|
| 146 |
+
|
| 147 |
+
return res;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
// vim:sts=4:sw=4
|
pool/shard009/C++/0106902_ABI38_0_0EventEmitter.cpp
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
| 3 |
+
*
|
| 4 |
+
* This source code is licensed under the MIT license found in the
|
| 5 |
+
* LICENSE file in the root directory of this source tree.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
#include "ABI38_0_0EventEmitter.h"
|
| 9 |
+
|
| 10 |
+
#include <folly/dynamic.h>
|
| 11 |
+
#include <ABI38_0_0jsi/ABI38_0_0JSIDynamic.h>
|
| 12 |
+
#include <ABI38_0_0jsi/ABI38_0_0jsi.h>
|
| 13 |
+
#include <ABI38_0_0React/debug/SystraceSection.h>
|
| 14 |
+
|
| 15 |
+
#include "ABI38_0_0RawEvent.h"
|
| 16 |
+
|
| 17 |
+
namespace ABI38_0_0facebook {
|
| 18 |
+
namespace ABI38_0_0React {
|
| 19 |
+
|
| 20 |
+
// TODO(T29874519): Get rid of "top" prefix once and for all.
|
| 21 |
+
/*
|
| 22 |
+
* Capitalizes the first letter of the event type and adds "top" prefix if
|
| 23 |
+
* necessary (e.g. "layout" becames "topLayout").
|
| 24 |
+
*/
|
| 25 |
+
static std::string normalizeEventType(const std::string &type) {
|
| 26 |
+
auto prefixedType = type;
|
| 27 |
+
if (type.find("top", 0) != 0) {
|
| 28 |
+
prefixedType.insert(0, "top");
|
| 29 |
+
prefixedType[3] = toupper(prefixedType[3]);
|
| 30 |
+
}
|
| 31 |
+
return prefixedType;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
std::mutex &EventEmitter::DispatchMutex() {
|
| 35 |
+
static std::mutex mutex;
|
| 36 |
+
return mutex;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
ValueFactory EventEmitter::defaultPayloadFactory() {
|
| 40 |
+
static auto payloadFactory =
|
| 41 |
+
ValueFactory{[](jsi::Runtime &runtime) { return jsi::Object(runtime); }};
|
| 42 |
+
return payloadFactory;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
EventEmitter::EventEmitter(
|
| 46 |
+
SharedEventTarget eventTarget,
|
| 47 |
+
Tag tag,
|
| 48 |
+
EventDispatcher::Weak eventDispatcher)
|
| 49 |
+
: eventTarget_(std::move(eventTarget)),
|
| 50 |
+
eventDispatcher_(std::move(eventDispatcher)) {}
|
| 51 |
+
|
| 52 |
+
void EventEmitter::dispatchEvent(
|
| 53 |
+
const std::string &type,
|
| 54 |
+
const folly::dynamic &payload,
|
| 55 |
+
const EventPriority &priority) const {
|
| 56 |
+
dispatchEvent(
|
| 57 |
+
type,
|
| 58 |
+
[payload](jsi::Runtime &runtime) {
|
| 59 |
+
return valueFromDynamic(runtime, payload);
|
| 60 |
+
},
|
| 61 |
+
priority);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
void EventEmitter::dispatchEvent(
|
| 65 |
+
const std::string &type,
|
| 66 |
+
const ValueFactory &payloadFactory,
|
| 67 |
+
const EventPriority &priority) const {
|
| 68 |
+
SystraceSection s("EventEmitter::dispatchEvent");
|
| 69 |
+
|
| 70 |
+
auto eventDispatcher = eventDispatcher_.lock();
|
| 71 |
+
if (!eventDispatcher) {
|
| 72 |
+
return;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
eventDispatcher->dispatchEvent(
|
| 76 |
+
RawEvent(normalizeEventType(type), payloadFactory, eventTarget_),
|
| 77 |
+
priority);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
void EventEmitter::setEnabled(bool enabled) const {
|
| 81 |
+
enableCounter_ += enabled ? 1 : -1;
|
| 82 |
+
|
| 83 |
+
bool shouldBeEnabled = enableCounter_ > 0;
|
| 84 |
+
if (isEnabled_ != shouldBeEnabled) {
|
| 85 |
+
isEnabled_ = shouldBeEnabled;
|
| 86 |
+
if (eventTarget_) {
|
| 87 |
+
eventTarget_->setEnabled(isEnabled_);
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// Note: Initially, the state of `eventTarget_` and the value `enableCounter_`
|
| 92 |
+
// is mismatched intentionally (it's `non-null` and `0` accordingly). We need
|
| 93 |
+
// this to support an initial nebula state where the event target must be
|
| 94 |
+
// retained without any associated mounted node.
|
| 95 |
+
bool shouldBeRetained = enableCounter_ > 0;
|
| 96 |
+
if (shouldBeRetained != (eventTarget_ != nullptr)) {
|
| 97 |
+
if (!shouldBeRetained) {
|
| 98 |
+
eventTarget_.reset();
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
} // namespace ABI38_0_0React
|
| 104 |
+
} // namespace ABI38_0_0facebook
|
pool/shard009/C++/0106903_FXNode.cpp
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// libavg - Media Playback Engine.
|
| 3 |
+
// Copyright (C) 2003-2021 Ulrich von Zadow
|
| 4 |
+
//
|
| 5 |
+
// This library is free software; you can redistribute it and/or
|
| 6 |
+
// modify it under the terms of the GNU Lesser General Public
|
| 7 |
+
// License as published by the Free Software Foundation; either
|
| 8 |
+
// version 2 of the License, or (at your option) any later version.
|
| 9 |
+
//
|
| 10 |
+
// This library is distributed in the hope that it will be useful,
|
| 11 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 |
+
// Lesser General Public License for more details.
|
| 14 |
+
//
|
| 15 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 16 |
+
// License along with this library; if not, write to the Free Software
|
| 17 |
+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 18 |
+
//
|
| 19 |
+
// Current versions can be found at www.libavg.de
|
| 20 |
+
//
|
| 21 |
+
|
| 22 |
+
#include "FXNode.h"
|
| 23 |
+
#include "Player.h"
|
| 24 |
+
|
| 25 |
+
#include "../base/ObjectCounter.h"
|
| 26 |
+
#include "../graphics/GLContext.h"
|
| 27 |
+
#include "../graphics/GPUFilter.h"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
namespace avg {
|
| 31 |
+
|
| 32 |
+
using namespace std;
|
| 33 |
+
|
| 34 |
+
FXNode::FXNode(bool bSupportsGLES)
|
| 35 |
+
: m_Size(0, 0),
|
| 36 |
+
m_bSupportsGLES(bSupportsGLES),
|
| 37 |
+
m_bDirty(true)
|
| 38 |
+
{
|
| 39 |
+
ObjectCounter::get()->incRef(&typeid(*this));
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
FXNode::~FXNode()
|
| 43 |
+
{
|
| 44 |
+
ObjectCounter::get()->decRef(&typeid(*this));
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
void FXNode::connect()
|
| 48 |
+
{
|
| 49 |
+
checkGLES();
|
| 50 |
+
if (m_Size != IntPoint(0,0)) {
|
| 51 |
+
m_pFilter = createFilter(m_Size);
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
void FXNode::disconnect()
|
| 56 |
+
{
|
| 57 |
+
m_pFilter = GPUFilterPtr();
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
void FXNode::setSize(const IntPoint& newSize)
|
| 61 |
+
{
|
| 62 |
+
if (newSize != m_Size) {
|
| 63 |
+
m_Size = newSize;
|
| 64 |
+
if (m_pFilter) {
|
| 65 |
+
m_pFilter = createFilter(m_Size);
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
void FXNode::apply(GLContext* pContext, GLTexturePtr pSrcTex)
|
| 71 |
+
{
|
| 72 |
+
// blt overwrites everything, so no glClear necessary before.
|
| 73 |
+
pContext->setBlendMode(GLContext::BLEND_COPY);
|
| 74 |
+
m_pFilter->apply(pContext, pSrcTex);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
GLTexturePtr FXNode::getTex(GLContext* pContext)
|
| 78 |
+
{
|
| 79 |
+
return m_pFilter->getDestTex(pContext);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
BitmapPtr FXNode::getImage(GLContext* pContext)
|
| 83 |
+
{
|
| 84 |
+
return m_pFilter->getImage(pContext);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
FRect FXNode::getRelDestRect() const
|
| 88 |
+
{
|
| 89 |
+
return m_pFilter->getRelDestRect();
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
bool FXNode::isDirty() const
|
| 93 |
+
{
|
| 94 |
+
return m_bDirty;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
void FXNode::resetDirty()
|
| 98 |
+
{
|
| 99 |
+
m_bDirty = false;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
FBOPtr FXNode::getFBO(GLContext* pContext)
|
| 103 |
+
{
|
| 104 |
+
return m_pFilter->getFBO(pContext);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
void FXNode::setDirty()
|
| 108 |
+
{
|
| 109 |
+
m_bDirty = true;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
void FXNode::checkGLES() const
|
| 113 |
+
{
|
| 114 |
+
if (!m_bSupportsGLES && GLContext::getCurrent()->isGLES()) {
|
| 115 |
+
throw Exception(AVG_ERR_UNSUPPORTED,
|
| 116 |
+
"This effect is unsupported under OpenGL ES.");
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
}
|
pool/shard009/C++/0106904_touchSensor.cpp
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright 2007-2015 QReal Research Group
|
| 2 |
+
*
|
| 3 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
* you may not use this file except in compliance with the License.
|
| 5 |
+
* You may obtain a copy of the License at
|
| 6 |
+
*
|
| 7 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
*
|
| 9 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
* See the License for the specific language governing permissions and
|
| 13 |
+
* limitations under the License. */
|
| 14 |
+
|
| 15 |
+
#include "touchSensor.h"
|
| 16 |
+
|
| 17 |
+
#include <utils/tracer.h>
|
| 18 |
+
|
| 19 |
+
using namespace nxt::robotModel::real::parts;
|
| 20 |
+
using namespace kitBase;
|
| 21 |
+
using namespace robotModel;
|
| 22 |
+
using namespace utils;
|
| 23 |
+
using namespace robotCommunication;
|
| 24 |
+
|
| 25 |
+
TouchSensor::TouchSensor(const kitBase::robotModel::DeviceInfo &info
|
| 26 |
+
, const kitBase::robotModel::PortInfo &port
|
| 27 |
+
, utils::robotCommunication::RobotCommunicator &robotCommunicator)
|
| 28 |
+
: kitBase::robotModel::robotParts::TouchSensor(info, port)
|
| 29 |
+
, mImplementation(robotCommunicator, port, enums::lowLevelSensorType::SWITCH, enums::sensorMode::RAWMODE)
|
| 30 |
+
{
|
| 31 |
+
connect(&mImplementation, &NxtInputDevice::sensorSpecificProcessResponse
|
| 32 |
+
, this, &TouchSensor::sensorSpecificProcessResponse);
|
| 33 |
+
connect(&mImplementation, &NxtInputDevice::configured, this, &TouchSensor::configurationCompleted);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
void TouchSensor::sensorSpecificProcessResponse(const QByteArray &reading)
|
| 37 |
+
{
|
| 38 |
+
mImplementation.setState(NxtInputDevice::idle);
|
| 39 |
+
int sensorValue = (0xff & reading[13]) << 8 | (0xff & reading[14]);
|
| 40 |
+
Tracer::debug(Tracer::sensors, "TouchSensor::sensorSpecificProcessResponse", QString::number(sensorValue));
|
| 41 |
+
if (reading[4] == 0 && sensorValue < 500) {
|
| 42 |
+
// Sensor is pressed.
|
| 43 |
+
emit newData(1);
|
| 44 |
+
} else {
|
| 45 |
+
emit newData(0);
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void TouchSensor::read()
|
| 50 |
+
{
|
| 51 |
+
if (!mImplementation.isConfigured()) {
|
| 52 |
+
// If sensor is not configured, report failure and return immediately.
|
| 53 |
+
// It is not an error, it shall be possible to reconfigure sensor "on the fly",
|
| 54 |
+
// but when it is reconfiguring it shall not be available.
|
| 55 |
+
emit failure();
|
| 56 |
+
return;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (mImplementation.state() == NxtInputDevice::pending) {
|
| 60 |
+
return;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
mImplementation.setState(NxtInputDevice::pending);
|
| 64 |
+
QByteArray command(5, 0);
|
| 65 |
+
command[0] = 0x03; //command length
|
| 66 |
+
command[1] = 0x00;
|
| 67 |
+
command[2] = enums::telegramType::directCommandResponseRequired;
|
| 68 |
+
command[3] = enums::commandCode::GETINPUTVALUES;
|
| 69 |
+
command[4] = mImplementation.lowLevelPort();
|
| 70 |
+
mImplementation.send(command, 18);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
void TouchSensor::doConfiguration()
|
| 74 |
+
{
|
| 75 |
+
mImplementation.configure();
|
| 76 |
+
}
|
pool/shard009/C++/0106905_glapp.cpp
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************
|
| 2 |
+
* Name: Tetro2App.cpp
|
| 3 |
+
* Purpose: Code for Application Class
|
| 4 |
+
* Author: CHEN Junshi (cjshappy@163.com)
|
| 5 |
+
* Created: 2014-02-12
|
| 6 |
+
* Copyright: CHEN Junshi ()
|
| 7 |
+
* License:
|
| 8 |
+
**************************************************************/
|
| 9 |
+
|
| 10 |
+
#include "wx_pch.h"
|
| 11 |
+
#include "glapp.h"
|
| 12 |
+
|
| 13 |
+
//(*AppHeaders
|
| 14 |
+
#include "glmainwindow.h"
|
| 15 |
+
#include <wx/image.h>
|
| 16 |
+
#include <wx/log.h>
|
| 17 |
+
#include <stdio.h>
|
| 18 |
+
//*)
|
| 19 |
+
|
| 20 |
+
IMPLEMENT_APP(GLApp);
|
| 21 |
+
|
| 22 |
+
bool GLApp::OnInit()
|
| 23 |
+
{
|
| 24 |
+
//(*AppInitialize
|
| 25 |
+
bool wxsOK = true;
|
| 26 |
+
wxInitAllImageHandlers();
|
| 27 |
+
if ( wxsOK )
|
| 28 |
+
{
|
| 29 |
+
GLMainWindow* Frame = new GLMainWindow(0);
|
| 30 |
+
Frame->Show();
|
| 31 |
+
SetTopWindow(Frame);
|
| 32 |
+
|
| 33 |
+
m_pLogFile = fopen("log.txt", "w+");
|
| 34 |
+
delete wxLog::SetActiveTarget(new wxLogStderr(m_pLogFile));
|
| 35 |
+
wxLog::SetTimestamp(wxT("%Y-%m-%d %H:%M:%S"));
|
| 36 |
+
wxLog::SetLogLevel(wxLOG_Info);
|
| 37 |
+
|
| 38 |
+
wxLogMessage("Launch Application.");
|
| 39 |
+
}
|
| 40 |
+
//*)
|
| 41 |
+
return wxsOK;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
int GLApp::OnExit()
|
| 45 |
+
{
|
| 46 |
+
fclose(m_pLogFile);
|
| 47 |
+
return 0;
|
| 48 |
+
}
|
pool/shard009/C++/0106907_FullPermutation.cc
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
*--------------------------------------------------------------------------
|
| 3 |
+
* File Name: FullPermutation.cc
|
| 4 |
+
*
|
| 5 |
+
* Author: Zhao Yanbai [zhaoyanbai@126.com]
|
| 6 |
+
* Mon Jul 19 15:14:43 2010
|
| 7 |
+
*
|
| 8 |
+
* Description:
|
| 9 |
+
*
|
| 10 |
+
* 全排列的算法
|
| 11 |
+
*
|
| 12 |
+
* 设要全排列的集合为R={r1, r2, ..., rn}. Ri = R - ri.
|
| 13 |
+
* 对集合X进行全排列记为P(X). (ri)P(X)表示在全排列P(X)的每一个排列前
|
| 14 |
+
* 面都加上ri得到的排列.
|
| 15 |
+
* 则R的全排列定义如下:
|
| 16 |
+
* 当n==1时: P(R) = (r)
|
| 17 |
+
* 当n >1时: P(R) = {(r1)P(1), (r2)P(2), ...., (rn)P(n)}
|
| 18 |
+
*--------------------------------------------------------------------------
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
#include<iostream>
|
| 23 |
+
using namespace std;
|
| 24 |
+
|
| 25 |
+
template <typename T>
|
| 26 |
+
void Swap(T &a, T &b)
|
| 27 |
+
{
|
| 28 |
+
T c;
|
| 29 |
+
c = a;
|
| 30 |
+
a = b;
|
| 31 |
+
b = c;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
template <typename T>
|
| 36 |
+
void P(T *set, int b, int e)
|
| 37 |
+
{
|
| 38 |
+
if(b == e)
|
| 39 |
+
{
|
| 40 |
+
for(int i=0; i<e; i++)
|
| 41 |
+
cout<<set[i];
|
| 42 |
+
cout<<endl;
|
| 43 |
+
|
| 44 |
+
return ;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
for(int i=b; i<e; i++)
|
| 49 |
+
{
|
| 50 |
+
Swap(set[b], set[i]);
|
| 51 |
+
P(set, b+1, e);
|
| 52 |
+
Swap(set[b], set[i]);
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
int main()
|
| 57 |
+
{
|
| 58 |
+
|
| 59 |
+
const int n = 3;
|
| 60 |
+
char a[n];
|
| 61 |
+
for(int i=0; i<n; i++)
|
| 62 |
+
a[i] = 'a' + i;
|
| 63 |
+
|
| 64 |
+
P(a, 0, n);
|
| 65 |
+
|
| 66 |
+
return 0;
|
| 67 |
+
}
|
pool/shard009/C++/0106908_compare.pass.cpp
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===----------------------------------------------------------------------===//
|
| 2 |
+
//
|
| 3 |
+
// The LLVM Compiler Infrastructure
|
| 4 |
+
//
|
| 5 |
+
// This file is dual licensed under the MIT and the University of Illinois Open
|
| 6 |
+
// Source Licenses. See LICENSE.TXT for details.
|
| 7 |
+
//
|
| 8 |
+
//===----------------------------------------------------------------------===//
|
| 9 |
+
|
| 10 |
+
// <unordered_map>
|
| 11 |
+
|
| 12 |
+
// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
|
| 13 |
+
// class Alloc = allocator<pair<const Key, T>>>
|
| 14 |
+
// class unordered_map
|
| 15 |
+
|
| 16 |
+
// https://bugs.llvm.org/show_bug.cgi?id=16538
|
| 17 |
+
// https://bugs.llvm.org/show_bug.cgi?id=16549
|
| 18 |
+
|
| 19 |
+
#include <unordered_map>
|
| 20 |
+
#include <cassert>
|
| 21 |
+
|
| 22 |
+
struct Key {
|
| 23 |
+
template <typename T> Key(const T&) {}
|
| 24 |
+
bool operator== (const Key&) const { return true; }
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
namespace std
|
| 28 |
+
{
|
| 29 |
+
template <>
|
| 30 |
+
struct hash<Key>
|
| 31 |
+
{
|
| 32 |
+
size_t operator()(Key const &) const {return 0;}
|
| 33 |
+
};
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
int
|
| 37 |
+
main()
|
| 38 |
+
{
|
| 39 |
+
typedef std::unordered_map<Key, int> MapT;
|
| 40 |
+
typedef MapT::iterator Iter;
|
| 41 |
+
MapT map;
|
| 42 |
+
Iter it = map.find(Key(0));
|
| 43 |
+
assert(it == map.end());
|
| 44 |
+
std::pair<Iter, bool> result = map.insert(std::make_pair(Key(0), 42));
|
| 45 |
+
assert(result.second);
|
| 46 |
+
assert(result.first->second == 42);
|
| 47 |
+
}
|
pool/shard009/C++/0106909_Scale_dlg.cpp
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// WinProm Copyright 2015 Edward Earl
|
| 2 |
+
// All rights reserved.
|
| 3 |
+
//
|
| 4 |
+
// This software is distributed under a license that is described in
|
| 5 |
+
// the LICENSE file that accompanies it.
|
| 6 |
+
//
|
| 7 |
+
// Scale_dlg.cpp : implementation file
|
| 8 |
+
//
|
| 9 |
+
|
| 10 |
+
#include "stdafx.h"
|
| 11 |
+
#include "winprom.h"
|
| 12 |
+
#include "Scale_dlg.h"
|
| 13 |
+
|
| 14 |
+
#ifdef _DEBUG
|
| 15 |
+
#define new DEBUG_NEW
|
| 16 |
+
#undef THIS_FILE
|
| 17 |
+
static char THIS_FILE[] = __FILE__;
|
| 18 |
+
#endif
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
/////////////////////////////////////////////////////////////////////////////
|
| 22 |
+
// CScale_dlg dialog
|
| 23 |
+
|
| 24 |
+
CScale_dlg::CScale_dlg(CWnd* pParent /*=NULL*/)
|
| 25 |
+
: CDialog(CScale_dlg::IDD, pParent)
|
| 26 |
+
{
|
| 27 |
+
//{{AFX_DATA_INIT(CScale_dlg)
|
| 28 |
+
m_scale = 0.0f;
|
| 29 |
+
//}}AFX_DATA_INIT
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void CScale_dlg::DoDataExchange(CDataExchange* pDX)
|
| 33 |
+
{
|
| 34 |
+
CDialog::DoDataExchange(pDX);
|
| 35 |
+
//{{AFX_DATA_MAP(CScale_dlg)
|
| 36 |
+
DDX_Text(pDX, IDC_SCALE, m_scale);
|
| 37 |
+
//}}AFX_DATA_MAP
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
BEGIN_MESSAGE_MAP(CScale_dlg, CDialog)
|
| 42 |
+
//{{AFX_MSG_MAP(CScale_dlg)
|
| 43 |
+
//}}AFX_MSG_MAP
|
| 44 |
+
END_MESSAGE_MAP()
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
/////////////////////////////////////////////////////////////////////////////
|
| 48 |
+
// CScale_dlg message handlers
|
| 49 |
+
|
| 50 |
+
void CScale_dlg::OnOK()
|
| 51 |
+
{
|
| 52 |
+
if (!UpdateData()) return;
|
| 53 |
+
if (m_scale<=0) {
|
| 54 |
+
MessageBox("Scale must be greater than 0.","Winprom Scale Error",MB_OK|MB_ICONERROR);
|
| 55 |
+
return;
|
| 56 |
+
}
|
| 57 |
+
CDialog::OnOK();
|
| 58 |
+
}
|
pool/shard009/C++/0106913_ComputeWindUp.cpp
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma ident "$Id$"
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* @file ComputeWindUp.cpp
|
| 5 |
+
* This class computes the wind-up effect on the phase observables, in radians.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
//============================================================================
|
| 9 |
+
//
|
| 10 |
+
// This file is part of GPSTk, the GPS Toolkit.
|
| 11 |
+
//
|
| 12 |
+
// The GPSTk is free software; you can redistribute it and/or modify
|
| 13 |
+
// it 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 |
+
// any later version.
|
| 16 |
+
//
|
| 17 |
+
// The GPSTk is distributed in the hope that it will be useful,
|
| 18 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 20 |
+
// GNU Lesser General Public License for more details.
|
| 21 |
+
//
|
| 22 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
// License along with GPSTk; if not, write to the Free Software Foundation,
|
| 24 |
+
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 25 |
+
//
|
| 26 |
+
// Dagoberto Salazar - gAGE ( http://www.gage.es ). 2007, 2008, 2009
|
| 27 |
+
//
|
| 28 |
+
//============================================================================
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
#include "ComputeWindUp.hpp"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
namespace gpstk
|
| 35 |
+
{
|
| 36 |
+
|
| 37 |
+
// Index initially assigned to this class
|
| 38 |
+
int ComputeWindUp::classIndex = 4500000;
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
// Returns an index identifying this object.
|
| 42 |
+
int ComputeWindUp::getIndex() const
|
| 43 |
+
{ return index; }
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
// Returns a string identifying this object.
|
| 47 |
+
std::string ComputeWindUp::getClassName() const
|
| 48 |
+
{ return "ComputeWindUp"; }
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
/* Returns a satTypeValueMap object, adding the new data generated when
|
| 53 |
+
* calling this object.
|
| 54 |
+
*
|
| 55 |
+
* @param time Epoch corresponding to the data.
|
| 56 |
+
* @param gData Data object holding the data.
|
| 57 |
+
*/
|
| 58 |
+
satTypeValueMap& ComputeWindUp::Process( const DayTime& time,
|
| 59 |
+
satTypeValueMap& gData )
|
| 60 |
+
throw(ProcessingException)
|
| 61 |
+
{
|
| 62 |
+
|
| 63 |
+
try
|
| 64 |
+
{
|
| 65 |
+
|
| 66 |
+
// Compute Sun position at this epoch
|
| 67 |
+
SunPosition sunPosition;
|
| 68 |
+
Triple sunPos(sunPosition.getPosition(time));
|
| 69 |
+
|
| 70 |
+
// Define a Triple that will hold satellite position, in ECEF
|
| 71 |
+
Triple svPos(0.0, 0.0, 0.0);
|
| 72 |
+
|
| 73 |
+
SatIDSet satRejectedSet;
|
| 74 |
+
|
| 75 |
+
// Loop through all the satellites
|
| 76 |
+
for ( satTypeValueMap::iterator it = gData.begin();
|
| 77 |
+
it != gData.end();
|
| 78 |
+
++it )
|
| 79 |
+
{
|
| 80 |
+
|
| 81 |
+
// First check if this satellite has previous arc information
|
| 82 |
+
if( satArcMap.find( (*it).first ) == satArcMap.end() )
|
| 83 |
+
{
|
| 84 |
+
// If it doesn't have an entry, insert one
|
| 85 |
+
satArcMap[ (*it).first ] = 0.0;
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
// Then, check both if there is arc information, and if current
|
| 89 |
+
// arc number is different from arc number in storage (which
|
| 90 |
+
// means a cycle slip happened)
|
| 91 |
+
if ( (*it).second.find(TypeID::satArc) != (*it).second.end() &&
|
| 92 |
+
(*it).second(TypeID::satArc) != satArcMap[ (*it).first ] )
|
| 93 |
+
{
|
| 94 |
+
// If different, update satellite arc in storage
|
| 95 |
+
satArcMap[ (*it).first ] = (*it).second(TypeID::satArc);
|
| 96 |
+
|
| 97 |
+
// Reset phase information
|
| 98 |
+
phase_satellite[ (*it).first ].previousPhase = 0.0;
|
| 99 |
+
phase_station[ (*it).first ].previousPhase = 0.0;
|
| 100 |
+
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
// Use ephemeris if satellite position is not already computed
|
| 105 |
+
if( ( (*it).second.find(TypeID::satX) == (*it).second.end() ) ||
|
| 106 |
+
( (*it).second.find(TypeID::satY) == (*it).second.end() ) ||
|
| 107 |
+
( (*it).second.find(TypeID::satZ) == (*it).second.end() ) )
|
| 108 |
+
{
|
| 109 |
+
|
| 110 |
+
if(pEphemeris==NULL)
|
| 111 |
+
{
|
| 112 |
+
|
| 113 |
+
// If ephemeris is missing, then remove all satellites
|
| 114 |
+
satRejectedSet.insert( (*it).first );
|
| 115 |
+
|
| 116 |
+
continue;
|
| 117 |
+
|
| 118 |
+
}
|
| 119 |
+
else
|
| 120 |
+
{
|
| 121 |
+
|
| 122 |
+
// Try to get satellite position
|
| 123 |
+
// if it is not already computed
|
| 124 |
+
try
|
| 125 |
+
{
|
| 126 |
+
// For our purposes, position at receive time
|
| 127 |
+
// is fine enough
|
| 128 |
+
Xvt svPosVel(pEphemeris->getXvt( (*it).first, time ));
|
| 129 |
+
|
| 130 |
+
// If everything is OK, then continue processing.
|
| 131 |
+
svPos[0] = svPosVel.x.theArray[0];
|
| 132 |
+
svPos[1] = svPosVel.x.theArray[1];
|
| 133 |
+
svPos[2] = svPosVel.x.theArray[2];
|
| 134 |
+
|
| 135 |
+
}
|
| 136 |
+
catch(...)
|
| 137 |
+
{
|
| 138 |
+
|
| 139 |
+
// If satellite is missing, then schedule it
|
| 140 |
+
// for removal
|
| 141 |
+
satRejectedSet.insert( (*it).first );
|
| 142 |
+
|
| 143 |
+
continue;
|
| 144 |
+
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
}
|
| 150 |
+
else
|
| 151 |
+
{
|
| 152 |
+
|
| 153 |
+
// Get satellite position out of GDS
|
| 154 |
+
svPos[0] = (*it).second[TypeID::satX];
|
| 155 |
+
svPos[1] = (*it).second[TypeID::satY];
|
| 156 |
+
svPos[2] = (*it).second[TypeID::satZ];
|
| 157 |
+
|
| 158 |
+
} // End of 'if( ( (*it).second.find(TypeID::satX) == ...'
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
// Let's get wind-up value in radians, and insert it
|
| 162 |
+
// into GNSS data structure.
|
| 163 |
+
(*it).second[TypeID::windUp] =
|
| 164 |
+
getWindUp((*it).first, time, svPos, sunPos);
|
| 165 |
+
|
| 166 |
+
} // End of 'for (it = gData.begin(); it != gData.end(); ++it)'
|
| 167 |
+
|
| 168 |
+
// Remove satellites with missing data
|
| 169 |
+
gData.removeSatID(satRejectedSet);
|
| 170 |
+
|
| 171 |
+
return gData;
|
| 172 |
+
|
| 173 |
+
}
|
| 174 |
+
catch(Exception& u)
|
| 175 |
+
{
|
| 176 |
+
// Throw an exception if something unexpected happens
|
| 177 |
+
ProcessingException e( getClassName() + ":"
|
| 178 |
+
+ StringUtils::asString( getIndex() ) + ":"
|
| 179 |
+
+ u.what() );
|
| 180 |
+
|
| 181 |
+
GPSTK_THROW(e);
|
| 182 |
+
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
} // End of method 'ComputeWindUp::Process()'
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
/* Sets name of "PRN_GPS"-like file containing satellite data.
|
| 190 |
+
* @param name Name of satellite data file.
|
| 191 |
+
*/
|
| 192 |
+
ComputeWindUp& ComputeWindUp::setFilename(const string& name)
|
| 193 |
+
{
|
| 194 |
+
|
| 195 |
+
fileData = name;
|
| 196 |
+
satData.open(fileData);
|
| 197 |
+
|
| 198 |
+
return (*this);
|
| 199 |
+
|
| 200 |
+
} // End of method 'ComputeWindUp::setFilename()'
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
/* Compute the value of the wind-up, in radians.
|
| 205 |
+
* @param sat Satellite IDmake
|
| 206 |
+
* @param time Epoch of interest
|
| 207 |
+
* @param satpos Satellite position, as a Triple
|
| 208 |
+
* @param sunpos Sun position, as a Triple
|
| 209 |
+
*
|
| 210 |
+
* @return Wind-up computation, in radians
|
| 211 |
+
*/
|
| 212 |
+
double ComputeWindUp::getWindUp( const SatID& satid,
|
| 213 |
+
const DayTime& time,
|
| 214 |
+
const Triple& sat,
|
| 215 |
+
const Triple& sunPosition )
|
| 216 |
+
{
|
| 217 |
+
|
| 218 |
+
// Unitary vector from satellite to Earth mass center
|
| 219 |
+
Triple rk( ( (-1.0)*(sat.unitVector()) ) );
|
| 220 |
+
|
| 221 |
+
// Unitary vector from Earth mass center to Sun
|
| 222 |
+
Triple ri( sunPosition.unitVector() );
|
| 223 |
+
|
| 224 |
+
// rj = rk x ri
|
| 225 |
+
Triple rj(rk.cross(ri));
|
| 226 |
+
|
| 227 |
+
// ri = rj x rk
|
| 228 |
+
ri = rj.cross(rk);
|
| 229 |
+
|
| 230 |
+
// Let's convert ri, rj to unitary vectors.
|
| 231 |
+
// Now ri, rj, rk form a base in the ECEF reference frame
|
| 232 |
+
ri = ri.unitVector();
|
| 233 |
+
rj = rj.unitVector();
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
// Get satellite rotation angle
|
| 237 |
+
|
| 238 |
+
// Get vector from Earth mass center to receiver
|
| 239 |
+
Triple rxPos(nominalPos.X(), nominalPos.Y(), nominalPos.Z());
|
| 240 |
+
|
| 241 |
+
// Compute unitary vector vector from satellite to RECEIVER
|
| 242 |
+
Triple rrho( (rxPos-sat).unitVector() );
|
| 243 |
+
|
| 244 |
+
// Vector from SV to Sun center of mass
|
| 245 |
+
Triple gps_sun( sunPosition-sat );
|
| 246 |
+
|
| 247 |
+
// Redefine rk: Unitary vector from SV to Earth mass center
|
| 248 |
+
rk = (-1.0)*(sat.unitVector());
|
| 249 |
+
|
| 250 |
+
// Redefine rj: rj = rk x gps_sun, then make sure it is unitary
|
| 251 |
+
rj = (rk.cross(gps_sun)).unitVector();
|
| 252 |
+
|
| 253 |
+
// Redefine ri: ri = rj x rk, then make sure it is unitary
|
| 254 |
+
// Now, ri, rj, rk form a base in the satellite body reference
|
| 255 |
+
// frame, expressed in the ECEF reference frame
|
| 256 |
+
ri = (rj.cross(rk)).unitVector();
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
// Projection of "rk" vector to line of sight vector (rrho)
|
| 260 |
+
double zk(rrho.dot(rk));
|
| 261 |
+
|
| 262 |
+
// Get a vector without components on rk (i.e., belonging
|
| 263 |
+
// to ri, rj plane)
|
| 264 |
+
Triple dpp(rrho-zk*rk);
|
| 265 |
+
|
| 266 |
+
// Compute dpp components in ri, rj plane
|
| 267 |
+
double xk(dpp.dot(ri));
|
| 268 |
+
double yk(dpp.dot(rj));
|
| 269 |
+
|
| 270 |
+
// Compute satellite rotation angle, in radians
|
| 271 |
+
double alpha1(std::atan2(yk,xk));
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
// Get receiver rotation angle
|
| 275 |
+
|
| 276 |
+
// Redefine rk: Unitary vector from Receiver to Earth mass center
|
| 277 |
+
rk = (-1.0)*(rxPos.unitVector());
|
| 278 |
+
|
| 279 |
+
// Let's define a NORTH unitary vector in the Up, East, North
|
| 280 |
+
// (UEN) topocentric reference frame
|
| 281 |
+
Triple delta(0.0, 0.0, 1.0);
|
| 282 |
+
|
| 283 |
+
// Rotate delta to XYZ reference frame
|
| 284 |
+
delta =
|
| 285 |
+
(delta.R2(nominalPos.geodeticLatitude())).R3(-nominalPos.longitude());
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
// Computation of reference trame unitary vectors for receiver
|
| 289 |
+
// rj = rk x delta, and make it unitary
|
| 290 |
+
rj = (rk.cross(delta)).unitVector();
|
| 291 |
+
|
| 292 |
+
// ri = rj x rk, and make it unitary
|
| 293 |
+
ri = (rj.cross(rk)).unitVector();
|
| 294 |
+
|
| 295 |
+
// Projection of "rk" vector to line of sight vector (rrho)
|
| 296 |
+
zk = rrho.dot(rk);
|
| 297 |
+
|
| 298 |
+
// Get a vector without components on rk (i.e., belonging
|
| 299 |
+
// to ri, rj plane)
|
| 300 |
+
dpp = rrho-zk*rk;
|
| 301 |
+
|
| 302 |
+
// Compute dpp components in ri, rj plane
|
| 303 |
+
xk = dpp.dot(ri);
|
| 304 |
+
yk = dpp.dot(rj);
|
| 305 |
+
|
| 306 |
+
// Compute receiver rotation angle, in radians
|
| 307 |
+
double alpha2(std::atan2(yk,xk));
|
| 308 |
+
|
| 309 |
+
double wind_up(0.0);
|
| 310 |
+
|
| 311 |
+
// Find out if satellite belongs to block "IIR", because
|
| 312 |
+
// satellites of block IIR have a 180 phase shift
|
| 313 |
+
if(satData.getBlock( satid, time ) == "IIR")
|
| 314 |
+
{
|
| 315 |
+
wind_up = PI;
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
alpha1 = alpha1 + wind_up;
|
| 319 |
+
|
| 320 |
+
double da1(alpha1-phase_satellite[satid].previousPhase);
|
| 321 |
+
|
| 322 |
+
double da2(alpha2-phase_station[satid].previousPhase);
|
| 323 |
+
|
| 324 |
+
// Let's avoid problems when passing from 359 to 0 degrees.
|
| 325 |
+
phase_satellite[satid].previousPhase += std::atan2( std::sin(da1),
|
| 326 |
+
std::cos(da1) );
|
| 327 |
+
|
| 328 |
+
phase_station[satid].previousPhase += std::atan2( std::sin(da2),
|
| 329 |
+
std::cos(da2) );
|
| 330 |
+
|
| 331 |
+
// Compute wind up effect in radians
|
| 332 |
+
wind_up = phase_satellite[satid].previousPhase -
|
| 333 |
+
phase_station[satid].previousPhase;
|
| 334 |
+
|
| 335 |
+
return wind_up;
|
| 336 |
+
|
| 337 |
+
} // End of method 'ComputeWindUp::getWindUp()'
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
} // End of namespace gpstk
|
pool/shard009/C++/0106915_CacheTest.cpp
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 3 |
+
*
|
| 4 |
+
* This source code is licensed under the MIT license found in the
|
| 5 |
+
* LICENSE file in the root directory of this source tree.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
#include <folly/executors/ManualExecutor.h>
|
| 9 |
+
#include <folly/init/Init.h>
|
| 10 |
+
#include <folly/portability/GTest.h>
|
| 11 |
+
#include <gtest/gtest-printers.h>
|
| 12 |
+
#include <deque>
|
| 13 |
+
#include <stdexcept>
|
| 14 |
+
#include <string>
|
| 15 |
+
#include "watchman/LRUCache.h"
|
| 16 |
+
|
| 17 |
+
using namespace watchman;
|
| 18 |
+
|
| 19 |
+
static constexpr const std::chrono::milliseconds kErrorTTL(1000);
|
| 20 |
+
|
| 21 |
+
namespace watchman::lrucache {
|
| 22 |
+
template <typename... A>
|
| 23 |
+
FOLLY_MAYBE_UNUSED static std::ostream& operator<<(
|
| 24 |
+
std::ostream& out,
|
| 25 |
+
Node<A...> const& node) {
|
| 26 |
+
return out << (const void*)&node;
|
| 27 |
+
}
|
| 28 |
+
} // namespace watchman::lrucache
|
| 29 |
+
|
| 30 |
+
TEST(CacheTest, basics) {
|
| 31 |
+
LRUCache<std::string, bool> cache(5, kErrorTTL);
|
| 32 |
+
|
| 33 |
+
EXPECT_EQ(cache.size(), 0) << "initially empty";
|
| 34 |
+
EXPECT_EQ(cache.get("foo"), nullptr) << "nullptr for non-existent item";
|
| 35 |
+
|
| 36 |
+
EXPECT_TRUE(cache.set("foo", true)->value()) << "inserted true";
|
| 37 |
+
EXPECT_EQ(cache.size(), 1) << "size is now one";
|
| 38 |
+
EXPECT_TRUE(cache.get("foo")->value()) << "looked up item";
|
| 39 |
+
|
| 40 |
+
EXPECT_FALSE(cache.set("foo", false)->value()) << "replaced true with false";
|
| 41 |
+
EXPECT_FALSE(cache.get("foo")->value()) << "looked up new false item";
|
| 42 |
+
EXPECT_EQ(cache.size(), 1) << "replacement didn't change size";
|
| 43 |
+
|
| 44 |
+
EXPECT_FALSE(cache.erase("foo")->value()) << "erased and returned false foo";
|
| 45 |
+
EXPECT_EQ(cache.erase("foo"), nullptr)
|
| 46 |
+
<< "double erase doesn't return anything";
|
| 47 |
+
EXPECT_EQ(cache.get("foo"), nullptr) << "nullptr for non-existent item";
|
| 48 |
+
|
| 49 |
+
for (size_t i = 0; i < 6; ++i) {
|
| 50 |
+
EXPECT_NE(cache.set(std::to_string(i), true), nullptr) << "inserted";
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
EXPECT_EQ(cache.size(), 5)
|
| 54 |
+
<< "limited to 5 items, despite inserting 6 total. size=" << cache.size();
|
| 55 |
+
|
| 56 |
+
EXPECT_EQ(cache.get("0"), nullptr) << "we expect 0 to have been evicted";
|
| 57 |
+
for (size_t i = 1; i < 6; ++i) {
|
| 58 |
+
EXPECT_TRUE(cache.get(std::to_string(i))) << "found later node " << i;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
EXPECT_TRUE(cache.set("bar", true)) << "added new item";
|
| 62 |
+
EXPECT_EQ(cache.get("1"), nullptr) << "we expect 1 to be evicted";
|
| 63 |
+
EXPECT_TRUE(cache.get("2")) << "2 should be there, and we just touched it";
|
| 64 |
+
EXPECT_TRUE(cache.set("baz", true)) << "added new item";
|
| 65 |
+
EXPECT_EQ(cache.size(), 5) << "max size still respected";
|
| 66 |
+
EXPECT_TRUE(cache.get("2")) << "2 should still be there; not evicted";
|
| 67 |
+
EXPECT_EQ(cache.get("3"), nullptr) << "we expect 3 to be evicted";
|
| 68 |
+
|
| 69 |
+
cache.clear();
|
| 70 |
+
EXPECT_EQ(cache.size(), 0) << "cleared out and have zero items";
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
TEST(CacheTest, future) {
|
| 74 |
+
using Cache = LRUCache<int, int>;
|
| 75 |
+
using Node = typename Cache::NodeType;
|
| 76 |
+
Cache cache(5, kErrorTTL);
|
| 77 |
+
folly::ManualExecutor exec;
|
| 78 |
+
|
| 79 |
+
auto now = std::chrono::steady_clock::now();
|
| 80 |
+
|
| 81 |
+
auto okGetter = [&exec](int k) {
|
| 82 |
+
return folly::makeFuture(k).via(&exec).thenTry(
|
| 83 |
+
[](folly::Try<int>&& key) { return (1 + key.value()) * 2; });
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
auto failGetter = [&exec](int k) {
|
| 87 |
+
return folly::makeFuture(k).via(&exec).thenTry(
|
| 88 |
+
[](folly::Try<int>&&) -> int { throw std::runtime_error("bleet"); });
|
| 89 |
+
};
|
| 90 |
+
|
| 91 |
+
// Queue up a get via a getter that will succeed
|
| 92 |
+
auto f = cache.get(0, okGetter, now);
|
| 93 |
+
EXPECT_FALSE(f.isReady()) << "future didn't finish yet";
|
| 94 |
+
|
| 95 |
+
EXPECT_THROW(cache.get(0), std::runtime_error);
|
| 96 |
+
|
| 97 |
+
// Queue up a second get using the same getter
|
| 98 |
+
auto f2 = cache.get(0, okGetter, now);
|
| 99 |
+
EXPECT_FALSE(f2.isReady()) << "also not ready";
|
| 100 |
+
|
| 101 |
+
exec.drain();
|
| 102 |
+
|
| 103 |
+
EXPECT_TRUE(f.isReady()) << "first is ready";
|
| 104 |
+
EXPECT_TRUE(f2.isReady()) << "second is ready";
|
| 105 |
+
|
| 106 |
+
EXPECT_EQ(f.value()->value(), 2) << "got correct value for first";
|
| 107 |
+
EXPECT_EQ(f.value()->value(), f2.value()->value())
|
| 108 |
+
<< "got same value for second";
|
| 109 |
+
|
| 110 |
+
// Now to saturate the cache with failed lookups
|
| 111 |
+
|
| 112 |
+
cache.clear();
|
| 113 |
+
std::vector<folly::Future<std::shared_ptr<const Node>>> futures;
|
| 114 |
+
for (size_t i = 1; i < 7; ++i) {
|
| 115 |
+
futures.emplace_back(
|
| 116 |
+
cache.get(i, failGetter, now + std::chrono::milliseconds(i)));
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
auto drained = exec.drain();
|
| 120 |
+
EXPECT_EQ(drained, 13) << "should be 13 things pending, but have " << drained;
|
| 121 |
+
|
| 122 |
+
// Let them make progress
|
| 123 |
+
exec.drain();
|
| 124 |
+
|
| 125 |
+
EXPECT_EQ(cache.size(), 5)
|
| 126 |
+
<< "cache should be full, but has " << cache.size();
|
| 127 |
+
|
| 128 |
+
folly::collectAll(futures.begin(), futures.end())
|
| 129 |
+
.defer(
|
| 130 |
+
[](folly::Try<std::vector<folly::Try<std::shared_ptr<const Node>>>>&&
|
| 131 |
+
result) {
|
| 132 |
+
for (auto& r : result.value()) {
|
| 133 |
+
EXPECT_TRUE(r.value()->result().hasException())
|
| 134 |
+
<< "should be an error node";
|
| 135 |
+
}
|
| 136 |
+
})
|
| 137 |
+
.wait();
|
| 138 |
+
|
| 139 |
+
EXPECT_EQ(cache.size(), 5)
|
| 140 |
+
<< "cache should still be full (no excess) but has " << cache.size();
|
| 141 |
+
|
| 142 |
+
EXPECT_EQ(cache.get(42, now), nullptr) << "we don't have 42 yet";
|
| 143 |
+
|
| 144 |
+
// Now if we "sleep" for long enough, we should be able to evict
|
| 145 |
+
// the error nodes and allow the insert to happen.
|
| 146 |
+
EXPECT_EQ(cache.get(42, now), nullptr) << "we don't have 42 yet";
|
| 147 |
+
EXPECT_TRUE(cache.set(42, 42, now + kErrorTTL + std::chrono::milliseconds(1)))
|
| 148 |
+
<< "inserted";
|
| 149 |
+
EXPECT_NE(cache.get(42, now), nullptr) << "we found 42 in the cache";
|
| 150 |
+
EXPECT_EQ(cache.size(), 5)
|
| 151 |
+
<< "cache should still be full (no excess) but has " << cache.size();
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
int main(int argc, char* argv[]) {
|
| 155 |
+
testing::InitGoogleTest(&argc, argv);
|
| 156 |
+
folly::init(&argc, &argv);
|
| 157 |
+
return RUN_ALL_TESTS();
|
| 158 |
+
}
|
pool/shard009/C++/0106919_B.cpp
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* ========================================
|
| 2 |
+
|
| 3 |
+
ID: mathema6
|
| 4 |
+
TASK: B
|
| 5 |
+
LANG: C++11
|
| 6 |
+
(...for USACO solutions)
|
| 7 |
+
|
| 8 |
+
* File Name : B.cpp
|
| 9 |
+
|
| 10 |
+
* Creation Date : 30-12-2014
|
| 11 |
+
|
| 12 |
+
* Last Modified :
|
| 13 |
+
|
| 14 |
+
* Created By : Karel Ha <mathemage@gmail.com>
|
| 15 |
+
|
| 16 |
+
* URL : http://codeforces.com/contest/500/problem/B
|
| 17 |
+
|
| 18 |
+
* Points Gained (in case of online contest) : 828 / 1000
|
| 19 |
+
|
| 20 |
+
==========================================*/
|
| 21 |
+
|
| 22 |
+
#include <vector>
|
| 23 |
+
#include <list>
|
| 24 |
+
#include <map>
|
| 25 |
+
#include <set>
|
| 26 |
+
#include <deque>
|
| 27 |
+
#include <stack>
|
| 28 |
+
#include <bitset>
|
| 29 |
+
#include <algorithm>
|
| 30 |
+
#include <functional>
|
| 31 |
+
#include <numeric>
|
| 32 |
+
#include <utility>
|
| 33 |
+
#include <sstream>
|
| 34 |
+
#include <iostream>
|
| 35 |
+
#include <iomanip>
|
| 36 |
+
#include <cstdio>
|
| 37 |
+
#include <cmath>
|
| 38 |
+
#include <cstdlib>
|
| 39 |
+
#include <ctime>
|
| 40 |
+
#include <cassert>
|
| 41 |
+
#include <string>
|
| 42 |
+
#include <cctype>
|
| 43 |
+
#include <fstream>
|
| 44 |
+
#include <unordered_set>
|
| 45 |
+
#include <unordered_map>
|
| 46 |
+
|
| 47 |
+
using namespace std;
|
| 48 |
+
|
| 49 |
+
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
|
| 50 |
+
#define REP(I,N) FOR(I,0,N)
|
| 51 |
+
#define ALL(A) (A).begin(), (A).end()
|
| 52 |
+
#define MSG(a) cout << #a << " == " << a << endl;
|
| 53 |
+
|
| 54 |
+
// uncomment following line for debug mode
|
| 55 |
+
//#define DEBUG
|
| 56 |
+
|
| 57 |
+
int main() {
|
| 58 |
+
int n;
|
| 59 |
+
cin >> n;
|
| 60 |
+
vector<int> p(n);
|
| 61 |
+
REP(i,n) {
|
| 62 |
+
cin >> p[i];
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
vector<vector<bool>> A(n);
|
| 66 |
+
string line;
|
| 67 |
+
REP(i,n) {
|
| 68 |
+
A[i].assign(n,false);
|
| 69 |
+
cin >> line;
|
| 70 |
+
REP(j,n) {
|
| 71 |
+
A[i][j] = (line[j] == '0') ? false : true;
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// FW
|
| 76 |
+
REP(k,n) {
|
| 77 |
+
#ifdef DEBUG
|
| 78 |
+
// display A
|
| 79 |
+
MSG(k)
|
| 80 |
+
cout << "A:" << endl;
|
| 81 |
+
REP(i,n) {
|
| 82 |
+
REP(j,n) {
|
| 83 |
+
cout << A[i][j] ? "1" : "0";
|
| 84 |
+
}
|
| 85 |
+
cout << endl;
|
| 86 |
+
}
|
| 87 |
+
#endif
|
| 88 |
+
|
| 89 |
+
REP(i,n) {
|
| 90 |
+
REP(j,n) {
|
| 91 |
+
A[i][j] = A[i][j] || (A[i][k] && A[k][j]);
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
REP(i,n-1) {
|
| 97 |
+
int mi = n+1;
|
| 98 |
+
int idx = i;
|
| 99 |
+
FOR(j,i,n) {
|
| 100 |
+
if (A[i][j] && p[j] < mi) {
|
| 101 |
+
mi = p[j];
|
| 102 |
+
idx = j;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
swap(p[i], p[idx]);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
REP(i,n) {
|
| 109 |
+
cout << p[i];
|
| 110 |
+
if (i < n-1)
|
| 111 |
+
cout << " ";
|
| 112 |
+
}
|
| 113 |
+
return 0;
|
| 114 |
+
}
|
pool/shard009/C++/0106920_olethros.cpp
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
|
| 3 |
+
file : olethros.cpp
|
| 4 |
+
copyright : (C) 2002-2004 Bernhard Wymann
|
| 5 |
+
2004 Christos Dimitrakakis
|
| 6 |
+
email : dimitrak@idiap.ch
|
| 7 |
+
version : $Id: olethros.cpp,v 1.10.2.2 2008/11/09 17:50:20 berniw Exp $
|
| 8 |
+
|
| 9 |
+
***************************************************************************/
|
| 10 |
+
|
| 11 |
+
/***************************************************************************
|
| 12 |
+
* *
|
| 13 |
+
* This program is free software; you can redistribute it and/or modify *
|
| 14 |
+
* it under the terms of the GNU General Public License as published by *
|
| 15 |
+
* the Free Software Foundation; either version 2 of the License, or *
|
| 16 |
+
* (at your option) any later version. *
|
| 17 |
+
* *
|
| 18 |
+
***************************************************************************/
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
\file olethros.cpp
|
| 22 |
+
|
| 23 |
+
\brief This is the main file for the Olethros robot.
|
| 24 |
+
|
| 25 |
+
The Olethros robot is basically the same as berniw's BT robot with
|
| 26 |
+
added learning capabilities.
|
| 27 |
+
*/
|
| 28 |
+
|
| 29 |
+
#ifdef _WIN32
|
| 30 |
+
#include <windows.h>
|
| 31 |
+
#endif
|
| 32 |
+
|
| 33 |
+
#include <stdio.h>
|
| 34 |
+
#include <stdlib.h>
|
| 35 |
+
#include <math.h>
|
| 36 |
+
|
| 37 |
+
#include <tgf.h>
|
| 38 |
+
#include <track.h>
|
| 39 |
+
#include <car.h>
|
| 40 |
+
#include <raceman.h>
|
| 41 |
+
#include <robottools.h>
|
| 42 |
+
#include <robot.h>
|
| 43 |
+
|
| 44 |
+
#include "driver.h"
|
| 45 |
+
|
| 46 |
+
#ifdef USE_OLETHROS_NAMESPACE
|
| 47 |
+
namespace olethros
|
| 48 |
+
{
|
| 49 |
+
#endif
|
| 50 |
+
|
| 51 |
+
#define BUFSIZE 20
|
| 52 |
+
#define NBBOTS 10
|
| 53 |
+
|
| 54 |
+
static const char* botname[NBBOTS] = {
|
| 55 |
+
"olethros 1", "olethros 2", "olethros 3", "olethros 4", "olethros 5",
|
| 56 |
+
"olethros 6", "olethros 7", "olethros 8", "olethros 9", "olethros 10"
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
static const char* botdesc[NBBOTS] = {
|
| 60 |
+
"olethros 1", "olethros 2", "olethros 3", "olethros 4", "olethros 5",
|
| 61 |
+
"olethros 6", "olethros 7", "olethros 8", "olethros 9", "olethros 10"
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
static Driver *driver[NBBOTS];
|
| 65 |
+
|
| 66 |
+
static void initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSituation *s);
|
| 67 |
+
static void newRace(int index, tCarElt* car, tSituation *s);
|
| 68 |
+
static void drive(int index, tCarElt* car, tSituation *s);
|
| 69 |
+
static int pitcmd(int index, tCarElt* car, tSituation *s);
|
| 70 |
+
static void shutdown(int index);
|
| 71 |
+
static int InitFuncPt(int index, void *pt);
|
| 72 |
+
static void endRace(int index, tCarElt *car, tSituation *s);
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
// Module entry point.
|
| 76 |
+
extern "C" int olethros(tModInfo *modInfo)
|
| 77 |
+
{
|
| 78 |
+
int i;
|
| 79 |
+
|
| 80 |
+
// Clear all structures.
|
| 81 |
+
memset(modInfo, 0, 10*sizeof(tModInfo));
|
| 82 |
+
|
| 83 |
+
for (i = 0; i < NBBOTS; i++) {
|
| 84 |
+
modInfo[i].name = strdup(botname[i]); // name of the module (short).
|
| 85 |
+
modInfo[i].desc = strdup(botdesc[i]); // Description of the module (can be long).
|
| 86 |
+
modInfo[i].fctInit = InitFuncPt; // Init function.
|
| 87 |
+
modInfo[i].gfId = ROB_IDENT; // Supported framework version.
|
| 88 |
+
modInfo[i].index = i; // Indices from 0 to 9.
|
| 89 |
+
}
|
| 90 |
+
return 0;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
// Module interface initialization.
|
| 95 |
+
static int InitFuncPt(int index, void *pt)
|
| 96 |
+
{
|
| 97 |
+
tRobotItf *itf = (tRobotItf *)pt;
|
| 98 |
+
|
| 99 |
+
// Create robot instance for index.
|
| 100 |
+
driver[index] = new Driver(index);
|
| 101 |
+
itf->rbNewTrack = initTrack; // Give the robot the track view called.
|
| 102 |
+
itf->rbNewRace = newRace; // Start a new race.
|
| 103 |
+
itf->rbDrive = drive; // Drive during race.
|
| 104 |
+
itf->rbPitCmd = pitcmd; // Pit commands.
|
| 105 |
+
itf->rbEndRace = endRace; // End of the current race.
|
| 106 |
+
itf->rbShutdown = shutdown; // Called before the module is unloaded.
|
| 107 |
+
itf->index = index; // Index used if multiple interfaces.
|
| 108 |
+
return 0;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
// Called for every track change or new race.
|
| 113 |
+
static void initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSituation *s)
|
| 114 |
+
{
|
| 115 |
+
driver[index]->initTrack(track, carHandle, carParmHandle, s);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
// Start a new race.
|
| 120 |
+
static void newRace(int index, tCarElt* car, tSituation *s)
|
| 121 |
+
{
|
| 122 |
+
driver[index]->newRace(car, s);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
// Drive during race.
|
| 127 |
+
static void drive(int index, tCarElt* car, tSituation *s)
|
| 128 |
+
{
|
| 129 |
+
driver[index]->drive(s);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
// Pitstop callback.
|
| 134 |
+
static int pitcmd(int index, tCarElt* car, tSituation *s)
|
| 135 |
+
{
|
| 136 |
+
return driver[index]->pitCommand(s);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
// End of the current race.
|
| 141 |
+
static void endRace(int index, tCarElt *car, tSituation *s)
|
| 142 |
+
{
|
| 143 |
+
driver[index]->endRace(s);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
// Called before the module is unloaded.
|
| 148 |
+
static void shutdown(int index)
|
| 149 |
+
{
|
| 150 |
+
delete driver[index];
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
#ifdef USE_OLETHROS_NAMESPACE
|
| 154 |
+
}
|
| 155 |
+
#endif
|
pool/shard009/C++/0106926_SpatialController.cpp
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "SpatialController.h"
|
| 2 |
+
#include "Scene.h"
|
| 3 |
+
|
| 4 |
+
//======================================================================
|
| 5 |
+
using namespace vivid;
|
| 6 |
+
|
| 7 |
+
//======================================================================
|
| 8 |
+
SpatialController::SpatialController ():
|
| 9 |
+
Rotation (math::MatrixIdentity (math::Mat3f ()))
|
| 10 |
+
{ }
|
| 11 |
+
|
| 12 |
+
//======================================================================
|
| 13 |
+
SpatialController::~SpatialController ()
|
| 14 |
+
{ }
|
| 15 |
+
|
| 16 |
+
//======================================================================
|
| 17 |
+
void SpatialController::Update (float time)
|
| 18 |
+
{
|
| 19 |
+
if (Scene::Validate (Node))
|
| 20 |
+
{
|
| 21 |
+
auto& n = Scene::GetNode (Node);
|
| 22 |
+
n.Local.SetRotation (Rotation);
|
| 23 |
+
n.Local.SetTranslation (Translation);
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
//======================================================================
|
| 28 |
+
void SpatialController::MoveForward (float distance)
|
| 29 |
+
{
|
| 30 |
+
Translation += Rotation.GetRow (2) * distance;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
//======================================================================
|
| 34 |
+
void SpatialController::MoveBackward (float distance)
|
| 35 |
+
{
|
| 36 |
+
Translation -= Rotation.GetRow (2) * distance;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
//======================================================================
|
| 40 |
+
void SpatialController::MoveRight (float distance)
|
| 41 |
+
{
|
| 42 |
+
Translation += Rotation.GetRow (0) * distance;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
//======================================================================
|
| 46 |
+
void SpatialController::MoveLeft (float distance)
|
| 47 |
+
{
|
| 48 |
+
Translation -= Rotation.GetRow (0) * distance;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
//======================================================================
|
| 52 |
+
void SpatialController::MoveUp (float distance)
|
| 53 |
+
{
|
| 54 |
+
Translation += Rotation.GetRow (1) * distance;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
//======================================================================
|
| 58 |
+
void SpatialController::MoveDown (float distance)
|
| 59 |
+
{
|
| 60 |
+
Translation -= Rotation.GetRow (1) * distance;
|
| 61 |
+
}
|
pool/shard009/C++/0106931_os_kick.cpp
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* OperServ core functions
|
| 2 |
+
*
|
| 3 |
+
* (C) 2003-2016 Anope Team
|
| 4 |
+
* Contact us at team@anope.org
|
| 5 |
+
*
|
| 6 |
+
* Please read COPYING and README for further details.
|
| 7 |
+
*
|
| 8 |
+
* Based on the original code of Epona by Lara.
|
| 9 |
+
* Based on the original code of Services by Andy Church.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
#include "module.h"
|
| 13 |
+
|
| 14 |
+
class CommandOSKick : public Command
|
| 15 |
+
{
|
| 16 |
+
public:
|
| 17 |
+
CommandOSKick(Module *creator) : Command(creator, "operserv/kick", 3, 3)
|
| 18 |
+
{
|
| 19 |
+
this->SetDesc(_("Kick a user from a channel"));
|
| 20 |
+
this->SetSyntax(_("\037channel\037 \037user\037 \037reason\037"));
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
|
| 24 |
+
{
|
| 25 |
+
const Anope::string &chan = params[0];
|
| 26 |
+
const Anope::string &nick = params[1];
|
| 27 |
+
const Anope::string &s = params[2];
|
| 28 |
+
Channel *c;
|
| 29 |
+
User *u2;
|
| 30 |
+
|
| 31 |
+
if (!(c = Channel::Find(chan)))
|
| 32 |
+
{
|
| 33 |
+
source.Reply(CHAN_X_NOT_IN_USE, chan.c_str());
|
| 34 |
+
return;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
if (c->bouncy_modes)
|
| 38 |
+
{
|
| 39 |
+
source.Reply(_("Services is unable to change modes. Are your servers' U:lines configured correctly?"));
|
| 40 |
+
return;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
if (!(u2 = User::Find(nick, true)))
|
| 44 |
+
{
|
| 45 |
+
source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
|
| 46 |
+
return;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if (!c->Kick(source.service, u2, "%s (%s)", source.GetNick().c_str(), s.c_str()))
|
| 50 |
+
{
|
| 51 |
+
source.Reply(ACCESS_DENIED);
|
| 52 |
+
return;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
Log(LOG_ADMIN, source, this) << "on " << u2->nick << " in " << c->name << " (" << s << ")";
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
|
| 59 |
+
{
|
| 60 |
+
this->SendSyntax(source);
|
| 61 |
+
source.Reply(" ");
|
| 62 |
+
source.Reply(_("Allows staff to kick a user from any channel.\n"
|
| 63 |
+
"Parameters are the same as for the standard /KICK\n"
|
| 64 |
+
"command. The kick message will have the nickname of the\n"
|
| 65 |
+
"IRCop sending the KICK command prepended; for example:\n"
|
| 66 |
+
" \n"
|
| 67 |
+
"*** SpamMan has been kicked off channel #my_channel by %s (Alcan (Flood))"), source.service->nick.c_str());
|
| 68 |
+
return true;
|
| 69 |
+
}
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
class OSKick : public Module
|
| 73 |
+
{
|
| 74 |
+
CommandOSKick commandoskick;
|
| 75 |
+
|
| 76 |
+
public:
|
| 77 |
+
OSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
|
| 78 |
+
commandoskick(this)
|
| 79 |
+
{
|
| 80 |
+
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
MODULE_INIT(OSKick)
|
pool/shard009/C++/0106932_transcoderoptionsflac.cpp
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* This file is part of Clementine.
|
| 2 |
+
Copyright 2010, David Sansome <me@davidsansome.com>
|
| 3 |
+
|
| 4 |
+
Clementine is free software: you can redistribute it and/or modify
|
| 5 |
+
it under the terms of the GNU General Public License as published by
|
| 6 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 7 |
+
(at your option) any later version.
|
| 8 |
+
|
| 9 |
+
Clementine is distributed in the hope that it will be useful,
|
| 10 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
GNU General Public License for more details.
|
| 13 |
+
|
| 14 |
+
You should have received a copy of the GNU General Public License
|
| 15 |
+
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include "transcoderoptionsflac.h"
|
| 19 |
+
#include "ui_transcoderoptionsflac.h"
|
| 20 |
+
|
| 21 |
+
#include <QSettings>
|
| 22 |
+
|
| 23 |
+
const char* TranscoderOptionsFlac::kSettingsGroup = "Transcoder/flacenc";
|
| 24 |
+
|
| 25 |
+
TranscoderOptionsFlac::TranscoderOptionsFlac(QWidget* parent)
|
| 26 |
+
: TranscoderOptionsInterface(parent), ui_(new Ui_TranscoderOptionsFlac) {
|
| 27 |
+
ui_->setupUi(this);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
TranscoderOptionsFlac::~TranscoderOptionsFlac() { delete ui_; }
|
| 31 |
+
|
| 32 |
+
void TranscoderOptionsFlac::Load() {
|
| 33 |
+
QSettings s;
|
| 34 |
+
s.beginGroup(kSettingsGroup);
|
| 35 |
+
|
| 36 |
+
ui_->quality->setValue(s.value("quality", 5).toInt());
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
void TranscoderOptionsFlac::Save() {
|
| 40 |
+
QSettings s;
|
| 41 |
+
s.beginGroup(kSettingsGroup);
|
| 42 |
+
|
| 43 |
+
s.setValue("quality", ui_->quality->value());
|
| 44 |
+
}
|
pool/shard009/C++/0106938_rpcdump.cpp
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2009-2012 Bitcoin Developers
|
| 2 |
+
// Copyright (c) 2011-2012 Litecoin 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 "init.h" // for pwalletMain
|
| 7 |
+
#include "bitcoinrpc.h"
|
| 8 |
+
#include "ui_interface.h"
|
| 9 |
+
#include "base58.h"
|
| 10 |
+
|
| 11 |
+
#include <boost/lexical_cast.hpp>
|
| 12 |
+
|
| 13 |
+
#define printf OutputDebugStringF
|
| 14 |
+
|
| 15 |
+
using namespace json_spirit;
|
| 16 |
+
using namespace std;
|
| 17 |
+
|
| 18 |
+
class CTxDump
|
| 19 |
+
{
|
| 20 |
+
public:
|
| 21 |
+
CBlockIndex *pindex;
|
| 22 |
+
int64 nValue;
|
| 23 |
+
bool fSpent;
|
| 24 |
+
CWalletTx* ptx;
|
| 25 |
+
int nOut;
|
| 26 |
+
CTxDump(CWalletTx* ptx = NULL, int nOut = -1)
|
| 27 |
+
{
|
| 28 |
+
pindex = NULL;
|
| 29 |
+
nValue = 0;
|
| 30 |
+
fSpent = false;
|
| 31 |
+
this->ptx = ptx;
|
| 32 |
+
this->nOut = nOut;
|
| 33 |
+
}
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
Value importprivkey(const Array& params, bool fHelp)
|
| 37 |
+
{
|
| 38 |
+
if (fHelp || params.size() < 1 || params.size() > 2)
|
| 39 |
+
throw runtime_error(
|
| 40 |
+
"importprivkey <talarocoin private key> [label]\n"
|
| 41 |
+
"Adds a private key (as returned by dumpprivkey) to your wallet.");
|
| 42 |
+
|
| 43 |
+
string strSecret = params[0].get_str();
|
| 44 |
+
string strLabel = "";
|
| 45 |
+
if (params.size() > 1)
|
| 46 |
+
strLabel = params[1].get_str();
|
| 47 |
+
CBitcoinSecret vchSecret;
|
| 48 |
+
bool fGood = vchSecret.SetString(strSecret);
|
| 49 |
+
|
| 50 |
+
if (!fGood) throw JSONRPCError(-5,"Invalid private key");
|
| 51 |
+
|
| 52 |
+
CKey key;
|
| 53 |
+
bool fCompressed;
|
| 54 |
+
CSecret secret = vchSecret.GetSecret(fCompressed);
|
| 55 |
+
key.SetSecret(secret, fCompressed);
|
| 56 |
+
CKeyID vchAddress = key.GetPubKey().GetID();
|
| 57 |
+
{
|
| 58 |
+
LOCK2(cs_main, pwalletMain->cs_wallet);
|
| 59 |
+
|
| 60 |
+
pwalletMain->MarkDirty();
|
| 61 |
+
pwalletMain->SetAddressBookName(vchAddress, strLabel);
|
| 62 |
+
|
| 63 |
+
if (!pwalletMain->AddKey(key))
|
| 64 |
+
throw JSONRPCError(-4,"Error adding key to wallet");
|
| 65 |
+
|
| 66 |
+
pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true);
|
| 67 |
+
pwalletMain->ReacceptWalletTransactions();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
return Value::null;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
Value dumpprivkey(const Array& params, bool fHelp)
|
| 74 |
+
{
|
| 75 |
+
if (fHelp || params.size() != 1)
|
| 76 |
+
throw runtime_error(
|
| 77 |
+
"dumpprivkey <talarocoin address>\n"
|
| 78 |
+
"Reveals the private key corresponding to <talarocoin address>.");
|
| 79 |
+
|
| 80 |
+
string strAddress = params[0].get_str();
|
| 81 |
+
CBitcoinAddress address;
|
| 82 |
+
if (!address.SetString(strAddress))
|
| 83 |
+
throw JSONRPCError(-5, "Invalid TalaroCoin address");
|
| 84 |
+
CKeyID keyID;
|
| 85 |
+
if (!address.GetKeyID(keyID))
|
| 86 |
+
throw JSONRPCError(-3, "Address does not refer to a key");
|
| 87 |
+
CSecret vchSecret;
|
| 88 |
+
bool fCompressed;
|
| 89 |
+
if (!pwalletMain->GetSecret(keyID, vchSecret, fCompressed))
|
| 90 |
+
throw JSONRPCError(-4,"Private key for address " + strAddress + " is not known");
|
| 91 |
+
return CBitcoinSecret(vchSecret, fCompressed).ToString();
|
| 92 |
+
}
|
pool/shard009/C++/0106941_PageParser.cpp
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "PageParser.hpp"
|
| 2 |
+
|
| 3 |
+
#include <gumbo-query/Node.h>
|
| 4 |
+
#include <gumbo-query/Document.h>
|
| 5 |
+
|
| 6 |
+
namespace bmrk {
|
| 7 |
+
|
| 8 |
+
PageParser::PageParser(const String& html) : doc_{new CDocument} {
|
| 9 |
+
if (html.empty()) {
|
| 10 |
+
throw Error{"Empty document"};
|
| 11 |
+
}
|
| 12 |
+
doc_->parse(html.c_str());
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
String PageParser::getTitle() const {
|
| 16 |
+
auto&& node = doc_->find("head title").nodeAt(0);
|
| 17 |
+
if (!node.valid()) {
|
| 18 |
+
throw Error{"Cannot parse title"};
|
| 19 |
+
}
|
| 20 |
+
return node.text();
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
} /* bmrk */
|
pool/shard009/C++/0106946_vbucketmap.cc
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2015 Couchbase, Inc
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
* you may not use this file except in compliance with the License.
|
| 7 |
+
* You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include "vbucketmap.h"
|
| 19 |
+
#include "bucket_logger.h"
|
| 20 |
+
#include "ep_engine.h"
|
| 21 |
+
#include "kv_bucket.h"
|
| 22 |
+
#include <memory>
|
| 23 |
+
#include <vector>
|
| 24 |
+
|
| 25 |
+
VBucketMap::VBucketMap(Configuration& config, KVBucket& store)
|
| 26 |
+
: size(config.getMaxVbuckets()) {
|
| 27 |
+
auto& engine = store.getEPEngine();
|
| 28 |
+
const auto numShards = engine.getWorkLoadPolicy().getNumShards();
|
| 29 |
+
for (size_t shardId = 0; shardId < numShards; shardId++) {
|
| 30 |
+
shards.push_back(std::make_unique<KVShard>(engine, shardId));
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
config.addValueChangedListener(
|
| 34 |
+
"hlc_drift_ahead_threshold_us",
|
| 35 |
+
std::make_unique<VBucketConfigChangeListener>(*this));
|
| 36 |
+
config.addValueChangedListener(
|
| 37 |
+
"hlc_drift_behind_threshold_us",
|
| 38 |
+
std::make_unique<VBucketConfigChangeListener>(*this));
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
VBucketPtr VBucketMap::getBucket(Vbid id) const {
|
| 42 |
+
if (id.get() < size) {
|
| 43 |
+
return getShardByVbId(id)->getBucket(id);
|
| 44 |
+
} else {
|
| 45 |
+
return {};
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
ENGINE_ERROR_CODE VBucketMap::addBucket(VBucketPtr vb) {
|
| 50 |
+
if (vb->getId().get() < size) {
|
| 51 |
+
getShardByVbId(vb->getId())->setBucket(vb);
|
| 52 |
+
++vbStateCount[vb->getState() - vbucket_state_active];
|
| 53 |
+
EP_LOG_DEBUG("Mapped new {} in state {}",
|
| 54 |
+
vb->getId(),
|
| 55 |
+
VBucket::toString(vb->getState()));
|
| 56 |
+
return ENGINE_SUCCESS;
|
| 57 |
+
}
|
| 58 |
+
EP_LOG_WARN("Cannot create {}, max vbuckets is {}", vb->getId(), size);
|
| 59 |
+
return ENGINE_ERANGE;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
void VBucketMap::enablePersistence(EPBucket& ep) {
|
| 63 |
+
for (auto& shard : shards) {
|
| 64 |
+
shard->enablePersistence(ep);
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
void VBucketMap::dropVBucketAndSetupDeferredDeletion(Vbid id,
|
| 69 |
+
const void* cookie) {
|
| 70 |
+
if (id.get() < size) {
|
| 71 |
+
getShardByVbId(id)->dropVBucketAndSetupDeferredDeletion(id, cookie);
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
std::vector<Vbid> VBucketMap::getBuckets() const {
|
| 76 |
+
std::vector<Vbid> rv;
|
| 77 |
+
for (size_t i = 0; i < size; ++i) {
|
| 78 |
+
VBucketPtr b(getBucket(Vbid(i)));
|
| 79 |
+
if (b) {
|
| 80 |
+
rv.push_back(b->getId());
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
return rv;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
std::vector<Vbid> VBucketMap::getBucketsSortedByState() const {
|
| 87 |
+
std::vector<Vbid> rv;
|
| 88 |
+
for (int state = vbucket_state_active;
|
| 89 |
+
state <= vbucket_state_dead; ++state) {
|
| 90 |
+
for (size_t i = 0; i < size; ++i) {
|
| 91 |
+
VBucketPtr b = getBucket(Vbid(i));
|
| 92 |
+
if (b && b->getState() == state) {
|
| 93 |
+
rv.push_back(b->getId());
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
return rv;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
std::vector<Vbid> VBucketMap::getBucketsInState(vbucket_state_t state) const {
|
| 101 |
+
std::vector<Vbid> rv;
|
| 102 |
+
for (size_t i = 0; i < size; ++i) {
|
| 103 |
+
VBucketPtr b = getBucket(Vbid(i));
|
| 104 |
+
if (b && b->getState() == state) {
|
| 105 |
+
rv.push_back(b->getId());
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
return rv;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
std::vector<std::pair<Vbid, size_t>> VBucketMap::getVBucketsSortedByChkMgrMem() const {
|
| 112 |
+
std::vector<std::pair<Vbid, size_t>> rv;
|
| 113 |
+
for (size_t i = 0; i < size; ++i) {
|
| 114 |
+
VBucketPtr b = getBucket(Vbid(i));
|
| 115 |
+
if (b) {
|
| 116 |
+
rv.push_back(std::make_pair(b->getId(), b->getChkMgrMemUsage()));
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
struct SortCtx {
|
| 121 |
+
static bool compareSecond(std::pair<Vbid, size_t> a,
|
| 122 |
+
std::pair<Vbid, size_t> b) {
|
| 123 |
+
return (a.second < b.second);
|
| 124 |
+
}
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
std::sort(rv.begin(), rv.end(), SortCtx::compareSecond);
|
| 128 |
+
|
| 129 |
+
return rv;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
size_t VBucketMap::getVBucketsTotalCheckpointMemoryUsage() const {
|
| 133 |
+
size_t checkpointMemoryUsage = 0;
|
| 134 |
+
for (size_t i = 0; i < size; ++i) {
|
| 135 |
+
VBucketPtr b = getBucket(Vbid(i));
|
| 136 |
+
if (b) {
|
| 137 |
+
checkpointMemoryUsage += b->getChkMgrMemUsage();
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
return checkpointMemoryUsage;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
KVShard* VBucketMap::getShardByVbId(Vbid id) const {
|
| 144 |
+
return shards[id.get() % shards.size()].get();
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
KVShard* VBucketMap::getShard(KVShard::id_type shardId) const {
|
| 148 |
+
return shards[shardId].get();
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
size_t VBucketMap::getNumShards() const {
|
| 152 |
+
return shards.size();
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
void VBucketMap::setHLCDriftAheadThreshold(std::chrono::microseconds threshold) {
|
| 156 |
+
for (size_t id = 0; id < size; id++) {
|
| 157 |
+
auto vb = getBucket(Vbid(id));
|
| 158 |
+
if (vb) {
|
| 159 |
+
vb->setHLCDriftAheadThreshold(threshold);
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
void VBucketMap::setHLCDriftBehindThreshold(std::chrono::microseconds threshold) {
|
| 165 |
+
for (size_t id = 0; id < size; id++) {
|
| 166 |
+
auto vb = getBucket(Vbid(id));
|
| 167 |
+
if (vb) {
|
| 168 |
+
vb->setHLCDriftBehindThreshold(threshold);
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
void VBucketMap::VBucketConfigChangeListener::sizeValueChanged(const std::string &key,
|
| 174 |
+
size_t value) {
|
| 175 |
+
if (key == "hlc_drift_ahead_threshold_us") {
|
| 176 |
+
map.setHLCDriftAheadThreshold(std::chrono::microseconds(value));
|
| 177 |
+
} else if (key == "hlc_drift_behind_threshold_us") {
|
| 178 |
+
map.setHLCDriftBehindThreshold(std::chrono::microseconds(value));
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
vbucket_state_t VBucketMap::setState(VBucket& vb,
|
| 183 |
+
vbucket_state_t newState,
|
| 184 |
+
const nlohmann::json* meta) {
|
| 185 |
+
folly::SharedMutex::WriteHolder vbStateLock(vb.getStateLock());
|
| 186 |
+
return setState_UNLOCKED(vb, newState, meta, vbStateLock);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
vbucket_state_t VBucketMap::setState_UNLOCKED(
|
| 190 |
+
VBucket& vb,
|
| 191 |
+
vbucket_state_t newState,
|
| 192 |
+
const nlohmann::json* meta,
|
| 193 |
+
folly::SharedMutex::WriteHolder& vbStateLock) {
|
| 194 |
+
vbucket_state_t oldState = vb.getState();
|
| 195 |
+
vb.setState_UNLOCKED(newState, meta, vbStateLock);
|
| 196 |
+
|
| 197 |
+
decVBStateCount(oldState);
|
| 198 |
+
incVBStateCount(newState);
|
| 199 |
+
|
| 200 |
+
return oldState;
|
| 201 |
+
}
|
pool/shard009/C++/0106949_qaudiopluginloader.cpp
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/****************************************************************************
|
| 2 |
+
**
|
| 3 |
+
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
| 4 |
+
** All rights reserved.
|
| 5 |
+
** Contact: Nokia Corporation (qt-info@nokia.com)
|
| 6 |
+
**
|
| 7 |
+
** This file is part of the Qt Mobility Components.
|
| 8 |
+
**
|
| 9 |
+
** $QT_BEGIN_LICENSE:LGPL$
|
| 10 |
+
** Commercial Usage
|
| 11 |
+
** Licensees holding valid Qt Commercial licenses may use this file in
|
| 12 |
+
** accordance with the Qt Commercial License Agreement provided with
|
| 13 |
+
** the Software or, alternatively, in accordance with the terms
|
| 14 |
+
** contained in a written agreement between you and Nokia.
|
| 15 |
+
**
|
| 16 |
+
** GNU Lesser General Public License Usage
|
| 17 |
+
** Alternatively, this file may be used under the terms of the GNU Lesser
|
| 18 |
+
** General Public License version 2.1 as published by the Free Software
|
| 19 |
+
** Foundation and appearing in the file LICENSE.LGPL included in the
|
| 20 |
+
** packaging of this file. Please review the following information to
|
| 21 |
+
** ensure the GNU Lesser General Public License version 2.1 requirements
|
| 22 |
+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
| 23 |
+
**
|
| 24 |
+
** In addition, as a special exception, Nokia gives you certain additional
|
| 25 |
+
** rights. These rights are described in the Nokia Qt LGPL Exception
|
| 26 |
+
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
| 27 |
+
**
|
| 28 |
+
** GNU General Public License Usage
|
| 29 |
+
** Alternatively, this file may be used under the terms of the GNU
|
| 30 |
+
** General Public License version 3.0 as published by the Free Software
|
| 31 |
+
** Foundation and appearing in the file LICENSE.GPL included in the
|
| 32 |
+
** packaging of this file. Please review the following information to
|
| 33 |
+
** ensure the GNU General Public License version 3.0 requirements will be
|
| 34 |
+
** met: http://www.gnu.org/copyleft/gpl.html.
|
| 35 |
+
**
|
| 36 |
+
** If you are unsure which license is appropriate for your use, please
|
| 37 |
+
** contact the sales department at qt-sales@nokia.com.
|
| 38 |
+
** $QT_END_LICENSE$
|
| 39 |
+
**
|
| 40 |
+
****************************************************************************/
|
| 41 |
+
|
| 42 |
+
#include "qaudiosystemplugin.h"
|
| 43 |
+
#include "qaudiopluginloader_p.h"
|
| 44 |
+
|
| 45 |
+
#include <QtCore/qcoreapplication.h>
|
| 46 |
+
#include <QtGui/qapplication.h>
|
| 47 |
+
#include <QtCore/qpluginloader.h>
|
| 48 |
+
#include <QtCore/qfactoryinterface.h>
|
| 49 |
+
#include <QtCore/qdir.h>
|
| 50 |
+
#include <QtCore/qdebug.h>
|
| 51 |
+
|
| 52 |
+
QT_BEGIN_NAMESPACE
|
| 53 |
+
|
| 54 |
+
QAudioPluginLoader::QAudioPluginLoader(const char *iid, const QString &location, Qt::CaseSensitivity):
|
| 55 |
+
m_iid(iid)
|
| 56 |
+
{
|
| 57 |
+
m_location = location + "/";
|
| 58 |
+
load();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
QAudioPluginLoader::~QAudioPluginLoader()
|
| 62 |
+
{
|
| 63 |
+
for (int i = 0; i < m_plugins.count(); i++ ) {
|
| 64 |
+
delete m_plugins.at(i);
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
QStringList QAudioPluginLoader::pluginList() const
|
| 69 |
+
{
|
| 70 |
+
#if !defined QT_NO_DEBUG
|
| 71 |
+
const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0;
|
| 72 |
+
#endif
|
| 73 |
+
|
| 74 |
+
QStringList paths = QApplication::libraryPaths();
|
| 75 |
+
#ifdef QTM_PLUGIN_PATH
|
| 76 |
+
paths << QLatin1String(QTM_PLUGIN_PATH);
|
| 77 |
+
#endif
|
| 78 |
+
#if !defined QT_NO_DEBUG
|
| 79 |
+
if (showDebug)
|
| 80 |
+
qDebug() << "Plugin paths:" << paths;
|
| 81 |
+
#endif
|
| 82 |
+
|
| 83 |
+
//temp variable to avoid multiple identic path
|
| 84 |
+
QSet<QString> processed;
|
| 85 |
+
|
| 86 |
+
/* Discover a bunch o plugins */
|
| 87 |
+
QStringList plugins;
|
| 88 |
+
|
| 89 |
+
/* Enumerate our plugin paths */
|
| 90 |
+
for (int i=0; i < paths.count(); i++) {
|
| 91 |
+
if (processed.contains(paths.at(i)))
|
| 92 |
+
continue;
|
| 93 |
+
processed.insert(paths.at(i));
|
| 94 |
+
QDir pluginsDir(paths.at(i)+m_location);
|
| 95 |
+
if (!pluginsDir.exists())
|
| 96 |
+
continue;
|
| 97 |
+
|
| 98 |
+
QStringList files = pluginsDir.entryList(QDir::Files);
|
| 99 |
+
#if !defined QT_NO_DEBUG
|
| 100 |
+
if (showDebug)
|
| 101 |
+
qDebug()<<"Looking for plugins in "<<pluginsDir.path()<<files;
|
| 102 |
+
#endif
|
| 103 |
+
for (int j=0; j < files.count(); j++) {
|
| 104 |
+
const QString &file = files.at(j);
|
| 105 |
+
#if defined(Q_WS_MAEMO_5)
|
| 106 |
+
if (!file.contains(QLatin1String("n900audio")))
|
| 107 |
+
#endif
|
| 108 |
+
plugins << pluginsDir.absoluteFilePath(file);
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
return plugins;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
QStringList QAudioPluginLoader::keys() const
|
| 115 |
+
{
|
| 116 |
+
QMutexLocker locker(const_cast<QMutex *>(&m_mutex));
|
| 117 |
+
|
| 118 |
+
QStringList list;
|
| 119 |
+
for (int i = 0; i < m_plugins.count(); i++) {
|
| 120 |
+
QAudioSystemPlugin* p = qobject_cast<QAudioSystemPlugin*>(m_plugins.at(i)->instance());
|
| 121 |
+
if (p) list << p->keys();
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
return list;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
QObject* QAudioPluginLoader::instance(QString const &key)
|
| 128 |
+
{
|
| 129 |
+
QMutexLocker locker(&m_mutex);
|
| 130 |
+
|
| 131 |
+
for (int i = 0; i < m_plugins.count(); i++) {
|
| 132 |
+
QAudioSystemPlugin* p = qobject_cast<QAudioSystemPlugin*>(m_plugins.at(i)->instance());
|
| 133 |
+
if (p && p->keys().contains(key))
|
| 134 |
+
return m_plugins.at(i)->instance();
|
| 135 |
+
}
|
| 136 |
+
return 0;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
QList<QObject*> QAudioPluginLoader::instances(QString const &key)
|
| 140 |
+
{
|
| 141 |
+
QMutexLocker locker(&m_mutex);
|
| 142 |
+
|
| 143 |
+
QList<QObject*> list;
|
| 144 |
+
for (int i = 0; i < m_plugins.count(); i++) {
|
| 145 |
+
QAudioSystemPlugin* p = qobject_cast<QAudioSystemPlugin*>(m_plugins.at(i)->instance());
|
| 146 |
+
if (p && p->keys().contains(key))
|
| 147 |
+
list << m_plugins.at(i)->instance();
|
| 148 |
+
}
|
| 149 |
+
return list;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
void QAudioPluginLoader::load()
|
| 153 |
+
{
|
| 154 |
+
if (!m_plugins.isEmpty())
|
| 155 |
+
return;
|
| 156 |
+
|
| 157 |
+
QStringList plugins = pluginList();
|
| 158 |
+
for (int i=0; i < plugins.count(); i++) {
|
| 159 |
+
QPluginLoader* loader = new QPluginLoader(plugins.at(i));
|
| 160 |
+
QObject *o = loader->instance();
|
| 161 |
+
if (o != 0 && o->qt_metacast(m_iid) != 0)
|
| 162 |
+
m_plugins.append(loader);
|
| 163 |
+
else {
|
| 164 |
+
qWarning() << "QAudioPluginLoader: Failed to load plugin: "
|
| 165 |
+
<< plugins.at(i) << loader->errorString();
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
QT_END_NAMESPACE
|
| 170 |
+
|
pool/shard009/C++/0106950_RPLidarTest.cpp
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <eeros/logger/Logger.hpp>
|
| 2 |
+
#include <eeros/safety/SafetySystem.hpp>
|
| 3 |
+
#include <eeros/control/TimeDomain.hpp>
|
| 4 |
+
#include <eeros/task/Periodic.hpp>
|
| 5 |
+
#include <eeros/core/Executor.hpp>
|
| 6 |
+
#include <eeros/task/Lambda.hpp>
|
| 7 |
+
#include <eeros/control/sensor/RPLidarInput.hpp>
|
| 8 |
+
|
| 9 |
+
using namespace eeros;
|
| 10 |
+
using namespace eeros::safety;
|
| 11 |
+
using namespace eeros::control;
|
| 12 |
+
using namespace eeros::logger;
|
| 13 |
+
using namespace eeros::task;
|
| 14 |
+
|
| 15 |
+
double period = 0.01;
|
| 16 |
+
|
| 17 |
+
void signalHandler(int signum){
|
| 18 |
+
SafetySystem::exitHandler();
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
class ControlSystem {
|
| 22 |
+
public:
|
| 23 |
+
ControlSystem() : lidar("/dev/ttyUSB1"), td("td", period, true) {
|
| 24 |
+
td.addBlock(lidar);
|
| 25 |
+
}
|
| 26 |
+
RPLidarInput lidar;
|
| 27 |
+
TimeDomain td;
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
class PPSafetyProperties : public SafetyProperties {
|
| 31 |
+
public:
|
| 32 |
+
PPSafetyProperties() : slState1("state 1") {
|
| 33 |
+
addLevel(slState1);
|
| 34 |
+
setEntryLevel(slState1);
|
| 35 |
+
};
|
| 36 |
+
SafetyLevel slState1;
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
int main() {
|
| 40 |
+
Logger::setDefaultStreamLogger(std::cout);
|
| 41 |
+
Logger log = Logger::getLogger();
|
| 42 |
+
log.info() << "Program started - Read out RP Lidar sensors data";
|
| 43 |
+
|
| 44 |
+
ControlSystem cs;
|
| 45 |
+
Periodic p1("p1", period, cs.td);
|
| 46 |
+
PPSafetyProperties sp;
|
| 47 |
+
SafetySystem ss(sp, period);
|
| 48 |
+
|
| 49 |
+
// create periodic function for logging
|
| 50 |
+
Lambda l1 ([&] () { });
|
| 51 |
+
Periodic p2("p2", period, l1);
|
| 52 |
+
p2.monitors.push_back([&](PeriodicCounter &pc, Logger &log) {
|
| 53 |
+
log.info() << cs.lidar.getOut(0).getSignal().getValue() << ", "
|
| 54 |
+
<< cs.lidar.getOut(1).getSignal().getValue();
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
auto& executor = Executor::instance();
|
| 58 |
+
executor.setMainTask(ss);
|
| 59 |
+
p1.after.push_back(p2); // make sure that logging happens after running of path planner
|
| 60 |
+
executor.add(p1);
|
| 61 |
+
executor.run();
|
| 62 |
+
|
| 63 |
+
log.info() << "Program finished...";
|
| 64 |
+
return 0;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
pool/shard009/C++/0106952_tst_preferenciastest.cpp
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <QString>
|
| 2 |
+
#include <QtTest>
|
| 3 |
+
#include <QCoreApplication>
|
| 4 |
+
|
| 5 |
+
#include "preferencias.h"
|
| 6 |
+
#include "formprefdb.h"
|
| 7 |
+
|
| 8 |
+
class PreferenciasTest : public QObject
|
| 9 |
+
{
|
| 10 |
+
Q_OBJECT
|
| 11 |
+
|
| 12 |
+
private Q_SLOTS:
|
| 13 |
+
void initTestCase();
|
| 14 |
+
void cleanupTestCase();
|
| 15 |
+
void testGuardarPreferencias();
|
| 16 |
+
|
| 17 |
+
private:
|
| 18 |
+
preferencias *p;
|
| 19 |
+
FormPrefDb *form;
|
| 20 |
+
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
void PreferenciasTest::initTestCase()
|
| 24 |
+
{
|
| 25 |
+
p = preferencias::getInstancia();
|
| 26 |
+
form = new FormPrefDb();
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
void PreferenciasTest::cleanupTestCase()
|
| 30 |
+
{
|
| 31 |
+
p=0;
|
| 32 |
+
delete form;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
void PreferenciasTest::testGuardarPreferencias()
|
| 36 |
+
{
|
| 37 |
+
form->cargar();
|
| 38 |
+
form->CkBPuerto->setChecked( false );
|
| 39 |
+
form->guardar();
|
| 40 |
+
p->inicio();
|
| 41 |
+
p->beginGroup( "Preferencias" );
|
| 42 |
+
p->beginGroup( "General" );
|
| 43 |
+
p->beginGroup( "mysql" );
|
| 44 |
+
QCOMPARE( false, p->contains( "puerto" ) );
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
QTEST_MAIN(PreferenciasTest)
|
| 48 |
+
|
| 49 |
+
#include "tst_preferenciastest.moc"
|
| 50 |
+
|
pool/shard009/C++/0106953_MSP430RegisterInfo.cpp
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===-- MSP430RegisterInfo.cpp - MSP430 Register Information --------------===//
|
| 2 |
+
//
|
| 3 |
+
// The LLVM Compiler Infrastructure
|
| 4 |
+
//
|
| 5 |
+
// This file is distributed under the University of Illinois Open Source
|
| 6 |
+
// License. See LICENSE.TXT for details.
|
| 7 |
+
//
|
| 8 |
+
//===----------------------------------------------------------------------===//
|
| 9 |
+
//
|
| 10 |
+
// This file contains the MSP430 implementation of the TargetRegisterInfo class.
|
| 11 |
+
//
|
| 12 |
+
//===----------------------------------------------------------------------===//
|
| 13 |
+
|
| 14 |
+
#include "MSP430RegisterInfo.h"
|
| 15 |
+
#include "MSP430.h"
|
| 16 |
+
#include "MSP430MachineFunctionInfo.h"
|
| 17 |
+
#include "MSP430TargetMachine.h"
|
| 18 |
+
#include "llvm/ADT/BitVector.h"
|
| 19 |
+
#include "llvm/CodeGen/MachineFrameInfo.h"
|
| 20 |
+
#include "llvm/CodeGen/MachineFunction.h"
|
| 21 |
+
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
| 22 |
+
#include "llvm/IR/Function.h"
|
| 23 |
+
#include "llvm/Support/ErrorHandling.h"
|
| 24 |
+
#include "llvm/Target/TargetMachine.h"
|
| 25 |
+
#include "llvm/Target/TargetOptions.h"
|
| 26 |
+
|
| 27 |
+
using namespace llvm;
|
| 28 |
+
|
| 29 |
+
#define DEBUG_TYPE "msp430-reg-info"
|
| 30 |
+
|
| 31 |
+
#define GET_REGINFO_TARGET_DESC
|
| 32 |
+
#include "MSP430GenRegisterInfo.inc"
|
| 33 |
+
|
| 34 |
+
// FIXME: Provide proper call frame setup / destroy opcodes.
|
| 35 |
+
MSP430RegisterInfo::MSP430RegisterInfo()
|
| 36 |
+
: MSP430GenRegisterInfo(MSP430::PC) {}
|
| 37 |
+
|
| 38 |
+
const MCPhysReg*
|
| 39 |
+
MSP430RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
|
| 40 |
+
const TargetFrameLowering *TFI = MF->getSubtarget().getFrameLowering();
|
| 41 |
+
const Function* F = MF->getFunction();
|
| 42 |
+
static const MCPhysReg CalleeSavedRegs[] = {
|
| 43 |
+
MSP430::FP, MSP430::R5, MSP430::R6, MSP430::R7,
|
| 44 |
+
MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11,
|
| 45 |
+
0
|
| 46 |
+
};
|
| 47 |
+
static const MCPhysReg CalleeSavedRegsFP[] = {
|
| 48 |
+
MSP430::R5, MSP430::R6, MSP430::R7,
|
| 49 |
+
MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11,
|
| 50 |
+
0
|
| 51 |
+
};
|
| 52 |
+
static const MCPhysReg CalleeSavedRegsIntr[] = {
|
| 53 |
+
MSP430::FP, MSP430::R5, MSP430::R6, MSP430::R7,
|
| 54 |
+
MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11,
|
| 55 |
+
MSP430::R12, MSP430::R13, MSP430::R14, MSP430::R15,
|
| 56 |
+
0
|
| 57 |
+
};
|
| 58 |
+
static const MCPhysReg CalleeSavedRegsIntrFP[] = {
|
| 59 |
+
MSP430::R5, MSP430::R6, MSP430::R7,
|
| 60 |
+
MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11,
|
| 61 |
+
MSP430::R12, MSP430::R13, MSP430::R14, MSP430::R15,
|
| 62 |
+
0
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
if (TFI->hasFP(*MF))
|
| 66 |
+
return (F->getCallingConv() == CallingConv::MSP430_INTR ?
|
| 67 |
+
CalleeSavedRegsIntrFP : CalleeSavedRegsFP);
|
| 68 |
+
else
|
| 69 |
+
return (F->getCallingConv() == CallingConv::MSP430_INTR ?
|
| 70 |
+
CalleeSavedRegsIntr : CalleeSavedRegs);
|
| 71 |
+
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
BitVector MSP430RegisterInfo::getReservedRegs(const MachineFunction &MF) const {
|
| 75 |
+
BitVector Reserved(getNumRegs());
|
| 76 |
+
const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
|
| 77 |
+
|
| 78 |
+
// Mark 4 special registers with subregisters as reserved.
|
| 79 |
+
Reserved.set(MSP430::PCB);
|
| 80 |
+
Reserved.set(MSP430::SPB);
|
| 81 |
+
Reserved.set(MSP430::SRB);
|
| 82 |
+
Reserved.set(MSP430::CGB);
|
| 83 |
+
Reserved.set(MSP430::PC);
|
| 84 |
+
Reserved.set(MSP430::SP);
|
| 85 |
+
Reserved.set(MSP430::SR);
|
| 86 |
+
Reserved.set(MSP430::CG);
|
| 87 |
+
|
| 88 |
+
// Mark frame pointer as reserved if needed.
|
| 89 |
+
if (TFI->hasFP(MF)) {
|
| 90 |
+
Reserved.set(MSP430::FPB);
|
| 91 |
+
Reserved.set(MSP430::FP);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
return Reserved;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
const TargetRegisterClass *
|
| 98 |
+
MSP430RegisterInfo::getPointerRegClass(const MachineFunction &MF, unsigned Kind)
|
| 99 |
+
const {
|
| 100 |
+
return &MSP430::GR16RegClass;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
void
|
| 104 |
+
MSP430RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
|
| 105 |
+
int SPAdj, unsigned FIOperandNum,
|
| 106 |
+
RegScavenger *RS) const {
|
| 107 |
+
assert(SPAdj == 0 && "Unexpected");
|
| 108 |
+
|
| 109 |
+
MachineInstr &MI = *II;
|
| 110 |
+
MachineBasicBlock &MBB = *MI.getParent();
|
| 111 |
+
MachineFunction &MF = *MBB.getParent();
|
| 112 |
+
const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
|
| 113 |
+
DebugLoc dl = MI.getDebugLoc();
|
| 114 |
+
int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
|
| 115 |
+
|
| 116 |
+
unsigned BasePtr = (TFI->hasFP(MF) ? MSP430::FP : MSP430::SP);
|
| 117 |
+
int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex);
|
| 118 |
+
|
| 119 |
+
// Skip the saved PC
|
| 120 |
+
Offset += 2;
|
| 121 |
+
|
| 122 |
+
if (!TFI->hasFP(MF))
|
| 123 |
+
Offset += MF.getFrameInfo()->getStackSize();
|
| 124 |
+
else
|
| 125 |
+
Offset += 2; // Skip the saved FP
|
| 126 |
+
|
| 127 |
+
// Fold imm into offset
|
| 128 |
+
Offset += MI.getOperand(FIOperandNum + 1).getImm();
|
| 129 |
+
|
| 130 |
+
if (MI.getOpcode() == MSP430::ADD16ri) {
|
| 131 |
+
// This is actually "load effective address" of the stack slot
|
| 132 |
+
// instruction. We have only two-address instructions, thus we need to
|
| 133 |
+
// expand it into mov + add
|
| 134 |
+
const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
|
| 135 |
+
|
| 136 |
+
MI.setDesc(TII.get(MSP430::MOV16rr));
|
| 137 |
+
MI.getOperand(FIOperandNum).ChangeToRegister(BasePtr, false);
|
| 138 |
+
|
| 139 |
+
if (Offset == 0)
|
| 140 |
+
return;
|
| 141 |
+
|
| 142 |
+
// We need to materialize the offset via add instruction.
|
| 143 |
+
unsigned DstReg = MI.getOperand(0).getReg();
|
| 144 |
+
if (Offset < 0)
|
| 145 |
+
BuildMI(MBB, std::next(II), dl, TII.get(MSP430::SUB16ri), DstReg)
|
| 146 |
+
.addReg(DstReg).addImm(-Offset);
|
| 147 |
+
else
|
| 148 |
+
BuildMI(MBB, std::next(II), dl, TII.get(MSP430::ADD16ri), DstReg)
|
| 149 |
+
.addReg(DstReg).addImm(Offset);
|
| 150 |
+
|
| 151 |
+
return;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
MI.getOperand(FIOperandNum).ChangeToRegister(BasePtr, false);
|
| 155 |
+
MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
unsigned MSP430RegisterInfo::getFrameRegister(const MachineFunction &MF) const {
|
| 159 |
+
const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
|
| 160 |
+
|
| 161 |
+
return TFI->hasFP(MF) ? MSP430::FP : MSP430::SP;
|
| 162 |
+
}
|
pool/shard009/C++/0106956_helpers.cpp
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#include "builtin/object.hpp"
|
| 3 |
+
#include "call_frame.hpp"
|
| 4 |
+
#include "builtin/autoload.hpp"
|
| 5 |
+
#include "builtin/symbol.hpp"
|
| 6 |
+
#include "builtin/module.hpp"
|
| 7 |
+
#include "builtin/compiledmethod.hpp"
|
| 8 |
+
#include "builtin/class.hpp"
|
| 9 |
+
#include "builtin/staticscope.hpp"
|
| 10 |
+
#include "builtin/lookuptable.hpp"
|
| 11 |
+
#include "global_cache.hpp"
|
| 12 |
+
#include "objectmemory.hpp"
|
| 13 |
+
#include "builtin/tuple.hpp"
|
| 14 |
+
#include "builtin/system.hpp"
|
| 15 |
+
#include "builtin/thread.hpp"
|
| 16 |
+
#include "builtin/channel.hpp"
|
| 17 |
+
#include "builtin/global_cache_entry.hpp"
|
| 18 |
+
#include "builtin/methodtable.hpp"
|
| 19 |
+
#include "builtin/location.hpp"
|
| 20 |
+
|
| 21 |
+
#include "vm.hpp"
|
| 22 |
+
#include "object_utils.hpp"
|
| 23 |
+
#include "arguments.hpp"
|
| 24 |
+
#include "call_frame.hpp"
|
| 25 |
+
#include "lookup_data.hpp"
|
| 26 |
+
|
| 27 |
+
#include "on_stack.hpp"
|
| 28 |
+
|
| 29 |
+
#include "helpers.hpp"
|
| 30 |
+
|
| 31 |
+
namespace rubinius {
|
| 32 |
+
namespace Helpers {
|
| 33 |
+
Object* const_get_under(STATE, Module* mod, Symbol* name, bool* found) {
|
| 34 |
+
Object* res;
|
| 35 |
+
|
| 36 |
+
*found = false;
|
| 37 |
+
|
| 38 |
+
while(!mod->nil_p()) {
|
| 39 |
+
res = mod->get_const(state, name, found);
|
| 40 |
+
if(*found) return res;
|
| 41 |
+
|
| 42 |
+
// Don't stop when you see Object, because we need to check any
|
| 43 |
+
// includes into Object as well, and they're found via superclass
|
| 44 |
+
mod = mod->superclass();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
return cNil;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
Object* const_get(STATE, CallFrame* call_frame, Symbol* name, bool* found) {
|
| 51 |
+
StaticScope *cur;
|
| 52 |
+
Object* result;
|
| 53 |
+
|
| 54 |
+
*found = false;
|
| 55 |
+
|
| 56 |
+
call_frame = call_frame->top_ruby_frame();
|
| 57 |
+
|
| 58 |
+
// Ok, this has to be explained or it will be considered black magic.
|
| 59 |
+
// The scope chain always ends with an entry at the top that contains
|
| 60 |
+
// a parent of nil, and a module of Object. This entry is put in
|
| 61 |
+
// regardless of lexical scoping, it's the default scope.
|
| 62 |
+
//
|
| 63 |
+
// When looking up a constant, we don't want to consider the default
|
| 64 |
+
// scope (ie, Object) initially because we need to lookup up
|
| 65 |
+
// the superclass chain first, because falling back on the default.
|
| 66 |
+
//
|
| 67 |
+
// The rub comes from the fact that if a user explicitly opens up
|
| 68 |
+
// Object in their code, we DO consider it. Like:
|
| 69 |
+
//
|
| 70 |
+
// class Idiot
|
| 71 |
+
// A = 2
|
| 72 |
+
// end
|
| 73 |
+
//
|
| 74 |
+
// class ::Object
|
| 75 |
+
// A = 1
|
| 76 |
+
// class Stupid < Idiot
|
| 77 |
+
// def foo
|
| 78 |
+
// p A
|
| 79 |
+
// end
|
| 80 |
+
// end
|
| 81 |
+
// end
|
| 82 |
+
//
|
| 83 |
+
// In this code, when A is looked up, Object must be considering during
|
| 84 |
+
// the scope walk, NOT during the superclass walk.
|
| 85 |
+
//
|
| 86 |
+
// So, in this case, foo would print "1", not "2".
|
| 87 |
+
//
|
| 88 |
+
cur = call_frame->static_scope();
|
| 89 |
+
while(!cur->nil_p()) {
|
| 90 |
+
// Detect the toplevel scope (the default) and get outta dodge.
|
| 91 |
+
if(cur->top_level_p(state)) break;
|
| 92 |
+
|
| 93 |
+
result = cur->module()->get_const(state, name, found);
|
| 94 |
+
if(*found) return result;
|
| 95 |
+
|
| 96 |
+
cur = cur->parent();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
// Now look up the superclass chain.
|
| 100 |
+
cur = call_frame->static_scope();
|
| 101 |
+
if(!cur->nil_p()) {
|
| 102 |
+
Module* mod = cur->module();
|
| 103 |
+
while(!mod->nil_p()) {
|
| 104 |
+
result = mod->get_const(state, name, found);
|
| 105 |
+
if(*found) return result;
|
| 106 |
+
|
| 107 |
+
mod = mod->superclass();
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
// Lastly, check Object specifically
|
| 112 |
+
result = G(object)->get_const(state, name, found, true);
|
| 113 |
+
if(*found) return result;
|
| 114 |
+
|
| 115 |
+
return cNil;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
Object* const_missing_under(STATE, Module* under, Symbol* sym, CallFrame* call_frame) {
|
| 119 |
+
Array* args = Array::create(state, 1);
|
| 120 |
+
args->set(state, 0, sym);
|
| 121 |
+
return under->send(state, call_frame, G(sym_const_missing), args);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
Object* const_missing(STATE, Symbol* sym, CallFrame* call_frame) {
|
| 125 |
+
Module* under;
|
| 126 |
+
|
| 127 |
+
call_frame = call_frame->top_ruby_frame();
|
| 128 |
+
|
| 129 |
+
StaticScope* scope = call_frame->static_scope();
|
| 130 |
+
if(scope->nil_p()) {
|
| 131 |
+
under = G(object);
|
| 132 |
+
} else {
|
| 133 |
+
under = scope->module();
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
Array* args = Array::create(state, 1);
|
| 137 |
+
args->set(state, 0, sym);
|
| 138 |
+
return under->send(state, call_frame, G(sym_const_missing), args);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/** @todo Remove redundancy between this and sends. --rue */
|
| 142 |
+
Tuple* locate_method_on(STATE, CallFrame* call_frame, Object* recv, Symbol* name, Object* priv) {
|
| 143 |
+
LookupData lookup(recv, recv->lookup_begin(state), CBOOL(priv) ? G(sym_private) : G(sym_protected));
|
| 144 |
+
Dispatch dis(name);
|
| 145 |
+
|
| 146 |
+
if(!GlobalCache::resolve(state, dis.name, dis, lookup)) {
|
| 147 |
+
return nil<Tuple>();
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
return Tuple::from(state, 2, dis.method, dis.module);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
Class* open_class(STATE, CallFrame* call_frame, Object* super, Symbol* name, bool* created) {
|
| 154 |
+
Module* under;
|
| 155 |
+
|
| 156 |
+
call_frame = call_frame->top_ruby_frame();
|
| 157 |
+
|
| 158 |
+
if(call_frame->static_scope()->nil_p()) {
|
| 159 |
+
under = G(object);
|
| 160 |
+
} else {
|
| 161 |
+
under = call_frame->static_scope()->module();
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
return open_class(state, call_frame, under, super, name, created);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
static Class* add_class(STATE, Module* under, Object* super, Symbol* name) {
|
| 168 |
+
if(super->nil_p()) super = G(object);
|
| 169 |
+
Class* cls = Class::create(state, as<Class>(super));
|
| 170 |
+
|
| 171 |
+
cls->set_name(state, name, under);
|
| 172 |
+
under->set_const(state, name, cls);
|
| 173 |
+
|
| 174 |
+
return cls;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
static Class* check_superclass(STATE, CallFrame* call_frame, Class* cls, Object* super) {
|
| 178 |
+
if(super->nil_p()) return cls;
|
| 179 |
+
if(cls->true_superclass(state) != super) {
|
| 180 |
+
std::ostringstream message;
|
| 181 |
+
message << "Superclass mismatch: given "
|
| 182 |
+
<< as<Module>(super)->debug_str(state)
|
| 183 |
+
<< " but previously set to "
|
| 184 |
+
<< cls->true_superclass(state)->debug_str(state);
|
| 185 |
+
Exception* exc =
|
| 186 |
+
Exception::make_type_error(state, Class::type, super, message.str().c_str());
|
| 187 |
+
exc->locations(state, Location::from_call_stack(state, call_frame));
|
| 188 |
+
state->raise_exception(exc);
|
| 189 |
+
return NULL;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
return cls;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
Class* open_class(STATE, CallFrame* call_frame, Module* under, Object* super, Symbol* name, bool* created) {
|
| 196 |
+
bool found;
|
| 197 |
+
|
| 198 |
+
*created = false;
|
| 199 |
+
|
| 200 |
+
Object* obj = under->get_const(state, name, &found);
|
| 201 |
+
if(found) {
|
| 202 |
+
TypedRoot<Object*> sup(state, super);
|
| 203 |
+
|
| 204 |
+
if(Autoload* autoload = try_as<Autoload>(obj)) {
|
| 205 |
+
obj = autoload->resolve(state, call_frame, true);
|
| 206 |
+
|
| 207 |
+
// Check if an exception occurred
|
| 208 |
+
if(!obj) return NULL;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
// Autoload::resolve will return nil if code loading failed, in which
|
| 212 |
+
// case we ignore the autoload.
|
| 213 |
+
if(!obj->nil_p()) {
|
| 214 |
+
return check_superclass(state, call_frame, as<Class>(obj), sup.get());
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
*created = true;
|
| 219 |
+
return add_class(state, under, super, name);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
Module* open_module(STATE, CallFrame* call_frame, Symbol* name) {
|
| 223 |
+
Module* under = G(object);
|
| 224 |
+
|
| 225 |
+
call_frame = call_frame->top_ruby_frame();
|
| 226 |
+
|
| 227 |
+
if(!call_frame->static_scope()->nil_p()) {
|
| 228 |
+
under = call_frame->static_scope()->module();
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
return open_module(state, call_frame, under, name);
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
Module* open_module(STATE, CallFrame* call_frame, Module* under, Symbol* name) {
|
| 235 |
+
Module* module;
|
| 236 |
+
bool found;
|
| 237 |
+
|
| 238 |
+
Object* obj = under->get_const(state, name, &found);
|
| 239 |
+
|
| 240 |
+
if(found) {
|
| 241 |
+
if(Autoload* autoload = try_as<Autoload>(obj)) {
|
| 242 |
+
obj = autoload->resolve(state, call_frame, true);
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
// Check if an exception occurred
|
| 246 |
+
if(!obj) return NULL;
|
| 247 |
+
|
| 248 |
+
// Autoload::resolve will return nil if code loading failed, in which
|
| 249 |
+
// case we ignore the autoload.
|
| 250 |
+
if(!obj->nil_p()) {
|
| 251 |
+
return as<Module>(obj);
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
module = Module::create(state);
|
| 256 |
+
|
| 257 |
+
module->set_name(state, name, under);
|
| 258 |
+
under->set_const(state, name, module);
|
| 259 |
+
|
| 260 |
+
return module;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
bool yield_debugger(STATE, GCToken gct, CallFrame* call_frame, Object* bp) {
|
| 264 |
+
Thread* cur = Thread::current(state);
|
| 265 |
+
Thread* debugger = cur->debugger_thread();
|
| 266 |
+
|
| 267 |
+
// No debugger, bail.
|
| 268 |
+
if(debugger->nil_p()) {
|
| 269 |
+
std::cout << "no debugger\n";
|
| 270 |
+
return true;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
Channel* debugger_chan = debugger->control_channel();
|
| 274 |
+
|
| 275 |
+
// Debugger not initialized? bail.
|
| 276 |
+
if(debugger_chan->nil_p()) {
|
| 277 |
+
std::cout << "no debugger channel\n";
|
| 278 |
+
return true;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
// No one waiting on it? Well, nevermind then.
|
| 282 |
+
if(!debugger_chan->has_readers_p()) {
|
| 283 |
+
std::cout << "no waiters\n";
|
| 284 |
+
return true;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
// If we're hitting here, clear any chance that step would be used
|
| 288 |
+
// without being explicitly requested.
|
| 289 |
+
state->vm()->clear_thread_step();
|
| 290 |
+
|
| 291 |
+
state->set_call_frame(call_frame);
|
| 292 |
+
|
| 293 |
+
Channel* my_control = cur->control_channel();
|
| 294 |
+
|
| 295 |
+
// Lazily create our own control channel.
|
| 296 |
+
if(my_control->nil_p()) {
|
| 297 |
+
my_control = Channel::create(state);
|
| 298 |
+
cur->control_channel(state, my_control);
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
Array* locs = Location::from_call_stack(state, call_frame, true, true);
|
| 302 |
+
|
| 303 |
+
OnStack<1> os(state, my_control);
|
| 304 |
+
|
| 305 |
+
debugger_chan->send(state, gct,
|
| 306 |
+
Tuple::from(state, 4, bp, cur, my_control, locs));
|
| 307 |
+
|
| 308 |
+
// Block until the debugger wakes us back up.
|
| 309 |
+
Object* ret = my_control->receive(state, gct, call_frame);
|
| 310 |
+
|
| 311 |
+
// Do not access any locals other than ret beyond here unless you add OnStack<>
|
| 312 |
+
// to them! The GC has probably run and moved things.
|
| 313 |
+
|
| 314 |
+
// if ret is null, then receive was interrupted and there is an exception
|
| 315 |
+
// to propagate.
|
| 316 |
+
if(!ret) return false;
|
| 317 |
+
|
| 318 |
+
// Process a few commands...
|
| 319 |
+
if(ret == state->symbol("step")) {
|
| 320 |
+
state->vm()->get_attention();
|
| 321 |
+
state->vm()->set_thread_step();
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
// All done!
|
| 325 |
+
return true;
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
}
|
pool/shard009/C++/0106962_keys.cpp
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright 2013 - 2015 Matvey Bryksin, Yurii Litvinov and CyberTech Labs Ltd.
|
| 2 |
+
*
|
| 3 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
* you may not use this file except in compliance with the License.
|
| 5 |
+
* You may obtain a copy of the License at
|
| 6 |
+
*
|
| 7 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
*
|
| 9 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
* See the License for the specific language governing permissions and
|
| 13 |
+
* limitations under the License. */
|
| 14 |
+
|
| 15 |
+
#include "keys.h"
|
| 16 |
+
|
| 17 |
+
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
| 18 |
+
#include <QtGui/QApplication>
|
| 19 |
+
#else
|
| 20 |
+
#include <QtWidgets/QApplication>
|
| 21 |
+
#endif
|
| 22 |
+
|
| 23 |
+
#include <unistd.h>
|
| 24 |
+
|
| 25 |
+
#include <trikKernel/configurer.h>
|
| 26 |
+
|
| 27 |
+
#include "keysWorker.h"
|
| 28 |
+
|
| 29 |
+
using namespace trikControl;
|
| 30 |
+
|
| 31 |
+
Keys::Keys(const trikKernel::Configurer &configurer, const trikHal::HardwareAbstractionInterface &hardwareAbstraction)
|
| 32 |
+
: mState("Keys")
|
| 33 |
+
{
|
| 34 |
+
mKeysWorker.reset(new KeysWorker(configurer.attributeByDevice("keys", "deviceFile"), mState, hardwareAbstraction));
|
| 35 |
+
if (!mState.isFailed()) {
|
| 36 |
+
connect(mKeysWorker.data(), SIGNAL(buttonPressed(int, int)), this, SIGNAL(buttonPressed(int, int)));
|
| 37 |
+
connect(mKeysWorker.data(), SIGNAL(buttonPressed(int, int)), this, SLOT(changeButtonState(int, int)));
|
| 38 |
+
mKeysWorker->moveToThread(&mWorkerThread);
|
| 39 |
+
mWorkerThread.start();
|
| 40 |
+
mState.ready();
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
Keys::~Keys()
|
| 45 |
+
{
|
| 46 |
+
if (mWorkerThread.isRunning()) {
|
| 47 |
+
mWorkerThread.quit();
|
| 48 |
+
mWorkerThread.wait();
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
Keys::Status Keys::status() const
|
| 53 |
+
{
|
| 54 |
+
return mState.status();
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void Keys::reset()
|
| 58 |
+
{
|
| 59 |
+
mKeysWorker->reset();
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
bool Keys::wasPressed(int code)
|
| 63 |
+
{
|
| 64 |
+
return mKeysWorker->wasPressed(code);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
bool Keys::isPressed(int code)
|
| 68 |
+
{
|
| 69 |
+
return mKeysPressed.value(code, false);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
void Keys::changeButtonState(int code, int value)
|
| 73 |
+
{
|
| 74 |
+
mKeysPressed[code] = value;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
int Keys::buttonCode(bool wait)
|
| 78 |
+
{
|
| 79 |
+
if (!wait) {
|
| 80 |
+
return pressedButton();
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
while (true) {
|
| 84 |
+
int code = pressedButton();
|
| 85 |
+
if (code == -1) {
|
| 86 |
+
usleep(20);
|
| 87 |
+
QApplication::processEvents();
|
| 88 |
+
} else {
|
| 89 |
+
return code;
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
int Keys::pressedButton()
|
| 95 |
+
{
|
| 96 |
+
for (int button : mKeysPressed.keys()) {
|
| 97 |
+
if (mKeysPressed[button]) {
|
| 98 |
+
return button;
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
return -1;
|
| 103 |
+
}
|
pool/shard009/C++/0106964_unit-test-semantic-actions.cpp
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// unit-test-semantic-actions.cpp
|
| 2 |
+
// Started 14 Aug 2018
|
| 3 |
+
#include "pch-Unit-Tests.hpp"
|
| 4 |
+
namespace client {
|
| 5 |
+
namespace qi = boost::spirit::qi;
|
| 6 |
+
namespace ascii = boost::spirit::ascii;
|
| 7 |
+
|
| 8 |
+
template<typename Iterator>
|
| 9 |
+
struct int_parser : qi::grammar<Iterator, void(), ascii::space_type>
|
| 10 |
+
{
|
| 11 |
+
typedef int_parser<Iterator> This;
|
| 12 |
+
int result = 0;
|
| 13 |
+
void set_result(int i) { result = i; }
|
| 14 |
+
qi::rule<Iterator, void(), ascii::space_type> start;
|
| 15 |
+
|
| 16 |
+
int_parser()
|
| 17 |
+
: base_type{ start }
|
| 18 |
+
{
|
| 19 |
+
start = qi::lit('<')
|
| 20 |
+
>> qi::int_[boost::bind(&This::set_result, this, _1)]
|
| 21 |
+
>> qi::lit('>');
|
| 22 |
+
}
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
template<typename Iterator>
|
| 27 |
+
struct coords_parser : qi::grammar<Iterator, void(), ascii::space_type>
|
| 28 |
+
{
|
| 29 |
+
typedef coords_parser<Iterator> This;
|
| 30 |
+
std::pair<double, double> result{};
|
| 31 |
+
void set_first(double x) { result.first = x; }
|
| 32 |
+
void set_second(double y) { result.second = y; }
|
| 33 |
+
qi::rule<Iterator, void(), ascii::space_type> start;
|
| 34 |
+
|
| 35 |
+
coords_parser()
|
| 36 |
+
: base_type{ start }
|
| 37 |
+
{
|
| 38 |
+
start = qi::lit('(')
|
| 39 |
+
>> qi::double_[boost::bind(&This::set_first, this, _1)]
|
| 40 |
+
>> qi::lit(',')
|
| 41 |
+
>> qi::double_[boost::bind(&This::set_second, this, _1)]
|
| 42 |
+
>> qi::lit(')');
|
| 43 |
+
}
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
template<typename Iterator>
|
| 48 |
+
struct assignment_parser : qi::grammar<Iterator, void(), ascii::space_type>
|
| 49 |
+
{
|
| 50 |
+
typedef assignment_parser<Iterator> This;
|
| 51 |
+
typedef std::pair<std::string, std::string> Result_Type;
|
| 52 |
+
Result_Type result{};
|
| 53 |
+
void append_head(char x) { result.first += x; }
|
| 54 |
+
void set_head(std::vector<char> x) { result.first.assign(x.begin(), x.end()); }
|
| 55 |
+
void set_tail(std::vector<char> y) { result.second.assign(y.begin(), y.end()); }
|
| 56 |
+
qi::rule<Iterator, void(), ascii::space_type> start;
|
| 57 |
+
qi::rule<Iterator, void(), ascii::space_type> head;
|
| 58 |
+
qi::rule<Iterator, void(), ascii::space_type> tail;
|
| 59 |
+
|
| 60 |
+
assignment_parser()
|
| 61 |
+
: base_type{ start }
|
| 62 |
+
{
|
| 63 |
+
auto head = qi::lexeme[+ascii::alnum[boost::bind(&This::append_head, this, _1)]];
|
| 64 |
+
// [boost::bind(&This::append_head, this, _1)]
|
| 65 |
+
// auto tail = qi::lit('"') >> qi::no_skip[*(qi::char_ - '"')] >> qi::lit('"');
|
| 66 |
+
// auto tail = qi::no_skip[*(qi::char_ - '"')];
|
| 67 |
+
|
| 68 |
+
auto tail = qi::lexeme[*qi::char_];
|
| 69 |
+
// [boost::bind(&This::set_tail, this, _1)]
|
| 70 |
+
// Logger::WriteMessage(typeid(tail).name());
|
| 71 |
+
// auto start = head >> qi::lit('=') >> tail;
|
| 72 |
+
start = head; // >> tail;
|
| 73 |
+
}
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
namespace UnitTests {
|
| 80 |
+
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
| 81 |
+
// For test macros see:
|
| 82 |
+
// C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\VS\UnitTest\include\CppUnitTestAssert.h
|
| 83 |
+
|
| 84 |
+
TEST_CLASS(unit_test_semantic_actions)
|
| 85 |
+
{
|
| 86 |
+
public:
|
| 87 |
+
TEST_METHOD(int_parser_semantic_action)
|
| 88 |
+
{
|
| 89 |
+
namespace qi = boost::spirit::qi;
|
| 90 |
+
namespace ascii = boost::spirit::ascii;
|
| 91 |
+
const std::string str = " <22> ";
|
| 92 |
+
typedef std::string::const_iterator StringIterator;
|
| 93 |
+
client::int_parser<StringIterator> grammar;
|
| 94 |
+
StringIterator itr = str.begin(), end = str.end();
|
| 95 |
+
Assert::IsTrue(qi::phrase_parse(itr, end, grammar, ascii::space));
|
| 96 |
+
Assert::AreEqual(22, grammar.result);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
TEST_METHOD(double_parser_semantic_action)
|
| 100 |
+
{
|
| 101 |
+
namespace qi = boost::spirit::qi;
|
| 102 |
+
namespace ascii = boost::spirit::ascii;
|
| 103 |
+
const std::string str = " ( 11 , 22.3 ) ";
|
| 104 |
+
typedef std::string::const_iterator StringIterator;
|
| 105 |
+
client::coords_parser<StringIterator> grammar;
|
| 106 |
+
StringIterator itr = str.begin(), end = str.end();
|
| 107 |
+
Assert::IsTrue(qi::phrase_parse(itr, end, grammar, ascii::space));
|
| 108 |
+
Assert::AreEqual(std::make_pair(11.0, 22.3), grammar.result);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
#if 0
|
| 112 |
+
TEST_METHOD(assignment_parser_semantic_action)
|
| 113 |
+
{
|
| 114 |
+
namespace qi = boost::spirit::qi;
|
| 115 |
+
namespace ascii = boost::spirit::ascii;
|
| 116 |
+
typedef std::string::const_iterator StringIterator;
|
| 117 |
+
typedef client::assignment_parser<StringIterator> Grammar;
|
| 118 |
+
Grammar parser;
|
| 119 |
+
Grammar::Result_Type expected{ "white","horse" };
|
| 120 |
+
const std::string str = " white horse ";
|
| 121 |
+
StringIterator itr = str.begin(), end = str.end();
|
| 122 |
+
Assert::IsTrue(qi::phrase_parse(itr, end, parser, ascii::space));
|
| 123 |
+
Logger::WriteMessage("assignment_parser_semantic_action");
|
| 124 |
+
Logger::WriteMessage(parser.result.first.c_str());
|
| 125 |
+
Logger::WriteMessage(parser.result.second.c_str());
|
| 126 |
+
// Assert::AreEqual(expected, parser.result);
|
| 127 |
+
}
|
| 128 |
+
#endif
|
| 129 |
+
|
| 130 |
+
};
|
| 131 |
+
}
|
pool/shard009/C++/0106966_DNSServer.cpp
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "./DNSServer.h"
|
| 2 |
+
#include <lwip/def.h>
|
| 3 |
+
#include <Arduino.h>
|
| 4 |
+
|
| 5 |
+
#define DEBUG
|
| 6 |
+
#define DEBUG_OUTPUT Serial
|
| 7 |
+
|
| 8 |
+
DNSServer::DNSServer()
|
| 9 |
+
{
|
| 10 |
+
_ttl = htonl(60);
|
| 11 |
+
_errorReplyCode = DNSReplyCode::NonExistentDomain;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
bool DNSServer::start(const uint16_t &port, const String &domainName,
|
| 15 |
+
const IPAddress &resolvedIP)
|
| 16 |
+
{
|
| 17 |
+
_port = port;
|
| 18 |
+
_domainName = domainName;
|
| 19 |
+
_resolvedIP[0] = resolvedIP[0];
|
| 20 |
+
_resolvedIP[1] = resolvedIP[1];
|
| 21 |
+
_resolvedIP[2] = resolvedIP[2];
|
| 22 |
+
_resolvedIP[3] = resolvedIP[3];
|
| 23 |
+
downcaseAndRemoveWwwPrefix(_domainName);
|
| 24 |
+
return _udp.begin(_port) == 1;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
void DNSServer::setErrorReplyCode(const DNSReplyCode &replyCode)
|
| 28 |
+
{
|
| 29 |
+
_errorReplyCode = replyCode;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void DNSServer::setTTL(const uint32_t &ttl)
|
| 33 |
+
{
|
| 34 |
+
_ttl = htonl(ttl);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void DNSServer::stop()
|
| 38 |
+
{
|
| 39 |
+
_udp.stop();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
void DNSServer::downcaseAndRemoveWwwPrefix(String &domainName)
|
| 43 |
+
{
|
| 44 |
+
domainName.toLowerCase();
|
| 45 |
+
domainName.replace("www.", "");
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void DNSServer::processNextRequest()
|
| 49 |
+
{
|
| 50 |
+
_currentPacketSize = _udp.parsePacket();
|
| 51 |
+
if (_currentPacketSize)
|
| 52 |
+
{
|
| 53 |
+
_buffer = (unsigned char*)malloc(_currentPacketSize * sizeof(char));
|
| 54 |
+
_udp.read(_buffer, _currentPacketSize);
|
| 55 |
+
_dnsHeader = (DNSHeader*) _buffer;
|
| 56 |
+
|
| 57 |
+
if (_dnsHeader->QR == DNS_QR_QUERY &&
|
| 58 |
+
_dnsHeader->OPCode == DNS_OPCODE_QUERY &&
|
| 59 |
+
requestIncludesOnlyOneQuestion() &&
|
| 60 |
+
(_domainName == "*" || getDomainNameWithoutWwwPrefix() == _domainName)
|
| 61 |
+
)
|
| 62 |
+
{
|
| 63 |
+
replyWithIP();
|
| 64 |
+
}
|
| 65 |
+
else if (_dnsHeader->QR == DNS_QR_QUERY)
|
| 66 |
+
{
|
| 67 |
+
replyWithCustomCode();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
free(_buffer);
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
bool DNSServer::requestIncludesOnlyOneQuestion()
|
| 75 |
+
{
|
| 76 |
+
return ntohs(_dnsHeader->QDCount) == 1 &&
|
| 77 |
+
_dnsHeader->ANCount == 0 &&
|
| 78 |
+
_dnsHeader->NSCount == 0 &&
|
| 79 |
+
_dnsHeader->ARCount == 0;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
String DNSServer::getDomainNameWithoutWwwPrefix()
|
| 83 |
+
{
|
| 84 |
+
String parsedDomainName = "";
|
| 85 |
+
unsigned char *start = _buffer + 12;
|
| 86 |
+
if (*start == 0)
|
| 87 |
+
{
|
| 88 |
+
return parsedDomainName;
|
| 89 |
+
}
|
| 90 |
+
int pos = 0;
|
| 91 |
+
while(true)
|
| 92 |
+
{
|
| 93 |
+
unsigned char labelLength = *(start + pos);
|
| 94 |
+
for(int i = 0; i < labelLength; i++)
|
| 95 |
+
{
|
| 96 |
+
pos++;
|
| 97 |
+
parsedDomainName += (char)*(start + pos);
|
| 98 |
+
}
|
| 99 |
+
pos++;
|
| 100 |
+
if (*(start + pos) == 0)
|
| 101 |
+
{
|
| 102 |
+
downcaseAndRemoveWwwPrefix(parsedDomainName);
|
| 103 |
+
return parsedDomainName;
|
| 104 |
+
}
|
| 105 |
+
else
|
| 106 |
+
{
|
| 107 |
+
parsedDomainName += ".";
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
void DNSServer::replyWithIP()
|
| 113 |
+
{
|
| 114 |
+
_dnsHeader->QR = DNS_QR_RESPONSE;
|
| 115 |
+
_dnsHeader->ANCount = _dnsHeader->QDCount;
|
| 116 |
+
_dnsHeader->QDCount = _dnsHeader->QDCount;
|
| 117 |
+
//_dnsHeader->RA = 1;
|
| 118 |
+
|
| 119 |
+
_udp.beginPacket(_udp.remoteIP(), _udp.remotePort());
|
| 120 |
+
_udp.write(_buffer, _currentPacketSize);
|
| 121 |
+
|
| 122 |
+
_udp.write((uint8_t)192); // answer name is a pointer
|
| 123 |
+
_udp.write((uint8_t)12); // pointer to offset at 0x00c
|
| 124 |
+
|
| 125 |
+
_udp.write((uint8_t)0); // 0x0001 answer is type A query (host address)
|
| 126 |
+
_udp.write((uint8_t)1);
|
| 127 |
+
|
| 128 |
+
_udp.write((uint8_t)0); //0x0001 answer is class IN (internet address)
|
| 129 |
+
_udp.write((uint8_t)1);
|
| 130 |
+
|
| 131 |
+
_udp.write((unsigned char*)&_ttl, 4);
|
| 132 |
+
|
| 133 |
+
// Length of RData is 4 bytes (because, in this case, RData is IPv4)
|
| 134 |
+
_udp.write((uint8_t)0);
|
| 135 |
+
_udp.write((uint8_t)4);
|
| 136 |
+
_udp.write(_resolvedIP, sizeof(_resolvedIP));
|
| 137 |
+
_udp.endPacket();
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
#ifdef DEBUG
|
| 142 |
+
DEBUG_OUTPUT.print("DNS responds: ");
|
| 143 |
+
DEBUG_OUTPUT.print(_resolvedIP[0]);
|
| 144 |
+
DEBUG_OUTPUT.print(".");
|
| 145 |
+
DEBUG_OUTPUT.print(_resolvedIP[1]);
|
| 146 |
+
DEBUG_OUTPUT.print(".");
|
| 147 |
+
DEBUG_OUTPUT.print(_resolvedIP[2]);
|
| 148 |
+
DEBUG_OUTPUT.print(".");
|
| 149 |
+
DEBUG_OUTPUT.print(_resolvedIP[3]);
|
| 150 |
+
DEBUG_OUTPUT.print(" for ");
|
| 151 |
+
DEBUG_OUTPUT.println(getDomainNameWithoutWwwPrefix());
|
| 152 |
+
#endif
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
void DNSServer::replyWithCustomCode()
|
| 156 |
+
{
|
| 157 |
+
_dnsHeader->QR = DNS_QR_RESPONSE;
|
| 158 |
+
_dnsHeader->RCode = (unsigned char)_errorReplyCode;
|
| 159 |
+
_dnsHeader->QDCount = 0;
|
| 160 |
+
|
| 161 |
+
_udp.beginPacket(_udp.remoteIP(), _udp.remotePort());
|
| 162 |
+
_udp.write(_buffer, sizeof(DNSHeader));
|
| 163 |
+
_udp.endPacket();
|
| 164 |
+
}
|
| 165 |
+
|
pool/shard009/C++/0106978_14.40.cpp
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// based on ex10.16.cpp
|
| 2 |
+
#include <string>
|
| 3 |
+
#include <vector>
|
| 4 |
+
#include <algorithm>
|
| 5 |
+
#include <iostream>
|
| 6 |
+
|
| 7 |
+
std::string make_plural(size_t ctr, const std::string &word,
|
| 8 |
+
const std::string &ending = "s") {
|
| 9 |
+
return (ctr > 1) ? word + ending : word;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
void elimDups(std::vector<std::string> &words) {
|
| 13 |
+
std::sort(words.begin(), words.end());
|
| 14 |
+
auto end_unique = std::unique(words.begin(), words.end());
|
| 15 |
+
words.erase(end_unique, words.end());
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
struct Shorter {
|
| 19 |
+
bool operator()(const std::string &s1, const std::string &s2) const {
|
| 20 |
+
return s1.size() < s2.size();
|
| 21 |
+
}
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
struct Longer {
|
| 25 |
+
Longer(size_t size) : sz(size) { }
|
| 26 |
+
bool operator()(const std::string &s) const { return s.size() >= sz; }
|
| 27 |
+
|
| 28 |
+
private:
|
| 29 |
+
size_t sz;
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
struct PrintString {
|
| 33 |
+
PrintString(std::ostream &o = std::cout, char d = ' ')
|
| 34 |
+
: os(o), delimiter(d) { }
|
| 35 |
+
void operator()(const std::string &s) const { os << s << delimiter; }
|
| 36 |
+
|
| 37 |
+
private:
|
| 38 |
+
std::ostream &os;
|
| 39 |
+
char delimiter;
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
void biggies(std::vector<std::string> words, // use value instead of reference
|
| 43 |
+
std::vector<std::string>::size_type sz) {
|
| 44 |
+
elimDups(words);
|
| 45 |
+
std::stable_sort(words.begin(), words.end(), Shorter());
|
| 46 |
+
auto iter = std::find_if(words.begin(), words.end(), Longer(sz));
|
| 47 |
+
auto count = words.end() - iter;
|
| 48 |
+
std::cout << count << " " << make_plural(count, "word") << " of length "
|
| 49 |
+
<< sz << " or longer." << std::endl;
|
| 50 |
+
std::for_each(iter, words.end(), PrintString());
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
int main() {
|
| 54 |
+
std::vector<std::string> words;
|
| 55 |
+
for (std::string s; std::cin >> s; words.push_back(s)) { }
|
| 56 |
+
biggies(words, 3);
|
| 57 |
+
std::cout << std::endl;
|
| 58 |
+
biggies(words, 5);
|
| 59 |
+
|
| 60 |
+
return 0;
|
| 61 |
+
}
|
pool/shard009/C++/0106979_11305-3.cc
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// { dg-require-namedlocale "en_US.UTF-8" }
|
| 2 |
+
|
| 3 |
+
// Copyright (C) 2003-2013 Free Software Foundation, Inc.
|
| 4 |
+
//
|
| 5 |
+
// This file is part of the GNU ISO C++ Library. This library is free
|
| 6 |
+
// software; you can redistribute it and/or modify it under the
|
| 7 |
+
// terms of the GNU General Public License as published by the
|
| 8 |
+
// Free Software Foundation; either version 3, or (at your option)
|
| 9 |
+
// any later version.
|
| 10 |
+
|
| 11 |
+
// This library is distributed in the hope that it will be useful,
|
| 12 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
// GNU General Public License for more details.
|
| 15 |
+
|
| 16 |
+
// You should have received a copy of the GNU General Public License along
|
| 17 |
+
// with this library; see the file COPYING3. If not see
|
| 18 |
+
// <http://www.gnu.org/licenses/>.
|
| 19 |
+
|
| 20 |
+
// 27.8.1.4 Overridden virtual functions
|
| 21 |
+
|
| 22 |
+
#include <fstream>
|
| 23 |
+
#include <locale>
|
| 24 |
+
#include <testsuite_hooks.h>
|
| 25 |
+
|
| 26 |
+
void test03()
|
| 27 |
+
{
|
| 28 |
+
using namespace std;
|
| 29 |
+
bool test __attribute__((unused)) = true;
|
| 30 |
+
|
| 31 |
+
wfilebuf fb;
|
| 32 |
+
locale loc(locale("en_US.UTF-8"));
|
| 33 |
+
fb.pubimbue(loc);
|
| 34 |
+
fb.open("tmp_11305-3", ios_base::out);
|
| 35 |
+
wfilebuf::int_type n1 = fb.sputc(0x20000000);
|
| 36 |
+
wfilebuf* f = fb.close();
|
| 37 |
+
|
| 38 |
+
VERIFY( n1 != wfilebuf::traits_type::eof() );
|
| 39 |
+
VERIFY( f );
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
int main()
|
| 43 |
+
{
|
| 44 |
+
test03();
|
| 45 |
+
return 0;
|
| 46 |
+
}
|
pool/shard009/C++/0106983_demo_main.cc
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/at_exit.h"
|
| 6 |
+
#include "base/command_line.h"
|
| 7 |
+
#include "base/i18n/icu_util.h"
|
| 8 |
+
#include "base/macros.h"
|
| 9 |
+
#include "base/memory/scoped_ptr.h"
|
| 10 |
+
#include "base/message_loop/message_loop.h"
|
| 11 |
+
#include "base/power_monitor/power_monitor.h"
|
| 12 |
+
#include "base/power_monitor/power_monitor_device_source.h"
|
| 13 |
+
#include "build/build_config.h"
|
| 14 |
+
#include "third_party/skia/include/core/SkXfermode.h"
|
| 15 |
+
#include "ui/aura/client/default_capture_client.h"
|
| 16 |
+
#include "ui/aura/client/window_tree_client.h"
|
| 17 |
+
#include "ui/aura/env.h"
|
| 18 |
+
#include "ui/aura/test/test_focus_client.h"
|
| 19 |
+
#include "ui/aura/test/test_screen.h"
|
| 20 |
+
#include "ui/aura/window.h"
|
| 21 |
+
#include "ui/aura/window_delegate.h"
|
| 22 |
+
#include "ui/aura/window_tree_host.h"
|
| 23 |
+
#include "ui/base/hit_test.h"
|
| 24 |
+
#include "ui/compositor/paint_recorder.h"
|
| 25 |
+
#include "ui/compositor/test/in_process_context_factory.h"
|
| 26 |
+
#include "ui/events/event.h"
|
| 27 |
+
#include "ui/gfx/canvas.h"
|
| 28 |
+
#include "ui/gfx/geometry/rect.h"
|
| 29 |
+
#include "ui/gfx/skia_util.h"
|
| 30 |
+
#include "ui/gl/gl_surface.h"
|
| 31 |
+
|
| 32 |
+
#if defined(USE_X11)
|
| 33 |
+
#include "ui/gfx/x/x11_connection.h" // nogncheck
|
| 34 |
+
#endif
|
| 35 |
+
|
| 36 |
+
#if defined(OS_WIN)
|
| 37 |
+
#include "ui/gfx/win/dpi.h"
|
| 38 |
+
#endif
|
| 39 |
+
|
| 40 |
+
namespace {
|
| 41 |
+
|
| 42 |
+
// Trivial WindowDelegate implementation that draws a colored background.
|
| 43 |
+
class DemoWindowDelegate : public aura::WindowDelegate {
|
| 44 |
+
public:
|
| 45 |
+
explicit DemoWindowDelegate(SkColor color) : color_(color) {}
|
| 46 |
+
|
| 47 |
+
// Overridden from WindowDelegate:
|
| 48 |
+
gfx::Size GetMinimumSize() const override { return gfx::Size(); }
|
| 49 |
+
|
| 50 |
+
gfx::Size GetMaximumSize() const override { return gfx::Size(); }
|
| 51 |
+
|
| 52 |
+
void OnBoundsChanged(const gfx::Rect& old_bounds,
|
| 53 |
+
const gfx::Rect& new_bounds) override {
|
| 54 |
+
window_bounds_ = new_bounds;
|
| 55 |
+
}
|
| 56 |
+
gfx::NativeCursor GetCursor(const gfx::Point& point) override {
|
| 57 |
+
return gfx::kNullCursor;
|
| 58 |
+
}
|
| 59 |
+
int GetNonClientComponent(const gfx::Point& point) const override {
|
| 60 |
+
return HTCAPTION;
|
| 61 |
+
}
|
| 62 |
+
bool ShouldDescendIntoChildForEventHandling(
|
| 63 |
+
aura::Window* child,
|
| 64 |
+
const gfx::Point& location) override {
|
| 65 |
+
return true;
|
| 66 |
+
}
|
| 67 |
+
bool CanFocus() override { return true; }
|
| 68 |
+
void OnCaptureLost() override {}
|
| 69 |
+
void OnPaint(const ui::PaintContext& context) override {
|
| 70 |
+
ui::PaintRecorder recorder(context, window_bounds_.size());
|
| 71 |
+
recorder.canvas()->DrawColor(color_, SkXfermode::kSrc_Mode);
|
| 72 |
+
gfx::Rect r;
|
| 73 |
+
recorder.canvas()->GetClipBounds(&r);
|
| 74 |
+
// Fill with a non-solid color so that the compositor will exercise its
|
| 75 |
+
// texture upload path.
|
| 76 |
+
while (!r.IsEmpty()) {
|
| 77 |
+
r.Inset(2, 2);
|
| 78 |
+
recorder.canvas()->FillRect(r, color_, SkXfermode::kXor_Mode);
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
|
| 82 |
+
void OnWindowDestroying(aura::Window* window) override {}
|
| 83 |
+
void OnWindowDestroyed(aura::Window* window) override {}
|
| 84 |
+
void OnWindowTargetVisibilityChanged(bool visible) override {}
|
| 85 |
+
bool HasHitTestMask() const override { return false; }
|
| 86 |
+
void GetHitTestMask(gfx::Path* mask) const override {}
|
| 87 |
+
|
| 88 |
+
private:
|
| 89 |
+
SkColor color_;
|
| 90 |
+
gfx::Rect window_bounds_;
|
| 91 |
+
|
| 92 |
+
DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
class DemoWindowTreeClient : public aura::client::WindowTreeClient {
|
| 96 |
+
public:
|
| 97 |
+
explicit DemoWindowTreeClient(aura::Window* window) : window_(window) {
|
| 98 |
+
aura::client::SetWindowTreeClient(window_, this);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
~DemoWindowTreeClient() override {
|
| 102 |
+
aura::client::SetWindowTreeClient(window_, nullptr);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// Overridden from aura::client::WindowTreeClient:
|
| 106 |
+
aura::Window* GetDefaultParent(aura::Window* context,
|
| 107 |
+
aura::Window* window,
|
| 108 |
+
const gfx::Rect& bounds) override {
|
| 109 |
+
if (!capture_client_) {
|
| 110 |
+
capture_client_.reset(
|
| 111 |
+
new aura::client::DefaultCaptureClient(window_->GetRootWindow()));
|
| 112 |
+
}
|
| 113 |
+
return window_;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
private:
|
| 117 |
+
aura::Window* window_;
|
| 118 |
+
|
| 119 |
+
scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
|
| 120 |
+
|
| 121 |
+
DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient);
|
| 122 |
+
};
|
| 123 |
+
|
| 124 |
+
int DemoMain() {
|
| 125 |
+
#if defined(USE_X11)
|
| 126 |
+
// This demo uses InProcessContextFactory which uses X on a separate Gpu
|
| 127 |
+
// thread.
|
| 128 |
+
gfx::InitializeThreadedX11();
|
| 129 |
+
#endif
|
| 130 |
+
|
| 131 |
+
gfx::GLSurface::InitializeOneOff();
|
| 132 |
+
|
| 133 |
+
#if defined(OS_WIN)
|
| 134 |
+
gfx::SetDefaultDeviceScaleFactor(1.0f);
|
| 135 |
+
#endif
|
| 136 |
+
|
| 137 |
+
// The ContextFactory must exist before any Compositors are created.
|
| 138 |
+
bool context_factory_for_test = false;
|
| 139 |
+
scoped_ptr<ui::InProcessContextFactory> context_factory(
|
| 140 |
+
new ui::InProcessContextFactory(context_factory_for_test, nullptr));
|
| 141 |
+
context_factory->set_use_test_surface(false);
|
| 142 |
+
|
| 143 |
+
// Create the message-loop here before creating the root window.
|
| 144 |
+
base::MessageLoopForUI message_loop;
|
| 145 |
+
|
| 146 |
+
base::PowerMonitor power_monitor(make_scoped_ptr(
|
| 147 |
+
new base::PowerMonitorDeviceSource));
|
| 148 |
+
|
| 149 |
+
aura::Env::CreateInstance(true);
|
| 150 |
+
aura::Env::GetInstance()->set_context_factory(context_factory.get());
|
| 151 |
+
scoped_ptr<aura::TestScreen> test_screen(
|
| 152 |
+
aura::TestScreen::Create(gfx::Size()));
|
| 153 |
+
gfx::Screen::SetScreenInstance(test_screen.get());
|
| 154 |
+
scoped_ptr<aura::WindowTreeHost> host(
|
| 155 |
+
test_screen->CreateHostForPrimaryDisplay());
|
| 156 |
+
scoped_ptr<DemoWindowTreeClient> window_tree_client(
|
| 157 |
+
new DemoWindowTreeClient(host->window()));
|
| 158 |
+
aura::test::TestFocusClient focus_client;
|
| 159 |
+
aura::client::SetFocusClient(host->window(), &focus_client);
|
| 160 |
+
|
| 161 |
+
// Create a hierarchy of test windows.
|
| 162 |
+
gfx::Rect window1_bounds(100, 100, 400, 400);
|
| 163 |
+
DemoWindowDelegate window_delegate1(SK_ColorBLUE);
|
| 164 |
+
aura::Window window1(&window_delegate1);
|
| 165 |
+
window1.set_id(1);
|
| 166 |
+
window1.Init(ui::LAYER_TEXTURED);
|
| 167 |
+
window1.SetBounds(window1_bounds);
|
| 168 |
+
window1.Show();
|
| 169 |
+
aura::client::ParentWindowWithContext(&window1, host->window(), gfx::Rect());
|
| 170 |
+
|
| 171 |
+
gfx::Rect window2_bounds(200, 200, 350, 350);
|
| 172 |
+
DemoWindowDelegate window_delegate2(SK_ColorRED);
|
| 173 |
+
aura::Window window2(&window_delegate2);
|
| 174 |
+
window2.set_id(2);
|
| 175 |
+
window2.Init(ui::LAYER_TEXTURED);
|
| 176 |
+
window2.SetBounds(window2_bounds);
|
| 177 |
+
window2.Show();
|
| 178 |
+
aura::client::ParentWindowWithContext(&window2, host->window(), gfx::Rect());
|
| 179 |
+
|
| 180 |
+
gfx::Rect window3_bounds(10, 10, 50, 50);
|
| 181 |
+
DemoWindowDelegate window_delegate3(SK_ColorGREEN);
|
| 182 |
+
aura::Window window3(&window_delegate3);
|
| 183 |
+
window3.set_id(3);
|
| 184 |
+
window3.Init(ui::LAYER_TEXTURED);
|
| 185 |
+
window3.SetBounds(window3_bounds);
|
| 186 |
+
window3.Show();
|
| 187 |
+
window2.AddChild(&window3);
|
| 188 |
+
|
| 189 |
+
host->Show();
|
| 190 |
+
base::MessageLoopForUI::current()->Run();
|
| 191 |
+
|
| 192 |
+
return 0;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
} // namespace
|
| 196 |
+
|
| 197 |
+
int main(int argc, char** argv) {
|
| 198 |
+
base::CommandLine::Init(argc, argv);
|
| 199 |
+
|
| 200 |
+
// The exit manager is in charge of calling the dtors of singleton objects.
|
| 201 |
+
base::AtExitManager exit_manager;
|
| 202 |
+
|
| 203 |
+
base::i18n::InitializeICU();
|
| 204 |
+
|
| 205 |
+
return DemoMain();
|
| 206 |
+
}
|
pool/shard009/C++/0106991_DlgFilesSetup.cpp
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "Uvs2.h"
|
| 2 |
+
#pragma hdrstop
|
| 3 |
+
|
| 4 |
+
class TextCompareCtrl;
|
| 5 |
+
|
| 6 |
+
#define LAYOUTFILE <Uvs2/DlgFilesSetup.lay>
|
| 7 |
+
#include <CtrlCore/lay.h>
|
| 8 |
+
|
| 9 |
+
class ExtendedButton : public FrameRight<Button>
|
| 10 |
+
{
|
| 11 |
+
public:
|
| 12 |
+
ExtendedButton();
|
| 13 |
+
virtual bool HotKey(dword key);
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
ExtendedButton::ExtendedButton()
|
| 17 |
+
{
|
| 18 |
+
Width(16);
|
| 19 |
+
SetImage(CtrlImg::right_arrow());
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
bool ExtendedButton::HotKey(dword key)
|
| 23 |
+
{
|
| 24 |
+
if(key == K_ALT_ENTER) {
|
| 25 |
+
for(Ctrl *p = this; p; p = p->GetParent())
|
| 26 |
+
if(p->HasFocus()) {
|
| 27 |
+
Action();
|
| 28 |
+
return true;
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
return Button::HotKey(key);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
class DlgFilesSetup : public WithFilesSetupLayout<TopWindow>
|
| 35 |
+
{
|
| 36 |
+
public:
|
| 37 |
+
typedef DlgFilesSetup CLASSNAME;
|
| 38 |
+
DlgFilesSetup();
|
| 39 |
+
|
| 40 |
+
bool Run(UvsJob& job);
|
| 41 |
+
|
| 42 |
+
private:
|
| 43 |
+
void OnDirBrowse();
|
| 44 |
+
void OnLocalBrowse();
|
| 45 |
+
|
| 46 |
+
void OnBackupMenu(Ctrl *owner);
|
| 47 |
+
void OnBackupNone(Ctrl *owner);
|
| 48 |
+
void OnBackupSeparate(Ctrl *owner);
|
| 49 |
+
void OnBackupChapter(Ctrl *owner);
|
| 50 |
+
|
| 51 |
+
static void DoBrowseDir(Ctrl& owner, const char *name);
|
| 52 |
+
|
| 53 |
+
private:
|
| 54 |
+
ExtendedButton dir_browse;
|
| 55 |
+
ExtendedButton local_browse;
|
| 56 |
+
ExtendedButton tree_backup_menu;
|
| 57 |
+
ExtendedButton local_backup_menu;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
bool UvsJob::Edit() { return DlgFilesSetup().Run(*this); }
|
| 61 |
+
|
| 62 |
+
DlgFilesSetup::DlgFilesSetup()
|
| 63 |
+
{
|
| 64 |
+
CtrlLayoutOKCancel(*this, t_("Job properties"));
|
| 65 |
+
CtrlLayout(misc);
|
| 66 |
+
misc.dir.AddFrame(dir_browse);
|
| 67 |
+
dir_browse <<= THISBACK(OnDirBrowse);
|
| 68 |
+
misc.localrepository.AddFrame(local_browse);
|
| 69 |
+
local_browse <<= THISBACK(OnLocalBrowse);
|
| 70 |
+
tab.Add(misc.SizePos(), t_("Miscellaneous"));
|
| 71 |
+
CtrlLayout(back);
|
| 72 |
+
back.tree_backup.AddFrame(tree_backup_menu);
|
| 73 |
+
tree_backup_menu.WhenPush = THISBACK1(OnBackupMenu, &back.tree_backup);
|
| 74 |
+
back.local_backup.AddFrame(local_backup_menu);
|
| 75 |
+
local_backup_menu.WhenPush = THISBACK1(OnBackupMenu, &back.local_backup);
|
| 76 |
+
tab.Add(back.SizePos(), t_("Backups"));
|
| 77 |
+
CtrlLayout(excf);
|
| 78 |
+
tab.Add(excf.SizePos(), t_("Exclude files"));
|
| 79 |
+
CtrlLayout(excd);
|
| 80 |
+
tab.Add(excd.SizePos(), t_("Exclude folders"));
|
| 81 |
+
CtrlLayout(bin);
|
| 82 |
+
tab.Add(bin.SizePos(), t_("Binary files"));
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
bool DlgFilesSetup::Run(UvsJob& job)
|
| 86 |
+
{
|
| 87 |
+
CtrlRetriever rtvr;
|
| 88 |
+
rtvr
|
| 89 |
+
(misc.dir, job.dir)
|
| 90 |
+
(excd.excludedirs, job.excludedirs)
|
| 91 |
+
(bin.binaryfiles, job.binaryfiles)
|
| 92 |
+
(excf.excludefiles, job.excludefiles)
|
| 93 |
+
(misc.author, job.author)
|
| 94 |
+
(misc.localrepository, job.localrepository)
|
| 95 |
+
(misc.host, job.host)
|
| 96 |
+
(misc.user, job.user)
|
| 97 |
+
(misc.password, job.password)
|
| 98 |
+
(misc.hostrepository, job.hostrepository)
|
| 99 |
+
(misc.usecr, job.usecr)
|
| 100 |
+
(misc.passive, job.passive)
|
| 101 |
+
(misc.anonymous, job.anonymous)
|
| 102 |
+
(misc.fullblock, job.fullblock)
|
| 103 |
+
(back.tree_backup, job.tree_backup)
|
| 104 |
+
(back.local_backup, job.local_backup);
|
| 105 |
+
if(TopWindow::Run() != IDOK)
|
| 106 |
+
return false;
|
| 107 |
+
rtvr.Retrieve();
|
| 108 |
+
return true;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
void DlgFilesSetup::DoBrowseDir(Ctrl& owner, const char *name)
|
| 112 |
+
{
|
| 113 |
+
FileSel fsel;
|
| 114 |
+
fsel <<= NativePath((String)~owner);
|
| 115 |
+
if(fsel.ExecuteSelectDir(name))
|
| 116 |
+
owner <<= UnixPath(~fsel);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
void DlgFilesSetup::OnDirBrowse()
|
| 120 |
+
{
|
| 121 |
+
DoBrowseDir(misc.dir, t_("Source file folder"));
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
void DlgFilesSetup::OnLocalBrowse()
|
| 125 |
+
{
|
| 126 |
+
DoBrowseDir(misc.localrepository, t_("Local archive folder"));
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
void DlgFilesSetup::OnBackupMenu(Ctrl *owner)
|
| 130 |
+
{
|
| 131 |
+
MenuBar bar;
|
| 132 |
+
bar.Add(t_("No backup"), THISBACK1(OnBackupNone, owner));
|
| 133 |
+
bar.Add(t_("Separate files"), THISBACK1(OnBackupSeparate, owner));
|
| 134 |
+
bar.Add(t_("Chapter archive"), THISBACK1(OnBackupChapter, owner));
|
| 135 |
+
bar.Execute(owner -> GetScreenRect().TopRight());
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
void DlgFilesSetup::OnBackupNone(Ctrl *owner)
|
| 139 |
+
{
|
| 140 |
+
*owner <<= Null;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
void DlgFilesSetup::OnBackupSeparate(Ctrl *owner)
|
| 144 |
+
{
|
| 145 |
+
String path;
|
| 146 |
+
path << "jar32 a -r " << AppendFileName(GetTempPath(), "@@.j");
|
| 147 |
+
*owner <<= path;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
void DlgFilesSetup::OnBackupChapter(Ctrl *owner)
|
| 151 |
+
{
|
| 152 |
+
String path;
|
| 153 |
+
path << "jar32 ac -r " << AppendFileName(GetTempPath(), "soubory.j");
|
| 154 |
+
*owner <<= path;
|
| 155 |
+
}
|