Upload folder using huggingface_hub (part 120)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard011/C++/0118403_scim_skk_automaton.cpp +268 -0
- pool/shard011/C++/0118405_AnalyseFlight.cpp +181 -0
- pool/shard011/C++/0118406_soldier_spawn_point_map_element.cpp +55 -0
- pool/shard011/C++/0118407_SyntaxHighlighter.cpp +65 -0
- pool/shard011/C++/0118408_tstGuestControlSvc.cpp +302 -0
- pool/shard011/C++/0118410_compute_pair.cpp +120 -0
- pool/shard011/C++/0118412_main.cpp +59 -0
- pool/shard011/C++/0118413_main.cpp +142 -0
- pool/shard011/C++/0118414_6.23.cpp +60 -0
- pool/shard011/C++/0118415_coro.cc +37 -0
- pool/shard011/C++/0118416_CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_83_bad.cpp +43 -0
- pool/shard011/C++/0118419_tde-menu.cpp +171 -0
- pool/shard011/C++/0118420_transpose_op.cc +176 -0
- pool/shard011/C++/0118421_measure_et_al_02.cc +121 -0
- pool/shard011/C++/0118422_HDU4882.cpp +33 -0
- pool/shard011/C++/0118423_GModelSpectralRegistry.cpp +313 -0
- pool/shard011/C++/0118424_qpatternmatchingfns.cpp +230 -0
- pool/shard011/C++/0118425_memdatasource.cc +63 -0
- pool/shard011/C++/0118426_chrome.cpp +134 -0
- pool/shard011/C++/0118428_9322.cc +54 -0
- pool/shard011/C++/0118429_Fractal_Iterator.cpp +75 -0
- pool/shard011/C++/0118430_WxObsMap.cpp +244 -0
- pool/shard011/C++/0118431_bf_observe_linear_uncorrelated.cpp +92 -0
- pool/shard011/C++/0118432_DecoderBassmidi.cpp +252 -0
- pool/shard011/C++/0118433_stubserver.cpp +69 -0
- pool/shard011/C++/0118434_CWE190_Integer_Overflow__char_fscanf_square_74b.cpp +74 -0
- pool/shard011/C++/0118437_DodgeBurn.cpp +111 -0
- pool/shard011/C++/0118440_walletframe.cpp +196 -0
- pool/shard011/C++/0118441_shared_module_service_unittest.cc +179 -0
- pool/shard011/C++/0118442_konqframevisitor.cpp +68 -0
- pool/shard011/C++/0118443_io.cc +250 -0
- pool/shard011/C++/0118444_clara-sample.cpp +68 -0
- pool/shard011/C++/0118445_ArticleStateUfo.cpp +154 -0
- pool/shard011/C++/0118446_Boris_You_Are_Wrong_.cpp +73 -0
- pool/shard011/C++/0118447_bracketmatcher.cpp +142 -0
- pool/shard011/C++/0118448_main.cpp +28 -0
- pool/shard011/C++/0118449_main.cpp +135 -0
- pool/shard011/C++/0118450_main.cpp +222 -0
- pool/shard011/C++/0118451_mount_node_dir.cc +149 -0
- pool/shard011/C++/0118453_server_options.cpp +102 -0
- pool/shard011/C++/0118454_Table.cpp +160 -0
- pool/shard011/C++/0118456_temporal_format_test.cc +157 -0
- pool/shard011/C++/0118457_merkleblock.cpp +152 -0
- pool/shard011/C++/0118458_slate_modern.cpp +61 -0
- pool/shard011/C++/0118459_BlinkSignal.cpp +43 -0
- pool/shard011/C++/0118460_try_lock_shared.pass.cpp +69 -0
- pool/shard011/C++/0118462_document.cpp +97 -0
- pool/shard011/C++/0118463_extract_intertimes.cpp +69 -0
- pool/shard011/C++/0118464_utilitydialog.cpp +197 -0
- pool/shard011/C++/0118465_arch_test.cc +166 -0
pool/shard011/C++/0118403_scim_skk_automaton.cpp
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
| 2 |
+
/*
|
| 3 |
+
* Copyright (C) 2004 Hiroyuki Ikezoe
|
| 4 |
+
* Copyright (C) 2004 Takuro Ashie
|
| 5 |
+
*
|
| 6 |
+
* This program is free software; you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License as published by
|
| 8 |
+
* the Free Software Foundation; either version 2, or (at your option)
|
| 9 |
+
* any later version.
|
| 10 |
+
*
|
| 11 |
+
* This program is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with this program; if not, write to the Free Software
|
| 18 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include "scim_skk_automaton.h"
|
| 22 |
+
#include "conv_table.h"
|
| 23 |
+
|
| 24 |
+
using namespace scim_skk;
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
ConvEntry::ConvEntry (WideString s, WideString r, WideString c)
|
| 28 |
+
: str (s), res (r), cont (c)
|
| 29 |
+
{
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
ConvEntry::ConvEntry (WideString s, WideString r)
|
| 33 |
+
: str (s), res (r)
|
| 34 |
+
{
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
SKKAutomaton::SKKAutomaton (WideString title)
|
| 38 |
+
: m_exact_match (NULL),
|
| 39 |
+
m_title (title),
|
| 40 |
+
m_period_style(PERIOD_STYLE_TEN_MARU)
|
| 41 |
+
{
|
| 42 |
+
set_period_style(PERIOD_STYLE_TEN_MARU);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
SKKAutomaton::~SKKAutomaton ()
|
| 46 |
+
{
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
WideString&
|
| 50 |
+
SKKAutomaton::get_title (void)
|
| 51 |
+
{
|
| 52 |
+
return m_title;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
void
|
| 56 |
+
SKKAutomaton::set_title (const WideString &title)
|
| 57 |
+
{
|
| 58 |
+
m_title = title;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
bool
|
| 62 |
+
SKKAutomaton::append (const String & str, WideString & result)
|
| 63 |
+
{
|
| 64 |
+
WideString widestr = utf8_mbstowcs (str);
|
| 65 |
+
WideString newstr = m_pending + widestr;
|
| 66 |
+
const ConvEntry *exact_match = NULL;
|
| 67 |
+
bool has_partial_match = false;
|
| 68 |
+
bool retval = false;
|
| 69 |
+
ConvEntry *tmp_entry = NULL;
|
| 70 |
+
|
| 71 |
+
/* FIXME! should be optimized */
|
| 72 |
+
|
| 73 |
+
/* find matched table */
|
| 74 |
+
for (std::list<ConvEntry>::const_iterator it = m_rules.begin();
|
| 75 |
+
it != m_rules.end();
|
| 76 |
+
it++) {
|
| 77 |
+
/* matching */
|
| 78 |
+
const WideString &roma = it->str;
|
| 79 |
+
if (roma.find (newstr) == 0) {
|
| 80 |
+
if (roma.length () == newstr.length ()) {
|
| 81 |
+
/* exact match */
|
| 82 |
+
for (std::list<ConvEntry>::const_iterator j = m_period_rules.begin(); j != m_period_rules.end(); j++) {
|
| 83 |
+
if (j->str.compare(it->res) == 0) {
|
| 84 |
+
tmp_entry = new ConvEntry(it->str, j->res);
|
| 85 |
+
exact_match = tmp_entry;
|
| 86 |
+
break;
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
if (!tmp_entry)
|
| 90 |
+
exact_match = &(*it);
|
| 91 |
+
} else {
|
| 92 |
+
/* partial match */
|
| 93 |
+
has_partial_match = true;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/* return result */
|
| 99 |
+
if (has_partial_match) {
|
| 100 |
+
m_exact_match = exact_match;
|
| 101 |
+
result.clear ();
|
| 102 |
+
m_pending += widestr;
|
| 103 |
+
} else if (exact_match) {
|
| 104 |
+
if (exact_match->cont.empty())
|
| 105 |
+
m_exact_match = NULL;
|
| 106 |
+
else
|
| 107 |
+
m_exact_match = exact_match;
|
| 108 |
+
m_pending = exact_match->cont;
|
| 109 |
+
result += exact_match->res;
|
| 110 |
+
} else {
|
| 111 |
+
retval = true; /* commit prev pending */
|
| 112 |
+
if (m_exact_match) {
|
| 113 |
+
WideString tmp_result;
|
| 114 |
+
|
| 115 |
+
if (!(m_exact_match->res.empty()) &&
|
| 116 |
+
m_exact_match->cont.empty()) {
|
| 117 |
+
result += m_exact_match->res;
|
| 118 |
+
}
|
| 119 |
+
m_pending.clear();
|
| 120 |
+
m_exact_match = NULL;
|
| 121 |
+
|
| 122 |
+
append(str, tmp_result);
|
| 123 |
+
result += tmp_result;
|
| 124 |
+
} else {
|
| 125 |
+
if (m_pending.length () > 0) {
|
| 126 |
+
m_pending.clear();
|
| 127 |
+
append(str, result);
|
| 128 |
+
} else {
|
| 129 |
+
result.clear();
|
| 130 |
+
for (int i = 0; i < str.size(); i++) {
|
| 131 |
+
if (isalpha(str[i]))
|
| 132 |
+
m_pending += widestr[i];
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
if (tmp_entry)
|
| 139 |
+
delete tmp_entry;
|
| 140 |
+
return retval;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
void
|
| 144 |
+
SKKAutomaton::clear (void)
|
| 145 |
+
{
|
| 146 |
+
m_pending.clear ();
|
| 147 |
+
m_exact_match = NULL;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
bool
|
| 151 |
+
SKKAutomaton::is_pending (void)
|
| 152 |
+
{
|
| 153 |
+
if (m_pending.length () > 0)
|
| 154 |
+
return true;
|
| 155 |
+
else
|
| 156 |
+
return false;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
WideString&
|
| 160 |
+
SKKAutomaton::get_pending (void)
|
| 161 |
+
{
|
| 162 |
+
return m_pending;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
void
|
| 166 |
+
SKKAutomaton::set_pending (WideString &pending)
|
| 167 |
+
{
|
| 168 |
+
m_pending = pending;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
WideString
|
| 172 |
+
SKKAutomaton::flush_pending (void)
|
| 173 |
+
{
|
| 174 |
+
WideString result;
|
| 175 |
+
if (m_exact_match &&
|
| 176 |
+
!(m_exact_match->res.empty()) && m_exact_match->cont.empty()) {
|
| 177 |
+
result = m_exact_match->res;
|
| 178 |
+
}
|
| 179 |
+
clear();
|
| 180 |
+
return result;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
void
|
| 184 |
+
SKKAutomaton::set_rules (ConvRule *rules)
|
| 185 |
+
{
|
| 186 |
+
clear_rules();
|
| 187 |
+
append_rules(rules);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
void
|
| 191 |
+
SKKAutomaton::append_rules (ConvRule *rules)
|
| 192 |
+
{
|
| 193 |
+
for (unsigned int i = 0; rules[i].string; i++) {
|
| 194 |
+
m_rules.push_front(ConvEntry(utf8_mbstowcs(rules[i].string),
|
| 195 |
+
utf8_mbstowcs(rules[i].result),
|
| 196 |
+
utf8_mbstowcs(rules[i].cont)));
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
void
|
| 201 |
+
SKKAutomaton::replace_rules (ConvRule *rules)
|
| 202 |
+
{
|
| 203 |
+
for (std::list<ConvEntry>::iterator it = m_rules.begin();
|
| 204 |
+
it != m_rules.end(); ) {
|
| 205 |
+
bool flag = true;
|
| 206 |
+
for (unsigned int i = 0; rules[i].string; i++) {
|
| 207 |
+
if (it->str == utf8_mbstowcs(rules[i].string)) {
|
| 208 |
+
it = m_rules.erase(it);
|
| 209 |
+
flag = false;
|
| 210 |
+
break;
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
if (flag) it++;
|
| 214 |
+
}
|
| 215 |
+
append_rules (rules);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
void
|
| 219 |
+
SKKAutomaton::clear_rules (void)
|
| 220 |
+
{
|
| 221 |
+
m_rules.clear();
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
void
|
| 225 |
+
SKKAutomaton::append_rule (String &key, std::vector<String> &vals)
|
| 226 |
+
{
|
| 227 |
+
if (vals.size() > 1) {
|
| 228 |
+
m_rules.push_back(ConvEntry(utf8_mbstowcs(key),
|
| 229 |
+
utf8_mbstowcs(vals[0]),
|
| 230 |
+
utf8_mbstowcs(vals[1])));
|
| 231 |
+
} else {
|
| 232 |
+
m_rules.push_back(ConvEntry(utf8_mbstowcs(key),
|
| 233 |
+
utf8_mbstowcs(vals[0]),
|
| 234 |
+
WideString()));
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
PeriodStyle
|
| 240 |
+
SKKAutomaton::get_period_style (void)
|
| 241 |
+
{
|
| 242 |
+
return m_period_style;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
void
|
| 246 |
+
SKKAutomaton::set_period_style (PeriodStyle newstyle)
|
| 247 |
+
{
|
| 248 |
+
ConvRule *rules;
|
| 249 |
+
m_period_style = newstyle;
|
| 250 |
+
switch(m_period_style) {
|
| 251 |
+
case PERIOD_STYLE_TEN_MARU:
|
| 252 |
+
rules = period_rule_ten_maru;
|
| 253 |
+
break;
|
| 254 |
+
case PERIOD_STYLE_COMMA_PERIOD:
|
| 255 |
+
rules = period_rule_comma_period;
|
| 256 |
+
break;
|
| 257 |
+
case PERIOD_STYLE_HALF_COMMA_PERIOD:
|
| 258 |
+
rules = period_rule_half_comma_period;
|
| 259 |
+
break;
|
| 260 |
+
case PERIOD_STYLE_COMMA_MARU:
|
| 261 |
+
rules = period_rule_comma_maru;
|
| 262 |
+
break;
|
| 263 |
+
}
|
| 264 |
+
for (unsigned int i = 0; rules[i].string; i++) {
|
| 265 |
+
m_period_rules.push_front(ConvEntry(utf8_mbstowcs(rules[i].string),
|
| 266 |
+
utf8_mbstowcs(rules[i].result)));
|
| 267 |
+
}
|
| 268 |
+
}
|
pool/shard011/C++/0118405_AnalyseFlight.cpp
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright_License {
|
| 2 |
+
|
| 3 |
+
XCSoar Glide Computer - http://www.xcsoar.org/
|
| 4 |
+
Copyright (C) 2000-2014 The XCSoar Project
|
| 5 |
+
A detailed list of copyright holders can be found in the file "AUTHORS".
|
| 6 |
+
|
| 7 |
+
This program is free software; you can redistribute it and/or
|
| 8 |
+
modify it under the terms of the GNU General Public License
|
| 9 |
+
as published by the Free Software Foundation; either version 2
|
| 10 |
+
of the License, or (at your option) any later version.
|
| 11 |
+
|
| 12 |
+
This program is distributed in the hope that it will be useful,
|
| 13 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 |
+
GNU General Public License for more details.
|
| 16 |
+
|
| 17 |
+
You should have received a copy of the GNU General Public License
|
| 18 |
+
along with this program; if not, write to the Free Software
|
| 19 |
+
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 20 |
+
}
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include "AnalyseFlight.hpp"
|
| 24 |
+
#include "DebugReplay.hpp"
|
| 25 |
+
#include "Engine/Trace/Trace.hpp"
|
| 26 |
+
#include "Contest/ContestManager.hpp"
|
| 27 |
+
#include "Math/Angle.hpp"
|
| 28 |
+
#include "Time/BrokenDateTime.hpp"
|
| 29 |
+
#include "Computer/CirclingComputer.hpp"
|
| 30 |
+
#include "Computer/Wind/Computer.hpp"
|
| 31 |
+
#include "Computer/Settings.hpp"
|
| 32 |
+
#include "FlightPhaseDetector.hpp"
|
| 33 |
+
|
| 34 |
+
#include <limits>
|
| 35 |
+
|
| 36 |
+
void
|
| 37 |
+
Run(DebugReplay &replay, FlightPhaseDetector &flight_phase_detector,
|
| 38 |
+
WindList &wind_list,
|
| 39 |
+
const BrokenDateTime &takeoff_time,
|
| 40 |
+
const BrokenDateTime &scoring_start_time,
|
| 41 |
+
const BrokenDateTime &scoring_end_time,
|
| 42 |
+
const BrokenDateTime &landing_time,
|
| 43 |
+
Trace &full_trace, Trace &triangle_trace, Trace &sprint_trace)
|
| 44 |
+
{
|
| 45 |
+
GeoPoint last_location = GeoPoint::Invalid();
|
| 46 |
+
constexpr Angle max_longitude_change = Angle::Degrees(30);
|
| 47 |
+
constexpr Angle max_latitude_change = Angle::Degrees(1);
|
| 48 |
+
|
| 49 |
+
CirclingSettings circling_settings;
|
| 50 |
+
circling_settings.SetDefaults();
|
| 51 |
+
CirclingComputer circling_computer;
|
| 52 |
+
|
| 53 |
+
GlidePolar glide_polar(fixed(0));
|
| 54 |
+
|
| 55 |
+
WindSettings wind_settings;
|
| 56 |
+
wind_settings.SetDefaults();
|
| 57 |
+
|
| 58 |
+
WindComputer wind_computer;
|
| 59 |
+
wind_computer.Reset();
|
| 60 |
+
|
| 61 |
+
Validity last_wind;
|
| 62 |
+
last_wind.Clear();
|
| 63 |
+
|
| 64 |
+
const int64_t takeoff_unix = takeoff_time.ToUnixTimeUTC();
|
| 65 |
+
const int64_t landing_unix = landing_time.ToUnixTimeUTC();
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
int64_t scoring_start_unix, scoring_end_unix;
|
| 69 |
+
|
| 70 |
+
if (scoring_start_time.IsPlausible())
|
| 71 |
+
scoring_start_unix = scoring_start_time.ToUnixTimeUTC();
|
| 72 |
+
else
|
| 73 |
+
scoring_start_unix = std::numeric_limits<int64_t>::max();
|
| 74 |
+
|
| 75 |
+
if (scoring_end_time.IsPlausible())
|
| 76 |
+
scoring_end_unix = scoring_end_time.ToUnixTimeUTC();
|
| 77 |
+
else
|
| 78 |
+
scoring_end_unix = 0;
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
while (replay.Next()) {
|
| 82 |
+
const MoreData &basic = replay.Basic();
|
| 83 |
+
const int64_t date_time_utc = basic.date_time_utc.ToUnixTimeUTC();
|
| 84 |
+
|
| 85 |
+
if (date_time_utc < takeoff_unix)
|
| 86 |
+
continue;
|
| 87 |
+
|
| 88 |
+
if (date_time_utc > landing_unix)
|
| 89 |
+
break;
|
| 90 |
+
|
| 91 |
+
circling_computer.TurnRate(replay.SetCalculated(),
|
| 92 |
+
replay.Basic(),
|
| 93 |
+
replay.Calculated().flight);
|
| 94 |
+
circling_computer.Turning(replay.SetCalculated(),
|
| 95 |
+
replay.Basic(),
|
| 96 |
+
replay.Calculated().flight,
|
| 97 |
+
circling_settings);
|
| 98 |
+
|
| 99 |
+
flight_phase_detector.Update(replay.Basic(), replay.Calculated());
|
| 100 |
+
|
| 101 |
+
wind_computer.Compute(wind_settings, glide_polar, basic,
|
| 102 |
+
replay.SetCalculated());
|
| 103 |
+
|
| 104 |
+
if (replay.Calculated().estimated_wind_available.Modified(last_wind)) {
|
| 105 |
+
wind_list.push_back(WindListItem(basic.date_time_utc, basic.gps_altitude,
|
| 106 |
+
replay.Calculated().estimated_wind));
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
last_wind = replay.Calculated().estimated_wind_available;
|
| 110 |
+
|
| 111 |
+
if (!basic.time_available || !basic.location_available ||
|
| 112 |
+
!basic.NavAltitudeAvailable())
|
| 113 |
+
continue;
|
| 114 |
+
|
| 115 |
+
if (last_location.IsValid() &&
|
| 116 |
+
((last_location.latitude - basic.location.latitude).Absolute() > max_latitude_change ||
|
| 117 |
+
(last_location.longitude - basic.location.longitude).Absolute() > max_longitude_change))
|
| 118 |
+
/* there was an implausible warp, which is usually triggered by
|
| 119 |
+
an invalid point declared "valid" by a bugged logger; if that
|
| 120 |
+
happens, we stop the analysis, because the IGC file is
|
| 121 |
+
obviously broken */
|
| 122 |
+
break;
|
| 123 |
+
|
| 124 |
+
last_location = basic.location;
|
| 125 |
+
|
| 126 |
+
if (date_time_utc >= scoring_start_unix && date_time_utc <= scoring_end_unix) {
|
| 127 |
+
const TracePoint point(basic);
|
| 128 |
+
full_trace.push_back(point);
|
| 129 |
+
triangle_trace.push_back(point);
|
| 130 |
+
sprint_trace.push_back(point);
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
flight_phase_detector.Finish();
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
ContestStatistics
|
| 138 |
+
SolveContest(Contest contest,
|
| 139 |
+
Trace &full_trace, Trace &triangle_trace, Trace &sprint_trace,
|
| 140 |
+
const unsigned max_iterations, const unsigned max_tree_size)
|
| 141 |
+
{
|
| 142 |
+
ContestManager manager(contest, full_trace, triangle_trace, sprint_trace);
|
| 143 |
+
manager.SolveExhaustive(max_iterations, max_tree_size);
|
| 144 |
+
return manager.GetStats();
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
void AnalyseFlight(DebugReplay &replay,
|
| 148 |
+
const BrokenDateTime &takeoff_time,
|
| 149 |
+
const BrokenDateTime &scoring_start_time,
|
| 150 |
+
const BrokenDateTime &scoring_end_time,
|
| 151 |
+
const BrokenDateTime &landing_time,
|
| 152 |
+
ContestStatistics &olc_plus,
|
| 153 |
+
ContestStatistics &dmst,
|
| 154 |
+
PhaseList &phase_list,
|
| 155 |
+
PhaseTotals &phase_totals,
|
| 156 |
+
WindList &wind_list,
|
| 157 |
+
const unsigned full_points,
|
| 158 |
+
const unsigned triangle_points,
|
| 159 |
+
const unsigned sprint_points,
|
| 160 |
+
const unsigned max_iterations,
|
| 161 |
+
const unsigned max_tree_size)
|
| 162 |
+
{
|
| 163 |
+
Trace full_trace(0, Trace::null_time, full_points);
|
| 164 |
+
Trace triangle_trace(0, Trace::null_time, triangle_points);
|
| 165 |
+
Trace sprint_trace(0, 9000, sprint_points);
|
| 166 |
+
FlightPhaseDetector flight_phase_detector;
|
| 167 |
+
|
| 168 |
+
Run(replay, flight_phase_detector, wind_list,
|
| 169 |
+
takeoff_time, scoring_start_time, scoring_end_time, landing_time,
|
| 170 |
+
full_trace, triangle_trace, sprint_trace);
|
| 171 |
+
|
| 172 |
+
olc_plus = SolveContest(Contest::OLC_PLUS,
|
| 173 |
+
full_trace, triangle_trace, sprint_trace,
|
| 174 |
+
max_iterations, max_tree_size);
|
| 175 |
+
dmst = SolveContest(Contest::DMST,
|
| 176 |
+
full_trace, triangle_trace, sprint_trace,
|
| 177 |
+
max_iterations, max_tree_size);
|
| 178 |
+
|
| 179 |
+
phase_list = flight_phase_detector.GetPhases();
|
| 180 |
+
phase_totals = flight_phase_detector.GetTotals();
|
| 181 |
+
}
|
pool/shard011/C++/0118406_soldier_spawn_point_map_element.cpp
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "core/map/soldier_spawn_point_map_element.h"
|
| 2 |
+
|
| 3 |
+
namespace map {
|
| 4 |
+
|
| 5 |
+
SoldierSpawnPointMapElement::SoldierSpawnPointMapElement( int32_t Id )
|
| 6 |
+
: MapElement( Id )
|
| 7 |
+
, mX( 0 )
|
| 8 |
+
, mY( 0 )
|
| 9 |
+
{
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
void SoldierSpawnPointMapElement::Load( Json::Value& setters )
|
| 13 |
+
{
|
| 14 |
+
MapElement::Load( setters );
|
| 15 |
+
Json::Value const& position = setters["position"];
|
| 16 |
+
if( !position.isObject() )
|
| 17 |
+
{
|
| 18 |
+
return;
|
| 19 |
+
}
|
| 20 |
+
int32_t x;
|
| 21 |
+
if ( !Json::GetInt( position["x"], x ) )
|
| 22 |
+
{
|
| 23 |
+
return;
|
| 24 |
+
}
|
| 25 |
+
SetX( x );
|
| 26 |
+
int32_t y;
|
| 27 |
+
if ( !Json::GetInt( position["y"], y ) )
|
| 28 |
+
{
|
| 29 |
+
return;
|
| 30 |
+
}
|
| 31 |
+
SetY( y );
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
void SoldierSpawnPointMapElement::SetX( int32_t x )
|
| 35 |
+
{
|
| 36 |
+
mX = x;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
int32_t SoldierSpawnPointMapElement::GetX()const
|
| 40 |
+
{
|
| 41 |
+
return mX;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
void SoldierSpawnPointMapElement::SetY( int32_t y )
|
| 45 |
+
{
|
| 46 |
+
mY = y;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
int32_t SoldierSpawnPointMapElement::GetY()const
|
| 50 |
+
{
|
| 51 |
+
return mY;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
} // namespace map
|
pool/shard011/C++/0118407_SyntaxHighlighter.cpp
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright (C) Tim van Mourik, 2014-2016
|
| 2 |
+
Copyright (C) Tim van Mourik, 2017, DCCN
|
| 3 |
+
All rights reserved
|
| 4 |
+
|
| 5 |
+
This file is part of the Porcupine pipeline tool, see
|
| 6 |
+
https://github.com/TimVanMourik/Porcupine for the documentation and
|
| 7 |
+
details.
|
| 8 |
+
|
| 9 |
+
This toolbox is free software: you can redistribute it and/or modify
|
| 10 |
+
it under the terms of the GNU General Public License as published by
|
| 11 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 12 |
+
(at your option) any later version.
|
| 13 |
+
|
| 14 |
+
This toolbox 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 the fmri analysis toolbox. If not, see
|
| 21 |
+
<http://www.gnu.org/licenses/>.
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
#include "SyntaxHighlighter.hpp"
|
| 25 |
+
|
| 26 |
+
SyntaxHighlighter::SyntaxHighlighter(
|
| 27 |
+
QTextDocument* _parent
|
| 28 |
+
) :
|
| 29 |
+
QSyntaxHighlighter(_parent)
|
| 30 |
+
{
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
void SyntaxHighlighter::highlightBlock(
|
| 34 |
+
const QString& _text
|
| 35 |
+
)
|
| 36 |
+
{
|
| 37 |
+
foreach(const HighlightingRule& rule, m_highlightingRules)
|
| 38 |
+
{
|
| 39 |
+
QRegExp expression(rule.pattern);
|
| 40 |
+
int index = expression.indexIn(_text);
|
| 41 |
+
while(index >= 0)
|
| 42 |
+
{
|
| 43 |
+
int length = expression.matchedLength();
|
| 44 |
+
setFormat(index, length, rule.format);
|
| 45 |
+
index = expression.indexIn(_text, index + length);
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
setCurrentBlockState(0);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
void SyntaxHighlighter::addHighlightRule(
|
| 52 |
+
const QRegExp& _expression,
|
| 53 |
+
const QTextCharFormat& _format
|
| 54 |
+
)
|
| 55 |
+
{
|
| 56 |
+
HighlightingRule rule;
|
| 57 |
+
rule.pattern = _expression;
|
| 58 |
+
rule.format = _format;
|
| 59 |
+
m_highlightingRules.append(rule);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
SyntaxHighlighter::~SyntaxHighlighter()
|
| 63 |
+
{
|
| 64 |
+
|
| 65 |
+
}
|
pool/shard011/C++/0118408_tstGuestControlSvc.cpp
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* $Id: tstGuestControlSvc.cpp $ */
|
| 2 |
+
/** @file
|
| 3 |
+
*
|
| 4 |
+
* Testcase for the guest control service.
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* Copyright (C) 2011 Oracle Corporation
|
| 9 |
+
*
|
| 10 |
+
* This file is part of VirtualBox Open Source Edition (OSE), as
|
| 11 |
+
* available from http://www.virtualbox.org. This file is free software;
|
| 12 |
+
* you can redistribute it and/or modify it under the terms of the GNU
|
| 13 |
+
* General Public License (GPL) as published by the Free Software
|
| 14 |
+
* Foundation, in version 2 as it comes in the "COPYING" file of the
|
| 15 |
+
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
| 16 |
+
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
/*******************************************************************************
|
| 20 |
+
* Header Files *
|
| 21 |
+
*******************************************************************************/
|
| 22 |
+
#include <VBox/HostServices/GuestControlSvc.h>
|
| 23 |
+
#include <iprt/initterm.h>
|
| 24 |
+
#include <iprt/stream.h>
|
| 25 |
+
#include <iprt/test.h>
|
| 26 |
+
|
| 27 |
+
#include "../gctrl.h"
|
| 28 |
+
|
| 29 |
+
/*******************************************************************************
|
| 30 |
+
* Global Variables *
|
| 31 |
+
*******************************************************************************/
|
| 32 |
+
static RTTEST g_hTest = NIL_RTTEST;
|
| 33 |
+
|
| 34 |
+
using namespace guestControl;
|
| 35 |
+
|
| 36 |
+
extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad(VBOXHGCMSVCFNTABLE *pTable);
|
| 37 |
+
|
| 38 |
+
/** Simple call handle structure for the guest call completion callback */
|
| 39 |
+
struct VBOXHGCMCALLHANDLE_TYPEDEF
|
| 40 |
+
{
|
| 41 |
+
/** Where to store the result code. */
|
| 42 |
+
int32_t rc;
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
/** Call completion callback for guest calls. */
|
| 46 |
+
static void callComplete(VBOXHGCMCALLHANDLE callHandle, int32_t rc)
|
| 47 |
+
{
|
| 48 |
+
callHandle->rc = rc;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* Initialise the HGCM service table as much as we need to start the
|
| 53 |
+
* service.
|
| 54 |
+
*
|
| 55 |
+
* @return IPRT status.
|
| 56 |
+
* @param pTable the table to initialise
|
| 57 |
+
*/
|
| 58 |
+
int initTable(VBOXHGCMSVCFNTABLE *pTable, VBOXHGCMSVCHELPERS *pHelpers)
|
| 59 |
+
{
|
| 60 |
+
pTable->cbSize = sizeof (VBOXHGCMSVCFNTABLE);
|
| 61 |
+
pTable->u32Version = VBOX_HGCM_SVC_VERSION;
|
| 62 |
+
pHelpers->pfnCallComplete = callComplete;
|
| 63 |
+
pTable->pHelpers = pHelpers;
|
| 64 |
+
|
| 65 |
+
return VINF_SUCCESS;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
typedef struct CMDHOST
|
| 69 |
+
{
|
| 70 |
+
/** The HGCM command to execute. */
|
| 71 |
+
int cmd;
|
| 72 |
+
/** Number of parameters. */
|
| 73 |
+
int num_parms;
|
| 74 |
+
/** The actual parameters. */
|
| 75 |
+
const PVBOXHGCMSVCPARM parms;
|
| 76 |
+
/** Flag indicating whether we need a connected client for this command. */
|
| 77 |
+
bool fNeedsClient;
|
| 78 |
+
/** The desired return value from the host. */
|
| 79 |
+
int rc;
|
| 80 |
+
} CMDHOST, *PCMDHOST;
|
| 81 |
+
|
| 82 |
+
typedef struct CMDCLIENT
|
| 83 |
+
{
|
| 84 |
+
/** The client's ID. */
|
| 85 |
+
int client_id;
|
| 86 |
+
/** The HGCM command to execute. */
|
| 87 |
+
int cmd;
|
| 88 |
+
/** Number of parameters. */
|
| 89 |
+
int num_parms;
|
| 90 |
+
/** The actual parameters. */
|
| 91 |
+
const PVBOXHGCMSVCPARM parms;
|
| 92 |
+
/** The desired return value from the host. */
|
| 93 |
+
int rc;
|
| 94 |
+
} CMDCLIENT, *PCMDCLIENT;
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Tests the HOST_EXEC_CMD function.
|
| 98 |
+
* @returns iprt status value to indicate whether the test went as expected.
|
| 99 |
+
* @note prints its own diagnostic information to stdout.
|
| 100 |
+
*/
|
| 101 |
+
static int testHostCmd(const VBOXHGCMSVCFNTABLE *pTable, const PCMDHOST pCmd, uint32_t uNumTests)
|
| 102 |
+
{
|
| 103 |
+
int rc = VINF_SUCCESS;
|
| 104 |
+
if (!VALID_PTR(pTable->pfnHostCall))
|
| 105 |
+
{
|
| 106 |
+
RTTestPrintf(g_hTest, RTTESTLVL_FAILURE, "Invalid pfnHostCall() pointer\n");
|
| 107 |
+
rc = VERR_INVALID_POINTER;
|
| 108 |
+
}
|
| 109 |
+
if (RT_SUCCESS(rc))
|
| 110 |
+
{
|
| 111 |
+
for (unsigned i = 0; (i < uNumTests) && RT_SUCCESS(rc); i++)
|
| 112 |
+
{
|
| 113 |
+
RTTestPrintf(g_hTest, RTTESTLVL_INFO, "Testing #%u (cmd: %d, num_parms: %d, parms: 0x%p\n",
|
| 114 |
+
i, pCmd[i].cmd, pCmd[i].num_parms, pCmd[i].parms);
|
| 115 |
+
|
| 116 |
+
if (pCmd[i].fNeedsClient)
|
| 117 |
+
{
|
| 118 |
+
int client_rc = pTable->pfnConnect(pTable->pvService, 1000 /* Client ID */, NULL /* pvClient */);
|
| 119 |
+
if (RT_FAILURE(client_rc))
|
| 120 |
+
rc = client_rc;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
if (RT_SUCCESS(rc))
|
| 124 |
+
{
|
| 125 |
+
int host_rc = pTable->pfnHostCall(pTable->pvService,
|
| 126 |
+
pCmd[i].cmd,
|
| 127 |
+
pCmd[i].num_parms,
|
| 128 |
+
pCmd[i].parms);
|
| 129 |
+
if (host_rc != pCmd[i].rc)
|
| 130 |
+
{
|
| 131 |
+
RTTestPrintf(g_hTest, RTTESTLVL_FAILURE, "Host call test #%u returned with rc=%Rrc instead of rc=%Rrc\n",
|
| 132 |
+
i, host_rc, pCmd[i].rc);
|
| 133 |
+
rc = host_rc;
|
| 134 |
+
if (RT_SUCCESS(rc))
|
| 135 |
+
rc = VERR_INVALID_PARAMETER;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
if (pCmd[i].fNeedsClient)
|
| 139 |
+
{
|
| 140 |
+
int client_rc = pTable->pfnDisconnect(pTable->pvService, 1000 /* Client ID */, NULL /* pvClient */);
|
| 141 |
+
if (RT_SUCCESS(rc))
|
| 142 |
+
rc = client_rc;
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
return rc;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
static int testHost(const VBOXHGCMSVCFNTABLE *pTable)
|
| 151 |
+
{
|
| 152 |
+
RTTestSub(g_hTest, "Testing host commands ...");
|
| 153 |
+
|
| 154 |
+
static VBOXHGCMSVCPARM s_aParms[1];
|
| 155 |
+
s_aParms[0].setUInt32(1000 /* Context ID */);
|
| 156 |
+
|
| 157 |
+
static CMDHOST s_aCmdHostAll[] =
|
| 158 |
+
{
|
| 159 |
+
/** No client connected, invalid command. */
|
| 160 |
+
{ 1024 /* Not existing command */, 0, 0, false, VERR_NOT_SUPPORTED },
|
| 161 |
+
{ -1 /* Invalid command */, 0, 0, false, VERR_NOT_SUPPORTED },
|
| 162 |
+
{ HOST_CANCEL_PENDING_WAITS, 1024, 0, false, VERR_NOT_FOUND },
|
| 163 |
+
{ HOST_CANCEL_PENDING_WAITS, 0, &s_aParms[0], false, VERR_NOT_FOUND },
|
| 164 |
+
|
| 165 |
+
/** No client connected, valid command. */
|
| 166 |
+
{ HOST_CANCEL_PENDING_WAITS, 0, 0, false, VERR_NOT_FOUND },
|
| 167 |
+
|
| 168 |
+
/** Client connected. */
|
| 169 |
+
{ 1024 /* Not existing command */, 0, 0, true, VERR_NOT_SUPPORTED },
|
| 170 |
+
{ -1 /* Invalid command */, 0, 0, true, VERR_NOT_SUPPORTED },
|
| 171 |
+
|
| 172 |
+
/** Client connected, valid parameters given. */
|
| 173 |
+
{ HOST_CANCEL_PENDING_WAITS, 0, 0, true, VINF_SUCCESS },
|
| 174 |
+
{ HOST_CANCEL_PENDING_WAITS, 1024, &s_aParms[0], true, VINF_SUCCESS },
|
| 175 |
+
{ HOST_CANCEL_PENDING_WAITS, 0, &s_aParms[0], true, VINF_SUCCESS},
|
| 176 |
+
|
| 177 |
+
/** Client connected, invalid parameters given. */
|
| 178 |
+
{ HOST_CANCEL_PENDING_WAITS, 1024, 0, true, VERR_INVALID_POINTER },
|
| 179 |
+
{ HOST_CANCEL_PENDING_WAITS, 1, 0, true, VERR_INVALID_POINTER },
|
| 180 |
+
{ HOST_CANCEL_PENDING_WAITS, -1, 0, true, VERR_INVALID_POINTER },
|
| 181 |
+
|
| 182 |
+
/** Client connected, parameters given. */
|
| 183 |
+
{ HOST_CANCEL_PENDING_WAITS, 1, &s_aParms[0], true, VINF_SUCCESS },
|
| 184 |
+
{ HOST_EXEC_CMD, 1, &s_aParms[0], true, VINF_SUCCESS },
|
| 185 |
+
{ HOST_EXEC_SET_INPUT, 1, &s_aParms[0], true, VINF_SUCCESS },
|
| 186 |
+
{ HOST_EXEC_GET_OUTPUT, 1, &s_aParms[0], true, VINF_SUCCESS }
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
int rc = testHostCmd(pTable, &s_aCmdHostAll[0], RT_ELEMENTS(s_aCmdHostAll));
|
| 190 |
+
RTTestSubDone(g_hTest);
|
| 191 |
+
return rc;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
static int testClient(const VBOXHGCMSVCFNTABLE *pTable)
|
| 195 |
+
{
|
| 196 |
+
RTTestSub(g_hTest, "Testing client commands ...");
|
| 197 |
+
|
| 198 |
+
int rc = pTable->pfnConnect(pTable->pvService, 1 /* Client ID */, NULL /* pvClient */);
|
| 199 |
+
if (RT_SUCCESS(rc))
|
| 200 |
+
{
|
| 201 |
+
VBOXHGCMCALLHANDLE_TYPEDEF callHandle = { VINF_SUCCESS };
|
| 202 |
+
|
| 203 |
+
/* No commands from host yet. */
|
| 204 |
+
static VBOXHGCMSVCPARM s_aParmsGuest[8];
|
| 205 |
+
pTable->pfnCall(pTable->pvService, &callHandle, 1 /* Client ID */, NULL /* pvClient */,
|
| 206 |
+
GUEST_GET_HOST_MSG, 2, &s_aParmsGuest[0]);
|
| 207 |
+
RTTEST_CHECK_RC_RET(g_hTest, callHandle.rc, VINF_SUCCESS, callHandle.rc);
|
| 208 |
+
|
| 209 |
+
/* Host: Add a dummy command. */
|
| 210 |
+
static VBOXHGCMSVCPARM s_aParmsHost[8];
|
| 211 |
+
s_aParmsHost[0].setUInt32(1000 /* Context ID */);
|
| 212 |
+
s_aParmsHost[1].setString("foo.bar");
|
| 213 |
+
|
| 214 |
+
rc = pTable->pfnHostCall(pTable->pvService, HOST_EXEC_CMD, 2, &s_aParmsHost[0]);
|
| 215 |
+
RTTEST_CHECK_RC_RET(g_hTest, rc, VINF_SUCCESS, rc);
|
| 216 |
+
|
| 217 |
+
/* Client: Get host command with a invalid parameter count specified. */
|
| 218 |
+
pTable->pfnCall(pTable->pvService, &callHandle, 1 /* Client ID */, NULL /* pvClient */,
|
| 219 |
+
GUEST_GET_HOST_MSG, 1024, &s_aParmsGuest[0]);
|
| 220 |
+
RTTEST_CHECK_RC_RET(g_hTest, callHandle.rc, VERR_INVALID_PARAMETER, callHandle.rc);
|
| 221 |
+
pTable->pfnCall(pTable->pvService, &callHandle, 1 /* Client ID */, NULL /* pvClient */,
|
| 222 |
+
GUEST_GET_HOST_MSG, -1, &s_aParmsGuest[0]);
|
| 223 |
+
RTTEST_CHECK_RC_RET(g_hTest, callHandle.rc, VERR_INVALID_PARAMETER, callHandle.rc);
|
| 224 |
+
pTable->pfnCall(pTable->pvService, &callHandle, 1 /* Client ID */, NULL /* pvClient */,
|
| 225 |
+
GUEST_GET_HOST_MSG, -1, NULL);
|
| 226 |
+
RTTEST_CHECK_RC_RET(g_hTest, callHandle.rc, VERR_INVALID_PARAMETER, callHandle.rc);
|
| 227 |
+
pTable->pfnCall(pTable->pvService, &callHandle, 1 /* Client ID */, NULL /* pvClient */,
|
| 228 |
+
GUEST_GET_HOST_MSG, 16, NULL);
|
| 229 |
+
RTTEST_CHECK_RC_RET(g_hTest, callHandle.rc, VERR_INVALID_PARAMETER, callHandle.rc);
|
| 230 |
+
|
| 231 |
+
/* Client: Get host command with a too small HGCM array. */
|
| 232 |
+
pTable->pfnCall(pTable->pvService, &callHandle, 1 /* Client ID */, NULL /* pvClient */,
|
| 233 |
+
GUEST_GET_HOST_MSG, 0, &s_aParmsGuest[0]);
|
| 234 |
+
RTTEST_CHECK_RC_RET(g_hTest, callHandle.rc, VERR_TOO_MUCH_DATA, callHandle.rc);
|
| 235 |
+
pTable->pfnCall(pTable->pvService, &callHandle, 1 /* Client ID */, NULL /* pvClient */,
|
| 236 |
+
GUEST_GET_HOST_MSG, 1, &s_aParmsGuest[0]);
|
| 237 |
+
RTTEST_CHECK_RC_RET(g_hTest, callHandle.rc, VERR_TOO_MUCH_DATA, callHandle.rc);
|
| 238 |
+
|
| 239 |
+
/* Client: Get host command without an allocated buffer. */
|
| 240 |
+
pTable->pfnCall(pTable->pvService, &callHandle, 1 /* Client ID */, NULL /* pvClient */,
|
| 241 |
+
GUEST_GET_HOST_MSG, 2, &s_aParmsGuest[0]);
|
| 242 |
+
RTTEST_CHECK_RC_RET(g_hTest, callHandle.rc, VERR_BUFFER_OVERFLOW, callHandle.rc);
|
| 243 |
+
|
| 244 |
+
/* Client: Get host command, this time with a valid buffer. */
|
| 245 |
+
char szBuf[16];
|
| 246 |
+
s_aParmsGuest[1].setPointer(szBuf, sizeof(szBuf));
|
| 247 |
+
pTable->pfnCall(pTable->pvService, &callHandle, 1 /* Client ID */, NULL /* pvClient */,
|
| 248 |
+
GUEST_GET_HOST_MSG, 2, &s_aParmsGuest[0]);
|
| 249 |
+
RTTEST_CHECK_RC_RET(g_hTest, callHandle.rc, VINF_SUCCESS, callHandle.rc);
|
| 250 |
+
|
| 251 |
+
/* Client: Now make sure there's no host message left anymore. */
|
| 252 |
+
pTable->pfnCall(pTable->pvService, &callHandle, 1 /* Client ID */, NULL /* pvClient */,
|
| 253 |
+
GUEST_GET_HOST_MSG, 2, &s_aParmsGuest[0]);
|
| 254 |
+
RTTEST_CHECK_RC_RET(g_hTest, callHandle.rc, VINF_SUCCESS, callHandle.rc);
|
| 255 |
+
|
| 256 |
+
/* Client: Disconnect again. */
|
| 257 |
+
int rc2 = pTable->pfnDisconnect(pTable->pvService, 1000 /* Client ID */, NULL /* pvClient */);
|
| 258 |
+
if (RT_SUCCESS(rc))
|
| 259 |
+
rc = rc2;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
RTTestSubDone(g_hTest);
|
| 263 |
+
return rc;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
/*
|
| 267 |
+
* Set environment variable "IPRT_TEST_MAX_LEVEL=all" to get more debug output!
|
| 268 |
+
*/
|
| 269 |
+
int main(int argc, char **argv)
|
| 270 |
+
{
|
| 271 |
+
RTEXITCODE rcExit = RTTestInitAndCreate("tstGuestControlSvc", &g_hTest);
|
| 272 |
+
if (rcExit != RTEXITCODE_SUCCESS)
|
| 273 |
+
return rcExit;
|
| 274 |
+
RTTestBanner(g_hTest);
|
| 275 |
+
|
| 276 |
+
/* Some host info. */
|
| 277 |
+
RTTestIPrintf(RTTESTLVL_ALWAYS, "sizeof(void*)=%d\n", sizeof(void*));
|
| 278 |
+
|
| 279 |
+
/* Do the tests. */
|
| 280 |
+
VBOXHGCMSVCFNTABLE svcTable;
|
| 281 |
+
VBOXHGCMSVCHELPERS svcHelpers;
|
| 282 |
+
RTTEST_CHECK_RC_RET(g_hTest, initTable(&svcTable, &svcHelpers), VINF_SUCCESS, 1);
|
| 283 |
+
|
| 284 |
+
do
|
| 285 |
+
{
|
| 286 |
+
RTTESTI_CHECK_RC_BREAK(VBoxHGCMSvcLoad(&svcTable), VINF_SUCCESS);
|
| 287 |
+
|
| 288 |
+
RTTESTI_CHECK_RC_BREAK(testHost(&svcTable), VINF_SUCCESS);
|
| 289 |
+
|
| 290 |
+
RTTESTI_CHECK_RC_BREAK(svcTable.pfnUnload(svcTable.pvService), VINF_SUCCESS);
|
| 291 |
+
|
| 292 |
+
RTTESTI_CHECK_RC_BREAK(VBoxHGCMSvcLoad(&svcTable), VINF_SUCCESS);
|
| 293 |
+
|
| 294 |
+
RTTESTI_CHECK_RC_BREAK(testClient(&svcTable), VINF_SUCCESS);
|
| 295 |
+
|
| 296 |
+
RTTESTI_CHECK_RC_BREAK(svcTable.pfnUnload(svcTable.pvService), VINF_SUCCESS);
|
| 297 |
+
|
| 298 |
+
} while (0);
|
| 299 |
+
|
| 300 |
+
return RTTestSummaryAndDestroy(g_hTest);
|
| 301 |
+
}
|
| 302 |
+
|
pool/shard011/C++/0118410_compute_pair.cpp
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* ----------------------------------------------------------------------
|
| 2 |
+
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
| 3 |
+
http://lammps.sandia.gov, Sandia National Laboratories
|
| 4 |
+
Steve Plimpton, sjplimp@sandia.gov
|
| 5 |
+
|
| 6 |
+
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
| 7 |
+
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
| 8 |
+
certain rights in this software. This software is distributed under
|
| 9 |
+
the GNU General Public License.
|
| 10 |
+
|
| 11 |
+
See the README file in the top-level LAMMPS directory.
|
| 12 |
+
------------------------------------------------------------------------- */
|
| 13 |
+
|
| 14 |
+
#include <mpi.h>
|
| 15 |
+
#include <cstring>
|
| 16 |
+
#include "compute_pair.h"
|
| 17 |
+
#include "update.h"
|
| 18 |
+
#include "force.h"
|
| 19 |
+
#include "pair.h"
|
| 20 |
+
#include "error.h"
|
| 21 |
+
|
| 22 |
+
using namespace LAMMPS_NS;
|
| 23 |
+
|
| 24 |
+
enum{EPAIR,EVDWL,ECOUL};
|
| 25 |
+
|
| 26 |
+
/* ---------------------------------------------------------------------- */
|
| 27 |
+
|
| 28 |
+
ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) :
|
| 29 |
+
Compute(lmp, narg, arg),
|
| 30 |
+
pstyle(NULL), pair(NULL), one(NULL)
|
| 31 |
+
{
|
| 32 |
+
if (narg < 4 || narg > 5) error->all(FLERR,"Illegal compute pair command");
|
| 33 |
+
|
| 34 |
+
scalar_flag = 1;
|
| 35 |
+
extscalar = 1;
|
| 36 |
+
peflag = 1;
|
| 37 |
+
timeflag = 1;
|
| 38 |
+
|
| 39 |
+
int n = strlen(arg[3]) + 1;
|
| 40 |
+
if (lmp->suffix) n += strlen(lmp->suffix) + 1;
|
| 41 |
+
pstyle = new char[n];
|
| 42 |
+
strcpy(pstyle,arg[3]);
|
| 43 |
+
|
| 44 |
+
if (narg == 5) {
|
| 45 |
+
if (strcmp(arg[4],"epair") == 0) evalue = EPAIR;
|
| 46 |
+
if (strcmp(arg[4],"evdwl") == 0) evalue = EVDWL;
|
| 47 |
+
if (strcmp(arg[4],"ecoul") == 0) evalue = ECOUL;
|
| 48 |
+
} else evalue = EPAIR;
|
| 49 |
+
|
| 50 |
+
// check if pair style with and without suffix exists
|
| 51 |
+
|
| 52 |
+
pair = force->pair_match(pstyle,1);
|
| 53 |
+
if (!pair && lmp->suffix) {
|
| 54 |
+
strcat(pstyle,"/");
|
| 55 |
+
strcat(pstyle,lmp->suffix);
|
| 56 |
+
pair = force->pair_match(pstyle,1);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (!pair)
|
| 60 |
+
error->all(FLERR,"Unrecognized pair style in compute pair command");
|
| 61 |
+
npair = pair->nextra;
|
| 62 |
+
|
| 63 |
+
if (npair) {
|
| 64 |
+
vector_flag = 1;
|
| 65 |
+
size_vector = npair;
|
| 66 |
+
extvector = 1;
|
| 67 |
+
one = new double[npair];
|
| 68 |
+
vector = new double[npair];
|
| 69 |
+
} else one = vector = NULL;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/* ---------------------------------------------------------------------- */
|
| 73 |
+
|
| 74 |
+
ComputePair::~ComputePair()
|
| 75 |
+
{
|
| 76 |
+
delete [] pstyle;
|
| 77 |
+
delete [] one;
|
| 78 |
+
delete [] vector;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/* ---------------------------------------------------------------------- */
|
| 82 |
+
|
| 83 |
+
void ComputePair::init()
|
| 84 |
+
{
|
| 85 |
+
// recheck for pair style in case it has been deleted
|
| 86 |
+
|
| 87 |
+
pair = force->pair_match(pstyle,1);
|
| 88 |
+
if (!pair)
|
| 89 |
+
error->all(FLERR,"Unrecognized pair style in compute pair command");
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/* ---------------------------------------------------------------------- */
|
| 93 |
+
|
| 94 |
+
double ComputePair::compute_scalar()
|
| 95 |
+
{
|
| 96 |
+
invoked_scalar = update->ntimestep;
|
| 97 |
+
if (update->eflag_global != invoked_scalar)
|
| 98 |
+
error->all(FLERR,"Energy was not tallied on needed timestep");
|
| 99 |
+
|
| 100 |
+
double eng;
|
| 101 |
+
if (evalue == EPAIR) eng = pair->eng_vdwl + pair->eng_coul;
|
| 102 |
+
else if (evalue == EVDWL) eng = pair->eng_vdwl;
|
| 103 |
+
else if (evalue == ECOUL) eng = pair->eng_coul;
|
| 104 |
+
|
| 105 |
+
MPI_Allreduce(&eng,&scalar,1,MPI_DOUBLE,MPI_SUM,world);
|
| 106 |
+
return scalar;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/* ---------------------------------------------------------------------- */
|
| 110 |
+
|
| 111 |
+
void ComputePair::compute_vector()
|
| 112 |
+
{
|
| 113 |
+
invoked_vector = update->ntimestep;
|
| 114 |
+
if (update->eflag_global != invoked_vector)
|
| 115 |
+
error->all(FLERR,"Energy was not tallied on needed timestep");
|
| 116 |
+
|
| 117 |
+
for (int i = 0; i < npair; i++)
|
| 118 |
+
one[i] = pair->pvector[i];
|
| 119 |
+
MPI_Allreduce(one,vector,npair,MPI_DOUBLE,MPI_SUM,world);
|
| 120 |
+
}
|
pool/shard011/C++/0118412_main.cpp
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/****************************************************************************
|
| 2 |
+
**
|
| 3 |
+
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
| 4 |
+
** Contact: http://www.qt-project.org/legal
|
| 5 |
+
**
|
| 6 |
+
** This file is part of the documentation of the Qt Toolkit.
|
| 7 |
+
**
|
| 8 |
+
** $QT_BEGIN_LICENSE:BSD$
|
| 9 |
+
** You may use this file under the terms of the BSD license as follows:
|
| 10 |
+
**
|
| 11 |
+
** "Redistribution and use in source and binary forms, with or without
|
| 12 |
+
** modification, are permitted provided that the following conditions are
|
| 13 |
+
** met:
|
| 14 |
+
** * Redistributions of source code must retain the above copyright
|
| 15 |
+
** notice, this list of conditions and the following disclaimer.
|
| 16 |
+
** * Redistributions in binary form must reproduce the above copyright
|
| 17 |
+
** notice, this list of conditions and the following disclaimer in
|
| 18 |
+
** the documentation and/or other materials provided with the
|
| 19 |
+
** distribution.
|
| 20 |
+
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
| 21 |
+
** of its contributors may be used to endorse or promote products derived
|
| 22 |
+
** from this software without specific prior written permission.
|
| 23 |
+
**
|
| 24 |
+
**
|
| 25 |
+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 26 |
+
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 27 |
+
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 28 |
+
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 29 |
+
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 30 |
+
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 31 |
+
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 32 |
+
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 33 |
+
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 34 |
+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 35 |
+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
| 36 |
+
**
|
| 37 |
+
** $QT_END_LICENSE$
|
| 38 |
+
**
|
| 39 |
+
****************************************************************************/
|
| 40 |
+
|
| 41 |
+
#include <QtGui>
|
| 42 |
+
|
| 43 |
+
int main(int argc, char *argv[])
|
| 44 |
+
{
|
| 45 |
+
QApplication app(argc, argv);
|
| 46 |
+
QWidget *window = new QWidget();
|
| 47 |
+
//! [create, lay out widgets and show]
|
| 48 |
+
QLabel *label = new QLabel(tr("Name:"));
|
| 49 |
+
QLineEdit *lineEdit = new QLineEdit();
|
| 50 |
+
|
| 51 |
+
QHBoxLayout *layout = new QHBoxLayout();
|
| 52 |
+
layout->addWidget(label);
|
| 53 |
+
layout->addWidget(lineEdit);
|
| 54 |
+
window->setLayout(layout);
|
| 55 |
+
//! [create, lay out widgets and show]
|
| 56 |
+
window->setWindowTitle(tr("Window layout"));
|
| 57 |
+
window->show();
|
| 58 |
+
return app.exec();
|
| 59 |
+
}
|
pool/shard011/C++/0118413_main.cpp
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/* ========================================
|
| 3 |
+
|
| 4 |
+
* File Name : main.cpp
|
| 5 |
+
|
| 6 |
+
* Creation Date : 25-08-2015
|
| 7 |
+
|
| 8 |
+
* Last Modified : Sat 17 Oct 2015 03:54:10 PM CEST
|
| 9 |
+
|
| 10 |
+
* Created By : Karel Ha <mathemage@gmail.com>
|
| 11 |
+
|
| 12 |
+
==========================================*/
|
| 13 |
+
|
| 14 |
+
#include "commons.h"
|
| 15 |
+
#include "utils.h"
|
| 16 |
+
#include <cassert>
|
| 17 |
+
|
| 18 |
+
// default values from configuration for LHCb Upgrade 2
|
| 19 |
+
long long number_of_iterations = 1000;
|
| 20 |
+
long long chunk_size = 2000000;
|
| 21 |
+
long long number_of_chunks = 500;
|
| 22 |
+
tbb::tick_count tick, tock;
|
| 23 |
+
void *source, *destination;
|
| 24 |
+
bool verbose_enabled = false;
|
| 25 |
+
int nthreads = 0;
|
| 26 |
+
|
| 27 |
+
vector<double> iteration_times;
|
| 28 |
+
|
| 29 |
+
// returns the duration of one iteration (in seconds)
|
| 30 |
+
double stopwatch_an_iteration() {
|
| 31 |
+
tick = tbb::tick_count::now();
|
| 32 |
+
|
| 33 |
+
if (nthreads > 0) {
|
| 34 |
+
if (verbose_enabled) {
|
| 35 |
+
printf("Starting an iteration with %d threads...\n", nthreads);
|
| 36 |
+
}
|
| 37 |
+
#pragma omp parallel for num_threads(nthreads)
|
| 38 |
+
for (long long ni = 0; ni < number_of_chunks; ni++) {
|
| 39 |
+
memcpy(destination + ni * chunk_size, source + ni * chunk_size, chunk_size);
|
| 40 |
+
}
|
| 41 |
+
} else {
|
| 42 |
+
if (verbose_enabled) {
|
| 43 |
+
printf("Starting an iteration using dynamic team...\n");
|
| 44 |
+
}
|
| 45 |
+
#pragma omp parallel for
|
| 46 |
+
for (long long ni = 0; ni < number_of_chunks; ni++) {
|
| 47 |
+
memcpy(destination + ni * chunk_size, source + ni * chunk_size, chunk_size);
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
tock = tbb::tick_count::now();
|
| 52 |
+
return (tock-tick).seconds();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
int main(int argc, char *argv[]) {
|
| 57 |
+
/* ------------------------------------------------------------------------ */
|
| 58 |
+
/* PARSING ARGUMENTS */
|
| 59 |
+
int opt;
|
| 60 |
+
|
| 61 |
+
while ((opt = getopt(argc, argv, ":vi:c:n::ht:")) != -1) {
|
| 62 |
+
switch (opt) {
|
| 63 |
+
case 'i':
|
| 64 |
+
number_of_iterations = get_argument_long_value(optarg, "-i");
|
| 65 |
+
if (number_of_iterations < 1) {
|
| 66 |
+
fprintf(stderr, "Invalid number of iterations: enter positive integer!\n");
|
| 67 |
+
exit(EXIT_FAILURE);
|
| 68 |
+
}
|
| 69 |
+
break;
|
| 70 |
+
case 'c':
|
| 71 |
+
chunk_size = get_argument_long_value(optarg, "-c");
|
| 72 |
+
break;
|
| 73 |
+
case 'n':
|
| 74 |
+
number_of_chunks = get_argument_long_value(optarg, "-n");
|
| 75 |
+
break;
|
| 76 |
+
case 'v':
|
| 77 |
+
printf("Verbose mode enabled!\n");
|
| 78 |
+
verbose_enabled = true;
|
| 79 |
+
break;
|
| 80 |
+
case 't':
|
| 81 |
+
nthreads = get_argument_long_value(optarg, "-t");
|
| 82 |
+
break;
|
| 83 |
+
case 'h':
|
| 84 |
+
printf("Usage: %s", argv[0]);
|
| 85 |
+
printf(" [-i number_of_iterations] [-c chunk_size in bytes] [-n number_of_chunks] [-v enable_verbose_mode]");
|
| 86 |
+
printf("\n");
|
| 87 |
+
exit(EXIT_SUCCESS);
|
| 88 |
+
default:
|
| 89 |
+
fprintf(stderr, "Usage: %s", argv[0]);
|
| 90 |
+
fprintf(stderr, " [-i number_of_iterations] [-c chunk_size in bytes] [-n number_of_chunks] [-v enable_verbose_mode]");
|
| 91 |
+
fprintf(stderr, "\n");
|
| 92 |
+
exit(EXIT_FAILURE);
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
/* ------------------------------------------------------------------------ */
|
| 96 |
+
|
| 97 |
+
bool checkable = number_of_iterations * number_of_chunks * chunk_size < 1000000000;
|
| 98 |
+
|
| 99 |
+
iteration_times.assign(number_of_iterations, 0);
|
| 100 |
+
double total_time = 0;
|
| 101 |
+
|
| 102 |
+
source = try_calloc(number_of_chunks, chunk_size);
|
| 103 |
+
destination = try_calloc(number_of_chunks, chunk_size);
|
| 104 |
+
|
| 105 |
+
#pragma omp parallel
|
| 106 |
+
{
|
| 107 |
+
#pragma omp master
|
| 108 |
+
if (verbose_enabled) {
|
| 109 |
+
printf("Max. %d threads available\n", omp_get_num_threads());
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// initial iteration won't be included in the benchmarks
|
| 114 |
+
double initial_time = stopwatch_an_iteration();
|
| 115 |
+
for (long long i = 0; i < number_of_iterations; i++) {
|
| 116 |
+
if (verbose_enabled) {
|
| 117 |
+
printf("Iteration #%d: ", i+1);
|
| 118 |
+
}
|
| 119 |
+
total_time += (iteration_times[i] = stopwatch_an_iteration());
|
| 120 |
+
if (verbose_enabled && checkable) {
|
| 121 |
+
assert(0 == memcmp(source, destination, number_of_chunks * chunk_size));
|
| 122 |
+
printf("Iteration #%d has been verified successfully...\n", i+1);
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
printf("\n______________STATISTICS OF THROUGHPUTS (in GBps)______________\n");
|
| 127 |
+
printf("The initial iteration: %.5f secs\n", initial_time);
|
| 128 |
+
create_histogram(iteration_times);
|
| 129 |
+
printf("_______________________________________________________________\n");
|
| 130 |
+
|
| 131 |
+
printf("\n____________________________SUMMARY____________________________\n");
|
| 132 |
+
printf("Total time: %g secs\n", total_time);
|
| 133 |
+
|
| 134 |
+
const unsigned long long bytes_in_gb = 1000000000;
|
| 135 |
+
const double total_elements = number_of_iterations * number_of_chunks * chunk_size;
|
| 136 |
+
const double total_size = total_elements / bytes_in_gb;
|
| 137 |
+
printf("Total size: %g GB\n", total_size);
|
| 138 |
+
|
| 139 |
+
printf("Throughput: %g GBps\n", total_size / total_time);
|
| 140 |
+
printf("_______________________________________________________________\n");
|
| 141 |
+
return 0;
|
| 142 |
+
}
|
pool/shard011/C++/0118414_6.23.cpp
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* =====================================================================================
|
| 3 |
+
*
|
| 4 |
+
* Filename: 6.23.cpp
|
| 5 |
+
*
|
| 6 |
+
* Description:
|
| 7 |
+
*
|
| 8 |
+
* Version: 1.0
|
| 9 |
+
* Created: 2015年10月21日 11时16分45秒
|
| 10 |
+
* Revision: none
|
| 11 |
+
* Compiler: gcc
|
| 12 |
+
*
|
| 13 |
+
* Author: sun lianqiang (milton), 170262941@qq.com
|
| 14 |
+
* Company: Giant
|
| 15 |
+
*
|
| 16 |
+
* =====================================================================================
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
/*************************************************************************
|
| 20 |
+
> File Name: 6/6.23.cpp
|
| 21 |
+
> Author: ma6174
|
| 22 |
+
> Mail: ma6174@163.com
|
| 23 |
+
> Created Time: 2015年10月21日 星期三 11时16分45秒
|
| 24 |
+
************************************************************************/
|
| 25 |
+
|
| 26 |
+
#include<iostream>
|
| 27 |
+
using namespace std;
|
| 28 |
+
|
| 29 |
+
/*
|
| 30 |
+
* === FUNCTION ======================================================================
|
| 31 |
+
* Name: print
|
| 32 |
+
* Description:
|
| 33 |
+
* =====================================================================================
|
| 34 |
+
*/
|
| 35 |
+
void print (const int *pi)
|
| 36 |
+
{
|
| 37 |
+
cout << *pi <<endl;
|
| 38 |
+
return ;
|
| 39 |
+
} /* ----- end of function print ----- */
|
| 40 |
+
|
| 41 |
+
void print1 (const int *beg, const int *end)
|
| 42 |
+
{
|
| 43 |
+
while(beg != end)
|
| 44 |
+
{
|
| 45 |
+
cout << *beg++ << " ";
|
| 46 |
+
}
|
| 47 |
+
cout << endl;
|
| 48 |
+
return ;
|
| 49 |
+
} /* ----- end of function print1 ----- */
|
| 50 |
+
int main ( int argc, char *argv[] )
|
| 51 |
+
{
|
| 52 |
+
int i = 0, j[2] = {
|
| 53 |
+
0, 1
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
print(&i);
|
| 57 |
+
print1(begin(j), end(j));
|
| 58 |
+
|
| 59 |
+
return 0;
|
| 60 |
+
} /* ---------- end of function main ---------- */
|
pool/shard011/C++/0118415_coro.cc
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <yamail/resource_pool/async/pool.hpp>
|
| 2 |
+
|
| 3 |
+
#include <fstream>
|
| 4 |
+
#include <iostream>
|
| 5 |
+
#include <thread>
|
| 6 |
+
#include <memory>
|
| 7 |
+
|
| 8 |
+
using ofstream_pool = yamail::resource_pool::async::pool<std::unique_ptr<std::ofstream>>;
|
| 9 |
+
using time_traits = yamail::resource_pool::time_traits;
|
| 10 |
+
|
| 11 |
+
int main() {
|
| 12 |
+
boost::asio::io_context service;
|
| 13 |
+
ofstream_pool pool(1, 10);
|
| 14 |
+
boost::asio::spawn(service, [&](boost::asio::yield_context yield){
|
| 15 |
+
boost::system::error_code ec;
|
| 16 |
+
auto handle = pool.get_auto_waste(service, yield[ec], time_traits::duration::max());
|
| 17 |
+
if (ec) {
|
| 18 |
+
std::cout << "handle error: " << ec.message() << std::endl;
|
| 19 |
+
return;
|
| 20 |
+
}
|
| 21 |
+
std::cout << "got resource handle" << std::endl;
|
| 22 |
+
if (handle.empty()) {
|
| 23 |
+
auto file = std::make_unique<std::ofstream>("pool.log", std::ios::app);
|
| 24 |
+
if (!file->good()) {
|
| 25 |
+
std::cout << "open file pool.log error: " << file->rdstate() << std::endl;
|
| 26 |
+
return;
|
| 27 |
+
}
|
| 28 |
+
handle.reset(std::move(file));
|
| 29 |
+
}
|
| 30 |
+
*(handle.get()) << (time_traits::time_point::min() - time_traits::now()).count() << std::endl;
|
| 31 |
+
if (handle.get()->good()) {
|
| 32 |
+
handle.recycle();
|
| 33 |
+
}
|
| 34 |
+
});
|
| 35 |
+
service.run();
|
| 36 |
+
return 0;
|
| 37 |
+
}
|
pool/shard011/C++/0118416_CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_83_bad.cpp
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_83_bad.cpp
|
| 3 |
+
Label Definition File: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806.label.xml
|
| 4 |
+
Template File: sources-sink-83_bad.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 122 Heap Based Buffer Overflow
|
| 9 |
+
* BadSource: Initialize data as a large string
|
| 10 |
+
* GoodSource: Initialize data as a small string
|
| 11 |
+
* Sinks: ncat
|
| 12 |
+
* BadSink : Copy data to string using strncat
|
| 13 |
+
* Flow Variant: 83 Data flow: data passed to class constructor and destructor by declaring the class object on the stack
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
#ifndef OMITBAD
|
| 17 |
+
|
| 18 |
+
#include "std_testcase.h"
|
| 19 |
+
#include "CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_83.h"
|
| 20 |
+
|
| 21 |
+
namespace CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_83
|
| 22 |
+
{
|
| 23 |
+
CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_83_bad::CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_83_bad(char * dataCopy)
|
| 24 |
+
{
|
| 25 |
+
data = dataCopy;
|
| 26 |
+
/* FLAW: Initialize data as a large buffer that is larger than the small buffer used in the sink */
|
| 27 |
+
memset(data, 'A', 100-1); /* fill with 'A's */
|
| 28 |
+
data[100-1] = '\0'; /* null terminate */
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_83_bad::~CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_83_bad()
|
| 32 |
+
{
|
| 33 |
+
{
|
| 34 |
+
char dest[50] = "";
|
| 35 |
+
/* POTENTIAL FLAW: Possible buffer overflow if data is larger than sizeof(dest)-strlen(dest)*/
|
| 36 |
+
strncat(dest, data, strlen(data));
|
| 37 |
+
dest[50-1] = '\0'; /* Ensure the destination buffer is null terminated */
|
| 38 |
+
printLine(data);
|
| 39 |
+
delete [] data;
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
#endif /* OMITBAD */
|
pool/shard011/C++/0118419_tde-menu.cpp
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* This file is part of the KDE libraries
|
| 2 |
+
* Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
|
| 3 |
+
*
|
| 4 |
+
* This library is free software; you can redistribute it and/or
|
| 5 |
+
* modify it under the terms of the GNU Library General Public
|
| 6 |
+
* License version 2 as published by the Free Software Foundation;
|
| 7 |
+
*
|
| 8 |
+
* This library is distributed in the hope that it will be useful,
|
| 9 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 10 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 11 |
+
* Library General Public License for more details.
|
| 12 |
+
*
|
| 13 |
+
* You should have received a copy of the GNU Library General Public License
|
| 14 |
+
* along with this library; see the file COPYING.LIB. If not, write to
|
| 15 |
+
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
| 16 |
+
* Boston, MA 02110-1301, USA.
|
| 17 |
+
**/
|
| 18 |
+
|
| 19 |
+
#include <stdlib.h>
|
| 20 |
+
|
| 21 |
+
#include <tqfile.h>
|
| 22 |
+
|
| 23 |
+
#include <dcopclient.h>
|
| 24 |
+
#include <dcopref.h>
|
| 25 |
+
|
| 26 |
+
#include "tdeaboutdata.h"
|
| 27 |
+
#include "tdeapplication.h"
|
| 28 |
+
#include "tdecmdlineargs.h"
|
| 29 |
+
#include "tdeglobal.h"
|
| 30 |
+
#include "tdelocale.h"
|
| 31 |
+
#include "kservice.h"
|
| 32 |
+
#include "kservicegroup.h"
|
| 33 |
+
#include "kstandarddirs.h"
|
| 34 |
+
|
| 35 |
+
static TDECmdLineOptions options[] = {
|
| 36 |
+
{ "utf8", I18N_NOOP("Output data in UTF-8 instead of local encoding"), 0 },
|
| 37 |
+
{ "print-menu-id", I18N_NOOP("Print menu-id of the menu that contains\nthe application"), 0 },
|
| 38 |
+
{ "print-menu-name", I18N_NOOP("Print menu name (caption) of the menu that\ncontains the application"), 0 },
|
| 39 |
+
{ "highlight", I18N_NOOP("Highlight the entry in the menu"), 0 },
|
| 40 |
+
{ "nocache-update", I18N_NOOP("Do not check if sycoca database is up to date"), 0 },
|
| 41 |
+
{ "+<application-id>", I18N_NOOP("The id of the menu entry to locate"), 0 },
|
| 42 |
+
TDECmdLineLastOption
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
static const char appName[] = "tde-menu";
|
| 46 |
+
static const char appVersion[] = "1.0";
|
| 47 |
+
static bool utf8;
|
| 48 |
+
|
| 49 |
+
static bool bPrintMenuId;
|
| 50 |
+
static bool bPrintMenuName;
|
| 51 |
+
static bool bHighlight;
|
| 52 |
+
|
| 53 |
+
static void result(const TQString &txt)
|
| 54 |
+
{
|
| 55 |
+
if (utf8)
|
| 56 |
+
puts( txt.utf8() );
|
| 57 |
+
else
|
| 58 |
+
puts( txt.local8Bit() );
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
static void error(int exitCode, const TQString &txt)
|
| 62 |
+
{
|
| 63 |
+
tqWarning("tde-menu: %s", txt.local8Bit().data());
|
| 64 |
+
exit(exitCode);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
static void findMenuEntry(KServiceGroup::Ptr parent, const TQString &name, const TQString &menuId)
|
| 68 |
+
{
|
| 69 |
+
KServiceGroup::List list = parent->entries(true, true, false);
|
| 70 |
+
KServiceGroup::List::ConstIterator it = list.begin();
|
| 71 |
+
for (; it != list.end(); ++it)
|
| 72 |
+
{
|
| 73 |
+
KSycocaEntry * e = *it;
|
| 74 |
+
|
| 75 |
+
if (e->isType(KST_KServiceGroup))
|
| 76 |
+
{
|
| 77 |
+
KServiceGroup::Ptr g(static_cast<KServiceGroup *>(e));
|
| 78 |
+
|
| 79 |
+
findMenuEntry(g, name.isEmpty() ? g->caption() : name+"/"+g->caption(), menuId);
|
| 80 |
+
}
|
| 81 |
+
else if (e->isType(KST_KService))
|
| 82 |
+
{
|
| 83 |
+
KService::Ptr s(static_cast<KService *>(e));
|
| 84 |
+
if (s->menuId() == menuId)
|
| 85 |
+
{
|
| 86 |
+
if (bPrintMenuId)
|
| 87 |
+
{
|
| 88 |
+
result(parent->relPath());
|
| 89 |
+
}
|
| 90 |
+
if (bPrintMenuName)
|
| 91 |
+
{
|
| 92 |
+
result(name);
|
| 93 |
+
}
|
| 94 |
+
if (bHighlight)
|
| 95 |
+
{
|
| 96 |
+
DCOPRef kicker( "kicker", "kicker" );
|
| 97 |
+
bool result = kicker.call( "highlightMenuItem", menuId );
|
| 98 |
+
if (!result)
|
| 99 |
+
error(3, TQString(i18n("Menu item '%1' could not be highlighted.").arg(menuId)).local8Bit());
|
| 100 |
+
}
|
| 101 |
+
exit(0);
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
int main(int argc, char **argv)
|
| 109 |
+
{
|
| 110 |
+
TDELocale::setMainCatalogue("tdelibs");
|
| 111 |
+
const char *description = I18N_NOOP("TDE Menu query tool.\n"
|
| 112 |
+
"This tool can be used to find in which menu a specific application is shown.\n"
|
| 113 |
+
"The --highlight option can be used to visually indicate to the user where\n"
|
| 114 |
+
"in the TDE menu a specific application is located.");
|
| 115 |
+
|
| 116 |
+
TDEAboutData d(appName, I18N_NOOP("tde-menu"), appVersion,
|
| 117 |
+
description,
|
| 118 |
+
TDEAboutData::License_GPL, "(c) 2003 Waldo Bastian");
|
| 119 |
+
d.addAuthor("Waldo Bastian", I18N_NOOP("Author"), "bastian@kde.org");
|
| 120 |
+
|
| 121 |
+
TDECmdLineArgs::init(argc, argv, &d);
|
| 122 |
+
TDECmdLineArgs::addCmdLineOptions(options);
|
| 123 |
+
|
| 124 |
+
// TDEApplication k(false, false);
|
| 125 |
+
TDEApplication k(false);
|
| 126 |
+
k.disableSessionManagement();
|
| 127 |
+
|
| 128 |
+
// this program is in tdelibs so it uses tdelibs as catalog
|
| 129 |
+
TDELocale::setMainCatalogue("tdelibs");
|
| 130 |
+
|
| 131 |
+
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
|
| 132 |
+
if (args->count() != 1)
|
| 133 |
+
TDECmdLineArgs::usage(i18n("You must specify an application-id such as 'tde-konsole.desktop'"));
|
| 134 |
+
|
| 135 |
+
utf8 = args->isSet("utf8");
|
| 136 |
+
|
| 137 |
+
bPrintMenuId = args->isSet("print-menu-id");
|
| 138 |
+
bPrintMenuName = args->isSet("print-menu-name");
|
| 139 |
+
bHighlight = args->isSet("highlight");
|
| 140 |
+
|
| 141 |
+
if (!bPrintMenuId && !bPrintMenuName && !bHighlight)
|
| 142 |
+
TDECmdLineArgs::usage(i18n("You must specify at least one of --print-menu-id, --print-menu-name or --highlight"));
|
| 143 |
+
|
| 144 |
+
if (args->isSet("cache-update"))
|
| 145 |
+
{
|
| 146 |
+
TQStringList args;
|
| 147 |
+
args.append("--incremental");
|
| 148 |
+
args.append("--checkstamps");
|
| 149 |
+
TQString command = "tdebuildsycoca";
|
| 150 |
+
TQCString _launcher = TDEApplication::launcher();
|
| 151 |
+
if (!DCOPRef(_launcher, _launcher).call("tdeinit_exec_wait", command, args).isValid())
|
| 152 |
+
{
|
| 153 |
+
tqWarning("Can't talk to tdelauncher!");
|
| 154 |
+
command = TDEGlobal::dirs()->findExe(command);
|
| 155 |
+
command += " " + args.join(" ");
|
| 156 |
+
system(command.local8Bit());
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
TQString menuId = TQFile::decodeName(args->arg(0));
|
| 161 |
+
KService::Ptr s = KService::serviceByMenuId(menuId);
|
| 162 |
+
|
| 163 |
+
if (!s)
|
| 164 |
+
error(1, i18n("No menu item '%1'.").arg(menuId));
|
| 165 |
+
|
| 166 |
+
findMenuEntry(KServiceGroup::root(), "", menuId);
|
| 167 |
+
|
| 168 |
+
error(2, i18n("Menu item '%1' not found in menu.").arg(menuId));
|
| 169 |
+
return 2;
|
| 170 |
+
}
|
| 171 |
+
|
pool/shard011/C++/0118420_transpose_op.cc
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright 2015 Google Inc. All Rights Reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
you may not use this file except in compliance with the License.
|
| 5 |
+
You may obtain a copy of the License at
|
| 6 |
+
|
| 7 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
|
| 9 |
+
Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
See the License for the specific language governing permissions and
|
| 13 |
+
limitations under the License.
|
| 14 |
+
==============================================================================*/
|
| 15 |
+
|
| 16 |
+
// See docs in ../ops/array_ops.cc.
|
| 17 |
+
|
| 18 |
+
#define EIGEN_USE_THREADS
|
| 19 |
+
|
| 20 |
+
#include "tensorflow/core/kernels/transpose_op.h"
|
| 21 |
+
|
| 22 |
+
#include "tensorflow/core/framework/op_kernel.h"
|
| 23 |
+
#include "tensorflow/core/framework/register_types.h"
|
| 24 |
+
#include "tensorflow/core/framework/tensor.h"
|
| 25 |
+
#include "tensorflow/core/framework/tensor_shape.h"
|
| 26 |
+
#include "tensorflow/core/kernels/transpose_op_functor.h"
|
| 27 |
+
#include "tensorflow/core/lib/core/status.h"
|
| 28 |
+
#include "tensorflow/core/lib/strings/str_util.h"
|
| 29 |
+
#include "tensorflow/core/platform/logging.h"
|
| 30 |
+
|
| 31 |
+
namespace tensorflow {
|
| 32 |
+
|
| 33 |
+
// inv = InvertPermutationOp(T<int32> p) takes a permutation of
|
| 34 |
+
// integers 0, 1, ..., n - 1 and returns the inverted
|
| 35 |
+
// permutation of p. I.e., inv[p[i]] == i, for i in [0 .. n).
|
| 36 |
+
//
|
| 37 |
+
// REQUIRES: input is a vector of int32.
|
| 38 |
+
// REQUIRES: input is a permutation of 0, 1, ..., n-1.
|
| 39 |
+
|
| 40 |
+
class InvertPermutationOp : public OpKernel {
|
| 41 |
+
public:
|
| 42 |
+
explicit InvertPermutationOp(OpKernelConstruction* context)
|
| 43 |
+
: OpKernel(context) {}
|
| 44 |
+
|
| 45 |
+
void Compute(OpKernelContext* context) override {
|
| 46 |
+
const Tensor& input = context->input(0);
|
| 47 |
+
OP_REQUIRES(
|
| 48 |
+
context, TensorShapeUtils::IsVector(input.shape()),
|
| 49 |
+
errors::InvalidArgument("invert_permutation expects a 1D vector."));
|
| 50 |
+
auto Tin = input.vec<int32>();
|
| 51 |
+
const int N = Tin.size();
|
| 52 |
+
Tensor* output = nullptr;
|
| 53 |
+
OP_REQUIRES_OK(context,
|
| 54 |
+
context->allocate_output(0, input.shape(), &output));
|
| 55 |
+
auto Tout = output->vec<int32>();
|
| 56 |
+
std::fill_n(Tout.data(), N, -1);
|
| 57 |
+
for (int i = 0; i < N; ++i) {
|
| 58 |
+
const int32 d = Tin(i);
|
| 59 |
+
OP_REQUIRES(context, 0 <= d && d < N,
|
| 60 |
+
errors::InvalidArgument(d, " is not between 0 and ", N));
|
| 61 |
+
OP_REQUIRES(context, Tout(d) == -1,
|
| 62 |
+
errors::InvalidArgument(d, " is duplicated in the input."));
|
| 63 |
+
Tout(d) = i;
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
REGISTER_KERNEL_BUILDER(Name("InvertPermutation").Device(DEVICE_CPU),
|
| 69 |
+
InvertPermutationOp);
|
| 70 |
+
|
| 71 |
+
REGISTER_KERNEL_BUILDER(Name("InvertPermutation")
|
| 72 |
+
.Device(DEVICE_GPU)
|
| 73 |
+
.HostMemory("x")
|
| 74 |
+
.HostMemory("y"),
|
| 75 |
+
InvertPermutationOp);
|
| 76 |
+
|
| 77 |
+
// output = TransposeOp(T<any> input, T<int32> perm) takes a tensor
|
| 78 |
+
// of type T and rank N, and a permutation of 0, 1, ..., N-1. It
|
| 79 |
+
// shuffles the dimensions of the input tensor according to permutation.
|
| 80 |
+
//
|
| 81 |
+
// Specifically, the returned tensor output meets the following condition:
|
| 82 |
+
// 1) output.dims() == input.dims();
|
| 83 |
+
// 2) output.dim_size(i) == input.dim_size(perm[i]);
|
| 84 |
+
// 3) output.tensor<T, N>(i_0, i_1, ..., i_N-1) ==
|
| 85 |
+
// input.tensor<T, N>(j_0, j_1, ..., j_N-1),
|
| 86 |
+
// where i_s == j_{perm[s]}
|
| 87 |
+
//
|
| 88 |
+
// REQUIRES: perm is a vector of int32.
|
| 89 |
+
// REQUIRES: input.dims() == perm.size().
|
| 90 |
+
// REQUIRES: perm is a permutation.
|
| 91 |
+
|
| 92 |
+
void TransposeOp::Compute(OpKernelContext* ctx) {
|
| 93 |
+
const Tensor& input = ctx->input(0);
|
| 94 |
+
const Tensor& perm = ctx->input(1);
|
| 95 |
+
// Preliminary validation of sizes.
|
| 96 |
+
OP_REQUIRES(ctx, TensorShapeUtils::IsVector(perm.shape()),
|
| 97 |
+
errors::InvalidArgument("perm must be a vector, not ",
|
| 98 |
+
perm.shape().DebugString()));
|
| 99 |
+
auto Vperm = perm.vec<int32>();
|
| 100 |
+
const int dims = input.dims();
|
| 101 |
+
static const int kMinDims = 0;
|
| 102 |
+
static const int kMaxDims = 10;
|
| 103 |
+
OP_REQUIRES(ctx, kMinDims <= dims && dims <= kMaxDims,
|
| 104 |
+
errors::Unimplemented("Transposing a tensor of rank ", dims,
|
| 105 |
+
" is not implemented."));
|
| 106 |
+
OP_REQUIRES(ctx, dims == Vperm.size(),
|
| 107 |
+
errors::InvalidArgument(
|
| 108 |
+
"transpose expects a vector of size ", input.dims(),
|
| 109 |
+
". But input(1) is a vector of size ", Vperm.size()));
|
| 110 |
+
gtl::ArraySlice<int32> permutation(
|
| 111 |
+
reinterpret_cast<const int32*>(Vperm.data()), dims);
|
| 112 |
+
TensorShape shape;
|
| 113 |
+
|
| 114 |
+
// Check whether permutation is a permutation of integers of [0 .. dims).
|
| 115 |
+
gtl::InlinedVector<bool, 8> bits(dims);
|
| 116 |
+
for (const int32 d : permutation) {
|
| 117 |
+
OP_REQUIRES(
|
| 118 |
+
ctx, 0 <= d && d < dims,
|
| 119 |
+
errors::InvalidArgument(d, " is out of range [0 .. ", dims, ")"));
|
| 120 |
+
bits[d] = true;
|
| 121 |
+
shape.AddDim(input.dim_size(d));
|
| 122 |
+
}
|
| 123 |
+
for (int i = 0; i < dims; ++i) {
|
| 124 |
+
OP_REQUIRES(ctx, bits[i], errors::InvalidArgument(
|
| 125 |
+
i, " is missing from {",
|
| 126 |
+
str_util::Join(permutation, ","), "}."));
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// 0-D and 1-D transposes do nothing
|
| 130 |
+
if (dims <= 1) {
|
| 131 |
+
ctx->set_output(0, input);
|
| 132 |
+
return;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
Tensor* output = nullptr;
|
| 136 |
+
OP_REQUIRES_OK(ctx, ctx->allocate_output(0, shape, &output));
|
| 137 |
+
if (shape.num_elements() > 0) {
|
| 138 |
+
OP_REQUIRES_OK(ctx, DoTranspose(ctx, input, permutation, output));
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
Status TransposeCpuOp::DoTranspose(OpKernelContext* ctx, const Tensor& in,
|
| 143 |
+
gtl::ArraySlice<int32> perm, Tensor* out) {
|
| 144 |
+
typedef Eigen::ThreadPoolDevice CPUDevice;
|
| 145 |
+
return ::tensorflow::DoTranspose(ctx->eigen_device<CPUDevice>(), in, perm,
|
| 146 |
+
out);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
#define REGISTER(T) \
|
| 150 |
+
REGISTER_KERNEL_BUILDER(Name("Transpose") \
|
| 151 |
+
.Device(DEVICE_CPU) \
|
| 152 |
+
.TypeConstraint<T>("T") \
|
| 153 |
+
.HostMemory("perm"), \
|
| 154 |
+
TransposeCpuOp);
|
| 155 |
+
TF_CALL_ALL_TYPES(REGISTER)
|
| 156 |
+
#undef REGISTER
|
| 157 |
+
|
| 158 |
+
#if GOOGLE_CUDA
|
| 159 |
+
Status TransposeGpuOp::DoTranspose(OpKernelContext* ctx, const Tensor& in,
|
| 160 |
+
gtl::ArraySlice<int32> perm, Tensor* out) {
|
| 161 |
+
typedef Eigen::GpuDevice GPUDevice;
|
| 162 |
+
return ::tensorflow::DoTranspose(ctx->eigen_device<GPUDevice>(), in, perm,
|
| 163 |
+
out);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
#define REGISTER(T) \
|
| 167 |
+
REGISTER_KERNEL_BUILDER(Name("Transpose") \
|
| 168 |
+
.Device(DEVICE_GPU) \
|
| 169 |
+
.TypeConstraint<T>("T") \
|
| 170 |
+
.HostMemory("perm"), \
|
| 171 |
+
TransposeGpuOp);
|
| 172 |
+
TF_CALL_NUMBER_TYPES(REGISTER);
|
| 173 |
+
#undef REGISTER
|
| 174 |
+
#endif
|
| 175 |
+
|
| 176 |
+
} // namespace tensorflow
|
pool/shard011/C++/0118421_measure_et_al_02.cc
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ---------------------------------------------------------------------
|
| 2 |
+
//
|
| 3 |
+
// Copyright (C) 2005 - 2014 by the deal.II authors
|
| 4 |
+
//
|
| 5 |
+
// This file is part of the deal.II library.
|
| 6 |
+
//
|
| 7 |
+
// The deal.II library is free software; you can use it, redistribute
|
| 8 |
+
// it, and/or modify it under the terms of the GNU Lesser General
|
| 9 |
+
// Public License as published by the Free Software Foundation; either
|
| 10 |
+
// version 2.1 of the License, or (at your option) any later version.
|
| 11 |
+
// The full text of the license can be found in the file LICENSE at
|
| 12 |
+
// the top level of the deal.II distribution.
|
| 13 |
+
//
|
| 14 |
+
// ---------------------------------------------------------------------
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
// Computes diameter, extent_in_direction, and minimum_vertex_distance on a variety of cells
|
| 18 |
+
|
| 19 |
+
#include "../tests.h"
|
| 20 |
+
#include <deal.II/grid/tria.h>
|
| 21 |
+
#include <deal.II/grid/tria_iterator.h>
|
| 22 |
+
#include <deal.II/grid/tria_accessor.h>
|
| 23 |
+
#include <deal.II/grid/grid_generator.h>
|
| 24 |
+
#include <fstream>
|
| 25 |
+
#include <iomanip>
|
| 26 |
+
|
| 27 |
+
#define PRECISION 5
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
template<int dim>
|
| 31 |
+
void create_triangulation(const unsigned int,
|
| 32 |
+
Triangulation<dim> &)
|
| 33 |
+
{
|
| 34 |
+
Assert(false, ExcNotImplemented());
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
template<>
|
| 39 |
+
void create_triangulation(const unsigned int case_no,
|
| 40 |
+
Triangulation<2> &tria)
|
| 41 |
+
{
|
| 42 |
+
switch (case_no)
|
| 43 |
+
{
|
| 44 |
+
case 0:
|
| 45 |
+
GridGenerator::hyper_cube(tria, 1., 3.);
|
| 46 |
+
break;
|
| 47 |
+
case 1:
|
| 48 |
+
{
|
| 49 |
+
GridGenerator::hyper_cube(tria, 1., 3.);
|
| 50 |
+
Point<2> &v0=tria.begin_active()->vertex(0);
|
| 51 |
+
v0(0) = 0.;
|
| 52 |
+
break;
|
| 53 |
+
}
|
| 54 |
+
case 2:
|
| 55 |
+
{
|
| 56 |
+
GridGenerator::hyper_cube(tria, 1., 3.);
|
| 57 |
+
Point<2> &v0=tria.begin_active()->vertex(0);
|
| 58 |
+
v0(0) = 0.;
|
| 59 |
+
Point<2> &v3=tria.begin_active()->vertex(3);
|
| 60 |
+
v3(0) = 4.;
|
| 61 |
+
break;
|
| 62 |
+
}
|
| 63 |
+
default:
|
| 64 |
+
Assert(false, ExcNotImplemented());
|
| 65 |
+
};
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
template<>
|
| 70 |
+
void create_triangulation(const unsigned int case_no,
|
| 71 |
+
Triangulation<3> &tria)
|
| 72 |
+
{
|
| 73 |
+
switch (case_no)
|
| 74 |
+
{
|
| 75 |
+
case 0:
|
| 76 |
+
GridGenerator::hyper_cube(tria, 1., 3.);
|
| 77 |
+
break;
|
| 78 |
+
case 1:
|
| 79 |
+
case 2:// like case 1
|
| 80 |
+
{
|
| 81 |
+
GridGenerator::hyper_cube(tria, 1., 3.);
|
| 82 |
+
Point<3> &v0=tria.begin_active()->vertex(0);
|
| 83 |
+
v0(0) = 0.;
|
| 84 |
+
break;
|
| 85 |
+
}
|
| 86 |
+
default:
|
| 87 |
+
Assert(false, ExcNotImplemented());
|
| 88 |
+
};
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
template<int dim>
|
| 93 |
+
void test()
|
| 94 |
+
{
|
| 95 |
+
Triangulation<dim> tria;
|
| 96 |
+
for (unsigned int case_no=0; case_no<3; ++case_no)
|
| 97 |
+
{
|
| 98 |
+
create_triangulation(case_no, tria);
|
| 99 |
+
deallog << "dim" << dim << ":case" << case_no << ":diameter="
|
| 100 |
+
<< tria.begin_active()->diameter() << std::endl;
|
| 101 |
+
deallog << "dim" << dim << ":case" << case_no << ":extent_in_direction="
|
| 102 |
+
<< tria.begin_active()->extent_in_direction(0) << std::endl;
|
| 103 |
+
deallog << "dim" << dim << ":case" << case_no << ":minimum_vertex_distance="
|
| 104 |
+
<< tria.begin_active()->minimum_vertex_distance() << std::endl;
|
| 105 |
+
tria.clear();
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
int main()
|
| 111 |
+
{
|
| 112 |
+
std::ofstream logfile ("output");
|
| 113 |
+
deallog << std::setprecision (PRECISION);
|
| 114 |
+
deallog.attach(logfile);
|
| 115 |
+
deallog.depth_console(0);
|
| 116 |
+
deallog.threshold_double(1.e-10);
|
| 117 |
+
|
| 118 |
+
test<2>();
|
| 119 |
+
test<3>();
|
| 120 |
+
}
|
| 121 |
+
|
pool/shard011/C++/0118422_HDU4882.cpp
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include"iostream"
|
| 2 |
+
#include"cstdio"
|
| 3 |
+
#include"algorithm"
|
| 4 |
+
#include"cstring"
|
| 5 |
+
using namespace std;
|
| 6 |
+
const int ms=1e5+1;
|
| 7 |
+
struct Node
|
| 8 |
+
{
|
| 9 |
+
int t;
|
| 10 |
+
int v;
|
| 11 |
+
}a[ms];
|
| 12 |
+
bool cmp(const Node &a,const Node &b)
|
| 13 |
+
{
|
| 14 |
+
return a.t*b.v<a.v*b.t;
|
| 15 |
+
}
|
| 16 |
+
int main()
|
| 17 |
+
{
|
| 18 |
+
int n,i,j;
|
| 19 |
+
long long ans=0,sum=0;
|
| 20 |
+
scanf("%d",&n);
|
| 21 |
+
for(i=1;i<=n;i++)
|
| 22 |
+
scanf("%d",&a[i].t);
|
| 23 |
+
for(i=1;i<=n;i++)
|
| 24 |
+
scanf("%d",&a[i].v);
|
| 25 |
+
sort(a+1,a+1+n,cmp);
|
| 26 |
+
for(i=1;i<=n;i++)
|
| 27 |
+
{
|
| 28 |
+
sum+=a[i].t;
|
| 29 |
+
ans+=sum*a[i].v;
|
| 30 |
+
}
|
| 31 |
+
cout<<ans<<endl;
|
| 32 |
+
return 0;
|
| 33 |
+
}
|
pool/shard011/C++/0118423_GModelSpectralRegistry.cpp
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
* GModelSpectralRegistry.cpp - Spectral model registry class *
|
| 3 |
+
* ----------------------------------------------------------------------- *
|
| 4 |
+
* copyright (C) 2011-2012 by Juergen Knoedlseder *
|
| 5 |
+
* ----------------------------------------------------------------------- *
|
| 6 |
+
* *
|
| 7 |
+
* This program is free software: you can redistribute it and/or modify *
|
| 8 |
+
* it under the terms of the GNU General Public License as published by *
|
| 9 |
+
* the Free Software Foundation, either version 3 of the License, or *
|
| 10 |
+
* (at your option) any later version. *
|
| 11 |
+
* *
|
| 12 |
+
* This program is distributed in the hope that it will be useful, *
|
| 13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 15 |
+
* GNU General Public License for more details. *
|
| 16 |
+
* *
|
| 17 |
+
* You should have received a copy of the GNU General Public License *
|
| 18 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
| 19 |
+
* *
|
| 20 |
+
***************************************************************************/
|
| 21 |
+
/**
|
| 22 |
+
* @file GModelSpectralRegistry.cpp
|
| 23 |
+
* @brief Spectral model registry class implementation
|
| 24 |
+
* @author Juergen Knoedlseder
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
/* __ Includes ___________________________________________________________ */
|
| 28 |
+
#ifdef HAVE_CONFIG_H
|
| 29 |
+
#include <config.h>
|
| 30 |
+
#endif
|
| 31 |
+
#include "GModelSpectralRegistry.hpp"
|
| 32 |
+
#include "GException.hpp"
|
| 33 |
+
#include "GTools.hpp"
|
| 34 |
+
|
| 35 |
+
/* __ Static members _____________________________________________________ */
|
| 36 |
+
int GModelSpectralRegistry::m_number(0);
|
| 37 |
+
std::string* GModelSpectralRegistry::m_names(0);
|
| 38 |
+
const GModelSpectral** GModelSpectralRegistry::m_models(0);
|
| 39 |
+
|
| 40 |
+
/* __ Method name definitions ____________________________________________ */
|
| 41 |
+
#define G_NAME "GModelSpectralRegistry::name(int&)"
|
| 42 |
+
|
| 43 |
+
/* __ Macros _____________________________________________________________ */
|
| 44 |
+
|
| 45 |
+
/* __ Coding definitions _________________________________________________ */
|
| 46 |
+
|
| 47 |
+
/* __ Debug definitions __________________________________________________ */
|
| 48 |
+
#define G_DEBUG_REGISTRY 0
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
/*==========================================================================
|
| 52 |
+
= =
|
| 53 |
+
= Constructors/destructors =
|
| 54 |
+
= =
|
| 55 |
+
==========================================================================*/
|
| 56 |
+
|
| 57 |
+
/***********************************************************************//**
|
| 58 |
+
* @brief Void constructor
|
| 59 |
+
***************************************************************************/
|
| 60 |
+
GModelSpectralRegistry::GModelSpectralRegistry(void)
|
| 61 |
+
{
|
| 62 |
+
// Initialise private members for clean destruction
|
| 63 |
+
init_members();
|
| 64 |
+
|
| 65 |
+
// Debug option: Show actual registry
|
| 66 |
+
#if G_DEBUG_REGISTRY
|
| 67 |
+
std::cout << "GModelSpectralRegistry(void): ";
|
| 68 |
+
for (int i = 0; i < m_number; ++i)
|
| 69 |
+
std::cout << "\"" << m_names[i] << "\" ";
|
| 70 |
+
std::cout << std::endl;
|
| 71 |
+
#endif
|
| 72 |
+
|
| 73 |
+
// Return
|
| 74 |
+
return;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
/***********************************************************************//**
|
| 79 |
+
* @brief Model constructor
|
| 80 |
+
*
|
| 81 |
+
* @param[in] model Model.
|
| 82 |
+
***************************************************************************/
|
| 83 |
+
GModelSpectralRegistry::GModelSpectralRegistry(const GModelSpectral* model)
|
| 84 |
+
{
|
| 85 |
+
// Initialise private members for clean destruction
|
| 86 |
+
init_members();
|
| 87 |
+
|
| 88 |
+
// Debug option: Notify new registry
|
| 89 |
+
#if G_DEBUG_REGISTRY
|
| 90 |
+
std::cout << "GModelSpectralRegistry(const GModelSpatial*): ";
|
| 91 |
+
std::cout << "add \"" << model->type() << "\" to registry." << std::endl;
|
| 92 |
+
#endif
|
| 93 |
+
|
| 94 |
+
// Allocate new old registry
|
| 95 |
+
std::string* new_names = new std::string[m_number+1];
|
| 96 |
+
const GModelSpectral** new_models = new const GModelSpectral*[m_number+1];
|
| 97 |
+
|
| 98 |
+
// Save old registry
|
| 99 |
+
for (int i = 0; i < m_number; ++i) {
|
| 100 |
+
new_names[i] = m_names[i];
|
| 101 |
+
new_models[i] = m_models[i];
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// Add new model to registry
|
| 105 |
+
new_names[m_number] = model->type();
|
| 106 |
+
new_models[m_number] = model;
|
| 107 |
+
|
| 108 |
+
// Delete old registry
|
| 109 |
+
if (m_names != NULL) delete [] m_names;
|
| 110 |
+
if (m_models != NULL) delete [] m_models;
|
| 111 |
+
|
| 112 |
+
// Set pointers on new registry
|
| 113 |
+
m_names = new_names;
|
| 114 |
+
m_models = new_models;
|
| 115 |
+
|
| 116 |
+
// Increment number of models in registry
|
| 117 |
+
m_number++;
|
| 118 |
+
|
| 119 |
+
// Debug option: Show actual registry
|
| 120 |
+
#if G_DEBUG_REGISTRY
|
| 121 |
+
std::cout << "GModelSpectralRegistry(const GModelSpatial*): ";
|
| 122 |
+
for (int i = 0; i < m_number; ++i) {
|
| 123 |
+
std::cout << "\"" << m_names[i] << "\" ";
|
| 124 |
+
}
|
| 125 |
+
std::cout << std::endl;
|
| 126 |
+
#endif
|
| 127 |
+
|
| 128 |
+
// Return
|
| 129 |
+
return;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
/***********************************************************************//**
|
| 134 |
+
* @brief Copy constructor
|
| 135 |
+
*
|
| 136 |
+
* @param[in] registry Registry.
|
| 137 |
+
***************************************************************************/
|
| 138 |
+
GModelSpectralRegistry::GModelSpectralRegistry(const GModelSpectralRegistry& registry)
|
| 139 |
+
{
|
| 140 |
+
// Initialise private members
|
| 141 |
+
init_members();
|
| 142 |
+
|
| 143 |
+
// Copy members
|
| 144 |
+
copy_members(registry);
|
| 145 |
+
|
| 146 |
+
// Return
|
| 147 |
+
return;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
/***********************************************************************//**
|
| 152 |
+
* @brief Destructor
|
| 153 |
+
***************************************************************************/
|
| 154 |
+
GModelSpectralRegistry::~GModelSpectralRegistry(void)
|
| 155 |
+
{
|
| 156 |
+
// Free members
|
| 157 |
+
free_members();
|
| 158 |
+
|
| 159 |
+
// Return
|
| 160 |
+
return;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
/*==========================================================================
|
| 165 |
+
= =
|
| 166 |
+
= Operators =
|
| 167 |
+
= =
|
| 168 |
+
==========================================================================*/
|
| 169 |
+
|
| 170 |
+
/***********************************************************************//**
|
| 171 |
+
* @brief Assignment operator
|
| 172 |
+
*
|
| 173 |
+
* @param[in] registry Registry.
|
| 174 |
+
* @return Reference to registry.
|
| 175 |
+
***************************************************************************/
|
| 176 |
+
GModelSpectralRegistry& GModelSpectralRegistry::operator= (const GModelSpectralRegistry& registry)
|
| 177 |
+
{
|
| 178 |
+
// Execute only if object is not identical
|
| 179 |
+
if (this != ®istry) {
|
| 180 |
+
|
| 181 |
+
// Free members
|
| 182 |
+
free_members();
|
| 183 |
+
|
| 184 |
+
// Initialise private members
|
| 185 |
+
init_members();
|
| 186 |
+
|
| 187 |
+
// Copy members
|
| 188 |
+
copy_members(registry);
|
| 189 |
+
|
| 190 |
+
} // endif: object was not identical
|
| 191 |
+
|
| 192 |
+
// Return
|
| 193 |
+
return *this;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
/*==========================================================================
|
| 198 |
+
= =
|
| 199 |
+
= Public methods =
|
| 200 |
+
= =
|
| 201 |
+
==========================================================================*/
|
| 202 |
+
|
| 203 |
+
/***********************************************************************//**
|
| 204 |
+
* @brief Allocate spectral model of given name
|
| 205 |
+
*
|
| 206 |
+
* @param[in] name Spectral model name.
|
| 207 |
+
* @return Pointer to spectral model (NULL if name is not registered).
|
| 208 |
+
*
|
| 209 |
+
* Returns a pointer to a spectral model instance of the specified name.
|
| 210 |
+
* If the name has not been found in the registry, a NULL pointer is
|
| 211 |
+
* returned.
|
| 212 |
+
***************************************************************************/
|
| 213 |
+
GModelSpectral* GModelSpectralRegistry::alloc(const std::string& name) const
|
| 214 |
+
{
|
| 215 |
+
// Initialise spectral model
|
| 216 |
+
GModelSpectral* model = NULL;
|
| 217 |
+
|
| 218 |
+
// Search for model in registry
|
| 219 |
+
for (int i = 0; i < m_number; ++i) {
|
| 220 |
+
if (m_names[i] == name) {
|
| 221 |
+
model = m_models[i]->clone();
|
| 222 |
+
break;
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
// Return spectral model
|
| 227 |
+
return model;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
/***********************************************************************//**
|
| 232 |
+
* @brief Returns model name
|
| 233 |
+
*
|
| 234 |
+
* @param[in] index Model index [0,...,size()-1].
|
| 235 |
+
* @return Model name.
|
| 236 |
+
*
|
| 237 |
+
* @exception GException::out_of_range
|
| 238 |
+
* Model index is out of range.
|
| 239 |
+
***************************************************************************/
|
| 240 |
+
std::string GModelSpectralRegistry::name(const int& index) const
|
| 241 |
+
{
|
| 242 |
+
// Compile option: raise exception if index is out of range
|
| 243 |
+
#if defined(G_RANGE_CHECK)
|
| 244 |
+
if (index < 0 || index >= size()) {
|
| 245 |
+
throw GException::out_of_range(G_NAME, index, 0, size()-1);
|
| 246 |
+
}
|
| 247 |
+
#endif
|
| 248 |
+
|
| 249 |
+
// Return name
|
| 250 |
+
return (m_names[index]);
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
/***********************************************************************//**
|
| 255 |
+
* @brief Print registry information
|
| 256 |
+
*
|
| 257 |
+
* @return Registry content.
|
| 258 |
+
***************************************************************************/
|
| 259 |
+
std::string GModelSpectralRegistry::print(void) const
|
| 260 |
+
{
|
| 261 |
+
// Initialise result string
|
| 262 |
+
std::string result;
|
| 263 |
+
|
| 264 |
+
// Append header
|
| 265 |
+
result.append("=== GModelSpectralRegistry ===");
|
| 266 |
+
result.append("\n"+parformat("Number of models")+str(m_number));
|
| 267 |
+
|
| 268 |
+
// Append models
|
| 269 |
+
for (int i = 0; i < m_number; ++i) {
|
| 270 |
+
result.append("\n"+parformat(m_names[i]));
|
| 271 |
+
result.append(m_models[i]->type());
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
// Return result
|
| 275 |
+
return result;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
/*==========================================================================
|
| 279 |
+
= =
|
| 280 |
+
= Private methods =
|
| 281 |
+
= =
|
| 282 |
+
==========================================================================*/
|
| 283 |
+
|
| 284 |
+
/***********************************************************************//**
|
| 285 |
+
* @brief Initialise class members
|
| 286 |
+
***************************************************************************/
|
| 287 |
+
void GModelSpectralRegistry::init_members(void)
|
| 288 |
+
{
|
| 289 |
+
// Return
|
| 290 |
+
return;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
/***********************************************************************//**
|
| 295 |
+
* @brief Copy class members
|
| 296 |
+
*
|
| 297 |
+
* @param[in] registry Registry.
|
| 298 |
+
***************************************************************************/
|
| 299 |
+
void GModelSpectralRegistry::copy_members(const GModelSpectralRegistry& registry)
|
| 300 |
+
{
|
| 301 |
+
// Return
|
| 302 |
+
return;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
/***********************************************************************//**
|
| 307 |
+
* @brief Delete class members
|
| 308 |
+
***************************************************************************/
|
| 309 |
+
void GModelSpectralRegistry::free_members(void)
|
| 310 |
+
{
|
| 311 |
+
// Return
|
| 312 |
+
return;
|
| 313 |
+
}
|
pool/shard011/C++/0118424_qpatternmatchingfns.cpp
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 QtXmlPatterns module of the Qt Toolkit.
|
| 8 |
+
**
|
| 9 |
+
** $QT_BEGIN_LICENSE:LGPL$
|
| 10 |
+
** No Commercial Usage
|
| 11 |
+
** This file contains pre-release code and may not be distributed.
|
| 12 |
+
** You may use this file in accordance with the terms and conditions
|
| 13 |
+
** contained in the Technology Preview License Agreement accompanying
|
| 14 |
+
** this package.
|
| 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 |
+
** If you have questions regarding the use of this file, please contact
|
| 29 |
+
** Nokia at qt-info@nokia.com.
|
| 30 |
+
**
|
| 31 |
+
**
|
| 32 |
+
**
|
| 33 |
+
**
|
| 34 |
+
**
|
| 35 |
+
**
|
| 36 |
+
**
|
| 37 |
+
**
|
| 38 |
+
** $QT_END_LICENSE$
|
| 39 |
+
**
|
| 40 |
+
****************************************************************************/
|
| 41 |
+
|
| 42 |
+
#include <QStringList>
|
| 43 |
+
|
| 44 |
+
#include "qboolean_p.h"
|
| 45 |
+
#include "qcommonvalues_p.h"
|
| 46 |
+
#include "qitemmappingiterator_p.h"
|
| 47 |
+
#include "qpatternistlocale_p.h"
|
| 48 |
+
#include "qatomicstring_p.h"
|
| 49 |
+
|
| 50 |
+
#include "qpatternmatchingfns_p.h"
|
| 51 |
+
|
| 52 |
+
QT_BEGIN_NAMESPACE
|
| 53 |
+
|
| 54 |
+
using namespace QPatternist;
|
| 55 |
+
|
| 56 |
+
MatchesFN::MatchesFN() : PatternPlatform(2)
|
| 57 |
+
{
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
Item MatchesFN::evaluateSingleton(const DynamicContext::Ptr &context) const
|
| 61 |
+
{
|
| 62 |
+
const QRegExp regexp(pattern(context));
|
| 63 |
+
QString input;
|
| 64 |
+
|
| 65 |
+
const Item arg(m_operands.first()->evaluateSingleton(context));
|
| 66 |
+
if(arg)
|
| 67 |
+
input = arg.stringValue();
|
| 68 |
+
|
| 69 |
+
return Boolean::fromValue(input.contains(regexp));
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
ReplaceFN::ReplaceFN() : PatternPlatform(3)
|
| 73 |
+
{
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
Item ReplaceFN::evaluateSingleton(const DynamicContext::Ptr &context) const
|
| 77 |
+
{
|
| 78 |
+
const QRegExp regexp(pattern(context));
|
| 79 |
+
QString input;
|
| 80 |
+
|
| 81 |
+
const Item arg(m_operands.first()->evaluateSingleton(context));
|
| 82 |
+
if(arg)
|
| 83 |
+
input = arg.stringValue();
|
| 84 |
+
|
| 85 |
+
const QString replacement(m_replacementString.isNull() ? parseReplacement(regexp.captureCount(), context)
|
| 86 |
+
: m_replacementString);
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
return AtomicString::fromValue(input.replace(regexp, replacement));
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
QString ReplaceFN::errorAtEnd(const char ch)
|
| 93 |
+
{
|
| 94 |
+
return QtXmlPatterns::tr("%1 must be followed by %2 or %3, not at "
|
| 95 |
+
"the end of the replacement string.")
|
| 96 |
+
.arg(formatKeyword(QLatin1Char(ch)))
|
| 97 |
+
.arg(formatKeyword(QLatin1Char('\\')))
|
| 98 |
+
.arg(formatKeyword(QLatin1Char('$')));
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
QString ReplaceFN::parseReplacement(const int,
|
| 102 |
+
const DynamicContext::Ptr &context) const
|
| 103 |
+
{
|
| 104 |
+
// TODO what if there is no groups, can one rewrite to the replacement then?
|
| 105 |
+
const QString input(m_operands.at(2)->evaluateSingleton(context).stringValue());
|
| 106 |
+
|
| 107 |
+
QString retval;
|
| 108 |
+
retval.reserve(input.size());
|
| 109 |
+
const int len = input.length();
|
| 110 |
+
|
| 111 |
+
for(int i = 0; i < len; ++i)
|
| 112 |
+
{
|
| 113 |
+
const QChar ch(input.at(i));
|
| 114 |
+
switch(ch.toAscii())
|
| 115 |
+
{
|
| 116 |
+
case '$':
|
| 117 |
+
{
|
| 118 |
+
/* QRegExp uses '\' as opposed to '$' for marking sub groups. */
|
| 119 |
+
retval.append(QLatin1Char('\\'));
|
| 120 |
+
|
| 121 |
+
++i;
|
| 122 |
+
if(i == len)
|
| 123 |
+
{
|
| 124 |
+
context->error(errorAtEnd('$'), ReportContext::FORX0004, this);
|
| 125 |
+
return QString();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
const QChar nextCh(input.at(i));
|
| 129 |
+
if(nextCh.isDigit())
|
| 130 |
+
retval.append(nextCh);
|
| 131 |
+
else
|
| 132 |
+
{
|
| 133 |
+
context->error(QtXmlPatterns::tr("In the replacement string, %1 must be "
|
| 134 |
+
"followed by at least one digit when not escaped.")
|
| 135 |
+
.arg(formatKeyword(QLatin1Char('$'))),
|
| 136 |
+
ReportContext::FORX0004, this);
|
| 137 |
+
return QString();
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
break;
|
| 141 |
+
}
|
| 142 |
+
case '\\':
|
| 143 |
+
{
|
| 144 |
+
++i;
|
| 145 |
+
if(i == len)
|
| 146 |
+
{
|
| 147 |
+
/* error, we've reached the end. */;
|
| 148 |
+
context->error(errorAtEnd('\\'), ReportContext::FORX0004, this);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
const QChar nextCh(input.at(i));
|
| 152 |
+
if(nextCh == QLatin1Char('\\') || nextCh == QLatin1Char('$'))
|
| 153 |
+
{
|
| 154 |
+
retval.append(ch);
|
| 155 |
+
break;
|
| 156 |
+
}
|
| 157 |
+
else
|
| 158 |
+
{
|
| 159 |
+
context->error(QtXmlPatterns::tr("In the replacement string, %1 can only be used to "
|
| 160 |
+
"escape itself or %2, not %3")
|
| 161 |
+
.arg(formatKeyword(QLatin1Char('\\')))
|
| 162 |
+
.arg(formatKeyword(QLatin1Char('$')))
|
| 163 |
+
.arg(formatKeyword(nextCh)),
|
| 164 |
+
ReportContext::FORX0004, this);
|
| 165 |
+
return QString();
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
default:
|
| 169 |
+
retval.append(ch);
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
return retval;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
Expression::Ptr ReplaceFN::compress(const StaticContext::Ptr &context)
|
| 177 |
+
{
|
| 178 |
+
const Expression::Ptr me(PatternPlatform::compress(context));
|
| 179 |
+
|
| 180 |
+
if(me != this)
|
| 181 |
+
return me;
|
| 182 |
+
|
| 183 |
+
if(m_operands.at(2)->is(IDStringValue))
|
| 184 |
+
{
|
| 185 |
+
const int capt = captureCount();
|
| 186 |
+
if(capt == -1)
|
| 187 |
+
return me;
|
| 188 |
+
else
|
| 189 |
+
m_replacementString = parseReplacement(captureCount(), context->dynamicContext());
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
return me;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
TokenizeFN::TokenizeFN() : PatternPlatform(2)
|
| 196 |
+
{
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
/**
|
| 200 |
+
* Used by QAbstractXmlForwardIterator.
|
| 201 |
+
*/
|
| 202 |
+
static inline bool qIsForwardIteratorEnd(const QString &item)
|
| 203 |
+
{
|
| 204 |
+
return item.isNull();
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
Item TokenizeFN::mapToItem(const QString &subject, const DynamicContext::Ptr &) const
|
| 208 |
+
{
|
| 209 |
+
return AtomicString::fromValue(subject);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
Item::Iterator::Ptr TokenizeFN::evaluateSequence(const DynamicContext::Ptr &context) const
|
| 213 |
+
{
|
| 214 |
+
const Item arg(m_operands.first()->evaluateSingleton(context));
|
| 215 |
+
if(!arg)
|
| 216 |
+
return CommonValues::emptyIterator;
|
| 217 |
+
|
| 218 |
+
const QString input(arg.stringValue());
|
| 219 |
+
if(input.isEmpty())
|
| 220 |
+
return CommonValues::emptyIterator;
|
| 221 |
+
|
| 222 |
+
const QRegExp regExp(pattern(context));
|
| 223 |
+
const QStringList result(input.split(regExp, QString::KeepEmptyParts));
|
| 224 |
+
|
| 225 |
+
return makeItemMappingIterator<Item>(ConstPtr(this),
|
| 226 |
+
makeListIterator(result),
|
| 227 |
+
DynamicContext::Ptr());
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
QT_END_NAMESPACE
|
pool/shard011/C++/0118425_memdatasource.cc
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Maverick Model 3D
|
| 2 |
+
*
|
| 3 |
+
* Copyright (c) 2004-2008 Kevin Worcester
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with this program; if not, write to the Free Software
|
| 17 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
| 18 |
+
* USA.
|
| 19 |
+
*
|
| 20 |
+
* See the COPYING file for full license text.
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
#include "memdatasource.h"
|
| 25 |
+
|
| 26 |
+
#include <errno.h>
|
| 27 |
+
|
| 28 |
+
MemDataSource::MemDataSource( const uint8_t * buf, size_t bufSize )
|
| 29 |
+
: m_buf( buf ),
|
| 30 |
+
m_bufSize( bufSize )
|
| 31 |
+
{
|
| 32 |
+
if ( m_buf == NULL )
|
| 33 |
+
{
|
| 34 |
+
setErrno( EBADF );
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
setFileSize( bufSize );
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
MemDataSource::~MemDataSource()
|
| 42 |
+
{
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
bool MemDataSource::internalReadAt( off_t offset, const uint8_t ** buf, size_t * bufLen )
|
| 46 |
+
{
|
| 47 |
+
// TODO should assert on buf and bufLen
|
| 48 |
+
|
| 49 |
+
// If we had an error, just keep returning an error
|
| 50 |
+
if ( errorOccurred() )
|
| 51 |
+
return false;
|
| 52 |
+
|
| 53 |
+
if ( (size_t) offset > m_bufSize )
|
| 54 |
+
{
|
| 55 |
+
setUnexpectedEof( true );
|
| 56 |
+
return false;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
*buf = &m_buf[offset];
|
| 60 |
+
*bufLen = m_bufSize - offset;
|
| 61 |
+
return true;
|
| 62 |
+
}
|
| 63 |
+
|
pool/shard011/C++/0118426_chrome.cpp
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2007 Glenn Ergeerts <glenn.ergeerts@telenet.be>
|
| 3 |
+
* Copyright 2012 Glenn Ergeerts <marco.gulino@gmail.com>
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU Library General Public License as
|
| 7 |
+
* published by the Free Software Foundation; either version 2, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU Library General Public
|
| 16 |
+
* License along with this program; if not, write to the
|
| 17 |
+
* Free Software Foundation, Inc.,
|
| 18 |
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
#include "chrome.h"
|
| 23 |
+
#include "faviconfromblob.h"
|
| 24 |
+
#include "browsers/findprofile.h"
|
| 25 |
+
|
| 26 |
+
#include <QJsonDocument>
|
| 27 |
+
#include <QJsonObject>
|
| 28 |
+
#include <QFileInfo>
|
| 29 |
+
#include <QDebug>
|
| 30 |
+
#include "bookmarksrunner_defs.h"
|
| 31 |
+
#include <QFileInfo>
|
| 32 |
+
#include <QDir>
|
| 33 |
+
|
| 34 |
+
class ProfileBookmarks {
|
| 35 |
+
public:
|
| 36 |
+
ProfileBookmarks(Profile &profile) : m_profile(profile) {}
|
| 37 |
+
inline QList<QVariantMap> bookmarks() { return m_bookmarks; }
|
| 38 |
+
inline Profile profile() { return m_profile; }
|
| 39 |
+
void tearDown() { m_profile.favicon()->teardown(); m_bookmarks.clear(); }
|
| 40 |
+
void add(QVariantMap &bookmarkEntry) { m_bookmarks << bookmarkEntry; }
|
| 41 |
+
void clear() { m_bookmarks.clear(); }
|
| 42 |
+
private:
|
| 43 |
+
Profile m_profile;
|
| 44 |
+
QList<QVariantMap> m_bookmarks;
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
Chrome::Chrome( FindProfile* findProfile, QObject* parent )
|
| 48 |
+
: QObject(parent),
|
| 49 |
+
m_watcher(new KDirWatch(this)),
|
| 50 |
+
m_dirty(false)
|
| 51 |
+
{
|
| 52 |
+
foreach(Profile profile, findProfile->find()) {
|
| 53 |
+
m_profileBookmarks << new ProfileBookmarks(profile);
|
| 54 |
+
m_watcher->addFile(profile.path());
|
| 55 |
+
}
|
| 56 |
+
connect(m_watcher, &KDirWatch::created, [=] { m_dirty = true; });
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
Chrome::~Chrome()
|
| 60 |
+
{
|
| 61 |
+
foreach(ProfileBookmarks *profileBookmark, m_profileBookmarks) {
|
| 62 |
+
delete profileBookmark;
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
QList<BookmarkMatch> Chrome::match(const QString &term, bool addEveryThing)
|
| 67 |
+
{
|
| 68 |
+
if (m_dirty) {
|
| 69 |
+
prepare();
|
| 70 |
+
}
|
| 71 |
+
QList<BookmarkMatch> results;
|
| 72 |
+
foreach(ProfileBookmarks *profileBookmarks, m_profileBookmarks) {
|
| 73 |
+
results << match(term, addEveryThing, profileBookmarks);
|
| 74 |
+
}
|
| 75 |
+
return results;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
QList<BookmarkMatch> Chrome::match(const QString &term, bool addEveryThing, ProfileBookmarks *profileBookmarks)
|
| 79 |
+
{
|
| 80 |
+
QList<BookmarkMatch> results;
|
| 81 |
+
foreach(QVariantMap bookmark, profileBookmarks->bookmarks()) {
|
| 82 |
+
QString url = bookmark.value(QStringLiteral("url")).toString();
|
| 83 |
+
|
| 84 |
+
BookmarkMatch bookmarkMatch(profileBookmarks->profile().favicon(), term, bookmark.value(QStringLiteral("name")).toString(), url);
|
| 85 |
+
bookmarkMatch.addTo(results, addEveryThing);
|
| 86 |
+
}
|
| 87 |
+
return results;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
void Chrome::prepare()
|
| 91 |
+
{
|
| 92 |
+
m_dirty = false;
|
| 93 |
+
foreach(ProfileBookmarks *profileBookmarks, m_profileBookmarks) {
|
| 94 |
+
Profile profile = profileBookmarks->profile();
|
| 95 |
+
profileBookmarks->clear();
|
| 96 |
+
QFile bookmarksFile(profile.path());
|
| 97 |
+
if (!bookmarksFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
| 98 |
+
continue;
|
| 99 |
+
};
|
| 100 |
+
QJsonDocument jdoc = QJsonDocument::fromJson(bookmarksFile.readAll());
|
| 101 |
+
if (jdoc.isNull()) {
|
| 102 |
+
continue;
|
| 103 |
+
}
|
| 104 |
+
QVariantMap resultMap = jdoc.object().toVariantMap();
|
| 105 |
+
if (!resultMap.contains(QStringLiteral("roots"))) {
|
| 106 |
+
return;
|
| 107 |
+
}
|
| 108 |
+
QVariantMap entries = resultMap.value(QStringLiteral("roots")).toMap();
|
| 109 |
+
foreach(QVariant folder, entries.values()) {
|
| 110 |
+
parseFolder(folder.toMap(), profileBookmarks);
|
| 111 |
+
}
|
| 112 |
+
profile.favicon()->prepare();
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
void Chrome::teardown()
|
| 117 |
+
{
|
| 118 |
+
foreach(ProfileBookmarks *profileBookmarks, m_profileBookmarks) {
|
| 119 |
+
profileBookmarks->tearDown();
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
void Chrome::parseFolder(const QVariantMap &entry, ProfileBookmarks *profile)
|
| 124 |
+
{
|
| 125 |
+
QVariantList children = entry.value(QStringLiteral("children")).toList();
|
| 126 |
+
foreach(QVariant child, children) {
|
| 127 |
+
QVariantMap entry = child.toMap();
|
| 128 |
+
if(entry.value(QStringLiteral("type")).toString() == QLatin1String("folder"))
|
| 129 |
+
parseFolder(entry, profile);
|
| 130 |
+
else {
|
| 131 |
+
profile->add(entry);
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
}
|
pool/shard011/C++/0118428_9322.cc
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// { dg-require-namedlocale "en_US.ISO8859-1" }
|
| 2 |
+
// { dg-require-namedlocale "de_DE.ISO8859-15" }
|
| 3 |
+
|
| 4 |
+
// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
|
| 5 |
+
|
| 6 |
+
// Copyright (C) 2001-2021 Free Software Foundation, Inc.
|
| 7 |
+
//
|
| 8 |
+
// This file is part of the GNU ISO C++ Library. This library is free
|
| 9 |
+
// software; you can redistribute it and/or modify it under the
|
| 10 |
+
// terms of the GNU General Public License as published by the
|
| 11 |
+
// Free Software Foundation; either version 3, or (at your option)
|
| 12 |
+
// any later version.
|
| 13 |
+
|
| 14 |
+
// This library 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 along
|
| 20 |
+
// with this library; see the file COPYING3. If not see
|
| 21 |
+
// <http://www.gnu.org/licenses/>.
|
| 22 |
+
|
| 23 |
+
// 27.8.1.4 Overridden virtual functions
|
| 24 |
+
|
| 25 |
+
#include <fstream>
|
| 26 |
+
#include <locale>
|
| 27 |
+
#include <testsuite_hooks.h>
|
| 28 |
+
|
| 29 |
+
// libstdc++/9322
|
| 30 |
+
void test07()
|
| 31 |
+
{
|
| 32 |
+
using std::locale;
|
| 33 |
+
|
| 34 |
+
locale loc;
|
| 35 |
+
std::filebuf ob;
|
| 36 |
+
VERIFY( ob.getloc() == loc );
|
| 37 |
+
|
| 38 |
+
locale::global(locale(ISO_8859(1,en_US)));
|
| 39 |
+
VERIFY( ob.getloc() == loc );
|
| 40 |
+
|
| 41 |
+
locale loc_de = locale(ISO_8859(15,de_DE));
|
| 42 |
+
locale ret = ob.pubimbue(loc_de);
|
| 43 |
+
VERIFY( ob.getloc() == loc_de );
|
| 44 |
+
VERIFY( ret == loc );
|
| 45 |
+
|
| 46 |
+
locale::global(loc);
|
| 47 |
+
VERIFY( ob.getloc() == loc_de );
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
int main()
|
| 51 |
+
{
|
| 52 |
+
test07();
|
| 53 |
+
return 0;
|
| 54 |
+
}
|
pool/shard011/C++/0118429_Fractal_Iterator.cpp
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "Fractal_Iterator.h"
|
| 2 |
+
#include "config.h"
|
| 3 |
+
#include "constants.h"
|
| 4 |
+
|
| 5 |
+
Fractal_Iterator::Fractal_Iterator()
|
| 6 |
+
{
|
| 7 |
+
m_levels.push_back(Fractal_Element(&m_statics));
|
| 8 |
+
m_currentLevel = 0;
|
| 9 |
+
};
|
| 10 |
+
|
| 11 |
+
Fractal_Iterator::~Fractal_Iterator() {
|
| 12 |
+
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
void Fractal_Iterator::Draw(sf::RenderTarget& target, bool drawPrevious) {
|
| 16 |
+
m_levels[m_currentLevel].Draw(target, Line::dt_simple);
|
| 17 |
+
if(drawPrevious && m_currentLevel > 0) {
|
| 18 |
+
m_levels[m_currentLevel-1].Draw(target, Line::dt_overlay);
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
void Fractal_Iterator::SetBase(Fractal_Template newBase) {
|
| 23 |
+
m_levels.clear();
|
| 24 |
+
m_statics.clear();
|
| 25 |
+
m_base = newBase;
|
| 26 |
+
|
| 27 |
+
Fractal_Element element(&m_statics);
|
| 28 |
+
|
| 29 |
+
Line newBaseline = m_base.GetBase();
|
| 30 |
+
newBaseline.SetColor(sf::Color::Black);
|
| 31 |
+
newBaseline.SetType(Line::line_type::lt_topRight);
|
| 32 |
+
|
| 33 |
+
element.AddLine(newBaseline);
|
| 34 |
+
element.SetBase(newBaseline.GetStart(), newBaseline.GetFinish());
|
| 35 |
+
|
| 36 |
+
m_levels.push_back(element);
|
| 37 |
+
SetLevel(0);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
void Fractal_Iterator::SetLevel(size_t level) {
|
| 41 |
+
if(level > ITERATOR_LEVELS) {
|
| 42 |
+
m_currentLevel = ITERATOR_LEVELS + 1;
|
| 43 |
+
IterateToInfinity();
|
| 44 |
+
} else {
|
| 45 |
+
m_currentLevel = level;
|
| 46 |
+
IterateTo(level);
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
void Fractal_Iterator::IterateTo(size_t level) {
|
| 51 |
+
if(level < m_levels.size())
|
| 52 |
+
return;
|
| 53 |
+
for(size_t iii = m_levels.size(); iii <= level; iii++) {
|
| 54 |
+
Fractal_Element nextFE = m_levels[iii - 1].ReplaceAll(m_base);
|
| 55 |
+
m_levels.push_back(nextFE);
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
void Fractal_Iterator::IterateToInfinity() {
|
| 60 |
+
// If we already iterated to infinity once before
|
| 61 |
+
if (m_levels.size() > ITERATOR_LEVELS + 1)
|
| 62 |
+
return;
|
| 63 |
+
|
| 64 |
+
IterateTo(ITERATOR_LEVELS);
|
| 65 |
+
Fractal_Element nextFe = m_levels[ITERATOR_LEVELS];
|
| 66 |
+
if (nextFe.GetMaxLength() < nextFe.BaseLength()) {
|
| 67 |
+
while (nextFe.GetMaxLength() > config::infinity_stop_size) {
|
| 68 |
+
nextFe = nextFe.ReplaceAll(m_base);
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
else {
|
| 72 |
+
nextFe = nextFe.ReplaceAll(m_base);
|
| 73 |
+
}
|
| 74 |
+
m_levels.push_back(nextFe);
|
| 75 |
+
}
|
pool/shard011/C++/0118430_WxObsMap.cpp
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma ident "$Id$"
|
| 2 |
+
|
| 3 |
+
//============================================================================
|
| 4 |
+
//
|
| 5 |
+
// This file is part of GPSTk, the GPS Toolkit.
|
| 6 |
+
//
|
| 7 |
+
// The GPSTk is free software; you can redistribute it and/or modify
|
| 8 |
+
// it under the terms of the GNU Lesser General Public License as published
|
| 9 |
+
// by the Free Software Foundation; either version 2.1 of the License, or
|
| 10 |
+
// any later version.
|
| 11 |
+
//
|
| 12 |
+
// The GPSTk is distributed in the hope that it will be useful,
|
| 13 |
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 |
+
// GNU Lesser General Public License for more details.
|
| 16 |
+
//
|
| 17 |
+
// You should have received a copy of the GNU Lesser General Public
|
| 18 |
+
// License along with GPSTk; if not, write to the Free Software Foundation,
|
| 19 |
+
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
| 20 |
+
//
|
| 21 |
+
// Copyright 2004, The University of Texas at Austin
|
| 22 |
+
//
|
| 23 |
+
//============================================================================
|
| 24 |
+
|
| 25 |
+
//============================================================================
|
| 26 |
+
//
|
| 27 |
+
//This software developed by Applied Research Laboratories at the University of
|
| 28 |
+
//Texas at Austin, under contract to an agency or agencies within the U.S.
|
| 29 |
+
//Department of Defense. The U.S. Government retains all rights to use,
|
| 30 |
+
//duplicate, distribute, disclose, or release this software.
|
| 31 |
+
//
|
| 32 |
+
//Pursuant to DoD Directive 523024
|
| 33 |
+
//
|
| 34 |
+
// DISTRIBUTION STATEMENT A: This software has been approved for public
|
| 35 |
+
// release, distribution is unlimited.
|
| 36 |
+
//
|
| 37 |
+
//=============================================================================
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* @file WxObsMap.cpp
|
| 41 |
+
* A class encapsulating wx data.
|
| 42 |
+
*/
|
| 43 |
+
|
| 44 |
+
#include "WxObsMap.hpp"
|
| 45 |
+
#include "TimeString.hpp"
|
| 46 |
+
|
| 47 |
+
using namespace std;
|
| 48 |
+
using namespace gpstk;
|
| 49 |
+
|
| 50 |
+
namespace gpstk
|
| 51 |
+
{
|
| 52 |
+
|
| 53 |
+
WxObservation WxObsData::getMostRecent( const CommonTime& t ) const
|
| 54 |
+
throw()
|
| 55 |
+
{
|
| 56 |
+
if(obs.size() == 0)
|
| 57 |
+
return WxObservation();
|
| 58 |
+
|
| 59 |
+
WxObsMap::const_iterator i = obs.upper_bound(t);
|
| 60 |
+
if (i== obs.end())
|
| 61 |
+
i--;
|
| 62 |
+
if (i != obs.begin())
|
| 63 |
+
i--;
|
| 64 |
+
return i->second;
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
void WxObsData::insertObservation( const WxObservation& wx )
|
| 68 |
+
throw()
|
| 69 |
+
{
|
| 70 |
+
obs[wx.t] = wx;
|
| 71 |
+
if (wx.t > lastTime) lastTime=wx.t;
|
| 72 |
+
if (wx.t < firstTime) firstTime=wx.t;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
bool WxObservation::isAllValid() const
|
| 76 |
+
throw()
|
| 77 |
+
{
|
| 78 |
+
return temperatureSource != noWx
|
| 79 |
+
&& pressureSource != noWx
|
| 80 |
+
&& humiditySource != noWx;
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
void WxObsData::flush(const CommonTime& t) throw()
|
| 84 |
+
{
|
| 85 |
+
// remove data from the WxObsMap
|
| 86 |
+
// map is sorted by time, stop removing data at
|
| 87 |
+
// first point after t
|
| 88 |
+
WxObsMap::iterator i = obs.begin();
|
| 89 |
+
while (i != obs.end())
|
| 90 |
+
{
|
| 91 |
+
if (i->first < t)
|
| 92 |
+
{
|
| 93 |
+
obs.erase(i);
|
| 94 |
+
i = obs.begin();
|
| 95 |
+
firstTime = i->second.t;
|
| 96 |
+
}
|
| 97 |
+
else
|
| 98 |
+
break;
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
WxObservation WxObsData::getWxObservation(const CommonTime& t,
|
| 103 |
+
unsigned iv,
|
| 104 |
+
bool interpolate) const
|
| 105 |
+
throw(ObjectNotFound)
|
| 106 |
+
{
|
| 107 |
+
if (obs.empty())
|
| 108 |
+
{
|
| 109 |
+
ObjectNotFound e("No WxObservation available near time " +
|
| 110 |
+
printTime(t,"%02H:%02M:%02S on day %03j of %4Y"));
|
| 111 |
+
GPSTK_THROW(e);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// get the first object after time t;
|
| 115 |
+
WxObsMap::const_iterator after = obs.upper_bound(t);
|
| 116 |
+
|
| 117 |
+
if (after == obs.begin())
|
| 118 |
+
{
|
| 119 |
+
const WxObservation& wxa = after->second;
|
| 120 |
+
if ((wxa.t >= (t - iv)) && (wxa.t <= (t + iv)))
|
| 121 |
+
{
|
| 122 |
+
// only after point fits
|
| 123 |
+
return wxa;
|
| 124 |
+
}
|
| 125 |
+
else
|
| 126 |
+
{
|
| 127 |
+
ObjectNotFound e("No WxObservation available near time " +
|
| 128 |
+
printTime(t,"%02H:%02M:%02S on day %03j of %4Y"));
|
| 129 |
+
GPSTK_THROW(e);
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
// get the first object at or before time t;
|
| 135 |
+
WxObsMap::const_iterator before = after;
|
| 136 |
+
before--;
|
| 137 |
+
|
| 138 |
+
if (after == obs.end())
|
| 139 |
+
{
|
| 140 |
+
const WxObservation& wxb = before->second;
|
| 141 |
+
if((wxb.t >= (t - iv)) && (wxb.t <= (t + iv)))
|
| 142 |
+
{
|
| 143 |
+
// only before point fits
|
| 144 |
+
return wxb;
|
| 145 |
+
}
|
| 146 |
+
else
|
| 147 |
+
{
|
| 148 |
+
ObjectNotFound e("No WeatherData available near time " +
|
| 149 |
+
printTime(t,"%02H:%02M:%02S on day %03j of %4Y"));
|
| 150 |
+
GPSTK_THROW(e);
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
else
|
| 154 |
+
{
|
| 155 |
+
const WxObservation& wxa = after->second;
|
| 156 |
+
const WxObservation& wxb = before->second;
|
| 157 |
+
|
| 158 |
+
if (interpolate)
|
| 159 |
+
{
|
| 160 |
+
if((wxb.t >= (t - iv)) && (wxb.t <= (t + iv)))
|
| 161 |
+
{
|
| 162 |
+
if ((wxa.t >= (t - iv)) && (wxa.t <= (t + iv)))
|
| 163 |
+
{
|
| 164 |
+
// both points fit, linearly interpolate and create
|
| 165 |
+
// a WeatherData object with those values
|
| 166 |
+
double dtw = wxa.t - wxb.t;
|
| 167 |
+
double dt = t - wxb.t;
|
| 168 |
+
|
| 169 |
+
double slope = (wxa.pressure - wxb.pressure) / dtw;
|
| 170 |
+
double pressure = slope * dt + wxb.pressure;
|
| 171 |
+
|
| 172 |
+
slope = (wxa.humidity - wxb.humidity) / dtw;
|
| 173 |
+
double humidity = slope * dt + wxb.humidity;
|
| 174 |
+
|
| 175 |
+
slope = (wxa.temperature - wxb.temperature) / dtw;
|
| 176 |
+
double temp = slope * dt + wxb.temperature;
|
| 177 |
+
|
| 178 |
+
WxObservation wx(t, temp, pressure, humidity);
|
| 179 |
+
return wx;
|
| 180 |
+
}
|
| 181 |
+
else
|
| 182 |
+
{
|
| 183 |
+
// only before point fits
|
| 184 |
+
return wxb;
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
else if ((wxa.t >= (t - iv)) && (wxa.t <= (t + iv)))
|
| 188 |
+
{
|
| 189 |
+
// only after point fits
|
| 190 |
+
return wxa;
|
| 191 |
+
}
|
| 192 |
+
else
|
| 193 |
+
{
|
| 194 |
+
ObjectNotFound e("No WeatherData available near time " +
|
| 195 |
+
printTime(t,"%02H:%02M:%02S on day %03j of %4Y"));
|
| 196 |
+
GPSTK_THROW(e);
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
else
|
| 200 |
+
{
|
| 201 |
+
if((wxb.t >= (t - iv)) && (wxb.t <= (t + iv)))
|
| 202 |
+
{
|
| 203 |
+
if ((wxa.t >= (t - iv)) && (wxa.t <= (t + iv)))
|
| 204 |
+
{
|
| 205 |
+
// both points fit, return closer point, or
|
| 206 |
+
// before point if at same distance
|
| 207 |
+
double diffa = wxa.t - t;
|
| 208 |
+
double diffb = t - wxb.t;
|
| 209 |
+
return(diffa < diffb ? wxa : wxb);
|
| 210 |
+
}
|
| 211 |
+
else
|
| 212 |
+
{
|
| 213 |
+
// only before point fits
|
| 214 |
+
return wxb;
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
else if ((wxa.t >= (t - iv)) && (wxa.t <= (t + iv)))
|
| 218 |
+
{
|
| 219 |
+
// only after point fits
|
| 220 |
+
return wxa;
|
| 221 |
+
}
|
| 222 |
+
else
|
| 223 |
+
{
|
| 224 |
+
ObjectNotFound e("No WeatherData available near time " +
|
| 225 |
+
printTime(t,"%02H:%02M:%02S on day %03j of %4Y"));
|
| 226 |
+
GPSTK_THROW(e);
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
// These are just to facilitate debugging.
|
| 233 |
+
std::ostream& operator<<(std::ostream& s, const gpstk::WxObservation& obs)
|
| 234 |
+
throw()
|
| 235 |
+
{
|
| 236 |
+
// Note that this does not flag where the wx data came from
|
| 237 |
+
s << obs.t << ", t=" << obs.temperature
|
| 238 |
+
<< ", p=" << obs.pressure
|
| 239 |
+
<< ", rh=" << obs.humidity;
|
| 240 |
+
return s;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
} // namespace
|
pool/shard011/C++/0118431_bf_observe_linear_uncorrelated.cpp
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Bayes++ the Bayesian Filtering Library
|
| 3 |
+
* Copyright (c) 2004 Michael Stevens
|
| 4 |
+
* See accompanying Bayes++.html for terms and conditions of use.
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* MATLAB MEX interface for Bayes++
|
| 9 |
+
* bf_observe_linear_uncorrelated: Observe z with noise Zv through linear H
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
#include <mex.h>
|
| 13 |
+
#include "matlabBfilter.h"
|
| 14 |
+
|
| 15 |
+
using namespace::Matlab_convert;
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
void mexFunction(
|
| 19 |
+
int nlhs,
|
| 20 |
+
mxArray *plhs[],
|
| 21 |
+
int nrhs,
|
| 22 |
+
const mxArray *prhs[]
|
| 23 |
+
)
|
| 24 |
+
{
|
| 25 |
+
/* Check for proper usage */
|
| 26 |
+
bool usageOk = true;
|
| 27 |
+
if (nrhs != 4)
|
| 28 |
+
usageOk = false;
|
| 29 |
+
if (nlhs > 1)
|
| 30 |
+
usageOk = false;
|
| 31 |
+
|
| 32 |
+
if (!usageOk)
|
| 33 |
+
mexErrMsgTxt("usage: [ <rcond>= ] observe_linear_uncorrelated(<handle>, <Hx>, <z>, <Z_vector>)");
|
| 34 |
+
|
| 35 |
+
// Check handle and get filter pointer
|
| 36 |
+
Run_Filter* filter = Run_Filter::from_handle(prhs[0]);
|
| 37 |
+
|
| 38 |
+
// Need filter state size
|
| 39 |
+
Bayesian_filter::State_filter* f = dynamic_cast<Bayesian_filter::State_filter*>(filter);
|
| 40 |
+
Run_Filter::check_def(f);
|
| 41 |
+
|
| 42 |
+
// Must catch exceptions for Matlab kernel
|
| 43 |
+
try
|
| 44 |
+
{
|
| 45 |
+
// Arguments
|
| 46 |
+
FM::Matrix Hx = Matrix(prhs[1]);
|
| 47 |
+
FM::Vec z = Vector(prhs[2]);
|
| 48 |
+
FM::Vec Zv = Vector(prhs[3]);
|
| 49 |
+
// Check matrix conformance
|
| 50 |
+
if (f->x.size() != Hx.size2())
|
| 51 |
+
mexErrMsgTxt("Mismatch in x and H matrix");
|
| 52 |
+
if (z.size() != Hx.size1())
|
| 53 |
+
mexErrMsgTxt("Mismatch in z and H matrix");
|
| 54 |
+
if (Zv.size() != z.size())
|
| 55 |
+
mexErrMsgTxt("Mismatch in z and Zv size");
|
| 56 |
+
|
| 57 |
+
// Observe model
|
| 58 |
+
Bayesian_filter::General_LiUnAd_observe_model model(Hx.size2(), z.size());
|
| 59 |
+
model.Hx = Hx;
|
| 60 |
+
model.Zv = Zv;
|
| 61 |
+
|
| 62 |
+
bool bFilterOp = false; // Flag operation complete
|
| 63 |
+
double rcond;
|
| 64 |
+
// Must be a Sample, Linrz filter
|
| 65 |
+
if (Bayesian_filter::Sample_filter* f = dynamic_cast<Bayesian_filter::Sample_filter*>(filter)) {
|
| 66 |
+
bFilterOp = true;
|
| 67 |
+
f->observe (model, z);
|
| 68 |
+
rcond = f->update_resample ();
|
| 69 |
+
}
|
| 70 |
+
else
|
| 71 |
+
if (Bayesian_filter::Linrz_filter* f = dynamic_cast<Bayesian_filter::Linrz_filter*>(filter)) {
|
| 72 |
+
bFilterOp = true;
|
| 73 |
+
rcond = f->observe (model, z);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
if (bFilterOp) {
|
| 77 |
+
if (nlhs == 1) // Optional return value
|
| 78 |
+
plhs[0] = Array(rcond);
|
| 79 |
+
}
|
| 80 |
+
else {
|
| 81 |
+
Run_Filter::check_def(0);
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
catch (std::exception& se)
|
| 85 |
+
{
|
| 86 |
+
mexErrMsgTxt( se.what() );
|
| 87 |
+
}
|
| 88 |
+
catch (...)
|
| 89 |
+
{
|
| 90 |
+
mexErrMsgTxt( "Filter operation caused an unknown exception" );
|
| 91 |
+
}
|
| 92 |
+
}
|
pool/shard011/C++/0118432_DecoderBassmidi.cpp
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This is copyrighted software. More information is at the end of this file.
|
| 2 |
+
#include "Aulib/DecoderBassmidi.h"
|
| 3 |
+
|
| 4 |
+
#include "Buffer.h"
|
| 5 |
+
#include "aulib.h"
|
| 6 |
+
#include "aulib_debug.h"
|
| 7 |
+
#include "missing.h"
|
| 8 |
+
#include <SDL_audio.h>
|
| 9 |
+
#include <SDL_rwops.h>
|
| 10 |
+
#include <bass.h>
|
| 11 |
+
#include <bassmidi.h>
|
| 12 |
+
|
| 13 |
+
namespace chrono = std::chrono;
|
| 14 |
+
|
| 15 |
+
static bool bassIsInitialized = false;
|
| 16 |
+
|
| 17 |
+
class HstreamWrapper final
|
| 18 |
+
{
|
| 19 |
+
public:
|
| 20 |
+
HstreamWrapper() noexcept = default;
|
| 21 |
+
|
| 22 |
+
explicit HstreamWrapper(BOOL mem, const void* file, QWORD offset, QWORD len, DWORD flags,
|
| 23 |
+
DWORD freq)
|
| 24 |
+
{
|
| 25 |
+
reset(mem, file, offset, len, flags, freq);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
HstreamWrapper(const HstreamWrapper&) = delete;
|
| 29 |
+
HstreamWrapper(HstreamWrapper&&) = delete;
|
| 30 |
+
auto operator=(const HstreamWrapper&) -> HstreamWrapper& = delete;
|
| 31 |
+
auto operator=(HstreamWrapper&&) -> HstreamWrapper& = delete;
|
| 32 |
+
|
| 33 |
+
~HstreamWrapper()
|
| 34 |
+
{
|
| 35 |
+
freeStream();
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
explicit operator bool() const noexcept
|
| 39 |
+
{
|
| 40 |
+
return hstream != 0;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
auto get() const noexcept -> HSTREAM
|
| 44 |
+
{
|
| 45 |
+
return hstream;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
void reset(BOOL mem, const void* file, QWORD offset, QWORD len, DWORD flags, DWORD freq)
|
| 49 |
+
{
|
| 50 |
+
freeStream();
|
| 51 |
+
hstream = BASS_MIDI_StreamCreateFile(mem, file, offset, len, flags, freq);
|
| 52 |
+
if (hstream == 0) {
|
| 53 |
+
AM_debugPrintLn("DecoderBassmidi: got BASS error " << BASS_ErrorGetCode()
|
| 54 |
+
<< " while creating HSTREAM.");
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
void swap(HstreamWrapper& other) noexcept
|
| 59 |
+
{
|
| 60 |
+
std::swap(hstream, other.hstream);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
private:
|
| 64 |
+
HSTREAM hstream = 0;
|
| 65 |
+
|
| 66 |
+
void freeStream() noexcept
|
| 67 |
+
{
|
| 68 |
+
if (hstream == 0) {
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
if (BASS_StreamFree(hstream) == 0) {
|
| 72 |
+
AM_debugPrintLn("DecoderBassmidi: got BASS error " << BASS_ErrorGetCode()
|
| 73 |
+
<< " while freeing HSTREAM.");
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
namespace Aulib {
|
| 79 |
+
|
| 80 |
+
struct DecoderBassmidi_priv final
|
| 81 |
+
{
|
| 82 |
+
DecoderBassmidi_priv();
|
| 83 |
+
|
| 84 |
+
HstreamWrapper hstream;
|
| 85 |
+
Buffer<Uint8> midiData{0};
|
| 86 |
+
bool eof = false;
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
} // namespace Aulib
|
| 90 |
+
|
| 91 |
+
Aulib::DecoderBassmidi_priv::DecoderBassmidi_priv()
|
| 92 |
+
{
|
| 93 |
+
if (bassIsInitialized) {
|
| 94 |
+
return;
|
| 95 |
+
}
|
| 96 |
+
if (BASS_Init(0, Aulib::sampleRate(), 0, nullptr, nullptr) != 0) {
|
| 97 |
+
bassIsInitialized = true;
|
| 98 |
+
return;
|
| 99 |
+
}
|
| 100 |
+
AM_debugPrintLn("DecoderBassmidi: got BASS error " << BASS_ErrorGetCode()
|
| 101 |
+
<< " while initializing.");
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
Aulib::DecoderBassmidi::DecoderBassmidi()
|
| 105 |
+
: d(std::make_unique<DecoderBassmidi_priv>())
|
| 106 |
+
{}
|
| 107 |
+
|
| 108 |
+
Aulib::DecoderBassmidi::~DecoderBassmidi() = default;
|
| 109 |
+
|
| 110 |
+
auto Aulib::DecoderBassmidi::setDefaultSoundfont(const std::string& filename) -> bool
|
| 111 |
+
{
|
| 112 |
+
if (BASS_SetConfigPtr(BASS_CONFIG_MIDI_DEFFONT, filename.c_str()) != 0) {
|
| 113 |
+
return true;
|
| 114 |
+
}
|
| 115 |
+
AM_debugPrintLn("DecoderBassmidi: got BASS error " << BASS_ErrorGetCode()
|
| 116 |
+
<< " while setting default soundfont.");
|
| 117 |
+
return false;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
auto Aulib::DecoderBassmidi::open(SDL_RWops* rwops) -> bool
|
| 121 |
+
{
|
| 122 |
+
if (isOpen()) {
|
| 123 |
+
return true;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// FIXME: error reporting
|
| 127 |
+
Sint64 midiDataLen = SDL_RWsize(rwops);
|
| 128 |
+
if (midiDataLen <= 0) {
|
| 129 |
+
return false;
|
| 130 |
+
}
|
| 131 |
+
Buffer<Uint8> newMidiData(midiDataLen);
|
| 132 |
+
DWORD bassFlags =
|
| 133 |
+
BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE | BASS_MIDI_DECAYEND | BASS_MIDI_SINCINTER;
|
| 134 |
+
|
| 135 |
+
if (SDL_RWread(rwops, newMidiData.get(), newMidiData.size(), 1) != 1) {
|
| 136 |
+
return false;
|
| 137 |
+
}
|
| 138 |
+
d->hstream.reset(TRUE, newMidiData.get(), 0, newMidiData.size(), bassFlags, 1);
|
| 139 |
+
if (not d->hstream) {
|
| 140 |
+
return false;
|
| 141 |
+
}
|
| 142 |
+
d->midiData.swap(newMidiData);
|
| 143 |
+
setIsOpen(true);
|
| 144 |
+
return true;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
auto Aulib::DecoderBassmidi::getChannels() const -> int
|
| 148 |
+
{
|
| 149 |
+
return 2;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
auto Aulib::DecoderBassmidi::getRate() const -> int
|
| 153 |
+
{
|
| 154 |
+
if (not isOpen()) {
|
| 155 |
+
return 0;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
BASS_CHANNELINFO inf;
|
| 159 |
+
if (BASS_ChannelGetInfo(d->hstream.get(), &inf) != 0) {
|
| 160 |
+
return inf.freq;
|
| 161 |
+
}
|
| 162 |
+
AM_debugPrintLn("DecoderBassmidi: got BASS error " << BASS_ErrorGetCode()
|
| 163 |
+
<< " while getting BASS_CHANNELINFO");
|
| 164 |
+
return 0;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
auto Aulib::DecoderBassmidi::doDecoding(float buf[], int len, bool& /*callAgain*/) -> int
|
| 168 |
+
{
|
| 169 |
+
if (d->eof or not isOpen()) {
|
| 170 |
+
return 0;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
DWORD byteLen = len * static_cast<int>(sizeof(*buf));
|
| 174 |
+
DWORD ret = BASS_ChannelGetData(d->hstream.get(), buf, byteLen | BASS_DATA_FLOAT);
|
| 175 |
+
if (ret == static_cast<DWORD>(-1)) {
|
| 176 |
+
SDL_SetError("DecoderBassmidi: got BASS error %d during decoding.\n", BASS_ErrorGetCode());
|
| 177 |
+
return 0;
|
| 178 |
+
}
|
| 179 |
+
if (ret < byteLen) {
|
| 180 |
+
d->eof = true;
|
| 181 |
+
}
|
| 182 |
+
return ret / static_cast<int>(sizeof(*buf));
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
auto Aulib::DecoderBassmidi::rewind() -> bool
|
| 186 |
+
{
|
| 187 |
+
return seekToTime(chrono::microseconds::zero());
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
auto Aulib::DecoderBassmidi::duration() const -> chrono::microseconds
|
| 191 |
+
{
|
| 192 |
+
if (not isOpen()) {
|
| 193 |
+
return {};
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
QWORD pos = BASS_ChannelGetLength(d->hstream.get(), BASS_POS_BYTE);
|
| 197 |
+
if (pos == static_cast<QWORD>(-1)) {
|
| 198 |
+
AM_debugPrintLn("DecoderBassmidi: got BASS error " << BASS_ErrorGetCode()
|
| 199 |
+
<< " while getting channel length.");
|
| 200 |
+
return {};
|
| 201 |
+
}
|
| 202 |
+
double sec = BASS_ChannelBytes2Seconds(d->hstream.get(), pos);
|
| 203 |
+
if (sec < 0) {
|
| 204 |
+
AM_debugPrintLn("DecoderBassmidi: got BASS error "
|
| 205 |
+
<< BASS_ErrorGetCode()
|
| 206 |
+
<< " while translating duration from bytes to seconds.");
|
| 207 |
+
return {};
|
| 208 |
+
}
|
| 209 |
+
return chrono::duration_cast<chrono::microseconds>(chrono::duration<double>(sec));
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
auto Aulib::DecoderBassmidi::seekToTime(chrono::microseconds pos) -> bool
|
| 213 |
+
{
|
| 214 |
+
if (not isOpen()) {
|
| 215 |
+
return false;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
QWORD bytePos =
|
| 219 |
+
BASS_ChannelSeconds2Bytes(d->hstream.get(), chrono::duration<double>(pos).count());
|
| 220 |
+
if (bytePos == static_cast<QWORD>(-1)) {
|
| 221 |
+
SDL_SetError("DecoderBassmidi: got BASS error %d while translating seek time to bytes.",
|
| 222 |
+
BASS_ErrorGetCode());
|
| 223 |
+
return false;
|
| 224 |
+
}
|
| 225 |
+
if (BASS_ChannelSetPosition(d->hstream.get(), bytePos, BASS_POS_BYTE) == 0) {
|
| 226 |
+
SDL_SetError("DecoderBassmidi: got BASS error %d during rewinding.\n", BASS_ErrorGetCode());
|
| 227 |
+
return false;
|
| 228 |
+
}
|
| 229 |
+
d->eof = false;
|
| 230 |
+
return true;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
/*
|
| 234 |
+
|
| 235 |
+
Copyright (C) 2014, 2015, 2016, 2017, 2018, 2019 Nikos Chantziaras.
|
| 236 |
+
|
| 237 |
+
This file is part of SDL_audiolib.
|
| 238 |
+
|
| 239 |
+
SDL_audiolib is free software: you can redistribute it and/or modify it under
|
| 240 |
+
the terms of the GNU Lesser General Public License as published by the Free
|
| 241 |
+
Software Foundation, either version 3 of the License, or (at your option) any
|
| 242 |
+
later version.
|
| 243 |
+
|
| 244 |
+
SDL_audiolib is distributed in the hope that it will be useful, but WITHOUT
|
| 245 |
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
| 246 |
+
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
| 247 |
+
details.
|
| 248 |
+
|
| 249 |
+
You should have received a copy of the GNU Lesser General Public License
|
| 250 |
+
along with SDL_audiolib. If not, see <http://www.gnu.org/licenses/>.
|
| 251 |
+
|
| 252 |
+
*/
|
pool/shard011/C++/0118433_stubserver.cpp
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*************************************************************************
|
| 2 |
+
* libjson-rpc-cpp
|
| 3 |
+
*************************************************************************
|
| 4 |
+
* @file stubserver.cpp
|
| 5 |
+
* @date 02.05.2013
|
| 6 |
+
* @author Peter Spiess-Knafl <dev@spiessknafl.at>
|
| 7 |
+
* @license See attached LICENSE.txt
|
| 8 |
+
************************************************************************/
|
| 9 |
+
#include <iostream>
|
| 10 |
+
|
| 11 |
+
#include "gen/abstractstubserver.h"
|
| 12 |
+
#include <jsonrpccpp/server/connectors/httpserver.h>
|
| 13 |
+
#include <stdio.h>
|
| 14 |
+
|
| 15 |
+
using namespace jsonrpc;
|
| 16 |
+
using namespace std;
|
| 17 |
+
|
| 18 |
+
class MyStubServer : public AbstractStubServer {
|
| 19 |
+
public:
|
| 20 |
+
MyStubServer(AbstractServerConnector &connector, serverVersion_t type);
|
| 21 |
+
|
| 22 |
+
virtual void notifyServer();
|
| 23 |
+
virtual std::string sayHello(const std::string &name);
|
| 24 |
+
virtual int addNumbers(int param1, int param2);
|
| 25 |
+
virtual double addNumbers2(double param1, double param2);
|
| 26 |
+
virtual bool isEqual(const std::string &str1, const std::string &str2);
|
| 27 |
+
virtual Json::Value buildObject(const std::string &name, int age);
|
| 28 |
+
virtual std::string methodWithoutParameters();
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
MyStubServer::MyStubServer(AbstractServerConnector &connector,
|
| 32 |
+
serverVersion_t type)
|
| 33 |
+
: AbstractStubServer(connector, type) {}
|
| 34 |
+
|
| 35 |
+
void MyStubServer::notifyServer() { cout << "Server got notified" << endl; }
|
| 36 |
+
|
| 37 |
+
string MyStubServer::sayHello(const string &name) { return "Hello " + name; }
|
| 38 |
+
|
| 39 |
+
int MyStubServer::addNumbers(int param1, int param2) { return param1 + param2; }
|
| 40 |
+
|
| 41 |
+
double MyStubServer::addNumbers2(double param1, double param2) {
|
| 42 |
+
return param1 + param2;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
bool MyStubServer::isEqual(const string &str1, const string &str2) {
|
| 46 |
+
return str1 == str2;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
Json::Value MyStubServer::buildObject(const string &name, int age) {
|
| 50 |
+
Json::Value result;
|
| 51 |
+
result["name"] = name;
|
| 52 |
+
result["year"] = age;
|
| 53 |
+
return result;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
string MyStubServer::methodWithoutParameters() { return "Test"; }
|
| 57 |
+
|
| 58 |
+
int main() {
|
| 59 |
+
HttpServer httpserver(8383);
|
| 60 |
+
MyStubServer s(httpserver,
|
| 61 |
+
JSONRPC_SERVER_V1V2); // hybrid server (json-rpc 1.0 & 2.0)
|
| 62 |
+
s.StartListening();
|
| 63 |
+
cout << "Hit enter to stop the server" << endl;
|
| 64 |
+
getchar();
|
| 65 |
+
|
| 66 |
+
s.StopListening();
|
| 67 |
+
|
| 68 |
+
return 0;
|
| 69 |
+
}
|
pool/shard011/C++/0118434_CWE190_Integer_Overflow__char_fscanf_square_74b.cpp
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE190_Integer_Overflow__char_fscanf_square_74b.cpp
|
| 3 |
+
Label Definition File: CWE190_Integer_Overflow.label.xml
|
| 4 |
+
Template File: sources-sinks-74b.tmpl.cpp
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 190 Integer Overflow
|
| 9 |
+
* BadSource: fscanf Read data from the console using fscanf()
|
| 10 |
+
* GoodSource: Set data to a small, non-zero number (two)
|
| 11 |
+
* Sinks: square
|
| 12 |
+
* GoodSink: Ensure there will not be an overflow before squaring data
|
| 13 |
+
* BadSink : Square data, which can lead to overflow
|
| 14 |
+
* Flow Variant: 74 Data flow: data passed in a map from one function to another in different source files
|
| 15 |
+
*
|
| 16 |
+
* */
|
| 17 |
+
|
| 18 |
+
#include "std_testcase.h"
|
| 19 |
+
#include <map>
|
| 20 |
+
|
| 21 |
+
#include <math.h>
|
| 22 |
+
|
| 23 |
+
using namespace std;
|
| 24 |
+
|
| 25 |
+
namespace CWE190_Integer_Overflow__char_fscanf_square_74
|
| 26 |
+
{
|
| 27 |
+
|
| 28 |
+
#ifndef OMITBAD
|
| 29 |
+
|
| 30 |
+
void badSink(map<int, char> dataMap)
|
| 31 |
+
{
|
| 32 |
+
/* copy data out of dataMap */
|
| 33 |
+
char data = dataMap[2];
|
| 34 |
+
{
|
| 35 |
+
/* POTENTIAL FLAW: if (data*data) > CHAR_MAX, this will overflow */
|
| 36 |
+
char result = data * data;
|
| 37 |
+
printHexCharLine(result);
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
#endif /* OMITBAD */
|
| 42 |
+
|
| 43 |
+
#ifndef OMITGOOD
|
| 44 |
+
|
| 45 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 46 |
+
void goodG2BSink(map<int, char> dataMap)
|
| 47 |
+
{
|
| 48 |
+
char data = dataMap[2];
|
| 49 |
+
{
|
| 50 |
+
/* POTENTIAL FLAW: if (data*data) > CHAR_MAX, this will overflow */
|
| 51 |
+
char result = data * data;
|
| 52 |
+
printHexCharLine(result);
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/* goodB2G uses the BadSource with the GoodSink */
|
| 57 |
+
void goodB2GSink(map<int, char> dataMap)
|
| 58 |
+
{
|
| 59 |
+
char data = dataMap[2];
|
| 60 |
+
/* FIX: Add a check to prevent an overflow from occurring */
|
| 61 |
+
if (abs((long)data) <= (long)sqrt((double)CHAR_MAX))
|
| 62 |
+
{
|
| 63 |
+
char result = data * data;
|
| 64 |
+
printHexCharLine(result);
|
| 65 |
+
}
|
| 66 |
+
else
|
| 67 |
+
{
|
| 68 |
+
printLine("data value is too large to perform arithmetic safely.");
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
#endif /* OMITGOOD */
|
| 73 |
+
|
| 74 |
+
} /* close namespace */
|
pool/shard011/C++/0118437_DodgeBurn.cpp
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2009 Cyrille Berger <cberger@cberger.net>
|
| 3 |
+
*
|
| 4 |
+
* This program is free software; you can redistribute it and/or modify
|
| 5 |
+
* it under the terms of the GNU Lesser General Public License as published by
|
| 6 |
+
* the Free Software Foundation; version 2 of the License.
|
| 7 |
+
*
|
| 8 |
+
* This program is distributed in the hope that it will be useful,
|
| 9 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 10 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 11 |
+
* GNU General Public License for more details.
|
| 12 |
+
*
|
| 13 |
+
* You should have received a copy of the GNU Lesser General Public License
|
| 14 |
+
* along with this program; if not, write to the Free Software
|
| 15 |
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
#include "DodgeBurn.h"
|
| 19 |
+
#include <filter/kis_filter_configuration.h>
|
| 20 |
+
#include <kis_paint_device.h>
|
| 21 |
+
|
| 22 |
+
#include "ui_DodgeBurnConfigurationBaseWidget.h"
|
| 23 |
+
|
| 24 |
+
KisFilterDodgeBurn::KisFilterDodgeBurn(const QString& id, const QString& prefix, const QString& name ) : KisColorTransformationFilter(KoID(id, name), categoryAdjust(), name), m_prefix(prefix)
|
| 25 |
+
{
|
| 26 |
+
setColorSpaceIndependence(FULLY_INDEPENDENT);
|
| 27 |
+
setSupportsPainting(true);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
KisConfigWidget * KisFilterDodgeBurn::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev) const
|
| 31 |
+
{
|
| 32 |
+
Q_UNUSED(dev);
|
| 33 |
+
return new KisDodgeBurnConfigWidget(parent, id());
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
KoColorTransformation* KisFilterDodgeBurn::createTransformation(const KoColorSpace* cs, const KisFilterConfiguration* config) const
|
| 37 |
+
{
|
| 38 |
+
QHash<QString, QVariant> params;
|
| 39 |
+
QString suffix = "Midtones";
|
| 40 |
+
if (config) {
|
| 41 |
+
params["exposure"] = config->getDouble("exposure", 0.5);
|
| 42 |
+
int type = config->getInt("type", KisFilterDodgeBurn::MIDTONES);
|
| 43 |
+
switch(type)
|
| 44 |
+
{
|
| 45 |
+
case KisFilterDodgeBurn::HIGHLIGHTS:
|
| 46 |
+
suffix = "Highlights";
|
| 47 |
+
break;
|
| 48 |
+
case KisFilterDodgeBurn::SHADOWS:
|
| 49 |
+
suffix = "Shadows";
|
| 50 |
+
break;
|
| 51 |
+
default:
|
| 52 |
+
break;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
return cs->createColorTransformation(m_prefix + suffix, params);
|
| 56 |
+
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
KisDodgeBurnConfigWidget::KisDodgeBurnConfigWidget(QWidget * parent, const QString& id) : KisConfigWidget(parent), m_id(id)
|
| 60 |
+
{
|
| 61 |
+
m_page = new Ui_DodgeBurnConfigurationBaseWidget();
|
| 62 |
+
m_page->setupUi(this);
|
| 63 |
+
|
| 64 |
+
connect(m_page->radioButtonHighlights, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged()));
|
| 65 |
+
connect(m_page->radioButtonMidtones, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged()));
|
| 66 |
+
connect(m_page->radioButtonShadows, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged()));
|
| 67 |
+
connect(m_page->sliderExposure, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
KisDodgeBurnConfigWidget::~KisDodgeBurnConfigWidget()
|
| 71 |
+
{
|
| 72 |
+
delete m_page;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
KisPropertiesConfiguration * KisDodgeBurnConfigWidget::configuration() const
|
| 76 |
+
{
|
| 77 |
+
KisFilterConfiguration* c = new KisFilterConfiguration(m_id, 0);
|
| 78 |
+
int type = 0;
|
| 79 |
+
if(m_page->radioButtonHighlights->isChecked())
|
| 80 |
+
{
|
| 81 |
+
type = KisFilterDodgeBurn::HIGHLIGHTS;
|
| 82 |
+
} else if(m_page->radioButtonShadows->isChecked())
|
| 83 |
+
{
|
| 84 |
+
type = KisFilterDodgeBurn::SHADOWS;
|
| 85 |
+
} else {
|
| 86 |
+
type = KisFilterDodgeBurn::MIDTONES;
|
| 87 |
+
}
|
| 88 |
+
c->setProperty("type", type);
|
| 89 |
+
c->setProperty("exposure", m_page->sliderExposure->value() / 100.0);
|
| 90 |
+
return c;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
void KisDodgeBurnConfigWidget::setConfiguration(const KisPropertiesConfiguration * config)
|
| 94 |
+
{
|
| 95 |
+
int type = config->getInt("type", KisFilterDodgeBurn::MIDTONES);
|
| 96 |
+
switch(type)
|
| 97 |
+
{
|
| 98 |
+
case KisFilterDodgeBurn::HIGHLIGHTS:
|
| 99 |
+
m_page->radioButtonHighlights->setChecked(true);
|
| 100 |
+
break;
|
| 101 |
+
case KisFilterDodgeBurn::SHADOWS:
|
| 102 |
+
m_page->radioButtonShadows->setChecked(true);
|
| 103 |
+
break;
|
| 104 |
+
default:
|
| 105 |
+
case KisFilterDodgeBurn::MIDTONES:
|
| 106 |
+
m_page->radioButtonMidtones->setChecked(true);
|
| 107 |
+
break;
|
| 108 |
+
}
|
| 109 |
+
m_page->sliderExposure->setValue(config->getDouble("exposure", 0.5) * 100);
|
| 110 |
+
}
|
| 111 |
+
|
pool/shard011/C++/0118440_walletframe.cpp
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2011-2013 The Bitcoin Core and Deuscoin Core developers
|
| 2 |
+
// Distributed under the MIT/X11 software license, see the accompanying
|
| 3 |
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 4 |
+
|
| 5 |
+
#include "walletframe.h"
|
| 6 |
+
|
| 7 |
+
#include "deuscoingui.h"
|
| 8 |
+
#include "walletview.h"
|
| 9 |
+
|
| 10 |
+
#include <cstdio>
|
| 11 |
+
|
| 12 |
+
#include <QHBoxLayout>
|
| 13 |
+
#include <QLabel>
|
| 14 |
+
|
| 15 |
+
WalletFrame::WalletFrame(DeuscoinGUI *_gui) :
|
| 16 |
+
QFrame(_gui),
|
| 17 |
+
gui(_gui)
|
| 18 |
+
{
|
| 19 |
+
// Leave HBox hook for adding a list view later
|
| 20 |
+
QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
|
| 21 |
+
setContentsMargins(0,0,0,0);
|
| 22 |
+
walletStack = new QStackedWidget(this);
|
| 23 |
+
walletFrameLayout->setContentsMargins(0,0,0,0);
|
| 24 |
+
walletFrameLayout->addWidget(walletStack);
|
| 25 |
+
|
| 26 |
+
QLabel *noWallet = new QLabel(tr("No wallet has been loaded."));
|
| 27 |
+
noWallet->setAlignment(Qt::AlignCenter);
|
| 28 |
+
walletStack->addWidget(noWallet);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
WalletFrame::~WalletFrame()
|
| 32 |
+
{
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
void WalletFrame::setClientModel(ClientModel *clientModel)
|
| 36 |
+
{
|
| 37 |
+
this->clientModel = clientModel;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
|
| 41 |
+
{
|
| 42 |
+
if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
|
| 43 |
+
return false;
|
| 44 |
+
|
| 45 |
+
WalletView *walletView = new WalletView(this);
|
| 46 |
+
walletView->setDeuscoinGUI(gui);
|
| 47 |
+
walletView->setClientModel(clientModel);
|
| 48 |
+
walletView->setWalletModel(walletModel);
|
| 49 |
+
walletView->showOutOfSyncWarning(bOutOfSync);
|
| 50 |
+
|
| 51 |
+
/* TODO we should goto the currently selected page once dynamically adding wallets is supported */
|
| 52 |
+
walletView->gotoOverviewPage();
|
| 53 |
+
walletStack->addWidget(walletView);
|
| 54 |
+
mapWalletViews[name] = walletView;
|
| 55 |
+
|
| 56 |
+
// Ensure a walletView is able to show the main window
|
| 57 |
+
connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
|
| 58 |
+
|
| 59 |
+
return true;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
bool WalletFrame::setCurrentWallet(const QString& name)
|
| 63 |
+
{
|
| 64 |
+
if (mapWalletViews.count(name) == 0)
|
| 65 |
+
return false;
|
| 66 |
+
|
| 67 |
+
WalletView *walletView = mapWalletViews.value(name);
|
| 68 |
+
walletStack->setCurrentWidget(walletView);
|
| 69 |
+
walletView->updateEncryptionStatus();
|
| 70 |
+
return true;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
bool WalletFrame::removeWallet(const QString &name)
|
| 74 |
+
{
|
| 75 |
+
if (mapWalletViews.count(name) == 0)
|
| 76 |
+
return false;
|
| 77 |
+
|
| 78 |
+
WalletView *walletView = mapWalletViews.take(name);
|
| 79 |
+
walletStack->removeWidget(walletView);
|
| 80 |
+
return true;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
void WalletFrame::removeAllWallets()
|
| 84 |
+
{
|
| 85 |
+
QMap<QString, WalletView*>::const_iterator i;
|
| 86 |
+
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
| 87 |
+
walletStack->removeWidget(i.value());
|
| 88 |
+
mapWalletViews.clear();
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
|
| 92 |
+
{
|
| 93 |
+
WalletView *walletView = currentWalletView();
|
| 94 |
+
if (!walletView)
|
| 95 |
+
return false;
|
| 96 |
+
|
| 97 |
+
return walletView->handlePaymentRequest(recipient);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
void WalletFrame::showOutOfSyncWarning(bool fShow)
|
| 101 |
+
{
|
| 102 |
+
bOutOfSync = fShow;
|
| 103 |
+
QMap<QString, WalletView*>::const_iterator i;
|
| 104 |
+
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
| 105 |
+
i.value()->showOutOfSyncWarning(fShow);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
void WalletFrame::gotoOverviewPage()
|
| 109 |
+
{
|
| 110 |
+
QMap<QString, WalletView*>::const_iterator i;
|
| 111 |
+
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
| 112 |
+
i.value()->gotoOverviewPage();
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
void WalletFrame::gotoHistoryPage()
|
| 116 |
+
{
|
| 117 |
+
QMap<QString, WalletView*>::const_iterator i;
|
| 118 |
+
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
| 119 |
+
i.value()->gotoHistoryPage();
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
void WalletFrame::gotoReceiveCoinsPage()
|
| 123 |
+
{
|
| 124 |
+
QMap<QString, WalletView*>::const_iterator i;
|
| 125 |
+
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
| 126 |
+
i.value()->gotoReceiveCoinsPage();
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
void WalletFrame::gotoSendCoinsPage(QString addr)
|
| 130 |
+
{
|
| 131 |
+
QMap<QString, WalletView*>::const_iterator i;
|
| 132 |
+
for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
|
| 133 |
+
i.value()->gotoSendCoinsPage(addr);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
void WalletFrame::gotoSignMessageTab(QString addr)
|
| 137 |
+
{
|
| 138 |
+
WalletView *walletView = currentWalletView();
|
| 139 |
+
if (walletView)
|
| 140 |
+
walletView->gotoSignMessageTab(addr);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
void WalletFrame::gotoVerifyMessageTab(QString addr)
|
| 144 |
+
{
|
| 145 |
+
WalletView *walletView = currentWalletView();
|
| 146 |
+
if (walletView)
|
| 147 |
+
walletView->gotoVerifyMessageTab(addr);
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
void WalletFrame::encryptWallet(bool status)
|
| 151 |
+
{
|
| 152 |
+
WalletView *walletView = currentWalletView();
|
| 153 |
+
if (walletView)
|
| 154 |
+
walletView->encryptWallet(status);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
void WalletFrame::backupWallet()
|
| 158 |
+
{
|
| 159 |
+
WalletView *walletView = currentWalletView();
|
| 160 |
+
if (walletView)
|
| 161 |
+
walletView->backupWallet();
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
void WalletFrame::changePassphrase()
|
| 165 |
+
{
|
| 166 |
+
WalletView *walletView = currentWalletView();
|
| 167 |
+
if (walletView)
|
| 168 |
+
walletView->changePassphrase();
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
void WalletFrame::unlockWallet()
|
| 172 |
+
{
|
| 173 |
+
WalletView *walletView = currentWalletView();
|
| 174 |
+
if (walletView)
|
| 175 |
+
walletView->unlockWallet();
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
void WalletFrame::usedSendingAddresses()
|
| 179 |
+
{
|
| 180 |
+
WalletView *walletView = currentWalletView();
|
| 181 |
+
if (walletView)
|
| 182 |
+
walletView->usedSendingAddresses();
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
void WalletFrame::usedReceivingAddresses()
|
| 186 |
+
{
|
| 187 |
+
WalletView *walletView = currentWalletView();
|
| 188 |
+
if (walletView)
|
| 189 |
+
walletView->usedReceivingAddresses();
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
WalletView *WalletFrame::currentWalletView()
|
| 193 |
+
{
|
| 194 |
+
return qobject_cast<WalletView*>(walletStack->currentWidget());
|
| 195 |
+
}
|
| 196 |
+
|
pool/shard011/C++/0118441_shared_module_service_unittest.cc
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2014 The Chromium Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style license that can be
|
| 3 |
+
// found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "base/memory/ref_counted.h"
|
| 6 |
+
#include "base/memory/scoped_ptr.h"
|
| 7 |
+
#include "base/strings/string16.h"
|
| 8 |
+
#include "base/values.h"
|
| 9 |
+
#include "chrome/browser/extensions/extension_service.h"
|
| 10 |
+
#include "chrome/browser/extensions/extension_service_test_base.h"
|
| 11 |
+
#include "chrome/browser/extensions/pending_extension_manager.h"
|
| 12 |
+
#include "chrome/browser/extensions/shared_module_service.h"
|
| 13 |
+
#include "chrome/common/extensions/features/feature_channel.h"
|
| 14 |
+
#include "extensions/browser/extension_registry.h"
|
| 15 |
+
#include "extensions/browser/install_flag.h"
|
| 16 |
+
#include "extensions/common/extension_builder.h"
|
| 17 |
+
#include "extensions/common/id_util.h"
|
| 18 |
+
#include "extensions/common/value_builder.h"
|
| 19 |
+
#include "sync/api/string_ordinal.h"
|
| 20 |
+
|
| 21 |
+
namespace extensions {
|
| 22 |
+
|
| 23 |
+
namespace {
|
| 24 |
+
|
| 25 |
+
// Return an extension with |id| which imports a module with the given
|
| 26 |
+
// |import_id|.
|
| 27 |
+
scoped_refptr<Extension> CreateExtensionImportingModule(
|
| 28 |
+
const std::string& import_id, const std::string& id) {
|
| 29 |
+
scoped_ptr<base::DictionaryValue> manifest =
|
| 30 |
+
DictionaryBuilder()
|
| 31 |
+
.Set("name", "Has Dependent Modules")
|
| 32 |
+
.Set("version", "1.0")
|
| 33 |
+
.Set("manifest_version", 2)
|
| 34 |
+
.Set("import",
|
| 35 |
+
ListBuilder().Append(DictionaryBuilder().Set("id", import_id)))
|
| 36 |
+
.Build();
|
| 37 |
+
|
| 38 |
+
return ExtensionBuilder().SetManifest(manifest.Pass())
|
| 39 |
+
.AddFlags(Extension::FROM_WEBSTORE)
|
| 40 |
+
.SetID(id)
|
| 41 |
+
.Build();
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
} // namespace
|
| 45 |
+
|
| 46 |
+
class SharedModuleServiceUnitTest : public ExtensionServiceTestBase {
|
| 47 |
+
public:
|
| 48 |
+
SharedModuleServiceUnitTest() :
|
| 49 |
+
// The "export" key is open for dev-channel only, but unit tests
|
| 50 |
+
// run as stable channel on the official Windows build.
|
| 51 |
+
current_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {}
|
| 52 |
+
protected:
|
| 53 |
+
virtual void SetUp() OVERRIDE;
|
| 54 |
+
|
| 55 |
+
// Install an extension and notify the ExtensionService.
|
| 56 |
+
testing::AssertionResult InstallExtension(const Extension* extension);
|
| 57 |
+
ScopedCurrentChannel current_channel_;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
void SharedModuleServiceUnitTest::SetUp() {
|
| 61 |
+
ExtensionServiceTestBase::SetUp();
|
| 62 |
+
InitializeGoodInstalledExtensionService();
|
| 63 |
+
service_->Init();
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
testing::AssertionResult SharedModuleServiceUnitTest::InstallExtension(
|
| 67 |
+
const Extension* extension) {
|
| 68 |
+
// Verify the extension is not already installed.
|
| 69 |
+
if (registry()->GetExtensionById(extension->id(),
|
| 70 |
+
ExtensionRegistry::ENABLED)) {
|
| 71 |
+
return testing::AssertionFailure() << "Extension already installed.";
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// Notify the service that the extension is installed. This adds it to the
|
| 75 |
+
// registry, notifies interested parties, etc.
|
| 76 |
+
service_->OnExtensionInstalled(
|
| 77 |
+
extension, syncer::StringOrdinal(), kInstallFlagInstallImmediately);
|
| 78 |
+
|
| 79 |
+
// Verify that the extension is now installed.
|
| 80 |
+
if (!registry()->GetExtensionById(extension->id(),
|
| 81 |
+
ExtensionRegistry::ENABLED)) {
|
| 82 |
+
return testing::AssertionFailure() << "Could not install extension.";
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
return testing::AssertionSuccess();
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
TEST_F(SharedModuleServiceUnitTest, AddDependentSharedModules) {
|
| 89 |
+
// Create an extension that has a dependency.
|
| 90 |
+
std::string import_id = id_util::GenerateId("id");
|
| 91 |
+
std::string extension_id = id_util::GenerateId("extension_id");
|
| 92 |
+
scoped_refptr<Extension> extension =
|
| 93 |
+
CreateExtensionImportingModule(import_id, extension_id);
|
| 94 |
+
|
| 95 |
+
PendingExtensionManager* pending_extension_manager =
|
| 96 |
+
service_->pending_extension_manager();
|
| 97 |
+
|
| 98 |
+
// Verify that we don't currently want to install the imported module.
|
| 99 |
+
EXPECT_FALSE(pending_extension_manager->IsIdPending(import_id));
|
| 100 |
+
|
| 101 |
+
// Try to satisfy imports for the extension. This should queue the imported
|
| 102 |
+
// module's installation.
|
| 103 |
+
service_->shared_module_service()->SatisfyImports(extension);
|
| 104 |
+
EXPECT_TRUE(pending_extension_manager->IsIdPending(import_id));
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
TEST_F(SharedModuleServiceUnitTest, PruneSharedModulesOnUninstall) {
|
| 108 |
+
// Create a module which exports a resource, and install it.
|
| 109 |
+
scoped_ptr<base::DictionaryValue> manifest =
|
| 110 |
+
DictionaryBuilder()
|
| 111 |
+
.Set("name", "Shared Module")
|
| 112 |
+
.Set("version", "1.0")
|
| 113 |
+
.Set("manifest_version", 2)
|
| 114 |
+
.Set("export",
|
| 115 |
+
DictionaryBuilder().Set("resources",
|
| 116 |
+
ListBuilder().Append("foo.js"))).Build();
|
| 117 |
+
scoped_refptr<Extension> shared_module =
|
| 118 |
+
ExtensionBuilder().SetManifest(manifest.Pass())
|
| 119 |
+
.AddFlags(Extension::FROM_WEBSTORE)
|
| 120 |
+
.SetID(id_util::GenerateId("shared_module"))
|
| 121 |
+
.Build();
|
| 122 |
+
|
| 123 |
+
EXPECT_TRUE(InstallExtension(shared_module));
|
| 124 |
+
|
| 125 |
+
std::string extension_id = id_util::GenerateId("extension_id");
|
| 126 |
+
// Create and install an extension that imports our new module.
|
| 127 |
+
scoped_refptr<Extension> importing_extension =
|
| 128 |
+
CreateExtensionImportingModule(shared_module->id(), extension_id);
|
| 129 |
+
EXPECT_TRUE(InstallExtension(importing_extension));
|
| 130 |
+
|
| 131 |
+
// Uninstall the extension that imports our module.
|
| 132 |
+
base::string16 error;
|
| 133 |
+
service_->UninstallExtension(importing_extension->id(),
|
| 134 |
+
false, // Not external uninstall.
|
| 135 |
+
&error);
|
| 136 |
+
EXPECT_TRUE(error.empty());
|
| 137 |
+
|
| 138 |
+
// Since the module was only referenced by that single extension, it should
|
| 139 |
+
// have been uninstalled as a side-effect of uninstalling the extension that
|
| 140 |
+
// depended upon it.
|
| 141 |
+
EXPECT_FALSE(registry()->GetExtensionById(shared_module->id(),
|
| 142 |
+
ExtensionRegistry::EVERYTHING));
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
TEST_F(SharedModuleServiceUnitTest, WhitelistedImports) {
|
| 146 |
+
std::string whitelisted_id = id_util::GenerateId("whitelisted");
|
| 147 |
+
std::string nonwhitelisted_id = id_util::GenerateId("nonwhitelisted");
|
| 148 |
+
// Create a module which exports to a restricted whitelist.
|
| 149 |
+
scoped_ptr<base::DictionaryValue> manifest =
|
| 150 |
+
DictionaryBuilder()
|
| 151 |
+
.Set("name", "Shared Module")
|
| 152 |
+
.Set("version", "1.0")
|
| 153 |
+
.Set("manifest_version", 2)
|
| 154 |
+
.Set("export",
|
| 155 |
+
DictionaryBuilder().Set("whitelist",
|
| 156 |
+
ListBuilder()
|
| 157 |
+
.Append(whitelisted_id))
|
| 158 |
+
.Set("resources",
|
| 159 |
+
ListBuilder().Append("*"))).Build();
|
| 160 |
+
scoped_refptr<Extension> shared_module =
|
| 161 |
+
ExtensionBuilder().SetManifest(manifest.Pass())
|
| 162 |
+
.AddFlags(Extension::FROM_WEBSTORE)
|
| 163 |
+
.SetID(id_util::GenerateId("shared_module"))
|
| 164 |
+
.Build();
|
| 165 |
+
|
| 166 |
+
EXPECT_TRUE(InstallExtension(shared_module));
|
| 167 |
+
|
| 168 |
+
// Create and install an extension with the whitelisted ID.
|
| 169 |
+
scoped_refptr<Extension> whitelisted_extension =
|
| 170 |
+
CreateExtensionImportingModule(shared_module->id(), whitelisted_id);
|
| 171 |
+
EXPECT_TRUE(InstallExtension(whitelisted_extension));
|
| 172 |
+
|
| 173 |
+
// Try to install an extension with an ID that is not whitelisted.
|
| 174 |
+
scoped_refptr<Extension> nonwhitelisted_extension =
|
| 175 |
+
CreateExtensionImportingModule(shared_module->id(), nonwhitelisted_id);
|
| 176 |
+
EXPECT_FALSE(InstallExtension(nonwhitelisted_extension));
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
} // namespace extensions
|
pool/shard011/C++/0118442_konqframevisitor.cpp
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
This file is part of the KDE project
|
| 3 |
+
Copyright (C) 2007 David Faure <faure@kde.org>
|
| 4 |
+
|
| 5 |
+
This program is free software; you can redistribute it and/or
|
| 6 |
+
modify it under the terms of the GNU 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 program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 |
+
General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU General Public License
|
| 16 |
+
along with this program; see the file COPYING. If not, write to
|
| 17 |
+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
| 18 |
+
Boston, MA 02110-1301, USA.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include "konqframevisitor.h"
|
| 22 |
+
#include "konqframe.h"
|
| 23 |
+
#include "konqview.h"
|
| 24 |
+
|
| 25 |
+
bool KonqViewCollector::visit(KonqFrame *frame)
|
| 26 |
+
{
|
| 27 |
+
m_views.append(frame->childView());
|
| 28 |
+
return true;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
QList<KonqView *> KonqViewCollector::collect(KonqFrameBase *topLevel)
|
| 32 |
+
{
|
| 33 |
+
KonqViewCollector collector;
|
| 34 |
+
topLevel->accept(&collector);
|
| 35 |
+
return collector.m_views;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
bool KonqLinkableViewsCollector::visit(KonqFrame *frame)
|
| 39 |
+
{
|
| 40 |
+
if (!frame->childView()->isFollowActive()) {
|
| 41 |
+
m_views.append(frame->childView());
|
| 42 |
+
}
|
| 43 |
+
return true;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
QList<KonqView *> KonqLinkableViewsCollector::collect(KonqFrameBase *topLevel)
|
| 47 |
+
{
|
| 48 |
+
KonqLinkableViewsCollector collector;
|
| 49 |
+
topLevel->accept(&collector);
|
| 50 |
+
return collector.m_views;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
bool KonqModifiedViewsCollector::visit(KonqFrame *frame)
|
| 54 |
+
{
|
| 55 |
+
KonqView *view = frame->childView();
|
| 56 |
+
if (view && view->isModified()) {
|
| 57 |
+
m_views.append(view);
|
| 58 |
+
}
|
| 59 |
+
return true;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
QList<KonqView *> KonqModifiedViewsCollector::collect(KonqFrameBase *topLevel)
|
| 63 |
+
{
|
| 64 |
+
KonqModifiedViewsCollector collector;
|
| 65 |
+
topLevel->accept(&collector);
|
| 66 |
+
return collector.m_views;
|
| 67 |
+
}
|
| 68 |
+
|
pool/shard011/C++/0118443_io.cc
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Licensed to the Apache Software Foundation (ASF) under one
|
| 2 |
+
// or more contributor license agreements. See the NOTICE file
|
| 3 |
+
// distributed with this work for additional information
|
| 4 |
+
// regarding copyright ownership. The ASF licenses this file
|
| 5 |
+
// to you under the Apache License, Version 2.0 (the
|
| 6 |
+
// "License"); you may not use this file except in compliance
|
| 7 |
+
// with the License. You may obtain a copy of the License at
|
| 8 |
+
//
|
| 9 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
//
|
| 11 |
+
// Unless required by applicable law or agreed to in writing,
|
| 12 |
+
// software distributed under the License is distributed on an
|
| 13 |
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 14 |
+
// KIND, either express or implied. See the License for the
|
| 15 |
+
// specific language governing permissions and limitations
|
| 16 |
+
// under the License.
|
| 17 |
+
|
| 18 |
+
#include "plasma/io.h"
|
| 19 |
+
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <memory>
|
| 22 |
+
#include <sstream>
|
| 23 |
+
|
| 24 |
+
#include "arrow/status.h"
|
| 25 |
+
#include "arrow/util/bit_util.h"
|
| 26 |
+
#include "arrow/util/logging.h"
|
| 27 |
+
|
| 28 |
+
#include "plasma/common.h"
|
| 29 |
+
#include "plasma/plasma_generated.h"
|
| 30 |
+
|
| 31 |
+
using arrow::Status;
|
| 32 |
+
|
| 33 |
+
/// Number of times we try connecting to a socket.
|
| 34 |
+
constexpr int64_t kNumConnectAttempts = 80;
|
| 35 |
+
/// Time to wait between connection attempts to a socket.
|
| 36 |
+
constexpr int64_t kConnectTimeoutMs = 100;
|
| 37 |
+
|
| 38 |
+
namespace plasma {
|
| 39 |
+
|
| 40 |
+
using flatbuf::MessageType;
|
| 41 |
+
|
| 42 |
+
Status WriteBytes(int fd, uint8_t* cursor, size_t length) {
|
| 43 |
+
ssize_t nbytes = 0;
|
| 44 |
+
size_t bytesleft = length;
|
| 45 |
+
size_t offset = 0;
|
| 46 |
+
while (bytesleft > 0) {
|
| 47 |
+
// While we haven't written the whole message, write to the file descriptor,
|
| 48 |
+
// advance the cursor, and decrease the amount left to write.
|
| 49 |
+
nbytes = write(fd, cursor + offset, bytesleft);
|
| 50 |
+
if (nbytes < 0) {
|
| 51 |
+
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
|
| 52 |
+
continue;
|
| 53 |
+
}
|
| 54 |
+
return Status::IOError(strerror(errno));
|
| 55 |
+
} else if (nbytes == 0) {
|
| 56 |
+
return Status::IOError("Encountered unexpected EOF");
|
| 57 |
+
}
|
| 58 |
+
ARROW_CHECK(nbytes > 0);
|
| 59 |
+
bytesleft -= nbytes;
|
| 60 |
+
offset += nbytes;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
return Status::OK();
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
Status WriteMessage(int fd, MessageType type, int64_t length, uint8_t* bytes) {
|
| 67 |
+
int64_t version = arrow::BitUtil::ToLittleEndian(kPlasmaProtocolVersion);
|
| 68 |
+
assert(sizeof(MessageType) == sizeof(int64_t));
|
| 69 |
+
type = static_cast<MessageType>(
|
| 70 |
+
arrow::BitUtil::ToLittleEndian(static_cast<int64_t>(type)));
|
| 71 |
+
int64_t length_le = arrow::BitUtil::ToLittleEndian(length);
|
| 72 |
+
RETURN_NOT_OK(WriteBytes(fd, reinterpret_cast<uint8_t*>(&version), sizeof(version)));
|
| 73 |
+
RETURN_NOT_OK(WriteBytes(fd, reinterpret_cast<uint8_t*>(&type), sizeof(type)));
|
| 74 |
+
RETURN_NOT_OK(WriteBytes(fd, reinterpret_cast<uint8_t*>(&length_le), sizeof(length)));
|
| 75 |
+
return WriteBytes(fd, bytes, length * sizeof(char));
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
Status ReadBytes(int fd, uint8_t* cursor, size_t length) {
|
| 79 |
+
ssize_t nbytes = 0;
|
| 80 |
+
// Termination condition: EOF or read 'length' bytes total.
|
| 81 |
+
size_t bytesleft = length;
|
| 82 |
+
size_t offset = 0;
|
| 83 |
+
while (bytesleft > 0) {
|
| 84 |
+
nbytes = read(fd, cursor + offset, bytesleft);
|
| 85 |
+
if (nbytes < 0) {
|
| 86 |
+
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
|
| 87 |
+
continue;
|
| 88 |
+
}
|
| 89 |
+
return Status::IOError(strerror(errno));
|
| 90 |
+
} else if (0 == nbytes) {
|
| 91 |
+
return Status::IOError("Encountered unexpected EOF");
|
| 92 |
+
}
|
| 93 |
+
ARROW_CHECK(nbytes > 0);
|
| 94 |
+
bytesleft -= nbytes;
|
| 95 |
+
offset += nbytes;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
return Status::OK();
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
Status ReadMessage(int fd, MessageType* type, std::vector<uint8_t>* buffer) {
|
| 102 |
+
int64_t version;
|
| 103 |
+
RETURN_NOT_OK_ELSE(ReadBytes(fd, reinterpret_cast<uint8_t*>(&version), sizeof(version)),
|
| 104 |
+
*type = MessageType::PlasmaDisconnectClient);
|
| 105 |
+
version = arrow::BitUtil::FromLittleEndian(version);
|
| 106 |
+
ARROW_CHECK(version == kPlasmaProtocolVersion) << "version = " << version;
|
| 107 |
+
RETURN_NOT_OK_ELSE(ReadBytes(fd, reinterpret_cast<uint8_t*>(type), sizeof(*type)),
|
| 108 |
+
*type = MessageType::PlasmaDisconnectClient);
|
| 109 |
+
assert(sizeof(MessageType) == sizeof(int64_t));
|
| 110 |
+
*type = static_cast<MessageType>(
|
| 111 |
+
arrow::BitUtil::FromLittleEndian(static_cast<int64_t>(*type)));
|
| 112 |
+
int64_t length_temp;
|
| 113 |
+
RETURN_NOT_OK_ELSE(
|
| 114 |
+
ReadBytes(fd, reinterpret_cast<uint8_t*>(&length_temp), sizeof(length_temp)),
|
| 115 |
+
*type = MessageType::PlasmaDisconnectClient);
|
| 116 |
+
// The length must be read as an int64_t, but it should be used as a size_t.
|
| 117 |
+
size_t length = static_cast<size_t>(arrow::BitUtil::FromLittleEndian(length_temp));
|
| 118 |
+
if (length > buffer->size()) {
|
| 119 |
+
buffer->resize(length);
|
| 120 |
+
}
|
| 121 |
+
RETURN_NOT_OK_ELSE(ReadBytes(fd, buffer->data(), length),
|
| 122 |
+
*type = MessageType::PlasmaDisconnectClient);
|
| 123 |
+
return Status::OK();
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
int BindIpcSock(const std::string& pathname, bool shall_listen) {
|
| 127 |
+
struct sockaddr_un socket_address;
|
| 128 |
+
int socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
| 129 |
+
if (socket_fd < 0) {
|
| 130 |
+
ARROW_LOG(ERROR) << "socket() failed for pathname " << pathname;
|
| 131 |
+
return -1;
|
| 132 |
+
}
|
| 133 |
+
// Tell the system to allow the port to be reused.
|
| 134 |
+
int on = 1;
|
| 135 |
+
if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&on),
|
| 136 |
+
sizeof(on)) < 0) {
|
| 137 |
+
ARROW_LOG(ERROR) << "setsockopt failed for pathname " << pathname;
|
| 138 |
+
close(socket_fd);
|
| 139 |
+
return -1;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
unlink(pathname.c_str());
|
| 143 |
+
memset(&socket_address, 0, sizeof(socket_address));
|
| 144 |
+
socket_address.sun_family = AF_UNIX;
|
| 145 |
+
if (pathname.size() + 1 > sizeof(socket_address.sun_path)) {
|
| 146 |
+
ARROW_LOG(ERROR) << "Socket pathname is too long.";
|
| 147 |
+
close(socket_fd);
|
| 148 |
+
return -1;
|
| 149 |
+
}
|
| 150 |
+
strncpy(socket_address.sun_path, pathname.c_str(), pathname.size() + 1);
|
| 151 |
+
|
| 152 |
+
if (bind(socket_fd, reinterpret_cast<struct sockaddr*>(&socket_address),
|
| 153 |
+
sizeof(socket_address)) != 0) {
|
| 154 |
+
ARROW_LOG(ERROR) << "Bind failed for pathname " << pathname;
|
| 155 |
+
close(socket_fd);
|
| 156 |
+
return -1;
|
| 157 |
+
}
|
| 158 |
+
if (shall_listen && listen(socket_fd, 128) == -1) {
|
| 159 |
+
ARROW_LOG(ERROR) << "Could not listen to socket " << pathname;
|
| 160 |
+
close(socket_fd);
|
| 161 |
+
return -1;
|
| 162 |
+
}
|
| 163 |
+
return socket_fd;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
Status ConnectIpcSocketRetry(const std::string& pathname, int num_retries,
|
| 167 |
+
int64_t timeout, int* fd) {
|
| 168 |
+
// Pick the default values if the user did not specify.
|
| 169 |
+
if (num_retries < 0) {
|
| 170 |
+
num_retries = kNumConnectAttempts;
|
| 171 |
+
}
|
| 172 |
+
if (timeout < 0) {
|
| 173 |
+
timeout = kConnectTimeoutMs;
|
| 174 |
+
}
|
| 175 |
+
*fd = ConnectIpcSock(pathname);
|
| 176 |
+
while (*fd < 0 && num_retries > 0) {
|
| 177 |
+
ARROW_LOG(ERROR) << "Connection to IPC socket failed for pathname " << pathname
|
| 178 |
+
<< ", retrying " << num_retries << " more times";
|
| 179 |
+
// Sleep for timeout milliseconds.
|
| 180 |
+
usleep(static_cast<int>(timeout * 1000));
|
| 181 |
+
*fd = ConnectIpcSock(pathname);
|
| 182 |
+
--num_retries;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
// If we could not connect to the socket, exit.
|
| 186 |
+
if (*fd == -1) {
|
| 187 |
+
return Status::IOError("Could not connect to socket ", pathname);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
return Status::OK();
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
int ConnectIpcSock(const std::string& pathname) {
|
| 194 |
+
struct sockaddr_un socket_address;
|
| 195 |
+
int socket_fd;
|
| 196 |
+
|
| 197 |
+
socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
| 198 |
+
if (socket_fd < 0) {
|
| 199 |
+
ARROW_LOG(ERROR) << "socket() failed for pathname " << pathname;
|
| 200 |
+
return -1;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
memset(&socket_address, 0, sizeof(socket_address));
|
| 204 |
+
socket_address.sun_family = AF_UNIX;
|
| 205 |
+
if (pathname.size() + 1 > sizeof(socket_address.sun_path)) {
|
| 206 |
+
ARROW_LOG(ERROR) << "Socket pathname is too long.";
|
| 207 |
+
close(socket_fd);
|
| 208 |
+
return -1;
|
| 209 |
+
}
|
| 210 |
+
strncpy(socket_address.sun_path, pathname.c_str(), pathname.size() + 1);
|
| 211 |
+
|
| 212 |
+
if (connect(socket_fd, reinterpret_cast<struct sockaddr*>(&socket_address),
|
| 213 |
+
sizeof(socket_address)) != 0) {
|
| 214 |
+
close(socket_fd);
|
| 215 |
+
return -1;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
return socket_fd;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
int AcceptClient(int socket_fd) {
|
| 222 |
+
int client_fd = accept(socket_fd, NULL, NULL);
|
| 223 |
+
if (client_fd < 0) {
|
| 224 |
+
ARROW_LOG(ERROR) << "Error reading from socket.";
|
| 225 |
+
return -1;
|
| 226 |
+
}
|
| 227 |
+
return client_fd;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
std::unique_ptr<uint8_t[]> ReadMessageAsync(int sock) {
|
| 231 |
+
int64_t size;
|
| 232 |
+
Status s = ReadBytes(sock, reinterpret_cast<uint8_t*>(&size), sizeof(int64_t));
|
| 233 |
+
if (!s.ok()) {
|
| 234 |
+
// The other side has closed the socket.
|
| 235 |
+
ARROW_LOG(DEBUG) << "Socket has been closed, or some other error has occurred.";
|
| 236 |
+
close(sock);
|
| 237 |
+
return NULL;
|
| 238 |
+
}
|
| 239 |
+
auto message = std::unique_ptr<uint8_t[]>(new uint8_t[size]);
|
| 240 |
+
s = ReadBytes(sock, message.get(), size);
|
| 241 |
+
if (!s.ok()) {
|
| 242 |
+
// The other side has closed the socket.
|
| 243 |
+
ARROW_LOG(DEBUG) << "Socket has been closed, or some other error has occurred.";
|
| 244 |
+
close(sock);
|
| 245 |
+
return NULL;
|
| 246 |
+
}
|
| 247 |
+
return message;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
} // namespace plasma
|
pool/shard011/C++/0118444_clara-sample.cpp
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Small example of how to use Clara
|
| 2 |
+
//
|
| 3 |
+
// Save this snippet as `clara-sample.cpp` together with the simgle-header
|
| 4 |
+
// verion of Clara and call `g++` as shown below.
|
| 5 |
+
//
|
| 6 |
+
// g++ -Wall -std=c++11 -o clara-sample clara-sample.cpp
|
| 7 |
+
|
| 8 |
+
#include <string>
|
| 9 |
+
#include <iostream>
|
| 10 |
+
#include "clara.hpp"
|
| 11 |
+
|
| 12 |
+
// dont show the help by default. Use `-h or `-?` to enable it.
|
| 13 |
+
//
|
| 14 |
+
bool showHelp = false;
|
| 15 |
+
|
| 16 |
+
// this block of variables are changed by Clara with the corresponding options passed
|
| 17 |
+
// to the program.
|
| 18 |
+
//
|
| 19 |
+
int width = 0;
|
| 20 |
+
std::string name;
|
| 21 |
+
bool doIt = false;
|
| 22 |
+
std::string command;
|
| 23 |
+
|
| 24 |
+
// This is a special value which is set indirectly by an lamba function!
|
| 25 |
+
//
|
| 26 |
+
int index = 0;
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
int main ( int argc, char** argv )
|
| 30 |
+
{
|
| 31 |
+
auto cli = clara::detail::Help(showHelp)
|
| 32 |
+
| clara::detail::Opt( width, "width" )["-w"]["--width"]("How wide should it be?")
|
| 33 |
+
| clara::detail::Opt( name, "name" )["-n"]["--name"]("By what name should I be known")
|
| 34 |
+
| clara::detail::Opt( doIt )["-d"]["--doit"]("Do the thing" )
|
| 35 |
+
| clara::detail::Opt( [&]( int i )
|
| 36 |
+
{
|
| 37 |
+
if (i < 0 || i > 10)
|
| 38 |
+
return clara::detail::ParserResult::runtimeError("index must be between 0 and 10");
|
| 39 |
+
else {
|
| 40 |
+
index = i;
|
| 41 |
+
return clara::detail::ParserResult::ok( clara::detail::ParseResultType::Matched );
|
| 42 |
+
}
|
| 43 |
+
}, "index" )
|
| 44 |
+
["-i"]( "An index, which is an integer between 0 and 10, inclusive" )
|
| 45 |
+
| clara::detail::Arg( command, "command" )("which command to run").required();
|
| 46 |
+
auto result = cli.parse( clara::detail::Args( argc, argv ) );
|
| 47 |
+
if( !result )
|
| 48 |
+
{
|
| 49 |
+
std::cerr << "Error in command line: " << result.errorMessage() << std::endl;
|
| 50 |
+
return 1;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
if ( showHelp )
|
| 54 |
+
{
|
| 55 |
+
std::cerr << cli << std::endl;
|
| 56 |
+
return 0;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
// show the results!
|
| 60 |
+
std::cerr << "Show Help:" << showHelp << std::endl;
|
| 61 |
+
std::cerr << "Index:" << index << std::endl;
|
| 62 |
+
std::cerr << "Width:" << width << std::endl;
|
| 63 |
+
std::cerr << "Name:" << name << std::endl;
|
| 64 |
+
std::cerr << "Doit:" << doIt << std::endl;
|
| 65 |
+
std::cerr << "Command:" << command << std::endl;
|
| 66 |
+
|
| 67 |
+
return 0;
|
| 68 |
+
}
|
pool/shard011/C++/0118445_ArticleStateUfo.cpp
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2010-2020 OpenXcom Developers.
|
| 3 |
+
*
|
| 4 |
+
* This file is part of OpenXcom.
|
| 5 |
+
*
|
| 6 |
+
* OpenXcom is free software: you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License as published by
|
| 8 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
* (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* OpenXcom is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "ArticleStateUfo.h"
|
| 21 |
+
|
| 22 |
+
//#include <sstream>
|
| 23 |
+
|
| 24 |
+
#include "../Engine/Game.h"
|
| 25 |
+
#include "../Engine/LocalizedText.h"
|
| 26 |
+
//#include "../Engine/Palette.h"
|
| 27 |
+
#include "../Engine/Surface.h"
|
| 28 |
+
|
| 29 |
+
#include "../Interface/Text.h"
|
| 30 |
+
#include "../Interface/TextButton.h"
|
| 31 |
+
#include "../Interface/TextList.h"
|
| 32 |
+
|
| 33 |
+
#include "../Resource/ResourcePack.h"
|
| 34 |
+
|
| 35 |
+
#include "../Ruleset/ArticleDefinition.h"
|
| 36 |
+
//#include "../Ruleset/RuleInterface.h"
|
| 37 |
+
#include "../Ruleset/Ruleset.h"
|
| 38 |
+
#include "../Ruleset/RuleUfo.h"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
namespace OpenXcom
|
| 42 |
+
{
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* cTor.
|
| 46 |
+
* @param defs - pointer to ArticleDefinitionUfo (ArticleDefinition.h)
|
| 47 |
+
*/
|
| 48 |
+
ArticleStateUfo::ArticleStateUfo(const ArticleDefinitionUfo* const defs)
|
| 49 |
+
:
|
| 50 |
+
ArticleState(defs->id)
|
| 51 |
+
{
|
| 52 |
+
_txtTitle = new Text(155, 32, 5, 24);
|
| 53 |
+
|
| 54 |
+
setPalette(PAL_GEOSCAPE);
|
| 55 |
+
|
| 56 |
+
ArticleState::initLayout(false);
|
| 57 |
+
|
| 58 |
+
add(_txtTitle);
|
| 59 |
+
|
| 60 |
+
_game->getResourcePack()->getSurface("BACK11.SCR")->blit(_bg);
|
| 61 |
+
|
| 62 |
+
_btnOk->setColor(GEOSCAPE_CYAN);
|
| 63 |
+
_btnPrev->setColor(GEOSCAPE_CYAN);
|
| 64 |
+
_btnNext->setColor(GEOSCAPE_CYAN);
|
| 65 |
+
|
| 66 |
+
_txtTitle->setText(tr(defs->title));
|
| 67 |
+
_txtTitle->setColor(GEOSCAPE_CYAN);
|
| 68 |
+
_txtTitle->setBig();
|
| 69 |
+
_txtTitle->setWordWrap();
|
| 70 |
+
|
| 71 |
+
_image = new Surface(160, 52, 160, 6);
|
| 72 |
+
add(_image);
|
| 73 |
+
|
| 74 |
+
/* Surface* graphic = _game->getResourcePack()->getSurface("INTERWIN.DAT");
|
| 75 |
+
graphic->setX(0);
|
| 76 |
+
graphic->setY(0);
|
| 77 |
+
graphic->getCrop()->x = 0;
|
| 78 |
+
graphic->getCrop()->y = 0;
|
| 79 |
+
graphic->getCrop()->w = 160;
|
| 80 |
+
graphic->getCrop()->h = 52;
|
| 81 |
+
_image->drawRect(graphic->getCrop(), 15); */
|
| 82 |
+
|
| 83 |
+
/*old
|
| 84 |
+
graphic->getCrop()->y = 96;
|
| 85 |
+
graphic->getCrop()->h = 15;
|
| 86 |
+
graphic->blit(_image);
|
| 87 |
+
graphic->setY(67);
|
| 88 |
+
graphic->getCrop()->y = 111;
|
| 89 |
+
graphic->getCrop()->h = 29;
|
| 90 |
+
graphic->blit(_image); */
|
| 91 |
+
|
| 92 |
+
/* if (ufo->getSpriteString().empty())
|
| 93 |
+
{
|
| 94 |
+
graphic->getCrop()->y = 140 + 52 * static_cast<Sint16>(ufo->getSprite());
|
| 95 |
+
graphic->getCrop()->h = 52;
|
| 96 |
+
}
|
| 97 |
+
else
|
| 98 |
+
{
|
| 99 |
+
graphic = _game->getResourcePack()->getSurface(ufo->getSpriteString());
|
| 100 |
+
graphic->setX(0);
|
| 101 |
+
graphic->setY(0);
|
| 102 |
+
}
|
| 103 |
+
graphic->blit(_image); */
|
| 104 |
+
|
| 105 |
+
const RuleUfo* const ufo (_game->getRuleset()->getUfo(defs->id));
|
| 106 |
+
const int sprite (ufo->getSprite());
|
| 107 |
+
std::ostringstream oststr;
|
| 108 |
+
oststr << "INTERWIN_" << sprite;
|
| 109 |
+
Surface* const srfPreview (_game->getResourcePack()->getSurface(oststr.str()));
|
| 110 |
+
if (srfPreview != nullptr)
|
| 111 |
+
srfPreview->blit(_image);
|
| 112 |
+
|
| 113 |
+
_txtInfo = new Text(300, 50, 10, 140);
|
| 114 |
+
add(_txtInfo);
|
| 115 |
+
_txtInfo->setText(tr(defs->text));
|
| 116 |
+
_txtInfo->setColor(GEOSCAPE_CYAN);
|
| 117 |
+
_txtInfo->setWordWrap();
|
| 118 |
+
|
| 119 |
+
_lstInfo = new TextList(300, 65,10,68);
|
| 120 |
+
add(_lstInfo);
|
| 121 |
+
|
| 122 |
+
centerSurfaces();
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
_lstInfo->setColor(GEOSCAPE_CYAN);
|
| 126 |
+
_lstInfo->setColumns(2, 200, 100);
|
| 127 |
+
_lstInfo->setBig();
|
| 128 |
+
_lstInfo->setDot();
|
| 129 |
+
|
| 130 |
+
_lstInfo->addRow(
|
| 131 |
+
2,
|
| 132 |
+
tr("STR_DAMAGE_CAPACITY").c_str(),
|
| 133 |
+
Text::intWide(ufo->getUfoHullCap()).c_str());
|
| 134 |
+
_lstInfo->addRow(
|
| 135 |
+
2,
|
| 136 |
+
tr("STR_WEAPON_POWER").c_str(),
|
| 137 |
+
Text::intWide(ufo->getWeaponPower()).c_str());
|
| 138 |
+
_lstInfo->addRow(
|
| 139 |
+
2,
|
| 140 |
+
tr("STR_WEAPON_RANGE").c_str(),
|
| 141 |
+
tr("STR_KILOMETERS").arg(ufo->getWeaponRange()).c_str());
|
| 142 |
+
_lstInfo->addRow(
|
| 143 |
+
2,
|
| 144 |
+
tr("STR_MAXIMUM_SPEED").c_str(),
|
| 145 |
+
tr("STR_KNOTS").arg(ufo->getTopSpeed()).c_str());
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* dTor.
|
| 150 |
+
*/
|
| 151 |
+
ArticleStateUfo::~ArticleStateUfo() // virtual.
|
| 152 |
+
{}
|
| 153 |
+
|
| 154 |
+
}
|
pool/shard011/C++/0118446_Boris_You_Are_Wrong_.cpp
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include<cstdio>
|
| 2 |
+
#include<cmath>
|
| 3 |
+
const double pi=acos(-1.0);
|
| 4 |
+
struct point
|
| 5 |
+
{
|
| 6 |
+
double x,y;
|
| 7 |
+
}A1,B1,C1,A2,B2,C2;
|
| 8 |
+
bool ans;
|
| 9 |
+
void print()
|
| 10 |
+
{
|
| 11 |
+
if (!ans)printf("YES\n");
|
| 12 |
+
else
|
| 13 |
+
{
|
| 14 |
+
printf("NO\n");
|
| 15 |
+
printf("%.10lf %.10lf\n",A2.x,A2.y);
|
| 16 |
+
printf("%.10lf %.10lf\n",B2.x,B2.y);
|
| 17 |
+
printf("%.10lf %.10lf\n",C2.x,C2.y);
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
inline double sqr(double X)
|
| 21 |
+
{
|
| 22 |
+
return X*X;
|
| 23 |
+
}
|
| 24 |
+
inline double dotdet(double X1,double Y1,double X2,double Y2)
|
| 25 |
+
{
|
| 26 |
+
return X1*X2+Y1*Y2;
|
| 27 |
+
}
|
| 28 |
+
inline double dis(double X1,double Y1,double X2,double Y2)
|
| 29 |
+
{
|
| 30 |
+
return sqrt(sqr(X1-X2)+sqr(Y1-Y2));
|
| 31 |
+
}
|
| 32 |
+
void solve()
|
| 33 |
+
{
|
| 34 |
+
ans=false;
|
| 35 |
+
double AB,BC,AC,cosalpha,sinalpha,delta,a,b,c,x1,x2,AC_,tmp;
|
| 36 |
+
AB=dis(A1.x,A1.y,B1.x,B1.y);
|
| 37 |
+
AC=dis(A1.x,A1.y,C1.x,C1.y);
|
| 38 |
+
BC=dis(B1.x,B1.y,C1.x,C1.y);
|
| 39 |
+
tmp=dotdet(B1.x-A1.x,B1.y-A1.y,C1.x-A1.x,C1.y-A1.y);
|
| 40 |
+
cosalpha=tmp;
|
| 41 |
+
cosalpha/=AB;
|
| 42 |
+
cosalpha/=AC;
|
| 43 |
+
sinalpha=sqrt(1-sqr(cosalpha));
|
| 44 |
+
|
| 45 |
+
b=-2*tmp/AC;
|
| 46 |
+
c=sqr(AB)-sqr(BC);
|
| 47 |
+
delta=sqr(b)-4*c;
|
| 48 |
+
if (delta>0)
|
| 49 |
+
{
|
| 50 |
+
x1=(-b+sqrt(delta))/2;
|
| 51 |
+
x2=(-b-sqrt(delta))/2;
|
| 52 |
+
if (x1>0&&x2>0)
|
| 53 |
+
{
|
| 54 |
+
if (fabs(x1-AC)<1e-6)AC_=x2;
|
| 55 |
+
else AC_=x1;
|
| 56 |
+
A2.x=0;A2.y=0;
|
| 57 |
+
B2.x=AB;B2.y=0;
|
| 58 |
+
C2.x=cosalpha*AC_;C2.y=sinalpha*AC_;
|
| 59 |
+
ans=true;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
void init()
|
| 64 |
+
{
|
| 65 |
+
scanf("%lf%lf%lf%lf%lf%lf",&A1.x,&A1.y,&B1.x,&B1.y,&C1.x,&C1.y);
|
| 66 |
+
}
|
| 67 |
+
int main()
|
| 68 |
+
{
|
| 69 |
+
init();
|
| 70 |
+
solve();
|
| 71 |
+
print();
|
| 72 |
+
return 0;
|
| 73 |
+
}
|
pool/shard011/C++/0118447_bracketmatcher.cpp
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Subs Scheme Interpreter
|
| 3 |
+
* Copyright (C) 2010, 2011 Andy Balaam
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with this program; if not, write to the Free Software
|
| 17 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 18 |
+
**/
|
| 19 |
+
|
| 20 |
+
#include <iostream>
|
| 21 |
+
|
| 22 |
+
#include "lib/bracketmatcher.h"
|
| 23 |
+
#include "lib/lexer.h"
|
| 24 |
+
#include "lib/tokenlist.h"
|
| 25 |
+
|
| 26 |
+
BracketMatcher::BracketMatcher( Lexer& lexer, std::ostream& out,
|
| 27 |
+
bool print_continuation )
|
| 28 |
+
: lexer_( lexer )
|
| 29 |
+
, newline_processor_( out )
|
| 30 |
+
, print_continuation_( print_continuation )
|
| 31 |
+
{
|
| 32 |
+
if( print_continuation )
|
| 33 |
+
{
|
| 34 |
+
lexer_.SetNewLineProcessor( &newline_processor_ );
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
BracketMatcher::~BracketMatcher()
|
| 39 |
+
{
|
| 40 |
+
lexer_.SetNewLineProcessor( NULL );
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
TokenList BracketMatcher::ReadCombination()
|
| 44 |
+
{
|
| 45 |
+
// TODO: split into smaller functions
|
| 46 |
+
|
| 47 |
+
enum EMode
|
| 48 |
+
{
|
| 49 |
+
eOther
|
| 50 |
+
, eOperator
|
| 51 |
+
, eFirstOperand
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
TokenList ret;
|
| 55 |
+
unsigned int bracket_level = 0;
|
| 56 |
+
EMode mode = eOther;
|
| 57 |
+
|
| 58 |
+
while( true )
|
| 59 |
+
{
|
| 60 |
+
Token token = lexer_.NextToken();
|
| 61 |
+
|
| 62 |
+
// If the stream ended before a combo was closed, return an empty
|
| 63 |
+
// list - the user pressed Ctrl-D and doesn't want any output.
|
| 64 |
+
if( token.IsEndOfStream() )
|
| 65 |
+
{
|
| 66 |
+
return TokenList();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
token.AddToColumn( newline_processor_.GetIndent() );
|
| 70 |
+
|
| 71 |
+
// If we have got to the first operand of a combination
|
| 72 |
+
// store the indent level so that we can indent correctly
|
| 73 |
+
// in the repl when the user presses return.
|
| 74 |
+
switch( mode )
|
| 75 |
+
{
|
| 76 |
+
case eOperator:
|
| 77 |
+
{
|
| 78 |
+
mode = eFirstOperand;
|
| 79 |
+
break;
|
| 80 |
+
}
|
| 81 |
+
case eFirstOperand:
|
| 82 |
+
{
|
| 83 |
+
newline_processor_.PushIndent( bracket_level, token.Column() );
|
| 84 |
+
mode = eOther;
|
| 85 |
+
break;
|
| 86 |
+
}
|
| 87 |
+
default:
|
| 88 |
+
{
|
| 89 |
+
break;
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
ret.AddToken( token );
|
| 94 |
+
|
| 95 |
+
// If we've finished this combination, return now
|
| 96 |
+
if( token.Name() == ")" && bracket_level == 1 )
|
| 97 |
+
{
|
| 98 |
+
break;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
// Otherwise, adjust our bracket level if there is a ( or )
|
| 102 |
+
if( token.Name() == "(" )
|
| 103 |
+
{
|
| 104 |
+
++bracket_level;
|
| 105 |
+
mode = eOperator; // The next token will be the operator
|
| 106 |
+
}
|
| 107 |
+
else if( token.Name() == ")" )
|
| 108 |
+
{
|
| 109 |
+
newline_processor_.PopIndent( bracket_level );
|
| 110 |
+
--bracket_level;
|
| 111 |
+
mode = eOther;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// If we got a bare symbol (no brackets) we exit here
|
| 115 |
+
// (except that we skip straight past quotes)
|
| 116 |
+
if( bracket_level == 0 && token.Name() != "'" )
|
| 117 |
+
{
|
| 118 |
+
break;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
// If the lexer's token ended with newline, it couldn't call
|
| 122 |
+
// newline (because we hadn't processed the token yet). We
|
| 123 |
+
// have now processed it, so we can call NewLine now.
|
| 124 |
+
if( print_continuation_ && lexer_.EndedWithNewLine() )
|
| 125 |
+
{
|
| 126 |
+
newline_processor_.NewLine();
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
// When the combination (or bare symbol) is finished, we don't
|
| 131 |
+
// need to track indentation any more, so reset the newline processor,
|
| 132 |
+
// and we don't care about any newlines before the next token, so
|
| 133 |
+
// we skip whitespace in the lexer.
|
| 134 |
+
newline_processor_.Reset();
|
| 135 |
+
|
| 136 |
+
return ret;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
bool BracketMatcher::eof() const
|
| 140 |
+
{
|
| 141 |
+
return lexer_.eof();
|
| 142 |
+
}
|
pool/shard011/C++/0118448_main.cpp
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <QCoreApplication>
|
| 2 |
+
#include "core.h"
|
| 3 |
+
|
| 4 |
+
int main(int argc, char *argv[])
|
| 5 |
+
{
|
| 6 |
+
QCoreApplication application(argc, argv);
|
| 7 |
+
QCoreApplication::setApplicationName("bluetoothLeScanner");
|
| 8 |
+
QCoreApplication::setApplicationVersion("0.0.1");
|
| 9 |
+
|
| 10 |
+
QCommandLineParser *parser = new QCommandLineParser();
|
| 11 |
+
parser->setApplicationDescription("Tool to inspect a bluetooth low energy device.");
|
| 12 |
+
parser->addHelpOption();
|
| 13 |
+
parser->addVersionOption();
|
| 14 |
+
|
| 15 |
+
QCommandLineOption hostDeviceOption(QStringList() << "host", "The name of the Bluetooth host device to use. By default it will use the first host device found.", "hostname");
|
| 16 |
+
parser->addOption(hostDeviceOption);
|
| 17 |
+
|
| 18 |
+
QCommandLineOption discoverDevicesOption(QStringList() << "d" << "discover", "Search bluetooth devices.");
|
| 19 |
+
parser->addOption(discoverDevicesOption);
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
parser->process(application);
|
| 24 |
+
|
| 25 |
+
Core core(parser);
|
| 26 |
+
|
| 27 |
+
return application.exec();
|
| 28 |
+
}
|
pool/shard011/C++/0118449_main.cpp
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* This program is free software; you can redistribute it and/or modify
|
| 3 |
+
* it under the terms of the GNU General Public License as published by
|
| 4 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 5 |
+
* (at your option) any later version.
|
| 6 |
+
*
|
| 7 |
+
* This program is distributed in the hope that it will be useful,
|
| 8 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 10 |
+
* GNU General Public License for more details.
|
| 11 |
+
*
|
| 12 |
+
* You should have received a copy of the GNU General Public License
|
| 13 |
+
* along with this program; if not, write to the Free Software
|
| 14 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 15 |
+
*
|
| 16 |
+
*
|
| 17 |
+
* Author: Sapronov Alexander/WarmongeR
|
| 18 |
+
* E-Mail: sapronov.alexander92@.gmail.com
|
| 19 |
+
* Years: 2011, 2012
|
| 20 |
+
* WebSite: https://github.com/WarmongeR1/bQella
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
#include "mainwindow.h"
|
| 25 |
+
#include "config.h"
|
| 26 |
+
#include "pcommon.h"
|
| 27 |
+
#include "filecommon.h"
|
| 28 |
+
|
| 29 |
+
#include <QApplication>
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
int main( int argc, char ** argv )
|
| 33 |
+
{
|
| 34 |
+
// Q_INIT_RESOURCE(ra); //Initialize the resources specified by the .qrc file
|
| 35 |
+
|
| 36 |
+
// QString aDocPath;
|
| 37 |
+
bool hideSidebar = false;
|
| 38 |
+
bool withGUI = true;
|
| 39 |
+
QApplication a(argc, argv, withGUI);
|
| 40 |
+
a.setOrganizationName(GL_PROG_AUTHOR);
|
| 41 |
+
a.setApplicationName(GL_PROG_NAME);
|
| 42 |
+
|
| 43 |
+
Config *conf = new Config();
|
| 44 |
+
conf -> setAppDir(QDir::currentPath() + "/");
|
| 45 |
+
conf -> setCacheDir(conf -> AppDir() + "cache/");
|
| 46 |
+
conf -> setImgDir(conf -> AppDir() + "images/");
|
| 47 |
+
conf -> setPrjDir(conf -> AppDir() + "projects/");
|
| 48 |
+
conf -> setIniFile(conf -> AppDir() + "project.ini");
|
| 49 |
+
conf -> setErrPage(conf -> AppDir() + "last-error.html");
|
| 50 |
+
conf -> setAppLogFN(conf -> AppDir() + "log/project.log");
|
| 51 |
+
toLog(conf -> AppLogFN(), "-------");
|
| 52 |
+
toLog(conf -> AppLogFN(), "Project bQella started.");
|
| 53 |
+
conf -> loadSettings();
|
| 54 |
+
conf -> loadProject(conf -> CurProject());
|
| 55 |
+
|
| 56 |
+
if (!conf)
|
| 57 |
+
{
|
| 58 |
+
fprintf( stderr, "Profile '%s' does not exist!\n", conf -> CurProject().toUtf8().constData() );
|
| 59 |
+
fflush( stderr );
|
| 60 |
+
return -1;
|
| 61 |
+
}
|
| 62 |
+
//!+! load language based on locale on first startup or if it was not set directly
|
| 63 |
+
|
| 64 |
+
toLog(conf -> AppLogFN(), "Load: Language");
|
| 65 |
+
QTranslator translator;
|
| 66 |
+
if (conf -> Lang() == "Russian" or conf->Lang().isEmpty()) translator.load("bqella_ru",":lang/lang");
|
| 67 |
+
if (conf -> Lang() == "Deutch") translator.load("bqella_de",":lang/lang");
|
| 68 |
+
if (conf -> Lang() == "France") translator.load("bqella_fr",":lang/lang");
|
| 69 |
+
a.installTranslator(&translator);
|
| 70 |
+
toLog(conf -> AppLogFN(), "Load: Language - done");
|
| 71 |
+
conf -> hideSideBar( hideSidebar );
|
| 72 |
+
//qDebug() << "[10]";
|
| 73 |
+
QPointer<MainWindow> mw = new MainWindow();
|
| 74 |
+
|
| 75 |
+
//qDebug() << "[11]";
|
| 76 |
+
FontSettings settings = conf -> fontSettings();
|
| 77 |
+
if (mw -> font() != settings.windowFont)
|
| 78 |
+
a.setFont(settings.windowFont, "QWidget");
|
| 79 |
+
toLog(conf -> AppLogFN(), "Done with setup. Show main window.");
|
| 80 |
+
mw -> show();
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
//qDebug() << "[12]";
|
| 84 |
+
QStringList links = conf -> source();
|
| 85 |
+
|
| 86 |
+
toLog(conf -> AppLogFN(), "Load: Files");
|
| 87 |
+
if (links.isEmpty())
|
| 88 |
+
{
|
| 89 |
+
//!+! or option "Remember opened files" is not set
|
| 90 |
+
mw -> showLink( urlifyFileName(conf -> CurFile()) );
|
| 91 |
+
}
|
| 92 |
+
else
|
| 93 |
+
{
|
| 94 |
+
// qDebug() << "[13]";
|
| 95 |
+
mw -> showLinks( links );
|
| 96 |
+
}
|
| 97 |
+
a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
|
| 98 |
+
|
| 99 |
+
int appExec = a.exec();
|
| 100 |
+
delete (MainWindow*)mw;
|
| 101 |
+
toLog(conf -> AppLogFN(),QString("%1 shuts down normally.").arg(GL_PROG_NAME));
|
| 102 |
+
return appExec;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/********************* Comments to project *********************
|
| 106 |
+
|
| 107 |
+
--------------------- Files description ---------------------
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* @file
|
| 111 |
+
*
|
| 112 |
+
*
|
| 113 |
+
* config - configuration of the application, global functions and variables
|
| 114 |
+
* docuparser - parse profile file
|
| 115 |
+
* helpdialog - slidebar functions: content, index, bookmarks, search
|
| 116 |
+
* helpwindow - working area functions: text edit, font, file
|
| 117 |
+
* index - procedures to build up index in index tab on helpdialog slidebar
|
| 118 |
+
* mainwindow - main menu functions
|
| 119 |
+
* profile - configuration of a project
|
| 120 |
+
* msc - general purpose procedures with no class relations
|
| 121 |
+
*
|
| 122 |
+
*
|
| 123 |
+
* ------- Forms aviable from (classes interaction) -------
|
| 124 |
+
*
|
| 125 |
+
* HelpDialog Ui::HelpDialog ui; MainWindow *mw;
|
| 126 |
+
* HelpWindow MainWindow *mw; ItemProperties *itemprop;
|
| 127 |
+
* MainWindow Ui::MainWindow ui; TabbedBrowser *tabs;[private] HelpDialog *helpDock;[private]
|
| 128 |
+
* TabbedBrowser *browsers(); HelpDialog *helpDialog();
|
| 129 |
+
* TabbedBrowser Ui::TabbedBrowser ui; MainWindow *mainWindow(); HelpWindow *currentBrowser();
|
| 130 |
+
*
|
| 131 |
+
* To access from HelpDialog to HelpWindow functions use:
|
| 132 |
+
* mw -> browsers() -> currentBrowser() -> ...
|
| 133 |
+
*
|
| 134 |
+
*/
|
| 135 |
+
|
pool/shard011/C++/0118450_main.cpp
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
#include "ini_parser.hpp"
|
| 5 |
+
|
| 6 |
+
#include <string>
|
| 7 |
+
#include <iostream>
|
| 8 |
+
#include <fstream>
|
| 9 |
+
#include <stdexcept>
|
| 10 |
+
|
| 11 |
+
#include <boost/config.hpp>
|
| 12 |
+
#include <boost/range.hpp>
|
| 13 |
+
#include <boost/locale.hpp>
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
bool test_ini(int id, const std::string& locale, const std::wstring& multibyte_example, bool linux_like_line_ending, bool error1, bool error2, bool error3, bool error4)
|
| 19 |
+
{
|
| 20 |
+
|
| 21 |
+
std::wstring cendl = linux_like_line_ending ? L"\n" : L"\r\n";
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
/*
|
| 26 |
+
|
| 27 |
+
;comment
|
| 28 |
+
[section1]
|
| 29 |
+
;comment
|
| 30 |
+
|
| 31 |
+
key1=value1
|
| 32 |
+
key2=multibyte_example
|
| 33 |
+
;comment
|
| 34 |
+
|
| 35 |
+
[section2]
|
| 36 |
+
key1=value3
|
| 37 |
+
key2=key2+multibyte_example
|
| 38 |
+
;comment+multibyte_example
|
| 39 |
+
|
| 40 |
+
*/
|
| 41 |
+
|
| 42 |
+
std::wstring file_name = std::wstring(L"ini_test") + std::to_wstring(id) + std::wstring(L".ini");
|
| 43 |
+
{
|
| 44 |
+
std::wstringstream out;
|
| 45 |
+
|
| 46 |
+
out << cendl;
|
| 47 |
+
out << L";comment1" << cendl;
|
| 48 |
+
if(error1)
|
| 49 |
+
out << L"key1=" << multibyte_example << cendl;
|
| 50 |
+
out << L"[section1" << (error2 ? L"" : L"]") << cendl;
|
| 51 |
+
out << L";comment2" << cendl;
|
| 52 |
+
out << cendl;
|
| 53 |
+
out << L"key1=value1" << cendl;
|
| 54 |
+
out << L"key2 " << (error4 ? L"" : L"=") << multibyte_example << cendl;
|
| 55 |
+
out << cendl;
|
| 56 |
+
out << L";comment3" << cendl;
|
| 57 |
+
out << L"[section2]" << (error3 ? L"w" : L"") << cendl;
|
| 58 |
+
out << L"key1=value3" << cendl;
|
| 59 |
+
out << L"key2=key2" << multibyte_example << cendl;
|
| 60 |
+
out << L";comment4" << multibyte_example << cendl;
|
| 61 |
+
out << cendl;
|
| 62 |
+
|
| 63 |
+
std::string str;
|
| 64 |
+
if (locale == "UTF-16")
|
| 65 |
+
{
|
| 66 |
+
std::fstream file(file_name, std::fstream::out | std::fstream::trunc | std::fstream::binary);
|
| 67 |
+
file.write((char*)out.str().c_str(), out.str().length()*sizeof(out.str()[0]));
|
| 68 |
+
}
|
| 69 |
+
else
|
| 70 |
+
{
|
| 71 |
+
str = boost::locale::conv::from_utf(out.str(), locale);
|
| 72 |
+
if (locale == "UTF-8")
|
| 73 |
+
{
|
| 74 |
+
char bom[] = { (char)0xEF, (char)0xBB, (char)0xBF, 0 };
|
| 75 |
+
str = std::string(bom) + str;
|
| 76 |
+
}
|
| 77 |
+
std::fstream file(file_name, std::wfstream::out | std::wfstream::trunc);
|
| 78 |
+
file << str;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
bool is_parse_expection=false;
|
| 84 |
+
bool is_parse_correct=true;
|
| 85 |
+
|
| 86 |
+
try
|
| 87 |
+
{
|
| 88 |
+
ema::config::IniParser parser(file_name);
|
| 89 |
+
|
| 90 |
+
is_parse_correct&=parser.getString(L"section1", L"key1")==L"value1";
|
| 91 |
+
is_parse_correct&=parser.getString(L"section1", L"key2")==multibyte_example;
|
| 92 |
+
is_parse_correct&=parser.getString(L"section2", L"key1")==L"value3";
|
| 93 |
+
is_parse_correct&=parser.getString(L"section2", L"key2")==std::wstring(L"key2")+multibyte_example;
|
| 94 |
+
is_parse_correct&=parser.getString(L"section2", L"key3", L"value5")==L"value5";
|
| 95 |
+
}
|
| 96 |
+
catch (const std::exception&)
|
| 97 |
+
{
|
| 98 |
+
is_parse_expection=true;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
bool result=false;
|
| 102 |
+
if(is_parse_expection)
|
| 103 |
+
{
|
| 104 |
+
result = error1 || error2 || error3 || error4;
|
| 105 |
+
}else
|
| 106 |
+
{
|
| 107 |
+
result = !(error1 || error2 || error3 || error4) && is_parse_correct;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
return result;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
struct TestConfig
|
| 117 |
+
{
|
| 118 |
+
std::string locale;
|
| 119 |
+
std::wstring multibyte_example;
|
| 120 |
+
bool linux_like_line_ending;
|
| 121 |
+
bool key_without_section;
|
| 122 |
+
bool section_name_incorrect;
|
| 123 |
+
bool text_in_section_line;
|
| 124 |
+
bool key_format_invalid;
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
int run_test(int id, const TestConfig& config)
|
| 128 |
+
{
|
| 129 |
+
if (test_ini(id, config.locale, config.multibyte_example, config.linux_like_line_ending, config.key_without_section, config.section_name_incorrect, config.text_in_section_line, config.key_format_invalid))
|
| 130 |
+
{
|
| 131 |
+
std::cout << "test " << id << " passed" << std::endl;
|
| 132 |
+
return 0;
|
| 133 |
+
}
|
| 134 |
+
else
|
| 135 |
+
{
|
| 136 |
+
std::cout << "test " << id << " failed" << std::endl;
|
| 137 |
+
return -id;
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
#include <windows.h>
|
| 143 |
+
|
| 144 |
+
int main(int, char**)
|
| 145 |
+
{
|
| 146 |
+
int result = 0;
|
| 147 |
+
/*
|
| 148 |
+
english
|
| 149 |
+
english unicode
|
| 150 |
+
|
| 151 |
+
russian(current system locale)
|
| 152 |
+
russian utf-8
|
| 153 |
+
russian utf-16
|
| 154 |
+
japan utf-8
|
| 155 |
+
japan utf-16
|
| 156 |
+
|
| 157 |
+
bool linux like line ending
|
| 158 |
+
|
| 159 |
+
error1 - key bofore section
|
| 160 |
+
error2 - wrong section name(without close bracket)
|
| 161 |
+
error3 - wrong section name(other text in section line)
|
| 162 |
+
error4 - wrong key(without =)
|
| 163 |
+
*/
|
| 164 |
+
|
| 165 |
+
UINT langid = GetACP();
|
| 166 |
+
CPINFOEX info;
|
| 167 |
+
//GetCPInfo(langid, &info);
|
| 168 |
+
|
| 169 |
+
GetCPInfoEx(CP_ACP, 0, &info);
|
| 170 |
+
|
| 171 |
+
std::string current("cp1251");
|
| 172 |
+
std::string current_utf8("UTF-8");
|
| 173 |
+
std::string current_utf16("UTF-16");
|
| 174 |
+
std::string jap_utf8("UTF-8");
|
| 175 |
+
std::string jap_utf16("UTF-16");
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
/*
|
| 180 |
+
|
| 181 |
+
std::locale current(gen(""));
|
| 182 |
+
std::locale current_utf8(gen("rus_RUS.utf-8"));
|
| 183 |
+
std::locale current_utf16(gen("ru_RU.UTF16"));
|
| 184 |
+
std::locale jap_utf8(gen("ja_JP.UTF8"));
|
| 185 |
+
std::locale jap_utf16(gen("ja_JP.UTF16"));
|
| 186 |
+
|
| 187 |
+
std::cout << "current" << current.c_str() << std::endl;
|
| 188 |
+
std::cout << "current_utf8" << current_utf8.c_str() << std::endl;
|
| 189 |
+
std::cout << "current_utf16" << current_utf16.c_str() << std::endl;
|
| 190 |
+
std::cout << "jap_utf8" << jap_utf8.c_str() << std::endl;
|
| 191 |
+
std::cout << "jap_utf16" << jap_utf16.c_str() << std::endl;
|
| 192 |
+
*/
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
TestConfig testConfigs[]={
|
| 196 |
+
{current, L"test1", false, false, false, false, false},
|
| 197 |
+
{current_utf8, L"test2", false, false, false, false, false},
|
| 198 |
+
{current_utf16, L"test3", false, false, false, false, false},
|
| 199 |
+
{current, L"тест4", false, false, false, false, false},
|
| 200 |
+
{current_utf8, L"тест5", false, false, false, false, false},
|
| 201 |
+
{current_utf16, L"тест6", false, false, false, false, false},
|
| 202 |
+
{jap_utf8, L"試験7", false, false, false, false, false},
|
| 203 |
+
{jap_utf16, L"試験8", false, false, false, false, false},
|
| 204 |
+
{current_utf8, L"тест9", true, false, false, false, false},
|
| 205 |
+
{current_utf8, L"тест10", false, true, false, false, false},
|
| 206 |
+
{current_utf8, L"тест11", false, false, true, false, false},
|
| 207 |
+
{current_utf8, L"тест12", false, false, false, true, false},
|
| 208 |
+
{current_utf8, L"тест13", false, false, false, false, true},
|
| 209 |
+
{current_utf16, L"тест14", true, false, false, false, false},
|
| 210 |
+
{current_utf16, L"тест15", false, true, false, false, false},
|
| 211 |
+
{current_utf16, L"тест16", false, false, true, false, false},
|
| 212 |
+
{current_utf16, L"тест17", false, false, false, true, false},
|
| 213 |
+
{current_utf16, L"тест18", false, false, false, false, true}
|
| 214 |
+
};
|
| 215 |
+
|
| 216 |
+
for(size_t i=0; i < boost::size(testConfigs); ++i)
|
| 217 |
+
result|=run_test((int)i, testConfigs[i]);
|
| 218 |
+
|
| 219 |
+
return result;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
|
pool/shard011/C++/0118451_mount_node_dir.cc
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "nacl_io/mount_node_dir.h"
|
| 6 |
+
|
| 7 |
+
#include <errno.h>
|
| 8 |
+
#include <string.h>
|
| 9 |
+
|
| 10 |
+
#include "nacl_io/osdirent.h"
|
| 11 |
+
#include "nacl_io/osstat.h"
|
| 12 |
+
#include "sdk_util/auto_lock.h"
|
| 13 |
+
#include "sdk_util/macros.h"
|
| 14 |
+
|
| 15 |
+
namespace nacl_io {
|
| 16 |
+
|
| 17 |
+
MountNodeDir::MountNodeDir(Mount* mount) : MountNode(mount), cache_(NULL) {
|
| 18 |
+
stat_.st_mode |= S_IFDIR;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
MountNodeDir::~MountNodeDir() {
|
| 22 |
+
for (MountNodeMap_t::iterator it = map_.begin(); it != map_.end(); ++it) {
|
| 23 |
+
it->second->Unlink();
|
| 24 |
+
}
|
| 25 |
+
free(cache_);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
Error MountNodeDir::Read(size_t offs, void* buf, size_t count, int* out_bytes) {
|
| 29 |
+
*out_bytes = 0;
|
| 30 |
+
return EISDIR;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
Error MountNodeDir::FTruncate(off_t size) { return EISDIR; }
|
| 34 |
+
|
| 35 |
+
Error MountNodeDir::Write(size_t offs,
|
| 36 |
+
const void* buf,
|
| 37 |
+
size_t count,
|
| 38 |
+
int* out_bytes) {
|
| 39 |
+
*out_bytes = 0;
|
| 40 |
+
return EISDIR;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
Error MountNodeDir::GetDents(size_t offs,
|
| 44 |
+
struct dirent* pdir,
|
| 45 |
+
size_t size,
|
| 46 |
+
int* out_bytes) {
|
| 47 |
+
*out_bytes = 0;
|
| 48 |
+
|
| 49 |
+
AUTO_LOCK(node_lock_);
|
| 50 |
+
|
| 51 |
+
// If the buffer pointer is invalid, fail
|
| 52 |
+
if (NULL == pdir)
|
| 53 |
+
return EINVAL;
|
| 54 |
+
|
| 55 |
+
// If the buffer is too small, fail
|
| 56 |
+
if (size < sizeof(struct dirent))
|
| 57 |
+
return EINVAL;
|
| 58 |
+
|
| 59 |
+
// Force size to a multiple of dirent
|
| 60 |
+
size -= size % sizeof(struct dirent);
|
| 61 |
+
size_t max = map_.size() * sizeof(struct dirent);
|
| 62 |
+
if (cache_ == NULL)
|
| 63 |
+
BuildCache();
|
| 64 |
+
|
| 65 |
+
if (offs >= max) {
|
| 66 |
+
// OK, trying to read past the end.
|
| 67 |
+
return 0;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if (offs + size >= max)
|
| 71 |
+
size = max - offs;
|
| 72 |
+
|
| 73 |
+
memcpy(pdir, ((char*)cache_) + offs, size);
|
| 74 |
+
*out_bytes = size;
|
| 75 |
+
return 0;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
Error MountNodeDir::AddChild(const std::string& name,
|
| 79 |
+
const ScopedMountNode& node) {
|
| 80 |
+
AUTO_LOCK(node_lock_);
|
| 81 |
+
|
| 82 |
+
if (name.empty())
|
| 83 |
+
return ENOENT;
|
| 84 |
+
|
| 85 |
+
if (name.length() >= MEMBER_SIZE(struct dirent, d_name))
|
| 86 |
+
return ENAMETOOLONG;
|
| 87 |
+
|
| 88 |
+
MountNodeMap_t::iterator it = map_.find(name);
|
| 89 |
+
if (it != map_.end())
|
| 90 |
+
return EEXIST;
|
| 91 |
+
|
| 92 |
+
node->Link();
|
| 93 |
+
map_[name] = node;
|
| 94 |
+
ClearCache();
|
| 95 |
+
return 0;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
Error MountNodeDir::RemoveChild(const std::string& name) {
|
| 99 |
+
AUTO_LOCK(node_lock_);
|
| 100 |
+
MountNodeMap_t::iterator it = map_.find(name);
|
| 101 |
+
if (it != map_.end()) {
|
| 102 |
+
it->second->Unlink();
|
| 103 |
+
map_.erase(it);
|
| 104 |
+
ClearCache();
|
| 105 |
+
return 0;
|
| 106 |
+
}
|
| 107 |
+
return ENOENT;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
Error MountNodeDir::FindChild(const std::string& name,
|
| 111 |
+
ScopedMountNode* out_node) {
|
| 112 |
+
out_node->reset(NULL);
|
| 113 |
+
|
| 114 |
+
AUTO_LOCK(node_lock_);
|
| 115 |
+
MountNodeMap_t::iterator it = map_.find(name);
|
| 116 |
+
if (it == map_.end())
|
| 117 |
+
return ENOENT;
|
| 118 |
+
|
| 119 |
+
*out_node = it->second;
|
| 120 |
+
return 0;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
int MountNodeDir::ChildCount() {
|
| 124 |
+
AUTO_LOCK(node_lock_);
|
| 125 |
+
return map_.size();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
void MountNodeDir::ClearCache() {
|
| 129 |
+
free(cache_);
|
| 130 |
+
cache_ = NULL;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
void MountNodeDir::BuildCache() {
|
| 134 |
+
if (map_.size()) {
|
| 135 |
+
cache_ = (struct dirent*)malloc(sizeof(struct dirent) * map_.size());
|
| 136 |
+
MountNodeMap_t::iterator it = map_.begin();
|
| 137 |
+
for (size_t index = 0; it != map_.end(); it++, index++) {
|
| 138 |
+
size_t len = it->first.length();
|
| 139 |
+
cache_[index].d_ino = it->second->stat_.st_ino;
|
| 140 |
+
cache_[index].d_off = sizeof(struct dirent);
|
| 141 |
+
cache_[index].d_reclen = sizeof(struct dirent);
|
| 142 |
+
cache_[index].d_name[len] = 0;
|
| 143 |
+
strncpy(cache_[index].d_name, &it->first[0], len);
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
} // namespace nacl_io
|
| 149 |
+
|
pool/shard011/C++/0118453_server_options.cpp
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/// @author Alexander Rykovanov 2013
|
| 2 |
+
/// @email rykovanov.as@gmail.com
|
| 3 |
+
/// @brief OpcUa client command line options parser.
|
| 4 |
+
/// @license GNU LGPL
|
| 5 |
+
///
|
| 6 |
+
/// Distributed under the GNU LGPL License
|
| 7 |
+
/// (See accompanying file LICENSE or copy at
|
| 8 |
+
/// http://www.gnu.org/licenses/lgpl.html)
|
| 9 |
+
///
|
| 10 |
+
|
| 11 |
+
#include "server_options.h"
|
| 12 |
+
|
| 13 |
+
#include <algorithm>
|
| 14 |
+
#include <boost/program_options/options_description.hpp>
|
| 15 |
+
#include <boost/program_options/parsers.hpp>
|
| 16 |
+
#include <boost/program_options/variables_map.hpp>
|
| 17 |
+
#include <functional>
|
| 18 |
+
#include <iostream>
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
#ifndef CONFIG_PATH
|
| 22 |
+
#define CONFIG_PATH "/etc/opcua/server"
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
namespace
|
| 26 |
+
{
|
| 27 |
+
namespace po = boost::program_options;
|
| 28 |
+
using namespace OpcUa;
|
| 29 |
+
|
| 30 |
+
const char * DefaultLogFilePath = "/var/log/opcua/server.log";
|
| 31 |
+
|
| 32 |
+
const char * OPTION_HELP = "help";
|
| 33 |
+
const char * OPTION_CONFIG = "config-dir";
|
| 34 |
+
const char * OPTION_DAEMON = "daemon";
|
| 35 |
+
const char * OPTION_LOGFILE = "log-file";
|
| 36 |
+
|
| 37 |
+
std::string GetConfigOptionValue(const po::variables_map & vm)
|
| 38 |
+
{
|
| 39 |
+
if (vm.count(OPTION_CONFIG))
|
| 40 |
+
{
|
| 41 |
+
return vm[OPTION_CONFIG].as<std::string>();
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
return CONFIG_PATH;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
bool GetDaemonMode(const po::variables_map & vm)
|
| 49 |
+
{
|
| 50 |
+
return vm.count(OPTION_DAEMON) != 0;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
std::string GetLogFile(const po::variables_map & vm)
|
| 54 |
+
{
|
| 55 |
+
if (vm.count(OPTION_LOGFILE))
|
| 56 |
+
{
|
| 57 |
+
return vm[OPTION_LOGFILE].as<std::string>();
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
return DefaultLogFilePath;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
namespace OpcUa
|
| 67 |
+
{
|
| 68 |
+
namespace Server
|
| 69 |
+
{
|
| 70 |
+
|
| 71 |
+
CommandLine::CommandLine(int argc, const char ** argv)
|
| 72 |
+
: StartPossible(true)
|
| 73 |
+
, IsDaemon(false)
|
| 74 |
+
{
|
| 75 |
+
// Declare the supported options.
|
| 76 |
+
po::options_description desc("Parameters");
|
| 77 |
+
desc.add_options()
|
| 78 |
+
(OPTION_HELP, "Print help message and exit.")
|
| 79 |
+
(OPTION_CONFIG, po::value<std::string>(), (std::string("Path to directory with configuration files. Default: ") + CONFIG_PATH).c_str())
|
| 80 |
+
(OPTION_LOGFILE, po::value<std::string>(), "Set path to the log file. Default 'var/log/opcua/server.log")
|
| 81 |
+
(OPTION_DAEMON, "Start in daemon mode.")
|
| 82 |
+
;
|
| 83 |
+
|
| 84 |
+
po::variables_map vm;
|
| 85 |
+
po::store(po::parse_command_line(argc, argv, desc), vm);
|
| 86 |
+
po::notify(vm);
|
| 87 |
+
|
| 88 |
+
if (vm.count(OPTION_HELP))
|
| 89 |
+
{
|
| 90 |
+
desc.print(std::cout);
|
| 91 |
+
StartPossible = false;
|
| 92 |
+
return;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
IsDaemon = GetDaemonMode(vm);
|
| 96 |
+
ConfigDir = GetConfigOptionValue(vm);
|
| 97 |
+
LogFile = ::GetLogFile(vm);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
} // namespace UaServer
|
| 101 |
+
} // namespace OpcUa
|
| 102 |
+
|
pool/shard011/C++/0118454_Table.cpp
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#include "TestUtil.hpp"
|
| 3 |
+
|
| 4 |
+
#include "LuaCpp/LuaTable.hpp"
|
| 5 |
+
|
| 6 |
+
using namespace luacpp;
|
| 7 |
+
|
| 8 |
+
class LuaTableTest : public LuaStateTest
|
| 9 |
+
{
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
TEST_F(LuaTableTest, AddValue)
|
| 14 |
+
{
|
| 15 |
+
ScopedLuaStackTest stackTest(L);
|
| 16 |
+
|
| 17 |
+
auto top = lua_gettop(L);
|
| 18 |
+
LuaTable table = LuaTable::create(L);
|
| 19 |
+
table.addValue("key", "value");
|
| 20 |
+
|
| 21 |
+
ASSERT_TRUE(table.pushValue());
|
| 22 |
+
|
| 23 |
+
lua_getfield(L, -1, "key");
|
| 24 |
+
|
| 25 |
+
ASSERT_TRUE(lua_isstring(L, -1) == 1);
|
| 26 |
+
ASSERT_STREQ("value", lua_tostring(L, -1));
|
| 27 |
+
|
| 28 |
+
lua_pop(L, 2); // Pop value and table
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
TEST_F(LuaTableTest, SetReference)
|
| 32 |
+
{
|
| 33 |
+
ScopedLuaStackTest stackTest(L);
|
| 34 |
+
|
| 35 |
+
LuaTable table = LuaTable::create(L);
|
| 36 |
+
|
| 37 |
+
lua_pushliteral(L, "abc");
|
| 38 |
+
ASSERT_THROW(table.setReference(LuaReference::create(L)), LuaException);
|
| 39 |
+
|
| 40 |
+
lua_pop(L, 1);
|
| 41 |
+
|
| 42 |
+
lua_newtable(L);
|
| 43 |
+
ASSERT_NO_THROW(table.setReference(LuaReference::create(L)));
|
| 44 |
+
|
| 45 |
+
lua_pop(L, 1);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
TEST_F(LuaTableTest, GetValue)
|
| 49 |
+
{
|
| 50 |
+
ScopedLuaStackTest stackTest(L);
|
| 51 |
+
|
| 52 |
+
lua_newtable(L);
|
| 53 |
+
lua_pushstring(L, "value");
|
| 54 |
+
lua_setfield(L, -2, "key");
|
| 55 |
+
|
| 56 |
+
LuaTable table;
|
| 57 |
+
|
| 58 |
+
EXPECT_TRUE(convert::popValue(L, table));
|
| 59 |
+
|
| 60 |
+
std::string val;
|
| 61 |
+
ASSERT_TRUE(table.getValue("key", val));
|
| 62 |
+
ASSERT_STREQ("value", val.c_str());
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
TEST_F(LuaTableTest, GetLength)
|
| 66 |
+
{
|
| 67 |
+
ScopedLuaStackTest stackTest(L);
|
| 68 |
+
|
| 69 |
+
lua_newtable(L);
|
| 70 |
+
|
| 71 |
+
lua_pushnumber(L, 1);
|
| 72 |
+
lua_pushstring(L, "value1");
|
| 73 |
+
lua_settable(L, -3);
|
| 74 |
+
|
| 75 |
+
lua_pushnumber(L, 2);
|
| 76 |
+
lua_pushstring(L, "value2");
|
| 77 |
+
lua_settable(L, -3);
|
| 78 |
+
|
| 79 |
+
lua_pushnumber(L, 3);
|
| 80 |
+
lua_pushstring(L, "value3");
|
| 81 |
+
lua_settable(L, -3);
|
| 82 |
+
|
| 83 |
+
LuaTable table;
|
| 84 |
+
|
| 85 |
+
EXPECT_TRUE(convert::popValue(L, table));
|
| 86 |
+
|
| 87 |
+
ASSERT_EQ(3, table.getLength());
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
TEST_F(LuaTableTest, Iterator)
|
| 91 |
+
{
|
| 92 |
+
ScopedLuaStackTest stackTest(L);
|
| 93 |
+
|
| 94 |
+
lua_newtable(L);
|
| 95 |
+
|
| 96 |
+
lua_pushnumber(L, 1);
|
| 97 |
+
lua_pushstring(L, "value1");
|
| 98 |
+
lua_settable(L, -3);
|
| 99 |
+
|
| 100 |
+
lua_pushnumber(L, 2);
|
| 101 |
+
lua_pushstring(L, "value2");
|
| 102 |
+
lua_settable(L, -3);
|
| 103 |
+
|
| 104 |
+
lua_pushnumber(L, 3);
|
| 105 |
+
lua_pushstring(L, "value3");
|
| 106 |
+
lua_settable(L, -3);
|
| 107 |
+
|
| 108 |
+
lua_pushstring(L, "value4");
|
| 109 |
+
lua_setfield(L, -2, "key");
|
| 110 |
+
|
| 111 |
+
LuaTable table;
|
| 112 |
+
|
| 113 |
+
EXPECT_TRUE(convert::popValue(L, table));
|
| 114 |
+
|
| 115 |
+
auto iter = table.iterator();
|
| 116 |
+
|
| 117 |
+
int i = 0;
|
| 118 |
+
while (iter.toNext())
|
| 119 |
+
{
|
| 120 |
+
switch (i)
|
| 121 |
+
{
|
| 122 |
+
case 0:
|
| 123 |
+
{
|
| 124 |
+
ASSERT_STREQ("value1", lua_tostring(L, -1));
|
| 125 |
+
lua_pop(L, 1);
|
| 126 |
+
|
| 127 |
+
ASSERT_DOUBLE_EQ(1.0, lua_tonumber(L, -1));
|
| 128 |
+
break;
|
| 129 |
+
}
|
| 130 |
+
case 1:
|
| 131 |
+
{
|
| 132 |
+
ASSERT_STREQ("value2", lua_tostring(L, -1));
|
| 133 |
+
lua_pop(L, 1);
|
| 134 |
+
|
| 135 |
+
ASSERT_DOUBLE_EQ(2.0, lua_tonumber(L, -1));
|
| 136 |
+
break;
|
| 137 |
+
}
|
| 138 |
+
case 2:
|
| 139 |
+
{
|
| 140 |
+
ASSERT_STREQ("value3", lua_tostring(L, -1));
|
| 141 |
+
lua_pop(L, 1);
|
| 142 |
+
|
| 143 |
+
ASSERT_DOUBLE_EQ(3.0, lua_tonumber(L, -1));
|
| 144 |
+
break;
|
| 145 |
+
}
|
| 146 |
+
case 3:
|
| 147 |
+
{
|
| 148 |
+
ASSERT_STREQ("value4", lua_tostring(L, -1));
|
| 149 |
+
lua_pop(L, 1);
|
| 150 |
+
|
| 151 |
+
ASSERT_STREQ("key", lua_tostring(L, -1));
|
| 152 |
+
break;
|
| 153 |
+
}
|
| 154 |
+
default:
|
| 155 |
+
FAIL();
|
| 156 |
+
break;
|
| 157 |
+
}
|
| 158 |
+
++i;
|
| 159 |
+
}
|
| 160 |
+
}
|
pool/shard011/C++/0118456_temporal_format_test.cc
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
| 2 |
+
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
| 3 |
+
*
|
| 4 |
+
* Copyright (C) 2010 Pawel Blokus
|
| 5 |
+
*
|
| 6 |
+
* This program is free software; you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License as published by
|
| 8 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 9 |
+
* (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* This program is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
* GNU General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU General Public License
|
| 17 |
+
* along with this program; if not, write to the Free Software
|
| 18 |
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include <config.h>
|
| 22 |
+
|
| 23 |
+
#include <drizzled/temporal.h>
|
| 24 |
+
#include <drizzled/temporal_format.h>
|
| 25 |
+
|
| 26 |
+
#define BOOST_TEST_DYN_LINK
|
| 27 |
+
#include <boost/test/unit_test.hpp>
|
| 28 |
+
|
| 29 |
+
#include <vector>
|
| 30 |
+
|
| 31 |
+
#include "temporal_generator.h"
|
| 32 |
+
|
| 33 |
+
using namespace drizzled;
|
| 34 |
+
|
| 35 |
+
class TemporalFormatTest
|
| 36 |
+
{
|
| 37 |
+
protected:
|
| 38 |
+
TemporalFormat *tf;
|
| 39 |
+
Temporal *temporal;
|
| 40 |
+
bool result;
|
| 41 |
+
|
| 42 |
+
TemporalFormatTest()
|
| 43 |
+
{
|
| 44 |
+
tf= NULL;
|
| 45 |
+
temporal= NULL;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
~TemporalFormatTest()
|
| 49 |
+
{
|
| 50 |
+
if (tf != NULL)
|
| 51 |
+
delete tf;
|
| 52 |
+
if (temporal != NULL)
|
| 53 |
+
delete temporal;
|
| 54 |
+
}
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
BOOST_FIXTURE_TEST_SUITE(TemporalFormatTestSuite, TemporalFormatTest)
|
| 58 |
+
BOOST_AUTO_TEST_CASE(constructor_WithValidRegExp_shouldCompile)
|
| 59 |
+
{
|
| 60 |
+
tf= new TemporalFormat("^(\\d{4})[-/.]$");
|
| 61 |
+
|
| 62 |
+
result= tf->is_valid();
|
| 63 |
+
|
| 64 |
+
BOOST_REQUIRE(result);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
BOOST_AUTO_TEST_CASE(constructor_WithInvalidRegExp_shouldNotCompile)
|
| 68 |
+
{
|
| 69 |
+
tf= new TemporalFormat("^\\d{4)[-/.]$");
|
| 70 |
+
|
| 71 |
+
result= tf->is_valid();
|
| 72 |
+
|
| 73 |
+
BOOST_REQUIRE(not result);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
BOOST_AUTO_TEST_CASE(matches_OnNotMatchingString_shouldReturn_False)
|
| 77 |
+
{
|
| 78 |
+
tf= new TemporalFormat("^(\\d{4})[-/.]$");
|
| 79 |
+
char matched[] ="1234/ABC";
|
| 80 |
+
|
| 81 |
+
result= tf->matches(matched, sizeof(matched) - sizeof(char), NULL);
|
| 82 |
+
|
| 83 |
+
BOOST_REQUIRE(not result);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
BOOST_AUTO_TEST_CASE(matches_OnMatchingString_FormatWithIndexesSet_shouldPopulateTemporal)
|
| 87 |
+
{
|
| 88 |
+
char regexp[]= "^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})$";
|
| 89 |
+
char matched[]= "1999/9/14T23:29:05";
|
| 90 |
+
tf= TemporalGenerator::TemporalFormatGen::make_temporal_format(regexp, 1, 2, 3, 4, 5, 6, 0, 0);
|
| 91 |
+
temporal= new DateTime();
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
result= tf->matches(matched, sizeof(matched) - sizeof(char), temporal);
|
| 95 |
+
BOOST_REQUIRE(result);
|
| 96 |
+
|
| 97 |
+
BOOST_REQUIRE_EQUAL(1999, temporal->years());
|
| 98 |
+
BOOST_REQUIRE_EQUAL(9, temporal->months());
|
| 99 |
+
BOOST_REQUIRE_EQUAL(14, temporal->days());
|
| 100 |
+
BOOST_REQUIRE_EQUAL(23, temporal->hours());
|
| 101 |
+
BOOST_REQUIRE_EQUAL(29, temporal->minutes());
|
| 102 |
+
BOOST_REQUIRE_EQUAL(5, temporal->seconds());
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
BOOST_AUTO_TEST_CASE(matches_FormatWithMicroSecondIndexSet_shouldAddTrailingZeros)
|
| 106 |
+
{
|
| 107 |
+
tf= TemporalGenerator::TemporalFormatGen::make_temporal_format("^(\\d{1,6})$", 0, 0, 0, 0, 0, 0, 1, 0);
|
| 108 |
+
char matched[]= "560";
|
| 109 |
+
temporal= new Time();
|
| 110 |
+
|
| 111 |
+
tf->matches(matched, sizeof(matched) - sizeof(char), temporal);
|
| 112 |
+
|
| 113 |
+
BOOST_REQUIRE_EQUAL(560000, temporal->useconds());
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
BOOST_AUTO_TEST_CASE(matches_FormatWithNanoSecondIndexSet_shouldAddTrailingZeros)
|
| 117 |
+
{
|
| 118 |
+
tf= TemporalGenerator::TemporalFormatGen::make_temporal_format("^(\\d{1,9})$", 0, 0, 0, 0, 0, 0, 0, 1);
|
| 119 |
+
char matched[]= "4321";
|
| 120 |
+
temporal= new Time();
|
| 121 |
+
|
| 122 |
+
tf->matches(matched, sizeof(matched) - sizeof(char), temporal);
|
| 123 |
+
|
| 124 |
+
BOOST_REQUIRE_EQUAL(432100000, temporal->nseconds());
|
| 125 |
+
}
|
| 126 |
+
BOOST_AUTO_TEST_SUITE_END()
|
| 127 |
+
|
| 128 |
+
namespace drizzled
|
| 129 |
+
{
|
| 130 |
+
extern std::vector<TemporalFormat *> known_datetime_formats;
|
| 131 |
+
extern std::vector<TemporalFormat *> known_date_formats;
|
| 132 |
+
extern std::vector<TemporalFormat *> known_time_formats;
|
| 133 |
+
extern std::vector<TemporalFormat *> all_temporal_formats;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
BOOST_AUTO_TEST_SUITE(TemporalFormatTestSuite)
|
| 137 |
+
BOOST_AUTO_TEST_CASE(init_temporal_formats_vectorsWithKnownFormats_shouldHaveExpectedLengths)
|
| 138 |
+
{
|
| 139 |
+
init_temporal_formats();
|
| 140 |
+
|
| 141 |
+
BOOST_REQUIRE_EQUAL(13, known_datetime_formats.size());
|
| 142 |
+
BOOST_REQUIRE_EQUAL(8, known_date_formats.size());
|
| 143 |
+
BOOST_REQUIRE_EQUAL(11, known_time_formats.size());
|
| 144 |
+
BOOST_REQUIRE_EQUAL(19, all_temporal_formats.size());
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
BOOST_AUTO_TEST_CASE(deinit_temporal_formats_vectorsWithKnownFormats_shouldHaveZeroLengths)
|
| 148 |
+
{
|
| 149 |
+
init_temporal_formats();
|
| 150 |
+
deinit_temporal_formats();
|
| 151 |
+
|
| 152 |
+
BOOST_REQUIRE_EQUAL(0, known_datetime_formats.size());
|
| 153 |
+
BOOST_REQUIRE_EQUAL(0, known_date_formats.size());
|
| 154 |
+
BOOST_REQUIRE_EQUAL(0, known_time_formats.size());
|
| 155 |
+
BOOST_REQUIRE_EQUAL(0, all_temporal_formats.size());
|
| 156 |
+
}
|
| 157 |
+
BOOST_AUTO_TEST_SUITE_END()
|
pool/shard011/C++/0118457_merkleblock.cpp
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
| 2 |
+
// Copyright (c) 2009-2014 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 "merkleblock.h"
|
| 7 |
+
|
| 8 |
+
#include "hash.h"
|
| 9 |
+
#include "primitives/block.h" // for MAX_BLOCK_SIZE
|
| 10 |
+
#include "utilstrencodings.h"
|
| 11 |
+
|
| 12 |
+
using namespace std;
|
| 13 |
+
|
| 14 |
+
CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter& filter)
|
| 15 |
+
{
|
| 16 |
+
header = block.GetBlockHeader();
|
| 17 |
+
|
| 18 |
+
vector<bool> vMatch;
|
| 19 |
+
vector<uint256> vHashes;
|
| 20 |
+
|
| 21 |
+
vMatch.reserve(block.vtx.size());
|
| 22 |
+
vHashes.reserve(block.vtx.size());
|
| 23 |
+
|
| 24 |
+
for (unsigned int i = 0; i < block.vtx.size(); i++)
|
| 25 |
+
{
|
| 26 |
+
const uint256& hash = block.vtx[i].GetHash();
|
| 27 |
+
if (filter.IsRelevantAndUpdate(block.vtx[i]))
|
| 28 |
+
{
|
| 29 |
+
vMatch.push_back(true);
|
| 30 |
+
vMatchedTxn.push_back(make_pair(i, hash));
|
| 31 |
+
}
|
| 32 |
+
else
|
| 33 |
+
vMatch.push_back(false);
|
| 34 |
+
vHashes.push_back(hash);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
txn = CPartialMerkleTree(vHashes, vMatch);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
uint256 CPartialMerkleTree::CalcHash(int height, unsigned int pos, const std::vector<uint256> &vTxid) {
|
| 41 |
+
if (height == 0) {
|
| 42 |
+
// hash at height 0 is the txids themself
|
| 43 |
+
return vTxid[pos];
|
| 44 |
+
} else {
|
| 45 |
+
// calculate left hash
|
| 46 |
+
uint256 left = CalcHash(height-1, pos*2, vTxid), right;
|
| 47 |
+
// calculate right hash if not beyond the end of the array - copy left hash otherwise1
|
| 48 |
+
if (pos*2+1 < CalcTreeWidth(height-1))
|
| 49 |
+
right = CalcHash(height-1, pos*2+1, vTxid);
|
| 50 |
+
else
|
| 51 |
+
right = left;
|
| 52 |
+
// combine subhashes
|
| 53 |
+
return Hash(BEGIN(left), END(left), BEGIN(right), END(right));
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void CPartialMerkleTree::TraverseAndBuild(int height, unsigned int pos, const std::vector<uint256> &vTxid, const std::vector<bool> &vMatch) {
|
| 58 |
+
// determine whether this node is the parent of at least one matched txid
|
| 59 |
+
bool fParentOfMatch = false;
|
| 60 |
+
for (unsigned int p = pos << height; p < (pos+1) << height && p < nTransactions; p++)
|
| 61 |
+
fParentOfMatch |= vMatch[p];
|
| 62 |
+
// store as flag bit
|
| 63 |
+
vBits.push_back(fParentOfMatch);
|
| 64 |
+
if (height==0 || !fParentOfMatch) {
|
| 65 |
+
// if at height 0, or nothing interesting below, store hash and stop
|
| 66 |
+
vHash.push_back(CalcHash(height, pos, vTxid));
|
| 67 |
+
} else {
|
| 68 |
+
// otherwise, don't store any hash, but descend into the subtrees
|
| 69 |
+
TraverseAndBuild(height-1, pos*2, vTxid, vMatch);
|
| 70 |
+
if (pos*2+1 < CalcTreeWidth(height-1))
|
| 71 |
+
TraverseAndBuild(height-1, pos*2+1, vTxid, vMatch);
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
uint256 CPartialMerkleTree::TraverseAndExtract(int height, unsigned int pos, unsigned int &nBitsUsed, unsigned int &nHashUsed, std::vector<uint256> &vMatch) {
|
| 76 |
+
if (nBitsUsed >= vBits.size()) {
|
| 77 |
+
// overflowed the bits array - failure
|
| 78 |
+
fBad = true;
|
| 79 |
+
return 0;
|
| 80 |
+
}
|
| 81 |
+
bool fParentOfMatch = vBits[nBitsUsed++];
|
| 82 |
+
if (height==0 || !fParentOfMatch) {
|
| 83 |
+
// if at height 0, or nothing interesting below, use stored hash and do not descend
|
| 84 |
+
if (nHashUsed >= vHash.size()) {
|
| 85 |
+
// overflowed the hash array - failure
|
| 86 |
+
fBad = true;
|
| 87 |
+
return 0;
|
| 88 |
+
}
|
| 89 |
+
const uint256 &hash = vHash[nHashUsed++];
|
| 90 |
+
if (height==0 && fParentOfMatch) // in case of height 0, we have a matched txid
|
| 91 |
+
vMatch.push_back(hash);
|
| 92 |
+
return hash;
|
| 93 |
+
} else {
|
| 94 |
+
// otherwise, descend into the subtrees to extract matched txids and hashes
|
| 95 |
+
uint256 left = TraverseAndExtract(height-1, pos*2, nBitsUsed, nHashUsed, vMatch), right;
|
| 96 |
+
if (pos*2+1 < CalcTreeWidth(height-1))
|
| 97 |
+
right = TraverseAndExtract(height-1, pos*2+1, nBitsUsed, nHashUsed, vMatch);
|
| 98 |
+
else
|
| 99 |
+
right = left;
|
| 100 |
+
// and combine them before returning
|
| 101 |
+
return Hash(BEGIN(left), END(left), BEGIN(right), END(right));
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
CPartialMerkleTree::CPartialMerkleTree(const std::vector<uint256> &vTxid, const std::vector<bool> &vMatch) : nTransactions(vTxid.size()), fBad(false) {
|
| 106 |
+
// reset state
|
| 107 |
+
vBits.clear();
|
| 108 |
+
vHash.clear();
|
| 109 |
+
|
| 110 |
+
// calculate height of tree
|
| 111 |
+
int nHeight = 0;
|
| 112 |
+
while (CalcTreeWidth(nHeight) > 1)
|
| 113 |
+
nHeight++;
|
| 114 |
+
|
| 115 |
+
// traverse the partial tree
|
| 116 |
+
TraverseAndBuild(nHeight, 0, vTxid, vMatch);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
CPartialMerkleTree::CPartialMerkleTree() : nTransactions(0), fBad(true) {}
|
| 120 |
+
|
| 121 |
+
uint256 CPartialMerkleTree::ExtractMatches(std::vector<uint256> &vMatch) {
|
| 122 |
+
vMatch.clear();
|
| 123 |
+
// An empty set will not work
|
| 124 |
+
if (nTransactions == 0)
|
| 125 |
+
return 0;
|
| 126 |
+
// check for excessively high numbers of transactions
|
| 127 |
+
if (nTransactions > MAX_BLOCK_SIZE / 60) // 60 is the lower bound for the size of a serialized CTransaction
|
| 128 |
+
return 0;
|
| 129 |
+
// there can never be more hashes provided than one for every txid
|
| 130 |
+
if (vHash.size() > nTransactions)
|
| 131 |
+
return 0;
|
| 132 |
+
// there must be at least one bit per node in the partial tree, and at least one node per hash
|
| 133 |
+
if (vBits.size() < vHash.size())
|
| 134 |
+
return 0;
|
| 135 |
+
// calculate height of tree
|
| 136 |
+
int nHeight = 0;
|
| 137 |
+
while (CalcTreeWidth(nHeight) > 1)
|
| 138 |
+
nHeight++;
|
| 139 |
+
// traverse the partial tree
|
| 140 |
+
unsigned int nBitsUsed = 0, nHashUsed = 0;
|
| 141 |
+
uint256 hashMerkleRoot = TraverseAndExtract(nHeight, 0, nBitsUsed, nHashUsed, vMatch);
|
| 142 |
+
// verify that no problems occured during the tree traversal
|
| 143 |
+
if (fBad)
|
| 144 |
+
return 0;
|
| 145 |
+
// verify that all bits were consumed (except for the padding caused by serializing it as a byte sequence)
|
| 146 |
+
if ((nBitsUsed+7)/8 != (vBits.size()+7)/8)
|
| 147 |
+
return 0;
|
| 148 |
+
// verify that all hashes were consumed
|
| 149 |
+
if (nHashUsed != vHash.size())
|
| 150 |
+
return 0;
|
| 151 |
+
return hashMerkleRoot;
|
| 152 |
+
}
|
pool/shard011/C++/0118458_slate_modern.cpp
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <bits/stdc++.h>
|
| 2 |
+
using namespace std;
|
| 3 |
+
typedef long long int ll;
|
| 4 |
+
typedef pair<int, int> pii;
|
| 5 |
+
typedef pair<ll, ll> pll;
|
| 6 |
+
|
| 7 |
+
const ll mod = 1e9 + 7;
|
| 8 |
+
|
| 9 |
+
struct solver {
|
| 10 |
+
int r, c;
|
| 11 |
+
int n;
|
| 12 |
+
ll d;
|
| 13 |
+
|
| 14 |
+
vector<pll> pos;
|
| 15 |
+
vector<ll> values;
|
| 16 |
+
|
| 17 |
+
ll work() {
|
| 18 |
+
cin >> r >> c >> n >> d;
|
| 19 |
+
pos.resize(n);
|
| 20 |
+
values.resize(n);
|
| 21 |
+
for (int i = 0; i < n; i++) {
|
| 22 |
+
cin >> pos[i].first >> pos[i].second >> values[i];
|
| 23 |
+
pos[i].first--; pos[i].second--;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
ll ans = 0;
|
| 27 |
+
for (int q = 0; q < r; q++) {
|
| 28 |
+
for (int z = 0; z < c; z++) {
|
| 29 |
+
ll a = LLONG_MIN, b = LLONG_MAX;
|
| 30 |
+
for (int i = 0; i < n; i++) {
|
| 31 |
+
ll dist = abs(pos[i].first - q) + abs(pos[i].second - z);
|
| 32 |
+
a = max(a, values[i] - dist * d);
|
| 33 |
+
b = min(b, values[i] + dist * d);
|
| 34 |
+
if (a > b)
|
| 35 |
+
return -1;
|
| 36 |
+
}
|
| 37 |
+
ans += b;
|
| 38 |
+
ans %= mod;
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
return ans;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void solve() {
|
| 46 |
+
ll w = work();
|
| 47 |
+
if (w == -1)
|
| 48 |
+
cout << "IMPOSSIBLE" << endl;
|
| 49 |
+
else
|
| 50 |
+
cout << w << endl;
|
| 51 |
+
}
|
| 52 |
+
} s;
|
| 53 |
+
|
| 54 |
+
int main() {
|
| 55 |
+
int t;
|
| 56 |
+
cin >> t;
|
| 57 |
+
for (int i = 0; i < t; i++) {
|
| 58 |
+
cout << "Case #" << i + 1 << ": ";
|
| 59 |
+
s.solve();
|
| 60 |
+
}
|
| 61 |
+
}
|
pool/shard011/C++/0118459_BlinkSignal.cpp
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "BlinkSignal.h"
|
| 2 |
+
|
| 3 |
+
BlinkSignal::BlinkSignal(uint8_t pin, unsigned long pulseWidth) {
|
| 4 |
+
this->pin = pin;
|
| 5 |
+
this->offPulseWidth = pulseWidth;
|
| 6 |
+
this->onPulseWidth = pulseWidth;
|
| 7 |
+
pinMode(pin, OUTPUT);
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
void BlinkSignal::invertOutput(bool invert) {
|
| 11 |
+
this->invert = invert;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
void BlinkSignal::setOffPulseWidth(unsigned long pulseWidth) {
|
| 15 |
+
this->offPulseWidth = pulseWidth;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
void BlinkSignal::setOnPulseCount(uint8_t count) {
|
| 19 |
+
this->highPulseCount = count * 2 - 1;
|
| 20 |
+
this->onPulseWidth = offPulseWidth / highPulseCount ;
|
| 21 |
+
this->countDown = this->highPulseCount;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
void BlinkSignal::update(unsigned long millis) {
|
| 26 |
+
if (millis >= nextMillis) {
|
| 27 |
+
if (countDown > 0) {
|
| 28 |
+
countDown--;
|
| 29 |
+
nextMillis = millis + onPulseWidth;
|
| 30 |
+
} else {
|
| 31 |
+
countDown = highPulseCount;
|
| 32 |
+
nextMillis = millis + offPulseWidth;
|
| 33 |
+
}
|
| 34 |
+
currentState = currentState == HIGH ? LOW : HIGH;
|
| 35 |
+
illuminate();
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
void BlinkSignal::illuminate() {
|
| 40 |
+
// invert, since LED cathode is connected to GPIO pin
|
| 41 |
+
uint8_t value = invert ? (currentState == HIGH ? LOW : HIGH): currentState;
|
| 42 |
+
digitalWrite(pin, value);
|
| 43 |
+
}
|
pool/shard011/C++/0118460_try_lock_shared.pass.cpp
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//===----------------------------------------------------------------------===//
|
| 2 |
+
//
|
| 3 |
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
| 4 |
+
// See https://llvm.org/LICENSE.txt for license information.
|
| 5 |
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
| 6 |
+
//
|
| 7 |
+
//===----------------------------------------------------------------------===//
|
| 8 |
+
//
|
| 9 |
+
// UNSUPPORTED: libcpp-has-no-threads
|
| 10 |
+
// UNSUPPORTED: c++98, c++03, c++11
|
| 11 |
+
|
| 12 |
+
// FLAKY_TEST.
|
| 13 |
+
|
| 14 |
+
// <shared_mutex>
|
| 15 |
+
|
| 16 |
+
// class shared_timed_mutex;
|
| 17 |
+
|
| 18 |
+
// bool try_lock_shared();
|
| 19 |
+
|
| 20 |
+
#include <shared_mutex>
|
| 21 |
+
#include <thread>
|
| 22 |
+
#include <vector>
|
| 23 |
+
#include <cstdlib>
|
| 24 |
+
#include <cassert>
|
| 25 |
+
|
| 26 |
+
#include "test_macros.h"
|
| 27 |
+
|
| 28 |
+
std::shared_timed_mutex m;
|
| 29 |
+
|
| 30 |
+
typedef std::chrono::system_clock Clock;
|
| 31 |
+
typedef Clock::time_point time_point;
|
| 32 |
+
typedef Clock::duration duration;
|
| 33 |
+
typedef std::chrono::milliseconds ms;
|
| 34 |
+
typedef std::chrono::nanoseconds ns;
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
#if !defined(TEST_HAS_SANITIZERS)
|
| 38 |
+
ms Tolerance = ms(200);
|
| 39 |
+
#else
|
| 40 |
+
ms Tolerance = ms(200 * 5);
|
| 41 |
+
#endif
|
| 42 |
+
|
| 43 |
+
void f()
|
| 44 |
+
{
|
| 45 |
+
time_point t0 = Clock::now();
|
| 46 |
+
assert(!m.try_lock_shared());
|
| 47 |
+
assert(!m.try_lock_shared());
|
| 48 |
+
assert(!m.try_lock_shared());
|
| 49 |
+
while(!m.try_lock_shared())
|
| 50 |
+
;
|
| 51 |
+
time_point t1 = Clock::now();
|
| 52 |
+
m.unlock_shared();
|
| 53 |
+
ns d = t1 - t0 - ms(250);
|
| 54 |
+
assert(d < Tolerance); // within tolerance
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
int main(int, char**)
|
| 58 |
+
{
|
| 59 |
+
m.lock();
|
| 60 |
+
std::vector<std::thread> v;
|
| 61 |
+
for (int i = 0; i < 5; ++i)
|
| 62 |
+
v.push_back(std::thread(f));
|
| 63 |
+
std::this_thread::sleep_for(ms(250));
|
| 64 |
+
m.unlock();
|
| 65 |
+
for (auto& t : v)
|
| 66 |
+
t.join();
|
| 67 |
+
|
| 68 |
+
return 0;
|
| 69 |
+
}
|
pool/shard011/C++/0118462_document.cpp
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma warning(disable: 4786)
|
| 2 |
+
#include <set>
|
| 3 |
+
#include "document.h"
|
| 4 |
+
|
| 5 |
+
std::set<std::string> g_tagSetSupportingCDATA;
|
| 6 |
+
|
| 7 |
+
///////////////////////////////////////////////////////////////////////////////
|
| 8 |
+
|
| 9 |
+
TreeDocument::TreeDocument()
|
| 10 |
+
: mpRoot(NULL)
|
| 11 |
+
{
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
TreeNode *TreeDocument::AllocNode() {
|
| 15 |
+
mNodeHeap.push_back(TreeNode());
|
| 16 |
+
TreeNode *t = &mNodeHeap.back();
|
| 17 |
+
|
| 18 |
+
t->mpDocument = this;
|
| 19 |
+
|
| 20 |
+
return t;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
///////////////////////////////////////////////////////////////////////////////
|
| 24 |
+
|
| 25 |
+
TreeNode *TreeNode::ShallowClone() {
|
| 26 |
+
TreeNode *newNode = mpDocument->AllocNode();
|
| 27 |
+
|
| 28 |
+
newNode->mpLocation = mpLocation;
|
| 29 |
+
newNode->mLineno = mLineno;
|
| 30 |
+
newNode->mName = mName;
|
| 31 |
+
newNode->mAttribs = mAttribs;
|
| 32 |
+
newNode->mbIsText = mbIsText;
|
| 33 |
+
newNode->mbIsControl = mbIsControl;
|
| 34 |
+
|
| 35 |
+
return newNode;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const TreeAttribute *TreeNode::Attrib(const std::string& s) const {
|
| 39 |
+
Attributes::const_iterator it(mAttribs.begin()), itEnd(mAttribs.end());
|
| 40 |
+
|
| 41 |
+
for(; it!=itEnd; ++it) {
|
| 42 |
+
if ((*it).mName == s)
|
| 43 |
+
return &*it;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return NULL;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
const TreeNode *TreeNode::ResolvePath(const std::string& path, std::string& name) const {
|
| 50 |
+
std::string::size_type p = path.find('/');
|
| 51 |
+
|
| 52 |
+
if (!p) {
|
| 53 |
+
return mpDocument->mpRoot->ResolvePath(path.substr(1), name);
|
| 54 |
+
} else if (p != std::string::npos) {
|
| 55 |
+
const TreeNode *t = Child(path.substr(0, p));
|
| 56 |
+
|
| 57 |
+
if (!t)
|
| 58 |
+
return NULL;
|
| 59 |
+
|
| 60 |
+
return t->ResolvePath(path.substr(p+1), name);
|
| 61 |
+
} else {
|
| 62 |
+
name = path;
|
| 63 |
+
return this;
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
const TreeNode *TreeNode::Child(const std::string& s) const {
|
| 68 |
+
std::string name;
|
| 69 |
+
const TreeNode *parent = ResolvePath(s, name);
|
| 70 |
+
|
| 71 |
+
Children::const_iterator it(mChildren.begin()), itEnd(mChildren.end());
|
| 72 |
+
|
| 73 |
+
for(; it!=itEnd; ++it) {
|
| 74 |
+
TreeNode *child = *it;
|
| 75 |
+
if (!child->mbIsText) {
|
| 76 |
+
if (child->mName == "lina:data") {
|
| 77 |
+
const TreeNode *t = child->Child(name);
|
| 78 |
+
if (t)
|
| 79 |
+
return t;
|
| 80 |
+
}
|
| 81 |
+
if (child->mName == name)
|
| 82 |
+
return *it;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
return NULL;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
bool TreeNode::SupportsCDATA() const {
|
| 89 |
+
return g_tagSetSupportingCDATA.find(mName) != g_tagSetSupportingCDATA.end();
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
void TreeNode::SetSupportsCDATA(const std::string& tagname, bool supports_cdata) {
|
| 93 |
+
if (supports_cdata)
|
| 94 |
+
g_tagSetSupportingCDATA.insert(tagname);
|
| 95 |
+
else
|
| 96 |
+
g_tagSetSupportingCDATA.erase(tagname);
|
| 97 |
+
}
|
pool/shard011/C++/0118463_extract_intertimes.cpp
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <Rcpp.h>
|
| 2 |
+
using namespace Rcpp;
|
| 3 |
+
|
| 4 |
+
// Generate intertimes
|
| 5 |
+
// [[Rcpp::export]]
|
| 6 |
+
std::vector < int > extract_intertimes(std::vector < int > sessions){
|
| 7 |
+
|
| 8 |
+
//Declare output, iterator
|
| 9 |
+
std::vector < int > output;
|
| 10 |
+
std::vector < int > out_holding;
|
| 11 |
+
|
| 12 |
+
int in_size = sessions.size();
|
| 13 |
+
if(in_size >= 2){
|
| 14 |
+
std::sort(sessions.begin(),sessions.end());
|
| 15 |
+
for(int i = 1; i < in_size; i++){
|
| 16 |
+
output.push_back(sessions[i] - sessions[i-1]);
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
return output;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
//Extract all-but-last
|
| 24 |
+
// [[Rcpp::export]]
|
| 25 |
+
std::vector < int > all_but_last(std::list < std::vector < int > > sessions){
|
| 26 |
+
|
| 27 |
+
//Declare output, iterator
|
| 28 |
+
std::list < std::vector < int > >::const_iterator iterator;
|
| 29 |
+
std::vector < int > in_holding;
|
| 30 |
+
std::vector < int > output;
|
| 31 |
+
|
| 32 |
+
//For each list entry, extract all-but-the-last intertime - excepting one-intertime sessions.
|
| 33 |
+
//Always include those.
|
| 34 |
+
for (iterator = sessions.begin(); iterator != sessions.end(); ++iterator){
|
| 35 |
+
in_holding = *iterator;
|
| 36 |
+
int in_size = in_holding.size();
|
| 37 |
+
|
| 38 |
+
if(in_size >= 2){
|
| 39 |
+
for(int i = 1; i < in_size-1; i++){
|
| 40 |
+
output.push_back(in_holding[i]);
|
| 41 |
+
}
|
| 42 |
+
} else {
|
| 43 |
+
output.push_back(in_holding[0]);
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
return output;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
//Extract last-only
|
| 51 |
+
// [[Rcpp::export]]
|
| 52 |
+
std::vector < int > last_only(std::list < std::vector < int > > sessions){
|
| 53 |
+
|
| 54 |
+
//Declare output, iterator
|
| 55 |
+
std::list < std::vector < int > >::const_iterator iterator;
|
| 56 |
+
std::vector < int > in_holding;
|
| 57 |
+
std::vector < int > output;
|
| 58 |
+
|
| 59 |
+
//For each list entry, extract the last value. Ignore if it has <2 intertimes.
|
| 60 |
+
for (iterator = sessions.begin(); iterator != sessions.end(); ++iterator){
|
| 61 |
+
in_holding = *iterator;
|
| 62 |
+
int in_size = in_holding.size();
|
| 63 |
+
if(in_size >= 2){
|
| 64 |
+
output.push_back(in_holding[in_size-1]);
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
return output;
|
| 69 |
+
}
|
pool/shard011/C++/0118464_utilitydialog.cpp
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
| 2 |
+
// Copyright (c) 2014-2016 The Das 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 "utilitydialog.h"
|
| 7 |
+
|
| 8 |
+
#include "ui_helpmessagedialog.h"
|
| 9 |
+
|
| 10 |
+
#include "bitcoingui.h"
|
| 11 |
+
#include "clientmodel.h"
|
| 12 |
+
#include "guiconstants.h"
|
| 13 |
+
#include "intro.h"
|
| 14 |
+
#include "paymentrequestplus.h"
|
| 15 |
+
#include "guiutil.h"
|
| 16 |
+
|
| 17 |
+
#include "clientversion.h"
|
| 18 |
+
#include "init.h"
|
| 19 |
+
#include "util.h"
|
| 20 |
+
|
| 21 |
+
#include <stdio.h>
|
| 22 |
+
|
| 23 |
+
#include <QCloseEvent>
|
| 24 |
+
#include <QLabel>
|
| 25 |
+
#include <QRegExp>
|
| 26 |
+
#include <QTextTable>
|
| 27 |
+
#include <QTextCursor>
|
| 28 |
+
#include <QVBoxLayout>
|
| 29 |
+
|
| 30 |
+
/** "Help message" or "About" dialog box */
|
| 31 |
+
HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
|
| 32 |
+
QDialog(parent),
|
| 33 |
+
ui(new Ui::HelpMessageDialog)
|
| 34 |
+
{
|
| 35 |
+
ui->setupUi(this);
|
| 36 |
+
|
| 37 |
+
QString version = tr("Das Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
|
| 38 |
+
/* On x86 add a bit specifier to the version so that users can distinguish between
|
| 39 |
+
* 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
|
| 40 |
+
*/
|
| 41 |
+
#if defined(__x86_64__)
|
| 42 |
+
version += " " + tr("(%1-bit)").arg(64);
|
| 43 |
+
#elif defined(__i386__ )
|
| 44 |
+
version += " " + tr("(%1-bit)").arg(32);
|
| 45 |
+
#endif
|
| 46 |
+
|
| 47 |
+
if (about)
|
| 48 |
+
{
|
| 49 |
+
setWindowTitle(tr("About Das Core"));
|
| 50 |
+
|
| 51 |
+
/// HTML-format the license message from the core
|
| 52 |
+
QString licenseInfo = QString::fromStdString(LicenseInfo());
|
| 53 |
+
QString licenseInfoHTML = licenseInfo;
|
| 54 |
+
|
| 55 |
+
// Make URLs clickable
|
| 56 |
+
QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
|
| 57 |
+
uri.setMinimal(true); // use non-greedy matching
|
| 58 |
+
licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
|
| 59 |
+
// Replace newlines with HTML breaks
|
| 60 |
+
licenseInfoHTML.replace("\n\n", "<br><br>");
|
| 61 |
+
|
| 62 |
+
ui->aboutMessage->setTextFormat(Qt::RichText);
|
| 63 |
+
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
| 64 |
+
text = version + "\n" + licenseInfo;
|
| 65 |
+
ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
|
| 66 |
+
ui->aboutMessage->setWordWrap(true);
|
| 67 |
+
ui->helpMessage->setVisible(false);
|
| 68 |
+
} else {
|
| 69 |
+
setWindowTitle(tr("Command-line options"));
|
| 70 |
+
QString header = tr("Usage:") + "\n" +
|
| 71 |
+
" das-qt [" + tr("command-line options") + "] " + "\n";
|
| 72 |
+
QTextCursor cursor(ui->helpMessage->document());
|
| 73 |
+
cursor.insertText(version);
|
| 74 |
+
cursor.insertBlock();
|
| 75 |
+
cursor.insertText(header);
|
| 76 |
+
cursor.insertBlock();
|
| 77 |
+
|
| 78 |
+
std::string strUsage = HelpMessage(HMM_BITCOIN_QT);
|
| 79 |
+
const bool showDebug = GetBoolArg("-help-debug", false);
|
| 80 |
+
strUsage += HelpMessageGroup(tr("UI Options:").toStdString());
|
| 81 |
+
if (showDebug) {
|
| 82 |
+
strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS));
|
| 83 |
+
}
|
| 84 |
+
strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR));
|
| 85 |
+
strUsage += HelpMessageOpt("-lang=<lang>", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString());
|
| 86 |
+
strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString());
|
| 87 |
+
strUsage += HelpMessageOpt("-rootcertificates=<file>", tr("Set SSL root certificates for payment request (default: -system-)").toStdString());
|
| 88 |
+
strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN));
|
| 89 |
+
strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changes made over the GUI").toStdString());
|
| 90 |
+
if (showDebug) {
|
| 91 |
+
strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM));
|
| 92 |
+
}
|
| 93 |
+
QString coreOptions = QString::fromStdString(strUsage);
|
| 94 |
+
text = version + "\n" + header + "\n" + coreOptions;
|
| 95 |
+
|
| 96 |
+
QTextTableFormat tf;
|
| 97 |
+
tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
|
| 98 |
+
tf.setCellPadding(2);
|
| 99 |
+
QVector<QTextLength> widths;
|
| 100 |
+
widths << QTextLength(QTextLength::PercentageLength, 35);
|
| 101 |
+
widths << QTextLength(QTextLength::PercentageLength, 65);
|
| 102 |
+
tf.setColumnWidthConstraints(widths);
|
| 103 |
+
|
| 104 |
+
QTextCharFormat bold;
|
| 105 |
+
bold.setFontWeight(QFont::Bold);
|
| 106 |
+
|
| 107 |
+
Q_FOREACH (const QString &line, coreOptions.split("\n")) {
|
| 108 |
+
if (line.startsWith(" -"))
|
| 109 |
+
{
|
| 110 |
+
cursor.currentTable()->appendRows(1);
|
| 111 |
+
cursor.movePosition(QTextCursor::PreviousCell);
|
| 112 |
+
cursor.movePosition(QTextCursor::NextRow);
|
| 113 |
+
cursor.insertText(line.trimmed());
|
| 114 |
+
cursor.movePosition(QTextCursor::NextCell);
|
| 115 |
+
} else if (line.startsWith(" ")) {
|
| 116 |
+
cursor.insertText(line.trimmed()+' ');
|
| 117 |
+
} else if (line.size() > 0) {
|
| 118 |
+
//Title of a group
|
| 119 |
+
if (cursor.currentTable())
|
| 120 |
+
cursor.currentTable()->appendRows(1);
|
| 121 |
+
cursor.movePosition(QTextCursor::Down);
|
| 122 |
+
cursor.insertText(line.trimmed(), bold);
|
| 123 |
+
cursor.insertTable(1, 2, tf);
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
ui->helpMessage->moveCursor(QTextCursor::Start);
|
| 128 |
+
ui->scrollArea->setVisible(false);
|
| 129 |
+
ui->aboutLogo->setVisible(false);
|
| 130 |
+
}
|
| 131 |
+
// Theme dependent Gfx in About popup
|
| 132 |
+
QString helpMessageGfx = ":/images/" + GUIUtil::getThemeName() + "/about";
|
| 133 |
+
QPixmap pixmap = QPixmap(helpMessageGfx);
|
| 134 |
+
ui->aboutLogo->setPixmap(pixmap);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
HelpMessageDialog::~HelpMessageDialog()
|
| 138 |
+
{
|
| 139 |
+
delete ui;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
void HelpMessageDialog::printToConsole()
|
| 143 |
+
{
|
| 144 |
+
// On other operating systems, the expected action is to print the message to the console.
|
| 145 |
+
fprintf(stdout, "%s\n", qPrintable(text));
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
void HelpMessageDialog::showOrPrint()
|
| 149 |
+
{
|
| 150 |
+
#if defined(WIN32)
|
| 151 |
+
// On Windows, show a message box, as there is no stderr/stdout in windowed applications
|
| 152 |
+
exec();
|
| 153 |
+
#else
|
| 154 |
+
// On other operating systems, print help text to console
|
| 155 |
+
printToConsole();
|
| 156 |
+
#endif
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
void HelpMessageDialog::on_okButton_accepted()
|
| 160 |
+
{
|
| 161 |
+
close();
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
/** "Shutdown" window */
|
| 166 |
+
ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
|
| 167 |
+
QWidget(parent, f)
|
| 168 |
+
{
|
| 169 |
+
QVBoxLayout *layout = new QVBoxLayout();
|
| 170 |
+
layout->addWidget(new QLabel(
|
| 171 |
+
tr("Das Core is shutting down...") + "<br /><br />" +
|
| 172 |
+
tr("Do not shut down the computer until this window disappears.")));
|
| 173 |
+
setLayout(layout);
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
void ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
|
| 177 |
+
{
|
| 178 |
+
if (!window)
|
| 179 |
+
return;
|
| 180 |
+
|
| 181 |
+
// Show a simple window indicating shutdown status
|
| 182 |
+
QWidget *shutdownWindow = new ShutdownWindow();
|
| 183 |
+
// We don't hold a direct pointer to the shutdown window after creation, so use
|
| 184 |
+
// Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
|
| 185 |
+
shutdownWindow->setAttribute(Qt::WA_DeleteOnClose);
|
| 186 |
+
shutdownWindow->setWindowTitle(window->windowTitle());
|
| 187 |
+
|
| 188 |
+
// Center shutdown window at where main window was
|
| 189 |
+
const QPoint global = window->mapToGlobal(window->rect().center());
|
| 190 |
+
shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
|
| 191 |
+
shutdownWindow->show();
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
void ShutdownWindow::closeEvent(QCloseEvent *event)
|
| 195 |
+
{
|
| 196 |
+
event->ignore();
|
| 197 |
+
}
|
pool/shard011/C++/0118465_arch_test.cc
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2014 The Android Open Source Project
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
#include <stdint.h>
|
| 18 |
+
|
| 19 |
+
#include "art_method-inl.h"
|
| 20 |
+
#include "common_runtime_test.h"
|
| 21 |
+
#include "quick/quick_method_frame_info.h"
|
| 22 |
+
// Common tests are declared next to the constants.
|
| 23 |
+
#define ADD_TEST_EQ(x, y) EXPECT_EQ(x, y);
|
| 24 |
+
#include "asm_support.h"
|
| 25 |
+
|
| 26 |
+
namespace art {
|
| 27 |
+
|
| 28 |
+
class ArchTest : public CommonRuntimeTest {
|
| 29 |
+
protected:
|
| 30 |
+
void SetUpRuntimeOptions(RuntimeOptions *options) OVERRIDE {
|
| 31 |
+
// Use 64-bit ISA for runtime setup to make method size potentially larger
|
| 32 |
+
// than necessary (rather than smaller) during CreateCalleeSaveMethod
|
| 33 |
+
options->push_back(std::make_pair("imageinstructionset", "x86_64"));
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// Do not do any of the finalization. We don't want to run any code, we don't need the heap
|
| 37 |
+
// prepared, it actually will be a problem with setting the instruction set to x86_64 in
|
| 38 |
+
// SetUpRuntimeOptions.
|
| 39 |
+
void FinalizeSetup() OVERRIDE {
|
| 40 |
+
ASSERT_EQ(InstructionSet::kX86_64, Runtime::Current()->GetInstructionSet());
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
static void CheckFrameSize(InstructionSet isa, Runtime::CalleeSaveType type, uint32_t save_size)
|
| 44 |
+
NO_THREAD_SAFETY_ANALYSIS {
|
| 45 |
+
Runtime* const runtime = Runtime::Current();
|
| 46 |
+
Thread* const self = Thread::Current();
|
| 47 |
+
ScopedObjectAccess soa(self); // So we can create callee-save methods.
|
| 48 |
+
|
| 49 |
+
runtime->SetInstructionSet(isa);
|
| 50 |
+
ArtMethod* save_method = runtime->CreateCalleeSaveMethod();
|
| 51 |
+
runtime->SetCalleeSaveMethod(save_method, type);
|
| 52 |
+
QuickMethodFrameInfo frame_info = runtime->GetRuntimeMethodFrameInfo(save_method);
|
| 53 |
+
EXPECT_EQ(frame_info.FrameSizeInBytes(), save_size) << "Expected and real size differs for "
|
| 54 |
+
<< type << " core spills=" << std::hex << frame_info.CoreSpillMask() << " fp spills="
|
| 55 |
+
<< frame_info.FpSpillMask() << std::dec;
|
| 56 |
+
}
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
TEST_F(ArchTest, CheckCommonOffsetsAndSizes) {
|
| 60 |
+
CheckAsmSupportOffsetsAndSizes();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Grab architecture specific constants.
|
| 64 |
+
namespace arm {
|
| 65 |
+
#include "arch/arm/asm_support_arm.h"
|
| 66 |
+
static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
|
| 67 |
+
#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
|
| 68 |
+
static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
|
| 69 |
+
#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
|
| 70 |
+
static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
|
| 71 |
+
#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
namespace arm64 {
|
| 75 |
+
#include "arch/arm64/asm_support_arm64.h"
|
| 76 |
+
static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
|
| 77 |
+
#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
|
| 78 |
+
static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
|
| 79 |
+
#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
|
| 80 |
+
static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
|
| 81 |
+
#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
namespace mips {
|
| 85 |
+
#include "arch/mips/asm_support_mips.h"
|
| 86 |
+
static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
|
| 87 |
+
#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
|
| 88 |
+
static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
|
| 89 |
+
#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
|
| 90 |
+
static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
|
| 91 |
+
#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
namespace mips64 {
|
| 95 |
+
#include "arch/mips64/asm_support_mips64.h"
|
| 96 |
+
static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
|
| 97 |
+
#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
|
| 98 |
+
static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
|
| 99 |
+
#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
|
| 100 |
+
static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
|
| 101 |
+
#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
namespace x86 {
|
| 105 |
+
#include "arch/x86/asm_support_x86.h"
|
| 106 |
+
static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
|
| 107 |
+
#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
|
| 108 |
+
static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
|
| 109 |
+
#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
|
| 110 |
+
static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
|
| 111 |
+
#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
namespace x86_64 {
|
| 115 |
+
#include "arch/x86_64/asm_support_x86_64.h"
|
| 116 |
+
static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
|
| 117 |
+
#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
|
| 118 |
+
static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
|
| 119 |
+
#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
|
| 120 |
+
static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
|
| 121 |
+
#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
// Check architecture specific constants are sound.
|
| 125 |
+
TEST_F(ArchTest, ARM) {
|
| 126 |
+
CheckFrameSize(InstructionSet::kArm, Runtime::kSaveAll, arm::kFrameSizeSaveAllCalleeSave);
|
| 127 |
+
CheckFrameSize(InstructionSet::kArm, Runtime::kRefsOnly, arm::kFrameSizeRefsOnlyCalleeSave);
|
| 128 |
+
CheckFrameSize(InstructionSet::kArm, Runtime::kRefsAndArgs, arm::kFrameSizeRefsAndArgsCalleeSave);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
TEST_F(ArchTest, ARM64) {
|
| 133 |
+
CheckFrameSize(InstructionSet::kArm64, Runtime::kSaveAll, arm64::kFrameSizeSaveAllCalleeSave);
|
| 134 |
+
CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsOnly, arm64::kFrameSizeRefsOnlyCalleeSave);
|
| 135 |
+
CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsAndArgs,
|
| 136 |
+
arm64::kFrameSizeRefsAndArgsCalleeSave);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
TEST_F(ArchTest, MIPS) {
|
| 140 |
+
CheckFrameSize(InstructionSet::kMips, Runtime::kSaveAll, mips::kFrameSizeSaveAllCalleeSave);
|
| 141 |
+
CheckFrameSize(InstructionSet::kMips, Runtime::kRefsOnly, mips::kFrameSizeRefsOnlyCalleeSave);
|
| 142 |
+
CheckFrameSize(InstructionSet::kMips, Runtime::kRefsAndArgs,
|
| 143 |
+
mips::kFrameSizeRefsAndArgsCalleeSave);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
TEST_F(ArchTest, MIPS64) {
|
| 147 |
+
CheckFrameSize(InstructionSet::kMips64, Runtime::kSaveAll, mips64::kFrameSizeSaveAllCalleeSave);
|
| 148 |
+
CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsOnly, mips64::kFrameSizeRefsOnlyCalleeSave);
|
| 149 |
+
CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsAndArgs,
|
| 150 |
+
mips64::kFrameSizeRefsAndArgsCalleeSave);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
TEST_F(ArchTest, X86) {
|
| 154 |
+
CheckFrameSize(InstructionSet::kX86, Runtime::kSaveAll, x86::kFrameSizeSaveAllCalleeSave);
|
| 155 |
+
CheckFrameSize(InstructionSet::kX86, Runtime::kRefsOnly, x86::kFrameSizeRefsOnlyCalleeSave);
|
| 156 |
+
CheckFrameSize(InstructionSet::kX86, Runtime::kRefsAndArgs, x86::kFrameSizeRefsAndArgsCalleeSave);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
TEST_F(ArchTest, X86_64) {
|
| 160 |
+
CheckFrameSize(InstructionSet::kX86_64, Runtime::kSaveAll, x86_64::kFrameSizeSaveAllCalleeSave);
|
| 161 |
+
CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsOnly, x86_64::kFrameSizeRefsOnlyCalleeSave);
|
| 162 |
+
CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsAndArgs,
|
| 163 |
+
x86_64::kFrameSizeRefsAndArgsCalleeSave);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
} // namespace art
|