blob_id stringlengths 40 40 | directory_id stringlengths 40 40 | path stringlengths 3 264 | content_id stringlengths 40 40 | detected_licenses listlengths 0 85 | license_type stringclasses 2
values | repo_name stringlengths 5 140 | snapshot_id stringlengths 40 40 | revision_id stringlengths 40 40 | branch_name stringclasses 986
values | visit_date timestamp[us] | revision_date timestamp[us] | committer_date timestamp[us] | github_id int64 3.89k 681M ⌀ | star_events_count int64 0 209k | fork_events_count int64 0 110k | gha_license_id stringclasses 23
values | gha_event_created_at timestamp[us] | gha_created_at timestamp[us] | gha_language stringclasses 145
values | src_encoding stringclasses 34
values | language stringclasses 1
value | is_vendor bool 1
class | is_generated bool 2
classes | length_bytes int64 3 10.4M | extension stringclasses 122
values | content stringlengths 3 10.4M | authors listlengths 1 1 | author_id stringlengths 0 158 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
bd8cc94ccd6aa8f1402f2abe59af1b7d26748186 | 50249f2c0d924c87cd196fc0f815e7df198228f8 | /PubSubClient.ino | ea0b361d8f87f1334a1d712fc77ba66d9f592a3b | [] | no_license | hipotenusa/PubSubClient | fee4e4d4bb43650856582cef11bd8ab55feaf26d | 462b2a887f187921fcd7f85c6513bdca93959c88 | refs/heads/master | 2021-08-30T09:13:37.733314 | 2017-12-17T06:16:30 | 2017-12-17T06:16:30 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,667 | ino | #include <ESP8266WiFi.h>
#include <PubSubClient.h>
const char *ssid = ""; // nama ssid dari wi-fi, jangan lebih dari 32 karakter
const char *pass = ""; // password dari wi-fi
//------------------------------ Konfigurasi server pada <a href="https://www.cloudmqtt.com/">https://www.cloudmqtt.com/</a>
// perhatikan akun CloudMQTT yang telah dibuat, kemudian pastikan konfigurasi yang diperlukan ini, sama dengan akun yang anda miliki.
const char *mqtt_server = "m14.cloudmqtt.com";
const int mqtt_port = 18622;
const char *mqtt_user = "jztmmefb";
const char *mqtt_pass = "3Hm_ftWsUQwE";
//------------------------------ End Konfigurasi server pada <a href="https://www.cloudmqtt.com/">https://www.cloudmqtt.com/</a>
//deklarasi variabel untuk led
int led = 16;
int led2 = 4;
//deklarasi konfigurasi server
WiFiClient wclient;
PubSubClient client(wclient, mqtt_server, mqtt_port);
//------------------------------ fungsi untuk menerima nilai balik (subcribe)
void callback(const MQTT::Publish& pub) {
if(pub.payload_string() == "1")
{
digitalWrite(led, HIGH);
client.publish("/led/state", "Lampu Hidup");
}
else if(pub.payload_string() == "0")
{
digitalWrite(led, LOW);
client.publish("/led/state", "Lampu Mati");
}
Serial.println(pub.payload_string());
}
//------------------------------ End fungsi untuk menerima nilai balik (subcribe)
void setup() {
// Setup console
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
//----------------------------- cek apakah wi-fi sudah tersambung
if (WiFi.status() != WL_CONNECTED) {
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println("...");
WiFi.begin(ssid, pass);
if (WiFi.waitForConnectResult() != WL_CONNECTED)
return;
Serial.println("WiFi connected");
}
//----------------------------- End cek apakah wi-fi sudah tersambung
//----------------------------- cek apakah ESP sudah tersambung dengan server
if (WiFi.status() == WL_CONNECTED) {
if (!client.connected()) {
Serial.println("Connecting to MQTT server");
if (client.connect(MQTT::Connect("arduinoClient2").set_auth(mqtt_user, mqtt_pass))) {
Serial.println("Connected to MQTT server");
client.set_callback(callback);
client.subscribe("/led");
client.publish("/led/state", "0");
} else {
Serial.println("Could not connect to MQTT server");
}
}
//----------------------------- cek apakah ESP sudah tersambung dengan server
if (client.connected())
client.loop();
}
}
| [
"simatupang.ega@gmail.com"
] | simatupang.ega@gmail.com |
209b34ab5a0823a44f2d3765a45b3ad035a27a22 | fa4258ef4de2e5414abe4bbf3fb3ad15dc773c7d | /1401C.cpp | d2df3976dd394046c8c8eb3adcd9c60fc0d43a0c | [] | no_license | nihithreddy/Codeforces | 48a1adc78731bd3fce600614458f140be66653cb | b1b7f2fc2bc0d7d9e7b19153833d266986257746 | refs/heads/master | 2022-12-18T01:19:25.451339 | 2020-09-01T02:29:29 | 2020-09-01T02:29:29 | 286,294,639 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 839 | cpp | #include<bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=(0);i<(n);i++)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<double> vd;
typedef vector<string> vs;
void solve(){
int n,mi=(int)1e9;
cin>>n;
int a[n],b[n];
forn(i,n){
cin>>a[i];
b[i]=a[i];
mi=min(mi,a[i]);
}
sort(b,b+n);
bool ok = 1;
forn(i,n){
if(a[i]!=b[i]&& a[i]%mi){
ok = 0;
break;
}
}
string ans=(ok)?"YES":"NO";
cout<<ans<<"\n";
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
return 0;
} | [
"sainihith9618@gmail.com"
] | sainihith9618@gmail.com |
2dc8d1663f4e6a5a79aba2518e736e8552e875db | 4247edf4ecdd626c8d3160e08a8758781ff9b30d | /gazebo_ros_pkgs/gazebo_ros_control/include/gazebo_ros_control/internal/joint_state.h | 4fcf0716e482d72729ff122f533da8f2174e6c83 | [
"LicenseRef-scancode-unknown-license-reference",
"BSD-3-Clause"
] | permissive | ignaciotb/robi_final_project | 4a32588d8153800d4c8f545ed0f2f1965dc70b77 | dfb73d2d1c2c3eab15b0dec4d0a3f19f202d155e | refs/heads/master | 2022-06-18T04:14:24.812872 | 2022-06-10T11:53:15 | 2022-06-10T11:53:15 | 210,183,722 | 4 | 19 | null | 2019-10-04T12:45:36 | 2019-09-22T17:03:42 | C++ | UTF-8 | C++ | false | false | 3,815 | h | ///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015, PAL Robotics S.L.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of PAL Robotics S.L. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//////////////////////////////////////////////////////////////////////////////
#ifndef _GAZEBO_ROS_CONTROL__INTERNAL__JOINT_STATE_H_
#define _GAZEBO_ROS_CONTROL__INTERNAL__JOINT_STATE_H_
#include <algorithm>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <gazebo/physics/Joint.hh>
#include <gazebo_ros_control/internal/read_write_resource.h>
#include <urdf/model.h>
namespace hardware_interface
{
class RobotHW;
}
namespace gazebo_ros_control
{
namespace internal
{
// TODO: Create an abstract base class?, separate read from write?
class JointState : public ReadWriteResource
{
public:
JointState();
// TODO doc requisite: RobotHW must contain interface
virtual void init(const std::string& resource_name,
const ros::NodeHandle& nh,
boost::shared_ptr<gazebo::physics::Model> gazebo_model,
const urdf::Model* const urdf_model,
hardware_interface::RobotHW* robot_hw);
virtual void read(const ros::Time& time,
const ros::Duration& period,
bool in_estop);
virtual std::vector<std::string> getHardwareInterfaceTypes();
virtual std::string getName() const {return name_;}
protected:
std::string name_;
double pos_;
double vel_;
double eff_;
std::shared_ptr<const urdf::Joint> urdf_joint_;
gazebo::physics::JointPtr sim_joint_;
};
// Code copied almost verbatim from transmission_interface::JointStateInterfaceProvider
// TODO: Refactor to avoid duplication
template <class Interface>
bool hasResource(const std::string& name, const Interface& iface)
{
using hardware_interface::internal::demangledTypeName;
// Do nothing if resource already exists on the interface
const std::vector<std::string>& existing_res = iface.getNames();
return existing_res.end() != std::find(existing_res.begin(), existing_res.end(), name);
}
template <class T>
T clamp(const T& val, const T& min_val, const T& max_val)
{
return std::min(std::max(val, min_val), max_val);
}
} // namespace
} // namespace
#endif
| [
"torroba@kth.se"
] | torroba@kth.se |
43158d4fd5cdad56a527ee1d13e3d6707d68ac41 | 76f0efb245ff0013e0428ee7636e72dc288832ab | /out/Default/gen/blink/bindings/core/v8/V8HTMLFontElement.cpp | 0e0c9fa6ef079ebfaaa068e26399432fd84ee86b | [] | no_license | dckristiono/chromium | e8845d2a8754f39e0ca1d3d3d44d01231957367c | 8ad7c1bd5778bfda3347cf6b30ef60d3e4d7c0b9 | refs/heads/master | 2020-04-22T02:34:41.775069 | 2016-08-24T14:05:09 | 2016-08-24T14:05:09 | 66,465,243 | 0 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 8,606 | cpp | // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file has been auto-generated by code_generator_v8.py. DO NOT MODIFY!
#include "V8HTMLFontElement.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/V8DOMConfiguration.h"
#include "bindings/core/v8/V8ObjectConstructor.h"
#include "core/HTMLNames.h"
#include "core/animation/ElementAnimation.h"
#include "core/dom/Document.h"
#include "core/dom/ElementFullscreen.h"
#include "core/dom/custom/CEReactionsScope.h"
#include "core/dom/custom/V0CustomElementProcessingStack.h"
#include "wtf/GetPtr.h"
#include "wtf/RefPtr.h"
namespace blink {
// Suppress warning: global constructors, because struct WrapperTypeInfo is trivial
// and does not depend on another global objects.
#if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
const WrapperTypeInfo V8HTMLFontElement::wrapperTypeInfo = { gin::kEmbedderBlink, V8HTMLFontElement::domTemplate, V8HTMLFontElement::trace, V8HTMLFontElement::traceWrappers, 0, 0, V8HTMLFontElement::preparePrototypeAndInterfaceObject, nullptr, "HTMLFontElement", &V8HTMLElement::wrapperTypeInfo, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::NodeClassId, WrapperTypeInfo::InheritFromEventTarget, WrapperTypeInfo::Dependent };
#if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
// This static member must be declared by DEFINE_WRAPPERTYPEINFO in HTMLFontElement.h.
// For details, see the comment of DEFINE_WRAPPERTYPEINFO in
// bindings/core/v8/ScriptWrappable.h.
const WrapperTypeInfo& HTMLFontElement::s_wrapperTypeInfo = V8HTMLFontElement::wrapperTypeInfo;
static_assert(
!std::is_base_of<ActiveScriptWrappable, HTMLFontElement>::value,
"HTMLFontElement inherits from ActiveScriptWrappable, but does not specify "
"[ActiveScriptWrappable] extended attribute in the IDL file. "
"Be consistent.");
namespace HTMLFontElementV8Internal {
static void colorAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Object> holder = info.Holder();
HTMLFontElement* impl = V8HTMLFontElement::toImpl(holder);
v8SetReturnValueString(info, impl->fastGetAttribute(HTMLNames::colorAttr), info.GetIsolate());
}
static void colorAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
HTMLFontElementV8Internal::colorAttributeGetter(info);
}
static void colorAttributeSetter(v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Object> holder = info.Holder();
HTMLFontElement* impl = V8HTMLFontElement::toImpl(holder);
V8StringResource<TreatNullAsEmptyString> cppValue = v8Value;
if (!cppValue.prepare())
return;
impl->setAttribute(HTMLNames::colorAttr, cppValue);
}
static void colorAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Value> v8Value = info[0];
CEReactionsScope ceReactionsScope;
V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
HTMLFontElementV8Internal::colorAttributeSetter(v8Value, info);
}
static void faceAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Object> holder = info.Holder();
HTMLFontElement* impl = V8HTMLFontElement::toImpl(holder);
v8SetReturnValueString(info, impl->fastGetAttribute(HTMLNames::faceAttr), info.GetIsolate());
}
static void faceAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
HTMLFontElementV8Internal::faceAttributeGetter(info);
}
static void faceAttributeSetter(v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Object> holder = info.Holder();
HTMLFontElement* impl = V8HTMLFontElement::toImpl(holder);
V8StringResource<> cppValue = v8Value;
if (!cppValue.prepare())
return;
impl->setAttribute(HTMLNames::faceAttr, cppValue);
}
static void faceAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Value> v8Value = info[0];
CEReactionsScope ceReactionsScope;
V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
HTMLFontElementV8Internal::faceAttributeSetter(v8Value, info);
}
static void sizeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Object> holder = info.Holder();
HTMLFontElement* impl = V8HTMLFontElement::toImpl(holder);
v8SetReturnValueString(info, impl->fastGetAttribute(HTMLNames::sizeAttr), info.GetIsolate());
}
static void sizeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
HTMLFontElementV8Internal::sizeAttributeGetter(info);
}
static void sizeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Object> holder = info.Holder();
HTMLFontElement* impl = V8HTMLFontElement::toImpl(holder);
V8StringResource<> cppValue = v8Value;
if (!cppValue.prepare())
return;
impl->setAttribute(HTMLNames::sizeAttr, cppValue);
}
static void sizeAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Value> v8Value = info[0];
CEReactionsScope ceReactionsScope;
V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
HTMLFontElementV8Internal::sizeAttributeSetter(v8Value, info);
}
} // namespace HTMLFontElementV8Internal
const V8DOMConfiguration::AccessorConfiguration V8HTMLFontElementAccessors[] = {
{"color", HTMLFontElementV8Internal::colorAttributeGetterCallback, HTMLFontElementV8Internal::colorAttributeSetterCallback, 0, 0, 0, v8::DEFAULT, static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype, V8DOMConfiguration::CheckHolder},
{"face", HTMLFontElementV8Internal::faceAttributeGetterCallback, HTMLFontElementV8Internal::faceAttributeSetterCallback, 0, 0, 0, v8::DEFAULT, static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype, V8DOMConfiguration::CheckHolder},
{"size", HTMLFontElementV8Internal::sizeAttributeGetterCallback, HTMLFontElementV8Internal::sizeAttributeSetterCallback, 0, 0, 0, v8::DEFAULT, static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype, V8DOMConfiguration::CheckHolder},
};
static void installV8HTMLFontElementTemplate(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::FunctionTemplate> interfaceTemplate)
{
// Initialize the interface object's template.
V8DOMConfiguration::initializeDOMInterfaceTemplate(isolate, interfaceTemplate, V8HTMLFontElement::wrapperTypeInfo.interfaceName, V8HTMLElement::domTemplate(isolate, world), V8HTMLFontElement::internalFieldCount);
v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTemplate);
ALLOW_UNUSED_LOCAL(signature);
v8::Local<v8::ObjectTemplate> instanceTemplate = interfaceTemplate->InstanceTemplate();
ALLOW_UNUSED_LOCAL(instanceTemplate);
v8::Local<v8::ObjectTemplate> prototypeTemplate = interfaceTemplate->PrototypeTemplate();
ALLOW_UNUSED_LOCAL(prototypeTemplate);
// Register DOM constants, attributes and operations.
V8DOMConfiguration::installAccessors(isolate, world, instanceTemplate, prototypeTemplate, interfaceTemplate, signature, V8HTMLFontElementAccessors, WTF_ARRAY_LENGTH(V8HTMLFontElementAccessors));
}
v8::Local<v8::FunctionTemplate> V8HTMLFontElement::domTemplate(v8::Isolate* isolate, const DOMWrapperWorld& world)
{
return V8DOMConfiguration::domClassTemplate(isolate, world, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8HTMLFontElementTemplate);
}
bool V8HTMLFontElement::hasInstance(v8::Local<v8::Value> v8Value, v8::Isolate* isolate)
{
return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
}
v8::Local<v8::Object> V8HTMLFontElement::findInstanceInPrototypeChain(v8::Local<v8::Value> v8Value, v8::Isolate* isolate)
{
return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
}
HTMLFontElement* V8HTMLFontElement::toImplWithTypeCheck(v8::Isolate* isolate, v8::Local<v8::Value> value)
{
return hasInstance(value, isolate) ? toImpl(v8::Local<v8::Object>::Cast(value)) : nullptr;
}
} // namespace blink
| [
"dckristiono@gmail.com"
] | dckristiono@gmail.com |
f5c7dce5389fb76f22a9600e541868e7bf394f3b | cc0f632f56c572bd4f50c141f048b0bc7fad4055 | /UVA/10780.cpp | 2da90b26c24ac939640282394a0a68593b4506f0 | [] | no_license | AbuHorairaTarif/UvaProject | 78517e585c668a83b99866be19b84a0a120bc617 | b0688f97a7226bdd692c9ceb29e7b0c406b8a15a | refs/heads/master | 2021-05-04T08:19:46.607485 | 2016-11-11T14:26:23 | 2016-11-11T14:26:23 | 70,333,668 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 796 | cpp | #include <iostream>
#include <cstring>
using namespace std;
int getsum(int n,int x)
{
int ans=0;
while(n)
{
ans+=n/x;
n/=x;
}
return ans;
}
int main(int argc,char *argv[])
{
int n,m,i,j,t,c=1,temp,ans,a;
cin>>t;
while(t--)
{
cin>>m>>n;
i=2;
ans=1000000;
while(m>1)
{
a=0;
while(m%i==0)
{
a++;
m/=i;
}
if(a)
{
temp=getsum(n,i)/a;
if(ans>temp)
ans=temp;
}
i++;
}
cout<<"Case "<<c++<<":"<<endl;
if(ans)
cout<<ans<<endl;
else cout<<"Impossible to divide"<<endl;
}
return 0;
}
| [
"horaira_cse13@yahoo.com"
] | horaira_cse13@yahoo.com |
76c618cd0db4f1d053f3e398f65f5566769b49aa | e23b730868329011477751c841dc188ff9662938 | /Code/glwidget.h | 41aec03dc1fc49461279cad449aca91883177c23 | [] | no_license | NaifAlhar6i/Chapter7 | d18e597621f90cce1fc10f69134214338d19ce6a | 607f6da7c9949ebf0386397c1b42e5c8964266ae | refs/heads/master | 2022-04-27T05:19:48.007179 | 2020-04-26T10:38:17 | 2020-04-26T10:38:17 | 259,003,927 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,909 | h | #ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QPoint>
#include <QMouseEvent>
#include <QVector3D>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include "Helper/transformation.h"
#include "GL/glmanager.h"
#include <QTimer>
#include "Helper/framerate.h"
class MainWindow;
/**
* @brief The GLWidget class the rendering canvas
*/
class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions, public Transformation, public GLManager
{
Q_OBJECT
public:
/**
* @brief GLWidget class constructor
* @param parent specifies the parent
*/
explicit GLWidget( QWidget *parent=0);
~GLWidget();
/**
* @brief UpdateParticles updates particles data
* @param particle specifies the particle data
* @param color specifies the vertices color data
* @param map specifies the method to be used to update the OpenGL buffer
* @return true if data updated otherwise return false
*/
int UpdateParticles(void *particle, void *color, bool map = false);
/**
* @brief UpdateParticles updates particles data
* @param particle specifies the particle data
* @param map specifies the method to be used to update the OpenGL buffer
* @return true if data updated otherwise return false
*/
int UpdateParticles(void *particle, bool map = false);
protected:
/**
* @brief initializeGL initilizes OpenGL objects
*/
void initializeGL() Q_DECL_OVERRIDE;
/**
* @brief resizeGL resizes viewport
* @param w specifies the viewport widght
* @param h specifies the viewport hight
*/
void resizeGL(int w, int h) Q_DECL_OVERRIDE;
/**
* @brief paintGL paints the OpenGL
*/
void paintGL() Q_DECL_OVERRIDE;
public slots:
protected slots:
/**
* @brief zoom zoom in and out
* @param value zooming value
*/
void zoom( int value );
/**
* @brief mousePressEvent
*/
virtual void mousePressEvent(QMouseEvent*);
/**
* @brief mouseMoveEvent
*/
virtual void mouseMoveEvent(QMouseEvent*);
signals:
/**
* @brief FrameRateUpdated signals to be fired on frame is done
*/
void FrameRateUpdated( int );
/**
* @brief GLinitialized signals to be fired on OpenGL objects initilized
*/
void GLinitialized();
private:
/**
* @brief m_FrameRate
*/
FrameRate m_FrameRate;
/**
* @brief m_RefereshTimer
*/
QTimer m_RefereshTimer;
/**
* @brief getFrameRate gets a reference of the frame rate object FrameRate
* @return a reference to FrameRate
*/
inline FrameRate &getFrameRate() { return m_FrameRate; }
/**
* @brief getRefereshTimer gets a reference to the Widget referesing timer
* @return a reference to a QTimer object
*/
inline QTimer &getRefereshTimer() { return m_RefereshTimer; }
};
#endif // GLWIDGET_H
| [
"668696@swansea.ac.uk"
] | 668696@swansea.ac.uk |
4fd308eb0afce41061c44d32c83303d279ffd619 | de829c765d16dffe32e9777794c374c9e25348b3 | /libs/ledger/src/chain/address.cpp | 01b6497c21dc59ed9ce41d5a976740a92f67f5e3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-unknown"
] | permissive | jinmannwong/ledger | 8454cf12f0fc14905a0cd84bfb8fe88efb4c1680 | f3b129c127e107603e08bb192eb695d23eb17dbc | refs/heads/master | 2020-06-15T23:01:24.719743 | 2019-07-31T16:45:05 | 2019-07-31T16:45:05 | 195,414,732 | 0 | 0 | Apache-2.0 | 2019-07-18T15:00:53 | 2019-07-05T13:33:06 | C++ | UTF-8 | C++ | false | false | 3,550 | cpp | //------------------------------------------------------------------------------
//
// Copyright 2018-2019 Fetch.AI Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//------------------------------------------------------------------------------
#include "core/byte_array/const_byte_array.hpp"
#include "core/byte_array/decoders.hpp"
#include "core/byte_array/encoders.hpp"
#include "crypto/hash.hpp"
#include "crypto/identity.hpp"
#include "crypto/sha256.hpp"
#include "ledger/chain/address.hpp"
#include <cstddef>
#include <stdexcept>
#include <utility>
namespace fetch {
namespace ledger {
namespace {
using byte_array::ToBase58;
using byte_array::FromBase58;
/**
* Helper function to calculation the address checksum
*
* @param raw_address The input raw address
* @return The calculated checksum for the address
*/
Address::ConstByteArray CalculateChecksum(Address::ConstByteArray const &raw_address)
{
return crypto::Hash<crypto::SHA256>(raw_address).SubArray(0, Address::CHECKSUM_LENGTH);
}
} // namespace
/**
* Parse an address from a string of characters (not a series of bytes)
*
* @param input The input characters to be decoded
* @param output The output address to be populated
* @return true if successful, otherwise false
*/
bool Address::Parse(ConstByteArray const &input, Address &output)
{
bool success{false};
// decode the whole buffer
auto const decoded = FromBase58(input);
// ensure that the decode completed successfully (failure would result in 0 length byte array)
// and that the buffer is the correct size for an address
if (TOTAL_LENGTH == decoded.size())
{
// split the decoded into address and checksum
auto const address = decoded.SubArray(0, RAW_LENGTH);
auto const checksum = decoded.SubArray(RAW_LENGTH, CHECKSUM_LENGTH);
// compute the expected checksum and compare
if (CalculateChecksum(address) == checksum)
{
output.address_ = address;
output.display_ = input;
success = true;
}
}
return success;
}
/**
* Create an address from an identity
*
* @param identity The input identity to use
*/
Address::Address(crypto::Identity const &identity)
: address_(crypto::Hash<crypto::SHA256>(identity.identifier()))
, display_(ToBase58(address_ + CalculateChecksum(address_)))
{}
/**
* Create an address from a raw address (that is a fixed array of bytes)
*
* @param address The input (raw) address to use.
*/
Address::Address(RawAddress const &address)
: address_(address.data(), address.size())
, display_(ToBase58(address_ + CalculateChecksum(address_)))
{}
/**
* Create an address from the const byte array of raw bytes
*
* @param address The raw address
*/
Address::Address(ConstByteArray address)
: address_(std::move(address))
, display_(ToBase58(address_ + CalculateChecksum(address_)))
{
if (address_.size() != std::size_t{RAW_LENGTH})
{
throw std::runtime_error("Incorrect address size");
}
}
} // namespace ledger
} // namespace fetch
| [
"noreply@github.com"
] | jinmannwong.noreply@github.com |
687b11e09016a5a12ba8ee3d435e1264769720db | 005cb1c69358d301f72c6a6890ffeb430573c1a1 | /Pods/Headers/Private/GeoFeatures/boost/type_traits/detail/size_t_trait_undef.hpp | fa11a63f036eeaa6897ee05da2f23cda5f66ae60 | [
"Apache-2.0"
] | permissive | TheClimateCorporation/DemoCLUs | 05588dcca687cc5854755fad72f07759f81fe673 | f343da9b41807694055151a721b497cf6267f829 | refs/heads/master | 2021-01-10T15:10:06.021498 | 2016-04-19T20:31:34 | 2016-04-19T20:31:34 | 51,960,444 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 89 | hpp | ../../../../../../GeoFeatures/GeoFeatures/boost/type_traits/detail/size_t_trait_undef.hpp | [
"tommy.rogers@climate.com"
] | tommy.rogers@climate.com |
83222be5be996a3387395f8c80581c4a3700ff32 | 21a221c20313339ac7380f8d92f8006e5435ef1d | /src/arcscripts/src/SpellHandlers/HunterSpells.cpp | 279d7f831a0cd1c3ebe35611f46193ebff72f668 | [] | no_license | AwkwardDev/Descent-core-scripts-3.3.5 | a947a98d0fdedae36a488c542642fcf61472c3d7 | d773b1a41ed3f9f970d81962235e858d0848103f | refs/heads/master | 2021-01-18T10:16:03.750112 | 2014-08-12T16:28:15 | 2014-08-12T16:28:15 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,347 | cpp | /*
* ArcScript Scripts for Arcemu MMORPG Server
* Copyright (C) 2008-2009 Arcemu Team
* Copyright (C) 2007 Moon++ <http://www.moonplusplus.com/>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Setup.h"
bool Refocus(uint32 i, Spell * pSpell)
{
Player * playerTarget = pSpell->GetPlayerTarget();
if(playerTarget == 0) return true;
SpellSet::const_iterator itr = playerTarget->mSpells.begin();
for(; itr != playerTarget->mSpells.end(); ++itr)
{
if((*itr) == 24531) // skip calling spell.. otherwise spammies! :D
continue;
if((*itr) == 19434 || (*itr) == 20900 || (*itr) == 20901 || (*itr) == 20902 || (*itr) == 20903 || (*itr) == 20904 || (*itr) == 27632
|| (*itr) == 2643 || (*itr) == 14288|| (*itr) == 14289|| (*itr) == 14290 || (*itr) == 25294 || (*itr) == 14443 || (*itr) == 18651 || (*itr) == 20735 || (*itr) == 21390
|| (*itr) == 1510 || (*itr) == 14294 || (*itr) == 14295 || (*itr) == 1540 || (*itr) == 22908
|| (*itr) == 3044 || (*itr) == 14281 || (*itr) == 14282 || (*itr) == 14283 || (*itr) == 14284 || (*itr) == 14285 || (*itr) == 14286 || (*itr) == 14287)
playerTarget->ClearCooldownForSpell((*itr));
}
return true;
}
bool Readiness(uint32 i, Spell * pSpell)
{
if(!pSpell->p_caster)
return true;
pSpell->p_caster->ClearCooldownsOnLine(50 , pSpell->GetProto()->Id);//Beast Mastery
pSpell->p_caster->ClearCooldownsOnLine(163, pSpell->GetProto()->Id);//Marksmanship
pSpell->p_caster->ClearCooldownsOnLine(51 , pSpell->GetProto()->Id);//Survival
return true;
}
void SetupHunterSpells(ScriptMgr * mgr)
{
mgr->register_dummy_spell(24531, &Refocus);
mgr->register_dummy_spell(23989, &Readiness);
}
| [
"jozsab1@gmail.com"
] | jozsab1@gmail.com |
1066acb9fc28e63f52b3adc8725addd1f30a89f3 | a018eac0dd956c963a772b1b5f3c02e6947ec425 | /file_sig/Processor.h | dd9975eb525cfc608dcf8d07170967106440bc12 | [] | no_license | alexacz/filesig-crc32 | 41a4797257dd9ec53bc61f7bdb168111e6d5edcb | b59687c0f297deb0ee7e3544518703a748ffadc7 | refs/heads/master | 2020-03-30T08:52:50.626988 | 2018-10-01T10:16:02 | 2018-10-01T10:16:02 | 151,046,713 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,413 | h | //
// Processor.h
// veeam_sig
//
// Created by Alex Nik on 30/09/2018.
//
#ifndef Processor_h
#define Processor_h
#include "Buffer.h"
extern "C" { uint32_t crc32(uint32_t, const void*, size_t); }
/**
* Calculates CRC32 of block and puts the CRC32 to ouput stream.
*/
class Processor {
Buffer& _buffer;
Writer& _writer;
public:
/**
* Constructor.
* \param buffer Reference to Buffer.
* \param writer Reference to Writer.
*/
Processor(Buffer& buffer, Writer& writer):_buffer(buffer),_writer(writer){;}
/**
* Main loop
*/
void run()
{
while (true)
{
std::shared_ptr<Buffer::Block> block;
if ( _buffer.get(block) )
{
try {
uint32_t crc = crc32(0, reinterpret_cast<const void*>( block->_data.get() ), block->_len);
_writer.add(block->_num,crc);
} catch (const std::exception& e) {
std::cout << "Processor is occurred exception: " << e.what() << std::endl;
break;
}
}
else // Last block was processed, exit from while
{
break;
}
} // while (true)
}
};
#endif /* Processor_h */
| [
""
] | |
1dbc638ff90929aca169f8f9de26d24f362cfecc | 1d4bd0305958b7cd17f7bc428dd5b6a76e6bd09f | /栈/stack/main.cpp | 3d0c337f1362439b2d834422774ef2c6468b240a | [] | no_license | oycd/data-struct | 3dfec233b79f9bc97eb5fe0c6afb0b504d27cc33 | e78b0724e603c5b4c679a66753978112e58ea39c | refs/heads/main | 2023-08-14T04:18:40.382391 | 2021-10-17T02:32:49 | 2021-10-17T02:32:49 | 409,266,710 | 0 | 0 | null | null | null | null | GB18030 | C++ | false | false | 2,113 | cpp | #include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
//栈结构
typedef struct Node{
int data;
struct Node * Pnext;
}Node,* Pnode;
typedef struct Stack{
Pnode pbottom;
Pnode ptop;
}Stack,*Pstack;
//栈操作函数
void inint(Pstack);//初始化栈
void push(Pstack,int);//入栈
void show(Pstack);//输出栈元素
bool out(Pstack);//出栈
//主函数
int main(void)
{
Stack stack;
//printf("%d \n",stack.ptop);
//printf("%d \n",stack.pbottom);
inint(&stack);
//printf("%d \n",stack.ptop);
//printf("%d \n",stack.pbottom);
/*if(stack.ptop==stack.pbottom)
{
printf("函数外相等\n");
}
else
{
printf("函数外不等\n");
}*/
push(&stack,1);
push(&stack,2);
push(&stack,3);
push(&stack,4);
push(&stack,5);
push(&stack,6);
show(&stack);
out(&stack);
show(&stack);
return 0;
}
//栈操作函数具体实现
void inint(Pstack s)
{
s->ptop=(Pnode)malloc(sizeof(Node));
if(s->ptop==NULL)
{
printf("创建栈失败!");
exit(-1);
}
else
{
s->pbottom=s->ptop;
s->ptop->Pnext=NULL;
}
}
void push(Pstack stack,int e)
{ Pnode pnew;
pnew=(Pnode)malloc(sizeof(Node));
pnew->data=e;
pnew->Pnext=stack->ptop;
stack->ptop=pnew;
}
void show(Pstack stack)
{ Pnode p;
//p=(Pnode)malloc(sizeof(Node));
p=stack->ptop;
if(p==stack->pbottom)
{
printf("该栈为空!");
}
else
{
while(p!=stack->pbottom)
{
printf("%d ",p->data);
p=p->Pnext;
}
}
printf("\n");
}
bool out(Pstack stack)
{
Pnode r;//为什么要用malloc不能直接使用?
r=stack->ptop;
if(r==stack->pbottom)
{
printf("该栈为空无法删除!\n");
return false;
}
else
{
//r->Pnext=stack->ptop;有误,如果按这句话来的话ptop并未移动,然后后面释放了r因此会出现错误!
stack->ptop=r->Pnext;
free(r);
r=NULL;
return true;
}
}
| [
"66401986+oycd@users.noreply.github.com"
] | 66401986+oycd@users.noreply.github.com |
2809c2722f51b63455f6f079fa5c1cc4ac1e649a | 8dd73f14bc0b9792925d2596868e7f2e5fe1ff96 | /src/tvheadend/utilities/LifetimeMapper.h | d678669d10a402134512d84422d90dcde11c71b8 | [] | no_license | MovistarTV/pvr.hts | 2fd5a7d3dd00682b57a15a35b7064d4e655d697f | 0b796fee78fd1f18967a727109a9d55e1adb680c | refs/heads/master | 2020-03-28T09:45:55.767202 | 2018-09-09T21:22:14 | 2018-09-09T21:22:14 | 148,058,307 | 1 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 1,650 | h | #pragma once
/*
* Copyright (C) 2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "../HTSPTypes.h"
namespace tvheadend
{
namespace utilities
{
/**
* Maps "lifetime" values from Kodi to Tvheadend and vica versa
*/
class LifetimeMapper
{
public:
static int TvhToKodi(uint32_t tvhLifetime)
{
// pvr addon api: addon defined special values must be less than zero
if (tvhLifetime == DVR_RET_SPACE)
return -2;
else if (tvhLifetime == DVR_RET_FOREVER)
return -1;
else
return tvhLifetime; // lifetime in days
}
static uint32_t KodiToTvh(int kodiLifetime)
{
if (kodiLifetime == -2)
return DVR_RET_SPACE;
else if (kodiLifetime == -1)
return DVR_RET_FOREVER;
else
return kodiLifetime; // lifetime in days
}
};
}
}
| [
"kai.sommerfeld@gmx.com"
] | kai.sommerfeld@gmx.com |
49724ce04e67d5a01d8589b604134668ad77ce1c | 767a49334113d375f96049f99e940123b4a712fd | /DevSkill_CP/Intermediate/Batch 2/Class 30/code3.cpp | ce248a18b3927b3c66cb9f9a9086feb36fd8b5d8 | [] | no_license | Sadman007/DevSkill-Programming-Course---Basic---Public-CodeBank | 9f4effbbea048f4a6919b699bc0fb1b9a0d5fef7 | d831620c44f826c3c89ca18ff95fb81ea2a2cc40 | refs/heads/master | 2023-09-01T03:44:37.609267 | 2023-08-18T19:45:41 | 2023-08-18T19:45:41 | 173,104,184 | 83 | 64 | null | null | null | null | UTF-8 | C++ | false | false | 302 | cpp | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX (ll)1e18
vector<ll>store, store2;
int main()
{
for(ll i = 1; i<=1000000 ;i++) /// i ^ 3
{
ll v = i*i*i;
store.push_back(v);
}
for(int i=0;i<10;i++) cout << store[i] << endl;
return 0;
}
| [
"sakib.csedu21@gmail.com"
] | sakib.csedu21@gmail.com |
e5b7fa6407fce22770bd191b300aee76d94b4aa3 | 78918391a7809832dc486f68b90455c72e95cdda | /boost_lib/boost/metaparse/v1/fwd/get_message.hpp | bf870e1da1e114abb89dd2148c89f5edba22b6cc | [
"MIT"
] | permissive | kyx0r/FA_Patcher | 50681e3e8bb04745bba44a71b5fd04e1004c3845 | 3f539686955249004b4483001a9e49e63c4856ff | refs/heads/master | 2022-03-28T10:03:28.419352 | 2020-01-02T09:16:30 | 2020-01-02T09:16:30 | 141,066,396 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 471 | hpp | #ifndef BOOST_METAPARSE_V1_FWD_GET_MESSAGE_HPP
#define BOOST_METAPARSE_V1_FWD_GET_MESSAGE_HPP
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
namespace boost
{
namespace metaparse
{
namespace v1
{
template <class>
struct get_message_impl;
template <class>
struct get_message;
}
}
}
#endif
| [
"k.melekhin@gmail.com"
] | k.melekhin@gmail.com |
d23ecd631edcfbf8cc972bdc9f161a43d43f150b | 30603b5a0e6fc12da18e9da0f8b87ebad9b9f1a3 | /lop_faction_racs/lop_faction_racs/CfgBackpacks.hpp | 25ed14922ff1a19dde715e16ec085c688c414e46 | [] | no_license | ElectroEsper/LOP-Esper-s-Edit | 60c40cada55bb50203bb20b4bbaf0b5e691adbb9 | adf477e8fc04e68e4f5a2fcd7aadd35e269051a4 | refs/heads/master | 2020-06-02T22:01:49.834102 | 2015-08-08T21:11:05 | 2015-08-08T21:11:05 | 40,339,611 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,475 | hpp | class B_Kitbag_rgr;
class rhsusf_falconii;
class rhs_rpg_empty;
class B_FieldPack_khk;
class LOP_AA_Kitbag_Med : B_Kitbag_rgr {
_generalMacro = "LOP_AA_Kitbag_Med";
author = $STR_LOP_FULL_NAME;
scope = 1;
class TransportItems {
class _xx_FirstAidKit {
count = 15;
name = "FirstAidKit";
};
class _xx_Medikit {
count = 1;
name = "Medikit";
};
};
};
class LOP_AA_FalconII_SVD : rhsusf_falconii {
_generalMacro = "LOP_AA_FalconII_SVD";
author = $STR_LOP_FULL_NAME;
scope = 1;
class TransportMagazines {
class _xx_rhs_10Rnd_762x54mmR_7N1 {
count = 5;
magazine = "rhs_10Rnd_762x54mmR_7N1";
};
class _xx_rhs_mag_rgd5 {
count = 2;
magazine = "HandGrenade";
};
class _xx_rhs_mag_rdg2_white {
count = 1;
magazine = "rhs_mag_rdg2_white";
};
};
};
class LOP_AA_RPG_Pack : rhs_rpg_empty {
_generalMacro = "LOP_AA_RPG_Pack";
author = $STR_LOP_FULL_NAME;
scope = 1;
class TransportMagazines {
class _xx_rhs_rpg7_PG7VR_mag {
count = 2;
magazine = "rhs_rpg7_PG7VR_mag";
};
class _xx_rhs_rpg7_PG7VL_mag {
count = 1;
magazine = "rhs_rpg7_PG7VL_mag";
};
};
};
class LOP_AA_Fieldpack_PKM : B_FieldPack_khk {
_generalMacro = "LOP_AA_Fieldpack_PKM";
author = $STR_LOP_FULL_NAME;
scope = 1;
class TransportMagazines {
class _xx_rhs_100Rnd_762x54mmR {
count = 4;
magazine = "rhs_100Rnd_762x54mmR";
};
};
}; | [
"tawesper@gmail.com"
] | tawesper@gmail.com |
4c8dd2f4c19f4de0b197d1194d3727ce0aeb84d6 | 6538e4aaab6c90e35d5472caaf9649295b0b485b | /codeforces/div228/card game.cpp | 9b3052fab554361f7aab6fceca0c5b76c19b7c56 | [] | no_license | Garvit/code-backup | 28899e22bf3ac7050ae6bfed737fecfe6e66451e | a7cbccdf817f564f664cb0b50515ed4030acac0c | refs/heads/master | 2019-01-02T00:42:56.653043 | 2015-03-04T19:24:12 | 2015-03-04T19:24:12 | 13,009,994 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 734 | cpp | #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> mid;
int main()
{
int n,s,num,csum=0,jsum=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&s);
for(int j=1;j<=s/2;j++)
{
scanf("%d",&num);
csum+=num;
}
if(s%2)
{
scanf("%d",&num);
mid.push_back(num);
}
for(int j=(s+1)/2+1;j<=s;j++)
{
scanf("%d",&num);
jsum+=num;
}
}
sort(mid.begin(),mid.end());
for(int i=mid.size()-1,c=1;i>=0;i--,c++)
{
if(c%2) csum+=mid[i];
else jsum+=mid[i];
}
printf("%d %d",csum,jsum);
}
| [
"iitgarvit@gmail.com"
] | iitgarvit@gmail.com |
d4b585ede187f1ecadfc9410bcedecb7f6357fe3 | a34fe1a599b010d5e3f75a6f7838c8ecbf998a74 | /boost/xpressive/traits/cpp_regex_traits.hpp | 72da4f0aa6c591951abb4fd3e5197264fbfe0694 | [] | no_license | flmello/4thArticleIntel | 78652a9957c507beb4b7be6d8560076211134c0c | 2c204799553a0ca85b6baf1a1ff9876254fd4800 | refs/heads/master | 2021-08-23T03:45:51.554811 | 2017-12-03T01:32:27 | 2017-12-03T01:32:27 | 112,890,564 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 26,230 | hpp | ///////////////////////////////////////////////////////////////////////////////
/// \file cpp_regex_traits.hpp
/// Contains the definition of the cpp_regex_traits\<\> template, which is a
/// wrapper for std::locale that can be used to customize the behavior of
/// static and dynamic regexes.
//
// Copyright 2008 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_XPRESSIVE_TRAITS_CPP_REGEX_TRAITS_HPP_EAN_10_04_2005
#define BOOST_XPRESSIVE_TRAITS_CPP_REGEX_TRAITS_HPP_EAN_10_04_2005
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <ios>
#include <string>
#include <locale>
#include <sstream>
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/integer.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/xpressive/detail/detail_fwd.hpp>
#include <boost/xpressive/detail/utility/literals.hpp>
// From John Maddock:
// Fix for gcc prior to 3.4: std::ctype<wchar_t> doesn't allow masks to be combined, for example:
// std::use_facet<std::ctype<wchar_t> >(locale()).is(std::ctype_base::lower|std::ctype_base::upper, L'a');
// incorrectly returns false.
// NOTE: later version of the gcc define __GLIBCXX__, not __GLIBCPP__
#if BOOST_WORKAROUND(__GLIBCPP__, != 0)
# define BOOST_XPRESSIVE_BUGGY_CTYPE_FACET
#endif
namespace boost { namespace xpressive
{
namespace detail
{
// define an unsigned integral typedef of the same size as std::ctype_base::mask
typedef boost::uint_t<sizeof(std::ctype_base::mask) * CHAR_BIT>::least umask_t;
BOOST_MPL_ASSERT_RELATION(sizeof(std::ctype_base::mask), ==, sizeof(umask_t));
// Calculate what the size of the umaskex_t type should be to fix the 3 extra bitmasks
// 11 char categories in ctype_base
// + 3 extra categories for xpressive
// = 14 total bits needed
int const umaskex_bits = (14 > (sizeof(umask_t) * CHAR_BIT)) ? 14 : sizeof(umask_t) * CHAR_BIT;
// define an unsigned integral type with at least umaskex_bits
typedef boost::uint_t<umaskex_bits>::fast umaskex_t;
BOOST_MPL_ASSERT_RELATION(sizeof(umask_t), <=, sizeof(umaskex_t));
// cast a ctype mask to a umaskex_t
template<std::ctype_base::mask Mask>
struct mask_cast
{
BOOST_STATIC_CONSTANT(umaskex_t, value = static_cast<umask_t>(Mask));
};
#ifdef __CYGWIN__
// Work around a gcc warning on cygwin
template<>
struct mask_cast<std::ctype_base::print>
{
BOOST_MPL_ASSERT_RELATION('\227', ==, std::ctype_base::print);
BOOST_STATIC_CONSTANT(umaskex_t, value = 0227);
};
#endif
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
template<std::ctype_base::mask Mask>
umaskex_t const mask_cast<Mask>::value;
#endif
#ifndef BOOST_XPRESSIVE_BUGGY_CTYPE_FACET
// an unsigned integer with the highest bit set
umaskex_t const highest_bit = 1 << (sizeof(umaskex_t) * CHAR_BIT - 1);
///////////////////////////////////////////////////////////////////////////////
// unused_mask
// find a bit in an int that isn't set
template<umaskex_t In, umaskex_t Out = highest_bit, bool Done = (0 == (Out & In))>
struct unused_mask
{
BOOST_MPL_ASSERT_RELATION(1, !=, Out);
BOOST_STATIC_CONSTANT(umaskex_t, value = (unused_mask<In, (Out >> 1)>::value));
};
template<umaskex_t In, umaskex_t Out>
struct unused_mask<In, Out, true>
{
BOOST_STATIC_CONSTANT(umaskex_t, value = Out);
};
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
template<umaskex_t In, umaskex_t Out, bool Done>
umaskex_t const unused_mask<In, Out, Done>::value;
#endif
umaskex_t const std_ctype_alnum = mask_cast<std::ctype_base::alnum>::value;
umaskex_t const std_ctype_alpha = mask_cast<std::ctype_base::alpha>::value;
umaskex_t const std_ctype_cntrl = mask_cast<std::ctype_base::cntrl>::value;
umaskex_t const std_ctype_digit = mask_cast<std::ctype_base::digit>::value;
umaskex_t const std_ctype_graph = mask_cast<std::ctype_base::graph>::value;
umaskex_t const std_ctype_lower = mask_cast<std::ctype_base::lower>::value;
umaskex_t const std_ctype_print = mask_cast<std::ctype_base::print>::value;
umaskex_t const std_ctype_punct = mask_cast<std::ctype_base::punct>::value;
umaskex_t const std_ctype_space = mask_cast<std::ctype_base::space>::value;
umaskex_t const std_ctype_upper = mask_cast<std::ctype_base::upper>::value;
umaskex_t const std_ctype_xdigit = mask_cast<std::ctype_base::xdigit>::value;
// Reserve some bits for the implementation
#if defined(__GLIBCXX__)
umaskex_t const std_ctype_reserved = 0x8000;
#elif defined(_CPPLIB_VER) && defined(BOOST_WINDOWS)
umaskex_t const std_ctype_reserved = 0x8200;
#else
umaskex_t const std_ctype_reserved = 0;
#endif
// Bitwise-or all the ctype masks together
umaskex_t const all_ctype_masks = std_ctype_reserved
| std_ctype_alnum | std_ctype_alpha | std_ctype_cntrl | std_ctype_digit
| std_ctype_graph | std_ctype_lower | std_ctype_print | std_ctype_punct
| std_ctype_space | std_ctype_upper | std_ctype_xdigit;
// define a new mask for "underscore" ("word" == alnum | underscore)
umaskex_t const non_std_ctype_underscore = unused_mask<all_ctype_masks>::value;
// define a new mask for "blank"
umaskex_t const non_std_ctype_blank = unused_mask<all_ctype_masks | non_std_ctype_underscore>::value;
// define a new mask for "newline"
umaskex_t const non_std_ctype_newline = unused_mask<all_ctype_masks | non_std_ctype_underscore | non_std_ctype_blank>::value;
#else
///////////////////////////////////////////////////////////////////////////////
// Ugly work-around for buggy ctype facets.
umaskex_t const std_ctype_alnum = 1 << 0;
umaskex_t const std_ctype_alpha = 1 << 1;
umaskex_t const std_ctype_cntrl = 1 << 2;
umaskex_t const std_ctype_digit = 1 << 3;
umaskex_t const std_ctype_graph = 1 << 4;
umaskex_t const std_ctype_lower = 1 << 5;
umaskex_t const std_ctype_print = 1 << 6;
umaskex_t const std_ctype_punct = 1 << 7;
umaskex_t const std_ctype_space = 1 << 8;
umaskex_t const std_ctype_upper = 1 << 9;
umaskex_t const std_ctype_xdigit = 1 << 10;
umaskex_t const non_std_ctype_underscore = 1 << 11;
umaskex_t const non_std_ctype_blank = 1 << 12;
umaskex_t const non_std_ctype_newline = 1 << 13;
static umaskex_t const std_masks[] =
{
mask_cast<std::ctype_base::alnum>::value
, mask_cast<std::ctype_base::alpha>::value
, mask_cast<std::ctype_base::cntrl>::value
, mask_cast<std::ctype_base::digit>::value
, mask_cast<std::ctype_base::graph>::value
, mask_cast<std::ctype_base::lower>::value
, mask_cast<std::ctype_base::print>::value
, mask_cast<std::ctype_base::punct>::value
, mask_cast<std::ctype_base::space>::value
, mask_cast<std::ctype_base::upper>::value
, mask_cast<std::ctype_base::xdigit>::value
};
inline int mylog2(umaskex_t i)
{
return "\0\0\1\0\2\0\0\0\3"[i & 0xf]
+ "\0\4\5\0\6\0\0\0\7"[(i & 0xf0) >> 04]
+ "\0\10\11\0\12\0\0\0\13"[(i & 0xf00) >> 010];
}
#endif
// convenient constant for the extra masks
umaskex_t const non_std_ctype_masks = non_std_ctype_underscore | non_std_ctype_blank | non_std_ctype_newline;
///////////////////////////////////////////////////////////////////////////////
// cpp_regex_traits_base
// BUGBUG this should be replaced with a regex facet that lets you query for
// an array of underscore characters and an array of line separator characters.
template<typename Char, std::size_t SizeOfChar = sizeof(Char)>
struct cpp_regex_traits_base
{
protected:
void imbue(std::locale const &)
{
}
static bool is(std::ctype<Char> const &ct, Char ch, umaskex_t mask)
{
#ifndef BOOST_XPRESSIVE_BUGGY_CTYPE_FACET
if(ct.is((std::ctype_base::mask)(umask_t)mask, ch))
{
return true;
}
#else
umaskex_t tmp = mask & ~non_std_ctype_masks;
for(umaskex_t i; 0 != (i = (tmp & (~tmp+1))); tmp &= ~i)
{
std::ctype_base::mask m = (std::ctype_base::mask)(umask_t)std_masks[mylog2(i)];
if(ct.is(m, ch))
{
return true;
}
}
#endif
return ((mask & non_std_ctype_blank) && cpp_regex_traits_base::is_blank(ch))
|| ((mask & non_std_ctype_underscore) && cpp_regex_traits_base::is_underscore(ch))
|| ((mask & non_std_ctype_newline) && cpp_regex_traits_base::is_newline(ch));
}
private:
static bool is_blank(Char ch)
{
BOOST_MPL_ASSERT_RELATION('\t', ==, L'\t');
BOOST_MPL_ASSERT_RELATION(' ', ==, L' ');
return L' ' == ch || L'\t' == ch;
}
static bool is_underscore(Char ch)
{
BOOST_MPL_ASSERT_RELATION('_', ==, L'_');
return L'_' == ch;
}
static bool is_newline(Char ch)
{
BOOST_MPL_ASSERT_RELATION('\r', ==, L'\r');
BOOST_MPL_ASSERT_RELATION('\n', ==, L'\n');
BOOST_MPL_ASSERT_RELATION('\f', ==, L'\f');
return L'\r' == ch || L'\n' == ch || L'\f' == ch
|| (1 < SizeOfChar && (0x2028u == ch || 0x2029u == ch || 0x85u == ch));
}
};
#ifndef BOOST_XPRESSIVE_BUGGY_CTYPE_FACET
template<typename Char>
struct cpp_regex_traits_base<Char, 1>
{
protected:
void imbue(std::locale const &loc)
{
int i = 0;
Char allchars[UCHAR_MAX + 1];
for(i = 0; i <= UCHAR_MAX; ++i)
{
allchars[i] = static_cast<Char>(i);
}
std::ctype<Char> const &ct = BOOST_USE_FACET(std::ctype<Char>, loc);
std::ctype_base::mask tmp[UCHAR_MAX + 1];
ct.is(allchars, allchars + UCHAR_MAX + 1, tmp);
for(i = 0; i <= UCHAR_MAX; ++i)
{
this->masks_[i] = static_cast<umask_t>(tmp[i]);
BOOST_ASSERT(0 == (this->masks_[i] & non_std_ctype_masks));
}
this->masks_[static_cast<unsigned char>('_')] |= non_std_ctype_underscore;
this->masks_[static_cast<unsigned char>(' ')] |= non_std_ctype_blank;
this->masks_[static_cast<unsigned char>('\t')] |= non_std_ctype_blank;
this->masks_[static_cast<unsigned char>('\n')] |= non_std_ctype_newline;
this->masks_[static_cast<unsigned char>('\r')] |= non_std_ctype_newline;
this->masks_[static_cast<unsigned char>('\f')] |= non_std_ctype_newline;
}
bool is(std::ctype<Char> const &, Char ch, umaskex_t mask) const
{
return 0 != (this->masks_[static_cast<unsigned char>(ch)] & mask);
}
private:
umaskex_t masks_[UCHAR_MAX + 1];
};
#endif
} // namespace detail
///////////////////////////////////////////////////////////////////////////////
// cpp_regex_traits
//
/// \brief Encapsaulates a std::locale for use by the
/// basic_regex\<\> class template.
template<typename Char>
struct cpp_regex_traits
: detail::cpp_regex_traits_base<Char>
{
typedef Char char_type;
typedef std::basic_string<char_type> string_type;
typedef std::locale locale_type;
typedef detail::umaskex_t char_class_type;
typedef regex_traits_version_2_tag version_tag;
typedef detail::cpp_regex_traits_base<Char> base_type;
/// Initialize a cpp_regex_traits object to use the specified std::locale,
/// or the global std::locale if none is specified.
///
cpp_regex_traits(locale_type const &loc = locale_type())
: base_type()
, loc_()
{
this->imbue(loc);
}
/// Checks two cpp_regex_traits objects for equality
///
/// \return this->getloc() == that.getloc().
bool operator ==(cpp_regex_traits<char_type> const &that) const
{
return this->loc_ == that.loc_;
}
/// Checks two cpp_regex_traits objects for inequality
///
/// \return this->getloc() != that.getloc().
bool operator !=(cpp_regex_traits<char_type> const &that) const
{
return this->loc_ != that.loc_;
}
/// Convert a char to a Char
///
/// \param ch The source character.
/// \return std::use_facet\<std::ctype\<char_type\> \>(this->getloc()).widen(ch).
char_type widen(char ch) const
{
return this->ctype_->widen(ch);
}
/// Returns a hash value for a Char in the range [0, UCHAR_MAX]
///
/// \param ch The source character.
/// \return a value between 0 and UCHAR_MAX, inclusive.
static unsigned char hash(char_type ch)
{
return static_cast<unsigned char>(std::char_traits<Char>::to_int_type(ch));
}
/// No-op
///
/// \param ch The source character.
/// \return ch
static char_type translate(char_type ch)
{
return ch;
}
/// Converts a character to lower-case using the internally-stored std::locale.
///
/// \param ch The source character.
/// \return std::tolower(ch, this->getloc()).
char_type translate_nocase(char_type ch) const
{
return this->ctype_->tolower(ch);
}
/// Converts a character to lower-case using the internally-stored std::locale.
///
/// \param ch The source character.
/// \return std::tolower(ch, this->getloc()).
char_type tolower(char_type ch) const
{
return this->ctype_->tolower(ch);
}
/// Converts a character to upper-case using the internally-stored std::locale.
///
/// \param ch The source character.
/// \return std::toupper(ch, this->getloc()).
char_type toupper(char_type ch) const
{
return this->ctype_->toupper(ch);
}
/// Returns a string_type containing all the characters that compare equal
/// disregrarding case to the one passed in. This function can only be called
/// if has_fold_case\<cpp_regex_traits\<Char\> \>::value is true.
///
/// \param ch The source character.
/// \return string_type containing all chars which are equal to ch when disregarding
/// case
string_type fold_case(char_type ch) const
{
BOOST_MPL_ASSERT((is_same<char_type, char>));
char_type ntcs[] = {
this->ctype_->tolower(ch)
, this->ctype_->toupper(ch)
, 0
};
if(ntcs[1] == ntcs[0])
ntcs[1] = 0;
return string_type(ntcs);
}
/// Checks to see if a character is within a character range.
///
/// \param first The bottom of the range, inclusive.
/// \param last The top of the range, inclusive.
/// \param ch The source character.
/// \return first <= ch && ch <= last.
static bool in_range(char_type first, char_type last, char_type ch)
{
return first <= ch && ch <= last;
}
/// Checks to see if a character is within a character range, irregardless of case.
///
/// \param first The bottom of the range, inclusive.
/// \param last The top of the range, inclusive.
/// \param ch The source character.
/// \return in_range(first, last, ch) || in_range(first, last, tolower(ch, this->getloc())) ||
/// in_range(first, last, toupper(ch, this->getloc()))
/// \attention The default implementation doesn't do proper Unicode
/// case folding, but this is the best we can do with the standard
/// ctype facet.
bool in_range_nocase(char_type first, char_type last, char_type ch) const
{
// NOTE: this default implementation doesn't do proper Unicode
// case folding, but this is the best we can do with the standard
// std::ctype facet.
return this->in_range(first, last, ch)
|| this->in_range(first, last, this->ctype_->toupper(ch))
|| this->in_range(first, last, this->ctype_->tolower(ch));
}
/// INTERNAL ONLY
//string_type transform(char_type const *begin, char_type const *end) const
//{
// return this->collate_->transform(begin, end);
//}
/// Returns a sort key for the character sequence designated by the iterator range [F1, F2)
/// such that if the character sequence [G1, G2) sorts before the character sequence [H1, H2)
/// then v.transform(G1, G2) \< v.transform(H1, H2).
///
/// \attention Not currently used
template<typename FwdIter>
string_type transform(FwdIter begin, FwdIter end) const
{
//string_type str(begin, end);
//return this->transform(str.data(), str.data() + str.size());
BOOST_ASSERT(false);
return string_type();
}
/// Returns a sort key for the character sequence designated by the iterator range [F1, F2)
/// such that if the character sequence [G1, G2) sorts before the character sequence [H1, H2)
/// when character case is not considered then
/// v.transform_primary(G1, G2) \< v.transform_primary(H1, H2).
///
/// \attention Not currently used
template<typename FwdIter>
string_type transform_primary(FwdIter begin, FwdIter end) const
{
BOOST_ASSERT(false); // TODO implement me
return string_type();
}
/// Returns a sequence of characters that represents the collating element
/// consisting of the character sequence designated by the iterator range [F1, F2).
/// Returns an empty string if the character sequence is not a valid collating element.
///
/// \attention Not currently used
template<typename FwdIter>
string_type lookup_collatename(FwdIter begin, FwdIter end) const
{
BOOST_ASSERT(false); // TODO implement me
return string_type();
}
/// For the character class name represented by the specified character sequence,
/// return the corresponding bitmask representation.
///
/// \param begin A forward iterator to the start of the character sequence representing
/// the name of the character class.
/// \param end The end of the character sequence.
/// \param icase Specifies whether the returned bitmask should represent the case-insensitive
/// version of the character class.
/// \return A bitmask representing the character class.
template<typename FwdIter>
char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase) const
{
static detail::umaskex_t const icase_masks =
detail::std_ctype_lower | detail::std_ctype_upper;
BOOST_ASSERT(begin != end);
char_class_type char_class = this->lookup_classname_impl_(begin, end);
if(0 == char_class)
{
// convert the string to lowercase
string_type classname(begin, end);
for(typename string_type::size_type i = 0, len = classname.size(); i < len; ++i)
{
classname[i] = this->translate_nocase(classname[i]);
}
char_class = this->lookup_classname_impl_(classname.begin(), classname.end());
}
// erase case-sensitivity if icase==true
if(icase && 0 != (char_class & icase_masks))
{
char_class |= icase_masks;
}
return char_class;
}
/// Tests a character against a character class bitmask.
///
/// \param ch The character to test.
/// \param mask The character class bitmask against which to test.
/// \pre mask is a bitmask returned by lookup_classname, or is several such masks bit-or'ed
/// together.
/// \return true if the character is a member of any of the specified character classes, false
/// otherwise.
bool isctype(char_type ch, char_class_type mask) const
{
return this->base_type::is(*this->ctype_, ch, mask);
}
/// Convert a digit character into the integer it represents.
///
/// \param ch The digit character.
/// \param radix The radix to use for the conversion.
/// \pre radix is one of 8, 10, or 16.
/// \return -1 if ch is not a digit character, the integer value of the character otherwise.
/// The conversion is performed by imbueing a std::stringstream with this-\>getloc();
/// setting the radix to one of oct, hex or dec; inserting ch into the stream; and
/// extracting an int.
int value(char_type ch, int radix) const
{
BOOST_ASSERT(8 == radix || 10 == radix || 16 == radix);
int val = -1;
std::basic_stringstream<char_type> str;
str.imbue(this->getloc());
str << (8 == radix ? std::oct : (16 == radix ? std::hex : std::dec));
str.put(ch);
str >> val;
return str.fail() ? -1 : val;
}
/// Imbues *this with loc
///
/// \param loc A std::locale.
/// \return the previous std::locale used by *this.
locale_type imbue(locale_type loc)
{
locale_type old_loc = this->loc_;
this->loc_ = loc;
this->ctype_ = &BOOST_USE_FACET(std::ctype<char_type>, this->loc_);
//this->collate_ = &BOOST_USE_FACET(std::collate<char_type>, this->loc_);
this->base_type::imbue(this->loc_);
return old_loc;
}
/// Returns the current std::locale used by *this.
///
locale_type getloc() const
{
return this->loc_;
}
private:
///////////////////////////////////////////////////////////////////////////////
// char_class_pair
/// INTERNAL ONLY
struct char_class_pair
{
char_type const *class_name_;
char_class_type class_type_;
};
///////////////////////////////////////////////////////////////////////////////
// char_class
/// INTERNAL ONLY
static char_class_pair const &char_class(std::size_t j)
{
static char_class_pair const s_char_class_map[] =
{
{ BOOST_XPR_CSTR_(char_type, "alnum"), detail::std_ctype_alnum }
, { BOOST_XPR_CSTR_(char_type, "alpha"), detail::std_ctype_alpha }
, { BOOST_XPR_CSTR_(char_type, "blank"), detail::non_std_ctype_blank }
, { BOOST_XPR_CSTR_(char_type, "cntrl"), detail::std_ctype_cntrl }
, { BOOST_XPR_CSTR_(char_type, "d"), detail::std_ctype_digit }
, { BOOST_XPR_CSTR_(char_type, "digit"), detail::std_ctype_digit }
, { BOOST_XPR_CSTR_(char_type, "graph"), detail::std_ctype_graph }
, { BOOST_XPR_CSTR_(char_type, "lower"), detail::std_ctype_lower }
, { BOOST_XPR_CSTR_(char_type, "newline"),detail::non_std_ctype_newline }
, { BOOST_XPR_CSTR_(char_type, "print"), detail::std_ctype_print }
, { BOOST_XPR_CSTR_(char_type, "punct"), detail::std_ctype_punct }
, { BOOST_XPR_CSTR_(char_type, "s"), detail::std_ctype_space }
, { BOOST_XPR_CSTR_(char_type, "space"), detail::std_ctype_space }
, { BOOST_XPR_CSTR_(char_type, "upper"), detail::std_ctype_upper }
, { BOOST_XPR_CSTR_(char_type, "w"), detail::std_ctype_alnum | detail::non_std_ctype_underscore }
, { BOOST_XPR_CSTR_(char_type, "xdigit"), detail::std_ctype_xdigit }
, { 0, 0 }
};
return s_char_class_map[j];
}
///////////////////////////////////////////////////////////////////////////////
// lookup_classname_impl
/// INTERNAL ONLY
template<typename FwdIter>
static char_class_type lookup_classname_impl_(FwdIter begin, FwdIter end)
{
// find the classname
typedef cpp_regex_traits<Char> this_t;
for(std::size_t j = 0; 0 != this_t::char_class(j).class_name_; ++j)
{
if(this_t::compare_(this_t::char_class(j).class_name_, begin, end))
{
return this_t::char_class(j).class_type_;
}
}
return 0;
}
/// INTERNAL ONLY
template<typename FwdIter>
static bool compare_(char_type const *name, FwdIter begin, FwdIter end)
{
for(; *name && begin != end; ++name, ++begin)
{
if(*name != *begin)
{
return false;
}
}
return !*name && begin == end;
}
locale_type loc_;
std::ctype<char_type> const *ctype_;
//std::collate<char_type> const *collate_;
};
///////////////////////////////////////////////////////////////////////////////
// cpp_regex_traits<>::hash specializations
template<>
inline unsigned char cpp_regex_traits<unsigned char>::hash(unsigned char ch)
{
return ch;
}
template<>
inline unsigned char cpp_regex_traits<char>::hash(char ch)
{
return static_cast<unsigned char>(ch);
}
template<>
inline unsigned char cpp_regex_traits<signed char>::hash(signed char ch)
{
return static_cast<unsigned char>(ch);
}
#ifndef BOOST_XPRESSIVE_NO_WREGEX
template<>
inline unsigned char cpp_regex_traits<wchar_t>::hash(wchar_t ch)
{
return static_cast<unsigned char>(ch);
}
#endif
// Narrow C++ traits has fold_case() member function.
template<>
struct has_fold_case<cpp_regex_traits<char> >
: mpl::true_
{
};
}}
#endif
| [
"flavioluis.mello@gmail.com"
] | flavioluis.mello@gmail.com |
f111e7e3452c9dfdd94254a506e33bb73399f7b0 | 0a085d72288de171756e24d5484992aebcb67277 | /hzd_test/HRZ/Core/CameraEntity.h | 0209a0ff0a1560864697f62b0e72d37a2f28b8c0 | [] | no_license | spammydavis/HZDCoreEditor | 3bb44ae1b582a1e41e075b6a22e0734ebefe0271 | bb4507b40eee906563e0c51e21eb404388aff35a | refs/heads/master | 2023-08-20T21:23:29.556634 | 2021-10-30T09:31:02 | 2021-10-30T09:31:02 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,339 | h | #pragma once
#include "../PCore/Common.h"
#include "Entity.h"
namespace HRZ
{
DECL_RTTI(CameraEntity);
DECL_RTTI(CameraEntityRep);
DECL_RTTI(CameraEntityResource);
class CameraEntityResource : public EntityResource
{
public:
TYPE_RTTI(CameraEntityResource);
char _pad130[0xA8];
virtual const RTTI *GetRTTI() const override; // 0
virtual ~CameraEntityResource() override; // 1
virtual const RTTI *GetInstanceRTTI() const override; // 18
virtual const RTTI *GetRepRTTI() const override; // 19
virtual const RTTI *GetNetRTTI() const override; // 20
virtual Entity *CreateInstance(const WorldTransform& Transform) override; // 21
virtual void CameraEntityResourceUnknown28(); // 28
virtual void CameraEntityResourceUnknown29(); // 29
};
assert_size(CameraEntityResource, 0x1D8);
class CameraEntityRep : public EntityRep
{
TYPE_RTTI(CameraEntityRep);
};
class CameraEntity : public Entity
{
public:
TYPE_RTTI(CameraEntity);
char _pad2C0[0x84];
float m_FOV; // 0x344
char _pad34C[0x28];
float m_NearFuzzy; // 0x370
float m_NearSharp; // 0x374
float m_FarFuzzy; // 0x378
float m_FarSharp; // 0x37C
float m_MaxFuzzyNear; // 0x380
float m_MaxFuzzyFar; // 0x384
char _pad388[0x2C];
float m_NearPlane; // 0x3B4
float m_FarPlane; // 0x3B8
float m_StereoDepth; // 0x3BC
char _pad3C0[0xB0];
virtual const RTTI *GetRTTI() const override; // 0
virtual ~CameraEntity() override; // 1
virtual void SetResource(EntityResource *Resource) override; // 19
virtual void EntityUnknown29() override; // 29
virtual void EntityUnknown30() override; // 30
virtual class Player *IsPlayer() override; // 31
virtual void CameraEntityUnknown39(); // 39
virtual void CameraEntityUnknown40(); // 40
virtual void CameraEntityUnknown41(); // 41
virtual void CameraEntityUnknown42(); // 42
virtual void CameraEntityUnknown43(); // 43
virtual void CameraEntityUnknown44(); // 44
virtual void CameraEntityUnknown45(); // 45
virtual void CameraEntityUnknown46(); // 46
virtual void CameraEntityUnknown47(); // 47
};
assert_offset(CameraEntity, m_FOV, 0x344);
assert_offset(CameraEntity, m_NearFuzzy, 0x370);
assert_offset(CameraEntity, m_NearPlane, 0x3B4);
assert_size(CameraEntity, 0x470);
} | [
"Nukem@outlook.com"
] | Nukem@outlook.com |
43226a97d36dd9cd8eaaa372b389aa6aefaef353 | e52a624b75449dd21dd11be4f966b760d377e9ed | /RateLimitSvc.cpp | bd899f9c8e0f958ae2ffad094d5f47be6fd48f1b | [
"MIT"
] | permissive | jgaa/ratelimit-poc | 942e7b6a676ded3c9d296c108f20aa57f230b42b | de7b56e7e86f1c240f75a943a7773cf9a1a672e5 | refs/heads/master | 2022-12-25T19:16:50.945972 | 2020-09-23T15:25:30 | 2020-09-23T15:25:30 | 298,008,959 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 46 | cpp | #include "RateLimitSvc.h"
namespace rl {
}
| [
"jarle@jgaa.com"
] | jarle@jgaa.com |
41f6ecd3bfaef72f42112035587219a8b689dd62 | 7b379862f58f587d9327db829ae4c6493b745bb1 | /JuceLibraryCode/modules/juce_graphics/fonts/juce_TextLayout.cpp | be3a8ac66be9d6a05e9f52ad505853fbc05b11d6 | [] | no_license | owenvallis/Nomestate | 75e844e8ab68933d481640c12019f0d734c62065 | 7fe7c06c2893421a3c77b5180e5f27ab61dd0ffd | refs/heads/master | 2021-01-19T07:35:14.301832 | 2011-12-28T07:42:50 | 2011-12-28T07:42:50 | 2,950,072 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 20,576 | cpp | /*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-11 by Raw Material Software Ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the GNU General
Public License (Version 2), as published by the Free Software Foundation.
A copy of the license is included in the JUCE distribution, or can be found
online at www.gnu.org/licenses.
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------
To release a closed-source product which uses JUCE, commercial licenses are
available: visit www.rawmaterialsoftware.com/juce for more information.
==============================================================================
*/
BEGIN_JUCE_NAMESPACE
TextLayout::Glyph::Glyph (const int glyphCode_, const Point<float>& anchor_, float width_) noexcept
: glyphCode (glyphCode_), anchor (anchor_), width (width_)
{
}
TextLayout::Glyph::Glyph (const Glyph& other) noexcept
: glyphCode (other.glyphCode), anchor (other.anchor), width (other.width)
{
}
TextLayout::Glyph& TextLayout::Glyph::operator= (const Glyph& other) noexcept
{
glyphCode = other.glyphCode;
anchor = other.anchor;
width = other.width;
return *this;
}
TextLayout::Glyph::~Glyph() noexcept {}
//==============================================================================
TextLayout::Run::Run() noexcept
: colour (0xff000000)
{
}
TextLayout::Run::Run (const Range<int>& range, const int numGlyphsToPreallocate)
: colour (0xff000000), stringRange (range)
{
glyphs.ensureStorageAllocated (numGlyphsToPreallocate);
}
TextLayout::Run::Run (const Run& other)
: font (other.font),
colour (other.colour),
glyphs (other.glyphs),
stringRange (other.stringRange)
{
}
TextLayout::Run::~Run() noexcept {}
//==============================================================================
TextLayout::Line::Line() noexcept
: ascent (0.0f), descent (0.0f), leading (0.0f)
{
}
TextLayout::Line::Line (const Range<int>& stringRange_, const Point<float>& lineOrigin_,
const float ascent_, const float descent_, const float leading_,
const int numRunsToPreallocate)
: stringRange (stringRange_), lineOrigin (lineOrigin_),
ascent (ascent_), descent (descent_), leading (leading_)
{
runs.ensureStorageAllocated (numRunsToPreallocate);
}
TextLayout::Line::Line (const Line& other)
: stringRange (other.stringRange), lineOrigin (other.lineOrigin),
ascent (other.ascent), descent (other.descent), leading (other.leading)
{
runs.addCopiesOf (other.runs);
}
TextLayout::Line::~Line() noexcept
{
}
Range<float> TextLayout::Line::getLineBoundsX() const noexcept
{
Range<float> range;
bool isFirst = true;
for (int i = runs.size(); --i >= 0;)
{
const Run* run = runs.getUnchecked(i);
jassert (run != nullptr);
if (run->glyphs.size() > 0)
{
float minX = run->glyphs.getReference(0).anchor.x;
float maxX = minX;
for (int j = run->glyphs.size(); --j > 0;)
{
const Glyph& glyph = run->glyphs.getReference (j);
const float x = glyph.anchor.x;
minX = jmin (minX, x);
maxX = jmax (maxX, x + glyph.width);
}
if (isFirst)
{
isFirst = false;
range = Range<float> (minX, maxX);
}
else
{
range = range.getUnionWith (Range<float> (minX, maxX));
}
}
}
return range + lineOrigin.x;
}
//==============================================================================
TextLayout::TextLayout()
: width (0), justification (Justification::topLeft)
{
}
TextLayout::TextLayout (const TextLayout& other)
: width (other.width),
justification (other.justification)
{
lines.addCopiesOf (other.lines);
}
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
TextLayout::TextLayout (TextLayout&& other) noexcept
: lines (static_cast <OwnedArray<Line>&&> (other.lines)),
width (other.width),
justification (other.justification)
{
}
TextLayout& TextLayout::operator= (TextLayout&& other) noexcept
{
lines = static_cast <OwnedArray<Line>&&> (other.lines);
width = other.width;
justification = other.justification;
return *this;
}
#endif
TextLayout& TextLayout::operator= (const TextLayout& other)
{
width = other.width;
justification = other.justification;
lines.clear();
lines.addCopiesOf (other.lines);
return *this;
}
TextLayout::~TextLayout()
{
}
float TextLayout::getHeight() const noexcept
{
const Line* const lastLine = lines.getLast();
return lastLine != nullptr ? lastLine->lineOrigin.y + lastLine->descent
: 0;
}
TextLayout::Line& TextLayout::getLine (const int index) const
{
return *lines[index];
}
void TextLayout::ensureStorageAllocated (int numLinesNeeded)
{
lines.ensureStorageAllocated (numLinesNeeded);
}
void TextLayout::addLine (Line* line)
{
lines.add (line);
}
void TextLayout::draw (Graphics& g, const Rectangle<float>& area) const
{
const Point<float> origin (justification.appliedToRectangle (Rectangle<float> (0, 0, width, getHeight()), area).getPosition());
LowLevelGraphicsContext& context = *g.getInternalContext();
for (int i = 0; i < getNumLines(); ++i)
{
const Line& line = getLine (i);
const Point<float> lineOrigin (origin + line.lineOrigin);
for (int j = 0; j < line.runs.size(); ++j)
{
const Run* const run = line.runs.getUnchecked (j);
jassert (run != nullptr);
context.setFont (run->font);
context.setFill (run->colour);
for (int k = 0; k < run->glyphs.size(); ++k)
{
const Glyph& glyph = run->glyphs.getReference (k);
context.drawGlyph (glyph.glyphCode, AffineTransform::translation (lineOrigin.x + glyph.anchor.x,
lineOrigin.y + glyph.anchor.y));
}
}
}
}
void TextLayout::createLayout (const AttributedString& text, float maxWidth)
{
lines.clear();
width = maxWidth;
justification = text.getJustification();
if (! createNativeLayout (text))
createStandardLayout (text);
recalculateWidth();
}
//==============================================================================
namespace TextLayoutHelpers
{
struct FontAndColour
{
FontAndColour (const Font* font_) noexcept : font (font_), colour (0xff000000) {}
const Font* font;
Colour colour;
bool operator!= (const FontAndColour& other) const noexcept
{
return (font != other.font && *font != *other.font) || colour != other.colour;
}
};
struct RunAttribute
{
RunAttribute (const FontAndColour& fontAndColour_, const Range<int>& range_) noexcept
: fontAndColour (fontAndColour_), range (range_)
{}
FontAndColour fontAndColour;
Range<int> range;
};
struct Token
{
Token (const String& t, const Font& f, const Colour& c, const bool isWhitespace_)
: text (t), font (f), colour (c),
area (font.getStringWidth (t), roundToInt (f.getHeight())),
isWhitespace (isWhitespace_),
isNewLine (t.containsChar ('\n') || t.containsChar ('\r'))
{}
const String text;
const Font font;
const Colour colour;
Rectangle<int> area;
int line, lineHeight;
const bool isWhitespace, isNewLine;
private:
Token& operator= (const Token&);
};
class TokenList
{
public:
TokenList() noexcept : totalLines (0) {}
void createLayout (const AttributedString& text, TextLayout& layout)
{
tokens.ensureStorageAllocated (64);
layout.ensureStorageAllocated (totalLines);
addTextRuns (text);
layoutRuns ((int) layout.getWidth());
int charPosition = 0;
int lineStartPosition = 0;
int runStartPosition = 0;
TextLayout::Line* glyphLine = new TextLayout::Line();
TextLayout::Run* glyphRun = new TextLayout::Run();
for (int i = 0; i < tokens.size(); ++i)
{
const Token* const t = tokens.getUnchecked (i);
const Point<float> tokenPos (t->area.getPosition().toFloat());
Array <int> newGlyphs;
Array <float> xOffsets;
t->font.getGlyphPositions (t->text.trimEnd(), newGlyphs, xOffsets);
glyphRun->glyphs.ensureStorageAllocated (glyphRun->glyphs.size() + newGlyphs.size());
for (int j = 0; j < newGlyphs.size(); ++j)
{
if (charPosition == lineStartPosition)
glyphLine->lineOrigin = tokenPos.translated (0, t->font.getAscent());
const float x = xOffsets.getUnchecked (j);
glyphRun->glyphs.add (TextLayout::Glyph (newGlyphs.getUnchecked(j),
Point<float> (tokenPos.getX() + x, 0),
xOffsets.getUnchecked (j + 1) - x));
++charPosition;
}
if (t->isWhitespace || t->isNewLine)
++charPosition;
const Token* const nextToken = tokens [i + 1];
if (nextToken == nullptr) // this is the last token
{
addRun (glyphLine, glyphRun, t, runStartPosition, charPosition);
glyphLine->stringRange = Range<int> (lineStartPosition, charPosition);
layout.addLine (glyphLine);
}
else
{
if (t->font != nextToken->font || t->colour != nextToken->colour)
{
addRun (glyphLine, glyphRun, t, runStartPosition, charPosition);
runStartPosition = charPosition;
glyphRun = new TextLayout::Run();
}
if (t->line != nextToken->line)
{
addRun (glyphLine, glyphRun, t, runStartPosition, charPosition);
glyphLine->stringRange = Range<int> (lineStartPosition, charPosition);
layout.addLine (glyphLine);
runStartPosition = charPosition;
lineStartPosition = charPosition;
glyphLine = new TextLayout::Line();
glyphRun = new TextLayout::Run();
}
}
}
if ((text.getJustification().getFlags() & (Justification::right | Justification::horizontallyCentred)) != 0)
{
const int totalW = (int) layout.getWidth();
for (int i = 0; i < layout.getNumLines(); ++i)
{
const int lineW = getLineWidth (i);
float dx = 0;
if ((text.getJustification().getFlags() & Justification::right) != 0)
dx = (float) (totalW - lineW);
else
dx = (totalW - lineW) / 2.0f;
TextLayout::Line& glyphLine = layout.getLine (i);
glyphLine.lineOrigin.x += dx;
}
}
}
private:
static void addRun (TextLayout::Line* glyphLine, TextLayout::Run* glyphRun,
const Token* const t, const int start, const int end)
{
glyphRun->stringRange = Range<int> (start, end);
glyphRun->font = t->font;
glyphRun->colour = t->colour;
glyphLine->ascent = jmax (glyphLine->ascent, t->font.getAscent());
glyphLine->descent = jmax (glyphLine->descent, t->font.getDescent());
glyphLine->runs.add (glyphRun);
}
void appendText (const AttributedString& text, const Range<int>& stringRange,
const Font& font, const Colour& colour)
{
String stringText (text.getText().substring (stringRange.getStart(), stringRange.getEnd()));
String::CharPointerType t (stringText.getCharPointer());
String currentString;
int lastCharType = 0;
for (;;)
{
const juce_wchar c = t.getAndAdvance();
if (c == 0)
break;
int charType;
if (c == '\r' || c == '\n')
charType = 0;
else if (CharacterFunctions::isWhitespace (c))
charType = 2;
else
charType = 1;
if (charType == 0 || charType != lastCharType)
{
if (currentString.isNotEmpty())
tokens.add (new Token (currentString, font, colour,
lastCharType == 2 || lastCharType == 0));
currentString = String::charToString (c);
if (c == '\r' && *t == '\n')
currentString += t.getAndAdvance();
}
else
{
currentString += c;
}
lastCharType = charType;
}
if (currentString.isNotEmpty())
tokens.add (new Token (currentString, font, colour, lastCharType == 2));
}
void layoutRuns (const int maxWidth)
{
int x = 0, y = 0, h = 0;
int i;
for (i = 0; i < tokens.size(); ++i)
{
Token* const t = tokens.getUnchecked(i);
t->area.setPosition (x, y);
t->line = totalLines;
x += t->area.getWidth();
h = jmax (h, t->area.getHeight());
const Token* nextTok = tokens[i + 1];
if (nextTok == 0)
break;
if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->area.getWidth() > maxWidth))
{
setLastLineHeight (i + 1, h);
x = 0;
y += h;
h = 0;
++totalLines;
}
}
setLastLineHeight (jmin (i + 1, tokens.size()), h);
++totalLines;
}
void setLastLineHeight (int i, const int height) noexcept
{
while (--i >= 0)
{
Token* const tok = tokens.getUnchecked (i);
if (tok->line == totalLines)
tok->lineHeight = height;
else
break;
}
}
int getLineWidth (const int lineNumber) const noexcept
{
int maxW = 0;
for (int i = tokens.size(); --i >= 0;)
{
const Token* const t = tokens.getUnchecked (i);
if (t->line == lineNumber && ! t->isWhitespace)
maxW = jmax (maxW, t->area.getRight());
}
return maxW;
}
void addTextRuns (const AttributedString& text)
{
Font defaultFont;
Array<RunAttribute> runAttributes;
{
const int stringLength = text.getText().length();
int rangeStart = 0;
FontAndColour lastFontAndColour (nullptr);
// Iterate through every character in the string
for (int i = 0; i < stringLength; ++i)
{
FontAndColour newFontAndColour (&defaultFont);
const int numCharacterAttributes = text.getNumAttributes();
for (int j = 0; j < numCharacterAttributes; ++j)
{
const AttributedString::Attribute* const attr = text.getAttribute (j);
// Check if the current character falls within the range of a font attribute
if (attr->getFont() != nullptr && (i >= attr->range.getStart()) && (i < attr->range.getEnd()))
newFontAndColour.font = attr->getFont();
// Check if the current character falls within the range of a foreground colour attribute
if (attr->getColour() != nullptr && (i >= attr->range.getStart()) && (i < attr->range.getEnd()))
newFontAndColour.colour = *attr->getColour();
}
if (i > 0 && (newFontAndColour != lastFontAndColour || i == stringLength - 1))
{
runAttributes.add (RunAttribute (lastFontAndColour,
Range<int> (rangeStart, (i < stringLength - 1) ? i : (i + 1))));
rangeStart = i;
}
lastFontAndColour = newFontAndColour;
}
}
for (int i = 0; i < runAttributes.size(); ++i)
{
const RunAttribute& r = runAttributes.getReference(i);
appendText (text, r.range, *(r.fontAndColour.font), r.fontAndColour.colour);
}
}
OwnedArray<Token> tokens;
int totalLines;
JUCE_DECLARE_NON_COPYABLE (TokenList);
};
}
//==============================================================================
void TextLayout::createLayoutWithBalancedLineLengths (const AttributedString& text, float maxWidth)
{
const float minimumWidth = maxWidth / 2.0f;
float bestWidth = maxWidth;
float bestLineProportion = 0.0f;
while (maxWidth > minimumWidth)
{
createLayout (text, maxWidth);
if (getNumLines() < 2)
return;
const float line1 = lines.getUnchecked (lines.size() - 1)->getLineBoundsX().getLength();
const float line2 = lines.getUnchecked (lines.size() - 2)->getLineBoundsX().getLength();
const float prop = jmax (line1, line2) / jmin (line1, line2);
if (prop > 0.9f)
return;
if (prop > bestLineProportion)
{
bestLineProportion = prop;
bestWidth = maxWidth;
}
maxWidth -= 10.0f;
}
if (bestWidth != maxWidth)
createLayout (text, bestWidth);
}
//==============================================================================
void TextLayout::createStandardLayout (const AttributedString& text)
{
TextLayoutHelpers::TokenList l;
l.createLayout (text, *this);
}
void TextLayout::recalculateWidth()
{
if (lines.size() > 0)
{
Range<float> range (lines.getFirst()->getLineBoundsX());
int i;
for (i = lines.size(); --i > 0;)
range = range.getUnionWith (lines.getUnchecked(i)->getLineBoundsX());
for (i = lines.size(); --i >= 0;)
lines.getUnchecked(i)->lineOrigin.x -= range.getStart();
width = range.getLength();
}
}
END_JUCE_NAMESPACE
| [
"ow3nskip"
] | ow3nskip |
8231b9f1b2012116eb1473f0e903a2db4d7fdaef | 9040c3a2dd3a32ba98c51ce3a1fc4a0e92c735af | /Tree/BiTree.h | 07bd4f7bcc220a231ff742256bf8f5346871c6fe | [] | no_license | liubiyongge/DataStructExperimentCode | 1f5e5c24b99ac1ccca5c806c84593dfeb1274f55 | 48de90faab80f3db09f4d92dc23ca45d2aa6074b | refs/heads/master | 2021-06-25T18:37:27.028092 | 2020-10-25T08:48:52 | 2020-10-25T08:48:52 | 155,540,289 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,811 | h |
#ifndef MYTREE_H
#define MYTREE_H
#include "mytree.h"
#endif
#include<stack>
#include<cassert>
#include<queue>
#include<cstring>
#define LH 1 //左高
#define EH 0 //等高
#define RH -1 //右高
template<typename T>
class BiTree
{
public:
class node
{
public:
node() :lchild(NULL), rchild(NULL) {}; //!!!!!!????????
T data;
class node *lchild, *rchild;
};
typedef node*nodepointer;
void clear();
int countleaf(); //求叶子数
int countnode(); //求节点数
int depth(); //递归求深度
void displayseqtree(); //显示顺序存储
void exchangelrchild(); //交换所有左右子树
nodepointer getroot(); //取根指针
void inordertraverse(); //中序递归遍历
bool isempty();
void layordertraverse(); //层次顺序遍历
void linktosequential(); //二叉链表转换顺序存储
void norecursioninordertraverse(); //非递归中序遍历
void postordertraverse(); //后序递归遍历
void preordertraverse(); //前序递归遍历
void randomcreate(int n=-1); //随机生成一颗二叉树
void sequentialtolink(myseqtree<T> t); //顺序转换二叉树链式存储
void bitree_aux(nodepointer &p, nodepointer otherp); //拷贝初始化辅助函数
int countleaf_aux(nodepointer p); //求叶子辅助
int countnode_aux(nodepointer p); //求结点数辅助
void deletenode_aux(nodepointer p); //回收结点空间辅助
int depth_aux(nodepointer p); //递归求深度辅助
void exchangelrchild_aux(nodepointer p); //交换左右子树辅助
void inordertraverse_aux(nodepointer p); //中序递归遍历辅助
void linktosequential_aux(myseqtree<T>&tempt, nodepointer p, int i); //二叉链表转顺序存储辅助
void preordertraverse_aux(nodepointer p); //前序递归辅助
void postordertraverse_aux(nodepointer p); //后序递归辅助
void sequentialtolink_aux(int i, nodepointer& subroot); //顺序转二叉链表存储辅助
BiTree();
~BiTree();
BiTree(const BiTree<T>&othert);
void read(istream& in);
void display(ostream& ot);
protected:
nodepointer root;
myseqtree<T>seqt; //二叉树对应的顺序存储数
};
template<typename T>
void BiTree<T>::clear()
{
seqt.clear();
deletenode_aux(root);
root = NULL;
}
template<typename T>
int BiTree<T>::countleaf()
{
return countleaf_aux(root);
}
template<typename T>
int BiTree<T>::countleaf_aux(nodepointer p)
{
int num = 0;
static int i = 0;
if (p)
{
if (!p->lchild&&!p->rchild)
i++;
countleaf_aux(p->lchild);
countleaf_aux(p->rchild);
}
if (p == root)
{
num = i;
i = 0;
}
return num;
}
template<typename T>
int BiTree<T>::countnode()
{
return countnode_aux(root);
}
template<typename T>
int BiTree<T>::countnode_aux(nodepointer p)
{
int num = 0;
static int i = 0;
if (p)
{
i++;
countnode_aux(p->lchild);
countnode_aux(p->rchild);
}
if (p == root)
{
num = i;
i = 0;
}
return num;
}
template<typename T>
void BiTree<T>::deletenode_aux(nodepointer p)
{
if (p)
{
deletenode_aux(p->lchild);
deletenode_aux(p->rchild);
delete p;
}
}
template<typename T>
int BiTree<T>::depth()
{
return depth_aux(root);
}
template<typename T>
int BiTree<T>::depth_aux(nodepointer p)
{
int ldep = 0, rdep = 0;
if (!p)
return 0;
else
{
ldep = depth_aux(p->lchild);
rdep = depth_aux(p->rchild);
return (ldep > rdep ? ldep : rdep) + 1;
}
}
template<typename T>
void BiTree<T>::displayseqtree()
{
seqt.display();
}
template<typename T>
void BiTree<T>::exchangelrchild()
{
exchangelrchild_aux(root);
linktosequential();
}
template<typename T>
void BiTree<T>::exchangelrchild_aux(nodepointer p)
{
nodepointer s;
if (p)
{
exchangelrchild_aux(p->lchild);
exchangelrchild_aux(p->rchild);
s = p->lchild;
p->lchild = p->rchild;
p->rchild = s;
}
}
//!!!!
template<typename T>
typename BiTree<T>::nodepointer BiTree<T>::getroot() //!!!!!
{
return root;
}
template<typename T>
void BiTree<T>::inordertraverse()
{
inordertraverse_aux(root);
}
template<typename T>
void BiTree<T>::inordertraverse_aux(nodepointer p)
{
if (p)
{
inordertraverse_aux(p->lchild);
cout << p->data;
inordertraverse_aux(p->rchild);
}
}
template<typename T>
bool BiTree<T>::isempty()
{
return root ? false : true;
}
template <typename T>
void BiTree<T>::layordertraverse()
{
nodepointer p;
queue<nodepointer> q;
if (root != NULL)
q.push(root);
while (!q.empty())
{
p = q.front();
q.pop();
cout << p->data;
if (p->lchild)
q.push(p->lchild);
if (p->rchild)
q.push(p->rchild);
}
}
template <typename T>
void BiTree<T>::linktosequential()
{
int max_total = 0;
myseqtree<T> tempt;
if (!root)
{
seqt.clear();
return;
}
max_total = 1;
for (int d = 1; d <= depth(); d++)
max_total *= 2;
max_total -= 1;
tempt.setfinalindex(max_total - 1); //!!!!!!!!!!!!!!
linktosequential_aux(tempt, root, 0);
seqt = tempt;
}
template<typename T>
void BiTree<T>::linktosequential_aux(myseqtree<T>&tempt, nodepointer p, int i)
{
if (!p || i > tempt.getfinalindex())
return;
tempt.setnode(i, p->data);
if (p->lchild != NULL)
linktosequential_aux(tempt, p->lchild, 2 * i + 1);
if (p->rchild != NULL)
linktosequential_aux(tempt, p->rchild, 2 * i + 2);
}
template<typename T>
void BiTree<T>::norecursioninordertraverse()
{
nodepointer p = root;
stack<nodepointer> s;
while (p || !s.empty())
{
if (p)
{
s.push(p);
p = p->lchild;
}
else
{
p=s.top();
s.pop();
cout << p->data;
p = p->rchild;
}
}
}
template<typename T>
void BiTree<T>::postordertraverse()
{
postordertraverse_aux(root);
}
template<typename T>
void BiTree<T>::postordertraverse_aux(nodepointer p)
{
if (p)
{
postordertraverse_aux(p->lchild);
postordertraverse_aux(p->rchild);
cout << p->data;
}
}
template<typename T>
void BiTree<T>::preordertraverse()
{
preordertraverse_aux(root);
}
template<typename T>
void BiTree<T>::preordertraverse_aux(nodepointer p)
{
if (p)
{
cout << p->data;
preordertraverse_aux(p->lchild);
preordertraverse_aux(p->rchild);
}
}
template <typename T>
void BiTree<T>::randomcreate(int n)
{
seqt.randsqt(n);
sequentialtolink_aux(0, root);
}
template<typename T>
void BiTree<T>::sequentialtolink(myseqtree<T> t)
{
seqt = t;
sequentialtolink_aux(0, root);
}
template<typename T>
void BiTree<T> ::sequentialtolink_aux(int i, nodepointer&p)
{
int n = seqt.getfinalindex();
if (n == -1)
{
p = NULL;
return;
}
p = new BiTree<T>::node;
assert(p != 0);
p->data = seqt.getnode(i);
if (2 * i + 1 > n || seqt.getnode(2 * i + 1) == ' ')
p->lchild = NULL;
else
sequentialtolink_aux(2 * i + 1, p->lchild);
if (2 * i + 2 > n || seqt.getnode(2 * i + 2) == ' ')
p->rchild = NULL;
else
sequentialtolink_aux(2 * i + 2, p->rchild);
}
template <typename T>
BiTree<T>::BiTree()
{
root = NULL;
seqt.clear();
}
template<typename T>
BiTree<T>::BiTree(const BiTree<T>& othert)
{
if (!othert.root)
{
root = NULL;
seqt.clear();
}
else
{
bitree_aux(root, othert.root);
linktosequential();
}
}
template<typename T>
void BiTree<T>::bitree_aux(nodepointer& p, nodepointer otherp)
{
if (!otherp)
{
p = NULL;
return;
}
p = new node;
assert(p != 0);
p->data = otherp->data;
if (!otherp->lchild)
p->lchild = NULL;
else
bitree_aux(p->lchild, otherp->lchild);
if (!otherp->rchild)
p->rchild = NULL;
else
bitree_aux(p->rchild, otherp->rchild);
}
template<typename T>
BiTree<T>::~BiTree()
{
clear();
}
template<typename T>
void BiTree<T>::read(istream& in)
{
cout << "采用顺序存储方式创建一棵二叉树" << endl << endl;
in >> seqt;
sequentialtolink_aux(0, root);
}
template<typename T>
istream& operator >> (istream&in, BiTree<T>&bt)
{
bt.read(in);
return in;
}
template<typename T>
void BiTree<T>::display(ostream& out)
{
out << seqt << endl;
}
template<typename T>
ostream& operator<<(ostream&out, BiTree<T>& bt)
{
bt.display(out);
return out;
} | [
"liubiyongge@163.com"
] | liubiyongge@163.com |
69c05ea92ebecc2b84616dce137403c447cf463b | 05b166f163992e1aa67f089c0c86d27a9c3af786 | /~2022/Greedy/1339.cpp | f22285beb44e39ed4c1609d0a70bcd8eacc30740 | [] | no_license | gyeolse/algorithm_study | 52417554c9ab7ffc761c3b78e143683a9c18abaa | bdfd3f0ae0661a0163f5575f40a6984a6f453104 | refs/heads/master | 2022-08-31T11:32:27.502032 | 2022-08-06T12:18:50 | 2022-08-06T12:18:50 | 246,004,136 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,303 | cpp | #include <bits/stdc++.h>
using namespace std;
int alpha[30]; //알파벳 value 저장
vector<string> words;
int n; //단어의 갯수
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
cin>>n;
for(int i=0;i<n;i++) {
string t;
cin>>t;
words.push_back(t);
}
//1. word : words[i][j] -'0' - 17 (A가 17) (alpha에 넣어줄 때)
//알파벳이 어느 자릿수에, 얼마나 등장하는지 alpha 배열에 넣어줌
for(int i=0;i<n;i++) {
for(int j=0;j<words[i].size();j++) {
int cur = words[i][j]-'0'-17; //1234일떄 1은 1000 (10^3)
int curValue = pow(10,words[i].size()-(j+1));
alpha[cur] += curValue;
}
}
//2. alpha 배열의 idx, 빈도수를 같이 저장
vector<pair<int,int>> alphaPair;
for(int i=0;i<30;i++) {
if(alpha[i] == 0) continue;
alphaPair.push_back({alpha[i],i}); //value, idx
}
sort(alphaPair.begin(),alphaPair.end(),greater<>());
//3. 숫자 부여
int cur = 9;
int res = 0;
for(int i=0;i<alphaPair.size();i++) {
int t = alphaPair[i].first * cur;
res += t;
cur--;
// cout<<alphaPair[i].first<<" "<<alphaPair[i].second<<endl;
}
cout<<res<<endl;
return 0;
} | [
"threewave@kakao.com"
] | threewave@kakao.com |
6718b1b317956ead3279e09a1613d4112b9a1e49 | bb91762cc7683345d63a653db6c12cea65d5802e | /repetytorium12_12/Kalkulator/KalkulatorMain.cpp | 8f4b75a4fdbc7e539a19e1961891dea57999f37a | [] | no_license | svv1viktoria1soverda1mail1ru/Cplusplus | f705e2c3000b0bea39cd6d528737f094ffed1340 | 3f1c4945fb7f7bbbe0b35b324c092e3a657de0e4 | refs/heads/master | 2020-12-24T12:12:47.961412 | 2017-01-05T14:02:58 | 2017-01-05T14:02:58 | 73,069,123 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 12,646 | cpp | /***************************************************************
* Name: KalkulatorMain.cpp
* Purpose: Code for Application Frame
* Author: ()
* Created: 2016-12-05
* Copyright: ()
* License:
**************************************************************/
#include "KalkulatorMain.h"
#include <wx/msgdlg.h>
//(*InternalHeaders(KalkulatorFrame)
#include <wx/string.h>
#include <wx/intl.h>
//*)
//helper functions
enum wxbuildinfoformat {
short_f, long_f };
wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);
if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif
#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}
return wxbuild;
}
//(*IdInit(KalkulatorFrame)
const long KalkulatorFrame::ID_TEXTCTRL1 = wxNewId();
const long KalkulatorFrame::ID_BUTTON1 = wxNewId();
const long KalkulatorFrame::ID_BUTTON2 = wxNewId();
const long KalkulatorFrame::ID_BUTTON3 = wxNewId();
const long KalkulatorFrame::ID_BUTTON4 = wxNewId();
const long KalkulatorFrame::ID_BUTTON5 = wxNewId();
const long KalkulatorFrame::ID_BUTTON6 = wxNewId();
const long KalkulatorFrame::ID_BUTTON7 = wxNewId();
const long KalkulatorFrame::ID_BUTTON8 = wxNewId();
const long KalkulatorFrame::ID_BUTTON9 = wxNewId();
const long KalkulatorFrame::ID_BUTTON10 = wxNewId();
const long KalkulatorFrame::ID_BUTTON11 = wxNewId();
const long KalkulatorFrame::ID_BUTTON12 = wxNewId();
const long KalkulatorFrame::ID_BUTTON13 = wxNewId();
const long KalkulatorFrame::ID_BUTTON14 = wxNewId();
const long KalkulatorFrame::ID_BUTTON15 = wxNewId();
const long KalkulatorFrame::ID_BUTTON16 = wxNewId();
const long KalkulatorFrame::ID_BUTTON17 = wxNewId();
const long KalkulatorFrame::ID_BUTTON18 = wxNewId();
const long KalkulatorFrame::ID_BUTTON19 = wxNewId();
const long KalkulatorFrame::ID_BUTTON20 = wxNewId();
const long KalkulatorFrame::ID_MENUITEM1 = wxNewId();
const long KalkulatorFrame::idMenuAbout = wxNewId();
const long KalkulatorFrame::ID_STATUSBAR1 = wxNewId();
//*)
BEGIN_EVENT_TABLE(KalkulatorFrame,wxFrame)
//(*EventTable(KalkulatorFrame)
//*)
END_EVENT_TABLE()
KalkulatorFrame::KalkulatorFrame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(KalkulatorFrame)
wxMenuItem* MenuItem2;
wxMenuItem* MenuItem1;
wxGridSizer* GridSizer1;
wxMenu* Menu1;
wxBoxSizer* BoxSizer1;
wxMenuBar* MenuBar1;
wxMenu* Menu2;
Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
SetClientSize(wxSize(471,450));
BoxSizer1 = new wxBoxSizer(wxVERTICAL);
pole = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxSize(437,40), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
BoxSizer1->Add(pole, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
GridSizer1 = new wxGridSizer(5, 5, 0, 0);
Button1 = new wxButton(this, ID_BUTTON1, _("1"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
GridSizer1->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button2 = new wxButton(this, ID_BUTTON2, _("2"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
GridSizer1->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button3 = new wxButton(this, ID_BUTTON3, _("3"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
GridSizer1->Add(Button3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button4 = new wxButton(this, ID_BUTTON4, _("%"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
GridSizer1->Add(Button4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button5 = new wxButton(this, ID_BUTTON5, _("C"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON5"));
GridSizer1->Add(Button5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button6 = new wxButton(this, ID_BUTTON6, _("4"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON6"));
GridSizer1->Add(Button6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button7 = new wxButton(this, ID_BUTTON7, _("5"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON7"));
GridSizer1->Add(Button7, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button8 = new wxButton(this, ID_BUTTON8, _("6"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON8"));
GridSizer1->Add(Button8, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button9 = new wxButton(this, ID_BUTTON9, _("*"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON9"));
GridSizer1->Add(Button9, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button10 = new wxButton(this, ID_BUTTON10, _("/"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON10"));
GridSizer1->Add(Button10, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button11 = new wxButton(this, ID_BUTTON11, _("7"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON11"));
GridSizer1->Add(Button11, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button12 = new wxButton(this, ID_BUTTON12, _("8"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON12"));
GridSizer1->Add(Button12, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button13 = new wxButton(this, ID_BUTTON13, _("9"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON13"));
GridSizer1->Add(Button13, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button14 = new wxButton(this, ID_BUTTON14, _("x^2"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON14"));
GridSizer1->Add(Button14, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button15 = new wxButton(this, ID_BUTTON15, _("sqrt(x)"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON15"));
GridSizer1->Add(Button15, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button16 = new wxButton(this, ID_BUTTON16, _("."), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON16"));
GridSizer1->Add(Button16, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button17 = new wxButton(this, ID_BUTTON17, _("0"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON17"));
GridSizer1->Add(Button17, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button18 = new wxButton(this, ID_BUTTON18, _("="), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON18"));
GridSizer1->Add(Button18, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button19 = new wxButton(this, ID_BUTTON19, _("-"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON19"));
GridSizer1->Add(Button19, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Button20 = new wxButton(this, ID_BUTTON20, _("+"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON20"));
GridSizer1->Add(Button20, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer1->Add(GridSizer1, 5, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
SetSizer(BoxSizer1);
MenuBar1 = new wxMenuBar();
Menu1 = new wxMenu();
MenuItem1 = new wxMenuItem(Menu1, ID_MENUITEM1, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
Menu1->Append(MenuItem1);
MenuBar1->Append(Menu1, _("&File"));
Menu2 = new wxMenu();
MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
Menu2->Append(MenuItem2);
MenuBar1->Append(Menu2, _("Help"));
SetMenuBar(MenuBar1);
StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
int __wxStatusBarWidths_1[1] = { -1 };
int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
SetStatusBar(StatusBar1);
SetSizer(BoxSizer1);
Layout();
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton1Click);
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton2Click);
Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton3Click);
Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton4Click);
Connect(ID_BUTTON5,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton5Click);
Connect(ID_BUTTON6,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton6Click);
Connect(ID_BUTTON7,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton7Click);
Connect(ID_BUTTON8,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton8Click);
Connect(ID_BUTTON9,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton9Click);
Connect(ID_BUTTON11,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton11Click);
Connect(ID_BUTTON12,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton12Click);
Connect(ID_BUTTON13,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton13Click);
Connect(ID_BUTTON14,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&KalkulatorFrame::OnButton14Click);
Connect(ID_MENUITEM1,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&KalkulatorFrame::OnQuit);
Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&KalkulatorFrame::OnAbout);
//*)
}
KalkulatorFrame::~KalkulatorFrame()
{
//(*Destroy(KalkulatorFrame)
//*)
}
void KalkulatorFrame::OnQuit(wxCommandEvent& event)
{
exit(0);
}
void KalkulatorFrame::OnAbout(wxCommandEvent& event)
{
wxString msg = wxbuildinfo(long_f);
wxMessageBox(msg, _("Welcome to..."));
}
void KalkulatorFrame::OnButton1Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<1;
pole->SetValue(napis+liczba);
// Layout();
}
void KalkulatorFrame::OnButton2Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<2;
pole->SetValue(napis+liczba);
}
void KalkulatorFrame::OnButton3Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<3;
pole->SetValue(napis+liczba);
}
void KalkulatorFrame::OnButton5Click(wxCommandEvent& event)
{
pole->Clear();
}
void KalkulatorFrame::OnButton6Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<4;
pole->SetValue(napis+liczba);
}
void KalkulatorFrame::OnButton7Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<5;
pole->SetValue(napis+liczba);
}
void KalkulatorFrame::OnButton8Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<6;
pole->SetValue(napis+liczba);
}
void KalkulatorFrame::OnButton11Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<7;
pole->SetValue(napis+liczba);
}
void KalkulatorFrame::OnButton12Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<8;
pole->SetValue(napis+liczba);
}
void KalkulatorFrame::OnButton13Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<9;
pole->SetValue(napis+liczba);
}
void KalkulatorFrame::OnButton4Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<66;
pole->SetValue(napis+liczba);
}
void KalkulatorFrame::OnButton9Click(wxCommandEvent& event)
{
wxString liczba;
wxString napis;
napis=pole->GetValue();
liczba<<44;
pole->SetValue(napis+liczba);
}
void KalkulatorFrame::OnButton14Click(wxCommandEvent& event)
{
}
| [
"svv.viktoria.soverda@mail.ru"
] | svv.viktoria.soverda@mail.ru |
47478921634a52ca8ababb38302284a3c47cdf0e | e55f92f42d5fb994a6e6fc306478e73839d81c46 | /EdFc/zEdUser/SetGrp.h | ff2d505f67fd52c429fb245e65c0567fb78bac1d | [] | no_license | zphseu/cuiyan | 115f854e54ea35f18f44f26c2c865c4f8f98169e | ec121ddb16d9fe60b3edcc6c891f11318a12d32d | refs/heads/master | 2021-01-18T15:08:20.290861 | 2014-01-23T07:47:09 | 2014-01-23T07:47:09 | 53,846,163 | 1 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 1,254 | h | #if !defined(AFX_SETGRP_H__71AC8DFA_9B1A_498F_BC3E_13635DCA1BCB__INCLUDED_)
#define AFX_SETGRP_H__71AC8DFA_9B1A_498F_BC3E_13635DCA1BCB__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SetGrp.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CSetGrp recordset
struct tagGrp
{
CString m_csName;
CString m_csCmt;
};
class CSetGrp : public CRecordset, public tagGrp
{
public:
CSetGrp(CDatabase* pDatabase);
DECLARE_DYNAMIC(CSetGrp)
// Field/Param Data
//{{AFX_FIELD(CSetGrp, CRecordset)
//}}AFX_FIELD
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSetGrp)
public:
virtual CString GetDefaultSQL(); // Default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
virtual CString GetDefaultConnect();
//}}AFX_VIRTUAL
// Implementation
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_SETGRP_H__71AC8DFA_9B1A_498F_BC3E_13635DCA1BCB__INCLUDED_)
| [
"cui.cuiyan@8bba5440-9dad-11dd-b92e-bd4787f9249a"
] | cui.cuiyan@8bba5440-9dad-11dd-b92e-bd4787f9249a |
fef8da46d15155288c597f9e341149ca7ca085f9 | fbfff9f818c7ef52e4a583b46756526f49b8211e | /cpp_programs/fibonacci_series.cpp | cc3aef48dedfef3362913b4db34cd5cecaae7e55 | [] | no_license | tanyasharma219/tanya_sharma | 2882bd1132b2e0ba70e91ab4dcdd6bb08ebc9554 | a4ace48537a4719061f5b1de8d78881205b3e463 | refs/heads/master | 2022-12-10T05:32:13.292746 | 2020-09-10T17:43:19 | 2020-09-10T17:43:19 | 290,974,335 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 277 | cpp | #include <iostream>
using namespace std;
void fib(int num){
int a=0, b=1, sum=0;
for(int i=3; i<=num; i++){
cout<<sum<<" ";
a=b;
b=sum;
sum=a+b;
}
}
int main(){
int num;
cout<<"enter the num till which series be printed"<<endl;
cin>>num;
fib(num);
return 0;
}
| [
"noreply@github.com"
] | tanyasharma219.noreply@github.com |
e3110a3bf1314f25dfbccb80d0310b149f8e9896 | 806d887dcf79775f594ee547cffe26690c737d41 | /Iterative-Algorithms/1/Problema1ContarMaximos.cpp | 5ba5496df962685bf646807535e89135c52420cc | [] | no_license | YusefBM/Algorithms-and-Data-Structures | e58f9c9dd7e0991003d032568a86fdd7db1ac600 | a45c49b2467caf6005b8882eaaac6366ae11346d | refs/heads/master | 2022-04-15T22:57:17.851150 | 2020-04-12T21:56:09 | 2020-04-12T21:56:09 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,071 | cpp | // Nombre del alumno : Eduardo Martínez Martín
// Usuario del Juez : E31
#include <iostream>
#include <fstream>
using namespace std;
// Resuelve un caso de prueba, leyendo de la entrada la
// configuración, y escribiendo la respuesta
void resuelveCaso() {
// leer los datos de la entrada
int numero, maximo, tam, cont = 1;
cin >> tam;
cin >> maximo;
for (int i = 1; i < tam; i++) {
cin >> numero;
if (numero > maximo) {
maximo = numero;
cont = 1;
}
else if(numero == maximo)
cont++;
}
cout << maximo << " " << cont << endl;
}
int main() {
// Para la entrada por fichero.
// Comentar para acepta el reto
#ifndef DOMJUDGE
std::ifstream in("datos.txt");
auto cinbuf = std::cin.rdbuf(in.rdbuf()); //save old buf and redirect std::cin to casos.txt
#endif
int numCasos;
std::cin >> numCasos;
for (int i = 0; i < numCasos; ++i)
resuelveCaso();
// Para restablecer entrada. Comentar para acepta el reto
#ifndef DOMJUDGE // para dejar todo como estaba al principio
std::cin.rdbuf(cinbuf);
system("PAUSE");
#endif
return 0;
} | [
"edumar03@ucm.es"
] | edumar03@ucm.es |
5a16d792a4a788b9853aeccfc07aa888287cbf4e | 5de093a42b3d6c62d8ec6b217f44957e3ba4f8ce | /problems/112-path-sum/solution.cpp | b7e24a00711b4b72e068b3a8b972186b42f1e3da | [] | no_license | numbaa/lc | 2d311983f9e6536940d14aa57b90f7fbef5de545 | 4a7d0432ab4fa02e3e29bd82602dfd073e86bd8f | refs/heads/master | 2022-11-16T16:19:48.112387 | 2020-06-23T17:15:39 | 2020-06-23T17:15:39 | 262,825,471 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,020 | cpp | /**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
bool hasPathSum(TreeNode* root, int sum) {
if (root == nullptr) return false;
if (root->val == sum && root->left == nullptr && root->right == nullptr) return true;
return hasPathSum(root->left, root->val, sum) || hasPathSum(root->right, root->val, sum);
}
bool hasPathSum(TreeNode* node, int prevSum, int target)
{
if (node == nullptr) return false;
if (node->val + prevSum == target && node->left == nullptr && node->right == nullptr) return true;
return hasPathSum(node->left, node->val + prevSum, target) || hasPathSum(node->right, node->val + prevSum, target);
}
};
| [
"zhennan.tu@gmail.com"
] | zhennan.tu@gmail.com |
a1c4b1afeeea5256ad4a8f4dc108bf9fa590094d | 3bd90c6b89901eb563617191ccd34d2064e016d7 | /foundation/tekEventsLinux.cpp | c20441a258f1d1c508e92676c2417d81c7769567 | [] | no_license | tomerweller/teknic-example-single-threaded | 5132d4a52939b3037ec61fa2fac7fb939d468bd9 | 000273cbc1bc5c9b544a645a3bc36a82a54019ea | refs/heads/master | 2021-01-23T22:05:19.683522 | 2017-02-25T07:58:35 | 2017-02-25T07:58:35 | 83,116,362 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,559 | cpp | //*****************************************************************************
// $Archive: /ClearPath SC/LinuxPrjEclipse/sFoundation20/linux/src/tekEventsLinux.cpp $
// $Revision: 4 $ $Date: 9/19/16 12:11 $
// $Workfile: tekEventsLinux.cpp $
//
// DESCRIPTION:
/**
\file
\brief Implementation module for a portable event based library for
the Linux platform.
**/
// PRINCIPLE AUTHORS:
// Dave Sewhuk
//
// CREATION DATE:
// 2012-03-27 13:38:27
//
// COPYRIGHT NOTICE:
// (C)Copyright 2012 Teknic, Inc. All rights reserved.
//
// This copyright notice must be reproduced in any copy, modification,
// or portion thereof merged into another program. A copy of the
// copyright notice must be included in the object library of a user
// program.
// *
//*****************************************************************************
//*****************************************************************************
// NAME *
// tekEventsLinux.cpp headers
//
#include "tekEventsLinux.h"
#include <assert.h>
// *
//*****************************************************************************
//*****************************************************************************
// NAME *
// tekEventsLinux.cpp function prototypes
//
//
// *
//*****************************************************************************
//*****************************************************************************
// NAME *
// tekEventsLinux.cpp constants
//
//
const size_t MAXIMUM_WAIT_OBJECTS = 64;
// *
//*****************************************************************************
//*****************************************************************************
// NAME *
// tekEventsLinux.cpp static variables
//
//
// *
//*****************************************************************************
//*****************************************************************************
// NAME *
// CCMTMultiLock::CCMTMultiLock
//
// AUTHOR:
// Dave Sewhuk - created on 2012-03-27 13:42:31
//
// DESCRIPTION:
/**
Wait until all the events in the list signal when unlocking.
This version can only work with CCEvents and provides a subset
of the Windows functionality of the WaitForMultipleObjects
API function.
\param[in,out] xxx description
\return description
**/
// SYNOPSIS:
CCMTMultiLock::CCMTMultiLock(CCEvent *pObjects[],Uint32 dwCount,
Uint32 UnlockCount, bool bWaitForAll,
Uint32 dwTimeout, Uint32 dwWakeMask)
{
//dwWakeMask=dwWakeMask; // Suppress compiler warning
//dwTimeout=dwTimeout; // Suppress compiler warning
m_dwUnlockCount = UnlockCount;
assert(dwCount > 0 && dwCount <= MAXIMUM_WAIT_OBJECTS);
assert(pObjects != NULL);
// Linux can't really do this
assert(bWaitForAll);
m_ppObjectArray = pObjects;
m_dwCount = dwCount;
// as an optimization, skip allocating array if
// we can use a small, pre-eallocated bunch of handles
if (m_dwCount > (sizeof(m_hPreallocated)/sizeof(m_hPreallocated[0]))) {
m_pHandleArray = new CCEvent *[m_dwCount];
m_bLockedArray = new bool[m_dwCount];
}
else {
m_pHandleArray = m_hPreallocated;
m_bLockedArray = m_bPreallocated;
}
// get list of handles from array of objects passed
for (Uint32 i = 0; i <m_dwCount; i++) {
assert(pObjects[i]);
m_pHandleArray[i] = pObjects[i];
m_bLockedArray[i] = false;
}
////Lock(dwTimeout,bWaitForAll,dwWakeMask);
}
// *
//*****************************************************************************
//*****************************************************************************
// NAME *
// CCMTMultiLock::~CCMTMultiLock
//
// AUTHOR:
// Dave Sewhuk - created on 2012-03-27 13:43:39
//
// DESCRIPTION:
/**
\param[in,out] xxx description
\return description
**/
// SYNOPSIS:
CCMTMultiLock::~CCMTMultiLock()
{
for (Uint32 i=0; i < m_dwCount; i++)
if (m_bLockedArray[i])
m_ppObjectArray[i]->SetEvent();
if (m_pHandleArray != m_hPreallocated) {
delete[] m_bLockedArray;
delete[] m_pHandleArray;
}
}
// *
//*****************************************************************************
//*****************************************************************************
// NAME *
// CCMTMultiLock::Lock
//
// AUTHOR:
// Dave Sewhuk - created on 2012-03-27 13:47:05
//
// DESCRIPTION:
/**
\param[in,out] xxx description
\return description
**/
// SYNOPSIS:
Uint32 CCMTMultiLock::Lock(Uint32 dwTimeOut,
bool bWaitForAll,Uint32 dwWakeMask)
{
Uint32 dwResult = 0;
//dwWakeMask=dwWakeMask; // Suppress Compiler Warnings
if (bWaitForAll){
// Wait for all of our events to signal
for (Uint32 i = 0; i < m_dwCount; i++) {
m_bLockedArray[i] = m_pHandleArray[i]->WaitFor(dwTimeOut);
dwResult |= m_bLockedArray[i]<<i;
}
}
else {
assert(0);
}
return dwResult;
}
// *
//*****************************************************************************
//=============================================================================
// END OF FILE tekEventsLinux.cpp
//=============================================================================
| [
"tomer.weller@gmail.com"
] | tomer.weller@gmail.com |
1cea91f1d689892853860373850fad7d3e133857 | d85b1f3ce9a3c24ba158ca4a51ea902d152ef7b9 | /testcases/CWE122_Heap_Based_Buffer_Overflow/s05/CWE122_Heap_Based_Buffer_Overflow__CWE131_memcpy_72a.cpp | 155a06b025d8135918d3bde9be20447a3e83576b | [] | no_license | arichardson/juliet-test-suite-c | cb71a729716c6aa8f4b987752272b66b1916fdaa | e2e8cf80cd7d52f824e9a938bbb3aa658d23d6c9 | refs/heads/master | 2022-12-10T12:05:51.179384 | 2022-11-17T15:41:30 | 2022-12-01T15:25:16 | 179,281,349 | 34 | 34 | null | 2022-12-01T15:25:18 | 2019-04-03T12:03:21 | null | UTF-8 | C++ | false | false | 2,763 | cpp | /* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE122_Heap_Based_Buffer_Overflow__CWE131_memcpy_72a.cpp
Label Definition File: CWE122_Heap_Based_Buffer_Overflow__CWE131.label.xml
Template File: sources-sink-72a.tmpl.cpp
*/
/*
* @description
* CWE: 122 Heap Based Buffer Overflow
* BadSource: Allocate memory without using sizeof(int)
* GoodSource: Allocate memory using sizeof(int)
* Sinks: memcpy
* BadSink : Copy array to data using memcpy()
* Flow Variant: 72 Data flow: data passed in a vector from one function to another in different source files
*
* */
#include "std_testcase.h"
#include <vector>
using namespace std;
namespace CWE122_Heap_Based_Buffer_Overflow__CWE131_memcpy_72
{
#ifndef OMITBAD
/* bad function declaration */
void badSink(vector<int *> dataVector);
void bad()
{
int * data;
vector<int *> dataVector;
data = NULL;
/* FLAW: Allocate memory without using sizeof(int) */
data = (int *)malloc(10);
if (data == NULL) {exit(-1);}
/* Put data in a vector */
dataVector.insert(dataVector.end(), 1, data);
dataVector.insert(dataVector.end(), 1, data);
dataVector.insert(dataVector.end(), 1, data);
badSink(dataVector);
}
#endif /* OMITBAD */
#ifndef OMITGOOD
/* good function declarations */
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(vector<int *> dataVector);
static void goodG2B()
{
int * data;
vector<int *> dataVector;
data = NULL;
/* FIX: Allocate memory using sizeof(int) */
data = (int *)malloc(10*sizeof(int));
if (data == NULL) {exit(-1);}
/* Put data in a vector */
dataVector.insert(dataVector.end(), 1, data);
dataVector.insert(dataVector.end(), 1, data);
dataVector.insert(dataVector.end(), 1, data);
goodG2BSink(dataVector);
}
void good()
{
goodG2B();
}
#endif /* OMITGOOD */
} /* close namespace */
/* Below is the main(). It is only used when building this testcase on
* its own for testing or for building a binary to use in testing binary
* analysis tools. It is not used when compiling all the testcases as one
* application, which is how source code analysis tools are tested.
*/
#ifdef INCLUDEMAIN
using namespace CWE122_Heap_Based_Buffer_Overflow__CWE131_memcpy_72; /* so that we can use good and bad easily */
int main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine("Calling good()...");
good();
printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
printLine("Calling bad()...");
bad();
printLine("Finished bad()");
#endif /* OMITBAD */
return 0;
}
#endif
| [
"Alexander.Richardson@cl.cam.ac.uk"
] | Alexander.Richardson@cl.cam.ac.uk |
e6bcf4008b03b9c13274740b77841b24522a50be | 6e41458b8ec6ccf30d314a0cd0a3fdd94317925f | /Fuzzy/Codigo1/includes/RegrasVel.hpp | 58756e090607c2db41ce763a64cad30671dc30a9 | [] | no_license | UnbDroid/Festo2016 | 108577b4468513f609e921841e5365be6fc09274 | 8f22bcf9b68803a91ac20dfb282910db55415b98 | refs/heads/master | 2021-01-23T14:04:08.587503 | 2017-09-04T19:48:26 | 2017-09-04T19:48:26 | 58,758,496 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 774 | hpp | #ifndef REGRAS_VEL_HPP
#define REGRAS_VEL_HPP
#include "Regras.hpp"
#include <vector>
using namespace std;
template <class Owner> class TurboBackward: public Regras<Owner>{
public:
TurboBackward(Owner* o):Regras<Owner>(o){};
virtual void executar();
};
template <class Owner> class VeryFastBackward: public Regras<Owner>{
public:
VeryFastBackward(Owner* o):Regras<Owner>(o){};
virtual void executar();
};
template <class Owner> class FastBackward: public Regras<Owner>{
public:
FastBackward(Owner* o):Regras<Owner>(o){};
virtual void executar();
};
template <class Owner> class Backward: public Regras<Owner>{
public:
Backward(Owner* o):Regras<Owner>(o){};
virtual void executar();
};
#include "RegrasVel.tpp"
#endif // REGRAS_VEL_HPP | [
"rodrigowerberich@hotmail.com"
] | rodrigowerberich@hotmail.com |
bfa7b5a0a259a559a8e830af0be05e70f45939fc | dc147e412416807d1f6a73742152d48a00fde69c | /1A - Shopping App/Utils.cpp | f21fa91f0dce3cff3182ee4081fdc6a60daad697 | [] | no_license | MohitSheladiya/ObjectOrientedProgramming | 7a4b606098736c561c15c52cf9860cc1503cb178 | 04ccb2ea15bf1f0d31a6741c968d631e6c556c40 | refs/heads/master | 2023-07-06T18:02:32.455880 | 2021-08-15T06:59:57 | 2021-08-15T06:59:57 | 396,161,231 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,446 | cpp | /*
Name: Mohit Kishorbhai Sheladiya
Student ID: 117979203
Student Email: mksheladiya@myseneca.ca
Date: 20/1/21
*/
#include <iostream>
#include "Utils.h"
using namespace std;
namespace sdds {
void flushkeys() {
while (cin.get() != '\n');
}
bool ValidYesResponse(char ch) {
return ch == 'Y' || ch == 'y' || ch == 'N' || ch == 'n';
}
bool yes() {
char ch = 0;
do {
cin >> ch;
flushkeys();
} while (!ValidYesResponse(ch) && cout << "Only (Y/y) or (N/n) is acceptable: ");
return ch == 'y' || ch == 'Y';
}
void readCstr(char cstr[], int len) {
char buf[1024] = {};
int i;
cin.getline(buf, 1024);
for (i = 0; i < len && buf[i]; i++) {
cstr[i] = buf[i];
}
cstr[i] = 0;
}
int readInt(int min, int max) {
int value = 0;
bool done = false;
while (!done) {
cin >> value;
if (!cin) {
cin.clear();
cout << "Bad integer, try agian: ";
}
else {
if (value >= min && value <= max) {
done = true;
}
else {
cout << "Value out of range (" << min << "<=value<=" << max << "): ";
}
}
flushkeys();
}
return value;
}
} | [
"sheladiyamohit@gmail.com"
] | sheladiyamohit@gmail.com |
455b819f4b1fcf29e82c29b73b3e70254b4db447 | 46bf8aa86e7724629b269a0ac473b385dfe18c4b | /test/demosupport.h | 2910f915274fe27fe2940ef515c3455ffdc8e10b | [
"MIT"
] | permissive | equilibr/osgQt | 16938bd564010042972674bf8537ff229f318a54 | c59c973dcff1c12c649f8bb83e6736dccff13f8d | refs/heads/master | 2020-07-24T15:21:26.584542 | 2020-04-10T13:51:01 | 2020-04-10T13:51:01 | 207,967,538 | 5 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 275 | h | #ifndef DEMOSUPPORT_H
#define DEMOSUPPORT_H
#include <osg/Geode>
#include "../src/osgQtWidget.h"
namespace osgQtDemo
{
osg::Geode * createScene();
void setupCameraManipulator(osgQt::Widget * widget);
void setupCamera(osgQt::Widget * widget);
}
#endif // DEMOSUPPORT_H
| [
"47003432+equilibr@users.noreply.github.com"
] | 47003432+equilibr@users.noreply.github.com |
fd4be234176529442776cece8e1e590ab3e346b1 | 5d0ab3b290b0b997a8b2184037b01331af14fcfe | /practical5/src/dynamics/SpringForceField.cpp | d09c102d21be3af6d755dd4ed6e9c101d01b83f2 | [] | no_license | pie3636/3D-Kart | e58ff18fb9e5701431ea0c495ee43de6d9b6c4ac | 91310abe27d225b1d152b3722cafb9425a80c823 | refs/heads/master | 2023-06-09T08:34:03.739633 | 2016-04-26T10:20:01 | 2016-04-26T10:20:01 | 55,910,402 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 903 | cpp | #include "./../../include/dynamics/SpringForceField.hpp"
SpringForceField::SpringForceField(const ParticlePtr p1, const ParticlePtr p2, float stiffness, float equilibriumLength, float damping) :
m_p1(p1),
m_p2(p2),
m_stiffness(stiffness),
m_equilibriumLength(equilibriumLength),
m_damping(damping)
{}
void SpringForceField::do_addForce()
{
glm::vec3 u = m_p2->getPosition() - m_p1->getPosition();
if (glm::length(u) < std::numeric_limits<float>::epsilon()) {
return;
}
glm::vec3 nu = glm::normalize(u);
glm::vec3 force = -m_stiffness * (glm::length(u) - m_equilibriumLength) * u / glm::length(u) - m_damping * glm::dot(m_p2->getVelocity() - m_p1->getVelocity(), nu) * nu;
m_p2->incrForce(force);
m_p1->incrForce(-force);
}
ParticlePtr SpringForceField::getParticle1() const
{
return m_p1;
}
ParticlePtr SpringForceField::getParticle2() const
{
return m_p2;
}
| [
"maxime.meloux@ensimag.grenoble-inp.fr"
] | maxime.meloux@ensimag.grenoble-inp.fr |
328bc10ee6ef7f1fe14ff8b99bad36b3b80e8ef6 | fa939a703563ca6a5af3b79df3c4241757f3f059 | /Source/Laboratoare/Tema3/Transform2D.h | ea7517f6cb8277a9df056b354670e71c09f9c21e | [] | no_license | alexbiolete/opengl-skylised-runner | 47c13cc603cb8c0209bfbf2a13a4b570d6db3d42 | abc3f167b5fad10ed8daefd05cddb6c405279c36 | refs/heads/main | 2023-07-17T23:38:32.158513 | 2021-08-31T21:01:51 | 2021-08-31T21:01:51 | 401,839,595 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 686 | h | #pragma once
#include <include/glm.h>
namespace Transform2D
{
// Translate matrix
inline glm::mat3 Translate(float translateX, float translateY)
{
// TODO implement translate matrix
return glm::transpose(glm::mat3(1, 0, translateX,
0, 1, translateY,
0, 0, 1));
}
// Scale matrix
inline glm::mat3 Scale(float scaleX, float scaleY)
{
// TODO implement scale matrix
return glm::transpose(glm::mat3(scaleX, 0, 0, 0, scaleY, 0, 0, 0, 1));
}
// Rotate matrix
inline glm::mat3 Rotate(float radians)
{
// TODO implement rotate matrix
return glm::transpose(glm::mat3(cos(radians), -sin(radians), 0, sin(radians), cos(radians), 0, 0, 0, 1));
}
}
| [
"alexbiolete@pm.me"
] | alexbiolete@pm.me |
8ecbe36c8482cf6b44676b9439f59ccc4992ac1d | 139dfd1c0af642a3bc48e88f1ac740589b0590ea | /src/AS_02_PHDR.h | e9084042bccc79612f71440e5718122872548252 | [
"BSD-3-Clause"
] | permissive | DSRCorporation/asdcplib-as02 | 355c5fc76288e671d72e77a049e270ad6f9ca2e0 | 018002ccc5d62716514921a14782446e8edc4f3a | refs/heads/master | 2020-05-02T13:44:35.517720 | 2016-08-08T12:36:59 | 2016-08-08T12:36:59 | 65,993,564 | 8 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,201 | h | /*
Copyright (c) 2011-2015, John Hurst
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*! \file AS_02_PHDR.h
\version $Id: AS_02_PHDR.h,v 1.4 2015/01/22 21:05:58 jhurst Exp $
\brief AS-02 library, JPEG 2000 P-HDR essence reader and writer implementation
*/
#ifndef _AS_02_PHDR_H_
#define _AS_02_PHDR_H_
#include "AS_02.h"
namespace AS_02
{
namespace PHDR
{
//
class FrameBuffer : public ASDCP::JP2K::FrameBuffer
{
public:
std::string OpaqueMetadata;
FrameBuffer() {}
FrameBuffer(ui32_t size) { Capacity(size); }
virtual ~FrameBuffer() {}
// Print debugging information to stream (stderr default)
void Dump(FILE* = 0, ui32_t dump_bytes = 0) const;
};
// An object which reads a sequence of files containing
// JPEG 2000 P-HDR pictures and metadata.
class SequenceParser
{
class h__SequenceParser;
Kumu::mem_ptr<h__SequenceParser> m_Parser;
ASDCP_NO_COPY_CONSTRUCT(SequenceParser);
public:
SequenceParser();
virtual ~SequenceParser();
// Opens a directory for reading. The directory is expected to contain one or
// more pairs of files, each containing the codestream for exactly one picture (.j2c)
// and the corresponding P-HDR metadata (.xml). The files must be named such that the
// frames are in temporal order when sorted alphabetically by filename. The parser
// will automatically parse enough data from the first file to provide a complete set
// of stream metadata for the MXFWriter below. The contents of the metadata files will
// not be analyzed (i.e., the raw bytes will be passed in without scrutiny.) If the
// "pedantic" parameter is given and is true, the J2C parser will check the JPEG 2000
// metadata for each codestream and fail if a mismatch is detected.
Result_t OpenRead(const std::string& filename, bool pedantic = false) const;
// Opens a file sequence for reading. The sequence is expected to contain one or
// more pairs of filenames, each naming a file containing the codestream (.j2c) and the
// corresponding P-HDR metadata (.xml) for exactly one picture. The parser will
// automatically parse enough data from the first file to provide a complete set of
// stream metadata for the MXFWriter below. If the "pedantic" parameter is given and
// is true, the parser will check the metadata for each codestream and fail if a
// mismatch is detected.
Result_t OpenRead(const std::list<std::string>& file_list, bool pedantic = false) const;
// Fill a PictureDescriptor struct with the values from the first file's codestream.
// Returns RESULT_INIT if the directory is not open.
Result_t FillPictureDescriptor(ASDCP::JP2K::PictureDescriptor&) const;
// Rewind the directory to the beginning.
Result_t Reset() const;
// Reads the next sequential frame in the directory and places it in the frame buffer.
// Fails if the buffer is too small or the direcdtory contains no more files. The frame
// buffer's PlaintextOffset parameter will be set to the first byte of the data segment.
// Set this value to zero if you want encrypted headers.
Result_t ReadFrame(AS_02::PHDR::FrameBuffer&) const;
};
//
class MXFWriter
{
class h__Writer;
ASDCP::mem_ptr<h__Writer> m_Writer;
ASDCP_NO_COPY_CONSTRUCT(MXFWriter);
public:
MXFWriter();
virtual ~MXFWriter();
// Warning: direct manipulation of MXF structures can interfere
// with the normal operation of the wrapper. Caveat emptor!
virtual ASDCP::MXF::OP1aHeader& OP1aHeader();
virtual ASDCP::MXF::RIP& RIP();
// Open the file for writing. The file must not exist. Returns error if
// the operation cannot be completed or if nonsensical data is discovered
// in the essence descriptor.
Result_t OpenWrite(const std::string& filename, const ASDCP::WriterInfo&,
ASDCP::MXF::FileDescriptor* essence_descriptor,
ASDCP::MXF::InterchangeObject_list_t& essence_sub_descriptor_list,
const ASDCP::Rational& edit_rate, const ui32_t& header_size = 16384,
const IndexStrategy_t& strategy = IS_FOLLOW, const ui32_t& partition_space = 10);
// Writes a frame of essence to the MXF file. If the optional AESEncContext
// argument is present, the essence is encrypted prior to writing.
// Fails if the file is not open, is finalized, or an operating system
// error occurs.
Result_t WriteFrame(const AS_02::PHDR::FrameBuffer&, ASDCP::AESEncContext* = 0, ASDCP::HMACContext* = 0);
// Closes the MXF file, writing the final index, the PHDR master metadata and the revised header.
Result_t Finalize(const std::string& PHDR_master_metadata);
};
//
class MXFReader
{
class h__Reader;
ASDCP::mem_ptr<h__Reader> m_Reader;
ASDCP_NO_COPY_CONSTRUCT(MXFReader);
public:
MXFReader();
virtual ~MXFReader();
// Warning: direct manipulation of MXF structures can interfere
// with the normal operation of the wrapper. Caveat emptor!
virtual ASDCP::MXF::OP1aHeader& OP1aHeader();
virtual AS_02::MXF::AS02IndexReader& AS02IndexReader();
virtual ASDCP::MXF::RIP& RIP();
// Open the file for reading. The file must exist. Returns error if the
// operation cannot be completed. If master metadata is available it will
// be placed into the string object passed as the second argument.
Result_t OpenRead(const std::string& filename, std::string& PHDR_master_metadata) const;
// Returns RESULT_INIT if the file is not open.
Result_t Close() const;
// Fill a WriterInfo struct with the values from the file's header.
// Returns RESULT_INIT if the file is not open.
Result_t FillWriterInfo(ASDCP::WriterInfo&) const;
// Reads a frame of essence from the MXF file. If the optional AESEncContext
// argument is present, the essence is decrypted after reading. If the MXF
// file is encrypted and the AESDecContext argument is NULL, the frame buffer
// will contain the ciphertext frame data. If the HMACContext argument is
// not NULL, the HMAC will be calculated (if the file supports it).
// Returns RESULT_INIT if the file is not open, failure if the frame number is
// out of range, or if optional decrypt or HAMC operations fail.
Result_t ReadFrame(ui32_t frame_number, AS_02::PHDR::FrameBuffer&, ASDCP::AESDecContext* = 0, ASDCP::HMACContext* = 0) const;
// Print debugging information to stream
void DumpHeaderMetadata(FILE* = 0) const;
void DumpIndex(FILE* = 0) const;
};
} // end namespace PHDR
} // end namespace AS_02
#endif // _AS_02_PHDR_H_
//
// end AS_02_PHDR.h
//
| [
"Alexandr"
] | Alexandr |
b4844f7ba9b5c77354f46f17b06ba5dfb1fd421b | 753f9b8f260e7cb57a4c9091737a8bfb203c09b4 | /Plugins/VaRestPlugin/Source/VaRest/Public/VaRestSubsystem.h | 3fae927edbde90d15b79704140fc9253b48bdd36 | [
"MIT"
] | permissive | cheburashkalev/Yandex.Music.UE4 | 784a4abe262bf0dded1cb8a21345634c43224a4a | 58ccc6d0145eca4627bdf3a1daed5df4f0261dc3 | refs/heads/main | 2023-08-15T04:00:41.004801 | 2021-10-09T09:46:30 | 2021-10-09T09:46:30 | 412,085,960 | 4 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,616 | h | // Copyright 2014-2020 Vladimir Alyamkin. All Rights Reserved.
#pragma once
#include "VaRestJsonObject.h"
#include "VaRestJsonValue.h"
#include "VaRestRequestJSON.h"
#include "Subsystems/EngineSubsystem.h"
#include "VaRestSubsystem.generated.h"
DECLARE_DYNAMIC_DELEGATE_OneParam(FVaRestCallDelegate, UVaRestRequestJSON*, Request);
USTRUCT()
struct FVaRestCallResponse
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
UVaRestRequestJSON* Request;
UPROPERTY()
FVaRestCallDelegate Callback;
FDelegateHandle CompleteDelegateHandle;
FDelegateHandle FailDelegateHandle;
FVaRestCallResponse()
: Request(nullptr)
{
}
};
UCLASS()
class VAREST_API UVaRestSubsystem : public UEngineSubsystem
{
GENERATED_BODY()
public:
UVaRestSubsystem();
// Begin USubsystem
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override;
// End USubsystem
//////////////////////////////////////////////////////////////////////////
// Easy URL processing
public:
/** Easy way to process http requests */
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility")
void CallURL(const FString& URL, EVaRestRequestVerb Verb, EVaRestRequestContentType ContentType, UVaRestJsonObject* VaRestJson, const FVaRestCallDelegate& Callback);
/** Called when URL is processed (one for both success/unsuccess events)*/
void OnCallComplete(UVaRestRequestJSON* Request);
protected:
UPROPERTY()
TMap<UVaRestRequestJSON*, FVaRestCallResponse> RequestMap;
//////////////////////////////////////////////////////////////////////////
// Construction helpers
public:
/** Creates new request (totally empty) */
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Request (Empty)"), Category = "VaRest|Subsystem")
UVaRestRequestJSON* ConstructVaRestRequest();
/** Creates new request with defined verb and content type */
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Request"), Category = "VaRest|Subsystem")
UVaRestRequestJSON* ConstructVaRestRequestExt(EVaRestRequestVerb Verb, EVaRestRequestContentType ContentType);
/** Create new Json object */
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Object"), Category = "VaRest|Subsystem")
UVaRestJsonObject* ConstructVaRestJsonObject();
/** Create new Json object (static one for MakeJson node, hack for #293) */
UFUNCTION()
static UVaRestJsonObject* StaticConstructVaRestJsonObject();
/** Create new Json Number value
* Attn.!! float used instead of double to make the function blueprintable! */
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Number Value"), Category = "VaRest|Subsystem")
UVaRestJsonValue* ConstructJsonValueNumber(float Number);
/** Create new Json String value */
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json String Value"), Category = "VaRest|Subsystem")
UVaRestJsonValue* ConstructJsonValueString(const FString& StringValue);
/** Create new Json Bool value */
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Bool Value"), Category = "VaRest|Subsystem")
UVaRestJsonValue* ConstructJsonValueBool(bool InValue);
/** Create new Json Array value */
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Array Value"), Category = "VaRest|Subsystem")
UVaRestJsonValue* ConstructJsonValueArray(const TArray<UVaRestJsonValue*>& InArray);
/** Create new Json Object value */
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Object Value"), Category = "VaRest|Subsystem")
UVaRestJsonValue* ConstructJsonValueObject(UVaRestJsonObject* JsonObject);
/** Create new Json value from FJsonValue (to be used from VaRestJsonObject) */
UVaRestJsonValue* ConstructJsonValue(const TSharedPtr<FJsonValue>& InValue);
//////////////////////////////////////////////////////////////////////////
// Serialization
public:
/** Construct Json value from string */
UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem")
UVaRestJsonValue* DecodeJsonValue(const FString& JsonString);
/** Construct Json object from string */
UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem")
UVaRestJsonObject* DecodeJsonObject(const FString& JsonString);
//////////////////////////////////////////////////////////////////////////
// File system integration
public:
/**
* Load JSON from formatted text file
* @param bIsRelativeToContentDir if set to 'false' path is treated as absolute
*/
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility")
UVaRestJsonObject* LoadJsonFromFile(const FString& Path, const bool bIsRelativeToContentDir = true);
};
| [
"47310777+cheburashkalev@users.noreply.github.com"
] | 47310777+cheburashkalev@users.noreply.github.com |
b46f7d60633844c2925ce026a44e40c96c46e60b | 05b8ceb85880245663723fff23ffcf73c8e5c3e2 | /gm/fp_sample_chaining.cpp | 4ac66137ac166a0baa9d38ce476e9a3f066eca66 | [
"BSD-3-Clause"
] | permissive | RainwayApp/skia | 307e562bb197914f638e3d65b9ac1a62cbfc09dd | f5583b4936ad13c4efe170807fbaf9b2decd0618 | refs/heads/master | 2020-12-15T20:19:20.358046 | 2020-07-15T16:46:54 | 2020-07-15T16:46:54 | 235,236,299 | 2 | 0 | NOASSERTION | 2020-07-15T17:17:37 | 2020-01-21T02:02:45 | C++ | UTF-8 | C++ | false | false | 16,746 | cpp | /*
* Copyright 2019 Google LLC.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkFont.h"
#include "include/effects/SkRuntimeEffect.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrRenderTargetContextPriv.h"
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/ops/GrFillRectOp.h"
#include "tools/ToolUtils.h"
// Samples child with a constant (literal) matrix
// Scales along X
class ConstantMatrixEffect : public GrFragmentProcessor {
public:
static constexpr GrProcessor::ClassID CLASS_ID = (GrProcessor::ClassID) 3;
ConstantMatrixEffect(std::unique_ptr<GrFragmentProcessor> child)
: GrFragmentProcessor(CLASS_ID, kNone_OptimizationFlags) {
this->registerChild(std::move(child),
SkSL::SampleUsage::UniformMatrix(
"float3x3(float3(0.5, 0.0, 0.0), "
"float3(0.0, 1.0, 0.0), "
"float3(0.0, 0.0, 1.0))"));
}
const char* name() const override { return "ConstantMatrixEffect"; }
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bool onIsEqual(const GrFragmentProcessor& that) const override { return this == &that; }
std::unique_ptr<GrFragmentProcessor> clone() const override { return nullptr; }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
class Impl : public GrGLSLFragmentProcessor {
void emitCode(EmitArgs& args) override {
SkString sample = this->invokeChildWithMatrix(0, args);
args.fFragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, sample.c_str());
}
};
return new Impl;
}
};
// Samples child with a uniform matrix (functionally identical to GrMatrixEffect)
// Scales along Y
class UniformMatrixEffect : public GrFragmentProcessor {
public:
static constexpr GrProcessor::ClassID CLASS_ID = (GrProcessor::ClassID) 4;
UniformMatrixEffect(std::unique_ptr<GrFragmentProcessor> child)
: GrFragmentProcessor(CLASS_ID, kNone_OptimizationFlags) {
this->registerChild(std::move(child), SkSL::SampleUsage::UniformMatrix("matrix"));
}
const char* name() const override { return "UniformMatrixEffect"; }
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bool onIsEqual(const GrFragmentProcessor& that) const override { return this == &that; }
std::unique_ptr<GrFragmentProcessor> clone() const override { return nullptr; }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
class Impl : public GrGLSLFragmentProcessor {
void emitCode(EmitArgs& args) override {
fMatrixVar = args.fUniformHandler->addUniform(&args.fFp, kFragment_GrShaderFlag,
kFloat3x3_GrSLType, "matrix");
SkString sample = this->invokeChildWithMatrix(0, args);
args.fFragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, sample.c_str());
}
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& proc) override {
pdman.setSkMatrix(fMatrixVar, SkMatrix::Scale(1, 0.5f));
}
UniformHandle fMatrixVar;
};
return new Impl;
}
};
// Samples child with a variable matrix
// Translates along X
// Typically, kVariable would be due to multiple sample(matrix) invocations, but this artificially
// uses kVariable with a single (constant) matrix.
class VariableMatrixEffect : public GrFragmentProcessor {
public:
static constexpr GrProcessor::ClassID CLASS_ID = (GrProcessor::ClassID) 5;
VariableMatrixEffect(std::unique_ptr<GrFragmentProcessor> child)
: GrFragmentProcessor(CLASS_ID, kNone_OptimizationFlags) {
this->registerChild(std::move(child), SkSL::SampleUsage::VariableMatrix());
}
const char* name() const override { return "VariableMatrixEffect"; }
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bool onIsEqual(const GrFragmentProcessor& that) const override { return this == &that; }
std::unique_ptr<GrFragmentProcessor> clone() const override { return nullptr; }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
class Impl : public GrGLSLFragmentProcessor {
void emitCode(EmitArgs& args) override {
SkString sample = this->invokeChildWithMatrix(
0, args, "float3x3(1, 0, 0, 0, 1, 0, 8, 0, 1)");
args.fFragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, sample.c_str());
}
};
return new Impl;
}
};
// Samples child with explicit coords
// Translates along Y
class ExplicitCoordEffect : public GrFragmentProcessor {
public:
static constexpr GrProcessor::ClassID CLASS_ID = (GrProcessor::ClassID) 6;
ExplicitCoordEffect(std::unique_ptr<GrFragmentProcessor> child)
: GrFragmentProcessor(CLASS_ID, kNone_OptimizationFlags) {
this->registerChild(std::move(child), SkSL::SampleUsage::Explicit());
this->setUsesSampleCoordsDirectly();
}
const char* name() const override { return "ExplicitCoordEffect"; }
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bool onIsEqual(const GrFragmentProcessor& that) const override { return this == &that; }
std::unique_ptr<GrFragmentProcessor> clone() const override { return nullptr; }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
class Impl : public GrGLSLFragmentProcessor {
void emitCode(EmitArgs& args) override {
args.fFragBuilder->codeAppendf("float2 coord = %s + float2(0, 8);",
args.fSampleCoord);
SkString sample = this->invokeChild(0, args, "coord");
args.fFragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, sample.c_str());
}
};
return new Impl;
}
};
// Generates test pattern
class TestPatternEffect : public GrFragmentProcessor {
public:
static constexpr GrProcessor::ClassID CLASS_ID = (GrProcessor::ClassID) 7;
TestPatternEffect() : GrFragmentProcessor(CLASS_ID, kNone_OptimizationFlags) {
this->setUsesSampleCoordsDirectly();
}
const char* name() const override { return "TestPatternEffect"; }
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bool onIsEqual(const GrFragmentProcessor& that) const override { return this == &that; }
std::unique_ptr<GrFragmentProcessor> clone() const override { return nullptr; }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
class Impl : public GrGLSLFragmentProcessor {
void emitCode(EmitArgs& args) override {
auto fb = args.fFragBuilder;
fb->codeAppendf("float2 coord = %s / 64.0;", args.fSampleCoord);
fb->codeAppendf("coord = floor(coord * 4) / 3;");
fb->codeAppendf("%s = half4(half2(coord.rg), 0, 1);\n", args.fOutputColor);
}
};
return new Impl;
}
};
SkBitmap make_test_bitmap() {
SkBitmap bitmap;
bitmap.allocN32Pixels(64, 64);
SkCanvas canvas(bitmap);
SkFont font(ToolUtils::create_portable_typeface());
const char* alpha = "ABCDEFGHIJKLMNOP";
for (int i = 0; i < 16; ++i) {
int tx = i % 4,
ty = i / 4;
int x = tx * 16,
y = ty * 16;
SkPaint paint;
paint.setColor4f({ tx / 3.0f, ty / 3.0f, 0.0f, 1.0f });
canvas.drawRect(SkRect::MakeXYWH(x, y, 16, 16), paint);
paint.setColor4f({ (3-tx) / 3.0f, (3-ty)/3.0f, 1.0f, 1.0f });
canvas.drawSimpleText(alpha + i, 1, SkTextEncoding::kUTF8, x + 3, y + 13, font, paint);
}
return bitmap;
}
enum EffectType {
kConstant,
kUniform,
kVariable,
kExplicit,
};
static std::unique_ptr<GrFragmentProcessor> wrap(std::unique_ptr<GrFragmentProcessor> fp,
EffectType effectType) {
switch (effectType) {
case kConstant:
return std::unique_ptr<GrFragmentProcessor>(new ConstantMatrixEffect(std::move(fp)));
case kUniform:
return std::unique_ptr<GrFragmentProcessor>(new UniformMatrixEffect(std::move(fp)));
case kVariable:
return std::unique_ptr<GrFragmentProcessor>(new VariableMatrixEffect(std::move(fp)));
case kExplicit:
return std::unique_ptr<GrFragmentProcessor>(new ExplicitCoordEffect(std::move(fp)));
}
SkUNREACHABLE;
}
DEF_SIMPLE_GPU_GM(fp_sample_chaining, ctx, rtCtx, canvas, 380, 306) {
SkBitmap bmp = make_test_bitmap();
GrBitmapTextureMaker maker(ctx, bmp, GrImageTexGenPolicy::kDraw);
int x = 10, y = 10;
auto nextCol = [&] { x += (64 + 10); };
auto nextRow = [&] { x = 10; y += (64 + 10); };
auto draw = [&](std::initializer_list<EffectType> effects) {
// Enable TestPatternEffect to get a fully procedural inner effect. It's not quite as nice
// visually (no text labels in each box), but it avoids the extra GrMatrixEffect.
// Switching it on actually triggers *more* shader compilation failures.
#if 0
auto fp = std::unique_ptr<GrFragmentProcessor>(new TestPatternEffect());
#else
auto view = maker.view(GrMipMapped::kNo);
auto fp = GrTextureEffect::Make(std::move(view), maker.alphaType());
#endif
for (EffectType effectType : effects) {
fp = wrap(std::move(fp), effectType);
}
GrPaint paint;
paint.addColorFragmentProcessor(std::move(fp));
rtCtx->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::Translate(x, y),
SkRect::MakeIWH(64, 64));
nextCol();
};
// Reminder, in every case, the chain is more complicated than it seems, because the
// GrTextureEffect is wrapped in a GrMatrixEffect, which is subject to the same bugs that
// we're testing (particularly the bug about owner/base in UniformMatrixEffect).
// First row: no transform, then each one independently applied
draw({}); // Identity (4 rows and columns)
draw({ kConstant }); // Scale X axis by 2x (2 visible columns)
draw({ kUniform }); // Scale Y axis by 2x (2 visible rows)
draw({ kVariable }); // Translate left by 8px
draw({ kExplicit }); // Translate up by 8px
nextRow();
// Second row: transform duplicated
draw({ kConstant, kUniform }); // Scale XY by 2x (2 rows and columns)
draw({ kConstant, kConstant }); // Scale X axis by 4x (1 visible column)
draw({ kUniform, kUniform }); // Scale Y axis by 4x (1 visible row)
draw({ kVariable, kVariable }); // Translate left by 16px
draw({ kExplicit, kExplicit }); // Translate up by 16px
nextRow();
// Remember, these are applied inside out:
draw({ kConstant, kExplicit }); // Scale X by 2x and translate up by 8px
draw({ kConstant, kVariable }); // Scale X by 2x and translate left by 8px
draw({ kUniform, kVariable }); // Scale Y by 2x and translate left by 8px
draw({ kUniform, kExplicit }); // Scale Y by 2x and translate up by 8px
draw({ kVariable, kExplicit }); // Translate left and up by 8px
nextRow();
draw({ kExplicit, kExplicit, kConstant }); // Scale X by 2x and translate up by 16px
draw({ kVariable, kConstant }); // Scale X by 2x and translate left by 16px
draw({ kVariable, kVariable, kUniform }); // Scale Y by 2x and translate left by 16px
draw({ kExplicit, kUniform }); // Scale Y by 2x and translate up by 16px
draw({ kExplicit, kUniform, kVariable, kConstant }); // Scale XY by 2x and translate xy 16px
}
const char* gConstantMatrixSkSL = R"(
in shader child;
void main(float2 xy, inout half4 color) {
color = sample(child, float3x3(0.5, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0));
}
)";
const char* gUniformMatrixSkSL = R"(
in shader child;
uniform float3x3 matrix;
void main(float2 xy, inout half4 color) {
color = sample(child, matrix);
}
)";
// This form (uniform * constant) is currently detected as variable, thanks to our limited analysis
// when scanning for sample matrices. With that pulled into a separate local, it's highly unlikely
// we'll ever treat this as anything else.
const char* gVariableMatrixSkSL = R"(
in shader child;
uniform float3x3 matrix;
void main(float2 xy, inout half4 color) {
float3x3 varMatrix = matrix * 0.5;
color = sample(child, varMatrix);
}
)";
const char* gExplicitCoordSkSL = R"(
in shader child;
void main(float2 xy, inout half4 color) {
color = sample(child, xy + float2(0, 8));
}
)";
// Version of fp_sample_chaining that uses SkRuntimeEffect
DEF_SIMPLE_GM(sksl_sample_chaining, canvas, 380, 306) {
SkBitmap bmp = make_test_bitmap();
sk_sp<SkRuntimeEffect> effects[4] = {
std::get<0>(SkRuntimeEffect::Make(SkString(gConstantMatrixSkSL))),
std::get<0>(SkRuntimeEffect::Make(SkString(gUniformMatrixSkSL))),
std::get<0>(SkRuntimeEffect::Make(SkString(gVariableMatrixSkSL))),
std::get<0>(SkRuntimeEffect::Make(SkString(gExplicitCoordSkSL))),
};
canvas->translate(10, 10);
canvas->save();
auto nextCol = [&] { canvas->translate(64 + 10, 0); };
auto nextRow = [&] { canvas->restore(); canvas->translate(0, 64 + 10); canvas->save(); };
auto draw = [&](std::initializer_list<EffectType> effectTypes) {
auto shader = bmp.makeShader();
for (EffectType effectType : effectTypes) {
SkRuntimeShaderBuilder builder(effects[effectType]);
builder.child("child") = shader;
switch (effectType) {
case kUniform:
builder.input("matrix") = SkMatrix::Scale(1.0f, 0.5f);
break;
case kVariable:
builder.input("matrix") = SkMatrix::Translate(8, 0);
break;
default:
break;
}
shader = builder.makeShader(nullptr, true);
}
SkPaint paint;
paint.setShader(shader);
canvas->drawRect(SkRect::MakeWH(64, 64), paint);
nextCol();
};
// Reminder, in every case, the chain is more complicated than it seems, because the
// GrTextureEffect is wrapped in a GrMatrixEffect, which is subject to the same bugs that
// we're testing (particularly the bug about owner/base in UniformMatrixEffect).
// First row: no transform, then each one independently applied
draw({}); // Identity (4 rows and columns)
draw({ kConstant }); // Scale X axis by 2x (2 visible columns)
draw({ kUniform }); // Scale Y axis by 2x (2 visible rows)
draw({ kVariable }); // Translate left by 8px
draw({ kExplicit }); // Translate up by 8px
nextRow();
// Second row: transform duplicated
draw({ kConstant, kUniform }); // Scale XY by 2x (2 rows and columns)
draw({ kConstant, kConstant }); // Scale X axis by 4x (1 visible column)
draw({ kUniform, kUniform }); // Scale Y axis by 4x (1 visible row)
draw({ kVariable, kVariable }); // Translate left by 16px
draw({ kExplicit, kExplicit }); // Translate up by 16px
nextRow();
// Remember, these are applied inside out:
draw({ kConstant, kExplicit }); // Scale X by 2x and translate up by 8px
draw({ kConstant, kVariable }); // Scale X by 2x and translate left by 8px
draw({ kUniform, kVariable }); // Scale Y by 2x and translate left by 8px
draw({ kUniform, kExplicit }); // Scale Y by 2x and translate up by 8px
draw({ kVariable, kExplicit }); // Translate left and up by 8px
nextRow();
draw({ kExplicit, kExplicit, kConstant }); // Scale X by 2x and translate up by 16px
draw({ kVariable, kConstant }); // Scale X by 2x and translate left by 16px
draw({ kVariable, kVariable, kUniform }); // Scale Y by 2x and translate left by 16px
draw({ kExplicit, kUniform }); // Scale Y by 2x and translate up by 16px
draw({ kExplicit, kUniform, kVariable, kConstant }); // Scale XY by 2x and translate xy 16px
}
| [
"skia-commit-bot@chromium.org"
] | skia-commit-bot@chromium.org |
a11ad2b7827c668fe0c324ee4d14c58eed05c952 | 0641d87fac176bab11c613e64050330246569e5c | /tags/release-2-6-d01/source/test/intltest/calregts.h | 74243601aeac75dedb4dcef58bfd6f50ba883ab1 | [
"ICU"
] | permissive | svn2github/libicu_full | ecf883cedfe024efa5aeda4c8527f227a9dbf100 | f1246dcb7fec5a23ebd6d36ff3515ff0395aeb29 | refs/heads/master | 2021-01-01T17:00:58.555108 | 2015-01-27T16:59:40 | 2015-01-27T16:59:40 | 9,308,333 | 0 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 2,571 | h | /********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2001, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
#ifndef _CALENDARREGRESSIONTEST_
#define _CALENDARREGRESSIONTEST_
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#include "unicode/calendar.h"
#include "unicode/gregocal.h"
#include "intltest.h"
/**
* Performs regression test for Calendar
**/
class CalendarRegressionTest: public IntlTest {
// IntlTest override
void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
public:
void test4100311(void);
void test4074758(void);
void test4028518(void);
void test4031502(void) ;
void test4035301(void) ;
void test4040996(void) ;
void test4051765(void) ;
void test4059654(void) ;
void test4061476(void) ;
void test4070502(void) ;
void test4071197(void) ;
void test4071385(void) ;
void test4073929(void) ;
void test4083167(void) ;
void test4086724(void) ;
void test4092362(void) ;
void test4095407(void) ;
void test4096231(void) ;
void test4096539(void) ;
void test41003112(void) ;
void test4103271(void) ;
void test4106136(void) ;
void test4108764(void) ;
void test4114578(void) ;
void test4118384(void) ;
void test4125881(void) ;
void test4125892(void) ;
void test4141665(void) ;
void test4142933(void) ;
void test4145158(void) ;
void test4145983(void) ;
void test4147269(void) ;
void Test4149677(void) ;
void Test4162587(void) ;
void Test4165343(void) ;
void Test4166109(void) ;
void Test4167060(void) ;
void Test4197699(void);
void TestJ81(void);
void TestJ438(void);
void TestLeapFieldDifference(void);
void TestMalaysianInstance(void);
void TestWeekShift(void);
void TestTimeZoneTransitionAdd(void);
void printdate(GregorianCalendar *cal, const char *string);
void dowTest(UBool lenient) ;
static UDate getAssociatedDate(UDate d, UErrorCode& status);
static UDate makeDate(int32_t y, int32_t m = 0, int32_t d = 0, int32_t hr = 0, int32_t min = 0, int32_t sec = 0);
static const UDate EARLIEST_SUPPORTED_MILLIS;
static const UDate LATEST_SUPPORTED_MILLIS;
static const char* FIELD_NAME[];
protected:
UBool failure(UErrorCode status, const char* msg);
};
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif // _CALENDARREGRESSIONTEST_
//eof
| [
"(no author)@251d0590-4201-4cf1-90de-194747b24ca1"
] | (no author)@251d0590-4201-4cf1-90de-194747b24ca1 |
befe8e0d5eba478814dd4cdd8179b23230d9b40c | 869662062115ec5aeecf4f8164409cdcd661da1f | /src/main.cpp | c639fb35dab185db6d12a46f70af1aa317245349 | [] | no_license | kaloyanpenev/opengl-pbr | 80c641f85bf365c5bd4a29eb46870c3f0120992e | ddaca6347892049b5d560b71c8fbc1783bf0a538 | refs/heads/master | 2023-05-30T03:42:03.182552 | 2021-06-10T14:59:23 | 2021-06-10T14:59:23 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 7,554 | cpp | #include <SDL2/SDL.h>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/ext.hpp>
#include <iostream>
#include <exception>
#include <vector>
#include <windows.h>
#include "Shader.h"
#include "Camera.h"
#include "Time.h"
#include "Texture.h"
#include "Model.h"
#include "Framebuffer.h"
#include "Skybox.h"
int main(int argc, char *argv[])
{
// Global SDL state
// -------------------------------
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
throw std::exception();
}
SDL_GL_SetSwapInterval(0); //disable vsync evil
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16);
SDL_Window *window = SDL_CreateWindow("OpenGL PBR. FPS: ",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
WINDOW_WIDTH, WINDOW_HEIGHT,
SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
// Lock in mouse
//SDL_SetRelativeMouseMode(SDL_TRUE);
if (!SDL_GL_CreateContext(window))
{
throw std::exception();
}
// Global OpenGL state
// ---------------------------------
if (glewInit() != GLEW_OK)
{
throw std::exception();
}
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); // for skybox rendering
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); //// for lower mip levels in the pre-filter map.
// turn on multisample anti-aliasing
glEnable(GL_MULTISAMPLE);
//ensure multisampling is nicest quality
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
std::unique_ptr<Shader> lampShader = std::make_unique<Shader>("../src/shaders/pure-white.vert", "../src/shaders/pure-white.frag");
std::unique_ptr<Shader> skyboxShader = std::make_unique<Shader>("../src/shaders/skybox.vert", "../src/shaders/skybox.frag");
std::unique_ptr<Shader> pbrShader = std::make_unique<Shader>("../src/shaders/pbr.vert", "../src/shaders/pbr.frag");
//Max number of texture units that can be used concurrently from a model file is currently 9.
unsigned int skyboxSamplerID = 10;
//skybox - this also constructs maps for irradiance, prefilter and brdfLUT
std::shared_ptr<Skybox> skybox = std::make_shared<Skybox>("../assets/hdr/map.hdr", 2048);
//OTHER SKYBOXES
//std::shared_ptr<Skybox> skybox = std::make_shared<Skybox>("../assets/hdr/Road_to_MonumentValley_Ref.hdr", 2048);
//std::shared_ptr<Skybox> skybox = std::make_shared<Skybox>("../assets/hdr/Factory_Catwalk_2k.hdr", 2048);
//tv pbr
std::shared_ptr<Model> tv = std::make_shared<Model>("../assets/tv/tv.fbx");
tv->m_modelMatrix = glm::scale(tv->m_modelMatrix, glm::vec3(0.3f));
tv->m_modelMatrix = glm::rotate(tv->m_modelMatrix, glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
tv->m_modelMatrix = glm::translate(tv->m_modelMatrix, glm::vec3(-40.0f, 0.0f, -10.0f));
glm::vec3 lightPos[] {
glm::vec3{ 0.0f, 1.0f, 15.0f},
glm::vec3{ 25.0f, 3.0f, 10.0f},
glm::vec3{-25.0f, 3.0f, 10.0f},
};
glm::vec3 lightColors[] {
glm::vec3{300.0f, 300.0f, 300.0f},
glm::vec3{100.0f, 100.0f, 100.0f},
glm::vec3{100.0f, 100.0f, 100.0f},
};
//lamp 0
std::shared_ptr<Model> lamp0 = std::make_shared<Model>("../../assets/cube/cube.obj");
//lamp 1 - static
std::shared_ptr<Model> lamp1 = std::make_shared<Model>("../../assets/cube/cube.obj");
lamp1->m_modelMatrix = glm::translate(glm::mat4{ 1.0f }, lightPos[1]);
lamp1->m_modelMatrix = glm::scale(lamp1->m_modelMatrix, glm::vec3(0.2f, 0.2f, 0.2f));
//lamp 2 - static
std::shared_ptr<Model> lamp2 = std::make_shared<Model>("../../assets/cube/cube.obj");
lamp2->m_modelMatrix = glm::translate(glm::mat4{ 1.0f }, lightPos[2]);
lamp2->m_modelMatrix = glm::scale(lamp2->m_modelMatrix, glm::vec3{0.2f, 0.2f, 0.2f});
//camera
std::shared_ptr<Camera> cam1 = std::make_shared<Camera>(glm::vec3{ 0.0f, 0.0f, 15.0 });
bool quit = false;
float translation{ 0.0f };
pbrShader->Use();
//set irradiance map to higher texture units, to prevent
pbrShader->setInt("u_irradianceMap", skyboxSamplerID + 1);
pbrShader->setInt("u_prefilterMap", skyboxSamplerID + 2);
pbrShader->setInt("u_brdfLUT", skyboxSamplerID + 3);
for (unsigned int i = 0; i < sizeof(lightPos) / sizeof(lightPos[0]); i++)
{
pbrShader->setVec3("u_lightPos[" + std::to_string(i) + "]", lightPos[i]);
pbrShader->setVec3("u_lightColors[" + std::to_string(i) + "]", lightColors[i]);
}
pbrShader->StopUsing();
//SKYBOX////////////////////////////////////////////////
skyboxShader->Use();
skyboxShader->setInt("u_environmentCubemap", skyboxSamplerID);
skyboxShader->StopUsing();
//wireframe mode
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
Time::Update();
while (!quit)
{
SDL_Event e = { 0 };
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
{
quit = true;
}
else if (e.type == SDL_KEYDOWN)
{
//locking the cursor on F click
if (e.key.keysym.sym == SDLK_f)
{
if ((bool)SDL_GetRelativeMouseMode())
SDL_SetRelativeMouseMode(SDL_FALSE);
else
SDL_SetRelativeMouseMode(SDL_TRUE);
}
}
else if (e.type == SDL_MOUSEBUTTONDOWN)
{
//locking the cursor on mouse click
if ((bool)SDL_GetRelativeMouseMode())
SDL_SetRelativeMouseMode(SDL_FALSE);
else
SDL_SetRelativeMouseMode(SDL_TRUE);
}
else if (e.type == SDL_MOUSEMOTION)
{
//process mouse input
float deltaX = static_cast<float>(e.motion.xrel);
float deltaY = static_cast<float>(-e.motion.yrel);
cam1->ProcessMouseInput(deltaX, deltaY);
}
}
//time calculations
Time::Update();
Time::DisplayFPSinWindowTitle(window);
//window resizing calculation
int width = 0;
int height = 0;
SDL_GetWindowSize(window, &width, &height);
glViewport(0, 0, width, height);
//camera updates
cam1->ProcessKeyboardInput();
cam1->ProcessZoom();
cam1->ProcessWindowResizing(width, height);
//glBindFramebuffer(GL_FRAMEBUFFER, framebuf1->GetID());
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
pbrShader->Use();
pbrShader->setVec3("u_viewPos", cam1->getPosition());
pbrShader->setVec3("u_lightPos[0]", lightPos[0]);
pbrShader->setViewAndProjectionMatrix(*cam1, true);
// bind pre-computed IBL data
glActiveTexture(GL_TEXTURE0 + skyboxSamplerID + 1);
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox->GetIrradianceMap().lock()->m_id);
glActiveTexture(GL_TEXTURE0 + skyboxSamplerID + 2);
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox->GetPrefilterMap().lock()->m_id);
glActiveTexture(GL_TEXTURE0 + skyboxSamplerID + 3);
glBindTexture(GL_TEXTURE_2D, skybox->GetBrdfLUT().lock()->m_id);
tv->RenderMeshes(*pbrShader);
pbrShader->StopUsing();
lampShader->Use();
//main lamp translation
float speed = 0.001f;
float range = 10.0f;
translation = glm::sin(SDL_GetTicks()*speed)*range; //oscillate
lightPos[0].x = translation;
lampShader->setViewAndProjectionMatrix(*cam1, true);
lamp0->m_modelMatrix = glm::translate(glm::mat4{ 1.0f }, lightPos[0]);
lamp0->m_modelMatrix = glm::scale(lamp0->m_modelMatrix, glm::vec3{ 0.4f });
lamp0->RenderMeshes(*lampShader);
lamp1->RenderMeshes(*lampShader);
lamp2->RenderMeshes(*lampShader);
lampShader->StopUsing();
///////////////////////SKYBOX//////////////////////
skyboxShader->Use();
skyboxShader->setViewAndProjectionMatrix(*cam1, true);
glActiveTexture(GL_TEXTURE0 + skyboxSamplerID);
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox->GetSkyboxMap().lock()->m_id);
skybox->RenderCube();
skyboxShader->StopUsing();
glBindVertexArray(0);
SDL_GL_SwapWindow(window);
Time::Reset();
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
} | [
"kaloyan42x@gmail.com"
] | kaloyan42x@gmail.com |
47c584f0ffffa0fe9b556947cab467a3f524bb2e | 9e44da9a999c2334f767eb1dd4ffb2ff9f5d6c84 | /P1928外星密码.cpp | 27b547baf454549d687854156eff71309c67fbda | [] | no_license | wanan429/LuoGu_Cpp | 04839d9dc012fe8432db17bb917702181b3926aa | 31ccd1128e49255151c7359f3d91eabe784c0f95 | refs/heads/master | 2023-06-10T15:01:12.129698 | 2021-06-28T15:06:25 | 2021-06-28T15:06:25 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 367 | cpp | #include "bits/stdc++.h"
#include "string"
using namespace std;
string node(){
int N;
string s = "",qt;
char c;
while(cin >> c){
if(c=='['){
cin >> N;
qt = node();
while(N--){
s+=qt;
}
}else{
if(c ==']'){
return s;
}else{
s +=c;
}
}
}
}
int main(){
cout << node();
return 0;
}
| [
"xuanrandev@qq.com"
] | xuanrandev@qq.com |
34c15df69b795bb03df42116934845aac12d1c07 | 9923a00a9afcd97c2fb02f6ed615adea3fc3fe1d | /Branch/Deprecated/SickLDMRS/datatypes/FieldDescription.cpp | e0ca5076659c74b465ffcd5d119c8dfdbbd95a34 | [
"MIT"
] | permissive | Tsinghua-OpenICV/OpenICV | 93df0e3dda406a5b8958f50ee763756a45182bf3 | 3bdb2ba744fabe934b31e36ba9c1e6ced2d5e6fc | refs/heads/master | 2022-03-02T03:09:02.236509 | 2021-12-26T08:09:42 | 2021-12-26T08:09:42 | 225,785,128 | 13 | 9 | null | 2020-08-06T02:42:03 | 2019-12-04T05:17:57 | C++ | UTF-8 | C++ | false | false | 634 | cpp | /*
* FieldDescription.cpp
*
* Created on: 30.08.2011
* Author: wahnfla
*/
#include "FieldDescription.hpp"
#include "../tools/errorhandler.hpp"
namespace datatypes
{
FieldDescription::FieldDescription() :
m_fieldType(Undefined)
{
m_datatype = Datatype_FieldDescription;
}
//
//
//
std::string FieldDescription::fieldTypeToString(FieldType type)
{
switch (type)
{
case Segmented:
return "Segmented";
case Rectangle:
return "Rectangle";
case Radial:
return "Radial";
case Dynamic:
return "Dynamic";
default:
return "undefined";
}
}
} // namespace datatypes
| [
"synsin0@outlook.com"
] | synsin0@outlook.com |
fb617860d3220b89047d992f74dc74745b6172be | 98d075fd10bd084fd0972adb1320b78090a09ad9 | /testapp/stdafx.h | 4dffc357d6fd3df4d14cdff3bf0cfe585ac12427 | [] | no_license | mssmax/scratch | c4fe33567f0722b5b8b5de126f622a5b2b4dd107 | 5b3dc920ccc028a5a862a4f3f64187091a07608b | refs/heads/master | 2020-09-25T12:15:02.890504 | 2017-04-29T17:58:05 | 2017-04-29T17:58:05 | 66,651,672 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 448 | h | // stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <Windows.h>
#include <Sddl.h>
#include <AclAPI.h>
#include <tchar.h>
#include <strsafe.h>
#include <stdio.h>
#import <msxml6.dll> rename_namespace("MSXML")
#include <string>
#include <list>
#include "OutputDebugStringEx.h" | [
"max@gfi.com"
] | max@gfi.com |
658ba10a326f3f26dd7a402fb4da8a8a5e65c423 | 8afb5afd38548c631f6f9536846039ef6cb297b9 | /_REPO/MICROSOFT/cocos2d-x/cocos/editor-support/cocostudio/CCActionManagerEx.h | 772497bf15ce2315ad07696cec6e89be38c7b8e9 | [
"MIT"
] | permissive | bgoonz/UsefulResourceRepo2.0 | d87588ffd668bb498f7787b896cc7b20d83ce0ad | 2cb4b45dd14a230aa0e800042e893f8dfb23beda | refs/heads/master | 2023-03-17T01:22:05.254751 | 2022-08-11T03:18:22 | 2022-08-11T03:18:22 | 382,628,698 | 10 | 12 | MIT | 2022-10-10T14:13:54 | 2021-07-03T13:58:52 | null | UTF-8 | C++ | false | false | 3,794 | h | /****************************************************************************
Copyright (c) 2013-2017 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __ActionMANAGER_H__
#define __ActionMANAGER_H__
#include "editor-support/cocostudio/CCActionObject.h"
#include "editor-support/cocostudio/DictionaryHelper.h"
#include "editor-support/cocostudio/CocosStudioExport.h"
namespace cocostudio {
class CocoLoader;
struct stExpCocoNode;
class CC_STUDIO_DLL ActionManagerEx:public cocos2d::Ref
{
public:
/**
* Default constructor
* @js ctor
*/
ActionManagerEx();
/**
* Default destructor
* @js NA
* @lua NA
*/
virtual ~ActionManagerEx();
/**
* Gets the static instance of ActionManager.
* @js getInstance
* @lua getInstance
*/
static ActionManagerEx* getInstance();
/**
* Purges ActionManager point.
* @js purge
* @lua destroyActionManager
*/
static void destroyInstance();
/**
* Gets an ActionObject with a name.
*
* @param jsonName UI file name
*
* @param actionName action name in the UI file.
*
* @return ActionObject which named as the param name
*/
ActionObject* getActionByName(const char* jsonName,const char* actionName);
/**
* Play an Action with a name.
*
* @param jsonName UI file name
*
* @param actionName action name in the UIfile.
*
* @return ActionObject which named as the param name
*/
ActionObject* playActionByName(const char* jsonName,const char* actionName);
/**
* Play an Action with a name.
*
* @param jsonName UI file name
*
* @param actionName action name in the UIfile.
*
* @param func ui action call back
*/
ActionObject* playActionByName(const char* jsonName,const char* actionName, cocos2d::CallFunc* func);
/**
* Stop an Action with a name.
*
* @param jsonName UI file name
*
* @param actionName action name in the UIfile.
*
* @return ActionObject which named as the param name
*/
ActionObject* stopActionByName(const char* jsonName,const char* actionName);
/*init properties with json dictionary*/
void initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root, int version = 1600);
void initWithBinary(const char* file, Ref* root, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
/**
* Release all actions.
*
*/
void releaseActions();
int getStudioVersionNumber() const;
protected:
std::unordered_map<std::string, cocos2d::Vector<ActionObject*>> _actionDic;
int _studioVersionNumber;
};
}
#endif
| [
"bryan.guner@gmail.com"
] | bryan.guner@gmail.com |
951c754f8d7d7ffaf2c6afaa27e3d2ca2fe8e8d6 | 9fdb7597205151b7020c8dae34309ce461480ade | /Dijstra.cpp | ae1e2ae8ac28a9b7220e924fda609b7bdf37cca5 | [] | no_license | SownBanana/Applied-Algorithms | 853996f3d4f95f97dee339641659dc55aa83d730 | 7e6041447e821c5eb6ab0e55d5686ce3c0a1e7d4 | refs/heads/master | 2021-01-05T15:37:35.358243 | 2020-02-17T09:11:49 | 2020-02-17T09:11:49 | 241,063,836 | 1 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 2,840 | cpp | #include <iostream>
#include <vector>
#include <list>
#define MAX 100001
//using namespace std;
typedef struct a{
int u;
int w;
} pairWu;
int N,M;
int s,t; //start - target
std::vector<pairWu> A[MAX]; //tree
int p[MAX];
bool fixed[MAX];
//heap
int d[MAX]; //d[v] is the upper bound of the length of the shortest path from s to v;
int node[MAX]; //node[i] is the ith element(vertex -u and weight -w) in th HEAP
int idx[MAX]; //idx[v] is the index of v in the HEAP (idx[node[i].u] = i)
int sH; //size of HEAP
void input(){
std::cin>>N>>M;
for(int i = 0; i < M; i++){
int u;
pairWu v;
std::cin>>u>>v.u>>v.w;
A[u].push_back(v);
}
std::cin>>s>>t;
}
void swap(int i, int j){ //swap ith and jth elements of the HEAP
int tmp = node[i];
node[i] = node[j];
node[j] = tmp;
idx[node[i]] = i;
idx[node[j]] = j;
}
void upHeap(int i){
// printf("sH = %d", sH);
if(i == 0) return;
while(i>0){
int pi = (i-1)/2;
// printf("pi = %d\n", pi);
if(d[node[i]] < d[node[pi]]){
swap(i, pi);
}else{
break;
}
i = pi;
}
}
void downHeap(int i){
int L = 2*i + 1;
int R = 2*i +2;
int maxIdx = i;
if(L < sH && d[node[L]] < d[node[maxIdx]]) maxIdx = L;
if(R < sH && d[node[R]] < d[node[maxIdx]]) maxIdx = R;
if(maxIdx != i){
swap(i, maxIdx);
downHeap(maxIdx);
}
}
void insert(int v, int k){ //add element key = k, value = v into HEAP (v,d[v])
// printf("insert/n");
d[v] = k;
node[sH] = v;
idx[node[sH]] = sH;
upHeap(sH);
sH++;
}
int inHeap(int v){
// printf("%d o %d cua heap\n", v, idx[v]);
return idx[v];
}
void updateKey(int v, int k){
if(d[v] > k){
d[v] = k;
upHeap(v);
}
else{
downHeap(v);
}
}
int deleteMin(){
int sel_node = node[0];
swap(0, sH - 1);
sH--;
downHeap(0);
return sel_node;
}
void init(){
sH = 0;
for(int i = 1; i <= N; i++){
d[i] = 99999;
fixed[i] = false;
p[i] = 0;
idx[i] = -1;
}
for(int i = 0; i < A[s].size(); i++){
pairWu v = A[s][i];
// std::cout<<node[0]<<std::endl;
insert(v.u, v.w);
// std::cout<<node[0]<<std::endl;
}
fixed[s] = true;
}
void LOOP(){
while(sH>0){
int u = deleteMin();
fixed[u] = true;
// std::cout<<"d["<<u<<"] = "<<d[u]<<std::endl;
for(int i = 0; i < A[u].size(); i++){
pairWu v = A[u][i];
// std::cout<<"d["<<v.u<<"] = "<<d[v.u]<<std::endl;
// std::cout<<u<<"=>"<<v.u<<" = ";
// std::cout<<d[u] + v.w<<std::endl;
if(fixed[v.u]) continue;
if(inHeap(v.u) == -1){ //v.u <=> w(u,v)
// printf("%d vao heap\n", v.u);
int w = d[u] + v.w;
insert(v.u, w);
}
else{
if(d[v.u] > d[u] + v.w){
// printf("upadate %d\n", v.u);
updateKey(v.u, d[u] + v.w);
}
}
}
}
}
void solve(){
init();
LOOP();
int rs = d[t];
// if(!fixed[t]) rs = -1;
std::cout<<rs;
}
int main(){
input();
solve();
}
/*
5 7
2 5 87
1 2 97
4 5 78
3 1 72
1 4 19
2 3 63
5 1 18
1 5
*/
| [
"s.v.o.a.26@gmail.com"
] | s.v.o.a.26@gmail.com |
2554aa7eed1cb0523aba1a97e0c1fddf2bcc9861 | f416ab3adfb5c641dc84022f918df43985c19a09 | /problems/kattis/nsum/sol.cpp | 3d9289d3cadc156d604f9dcba385008a63ad50d5 | [] | no_license | NicoKNL/coding-problems | a4656e8423e8c7f54be1b9015a9502864f0b13a5 | 4c8c8d5da3cdf74aefcfad4e82066c4a4beb8c06 | refs/heads/master | 2023-07-26T02:00:35.834440 | 2023-07-11T22:47:13 | 2023-07-11T22:47:13 | 160,269,601 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 266 | cpp | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> V(n, 0);
for (int i = 0; i < n; ++i)
{
cin >> V[i];
}
int sum = accumulate(V.begin(), V.end(), 0);
cout << sum << endl;
return 0;
} | [
"klaassen.nico@gmail.com"
] | klaassen.nico@gmail.com |
103fe20f336afd3f64d3bc91262864ccbef27b9b | f38241a7b627c03a906a1a28b3ef9bc0f0b4cf24 | /src/blend2d/pipegen/blpipecompiler_p.h | 6442b6a6952060daddb02b75e4d5b89551715b02 | [
"LicenseRef-scancode-warranty-disclaimer",
"Zlib"
] | permissive | Sondro/blend2d | e2a0d9db5c60582490d233a38a2b880dbc8b3d3f | 337e969181a1e6e655c55d8e1dc015262178cc79 | refs/heads/master | 2020-05-16T12:49:54.308155 | 2019-04-21T22:36:53 | 2019-04-21T22:36:53 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 80,432 | h | // [Blend2D]
// 2D Vector Graphics Powered by a JIT Compiler.
//
// [License]
// ZLIB - See LICENSE.md file in the package.
#ifndef BLEND2D_PIPEGEN_BLPIPECOMPILER_P_H
#define BLEND2D_PIPEGEN_BLPIPECOMPILER_P_H
#include "../pipegen/blpipegencore_p.h"
#include "../pipegen/blpiperegusage_p.h"
//! \cond INTERNAL
//! \addtogroup blend2d_internal_pipegen
//! \{
namespace BLPipeGen {
// ============================================================================
// [BLPipeGen::PipeCompiler]
// ============================================================================
//! Pipeline compiler.
class PipeCompiler {
public:
BL_NONCOPYABLE(PipeCompiler)
//! AsmJit compiler.
x86::Compiler* cc;
//! Target CPU features.
x86::Features _features;
//! Optimization level.
uint32_t _optLevel;
//! Number of registers available to the pipeline compiler.
PipeRegUsage _availableRegs;
//! Estimation of registers used by the pipeline temporarily.
PipeRegUsage _temporaryRegs;
//! Estimation of registers used by the pipeline permanently.
PipeRegUsage _persistentRegs;
//! Function node.
asmjit::FuncNode* _funcNode;
//! Function initialization hook.
asmjit::BaseNode* _funcInit;
//! Function end hook (to add 'unlikely' branches).
asmjit::BaseNode* _funcEnd;
//! Invalid GP register.
x86::Gp _gpNone;
//! Holds `BLPipeFillFunc::ctxData` argument.
x86::Gp _ctxData;
//! Holds `BLPipeFillFunc::fillData` argument.
x86::Gp _fillData;
//! Holds `BLPipeFillFunc::fetchData` argument.
x86::Gp _fetchData;
//! Temporary stack used to transfer SIMD regs to GP/MM.
x86::Mem _tmpStack;
//! Offset to get real ctx-data from the passed pointer.
int _ctxDataOffset;
//! Offset to get real fill-data from the passed pointer.
int _fillDataOffset;
//! Offset to get real fetch-data from the passed pointer.
int _fetchDataOffset;
//! Offset to the first constant to the `blCommonTable` global.
int32_t _commonTableOff;
//! Pointer to the `blCommonTable` constant pool (only used in 64-bit mode).
x86::Gp _commonTablePtr;
//! XMM constants.
x86::Xmm _constantsXmm[4];
// --------------------------------------------------------------------------
// [PackedInst]
// --------------------------------------------------------------------------
//! Packing generic instructions and SSE+AVX instructions into a single 32-bit
//! integer.
//!
//! AsmJit has around 1400 instructions for X86|X64, which means that we need
//! at least 11 bits to represent each. Typically we need just one instruction
//! ID at a time, however, since SSE and AVX instructions use different IDs
//! we need a way to pack both SSE and AVX instruction ID into one integer as
//! it's much easier to use unified instruction set rather than using specific
//! paths for SSE and AVX code.
//!
//! PackedInst allows to specify the following:
//!
//! - SSE instruction ID for up to SSE4.2 code generation.
//! - AVX instruction ID for AVX+ code generation.
//! - Maximum operation width aka 0 (XMM), 1 (YMM) and 2 (ZMM).
//! - Special intrinsic used only by PipeCompiler.
struct PackedInst {
//! Limit width of operands of vector instructions to Xmm|Ymm|Zmm.
enum WidthLimit {
kWidthX = 0,
kWidthY = 1,
kWidthZ = 2
};
enum Bits {
kSseIdShift = 0,
kSseIdBits = 0xFFF,
kAvxIdShift = 12,
kAvxIdBits = 0xFFF,
kWidthShift = 24,
kWidthBits = 0x3,
kIntrinShift = 31,
kIntrinBits = 0x1
};
static inline uint32_t packIntrin(uint32_t intrinId, uint32_t width = kWidthZ) noexcept {
return (intrinId << kSseIdShift ) |
(width << kWidthShift ) |
(1u << kIntrinShift) ;
}
static inline uint32_t packAvxSse(uint32_t avxId, uint32_t sseId, uint32_t width = kWidthZ) noexcept {
return (avxId << kAvxIdShift) |
(sseId << kSseIdShift) |
(width << kWidthShift) ;
}
static inline uint32_t avxId(uint32_t packedId) noexcept { return (packedId >> kAvxIdShift) & kAvxIdBits; }
static inline uint32_t sseId(uint32_t packedId) noexcept { return (packedId >> kSseIdShift) & kSseIdBits; }
static inline uint32_t width(uint32_t packedId) noexcept { return (packedId >> kWidthShift) & kWidthBits; }
static inline uint32_t isIntrin(uint32_t packedId) noexcept { return (packedId & (kIntrinBits << kIntrinShift)) != 0; }
static inline uint32_t intrinId(uint32_t packedId) noexcept { return (packedId >> kSseIdShift) & kSseIdBits; }
};
//! Intrinsic ID.
//!
//! Some operations are not available as a single instruction or are part
//! of CPU extensions outside of the baseline instruction set. These are
//! handled as intrinsics.
enum IntrinId {
kIntrin2Vloadi128uRO,
kIntrin2Vmovu8u16,
kIntrin2Vmovu8u32,
kIntrin2Vmovu16u32,
kIntrin2Vabsi8,
kIntrin2Vabsi16,
kIntrin2Vabsi32,
kIntrin2Vabsi64,
kIntrin2Vinv255u16,
kIntrin2Vinv256u16,
kIntrin2Vinv255u32,
kIntrin2Vinv256u32,
kIntrin2Vduplpd,
kIntrin2Vduphpd,
kIntrin2iVswizps,
kIntrin2iVswizpd,
kIntrin3Vcombhli64,
kIntrin3Vcombhld64,
kIntrin3Vminu16,
kIntrin3Vmaxu16,
kIntrin3Vmulu64x32,
kIntrin3Vhaddpd,
kIntrin4Vpblendvb
};
enum {
//! Number of reserved GP registers for general use.
//!
//! NOTE: In 32-bit mode constants are absolutely addressed, however, in
//! 64-bit mode we can't address arbitrary 64-bit pointers, so one more
//! register is reserved as a compensation.
kReservedGpRegs = 1 + uint32_t(BL_TARGET_ARCH_BITS >= 64),
//! Number of spare MM registers to always reserve.
kReservedMmRegs = 1,
//! Number of spare XMM|YMM|ZMM registers to always reserve.
kReservedVecRegs = 1
};
// --------------------------------------------------------------------------
// [Construction / Destruction]
// --------------------------------------------------------------------------
PipeCompiler(x86::Compiler* cc, const asmjit::x86::Features& features) noexcept;
~PipeCompiler() noexcept;
// --------------------------------------------------------------------------
// [Reset]
// --------------------------------------------------------------------------
void reset() noexcept;
// --------------------------------------------------------------------------
// [Optimization Level]
// --------------------------------------------------------------------------
void updateOptLevel() noexcept;
//! Get the optimization level of the compiler.
inline uint32_t optLevel() const noexcept { return _optLevel; }
//! Set the optimization level of the compiler.
inline void setOptLevel(uint32_t optLevel) noexcept { _optLevel = optLevel; }
inline bool hasSSE2() const noexcept { return _optLevel >= kOptLevel_X86_SSE2; }
inline bool hasSSE3() const noexcept { return _optLevel >= kOptLevel_X86_SSE3; }
inline bool hasSSSE3() const noexcept { return _optLevel >= kOptLevel_X86_SSSE3; }
inline bool hasSSE4_1() const noexcept { return _optLevel >= kOptLevel_X86_SSE4_1; }
inline bool hasSSE4_2() const noexcept { return _optLevel >= kOptLevel_X86_SSE4_2; }
inline bool hasAVX() const noexcept { return _optLevel >= kOptLevel_X86_AVX; }
inline bool hasAVX2() const noexcept { return _optLevel >= kOptLevel_X86_AVX2; }
inline bool hasADX() const noexcept { return _features.hasADX(); }
inline bool hasBMI() const noexcept { return _features.hasBMI(); }
inline bool hasBMI2() const noexcept { return _features.hasBMI2(); }
inline bool hasLZCNT() const noexcept { return _features.hasLZCNT(); }
inline bool hasPOPCNT() const noexcept { return _features.hasPOPCNT(); }
//! Tell the compiler to emit EMMS at the end of the function. Only called
//! if the pipeline compiler or some part of it uses MMX registers.
inline void usingMmx() noexcept { _funcNode->frame().setMmxCleanup(); }
// --------------------------------------------------------------------------
// [Data Offsets]
// --------------------------------------------------------------------------
inline int ctxDataOffset() const noexcept { return _ctxDataOffset; }
inline int fillDataOffset() const noexcept { return _fillDataOffset; }
inline int fetchDataOffset() const noexcept { return _fetchDataOffset; }
inline void setCtxDataOffset(int offset) noexcept { _ctxDataOffset = offset; }
inline void setFillDataOffset(int offset) noexcept { _fillDataOffset = offset; }
inline void setFetchDataOffset(int offset) noexcept { _fetchDataOffset = offset; }
// --------------------------------------------------------------------------
// [Compilation]
// --------------------------------------------------------------------------
void beginFunction() noexcept;
void endFunction() noexcept;
// --------------------------------------------------------------------------
// [Parts Management]
// --------------------------------------------------------------------------
// TODO: [PIPEGEN] There should be a getter on asmjit side that will return
// the `ZoneAllocator` object that can be used for these kind of purposes.
// It doesn't make sense to create another ZoneAllocator.
template<typename T>
inline T* newPartT() noexcept {
return new(cc->_codeZone.alloc(sizeof(T), 8)) T(this);
}
template<typename T, typename... Args>
inline T* newPartT(Args&&... args) noexcept {
return new(cc->_codeZone.alloc(sizeof(T), 8)) T(this, std::forward<Args>(args)...);
}
FillPart* newFillPart(uint32_t fillType, FetchPart* dstPart, CompOpPart* compOpPart) noexcept;
FetchPart* newFetchPart(uint32_t fetchType, uint32_t fetchPayload, uint32_t format) noexcept;
CompOpPart* newCompOpPart(uint32_t compOp, FetchPart* dstPart, FetchPart* srcPart) noexcept;
// --------------------------------------------------------------------------
// [Init]
// --------------------------------------------------------------------------
void initPipeline(PipePart* root) noexcept;
void onPreInitPart(PipePart* part) noexcept;
void onPostInitPart(PipePart* part) noexcept;
//! Generate a function of the given `signature`.
void compileFunc(uint32_t signature) noexcept;
// --------------------------------------------------------------------------
// [Constants]
// --------------------------------------------------------------------------
void _initCommonTablePtr() noexcept;
x86::Mem constAsMem(const void* c) noexcept;
x86::Xmm constAsXmm(const void* c) noexcept;
// --------------------------------------------------------------------------
// [Registers / Memory]
// --------------------------------------------------------------------------
BL_NOINLINE void newXmmArray(OpArray& dst, uint32_t n, const char* name) noexcept {
BL_ASSERT(n <= OpArray::kMaxSize);
// Set the counter here as we don't want to hit an assert in OpArray::operator[].
dst._size = n;
for (uint32_t i = 0; i < n; i++)
dst[i] = cc->newXmm("%s%u", name, i);
}
x86::Mem tmpStack(uint32_t size) noexcept;
// --------------------------------------------------------------------------
// [Emit - Commons]
// --------------------------------------------------------------------------
// Emit helpers used by GP and MMX intrinsics.
void iemit2(uint32_t instId, const Operand_& op1, int imm) noexcept;
void iemit2(uint32_t instId, const Operand_& op1, const Operand_& op2) noexcept;
void iemit3(uint32_t instId, const Operand_& op1, const Operand_& op2, int imm) noexcept;
// Emit helpers to emit MOVE from SrcT to DstT, used by pre-AVX instructions.
// The `width` parameter is important as it describes how many bytes to read
// in case that `src` is a memory location. It's important as some instructions
// like PMOVZXBW read only 8 bytes, but to make the same operation in pre-SSE4.1
// code we need to read 8 bytes from memory and use PUNPCKLBW to interleave that
// bytes with zero. PUNPCKLBW would read 16 bytes from memory and would require
// them to be aligned to 16 bytes, if used with memory operand.
void vemit_xmov(const Operand_& dst, const Operand_& src, uint32_t width) noexcept;
void vemit_xmov(const OpArray& dst, const Operand_& src, uint32_t width) noexcept;
void vemit_xmov(const OpArray& dst, const OpArray& src, uint32_t width) noexcept;
// Emit helpers used by SSE|AVX intrinsics.
void vemit_vv_vv(uint32_t packedId, const Operand_& dst_, const Operand_& src_) noexcept;
void vemit_vv_vv(uint32_t packedId, const OpArray& dst_, const Operand_& src_) noexcept;
void vemit_vv_vv(uint32_t packedId, const OpArray& dst_, const OpArray& src_) noexcept;
void vemit_vvi_vi(uint32_t packedId, const Operand_& dst_, const Operand_& src_, int imm) noexcept;
void vemit_vvi_vi(uint32_t packedId, const OpArray& dst_, const Operand_& src_, int imm) noexcept;
void vemit_vvi_vi(uint32_t packedId, const OpArray& dst_, const OpArray& src_, int imm) noexcept;
void vemit_vvi_vvi(uint32_t packedId, const Operand_& dst_, const Operand_& src_, int imm) noexcept;
void vemit_vvi_vvi(uint32_t packedId, const OpArray& dst_, const Operand_& src_, int imm) noexcept;
void vemit_vvi_vvi(uint32_t packedId, const OpArray& dst_, const OpArray& src_, int imm) noexcept;
void vemit_vvv_vv(uint32_t packedId, const Operand_& dst_, const Operand_& src1_, const Operand_& src2_) noexcept;
void vemit_vvv_vv(uint32_t packedId, const OpArray& dst_, const Operand_& src1_, const OpArray& src2_) noexcept;
void vemit_vvv_vv(uint32_t packedId, const OpArray& dst_, const OpArray& src1_, const Operand_& src2_) noexcept;
void vemit_vvv_vv(uint32_t packedId, const OpArray& dst_, const OpArray& src1_, const OpArray& src2_) noexcept;
void vemit_vvvi_vvi(uint32_t packedId, const Operand_& dst_, const Operand_& src1_, const Operand_& src2_, int imm) noexcept;
void vemit_vvvi_vvi(uint32_t packedId, const OpArray& dst_, const Operand_& src1_, const OpArray& src2_, int imm) noexcept;
void vemit_vvvi_vvi(uint32_t packedId, const OpArray& dst_, const OpArray& src1_, const Operand_& src2_, int imm) noexcept;
void vemit_vvvi_vvi(uint32_t packedId, const OpArray& dst_, const OpArray& src1_, const OpArray& src2_, int imm) noexcept;
void vemit_vvvv_vvv(uint32_t packedId, const Operand_& dst_, const Operand_& src1_, const Operand_& src2_, const Operand_& src3_) noexcept;
void vemit_vvvv_vvv(uint32_t packedId, const OpArray& dst_, const OpArray& src1_, const OpArray& src2_, const Operand_& src3_) noexcept;
void vemit_vvvv_vvv(uint32_t packedId, const OpArray& dst_, const OpArray& src1_, const OpArray& src2_, const OpArray& src3_) noexcept;
#define I_EMIT_2(NAME, INST_ID) \
template<typename Op1, typename Op2> \
inline void NAME(const Op1& o1, \
const Op2& o2) noexcept { \
iemit2(x86::Inst::kId##INST_ID, o1, o2); \
}
#define I_EMIT_3(NAME, INST_ID) \
template<typename Op1, typename Op2, typename Op3> \
inline void NAME(const Op1& o1, \
const Op2& o2, \
const Op3& o3) noexcept { \
iemit3(x86::Inst::kId##INST_ID, o1, o2, o3); \
}
#define V_EMIT_VV_VV(NAME, PACKED_ID) \
template<typename DstT, typename SrcT> \
inline void NAME(const DstT& dst, \
const SrcT& src) noexcept { \
vemit_vv_vv(PACKED_ID, dst, src); \
}
#define V_EMIT_VVI_VI(NAME, PACKED_ID) \
template<typename DstT, typename SrcT> \
inline void NAME(const DstT& dst, \
const SrcT& src, \
int imm) noexcept { \
vemit_vvi_vi(PACKED_ID, dst, src, imm); \
}
#define V_EMIT_VVI_VVI(NAME, PACKED_ID) \
template<typename DstT, typename SrcT> \
inline void NAME(const DstT& dst, \
const SrcT& src, \
int imm) noexcept { \
vemit_vvi_vvi(PACKED_ID, dst, src, imm); \
}
#define V_EMIT_VVi_VVi(NAME, PACKED_ID, IMM_VALUE) \
template<typename DstT, typename SrcT> \
inline void NAME(const DstT& dst, \
const SrcT& src) noexcept { \
vemit_vvi_vvi(PACKED_ID, dst, src, IMM_VALUE); \
}
#define V_EMIT_VVV_VV(NAME, PACKED_ID) \
template<typename DstT, typename Src1T, typename Src2T> \
inline void NAME(const DstT& dst, \
const Src1T& src1, \
const Src2T& src2) noexcept { \
vemit_vvv_vv(PACKED_ID, dst, src1, src2); \
}
#define V_EMIT_VVVI_VVI(NAME, PACKED_ID) \
template<typename DstT, typename Src1T, typename Src2T> \
inline void NAME(const DstT& dst, \
const Src1T& src1, \
const Src2T& src2, \
int imm) noexcept { \
vemit_vvvi_vvi(PACKED_ID, dst, src1, src2, imm); \
}
#define V_EMIT_VVVi_VVi(NAME, PACKED_ID, IMM_VALUE) \
template<typename DstT, typename Src1T, typename Src2T> \
inline void NAME(const DstT& dst, \
const Src1T& src1, \
const Src2T& src2) noexcept { \
vemit_vvvi_vvi(PACKED_ID, dst, src1, src2, IMM_VALUE); \
}
#define V_EMIT_VVVV_VVV(NAME, PACKED_ID) \
template<typename DstT, typename Src1T, typename Src2T, typename Src3T> \
inline void NAME(const DstT& dst, \
const Src1T& src1, \
const Src2T& src2, \
const Src3T& src3) noexcept { \
vemit_vvvv_vvv(PACKED_ID, dst, src1, src2, src3); \
}
#define PACK_AVX_SSE(AVX_ID, SSE_ID, W) \
PackedInst::packAvxSse(x86::Inst::kId##AVX_ID, x86::Inst::kId##SSE_ID, PackedInst::kWidth##W)
// --------------------------------------------------------------------------
// [Emit - 'I' General Purpose Instructions]
// --------------------------------------------------------------------------
template<typename A, typename B>
BL_NOINLINE void uZeroIfEq(const A& a, const B& b) noexcept {
Label L = cc->newLabel();
cc->cmp(a, b);
cc->jne(L);
cc->mov(a, 0);
cc->bind(L);
}
// dst = abs(src)
template<typename DstT, typename SrcT>
BL_NOINLINE void uAbs(const DstT& dst, const SrcT& src) noexcept {
if (dst.id() == src.id()) {
x86::Gp tmp = cc->newSimilarReg(dst, "@tmp");
cc->mov(tmp, dst);
cc->neg(dst);
cc->cmovs(dst, tmp);
}
else {
cc->mov(dst, src);
cc->neg(dst);
cc->cmovs(dst, src);
}
}
template<typename DstT, typename ValueT, typename LimitT>
BL_NOINLINE void uBound0ToN(const DstT& dst, const ValueT& value, const LimitT& limit) noexcept {
if (dst.id() == value.id()) {
x86::Gp zero = cc->newSimilarReg(dst, "@zero");
cc->xor_(zero, zero);
cc->cmp(dst, limit);
cc->cmova(dst, zero);
cc->cmovg(dst, limit);
}
else {
cc->xor_(dst, dst);
cc->cmp(value, limit);
cc->cmovbe(dst, value);
cc->cmovg(dst, limit);
}
}
template<typename DstT, typename SrcT>
BL_NOINLINE void uReflect(const DstT& dst, const SrcT& src) noexcept {
BL_ASSERT(dst.size() == src.size());
int nBits = int(dst.size()) * 8 - 1;
if (dst.id() == src.id()) {
DstT copy = cc->newSimilarReg(dst, "@copy");
cc->mov(copy, dst);
cc->sar(copy, nBits);
cc->xor_(dst, copy);
}
else {
cc->mov(dst, src);
cc->sar(dst, nBits);
cc->xor_(dst, src);
}
}
template<typename DstT, typename SrcT>
BL_NOINLINE void uMod(const DstT& dst, const SrcT& src) noexcept {
x86::Gp mod = cc->newSimilarReg(dst, "@mod");
cc->xor_(mod, mod);
cc->div(mod, dst, src);
cc->mov(dst, mod);
}
BL_NOINLINE void uAdvanceAndDecrement(const x86::Gp& p, int pAdd, const x86::Gp& i, int iDec) noexcept {
cc->add(p, pAdd);
cc->sub(i, iDec);
}
//! dst = a * b.
BL_NOINLINE void uMulImm(const x86::Gp& dst, const x86::Gp& a, int b) noexcept {
if (b > 0) {
switch (b) {
case 1:
if (dst.id() != a.id())
cc->mov(dst, a);
return;
case 2:
if (dst.id() == a.id())
cc->shl(dst, 1);
else
cc->lea(dst, x86::ptr(a, a, 0));
return;
case 3:
cc->lea(dst, x86::ptr(a, a, 1));
return;
case 4:
case 8: {
int shift = 2 + (b == 8);
if (dst.id() == a.id())
cc->shl(dst, shift);
else
break;
// cc->lea(dst, x86::ptr(uint64_t(0), a, shift));
return;
}
}
}
if (dst.id() == a.id())
cc->imul(dst, b);
else
cc->imul(dst, a, b);
}
//! dst += a * b.
BL_NOINLINE void uAddMulImm(const x86::Gp& dst, const x86::Gp& a, int b) noexcept {
switch (b) {
case 1:
cc->add(dst, a);
return;
case 2:
case 4:
case 8: {
int shift = b == 2 ? 1 :
b == 4 ? 2 : 3;
cc->lea(dst, x86::ptr(dst, a, shift));
return;
}
default: {
x86::Gp tmp = cc->newSimilarReg(dst, "tmp");
cc->imul(tmp, a, b);
cc->add(dst, tmp);
return;
}
}
}
BL_NOINLINE void uLeaBpp(const x86::Gp& dst, const x86::Gp& src, const x86::Gp& idx, uint32_t scale, int32_t disp = 0) noexcept {
switch (scale) {
case 1:
if (dst.id() == src.id() && disp == 0)
cc->add(dst, idx);
else
cc->lea(dst, cc->intptr_ptr(src, idx, 0, disp));
break;
case 2:
cc->lea(dst, cc->intptr_ptr(src, idx, 1, disp));
break;
case 3:
cc->lea(dst, cc->intptr_ptr(src, idx, 1, disp));
cc->add(dst, idx);
break;
case 4:
cc->lea(dst, cc->intptr_ptr(src, idx, 2, disp));
break;
default:
BL_NOT_REACHED();
}
}
inline void uShl(const x86::Gp& dst, const x86::Gp& src) noexcept {
if (hasBMI2())
cc->shlx(dst, dst, src.cloneAs(dst));
else
cc->shl(dst, src.r8());
}
inline void uShr(const x86::Gp& dst, const x86::Gp& src) noexcept {
if (hasBMI2())
cc->shrx(dst, dst, src.cloneAs(dst));
else
cc->shr(dst, src.r8());
}
inline void uCTZ(const Operand& dst, const Operand& src) noexcept {
// INTEL - No difference, `bsf` and `tzcnt` both have latency ~2.5 cycles.
// AMD - Big difference, `tzcnt` has only ~1.5 cycle latency while `bsf` has ~2.5 cycles.
cc->emit(hasBMI() ? x86::Inst::kIdTzcnt : x86::Inst::kIdBsf, dst, src);
}
inline void uPrefetch(const x86::Mem& mem) noexcept {
cc->prefetcht0(mem);
}
// --------------------------------------------------------------------------
// [Emit - 'Q' Vector Instructions (64-bit MMX)]
// --------------------------------------------------------------------------
// MMX code should be considered legacy, however, CPUs don't penalize it. In
// 32-bit mode MMX can help with its 8 64-bit registers and instructions that
// allow pure 64-bit operations like addition and subtraction. To distinguish
// between MMX and SSE|AVX code all MMX instructions use 'q' (quad) prefix.
//
// NOTE: There are no instructions that allow transfer between MMX and XMM
// registers as that would conflict with AVX code, if used. Use MMX only if
// you don't need such transfer.
//
// MMX instructions that require SSE3+ are suffixed with `_` to make it clear
// that they are not part of the baseline instruction set.
I_EMIT_2(qmov32 , Movd) // MMX
I_EMIT_2(qmov64 , Movq) // MMX
I_EMIT_2(qmovmsku8 , Pmovmskb) // MMX2
I_EMIT_2(qabsi8_ , Pabsb) // SSSE3
I_EMIT_2(qabsi16_ , Pabsw) // SSSE3
I_EMIT_2(qabsi32_ , Pabsd) // SSSE3
I_EMIT_2(qavgu8 , Pavgb) // MMX2
I_EMIT_2(qavgu16 , Pavgw) // MMX2
I_EMIT_2(qsigni8_ , Psignb) // SSSE3
I_EMIT_2(qsigni16_ , Psignw) // SSSE3
I_EMIT_2(qsigni32_ , Psignd) // SSSE3
I_EMIT_2(qaddi8 , Paddb) // MMX
I_EMIT_2(qaddi16 , Paddw) // MMX
I_EMIT_2(qaddi32 , Paddd) // MMX
I_EMIT_2(qaddi64 , Paddq) // SSE2
I_EMIT_2(qaddsi8 , Paddsb) // MMX
I_EMIT_2(qaddsi16 , Paddsw) // MMX
I_EMIT_2(qaddsu8 , Paddusb) // MMX
I_EMIT_2(qaddsu16 , Paddusw) // MMX
I_EMIT_2(qsubi8 , Psubb) // MMX
I_EMIT_2(qsubi16 , Psubw) // MMX
I_EMIT_2(qsubi32 , Psubd) // MMX
I_EMIT_2(qsubi64 , Psubq) // SSE2
I_EMIT_2(qsubsi8 , Psubsb) // MMX
I_EMIT_2(qsubsi16 , Psubsw) // MMX
I_EMIT_2(qsubsu8 , Psubusb) // MMX
I_EMIT_2(qsubsu16 , Psubusw) // MMX
I_EMIT_2(qmuli16 , Pmullw) // MMX
I_EMIT_2(qmulu16 , Pmullw) // MMX
I_EMIT_2(qmulhi16 , Pmulhw) // MMX
I_EMIT_2(qmulhu16 , Pmulhuw) // MMX2
I_EMIT_2(qmulxllu32 , Pmuludq) // SSE2
I_EMIT_2(qand , Pand) // MMX
I_EMIT_2(qnand , Pandn) // MMX
I_EMIT_2(qor , Por) // MMX
I_EMIT_2(qxor , Pxor) // MMX
I_EMIT_2(qcmpeqi8 , Pcmpeqb) // MMX
I_EMIT_2(qcmpeqi16 , Pcmpeqw) // MMX
I_EMIT_2(qcmpeqi32 , Pcmpeqd) // MMX
I_EMIT_2(qcmpgti8 , Pcmpgtb) // MMX
I_EMIT_2(qcmpgti16 , Pcmpgtw) // MMX
I_EMIT_2(qcmpgti32 , Pcmpgtd) // MMX
I_EMIT_2(qminu8 , Pminub) // MMX2
I_EMIT_2(qmaxu8 , Pmaxub) // MMX2
I_EMIT_2(qmini16 , Pminsw) // MMX2
I_EMIT_2(qmaxi16 , Pmaxsw) // MMX2
I_EMIT_3(qinsertu16 , Pinsrw) // MMX2
I_EMIT_3(qextractu16, Pextrw) // MMX2
I_EMIT_2(qswizi8v_ , Pshufb) // SSSE3
I_EMIT_3(qswizi16 , Pshufw) // MMX2
I_EMIT_2(qslli16 , Psllw) // MMX
I_EMIT_2(qsrli16 , Psrlw) // MMX
I_EMIT_2(qsrai16 , Psraw) // MMX
I_EMIT_2(qslli32 , Pslld) // MMX
I_EMIT_2(qsrli32 , Psrld) // MMX
I_EMIT_2(qsrai32 , Psrad) // MMX
I_EMIT_2(qslli64 , Psllq) // MMX
I_EMIT_2(qsrli64 , Psrlq) // MMX
I_EMIT_2(qhaddi16_ , Phaddw) // SSSE3
I_EMIT_2(qhaddi32_ , Phaddd) // SSSE3
I_EMIT_2(qhsubi16_ , Phsubw) // SSSE3
I_EMIT_2(qhsubi32_ , Phsubd) // SSSE3
I_EMIT_2(qhaddsi16_ , Phaddsw) // SSSE3
I_EMIT_2(qhsubsi16_ , Phsubsw) // SSSE3
I_EMIT_3(qalignr8_ , Palignr) // SSE3
I_EMIT_2(qpacki32i16, Packssdw) // MMX
I_EMIT_2(qpacki16i8 , Packsswb) // MMX
I_EMIT_2(qpacki16u8 , Packuswb) // MMX
I_EMIT_2(qunpackli8 , Punpcklbw) // MMX
I_EMIT_2(qunpackhi8 , Punpckhbw) // MMX
I_EMIT_2(qunpackli16, Punpcklwd) // MMX
I_EMIT_2(qunpackhi16, Punpckhwd) // MMX
I_EMIT_2(qunpackli32, Punpckldq) // MMX
I_EMIT_2(qunpackhi32, Punpckhdq) // MMX
I_EMIT_2(qsadu8 , Psadbw) // MMX2
I_EMIT_2(qmulrhi16_ , Pmulhrsw) // SSSE3
I_EMIT_2(qmaddi16 , Pmaddwd) // MMX
I_EMIT_2(qmaddsu8i8_, Pmaddubsw) // SSSE3
inline void qzeropi(const Operand_& dst) noexcept { iemit2(x86::Inst::kIdPxor, dst, dst); }
inline void qswapi32(const Operand_& dst, const Operand_& src) noexcept { qswizi16(dst, src, x86::Predicate::shuf(1, 0, 3, 2)); }
inline void qdupli32(const Operand_& dst, const Operand_& src) noexcept { qswizi16(dst, src, x86::Predicate::shuf(1, 0, 1, 0)); }
inline void qduphi32(const Operand_& dst, const Operand_& src) noexcept { qswizi16(dst, src, x86::Predicate::shuf(3, 2, 3, 2)); }
// Multiplies 64-bit `a` (QWORD) with 32-bit `b` (low DWORD).
void qmulu64u32(const x86::Mm& d, const x86::Mm& a, const x86::Mm& b) noexcept;
// --------------------------------------------------------------------------
// [Emit - 'V' Vector Instructions (128..512-bit SSE|AVX)]
// --------------------------------------------------------------------------
// To make the code generation easier and more parametrizable we support both
// SSE|AVX through the same interface (always non-destructive source form) and
// each intrinsic can accept either `Operand_` or `OpArray`, which can hold up
// to 4 registers to form scalars, pairs and quads. Each 'V' instruction maps
// directly to the ISA so check the optimization level before using them or use
// instructions starting with 'x' that are generic and designed to map to the
// best instruction(s) possible.
//
// Also, multiple overloads are provided for convenience, similarly to AsmJit
// design, we don't want to inline expansion of `OpArray(op)` here so these
// overloads are implemented in pipecompiler.cpp.
// SSE instructions that require SSE3+ are suffixed with `_` to make it clear
// that they are not part of the baseline instruction set. Some instructions
// like that are always provided don't have such suffix, and will be emulated
// Integer SIMD - Core.
V_EMIT_VV_VV(vmov , PACK_AVX_SSE(Vmovaps , Movaps , Z)) // AVX | SSE2
V_EMIT_VV_VV(vmov64 , PACK_AVX_SSE(Vmovq , Movq , X)) // AVX | SSE2
V_EMIT_VV_VV(vmovi8i16_ , PACK_AVX_SSE(Vpmovsxbw , Pmovsxbw , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovu8u16_ , PACK_AVX_SSE(Vpmovzxbw , Pmovzxbw , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovi8i32_ , PACK_AVX_SSE(Vpmovsxbd , Pmovsxbd , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovu8u32_ , PACK_AVX_SSE(Vpmovzxbd , Pmovzxbd , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovi8i64_ , PACK_AVX_SSE(Vpmovsxbq , Pmovsxbq , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovu8u64_ , PACK_AVX_SSE(Vpmovzxbq , Pmovzxbq , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovi16i32_ , PACK_AVX_SSE(Vpmovsxwd , Pmovsxwd , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovu16u32_ , PACK_AVX_SSE(Vpmovzxwd , Pmovzxwd , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovi16i64_ , PACK_AVX_SSE(Vpmovsxwq , Pmovsxwq , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovu16u64_ , PACK_AVX_SSE(Vpmovzxwq , Pmovzxwq , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovi32i64_ , PACK_AVX_SSE(Vpmovsxdq , Pmovsxdq , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovu32u64_ , PACK_AVX_SSE(Vpmovzxdq , Pmovzxdq , Z)) // AVX2 | SSE4.1
V_EMIT_VV_VV(vmovmsku8 , PACK_AVX_SSE(Vpmovmskb , Pmovmskb , Z)) // AVX2 | SSE2
V_EMIT_VVVI_VVI(vinsertu8_ , PACK_AVX_SSE(Vpinsrb , Pinsrb , X)) // AVX2 | SSE4_1
V_EMIT_VVVI_VVI(vinsertu16 , PACK_AVX_SSE(Vpinsrw , Pinsrw , X)) // AVX2 | SSE2
V_EMIT_VVVI_VVI(vinsertu32_, PACK_AVX_SSE(Vpinsrd , Pinsrd , X)) // AVX2 | SSE4_1
V_EMIT_VVVI_VVI(vinsertu64_, PACK_AVX_SSE(Vpinsrq , Pinsrq , X)) // AVX2 | SSE4_1
V_EMIT_VVI_VVI(vextractu8_ , PACK_AVX_SSE(Vpextrb , Pextrb , X)) // AVX2 | SSE4_1
V_EMIT_VVI_VVI(vextractu16 , PACK_AVX_SSE(Vpextrw , Pextrw , X)) // AVX2 | SSE2
V_EMIT_VVI_VVI(vextractu32_, PACK_AVX_SSE(Vpextrd , Pextrd , X)) // AVX2 | SSE4_1
V_EMIT_VVI_VVI(vextractu64_, PACK_AVX_SSE(Vpextrq , Pextrq , X)) // AVX2 | SSE4_1
V_EMIT_VVV_VV(vunpackli8 , PACK_AVX_SSE(Vpunpcklbw , Punpcklbw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vunpackhi8 , PACK_AVX_SSE(Vpunpckhbw , Punpckhbw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vunpackli16 , PACK_AVX_SSE(Vpunpcklwd , Punpcklwd , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vunpackhi16 , PACK_AVX_SSE(Vpunpckhwd , Punpckhwd , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vunpackli32 , PACK_AVX_SSE(Vpunpckldq , Punpckldq , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vunpackhi32 , PACK_AVX_SSE(Vpunpckhdq , Punpckhdq , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vunpackli64 , PACK_AVX_SSE(Vpunpcklqdq, Punpcklqdq, Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vunpackhi64 , PACK_AVX_SSE(Vpunpckhqdq, Punpckhqdq, Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vpacki32i16 , PACK_AVX_SSE(Vpackssdw , Packssdw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vpacki32u16_ , PACK_AVX_SSE(Vpackusdw , Packusdw , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vpacki16i8 , PACK_AVX_SSE(Vpacksswb , Packsswb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vpacki16u8 , PACK_AVX_SSE(Vpackuswb , Packuswb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vswizi8v_ , PACK_AVX_SSE(Vpshufb , Pshufb , Z)) // AVX2 | SSSE3
V_EMIT_VVI_VVI(vswizli16 , PACK_AVX_SSE(Vpshuflw , Pshuflw , Z)) // AVX2 | SSE2
V_EMIT_VVI_VVI(vswizhi16 , PACK_AVX_SSE(Vpshufhw , Pshufhw , Z)) // AVX2 | SSE2
V_EMIT_VVI_VVI(vswizi32 , PACK_AVX_SSE(Vpshufd , Pshufd , Z)) // AVX2 | SSE2
V_EMIT_VVVI_VVI(vshufi32 , PACK_AVX_SSE(Vshufps , Shufps , Z)) // AVX | SSE
V_EMIT_VVVI_VVI(vshufi64 , PACK_AVX_SSE(Vshufpd , Shufpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vand , PACK_AVX_SSE(Vpand , Pand , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vandnot_a , PACK_AVX_SSE(Vpandn , Pandn , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vor , PACK_AVX_SSE(Vpor , Por , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vxor , PACK_AVX_SSE(Vpxor , Pxor , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vavgu8 , PACK_AVX_SSE(Vpavgb , Pavgb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vavgu16 , PACK_AVX_SSE(Vpavgw , Pavgw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vsigni8_ , PACK_AVX_SSE(Vpsignb , Psignb , Z)) // AVX2 | SSSE3
V_EMIT_VVV_VV(vsigni16_ , PACK_AVX_SSE(Vpsignw , Psignw , Z)) // AVX2 | SSSE3
V_EMIT_VVV_VV(vsigni32_ , PACK_AVX_SSE(Vpsignd , Psignd , Z)) // AVX2 | SSSE3
V_EMIT_VVV_VV(vaddi8 , PACK_AVX_SSE(Vpaddb , Paddb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vaddi16 , PACK_AVX_SSE(Vpaddw , Paddw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vaddi32 , PACK_AVX_SSE(Vpaddd , Paddd , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vaddi64 , PACK_AVX_SSE(Vpaddq , Paddq , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vaddsi8 , PACK_AVX_SSE(Vpaddsb , Paddsb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vaddsu8 , PACK_AVX_SSE(Vpaddusb , Paddusb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vaddsi16 , PACK_AVX_SSE(Vpaddsw , Paddsw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vaddsu16 , PACK_AVX_SSE(Vpaddusw , Paddusw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vsubi8 , PACK_AVX_SSE(Vpsubb , Psubb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vsubi16 , PACK_AVX_SSE(Vpsubw , Psubw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vsubi32 , PACK_AVX_SSE(Vpsubd , Psubd , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vsubi64 , PACK_AVX_SSE(Vpsubq , Psubq , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vsubsi8 , PACK_AVX_SSE(Vpsubsb , Psubsb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vsubsi16 , PACK_AVX_SSE(Vpsubsw , Psubsw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vsubsu8 , PACK_AVX_SSE(Vpsubusb , Psubusb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vsubsu16 , PACK_AVX_SSE(Vpsubusw , Psubusw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vmuli16 , PACK_AVX_SSE(Vpmullw , Pmullw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vmulu16 , PACK_AVX_SSE(Vpmullw , Pmullw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vmulhi16 , PACK_AVX_SSE(Vpmulhw , Pmulhw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vmulhu16 , PACK_AVX_SSE(Vpmulhuw , Pmulhuw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vmuli32_ , PACK_AVX_SSE(Vpmulld , Pmulld , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vmulu32_ , PACK_AVX_SSE(Vpmulld , Pmulld , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vmulxlli32_ , PACK_AVX_SSE(Vpmuldq , Pmuldq , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vmulxllu32 , PACK_AVX_SSE(Vpmuludq , Pmuludq , Z)) // AVX2 | SSE2
V_EMIT_VVVi_VVi(vmulxllu64_, PACK_AVX_SSE(Vpclmulqdq , Pclmulqdq , Z), 0x00) // AVX2 | PCLMULQDQ
V_EMIT_VVVi_VVi(vmulxhlu64_, PACK_AVX_SSE(Vpclmulqdq , Pclmulqdq , Z), 0x01) // AVX2 | PCLMULQDQ
V_EMIT_VVVi_VVi(vmulxlhu64_, PACK_AVX_SSE(Vpclmulqdq , Pclmulqdq , Z), 0x10) // AVX2 | PCLMULQDQ
V_EMIT_VVVi_VVi(vmulxhhu64_, PACK_AVX_SSE(Vpclmulqdq , Pclmulqdq , Z), 0x11) // AVX2 | PCLMULQDQ
V_EMIT_VVV_VV(vmini8_ , PACK_AVX_SSE(Vpminsb , Pminsb , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vmaxi8_ , PACK_AVX_SSE(Vpmaxsb , Pmaxsb , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vminu8 , PACK_AVX_SSE(Vpminub , Pminub , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vmaxu8 , PACK_AVX_SSE(Vpmaxub , Pmaxub , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vmini16 , PACK_AVX_SSE(Vpminsw , Pminsw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vmaxi16 , PACK_AVX_SSE(Vpmaxsw , Pmaxsw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vmini32_ , PACK_AVX_SSE(Vpminsd , Pminsd , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vmaxi32_ , PACK_AVX_SSE(Vpmaxsd , Pmaxsd , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vminu32_ , PACK_AVX_SSE(Vpminud , Pminud , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vmaxu32_ , PACK_AVX_SSE(Vpmaxud , Pmaxud , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vcmpeqi8 , PACK_AVX_SSE(Vpcmpeqb , Pcmpeqb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vcmpeqi16 , PACK_AVX_SSE(Vpcmpeqw , Pcmpeqw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vcmpeqi32 , PACK_AVX_SSE(Vpcmpeqd , Pcmpeqd , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vcmpeqi64_ , PACK_AVX_SSE(Vpcmpeqq , Pcmpeqq , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vcmpgti8 , PACK_AVX_SSE(Vpcmpgtb , Pcmpgtb , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vcmpgti16 , PACK_AVX_SSE(Vpcmpgtw , Pcmpgtw , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vcmpgti32 , PACK_AVX_SSE(Vpcmpgtd , Pcmpgtd , Z)) // AVX2 | SSE2
V_EMIT_VVV_VV(vcmpgti64_ , PACK_AVX_SSE(Vpcmpgtq , Pcmpgtq , Z)) // AVX2 | SSE4.2
V_EMIT_VVI_VI(vslli16 , PACK_AVX_SSE(Vpsllw , Psllw , Z)) // AVX2 | SSE2
V_EMIT_VVI_VI(vsrli16 , PACK_AVX_SSE(Vpsrlw , Psrlw , Z)) // AVX2 | SSE2
V_EMIT_VVI_VI(vsrai16 , PACK_AVX_SSE(Vpsraw , Psraw , Z)) // AVX2 | SSE2
V_EMIT_VVI_VI(vslli32 , PACK_AVX_SSE(Vpslld , Pslld , Z)) // AVX2 | SSE2
V_EMIT_VVI_VI(vsrli32 , PACK_AVX_SSE(Vpsrld , Psrld , Z)) // AVX2 | SSE2
V_EMIT_VVI_VI(vsrai32 , PACK_AVX_SSE(Vpsrad , Psrad , Z)) // AVX2 | SSE2
V_EMIT_VVI_VI(vslli64 , PACK_AVX_SSE(Vpsllq , Psllq , Z)) // AVX2 | SSE2
V_EMIT_VVI_VI(vsrli64 , PACK_AVX_SSE(Vpsrlq , Psrlq , Z)) // AVX2 | SSE2
V_EMIT_VVI_VI(vslli128b , PACK_AVX_SSE(Vpslldq , Pslldq , Z)) // AVX2 | SSE2
V_EMIT_VVI_VI(vsrli128b , PACK_AVX_SSE(Vpsrldq , Psrldq , Z)) // AVX2 | SSE2
V_EMIT_VVVV_VVV(vblendv8_ , PACK_AVX_SSE(Vpblendvb , Pblendvb , Z)) // AVX2 | SSE4.1
V_EMIT_VVVI_VVI(vblend16_ , PACK_AVX_SSE(Vpblendw , Pblendw , Z)) // AVX2 | SSE4.1
V_EMIT_VVV_VV(vhaddi16_ , PACK_AVX_SSE(Vphaddw , Phaddw , Z)) // AVX2 | SSSE3
V_EMIT_VVV_VV(vhaddi32_ , PACK_AVX_SSE(Vphaddd , Phaddd , Z)) // AVX2 | SSSE3
V_EMIT_VVV_VV(vhsubi16_ , PACK_AVX_SSE(Vphsubw , Phsubw , Z)) // AVX2 | SSSE3
V_EMIT_VVV_VV(vhsubi32_ , PACK_AVX_SSE(Vphsubd , Phsubd , Z)) // AVX2 | SSSE3
V_EMIT_VVV_VV(vhaddsi16_ , PACK_AVX_SSE(Vphaddsw , Phaddsw , Z)) // AVX2 | SSSE3
V_EMIT_VVV_VV(vhsubsi16_ , PACK_AVX_SSE(Vphsubsw , Phsubsw , Z)) // AVX2 | SSSE3
// Integer SIMD - Miscellaneous.
V_EMIT_VV_VV(vtest_ , PACK_AVX_SSE(Vptest , Ptest , Z)) // AVX2 | SSE4_1
// Integer SIMD - Consult X86 manual before using these...
V_EMIT_VVV_VV(vsadu8 , PACK_AVX_SSE(Vpsadbw , Psadbw , Z)) // AVX2 | SSE2 [dst.u64[0..X] = SUM{0.7}(ABS(src1.u8[N] - src2.u8[N]))))]
V_EMIT_VVV_VV(vmulrhi16_ , PACK_AVX_SSE(Vpmulhrsw , Pmulhrsw , Z)) // AVX2 | SSSE3 [dst.i16[0..X] = ((((src1.i16[0] * src2.i16[0])) >> 14)) + 1)) >> 1))]
V_EMIT_VVV_VV(vmaddsu8i8_ , PACK_AVX_SSE(Vpmaddubsw , Pmaddubsw , Z)) // AVX2 | SSSE3 [dst.i16[0..X] = SAT(src1.u8[0] * src2.i8[0] + src1.u8[1] * src2.i8[1]))
V_EMIT_VVV_VV(vmaddi16 , PACK_AVX_SSE(Vpmaddwd , Pmaddwd , Z)) // AVX2 | SSE2 [dst.i32[0..X] = (src1.i16[0] * src2.i16[0] + src1.i16[1] * src2.i16[1]))
V_EMIT_VVVI_VVI(vmpsadu8_ , PACK_AVX_SSE(Vmpsadbw , Mpsadbw , Z)) // AVX2 | SSE4.1
V_EMIT_VVVI_VVI(valignr8_ , PACK_AVX_SSE(Vpalignr , Palignr , Z)) // AVX2 | SSSE3
V_EMIT_VV_VV(vhminposu16_ , PACK_AVX_SSE(Vphminposuw, Phminposuw, Z)) // AVX2 | SSE4_1
// Floating Point - Core.
V_EMIT_VV_VV(vmovaps , PACK_AVX_SSE(Vmovaps , Movaps , Z)) // AVX | SSE
V_EMIT_VV_VV(vmovapd , PACK_AVX_SSE(Vmovapd , Movapd , Z)) // AVX | SSE2
V_EMIT_VV_VV(vmovups , PACK_AVX_SSE(Vmovups , Movups , Z)) // AVX | SSE
V_EMIT_VV_VV(vmovupd , PACK_AVX_SSE(Vmovupd , Movupd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vmovlps2x , PACK_AVX_SSE(Vmovlps , Movlps , X)) // AVX | SSE
V_EMIT_VVV_VV(vmovhps2x , PACK_AVX_SSE(Vmovhps , Movhps , X)) // AVX | SSE
V_EMIT_VVV_VV(vmovlhps2x , PACK_AVX_SSE(Vmovlhps , Movlhps , X)) // AVX | SSE
V_EMIT_VVV_VV(vmovhlps2x , PACK_AVX_SSE(Vmovhlps , Movhlps , X)) // AVX | SSE
V_EMIT_VVV_VV(vmovlpd , PACK_AVX_SSE(Vmovlpd , Movlpd , X)) // AVX | SSE
V_EMIT_VVV_VV(vmovhpd , PACK_AVX_SSE(Vmovhpd , Movhpd , X)) // AVX | SSE
V_EMIT_VV_VV(vmovduplps_ , PACK_AVX_SSE(Vmovsldup , Movsldup , Z)) // AVX | SSE3
V_EMIT_VV_VV(vmovduphps_ , PACK_AVX_SSE(Vmovshdup , Movshdup , Z)) // AVX | SSE3
V_EMIT_VV_VV(vmovduplpd_ , PACK_AVX_SSE(Vmovddup , Movddup , Z)) // AVX | SSE3
V_EMIT_VV_VV(vmovmskps , PACK_AVX_SSE(Vmovmskps , Movmskps , Z)) // AVX | SSE
V_EMIT_VV_VV(vmovmskpd , PACK_AVX_SSE(Vmovmskpd , Movmskpd , Z)) // AVX | SSE2
V_EMIT_VVI_VVI(vinsertss_ , PACK_AVX_SSE(Vinsertps , Insertps , X)) // AVX | SSE4_1
V_EMIT_VVI_VVI(vextractss_ , PACK_AVX_SSE(Vextractps , Extractps , X)) // AVX | SSE4_1
V_EMIT_VVV_VV(vunpacklps , PACK_AVX_SSE(Vunpcklps , Unpcklps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vunpacklpd , PACK_AVX_SSE(Vunpcklpd , Unpcklpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vunpackhps , PACK_AVX_SSE(Vunpckhps , Unpckhps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vunpackhpd , PACK_AVX_SSE(Vunpckhpd , Unpckhpd , Z)) // AVX | SSE2
V_EMIT_VVVI_VVI(vshufps , PACK_AVX_SSE(Vshufps , Shufps , Z)) // AVX | SSE
V_EMIT_VVVI_VVI(vshufpd , PACK_AVX_SSE(Vshufpd , Shufpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vandps , PACK_AVX_SSE(Vandps , Andps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vandpd , PACK_AVX_SSE(Vandpd , Andpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vandnot_aps , PACK_AVX_SSE(Vandnps , Andnps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vandnot_apd , PACK_AVX_SSE(Vandnpd , Andnpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vorps , PACK_AVX_SSE(Vorps , Orps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vorpd , PACK_AVX_SSE(Vorpd , Orpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vxorps , PACK_AVX_SSE(Vxorps , Xorps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vxorpd , PACK_AVX_SSE(Vxorpd , Xorpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vaddss , PACK_AVX_SSE(Vaddss , Addss , X)) // AVX | SSE
V_EMIT_VVV_VV(vaddsd , PACK_AVX_SSE(Vaddsd , Addsd , X)) // AVX | SSE2
V_EMIT_VVV_VV(vaddps , PACK_AVX_SSE(Vaddps , Addps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vaddpd , PACK_AVX_SSE(Vaddpd , Addpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vsubss , PACK_AVX_SSE(Vsubss , Subss , X)) // AVX | SSE
V_EMIT_VVV_VV(vsubsd , PACK_AVX_SSE(Vsubsd , Subsd , X)) // AVX | SSE2
V_EMIT_VVV_VV(vsubps , PACK_AVX_SSE(Vsubps , Subps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vsubpd , PACK_AVX_SSE(Vsubpd , Subpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vaddsubps_ , PACK_AVX_SSE(Vaddsubps , Addsubps , Z)) // AVX | SSE3
V_EMIT_VVV_VV(vaddsubpd_ , PACK_AVX_SSE(Vaddsubpd , Addsubpd , Z)) // AVX | SSE3
V_EMIT_VVV_VV(vmulss , PACK_AVX_SSE(Vmulss , Mulss , X)) // AVX | SSE
V_EMIT_VVV_VV(vmulsd , PACK_AVX_SSE(Vmulsd , Mulsd , X)) // AVX | SSE2
V_EMIT_VVV_VV(vmulps , PACK_AVX_SSE(Vmulps , Mulps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vmulpd , PACK_AVX_SSE(Vmulpd , Mulpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vdivss , PACK_AVX_SSE(Vdivss , Divss , X)) // AVX | SSE
V_EMIT_VVV_VV(vdivsd , PACK_AVX_SSE(Vdivsd , Divsd , X)) // AVX | SSE2
V_EMIT_VVV_VV(vdivps , PACK_AVX_SSE(Vdivps , Divps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vdivpd , PACK_AVX_SSE(Vdivpd , Divpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vminss , PACK_AVX_SSE(Vminss , Minss , X)) // AVX | SSE
V_EMIT_VVV_VV(vminsd , PACK_AVX_SSE(Vminsd , Minsd , X)) // AVX | SSE2
V_EMIT_VVV_VV(vminps , PACK_AVX_SSE(Vminps , Minps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vminpd , PACK_AVX_SSE(Vminpd , Minpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vmaxss , PACK_AVX_SSE(Vmaxss , Maxss , X)) // AVX | SSE
V_EMIT_VVV_VV(vmaxsd , PACK_AVX_SSE(Vmaxsd , Maxsd , X)) // AVX | SSE2
V_EMIT_VVV_VV(vmaxps , PACK_AVX_SSE(Vmaxps , Maxps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vmaxpd , PACK_AVX_SSE(Vmaxpd , Maxpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vsqrtss , PACK_AVX_SSE(Vsqrtss , Sqrtss , X)) // AVX | SSE
V_EMIT_VVV_VV(vsqrtsd , PACK_AVX_SSE(Vsqrtsd , Sqrtsd , X)) // AVX | SSE2
V_EMIT_VV_VV(vsqrtps , PACK_AVX_SSE(Vsqrtps , Sqrtps , Z)) // AVX | SSE
V_EMIT_VV_VV(vsqrtpd , PACK_AVX_SSE(Vsqrtpd , Sqrtpd , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vrcpss , PACK_AVX_SSE(Vrcpss , Rcpss , X)) // AVX | SSE
V_EMIT_VV_VV(vrcpps , PACK_AVX_SSE(Vrcpps , Rcpps , Z)) // AVX | SSE
V_EMIT_VVV_VV(vrsqrtss , PACK_AVX_SSE(Vrsqrtss , Rsqrtss , X)) // AVX | SSE
V_EMIT_VV_VV(vrsqrtps , PACK_AVX_SSE(Vrsqrtps , Rsqrtps , Z)) // AVX | SSE
V_EMIT_VVVI_VVI(vdpps_ , PACK_AVX_SSE(Vdpps , Dpps , Z)) // AVX | SSE4.1
V_EMIT_VVVI_VVI(vdppd_ , PACK_AVX_SSE(Vdppd , Dppd , Z)) // AVX | SSE4.1
V_EMIT_VVVI_VVI(vroundss_ , PACK_AVX_SSE(Vroundss , Roundss , X)) // AVX | SSE4.1
V_EMIT_VVVI_VVI(vroundsd_ , PACK_AVX_SSE(Vroundsd , Roundsd , X)) // AVX | SSE4.1
V_EMIT_VVI_VVI(vroundps_ , PACK_AVX_SSE(Vroundps , Roundps , Z)) // AVX | SSE4.1
V_EMIT_VVI_VVI(vroundpd_ , PACK_AVX_SSE(Vroundpd , Roundpd , Z)) // AVX | SSE4.1
V_EMIT_VVVI_VVI(vcmpss , PACK_AVX_SSE(Vcmpss , Cmpss , X)) // AVX | SSE
V_EMIT_VVVI_VVI(vcmpsd , PACK_AVX_SSE(Vcmpsd , Cmpsd , X)) // AVX | SSE2
V_EMIT_VVVI_VVI(vcmpps , PACK_AVX_SSE(Vcmpps , Cmpps , Z)) // AVX | SSE
V_EMIT_VVVI_VVI(vcmppd , PACK_AVX_SSE(Vcmppd , Cmppd , Z)) // AVX | SSE2
V_EMIT_VVVV_VVV(vblendvps_ , PACK_AVX_SSE(Vblendvps , Blendvps , Z)) // AVX | SSE4.1
V_EMIT_VVVV_VVV(vblendvpd_ , PACK_AVX_SSE(Vblendvpd , Blendvpd , Z)) // AVX | SSE4.1
V_EMIT_VVVI_VVI(vblendps_ , PACK_AVX_SSE(Vblendps , Blendps , Z)) // AVX | SSE4.1
V_EMIT_VVVI_VVI(vblendpd_ , PACK_AVX_SSE(Vblendpd , Blendpd , Z)) // AVX | SSE4.1
V_EMIT_VV_VV(vcvti32ps , PACK_AVX_SSE(Vcvtdq2ps , Cvtdq2ps , Z)) // AVX | SSE2
V_EMIT_VV_VV(vcvtpdps , PACK_AVX_SSE(Vcvtpd2ps , Cvtpd2ps , Z)) // AVX | SSE2
V_EMIT_VV_VV(vcvti32pd , PACK_AVX_SSE(Vcvtdq2pd , Cvtdq2pd , Z)) // AVX | SSE2
V_EMIT_VV_VV(vcvtpspd , PACK_AVX_SSE(Vcvtps2pd , Cvtps2pd , Z)) // AVX | SSE2
V_EMIT_VV_VV(vcvtpsi32 , PACK_AVX_SSE(Vcvtps2dq , Cvtps2dq , Z)) // AVX | SSE2
V_EMIT_VV_VV(vcvtpdi32 , PACK_AVX_SSE(Vcvtpd2dq , Cvtpd2dq , Z)) // AVX | SSE2
V_EMIT_VV_VV(vcvttpsi32 , PACK_AVX_SSE(Vcvttps2dq , Cvttps2dq , Z)) // AVX | SSE2
V_EMIT_VV_VV(vcvttpdi32 , PACK_AVX_SSE(Vcvttpd2dq , Cvttpd2dq , Z)) // AVX | SSE2
V_EMIT_VVV_VV(vcvtsdss , PACK_AVX_SSE(Vcvtsd2ss , Cvtsd2ss , X)) // AVX | SSE2
V_EMIT_VVV_VV(vcvtsssd , PACK_AVX_SSE(Vcvtss2sd , Cvtss2sd , X)) // AVX | SSE2
V_EMIT_VVV_VV(vcvtsiss , PACK_AVX_SSE(Vcvtsi2ss , Cvtsi2ss , X)) // AVX | SSE
V_EMIT_VVV_VV(vcvtsisd , PACK_AVX_SSE(Vcvtsi2sd , Cvtsi2sd , X)) // AVX | SSE2
V_EMIT_VV_VV(vcvtsssi , PACK_AVX_SSE(Vcvtss2si , Cvtss2si , X)) // AVX | SSE
V_EMIT_VV_VV(vcvtsdsi , PACK_AVX_SSE(Vcvtsd2si , Cvtsd2si , X)) // AVX | SSE2
V_EMIT_VV_VV(vcvttsssi , PACK_AVX_SSE(Vcvttss2si , Cvttss2si , X)) // AVX | SSE
V_EMIT_VV_VV(vcvttsdsi , PACK_AVX_SSE(Vcvttsd2si , Cvttsd2si , X)) // AVX | SSE2
V_EMIT_VVV_VV(vhaddps_ , PACK_AVX_SSE(Vhaddps , Haddps , Z)) // AVX | SSE3
V_EMIT_VVV_VV(vhaddpd_ , PACK_AVX_SSE(Vhaddpd , Haddpd , Z)) // AVX | SSE3
V_EMIT_VVV_VV(vhsubps_ , PACK_AVX_SSE(Vhsubps , Hsubps , Z)) // AVX | SSE3
V_EMIT_VVV_VV(vhsubpd_ , PACK_AVX_SSE(Vhsubpd , Hsubpd , Z)) // AVX | SSE3
// Floating Point - Miscellaneous.
V_EMIT_VV_VV(vcomiss , PACK_AVX_SSE(Vcomiss , Comiss , X)) // AVX | SSE
V_EMIT_VV_VV(vcomisd , PACK_AVX_SSE(Vcomisd , Comisd , X)) // AVX | SSE2
V_EMIT_VV_VV(vucomiss , PACK_AVX_SSE(Vucomiss , Ucomiss , X)) // AVX | SSE
V_EMIT_VV_VV(vucomisd , PACK_AVX_SSE(Vucomisd , Ucomisd , X)) // AVX | SSE2
// Initialization.
inline void vzeropi(const Operand_& dst) noexcept { vemit_vvv_vv(PACK_AVX_SSE(Vpxor , Pxor , Z), dst, dst, dst); }
inline void vzerops(const Operand_& dst) noexcept { vemit_vvv_vv(PACK_AVX_SSE(Vxorps, Xorps, Z), dst, dst, dst); }
inline void vzeropd(const Operand_& dst) noexcept { vemit_vvv_vv(PACK_AVX_SSE(Vxorpd, Xorpd, Z), dst, dst, dst); }
inline void vzeropi(const OpArray& dst) noexcept { for (uint32_t i = 0; i < dst.size(); i++) vzeropi(dst[i]); }
inline void vzerops(const OpArray& dst) noexcept { for (uint32_t i = 0; i < dst.size(); i++) vzerops(dst[i]); }
inline void vzeropd(const OpArray& dst) noexcept { for (uint32_t i = 0; i < dst.size(); i++) vzeropd(dst[i]); }
// Conversion.
inline void vmovsi32(const x86::Vec& dst, const x86::Gp& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovd, Movd, X), dst, src); }
inline void vmovsi64(const x86::Vec& dst, const x86::Gp& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovq, Movq, X), dst, src); }
inline void vmovsi32(const x86::Gp& dst, const x86::Vec& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovd, Movd, X), dst, src); }
inline void vmovsi64(const x86::Gp& dst, const x86::Vec& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovq, Movq, X), dst, src); }
// Memory Load & Store.
inline void vloadi32(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovd, Movd, X), dst, src); }
inline void vloadi64(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovq, Movq, X), dst, src); }
inline void vloadi128a(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovdqa, Movaps, X), dst, src); }
inline void vloadi128u(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovdqu, Movups, X), dst, src); }
inline void vloadi128u_ro(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vloadi128uRO), dst, src); }
inline void vloadi256a(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovdqa, Movaps, Y), dst, src); }
inline void vloadi256u(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovdqu, Movups, Y), dst, src); }
inline void vloadi256u_ro(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vloadi128uRO), dst, src); }
inline void vloadi64_u8u16_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovzxbw, Pmovzxbw, X), dst, src); }
inline void vloadi32_u8u32_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovzxbd, Pmovzxbd, X), dst, src); }
inline void vloadi16_u8u64_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovzxbq, Pmovzxbq, X), dst, src); }
inline void vloadi64_u16u32_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovzxwd, Pmovzxwd, X), dst, src); }
inline void vloadi32_u16u64_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovzxwq, Pmovzxwq, X), dst, src); }
inline void vloadi64_u32u64_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovzxdq, Pmovzxdq, X), dst, src); }
inline void vloadi64_i8i16_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovsxbw, Pmovsxbw, X), dst, src); }
inline void vloadi32_i8i32_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovsxbd, Pmovsxbd, X), dst, src); }
inline void vloadi16_i8i64_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovsxbq, Pmovsxbq, X), dst, src); }
inline void vloadi64_i16i32_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovsxwd, Pmovsxwd, X), dst, src); }
inline void vloadi32_i16i64_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovsxwq, Pmovsxwq, X), dst, src); }
inline void vloadi64_i32i64_(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vpmovsxdq, Pmovsxdq, X), dst, src); }
inline void vstorei32(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovd, Movd, X), dst, src); }
inline void vstorei64(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovq, Movq, X), dst, src); }
inline void vstorei128a(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovdqa, Movaps, X), dst, src); }
inline void vstorei128u(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovdqu, Movups, X), dst, src); }
inline void vstorei256a(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovdqa, Movaps, Y), dst, src); }
inline void vstorei256u(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovdqu, Movups, Y), dst, src); }
inline void vloadss(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovss, Movss, X), dst, src); }
inline void vloadsd(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovsd, Movsd, X), dst, src); }
inline void vloadps_64l(const Operand_& dst, const Operand_& src1, const x86::Mem& src2) noexcept { vemit_vvv_vv(PACK_AVX_SSE(Vmovlps, Movlps, X), dst, src1, src2); }
inline void vloadps_64h(const Operand_& dst, const Operand_& src1, const x86::Mem& src2) noexcept { vemit_vvv_vv(PACK_AVX_SSE(Vmovhps, Movhps, X), dst, src1, src2); }
inline void vloadpd_64l(const Operand_& dst, const Operand_& src1, const x86::Mem& src2) noexcept { vemit_vvv_vv(PACK_AVX_SSE(Vmovlpd, Movlpd, X), dst, src1, src2); }
inline void vloadpd_64h(const Operand_& dst, const Operand_& src1, const x86::Mem& src2) noexcept { vemit_vvv_vv(PACK_AVX_SSE(Vmovhpd, Movhpd, X), dst, src1, src2); }
inline void vloadps_128a(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovaps, Movaps, X), dst, src); }
inline void vloadps_128u(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovups, Movups, X), dst, src); }
inline void vloadpd_128a(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovapd, Movaps, X), dst, src); }
inline void vloadpd_128u(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovupd, Movups, X), dst, src); }
inline void vloadps_256a(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovaps, Movaps, Y), dst, src); }
inline void vloadps_256u(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovups, Movups, Y), dst, src); }
inline void vloadpd_256a(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovapd, Movaps, Y), dst, src); }
inline void vloadpd_256u(const Operand_& dst, const x86::Mem& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovupd, Movups, Y), dst, src); }
inline void vstoress(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovss, Movss, X), dst, src); }
inline void vstoresd(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovsd, Movsd, X), dst, src); }
inline void vstoreps_64l(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovlps, Movlps, X), dst, src); }
inline void vstoreps_64h(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovhps, Movhps, X), dst, src); }
inline void vstorepd_64l(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovsd , Movsd , X), dst, src); }
inline void vstorepd_64h(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovhpd, Movhpd, X), dst, src); }
inline void vstoreps_128a(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovaps, Movaps, X), dst, src); }
inline void vstoreps_128u(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovups, Movups, X), dst, src); }
inline void vstorepd_128a(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovapd, Movaps, X), dst, src); }
inline void vstorepd_128u(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovupd, Movups, X), dst, src); }
inline void vstoreps_256a(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovaps, Movaps, Y), dst, src); }
inline void vstoreps_256u(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovups, Movups, Y), dst, src); }
inline void vstorepd_256a(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovapd, Movaps, Y), dst, src); }
inline void vstorepd_256u(const x86::Mem& dst, const Operand_& src) noexcept { vemit_vv_vv(PACK_AVX_SSE(Vmovupd, Movups, Y), dst, src); }
// Intrinsics:
//
// - vmov{x}{y} - Move with sign or zero extension from {x} to {y}. Similar
// to instructions like `pmovzx..`, `pmovsx..`, and `punpckl..`
//
// - vswap{x} - Swap low and high elements. If the vector has more than 2
// elements it's divided into 2 element vectors in which the
// operation is performed separately.
//
// - vdup{l|h}{x} - Duplicate either low or high element into both. If there
// are more than 2 elements in the vector it's considered
// they are separate units. For example a 4-element vector
// can be considered as 2 2-element vectors on which the
// duplication operation is performed.
template<typename DstT, typename SrcT>
inline void vmovu8u16(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vmovu8u16), dst, src);
}
template<typename DstT, typename SrcT>
inline void vmovu8u32(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vmovu8u32), dst, src);
}
template<typename DstT, typename SrcT>
inline void vmovu16u32(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vmovu16u32), dst, src);
}
template<typename DstT, typename SrcT>
inline void vabsi8(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vabsi8), dst, src);
}
template<typename DstT, typename SrcT>
inline void vabsi16(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vabsi16), dst, src);
}
template<typename DstT, typename SrcT>
inline void vabsi32(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vabsi32), dst, src);
}
template<typename DstT, typename SrcT>
inline void vabsi64(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vabsi64), dst, src);
}
template<typename DstT, typename SrcT>
inline void vswapi32(const DstT& dst, const SrcT& src) noexcept {
vswizi32(dst, src, x86::Predicate::shuf(2, 3, 0, 1));
}
template<typename DstT, typename SrcT>
inline void vswapi64(const DstT& dst, const SrcT& src) noexcept {
vswizi32(dst, src, x86::Predicate::shuf(1, 0, 3, 2));
}
template<typename DstT, typename SrcT>
inline void vdupli32(const DstT& dst, const SrcT& src) noexcept {
vswizi32(dst, src, x86::Predicate::shuf(2, 2, 0, 0));
}
template<typename DstT, typename SrcT>
inline void vduphi32(const DstT& dst, const SrcT& src) noexcept {
vswizi32(dst, src, x86::Predicate::shuf(3, 3, 1, 1));
}
template<typename DstT, typename SrcT>
inline void vdupli64(const DstT& dst, const SrcT& src) noexcept {
vswizi32(dst, src, x86::Predicate::shuf(1, 0, 1, 0));
}
template<typename DstT, typename SrcT>
inline void vduphi64(const DstT& dst, const SrcT& src) noexcept {
vswizi32(dst, src, x86::Predicate::shuf(3, 2, 3, 2));
}
template<typename DstT, typename Src1T, typename Src2T, typename CondT>
inline void vblendv8(const DstT& dst, const Src1T& src1, const Src2T& src2, const CondT& cond) noexcept {
vemit_vvvv_vvv(PackedInst::packIntrin(kIntrin4Vpblendvb), dst, src1, src2, cond);
}
template<typename DstT, typename SrcT>
inline void vinv255u16(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vinv255u16), dst, src);
}
template<typename DstT, typename SrcT>
inline void vinv256u16(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vinv256u16), dst, src);
}
template<typename DstT, typename SrcT>
inline void vinv255u32(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vinv255u32), dst, src);
}
template<typename DstT, typename SrcT>
inline void vinv256u32(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vinv256u32), dst, src);
}
template<typename DstT, typename SrcT>
inline void vduplpd(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vduplpd), dst, src);
}
template<typename DstT, typename SrcT>
inline void vduphpd(const DstT& dst, const SrcT& src) noexcept {
vemit_vv_vv(PackedInst::packIntrin(kIntrin2Vduphpd), dst, src);
}
template<typename DstT, typename Src1T, typename Src2T>
inline void vhaddpd(const DstT& dst, const Src1T& src1, const Src2T& src2) noexcept {
vemit_vvv_vv(PackedInst::packIntrin(kIntrin3Vhaddpd), dst, src1, src2);
}
template<typename DstT, typename SrcT>
inline void vexpandli32(const DstT& dst, const SrcT& src) noexcept {
vswizi32(dst, src, x86::Predicate::shuf(0, 0, 0, 0));
}
// dst.u64[0] = src1.u64[1];
// dst.u64[1] = src2.u64[0];
template<typename DstT, typename Src1T, typename Src2T>
inline void vcombhli64(const DstT& dst, const Src1T& src1, const Src2T& src2) noexcept {
vemit_vvv_vv(PackedInst::packIntrin(kIntrin3Vcombhli64), dst, src1, src2);
}
// dst.d64[0] = src1.d64[1];
// dst.d64[1] = src2.d64[0];
template<typename DstT, typename Src1T, typename Src2T>
inline void vcombhld64(const DstT& dst, const Src1T& src1, const Src2T& src2) noexcept {
vemit_vvv_vv(PackedInst::packIntrin(kIntrin3Vcombhld64), dst, src1, src2);
}
template<typename DstT, typename Src1T, typename Src2T>
inline void vminu16(const DstT& dst, const Src1T& src1, const Src2T& src2) noexcept {
vemit_vvv_vv(PackedInst::packIntrin(kIntrin3Vminu16), dst, src1, src2);
}
template<typename DstT, typename Src1T, typename Src2T>
inline void vmaxu16(const DstT& dst, const Src1T& src1, const Src2T& src2) noexcept {
vemit_vvv_vv(PackedInst::packIntrin(kIntrin3Vmaxu16), dst, src1, src2);
}
// Multiplies packed uint64_t in `src1` with packed low uint32_t int `src2`.
template<typename DstT, typename Src1T, typename Src2T>
inline void vMulU64xU32Lo(const DstT& dst, const Src1T& src1, const Src2T& src2) noexcept {
vemit_vvv_vv(PackedInst::packIntrin(kIntrin3Vmulu64x32), dst, src1, src2);
}
// TODO: [PIPEGEN] Consolidate this to only one implementation.
template<typename DstSrcT>
BL_NOINLINE void vdiv255u16(const DstSrcT& x) {
vaddi16(x, x, constAsXmm(blCommonTable.i128_0080008000800080));
vmulhu16(x, x, constAsXmm(blCommonTable.i128_0101010101010101));
}
template<typename DstSrcT>
BL_NOINLINE void vdiv255u16_2x(
const DstSrcT& v0,
const DstSrcT& v1) noexcept {
x86::Xmm i128_0080008000800080 = constAsXmm(blCommonTable.i128_0080008000800080);
x86::Xmm i128_0101010101010101 = constAsXmm(blCommonTable.i128_0101010101010101);
vaddi16(v0, v0, i128_0080008000800080);
vmulhu16(v0, v0, i128_0101010101010101);
vaddi16(v1, v1, i128_0080008000800080);
vmulhu16(v1, v1, i128_0101010101010101);
}
template<typename DstSrcT>
BL_NOINLINE void vdiv255u16_3x(
const DstSrcT& v0,
const DstSrcT& v1,
const DstSrcT& v2) noexcept {
x86::Xmm i128_0080008000800080 = constAsXmm(blCommonTable.i128_0080008000800080);
x86::Xmm i128_0101010101010101 = constAsXmm(blCommonTable.i128_0101010101010101);
vaddi16(v0, v0, i128_0080008000800080);
vmulhu16(v0, v0, i128_0101010101010101);
vaddi16(v1, v1, i128_0080008000800080);
vmulhu16(v1, v1, i128_0101010101010101);
vaddi16(v2, v2, i128_0080008000800080);
vmulhu16(v2, v2, i128_0101010101010101);
}
template<typename DstT, typename SrcT>
inline void vexpandlps(const DstT& dst, const SrcT& src) noexcept {
vexpandli32(dst, src);
}
template<typename DstT, typename SrcT>
inline void vswizps(const DstT& dst, const SrcT& src, int imm) noexcept { vemit_vvi_vi(PackedInst::packIntrin(kIntrin2iVswizps), dst, src, imm); }
template<typename DstT, typename SrcT>
inline void vswizpd(const DstT& dst, const SrcT& src, int imm) noexcept { vemit_vvi_vi(PackedInst::packIntrin(kIntrin2iVswizpd), dst, src, imm); }
template<typename DstT, typename SrcT>
inline void vswapps(const DstT& dst, const SrcT& src) noexcept { vswizps(dst, src, x86::Predicate::shuf(2, 3, 0, 1)); }
template<typename DstT, typename SrcT>
inline void vswappd(const DstT& dst, const SrcT& src) noexcept { vswizpd(dst, src, x86::Predicate::shuf(0, 1)); }
// --------------------------------------------------------------------------
// [X-Emit - High-Level]
// --------------------------------------------------------------------------
void xLoopMemset32(x86::Gp& dst, x86::Vec& src, x86::Gp& i, uint32_t n, uint32_t granularity) noexcept;
void xLoopMemcpy32(x86::Gp& dst, x86::Gp& src, x86::Gp& i, uint32_t n, uint32_t granularity) noexcept;
void xInlineMemcpyXmm(
const x86::Mem& dPtr, bool dstAligned,
const x86::Mem& sPtr, bool srcAligned, int numBytes) noexcept;
// --------------------------------------------------------------------------
// [Fetch Utilities]
// --------------------------------------------------------------------------
//! Fetch 1 pixel to XMM register(s) in `p` from memory location `sMem`.
void xFetchARGB32_1x(PixelARGB& p, uint32_t flags, const x86::Mem& sMem, uint32_t sAlignment) noexcept;
//! Fetch 4 pixels to XMM register(s) in `p` from memory location `sMem`.
void xFetchARGB32_4x(PixelARGB& p, uint32_t flags, const x86::Mem& sMem, uint32_t sAlignment) noexcept;
//! Fetch 8 pixels to XMM register(s) in `p` from memory location `sMem`.
void xFetchARGB32_8x(PixelARGB& p, uint32_t flags, const x86::Mem& sMem, uint32_t sAlignment) noexcept;
inline void xSatisfyARGB32(PixelARGB& p, uint32_t flags, uint32_t n) noexcept {
if (n == 1)
xSatisfyARGB32_1x(p, flags);
else
xSatisfyARGB32_Nx(p, flags);
}
//! Handle all fetch `flags` in 1 fetched pixel `p`.
void xSatisfyARGB32_1x(PixelARGB& p, uint32_t flags) noexcept;
//! Handle all fetch `flags` in 4 fetched pixels `p`.
void xSatisfyARGB32_Nx(PixelARGB& p, uint32_t flags) noexcept;
//! Used by `FetchPart` and `CompOpPart`.
void xSatisfySolid(PixelARGB& p, uint32_t flags) noexcept;
//! Fill alpha channel to 1.
void vFillAlpha(PixelARGB& p) noexcept;
// --------------------------------------------------------------------------
// [Utilities - MM]
// --------------------------------------------------------------------------
inline void xStore32_ARGB(const x86::Gp& dPtr, const x86::Vec& dPixel) noexcept {
vstorei32(x86::dword_ptr(dPtr), dPixel);
}
BL_NOINLINE void xMovzxBW_LoHi(const x86::Vec& d0, const x86::Vec& d1, const x86::Vec& s) noexcept {
BL_ASSERT(d0.id() != d1.id());
if (hasSSE4_1()) {
if (d0.id() == s.id()) {
vswizi32(d1, d0, x86::Predicate::shuf(1, 0, 3, 2));
vmovu8u16_(d0, d0);
vmovu8u16_(d1, d1);
}
else {
vmovu8u16(d0, s);
vswizi32(d1, s, x86::Predicate::shuf(1, 0, 3, 2));
vmovu8u16(d1, d1);
}
}
else {
x86::Xmm i128_0000000000000000 = constAsXmm(blCommonTable.i128_0000000000000000);
if (d1.id() != s.id()) {
vunpackhi8(d1, s, i128_0000000000000000);
vunpackli8(d0, s, i128_0000000000000000);
}
else {
vunpackli8(d0, s, i128_0000000000000000);
vunpackhi8(d1, s, i128_0000000000000000);
}
}
}
template<typename Dst, typename Src>
inline void vExpandAlphaLo16(const Dst& d, const Src& s) noexcept { vswizli16(d, s, x86::Predicate::shuf(3, 3, 3, 3)); }
template<typename Dst, typename Src>
inline void vExpandAlphaHi16(const Dst& d, const Src& s) noexcept { vswizhi16(d, s, x86::Predicate::shuf(3, 3, 3, 3)); }
template<typename Dst, typename Src>
inline void vExpandAlpha16(const Dst& d, const Src& s, int useHiPart = 1) noexcept {
vExpandAlphaLo16(d, s);
if (useHiPart)
vExpandAlphaHi16(d, d);
}
template<typename Dst, typename Src>
inline void vExpandAlphaPS(const Dst& d, const Src& s) noexcept { vswizi32(d, s, x86::Predicate::shuf(3, 3, 3, 3)); }
template<typename DstT, typename SrcT>
inline void vFillAlpha255B(const DstT& dst, const SrcT& src) noexcept { vor(dst, src, constAsMem(blCommonTable.i128_FF000000FF000000)); }
template<typename DstT, typename SrcT>
inline void vFillAlpha255W(const DstT& dst, const SrcT& src) noexcept { vor(dst, src, constAsMem(blCommonTable.i128_00FF000000000000)); }
template<typename DstT, typename SrcT>
inline void vFillAlpha256W(const DstT& dst, const SrcT& src) noexcept { vor(dst, src, constAsMem(blCommonTable.i128_0100000000000000)); }
template<typename DstT, typename SrcT>
inline void vZeroAlphaB(const DstT& dst, const SrcT& src) noexcept { vand(dst, src, constAsMem(blCommonTable.i128_00FFFFFF00FFFFFF)); }
template<typename DstT, typename SrcT>
inline void vZeroAlphaW(const DstT& dst, const SrcT& src) noexcept { vand(dst, src, constAsMem(blCommonTable.i128_0000FFFFFFFFFFFF)); }
template<typename DstT, typename SrcT>
inline void vNegAlpha8B(const DstT& dst, const SrcT& src) noexcept { vxor(dst, src, constAsMem(blCommonTable.i128_FF000000FF000000)); }
template<typename DstT, typename SrcT>
inline void vNegAlpha8W(const DstT& dst, const SrcT& src) noexcept { vxor(dst, src, constAsMem(blCommonTable.i128_00FF000000000000)); }
template<typename DstT, typename SrcT>
inline void vNegRgb8B(const DstT& dst, const SrcT& src) noexcept { vxor(dst, src, constAsMem(blCommonTable.i128_00FFFFFF00FFFFFF)); }
template<typename DstT, typename SrcT>
inline void vNegRgb8W(const DstT& dst, const SrcT& src) noexcept { vxor(dst, src, constAsMem(blCommonTable.i128_000000FF00FF00FF)); }
// d = int(floor(a / b) * b).
template<typename XmmOrMem>
BL_NOINLINE void vmodpd(const x86::Xmm& d, const x86::Xmm& a, const XmmOrMem& b) noexcept {
if (hasSSE4_1()) {
vdivpd(d, a, b);
vroundpd_(d, d, x86::Predicate::kRoundTrunc | x86::Predicate::kRoundInexact);
vmulpd(d, d, b);
}
else {
x86::Xmm t = cc->newXmm("vmodpdTmp");
vdivpd(d, a, b);
vcvttpdi32(t, d);
vcvti32pd(t, t);
vcmppd(d, d, t, x86::Predicate::kCmpLT | x86::Predicate::kCmpUNORD);
vandpd(d, d, constAsMem(blCommonTable.d128_m1));
vaddpd(d, d, t);
vmulpd(d, d, b);
}
}
// Performs 32-bit unsigned modulo of 32-bit `a` (hi DWORD) with 32-bit `b` (lo DWORD).
template<typename XmmOrMem_A, typename XmmOrMem_B>
BL_NOINLINE void xModI64HIxU64LO(const x86::Xmm& d, const XmmOrMem_A& a, const XmmOrMem_B& b) noexcept {
x86::Xmm t0 = cc->newXmm("t0");
x86::Xmm t1 = cc->newXmm("t1");
vswizi32(t1, b, x86::Predicate::shuf(3, 3, 2, 0));
vswizi32(d , a, x86::Predicate::shuf(2, 0, 3, 1));
vcvti32pd(t1, t1);
vcvti32pd(t0, d);
vmodpd(t0, t0, t1);
vcvttpdi32(t0, t0);
vsubi32(d, d, t0);
vswizi32(d, d, x86::Predicate::shuf(1, 3, 0, 2));
}
// Performs 32-bit unsigned modulo of 32-bit `a` (hi DWORD) with 64-bit `b` (DOUBLE).
template<typename XmmOrMem_A, typename XmmOrMem_B>
BL_NOINLINE void xModI64HIxDouble(const x86::Xmm& d, const XmmOrMem_A& a, const XmmOrMem_B& b) noexcept {
x86::Xmm t0 = cc->newXmm("t0");
vswizi32(d, a, x86::Predicate::shuf(2, 0, 3, 1));
vcvti32pd(t0, d);
vmodpd(t0, t0, b);
vcvttpdi32(t0, t0);
vsubi32(d, d, t0);
vswizi32(d, d, x86::Predicate::shuf(1, 3, 0, 2));
}
BL_NOINLINE void xExtractUnpackedAFromPackedARGB32_1(const x86::Xmm& d, const x86::Xmm& s) noexcept {
vswizli16(d, s, x86::Predicate::shuf(1, 1, 1, 1));
vsrli16(d, d, 8);
}
BL_NOINLINE void xExtractUnpackedAFromPackedARGB32_2(const x86::Xmm& d, const x86::Xmm& s) noexcept {
if (hasSSSE3()) {
vswizi8v_(d, s, constAsMem(blCommonTable.i128_pshufb_packed_argb32_2x_lo_to_unpacked_a8));
}
else {
vswizli16(d, s, x86::Predicate::shuf(3, 3, 1, 1));
vswizi32(d, d, x86::Predicate::shuf(1, 1, 0, 0));
vsrli16(d, d, 8);
}
}
BL_NOINLINE void xExtractUnpackedAFromPackedARGB32_4(const x86::Vec& d0, const x86::Vec& d1, const x86::Vec& s) noexcept {
BL_ASSERT(d0.id() != d1.id());
if (hasSSSE3()) {
if (d0.id() == s.id()) {
vswizi8v_(d1, s, constAsMem(blCommonTable.i128_pshufb_packed_argb32_2x_hi_to_unpacked_a8));
vswizi8v_(d0, s, constAsMem(blCommonTable.i128_pshufb_packed_argb32_2x_lo_to_unpacked_a8));
}
else {
vswizi8v_(d0, s, constAsMem(blCommonTable.i128_pshufb_packed_argb32_2x_lo_to_unpacked_a8));
vswizi8v_(d1, s, constAsMem(blCommonTable.i128_pshufb_packed_argb32_2x_hi_to_unpacked_a8));
}
}
else {
if (d1.id() != s.id()) {
vswizhi16(d1, s, x86::Predicate::shuf(3, 3, 1, 1));
vswizli16(d0, s, x86::Predicate::shuf(3, 3, 1, 1));
vswizi32(d1, d1, x86::Predicate::shuf(3, 3, 2, 2));
vswizi32(d0, d0, x86::Predicate::shuf(1, 1, 0, 0));
vsrli16(d1, d1, 8);
vsrli16(d0, d0, 8);
}
else {
vswizli16(d0, s, x86::Predicate::shuf(3, 3, 1, 1));
vswizhi16(d1, s, x86::Predicate::shuf(3, 3, 1, 1));
vswizi32(d0, d0, x86::Predicate::shuf(1, 1, 0, 0));
vswizi32(d1, d1, x86::Predicate::shuf(3, 3, 2, 2));
vsrli16(d0, d0, 8);
vsrli16(d1, d1, 8);
}
}
}
BL_NOINLINE void xPackU32ToU16Lo(const x86::Vec& d0, const x86::Vec& s0) noexcept {
if (hasSSE4_1()) {
vpacki32u16_(d0, s0, s0);
}
else if (hasSSSE3()) {
vswizi8v_(d0, s0, constAsMem(blCommonTable.i128_pshufb_u32_to_u16_lo));
}
else {
// Sign extend and then use `packssdw()`.
vslli32(d0, s0, 16);
vsrai32(d0, d0, 16);
vpacki32i16(d0, d0, d0);
}
}
BL_NOINLINE void xPackU32ToU16Lo(const VecArray& d0, const VecArray& s0) noexcept {
for (uint32_t i = 0; i < d0.size(); i++)
xPackU32ToU16Lo(d0[i], s0[i]);
}
// --------------------------------------------------------------------------
// [Emit - End]
// --------------------------------------------------------------------------
#undef PACK_AVX_SSE
#undef V_EMIT_VVVV_VVV
#undef V_EMIT_VVVi_VVi
#undef V_EMIT_VVVI_VVI
#undef V_EMIT_VVV_VV
#undef V_EMIT_VVi_VVi
#undef V_EMIT_VVI_VVI
#undef V_EMIT_VVI_VVI
#undef V_EMIT_VVI_VI
#undef V_EMIT_VV_VV
#undef I_EMIT_3
#undef I_EMIT_2i
#undef I_EMIT_2
};
// ============================================================================
// [BLPipeGen::PipeInjectAtTheEnd]
// ============================================================================
class PipeInjectAtTheEnd {
public:
ScopedInjector _injector;
BL_INLINE PipeInjectAtTheEnd(PipeCompiler* pc) noexcept
: _injector(pc->cc, &pc->_funcEnd) {}
};
} // {BLPipeGen}
//! \}
//! \endcond
#endif // BLEND2D_PIPEGEN_BLPIPECOMPILER_P_H
| [
"kobalicek.petr@gmail.com"
] | kobalicek.petr@gmail.com |
e1d46d5c07a1170e0ec13390c3deeb9f4c4e698c | e2d709a6005a8dcd1eb0de818260be0d7b8fa6a2 | /include/okapi/api/chassis/controller/chassisControllerPid.hpp | 0a23f47455c9dfb858c457b4def76be17b86cf39 | [] | no_license | sealj553/VexV5NanoboyAdvance | ea33ceea18b84231a0e7ea581e05e7f639a1f2f1 | d11f44fba95d16fcb0f8fe8cfae22318e6ce9cbb | refs/heads/master | 2020-04-01T15:51:14.815109 | 2018-10-20T05:38:57 | 2018-10-20T05:38:57 | 153,354,793 | 11 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,719 | hpp | /**
* @author Ryan Benasutti, WPI
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef _OKAPI_CHASSISCONTROLLERPID_HPP_
#define _OKAPI_CHASSISCONTROLLERPID_HPP_
#include "okapi/api/chassis/controller/chassisController.hpp"
#include "okapi/api/control/iterative/iterativePosPidController.hpp"
#include "okapi/api/util/abstractRate.hpp"
#include "okapi/api/util/logging.hpp"
#include "okapi/api/util/timeUtil.hpp"
#include <atomic>
#include <memory>
namespace okapi {
class ChassisControllerPID : public virtual ChassisController {
public:
/**
* ChassisController using PID control. Puts the motors into encoder degree units. Throws a
* std::invalid_argument exception if the gear ratio is zero.
*
* @param imodelArgs ChassisModelArgs
* @param idistanceController distance PID controller
* @param iangleController angle PID controller (keeps the robot straight)
* @param igearset motor internal gearset and gear ratio
* @param iscales see ChassisScales docs
*/
ChassisControllerPID(const TimeUtil &itimeUtil,
std::shared_ptr<ChassisModel> imodel,
std::unique_ptr<IterativePosPIDController> idistanceController,
std::unique_ptr<IterativePosPIDController> iangleController,
std::unique_ptr<IterativePosPIDController> iturnController,
AbstractMotor::GearsetRatioPair igearset = AbstractMotor::gearset::red,
const ChassisScales &iscales = ChassisScales({1, 1}));
ChassisControllerPID(ChassisControllerPID &&other) noexcept;
~ChassisControllerPID() override;
/**
* Drives the robot straight for a distance (using closed-loop control).
*
* @param itarget distance to travel
*/
void moveDistance(QLength itarget) override;
/**
* Drives the robot straight for a distance (using closed-loop control).
*
* @param itarget distance to travel in motor degrees
*/
void moveDistance(double itarget) override;
/**
* Sets the target distance for the robot to drive straight (using closed-loop control).
*
* @param itarget distance to travel
*/
void moveDistanceAsync(QLength itarget) override;
/**
* Sets the target distance for the robot to drive straight (using closed-loop control).
*
* @param itarget distance to travel in motor degrees
*/
void moveDistanceAsync(double itarget) override;
/**
* Turns the robot clockwise in place (using closed-loop control).
*
* @param idegTarget angle to turn for
*/
void turnAngle(QAngle idegTarget) override;
/**
* Turns the robot clockwise in place (using closed-loop control).
*
* @param idegTarget angle to turn for in motor degrees
*/
void turnAngle(double idegTarget) override;
/**
* Sets the target angle for the robot to turn clockwise in place (using closed-loop control).
*
* @param idegTarget angle to turn for
*/
void turnAngleAsync(QAngle idegTarget) override;
/**
* Sets the target angle for the robot to turn clockwise in place (using closed-loop control).
*
* @param idegTarget angle to turn for in motor degrees
*/
void turnAngleAsync(double idegTarget) override;
/**
* Delays until the currently executing movement completes.
*/
void waitUntilSettled() override;
/**
* Stop the robot (set all the motors to 0).
*/
void stop() override;
/**
* Starts the internal thread. This should not be called by normal users. This method is called
* by the ChassisControllerFactory when making a new instance of this class.
*/
void startThread();
/**
* Get the ChassisScales.
*/
ChassisScales getChassisScales() const override;
/**
* Get the GearsetRatioPair.
*/
AbstractMotor::GearsetRatioPair getGearsetRatioPair() const override;
protected:
Logger *logger;
std::unique_ptr<AbstractRate> rate;
std::unique_ptr<IterativePosPIDController> distancePid;
std::unique_ptr<IterativePosPIDController> anglePid;
std::unique_ptr<IterativePosPIDController> turnPid;
ChassisScales scales;
AbstractMotor::GearsetRatioPair gearsetRatioPair;
std::atomic_bool doneLooping{true};
std::atomic_bool newMovement{false};
std::atomic_bool dtorCalled{false};
static void trampoline(void *context);
void loop();
bool waitForDistanceSettled();
bool waitForAngleSettled();
void stopAfterSettled();
typedef enum { distance, angle, none } modeType;
modeType mode{none};
CrossplatformThread *task{nullptr};
};
} // namespace okapi
#endif
| [
"sealj553@gmail.com"
] | sealj553@gmail.com |
4ee80f2d5f4025385d95c50a9992276921042387 | 6a19bec1f6c02d8defe37e8a7179149821ab5a93 | /src/wallet/rpcwallet.cpp | 1f053ac2ae025e83f1a6bd5f92e5730e36d9e947 | [
"MIT"
] | permissive | glpcoin/GodLikeProductsSource | 4800d486f0f6c1cee2f76131b750346bcd1948d9 | 74059e30f802343e1812b7c40f0b4621ae0980d9 | refs/heads/master | 2020-06-12T01:16:46.672122 | 2019-06-27T19:11:34 | 2019-06-27T19:11:34 | 194,148,521 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 142,216 | cpp | // Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2014-2017 The Dash Core developers
// Copyright (c) 2019 The GodLikeProducts Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "amount.h"
#include "base58.h"
#include "chain.h"
#include "consensus/validation.h"
#include "core_io.h"
#include "init.h"
#include "instantx.h"
#include "net.h"
#include "policy/rbf.h"
#include "rpc/server.h"
#include "timedata.h"
#include "util.h"
#include "utilmoneystr.h"
#include "validation.h"
#include "wallet.h"
#include "walletdb.h"
#include "keepass.h"
#include <stdint.h>
#include <boost/assign/list_of.hpp>
#include <univalue.h>
int64_t nWalletUnlockTime;
static CCriticalSection cs_nWalletUnlockTime;
std::string HelpRequiringPassphrase()
{
return pwalletMain && pwalletMain->IsCrypted()
? "\nRequires wallet passphrase to be set with walletpassphrase call."
: "";
}
bool EnsureWalletIsAvailable(bool avoidException)
{
if (!pwalletMain)
{
if (!avoidException)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)");
else
return false;
}
return true;
}
void EnsureWalletIsUnlocked()
{
if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
}
void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
{
int confirms = wtx.GetDepthInMainChain(false);
bool fLocked = instantsend.IsLockedInstantSendTransaction(wtx.GetHash());
entry.push_back(Pair("confirmations", confirms));
entry.push_back(Pair("instantlock", fLocked));
if (wtx.IsCoinBase())
entry.push_back(Pair("generated", true));
if (confirms > 0)
{
entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
entry.push_back(Pair("blockindex", wtx.nIndex));
entry.push_back(Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime()));
} else {
entry.push_back(Pair("trusted", wtx.IsTrusted()));
}
uint256 hash = wtx.GetHash();
entry.push_back(Pair("txid", hash.GetHex()));
UniValue conflicts(UniValue::VARR);
BOOST_FOREACH(const uint256& conflict, wtx.GetConflicts())
conflicts.push_back(conflict.GetHex());
entry.push_back(Pair("walletconflicts", conflicts));
entry.push_back(Pair("time", wtx.GetTxTime()));
entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived));
// Add opt-in RBF status
std::string rbfStatus = "no";
if (confirms <= 0) {
LOCK(mempool.cs);
RBFTransactionState rbfState = IsRBFOptIn(wtx, mempool);
if (rbfState == RBF_TRANSACTIONSTATE_UNKNOWN)
rbfStatus = "unknown";
else if (rbfState == RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125)
rbfStatus = "yes";
}
entry.push_back(Pair("bip125-replaceable", rbfStatus));
BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item, wtx.mapValue)
entry.push_back(Pair(item.first, item.second));
}
std::string AccountFromValue(const UniValue& value)
{
std::string strAccount = value.get_str();
if (strAccount == "*")
throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Invalid account name");
return strAccount;
}
UniValue getnewaddress(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 1)
throw std::runtime_error(
"getnewaddress ( \"account\" )\n"
"\nReturns a new GodLikeProducts address for receiving payments.\n"
"If 'account' is specified (DEPRECATED), it is added to the address book \n"
"so payments received with the address will be credited to 'account'.\n"
"\nArguments:\n"
"1. \"account\" (string, optional) DEPRECATED. The account name for the address to be linked to. If not provided, the default account \"\" is used. It can also be set to the empty string \"\" to represent the default account. The account does not need to exist, it will be created if there is no account by the given name.\n"
"\nResult:\n"
"\"address\" (string) The new godlikeproducts address\n"
"\nExamples:\n"
+ HelpExampleCli("getnewaddress", "")
+ HelpExampleRpc("getnewaddress", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
// Parse the account first so we don't generate a key if there's an error
std::string strAccount;
if (request.params.size() > 0)
strAccount = AccountFromValue(request.params[0]);
if (!pwalletMain->IsLocked(true))
pwalletMain->TopUpKeyPool();
// Generate a new key that is added to wallet
CPubKey newKey;
if (!pwalletMain->GetKeyFromPool(newKey, false))
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
CKeyID keyID = newKey.GetID();
pwalletMain->SetAddressBook(keyID, strAccount, "receive");
return CBitcoinAddress(keyID).ToString();
}
CBitcoinAddress GetAccountAddress(std::string strAccount, bool bForceNew=false)
{
CPubKey pubKey;
if (!pwalletMain->GetAccountPubkey(pubKey, strAccount, bForceNew)) {
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
}
return CBitcoinAddress(pubKey.GetID());
}
UniValue getaccountaddress(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"getaccountaddress \"account\"\n"
"\nDEPRECATED. Returns the current GodLikeProducts address for receiving payments to this account.\n"
"\nArguments:\n"
"1. \"account\" (string, required) The account name for the address. It can also be set to the empty string \"\" to represent the default account. The account does not need to exist, it will be created and a new address created if there is no account by the given name.\n"
"\nResult:\n"
"\"address\" (string) The account godlikeproducts address\n"
"\nExamples:\n"
+ HelpExampleCli("getaccountaddress", "")
+ HelpExampleCli("getaccountaddress", "\"\"")
+ HelpExampleCli("getaccountaddress", "\"myaccount\"")
+ HelpExampleRpc("getaccountaddress", "\"myaccount\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
// Parse the account first so we don't generate a key if there's an error
std::string strAccount = AccountFromValue(request.params[0]);
UniValue ret(UniValue::VSTR);
ret = GetAccountAddress(strAccount).ToString();
return ret;
}
UniValue getrawchangeaddress(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 1)
throw std::runtime_error(
"getrawchangeaddress\n"
"\nReturns a new GodLikeProducts address, for receiving change.\n"
"This is for use with raw transactions, NOT normal use.\n"
"\nResult:\n"
"\"address\" (string) The address\n"
"\nExamples:\n"
+ HelpExampleCli("getrawchangeaddress", "")
+ HelpExampleRpc("getrawchangeaddress", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
if (!pwalletMain->IsLocked(true))
pwalletMain->TopUpKeyPool();
CReserveKey reservekey(pwalletMain);
CPubKey vchPubKey;
if (!reservekey.GetReservedKey(vchPubKey, true))
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
reservekey.KeepKey();
CKeyID keyID = vchPubKey.GetID();
return CBitcoinAddress(keyID).ToString();
}
UniValue setaccount(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error(
"setaccount \"address\" \"account\"\n"
"\nDEPRECATED. Sets the account associated with the given address.\n"
"\nArguments:\n"
"1. \"address\" (string, required) The godlikeproducts address to be associated with an account.\n"
"2. \"account\" (string, required) The account to assign the address to.\n"
"\nExamples:\n"
+ HelpExampleCli("setaccount", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"tabby\"")
+ HelpExampleRpc("setaccount", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", \"tabby\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
CBitcoinAddress address(request.params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid GodLikeProducts address");
std::string strAccount;
if (request.params.size() > 1)
strAccount = AccountFromValue(request.params[1]);
// Only add the account if the address is yours.
if (IsMine(*pwalletMain, address.Get()))
{
// Detect when changing the account of an address that is the 'unused current key' of another account:
if (pwalletMain->mapAddressBook.count(address.Get()))
{
std::string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name;
if (address == GetAccountAddress(strOldAccount))
GetAccountAddress(strOldAccount, true);
}
pwalletMain->SetAddressBook(address.Get(), strAccount, "receive");
}
else
throw JSONRPCError(RPC_MISC_ERROR, "setaccount can only be used with own address");
return NullUniValue;
}
UniValue getaccount(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"getaccount \"address\"\n"
"\nDEPRECATED. Returns the account associated with the given address.\n"
"\nArguments:\n"
"1. \"address\" (string, required) The godlikeproducts address for account lookup.\n"
"\nResult:\n"
"\"accountname\" (string) the account address\n"
"\nExamples:\n"
+ HelpExampleCli("getaccount", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\"")
+ HelpExampleRpc("getaccount", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
CBitcoinAddress address(request.params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid GodLikeProducts address");
std::string strAccount;
std::map<CTxDestination, CAddressBookData>::iterator mi = pwalletMain->mapAddressBook.find(address.Get());
if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty())
strAccount = (*mi).second.name;
return strAccount;
}
UniValue getaddressesbyaccount(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"getaddressesbyaccount \"account\"\n"
"\nDEPRECATED. Returns the list of addresses for the given account.\n"
"\nArguments:\n"
"1. \"account\" (string, required) The account name.\n"
"\nResult:\n"
"[ (json array of string)\n"
" \"address\" (string) a godlikeproducts address associated with the given account\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getaddressesbyaccount", "\"tabby\"")
+ HelpExampleRpc("getaddressesbyaccount", "\"tabby\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
std::string strAccount = AccountFromValue(request.params[0]);
// Find all addresses that have the given account
UniValue ret(UniValue::VARR);
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
{
const CBitcoinAddress& address = item.first;
const std::string& strName = item.second.name;
if (strName == strAccount)
ret.push_back(address.ToString());
}
return ret;
}
static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew, bool fUseInstantSend=false, bool fUsePrivateSend=false)
{
CAmount curBalance = pwalletMain->GetBalance();
// Check amount
if (nValue <= 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
if (nValue > curBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
if (pwalletMain->GetBroadcastTransactions() && !g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
// Parse GodLikeProducts address
CScript scriptPubKey = GetScriptForDestination(address);
// Create and send the transaction
CReserveKey reservekey(pwalletMain);
CAmount nFeeRequired;
std::string strError;
std::vector<CRecipient> vecSend;
int nChangePosRet = -1;
CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount};
vecSend.push_back(recipient);
if (!pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet,
strError, NULL, true, fUsePrivateSend ? ONLY_DENOMINATED : ALL_COINS, fUseInstantSend)) {
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance)
strError = strprintf("Error: This transaction requires a transaction fee of at least %s", FormatMoney(nFeeRequired));
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
CValidationState state;
if (!pwalletMain->CommitTransaction(wtxNew, reservekey, g_connman.get(), state, fUseInstantSend ? NetMsgType::TXLOCKREQUEST : NetMsgType::TX)) {
strError = strprintf("Error: The transaction was rejected! Reason given: %s", state.GetRejectReason());
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
}
UniValue sendtoaddress(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 2 || request.params.size() > 7)
throw std::runtime_error(
"sendtoaddress \"address\" amount ( \"comment\" \"comment_to\" subtractfeefromamount use_is use_ps )\n"
"\nSend an amount to a given address.\n"
+ HelpRequiringPassphrase() +
"\nArguments:\n"
"1. \"address\" (string, required) The godlikeproducts address to send to.\n"
"2. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n"
"3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
" This is not part of the transaction, just kept in your wallet.\n"
"4. \"comment_to\" (string, optional) A comment to store the name of the person or organization \n"
" to which you're sending the transaction. This is not part of the \n"
" transaction, just kept in your wallet.\n"
"5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
" The recipient will receive less amount of GodLikeProducts than you enter in the amount field.\n"
"6. \"use_is\" (bool, optional, default=false) Send this transaction as InstantSend\n"
"7. \"use_ps\" (bool, optional, default=false) Use anonymized funds only\n"
"\nResult:\n"
"\"txid\" (string) The transaction id.\n"
"\nExamples:\n"
+ HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1")
+ HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1 \"donation\" \"seans outpost\"")
+ HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1 \"\" \"\" true")
+ HelpExampleRpc("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", 0.1, \"donation\", \"seans outpost\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
CBitcoinAddress address(request.params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid GodLikeProducts address");
// Amount
CAmount nAmount = AmountFromValue(request.params[1]);
if (nAmount <= 0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
// Wallet comments
CWalletTx wtx;
if (request.params.size() > 2 && !request.params[2].isNull() && !request.params[2].get_str().empty())
wtx.mapValue["comment"] = request.params[2].get_str();
if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty())
wtx.mapValue["to"] = request.params[3].get_str();
bool fSubtractFeeFromAmount = false;
if (request.params.size() > 4)
fSubtractFeeFromAmount = request.params[4].get_bool();
bool fUseInstantSend = false;
bool fUsePrivateSend = false;
if (request.params.size() > 5)
fUseInstantSend = request.params[5].get_bool();
if (request.params.size() > 6)
fUsePrivateSend = request.params[6].get_bool();
EnsureWalletIsUnlocked();
SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, wtx, fUseInstantSend, fUsePrivateSend);
return wtx.GetHash().GetHex();
}
UniValue instantsendtoaddress(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 2 || request.params.size() > 5)
throw std::runtime_error(
"instantsendtoaddress \"address\" amount ( \"comment\" \"comment-to\" subtractfeefromamount )\n"
"\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n"
+ HelpRequiringPassphrase() +
"\nArguments:\n"
"1. \"address\" (string, required) The godlikeproducts address to send to.\n"
"2. \"amount\" (numeric, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n"
"3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
" This is not part of the transaction, just kept in your wallet.\n"
"4. \"comment_to\" (string, optional) A comment to store the name of the person or organization \n"
" to which you're sending the transaction. This is not part of the \n"
" transaction, just kept in your wallet.\n"
"5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
" The recipient will receive less amount of GodLikeProducts than you enter in the amount field.\n"
"\nResult:\n"
"\"transactionid\" (string) The transaction id.\n"
"\nExamples:\n"
+ HelpExampleCli("instantsendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1")
+ HelpExampleCli("instantsendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1 \"donation\" \"seans outpost\"")
+ HelpExampleCli("instantsendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1 \"\" \"\" true")
+ HelpExampleRpc("instantsendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", 0.1, \"donation\", \"seans outpost\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
CBitcoinAddress address(request.params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid GodLikeProducts address");
// Amount
CAmount nAmount = AmountFromValue(request.params[1]);
if (nAmount <= 0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
// Wallet comments
CWalletTx wtx;
if (request.params.size() > 2 && !request.params[2].isNull() && !request.params[2].get_str().empty())
wtx.mapValue["comment"] = request.params[2].get_str();
if (request.params.size() > 3 && !request.params[3].isNull() && !request.params[3].get_str().empty())
wtx.mapValue["to"] = request.params[3].get_str();
bool fSubtractFeeFromAmount = false;
if (request.params.size() > 4)
fSubtractFeeFromAmount = request.params[4].get_bool();
EnsureWalletIsUnlocked();
SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, wtx, true);
return wtx.GetHash().GetHex();
}
UniValue listaddressgroupings(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp)
throw std::runtime_error(
"listaddressgroupings\n"
"\nLists groups of addresses which have had their common ownership\n"
"made public by common use as inputs or as the resulting change\n"
"in past transactions\n"
"\nResult:\n"
"[\n"
" [\n"
" [\n"
" \"address\", (string) The godlikeproducts address\n"
" amount, (numeric) The amount in " + CURRENCY_UNIT + "\n"
" \"account\" (string, optional) DEPRECATED. The account\n"
" ]\n"
" ,...\n"
" ]\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("listaddressgroupings", "")
+ HelpExampleRpc("listaddressgroupings", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
UniValue jsonGroupings(UniValue::VARR);
std::map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
BOOST_FOREACH(std::set<CTxDestination> grouping, pwalletMain->GetAddressGroupings())
{
UniValue jsonGrouping(UniValue::VARR);
BOOST_FOREACH(CTxDestination address, grouping)
{
UniValue addressInfo(UniValue::VARR);
addressInfo.push_back(CBitcoinAddress(address).ToString());
addressInfo.push_back(ValueFromAmount(balances[address]));
{
if (pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwalletMain->mapAddressBook.end())
addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second.name);
}
jsonGrouping.push_back(addressInfo);
}
jsonGroupings.push_back(jsonGrouping);
}
return jsonGroupings;
}
UniValue listaddressbalances(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 1)
throw std::runtime_error(
"listaddressbalances ( minamount )\n"
"\nLists addresses of this wallet and their balances\n"
"\nArguments:\n"
"1. minamount (numeric, optional, default=0) Minimum balance in " + CURRENCY_UNIT + " an address should have to be shown in the list\n"
"\nResult:\n"
"{\n"
" \"address\": amount, (string) The godlikeproducts address and the amount in " + CURRENCY_UNIT + "\n"
" ,...\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("listaddressbalances", "")
+ HelpExampleCli("listaddressbalances", "10")
+ HelpExampleRpc("listaddressbalances", "")
+ HelpExampleRpc("listaddressbalances", "10")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
CAmount nMinAmount = 0;
if (request.params.size() > 0)
nMinAmount = AmountFromValue(request.params[0]);
if (nMinAmount < 0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
UniValue jsonBalances(UniValue::VOBJ);
std::map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
for (auto& balance : balances)
if (balance.second >= nMinAmount)
jsonBalances.push_back(Pair(CBitcoinAddress(balance.first).ToString(), ValueFromAmount(balance.second)));
return jsonBalances;
}
UniValue signmessage(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 2)
throw std::runtime_error(
"signmessage \"address\" \"message\"\n"
"\nSign a message with the private key of an address"
+ HelpRequiringPassphrase() + "\n"
"\nArguments:\n"
"1. \"address\" (string, required) The godlikeproducts address to use for the private key.\n"
"2. \"message\" (string, required) The message to create a signature of.\n"
"\nResult:\n"
"\"signature\" (string) The signature of the message encoded in base 64\n"
"\nExamples:\n"
"\nUnlock the wallet for 30 seconds\n"
+ HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
"\nCreate the signature\n"
+ HelpExampleCli("signmessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"my message\"") +
"\nVerify the signature\n"
+ HelpExampleCli("verifymessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"signature\" \"my message\"") +
"\nAs json rpc\n"
+ HelpExampleRpc("signmessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", \"my message\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
EnsureWalletIsUnlocked();
std::string strAddress = request.params[0].get_str();
std::string strMessage = request.params[1].get_str();
CBitcoinAddress addr(strAddress);
if (!addr.IsValid())
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
CKeyID keyID;
if (!addr.GetKeyID(keyID))
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
CKey key;
if (!pwalletMain->GetKey(keyID, key))
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
CHashWriter ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << strMessage;
std::vector<unsigned char> vchSig;
if (!key.SignCompact(ss.GetHash(), vchSig))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
return EncodeBase64(&vchSig[0], vchSig.size());
}
UniValue getreceivedbyaddress(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
throw std::runtime_error(
"getreceivedbyaddress \"address\" ( minconf addlockconf )\n"
"\nReturns the total amount received by the given address in transactions with at least minconf confirmations.\n"
"\nArguments:\n"
"1. \"address\" (string, required) The godlikeproducts address for transactions.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
"3. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
"\nResult:\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n"
"\nExamples:\n"
"\nThe amount from transactions with at least 1 confirmation\n"
+ HelpExampleCli("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\"") +
"\nThe amount including unconfirmed transactions, zero confirmations\n"
+ HelpExampleCli("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0") +
"\nThe amount with at least 6 confirmation, very safe\n"
+ HelpExampleCli("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 6") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", 6")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
// GodLikeProducts address
CBitcoinAddress address = CBitcoinAddress(request.params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid GodLikeProducts address");
CScript scriptPubKey = GetScriptForDestination(address.Get());
if (!IsMine(*pwalletMain, scriptPubKey))
return ValueFromAmount(0);
// Minimum confirmations
int nMinDepth = 1;
if (request.params.size() > 1)
nMinDepth = request.params[1].get_int();
bool fAddLockConf = (request.params.size() > 2 && request.params[2].get_bool());
// Tally
CAmount nAmount = 0;
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
continue;
BOOST_FOREACH(const CTxOut& txout, wtx.tx->vout)
if (txout.scriptPubKey == scriptPubKey)
if (wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth)
nAmount += txout.nValue;
}
return ValueFromAmount(nAmount);
}
UniValue getreceivedbyaccount(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
throw std::runtime_error(
"getreceivedbyaccount \"account\" ( minconf addlockconf )\n"
"\nDEPRECATED. Returns the total amount received by addresses with <account> in transactions with specified minimum number of confirmations.\n"
"\nArguments:\n"
"1. \"account\" (string, required) The selected account, may be the default account using \"\".\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
"3. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
"\nResult:\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n"
"\nExamples:\n"
"\nAmount received by the default account with at least 1 confirmation\n"
+ HelpExampleCli("getreceivedbyaccount", "\"\"") +
"\nAmount received at the tabby account including unconfirmed amounts with zero confirmations\n"
+ HelpExampleCli("getreceivedbyaccount", "\"tabby\" 0") +
"\nThe amount with at least 6 confirmation, very safe\n"
+ HelpExampleCli("getreceivedbyaccount", "\"tabby\" 6") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("getreceivedbyaccount", "\"tabby\", 6")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
// Minimum confirmations
int nMinDepth = 1;
if (request.params.size() > 1)
nMinDepth = request.params[1].get_int();
bool fAddLockConf = (request.params.size() > 2 && request.params[2].get_bool());
// Get the set of pub keys assigned to account
std::string strAccount = AccountFromValue(request.params[0]);
std::set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);
// Tally
CAmount nAmount = 0;
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
continue;
BOOST_FOREACH(const CTxOut& txout, wtx.tx->vout)
{
CTxDestination address;
if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address))
if (wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth)
nAmount += txout.nValue;
}
}
return ValueFromAmount(nAmount);
}
UniValue getbalance(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 4)
throw std::runtime_error(
"getbalance ( \"account\" minconf addlockconf include_watchonly )\n"
"\nIf account is not specified, returns the server's total available balance.\n"
"If account is specified (DEPRECATED), returns the balance in the account.\n"
"Note that the account \"\" is not the same as leaving the parameter out.\n"
"The server total may be different to the balance in the default \"\" account.\n"
"\nArguments:\n"
"1. \"account\" (string, optional) DEPRECATED. The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
"3. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
"4. include_watchonly (bool, optional, default=false) Also include balance in watch-only addresses (see 'importaddress')\n"
"\nResult:\n"
"amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n"
"\nExamples:\n"
"\nThe total amount in the wallet\n"
+ HelpExampleCli("getbalance", "") +
"\nThe total amount in the wallet at least 5 blocks confirmed\n"
+ HelpExampleCli("getbalance", "\"*\" 6") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("getbalance", "\"*\", 6")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
if (request.params.size() == 0)
return ValueFromAmount(pwalletMain->GetBalance());
int nMinDepth = 1;
if (request.params.size() > 1)
nMinDepth = request.params[1].get_int();
bool fAddLockConf = (request.params.size() > 2 && request.params[2].get_bool());
isminefilter filter = ISMINE_SPENDABLE;
if(request.params.size() > 3)
if(request.params[3].get_bool())
filter = filter | ISMINE_WATCH_ONLY;
if (request.params[0].get_str() == "*") {
// Calculate total balance a different way from GetBalance()
// (GetBalance() sums up all unspent TxOuts)
// getbalance and "getbalance * 1 true" should return the same number
CAmount nBalance = 0;
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
continue;
CAmount allFee;
std::string strSentAccount;
std::list<COutputEntry> listReceived;
std::list<COutputEntry> listSent;
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
if (wtx.GetDepthInMainChain(fAddLockConf) >= nMinDepth)
{
BOOST_FOREACH(const COutputEntry& r, listReceived)
nBalance += r.amount;
}
BOOST_FOREACH(const COutputEntry& s, listSent)
nBalance -= s.amount;
nBalance -= allFee;
}
return ValueFromAmount(nBalance);
}
std::string strAccount = AccountFromValue(request.params[0]);
CAmount nBalance = pwalletMain->GetAccountBalance(strAccount, nMinDepth, filter, fAddLockConf);
return ValueFromAmount(nBalance);
}
UniValue getunconfirmedbalance(const JSONRPCRequest &request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 0)
throw std::runtime_error(
"getunconfirmedbalance\n"
"Returns the server's total unconfirmed balance\n");
LOCK2(cs_main, pwalletMain->cs_wallet);
return ValueFromAmount(pwalletMain->GetUnconfirmedBalance());
}
UniValue movecmd(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 3 || request.params.size() > 5)
throw std::runtime_error(
"move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
"\nDEPRECATED. Move a specified amount from one account in your wallet to another.\n"
"\nArguments:\n"
"1. \"fromaccount\" (string, required) The name of the account to move funds from. May be the default account using \"\".\n"
"2. \"toaccount\" (string, required) The name of the account to move funds to. May be the default account using \"\".\n"
"3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts.\n"
"4. (dummy) (numeric, optional) Ignored. Remains for backward compatibility.\n"
"5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n"
"\nResult:\n"
"true|false (boolean) true if successful.\n"
"\nExamples:\n"
"\nMove 0.01 " + CURRENCY_UNIT + " from the default account to the account named tabby\n"
+ HelpExampleCli("move", "\"\" \"tabby\" 0.01") +
"\nMove 0.01 " + CURRENCY_UNIT + " timotei to akiko with a comment and funds have 6 confirmations\n"
+ HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
std::string strFrom = AccountFromValue(request.params[0]);
std::string strTo = AccountFromValue(request.params[1]);
CAmount nAmount = AmountFromValue(request.params[2]);
if (nAmount <= 0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
if (request.params.size() > 3)
// unused parameter, used to be nMinDepth, keep type-checking it though
(void)request.params[3].get_int();
std::string strComment;
if (request.params.size() > 4)
strComment = request.params[4].get_str();
if (!pwalletMain->AccountMove(strFrom, strTo, nAmount, strComment))
throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
return true;
}
UniValue sendfrom(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 3 || request.params.size() > 7)
throw std::runtime_error(
"sendfrom \"fromaccount\" \"toaddress\" amount ( minconf addlockconf \"comment\" \"comment_to\" )\n"
"\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a godlikeproducts address."
+ HelpRequiringPassphrase() + "\n"
"\nArguments:\n"
"1. \"fromaccount\" (string, required) The name of the account to send funds from. May be the default account using \"\".\n"
" Specifying an account does not influence coin selection, but it does associate the newly created\n"
" transaction with the account, so the account's balance computation and transaction history can reflect\n"
" the spend.\n"
"2. \"toaddress\" (string, required) The godlikeproducts address to send funds to.\n"
"3. amount (numeric or string, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top).\n"
"4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n"
"5. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
"6. \"comment\" (string, optional) A comment used to store what the transaction is for. \n"
" This is not part of the transaction, just kept in your wallet.\n"
"7. \"comment_to\" (string, optional) An optional comment to store the name of the person or organization \n"
" to which you're sending the transaction. This is not part of the transaction, \n"
" it is just kept in your wallet.\n"
"\nResult:\n"
"\"txid\" (string) The transaction id.\n"
"\nExamples:\n"
"\nSend 0.01 " + CURRENCY_UNIT + " from the default account to the address, must have at least 1 confirmation\n"
+ HelpExampleCli("sendfrom", "\"\" \"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.01") +
"\nSend 0.01 from the tabby account to the given address, funds must have at least 6 confirmations\n"
+ HelpExampleCli("sendfrom", "\"tabby\" \"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.01 6 false \"donation\" \"seans outpost\"") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("sendfrom", "\"tabby\", \"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", 0.01, 6, false, \"donation\", \"seans outpost\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
std::string strAccount = AccountFromValue(request.params[0]);
CBitcoinAddress address(request.params[1].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid GodLikeProducts address");
CAmount nAmount = AmountFromValue(request.params[2]);
if (nAmount <= 0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
int nMinDepth = 1;
if (request.params.size() > 3)
nMinDepth = request.params[3].get_int();
bool fAddLockConf = (request.params.size() > 4 && request.params[4].get_bool());
CWalletTx wtx;
wtx.strFromAccount = strAccount;
if (request.params.size() > 5 && !request.params[5].isNull() && !request.params[5].get_str().empty())
wtx.mapValue["comment"] = request.params[5].get_str();
if (request.params.size() > 6 && !request.params[6].isNull() && !request.params[6].get_str().empty())
wtx.mapValue["to"] = request.params[6].get_str();
EnsureWalletIsUnlocked();
// Check funds
CAmount nBalance = pwalletMain->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE, fAddLockConf);
if (nAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
SendMoney(address.Get(), nAmount, false, wtx);
return wtx.GetHash().GetHex();
}
UniValue sendmany(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 2 || request.params.size() > 8)
throw std::runtime_error(
"sendmany \"fromaccount\" {\"address\":amount,...} ( minconf addlockconf \"comment\" [\"address\",...] subtractfeefromamount use_is use_ps )\n"
"\nSend multiple times. Amounts are double-precision floating point numbers."
+ HelpRequiringPassphrase() + "\n"
"\nArguments:\n"
"1. \"fromaccount\" (string, required) DEPRECATED. The account to send the funds from. Should be \"\" for the default account\n"
"2. \"amounts\" (string, required) A json object with addresses and amounts\n"
" {\n"
" \"address\":amount (numeric or string) The godlikeproducts address is the key, the numeric amount (can be string) in " + CURRENCY_UNIT + " is the value\n"
" ,...\n"
" }\n"
"3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n"
"4. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
"5. \"comment\" (string, optional) A comment\n"
"6. subtractfeefromamount (array, optional) A json array with addresses.\n"
" The fee will be equally deducted from the amount of each selected address.\n"
" Those recipients will receive less godlikeproductss than you enter in their corresponding amount field.\n"
" If no addresses are specified here, the sender pays the fee.\n"
" [\n"
" \"address\" (string) Subtract fee from this address\n"
" ,...\n"
" ]\n"
"7. \"use_is\" (bool, optional, default=false) Send this transaction as InstantSend\n"
"8. \"use_ps\" (bool, optional, default=false) Use anonymized funds only\n"
"\nResult:\n"
"\"txid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n"
" the number of addresses.\n"
"\nExamples:\n"
"\nSend two amounts to two different addresses:\n"
+ HelpExampleCli("sendmany", "\"tabby\" \"{\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\\\":0.01,\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcG\\\":0.02}\"") +
"\nSend two amounts to two different addresses setting the confirmation and comment:\n"
+ HelpExampleCli("sendmany", "\"tabby\" \"{\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\\\":0.01,\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcG\\\":0.02}\" 6 false \"testing\"") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("sendmany", "\"tabby\", \"{\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\\\":0.01,\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcG\\\":0.02}\", 6, false, \"testing\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
if (pwalletMain->GetBroadcastTransactions() && !g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
std::string strAccount = AccountFromValue(request.params[0]);
UniValue sendTo = request.params[1].get_obj();
int nMinDepth = 1;
if (request.params.size() > 2)
nMinDepth = request.params[2].get_int();
bool fAddLockConf = (request.params.size() > 3 && request.params[3].get_bool());
CWalletTx wtx;
wtx.strFromAccount = strAccount;
if (request.params.size() > 4 && !request.params[4].isNull() && !request.params[4].get_str().empty())
wtx.mapValue["comment"] = request.params[4].get_str();
UniValue subtractFeeFromAmount(UniValue::VARR);
if (request.params.size() > 5)
subtractFeeFromAmount = request.params[5].get_array();
std::set<CBitcoinAddress> setAddress;
std::vector<CRecipient> vecSend;
CAmount totalAmount = 0;
std::vector<std::string> keys = sendTo.getKeys();
BOOST_FOREACH(const std::string& name_, keys)
{
CBitcoinAddress address(name_);
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid GodLikeProducts address: ")+name_);
if (setAddress.count(address))
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ")+name_);
setAddress.insert(address);
CScript scriptPubKey = GetScriptForDestination(address.Get());
CAmount nAmount = AmountFromValue(sendTo[name_]);
if (nAmount <= 0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
totalAmount += nAmount;
bool fSubtractFeeFromAmount = false;
for (unsigned int idx = 0; idx < subtractFeeFromAmount.size(); idx++) {
const UniValue& addr = subtractFeeFromAmount[idx];
if (addr.get_str() == name_)
fSubtractFeeFromAmount = true;
}
CRecipient recipient = {scriptPubKey, nAmount, fSubtractFeeFromAmount};
vecSend.push_back(recipient);
}
EnsureWalletIsUnlocked();
// Check funds
CAmount nBalance = pwalletMain->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE, fAddLockConf);
if (totalAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
// Send
CReserveKey keyChange(pwalletMain);
CAmount nFeeRequired = 0;
int nChangePosRet = -1;
std::string strFailReason;
bool fUseInstantSend = false;
bool fUsePrivateSend = false;
if (request.params.size() > 6)
fUseInstantSend = request.params[6].get_bool();
if (request.params.size() > 7)
fUsePrivateSend = request.params[7].get_bool();
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason,
NULL, true, fUsePrivateSend ? ONLY_DENOMINATED : ALL_COINS, fUseInstantSend);
if (!fCreated)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
CValidationState state;
if (!pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get(), state, fUseInstantSend ? NetMsgType::TXLOCKREQUEST : NetMsgType::TX)) {
strFailReason = strprintf("Transaction commit failed:: %s", state.GetRejectReason());
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason);
}
return wtx.GetHash().GetHex();
}
// Defined in rpc/misc.cpp
extern CScript _createmultisig_redeemScript(const UniValue& params);
UniValue addmultisigaddress(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
{
std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n"
"\nAdd a nrequired-to-sign multisignature address to the wallet.\n"
"Each key is a GodLikeProducts address or hex-encoded public key.\n"
"If 'account' is specified (DEPRECATED), assign address to that account.\n"
"\nArguments:\n"
"1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
"2. \"keys\" (string, required) A json array of godlikeproducts addresses or hex-encoded public keys\n"
" [\n"
" \"address\" (string) godlikeproducts address or hex-encoded public key\n"
" ...,\n"
" ]\n"
"3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n"
"\nResult:\n"
"\"address\" (string) A godlikeproducts address associated with the keys.\n"
"\nExamples:\n"
"\nAdd a multisig address from 2 addresses\n"
+ HelpExampleCli("addmultisigaddress", "2 \"[\\\"Xt4qk9uKvQYAonVGSZNXqxeDmtjaEWgfrS\\\",\\\"XoSoWQkpgLpppPoyyzbUFh1fq2RBvW6UK2\\\"]\"") +
"\nAs json rpc call\n"
+ HelpExampleRpc("addmultisigaddress", "2, \"[\\\"Xt4qk9uKvQYAonVGSZNXqxeDmtjaEWgfrS\\\",\\\"XoSoWQkpgLpppPoyyzbUFh1fq2RBvW6UK2\\\"]\"")
;
throw std::runtime_error(msg);
}
LOCK2(cs_main, pwalletMain->cs_wallet);
std::string strAccount;
if (request.params.size() > 2)
strAccount = AccountFromValue(request.params[2]);
// Construct using pay-to-script-hash:
CScript inner = _createmultisig_redeemScript(request.params);
CScriptID innerID(inner);
pwalletMain->AddCScript(inner);
pwalletMain->SetAddressBook(innerID, strAccount, "send");
return CBitcoinAddress(innerID).ToString();
}
struct tallyitem
{
CAmount nAmount;
int nConf;
std::vector<uint256> txids;
bool fIsWatchonly;
tallyitem()
{
nAmount = 0;
nConf = std::numeric_limits<int>::max();
fIsWatchonly = false;
}
};
UniValue ListReceived(const UniValue& params, bool fByAccounts)
{
// Minimum confirmations
int nMinDepth = 1;
if (params.size() > 0)
nMinDepth = params[0].get_int();
bool fAddLockConf = (params.size() > 1 && params[1].get_bool());
// Whether to include empty accounts
bool fIncludeEmpty = false;
if (params.size() > 2)
fIncludeEmpty = params[2].get_bool();
isminefilter filter = ISMINE_SPENDABLE;
if(params.size() > 3)
if(params[3].get_bool())
filter = filter | ISMINE_WATCH_ONLY;
// Tally
std::map<CBitcoinAddress, tallyitem> mapTally;
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
continue;
int nDepth = wtx.GetDepthInMainChain(fAddLockConf);
if (nDepth < nMinDepth)
continue;
BOOST_FOREACH(const CTxOut& txout, wtx.tx->vout)
{
CTxDestination address;
if (!ExtractDestination(txout.scriptPubKey, address))
continue;
isminefilter mine = IsMine(*pwalletMain, address);
if(!(mine & filter))
continue;
tallyitem& item = mapTally[address];
item.nAmount += txout.nValue;
item.nConf = std::min(item.nConf, nDepth);
item.txids.push_back(wtx.GetHash());
if (mine & ISMINE_WATCH_ONLY)
item.fIsWatchonly = true;
}
}
// Reply
UniValue ret(UniValue::VARR);
std::map<std::string, tallyitem> mapAccountTally;
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
{
const CBitcoinAddress& address = item.first;
const std::string& strAccount = item.second.name;
std::map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address);
if (it == mapTally.end() && !fIncludeEmpty)
continue;
isminefilter mine = IsMine(*pwalletMain, address.Get());
if(!(mine & filter))
continue;
CAmount nAmount = 0;
int nConf = std::numeric_limits<int>::max();
bool fIsWatchonly = false;
if (it != mapTally.end())
{
nAmount = (*it).second.nAmount;
nConf = (*it).second.nConf;
fIsWatchonly = (*it).second.fIsWatchonly;
}
if (fByAccounts)
{
tallyitem& _item = mapAccountTally[strAccount];
_item.nAmount += nAmount;
_item.nConf = std::min(_item.nConf, nConf);
_item.fIsWatchonly = fIsWatchonly;
}
else
{
UniValue obj(UniValue::VOBJ);
if(fIsWatchonly)
obj.push_back(Pair("involvesWatchonly", true));
obj.push_back(Pair("address", address.ToString()));
obj.push_back(Pair("account", strAccount));
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
if (!fByAccounts)
obj.push_back(Pair("label", strAccount));
UniValue transactions(UniValue::VARR);
if (it != mapTally.end())
{
BOOST_FOREACH(const uint256& _item, (*it).second.txids)
{
transactions.push_back(_item.GetHex());
}
}
obj.push_back(Pair("txids", transactions));
ret.push_back(obj);
}
}
if (fByAccounts)
{
for (std::map<std::string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it)
{
CAmount nAmount = (*it).second.nAmount;
int nConf = (*it).second.nConf;
UniValue obj(UniValue::VOBJ);
if((*it).second.fIsWatchonly)
obj.push_back(Pair("involvesWatchonly", true));
obj.push_back(Pair("account", (*it).first));
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
ret.push_back(obj);
}
}
return ret;
}
UniValue listreceivedbyaddress(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 4)
throw std::runtime_error(
"listreceivedbyaddress ( minconf addlockconf include_empty include_watchonly)\n"
"\nList incoming payments grouped by receiving address.\n"
"\nArguments:\n"
"1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
"2. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
"3. include_empty (bool, optional, default=false) Whether to include addresses that haven't received any payments.\n"
"4. include_watchonly (bool, optional, default=false) Whether to include watch-only addresses (see 'importaddress').\n"
"\nResult:\n"
"[\n"
" {\n"
" \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
" \"address\" : \"receivingaddress\", (string) The receiving address\n"
" \"account\" : \"accountname\", (string) DEPRECATED. The account of the receiving address. The default account is \"\".\n"
" \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " received by the address\n"
" \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included.\n"
" If 'addlockconf' is true, the minimum number of confirmations is calculated\n"
" including additional " + std::to_string(nInstantSendDepth) + " confirmations for transactions locked via InstantSend\n"
" \"label\" : \"label\", (string) A comment for the address/transaction, if any\n"
" \"txids\": [\n"
" n, (numeric) The ids of transactions received with the address \n"
" ...\n"
" ]\n"
" }\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("listreceivedbyaddress", "")
+ HelpExampleCli("listreceivedbyaddress", "6 false true")
+ HelpExampleRpc("listreceivedbyaddress", "6, false, true, true")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
return ListReceived(request.params, false);
}
UniValue listreceivedbyaccount(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 4)
throw std::runtime_error(
"listreceivedbyaccount ( minconf addlockconf include_empty include_watchonly)\n"
"\nDEPRECATED. List incoming payments grouped by account.\n"
"\nArguments:\n"
"1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
"2. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
"3. include_empty (bool, optional, default=false) Whether to include accounts that haven't received any payments.\n"
"4. include_watchonly (bool, optional, default=false) Whether to include watch-only addresses (see 'importaddress').\n"
"\nResult:\n"
"[\n"
" {\n"
" \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n"
" \"account\" : \"accountname\", (string) The account name of the receiving account\n"
" \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n"
" \"confirmations\" : n (numeric) The number of blockchain confirmations of the most recent transaction included\n"
" \"label\" : \"label\" (string) A comment for the address/transaction, if any\n"
" }\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("listreceivedbyaccount", "")
+ HelpExampleCli("listreceivedbyaccount", "6 false true")
+ HelpExampleRpc("listreceivedbyaccount", "6, false, true, true")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
return ListReceived(request.params, true);
}
static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
{
CBitcoinAddress addr;
if (addr.Set(dest))
entry.push_back(Pair("address", addr.ToString()));
}
void ListTransactions(const CWalletTx& wtx, const std::string& strAccount, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter)
{
CAmount nFee;
std::string strSentAccount;
std::list<COutputEntry> listReceived;
std::list<COutputEntry> listSent;
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, filter);
bool fAllAccounts = (strAccount == std::string("*"));
bool involvesWatchonly = wtx.IsFromMe(ISMINE_WATCH_ONLY);
// Sent
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
{
BOOST_FOREACH(const COutputEntry& s, listSent)
{
UniValue entry(UniValue::VOBJ);
if(involvesWatchonly || (::IsMine(*pwalletMain, s.destination) & ISMINE_WATCH_ONLY))
entry.push_back(Pair("involvesWatchonly", true));
entry.push_back(Pair("account", strSentAccount));
MaybePushAddress(entry, s.destination);
std::map<std::string, std::string>::const_iterator it = wtx.mapValue.find("DS");
entry.push_back(Pair("category", (it != wtx.mapValue.end() && it->second == "1") ? "privatesend" : "send"));
entry.push_back(Pair("amount", ValueFromAmount(-s.amount)));
if (pwalletMain->mapAddressBook.count(s.destination))
entry.push_back(Pair("label", pwalletMain->mapAddressBook[s.destination].name));
entry.push_back(Pair("vout", s.vout));
entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
if (fLong)
WalletTxToJSON(wtx, entry);
entry.push_back(Pair("abandoned", wtx.isAbandoned()));
ret.push_back(entry);
}
}
// Received
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth)
{
BOOST_FOREACH(const COutputEntry& r, listReceived)
{
std::string account;
if (pwalletMain->mapAddressBook.count(r.destination))
account = pwalletMain->mapAddressBook[r.destination].name;
if (fAllAccounts || (account == strAccount))
{
UniValue entry(UniValue::VOBJ);
if(involvesWatchonly || (::IsMine(*pwalletMain, r.destination) & ISMINE_WATCH_ONLY))
entry.push_back(Pair("involvesWatchonly", true));
entry.push_back(Pair("account", account));
MaybePushAddress(entry, r.destination);
if (wtx.IsCoinBase())
{
if (wtx.GetDepthInMainChain() < 1)
entry.push_back(Pair("category", "orphan"));
else if (wtx.GetBlocksToMaturity() > 0)
entry.push_back(Pair("category", "immature"));
else
entry.push_back(Pair("category", "generate"));
}
else
{
entry.push_back(Pair("category", "receive"));
}
entry.push_back(Pair("amount", ValueFromAmount(r.amount)));
if (pwalletMain->mapAddressBook.count(r.destination))
entry.push_back(Pair("label", account));
entry.push_back(Pair("vout", r.vout));
if (fLong)
WalletTxToJSON(wtx, entry);
ret.push_back(entry);
}
}
}
}
void AcentryToJSON(const CAccountingEntry& acentry, const std::string& strAccount, UniValue& ret)
{
bool fAllAccounts = (strAccount == std::string("*"));
if (fAllAccounts || acentry.strAccount == strAccount)
{
UniValue entry(UniValue::VOBJ);
entry.push_back(Pair("account", acentry.strAccount));
entry.push_back(Pair("category", "move"));
entry.push_back(Pair("time", acentry.nTime));
entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit)));
entry.push_back(Pair("otheraccount", acentry.strOtherAccount));
entry.push_back(Pair("comment", acentry.strComment));
ret.push_back(entry);
}
}
UniValue listtransactions(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 4)
throw std::runtime_error(
"listtransactions ( \"account\" count skip include_watchonly)\n"
"\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n"
"\nArguments:\n"
"1. \"account\" (string, optional) DEPRECATED. The account name. Should be \"*\".\n"
"2. count (numeric, optional, default=10) The number of transactions to return\n"
"3. skip (numeric, optional, default=0) The number of transactions to skip\n"
"4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n"
"\nResult:\n"
"[\n"
" {\n"
" \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. \n"
" It will be \"\" for the default account.\n"
" \"address\":\"address\", (string) The godlikeproducts address of the transaction. Not present for \n"
" move transactions (category = move).\n"
" \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n"
" transaction between accounts, and not associated with an address,\n"
" transaction id or block. 'send' and 'receive' transactions are \n"
" associated with an address, transaction id and block details\n"
" \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the\n"
" 'move' category for moves outbound. It is positive for the 'receive' category,\n"
" and for the 'move' category for inbound funds.\n"
" \"label\": \"label\", (string) A comment for the address/transaction, if any\n"
" \"vout\": n, (numeric) the vout value\n"
" \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
" 'send' category of transactions.\n"
" \"instantlock\" : true|false, (bool) Current transaction lock state. Available for 'send' and 'receive' category of transactions.\n"
" \"confirmations\": n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send' and \n"
" 'receive' category of transactions. Negative confirmations indicate the\n"
" transation conflicts with the block chain\n"
" \"trusted\": xxx, (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend.\n"
" \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n"
" category of transactions.\n"
" \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive'\n"
" category of transactions.\n"
" \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
" \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
" \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
" \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n"
" for 'send' and 'receive' category of transactions.\n"
" \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
" \"otheraccount\": \"accountname\", (string) DEPRECATED. For the 'move' category of transactions, the account the funds came \n"
" from (for receiving funds, positive amounts), or went to (for sending funds,\n"
" negative amounts).\n"
" \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
" may be unknown for unconfirmed transactions not in the mempool\n"
" \"abandoned\": xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n"
" 'send' category of transactions.\n"
" }\n"
"]\n"
"\nExamples:\n"
"\nList the most recent 10 transactions in the systems\n"
+ HelpExampleCli("listtransactions", "") +
"\nList transactions 100 to 120\n"
+ HelpExampleCli("listtransactions", "\"*\" 20 100") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("listtransactions", "\"*\", 20, 100")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
std::string strAccount = "*";
if (request.params.size() > 0)
strAccount = request.params[0].get_str();
int nCount = 10;
if (request.params.size() > 1)
nCount = request.params[1].get_int();
int nFrom = 0;
if (request.params.size() > 2)
nFrom = request.params[2].get_int();
isminefilter filter = ISMINE_SPENDABLE;
if(request.params.size() > 3)
if(request.params[3].get_bool())
filter = filter | ISMINE_WATCH_ONLY;
if (nCount < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
if (nFrom < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
UniValue ret(UniValue::VARR);
const CWallet::TxItems & txOrdered = pwalletMain->wtxOrdered;
// iterate backwards until we have nCount items to return:
for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
{
CWalletTx *const pwtx = (*it).second.first;
if (pwtx != 0)
ListTransactions(*pwtx, strAccount, 0, true, ret, filter);
CAccountingEntry *const pacentry = (*it).second.second;
if (pacentry != 0)
AcentryToJSON(*pacentry, strAccount, ret);
if ((int)ret.size() >= (nCount+nFrom)) break;
}
// ret is newest to oldest
if (nFrom > (int)ret.size())
nFrom = ret.size();
if ((nFrom + nCount) > (int)ret.size())
nCount = ret.size() - nFrom;
std::vector<UniValue> arrTmp = ret.getValues();
std::vector<UniValue>::iterator first = arrTmp.begin();
std::advance(first, nFrom);
std::vector<UniValue>::iterator last = arrTmp.begin();
std::advance(last, nFrom+nCount);
if (last != arrTmp.end()) arrTmp.erase(last, arrTmp.end());
if (first != arrTmp.begin()) arrTmp.erase(arrTmp.begin(), first);
std::reverse(arrTmp.begin(), arrTmp.end()); // Return oldest to newest
ret.clear();
ret.setArray();
ret.push_backV(arrTmp);
return ret;
}
UniValue listaccounts(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 3)
throw std::runtime_error(
"listaccounts ( minconf addlockconf include_watchonly)\n"
"\nDEPRECATED. Returns Object that has account names as keys, account balances as values.\n"
"\nArguments:\n"
"1. minconf (numeric, optional, default=1) Only include transactions with at least this many confirmations\n"
"2. addlockconf (bool, optional, default=false) Whether to add " + std::to_string(nInstantSendDepth) + " confirmations to transactions locked via InstantSend.\n"
"3. include_watchonly (bool, optional, default=false) Include balances in watch-only addresses (see 'importaddress')\n"
"\nResult:\n"
"{ (json object where keys are account names, and values are numeric balances\n"
" \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n"
" ...\n"
"}\n"
"\nExamples:\n"
"\nList account balances where there at least 1 confirmation\n"
+ HelpExampleCli("listaccounts", "") +
"\nList account balances including zero confirmation transactions\n"
+ HelpExampleCli("listaccounts", "0") +
"\nList account balances for 6 or more confirmations\n"
+ HelpExampleCli("listaccounts", "6") +
"\nAs json rpc call\n"
+ HelpExampleRpc("listaccounts", "6")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
int nMinDepth = 1;
if (request.params.size() > 0)
nMinDepth = request.params[0].get_int();
bool fAddLockConf = (request.params.size() > 1 && request.params[1].get_bool());
isminefilter includeWatchonly = ISMINE_SPENDABLE;
if(request.params.size() > 2)
if(request.params[2].get_bool())
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
std::map<std::string, CAmount> mapAccountBalances;
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me
mapAccountBalances[entry.second.name] = 0;
}
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
CAmount nFee;
std::string strSentAccount;
std::list<COutputEntry> listReceived;
std::list<COutputEntry> listSent;
int nDepth = wtx.GetDepthInMainChain(fAddLockConf);
if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
continue;
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
mapAccountBalances[strSentAccount] -= nFee;
BOOST_FOREACH(const COutputEntry& s, listSent)
mapAccountBalances[strSentAccount] -= s.amount;
if (nDepth >= nMinDepth)
{
BOOST_FOREACH(const COutputEntry& r, listReceived)
if (pwalletMain->mapAddressBook.count(r.destination))
mapAccountBalances[pwalletMain->mapAddressBook[r.destination].name] += r.amount;
else
mapAccountBalances[""] += r.amount;
}
}
const std::list<CAccountingEntry> & acentries = pwalletMain->laccentries;
BOOST_FOREACH(const CAccountingEntry& entry, acentries)
mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
UniValue ret(UniValue::VOBJ);
BOOST_FOREACH(const PAIRTYPE(std::string, CAmount)& accountBalance, mapAccountBalances) {
ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
}
return ret;
}
UniValue listsinceblock(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp)
throw std::runtime_error(
"listsinceblock ( \"blockhash\" target_confirmations include_watchonly)\n"
"\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n"
"\nArguments:\n"
"1. \"blockhash\" (string, optional) The block hash to list transactions since\n"
"2. target_confirmations: (numeric, optional) The confirmations required, must be 1 or more\n"
"3. include_watchonly: (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')"
"\nResult:\n"
"{\n"
" \"transactions\": [\n"
" \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. Will be \"\" for the default account.\n"
" \"address\":\"address\", (string) The godlikeproducts address of the transaction. Not present for move transactions (category = move).\n"
" \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n"
" \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the 'move' category for moves \n"
" outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n"
" \"vout\" : n, (numeric) the vout value\n"
" \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the 'send' category of transactions.\n"
" \"instantlock\" : true|false, (bool) Current transaction lock state. Available for 'send' and 'receive' category of transactions.\n"
" \"confirmations\" : n, (numeric) The number of blockchain confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n"
" When it's < 0, it means the transaction conflicted that many blocks ago.\n"
" \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
" \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive' category of transactions.\n"
" \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
" \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
" \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n"
" \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n"
" \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
" may be unknown for unconfirmed transactions not in the mempool\n"
" \"abandoned\": xxx, (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the 'send' category of transactions.\n"
" \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
" \"label\" : \"label\" (string) A comment for the address/transaction, if any\n"
" \"to\": \"...\", (string) If a comment to is associated with the transaction.\n"
" ],\n"
" \"lastblock\": \"lastblockhash\" (string) The hash of the last block\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("listsinceblock", "")
+ HelpExampleCli("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\" 6")
+ HelpExampleRpc("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\", 6")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
const CBlockIndex *pindex = NULL;
int target_confirms = 1;
isminefilter filter = ISMINE_SPENDABLE;
if (request.params.size() > 0)
{
uint256 blockId;
blockId.SetHex(request.params[0].get_str());
BlockMap::iterator it = mapBlockIndex.find(blockId);
if (it != mapBlockIndex.end())
{
pindex = it->second;
if (chainActive[pindex->nHeight] != pindex)
{
// the block being asked for is a part of a deactivated chain;
// we don't want to depend on its perceived height in the block
// chain, we want to instead use the last common ancestor
pindex = chainActive.FindFork(pindex);
}
}
else
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid blockhash");
}
if (request.params.size() > 1)
{
target_confirms = request.params[1].get_int();
if (target_confirms < 1)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
}
if (request.params.size() > 2 && request.params[2].get_bool())
{
filter = filter | ISMINE_WATCH_ONLY;
}
int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1;
UniValue transactions(UniValue::VARR);
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++)
{
CWalletTx tx = (*it).second;
if (depth == -1 || tx.GetDepthInMainChain(false) < depth)
ListTransactions(tx, "*", 0, true, transactions, filter);
}
CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : uint256();
UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("transactions", transactions));
ret.push_back(Pair("lastblock", lastblock.GetHex()));
return ret;
}
UniValue gettransaction(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error(
"gettransaction \"txid\" ( include_watchonly )\n"
"\nGet detailed information about in-wallet transaction <txid>\n"
"\nArguments:\n"
"1. \"txid\" (string, required) The transaction id\n"
"2. \"include_watchonly\" (bool, optional, default=false) Whether to include watch-only addresses in balance calculation and details[]\n"
"\nResult:\n"
"{\n"
" \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + "\n"
" \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
" 'send' category of transactions.\n"
" \"instantlock\" : true|false, (bool) Current transaction lock state\n"
" \"confirmations\" : n, (numeric) The number of blockchain confirmations\n"
" \"blockhash\" : \"hash\", (string) The block hash\n"
" \"blockindex\" : xx, (numeric) The index of the transaction in the block that includes it\n"
" \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n"
" \"txid\" : \"transactionid\", (string) The transaction id.\n"
" \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n"
" \"timereceived\" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT)\n"
" \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
" may be unknown for unconfirmed transactions not in the mempool\n"
" \"details\" : [\n"
" {\n"
" \"account\" : \"accountname\", (string) DEPRECATED. The account name involved in the transaction, can be \"\" for the default account.\n"
" \"address\" : \"address\", (string) The godlikeproducts address involved in the transaction\n"
" \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n"
" \"amount\" : x.xxx, (numeric) The amount in " + CURRENCY_UNIT + "\n"
" \"label\" : \"label\", (string) A comment for the address/transaction, if any\n"
" \"vout\" : n, (numeric) the vout value\n"
" \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
" 'send' category of transactions.\n"
" \"abandoned\": xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n"
" 'send' category of transactions.\n"
" }\n"
" ,...\n"
" ],\n"
" \"hex\" : \"data\" (string) Raw data for transaction\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
+ HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true")
+ HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
uint256 hash;
hash.SetHex(request.params[0].get_str());
isminefilter filter = ISMINE_SPENDABLE;
if(request.params.size() > 1)
if(request.params[1].get_bool())
filter = filter | ISMINE_WATCH_ONLY;
UniValue entry(UniValue::VOBJ);
if (!pwalletMain->mapWallet.count(hash))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
CAmount nCredit = wtx.GetCredit(filter);
CAmount nDebit = wtx.GetDebit(filter);
CAmount nNet = nCredit - nDebit;
CAmount nFee = (wtx.IsFromMe(filter) ? wtx.tx->GetValueOut() - nDebit : 0);
entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
if (wtx.IsFromMe(filter))
entry.push_back(Pair("fee", ValueFromAmount(nFee)));
WalletTxToJSON(wtx, entry);
UniValue details(UniValue::VARR);
ListTransactions(wtx, "*", 0, false, details, filter);
entry.push_back(Pair("details", details));
std::string strHex = EncodeHexTx(static_cast<CTransaction>(wtx));
entry.push_back(Pair("hex", strHex));
return entry;
}
UniValue abandontransaction(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"abandontransaction \"txid\"\n"
"\nMark in-wallet transaction <txid> as abandoned\n"
"This will mark this transaction and all its in-wallet descendants as abandoned which will allow\n"
"for their inputs to be respent. It can be used to replace \"stuck\" or evicted transactions.\n"
"It only works on transactions which are not included in a block and are not currently in the mempool.\n"
"It has no effect on transactions which are already conflicted or abandoned.\n"
"\nArguments:\n"
"1. \"txid\" (string, required) The transaction id\n"
"\nResult:\n"
"\nExamples:\n"
+ HelpExampleCli("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
+ HelpExampleRpc("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
uint256 hash;
hash.SetHex(request.params[0].get_str());
if (!pwalletMain->mapWallet.count(hash))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
if (!pwalletMain->AbandonTransaction(hash))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not eligible for abandonment");
return NullUniValue;
}
UniValue backupwallet(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"backupwallet \"destination\"\n"
"\nSafely copies current wallet file to destination, which can be a directory or a path with filename.\n"
"\nArguments:\n"
"1. \"destination\" (string) The destination directory or file\n"
"\nExamples:\n"
+ HelpExampleCli("backupwallet", "\"backup.dat\"")
+ HelpExampleRpc("backupwallet", "\"backup.dat\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
std::string strDest = request.params[0].get_str();
if (!pwalletMain->BackupWallet(strDest))
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
return NullUniValue;
}
UniValue keypoolrefill(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 1)
throw std::runtime_error(
"keypoolrefill ( newsize )\n"
"\nFills the keypool."
+ HelpRequiringPassphrase() + "\n"
"\nArguments:\n"
"1. newsize (numeric, optional, default=" + itostr(DEFAULT_KEYPOOL_SIZE) + ") The new keypool size\n"
"\nExamples:\n"
+ HelpExampleCli("keypoolrefill", "")
+ HelpExampleRpc("keypoolrefill", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
// 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
unsigned int kpSize = 0;
if (request.params.size() > 0) {
if (request.params[0].get_int() < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size.");
kpSize = (unsigned int)request.params[0].get_int();
}
EnsureWalletIsUnlocked();
pwalletMain->TopUpKeyPool(kpSize);
if (pwalletMain->GetKeyPoolSize() < (pwalletMain->IsHDEnabled() ? kpSize * 2 : kpSize))
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
return NullUniValue;
}
static void LockWallet(CWallet* pWallet)
{
LOCK(cs_nWalletUnlockTime);
nWalletUnlockTime = 0;
pWallet->Lock();
}
UniValue walletpassphrase(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (pwalletMain->IsCrypted() && (request.fHelp || request.params.size() < 2 || request.params.size() > 3))
throw std::runtime_error(
"walletpassphrase \"passphrase\" timeout ( mixingonly )\n"
"\nStores the wallet decryption key in memory for 'timeout' seconds.\n"
"This is needed prior to performing transactions related to private keys such as sending godlikeproductss\n"
"\nArguments:\n"
"1. \"passphrase\" (string, required) The wallet passphrase\n"
"2. timeout (numeric, required) The time to keep the decryption key in seconds.\n"
"3. mixingonly (boolean, optional, default=false) If is true sending functions are disabled.\n"
"\nNote:\n"
"Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n"
"time that overrides the old one.\n"
"\nExamples:\n"
"\nUnlock the wallet for 60 seconds\n"
+ HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") +
"\nUnlock the wallet for 60 seconds but allow PrivateSend mixing only\n"
+ HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60 true") +
"\nLock the wallet again (before 60 seconds)\n"
+ HelpExampleCli("walletlock", "") +
"\nAs json rpc call\n"
+ HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
if (request.fHelp)
return true;
if (!pwalletMain->IsCrypted())
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called.");
// Note that the walletpassphrase is stored in request.params[0] which is not mlock()ed
SecureString strWalletPass;
strWalletPass.reserve(100);
// TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
strWalletPass = request.params[0].get_str().c_str();
int64_t nSleepTime = request.params[1].get_int64();
bool fForMixingOnly = false;
if (request.params.size() >= 3)
fForMixingOnly = request.params[2].get_bool();
if (fForMixingOnly && !pwalletMain->IsLocked(true) && pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already unlocked for mixing only.");
if (!pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already fully unlocked.");
if (!pwalletMain->Unlock(strWalletPass, fForMixingOnly))
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
pwalletMain->TopUpKeyPool();
LOCK(cs_nWalletUnlockTime);
nWalletUnlockTime = GetTime() + nSleepTime;
RPCRunLater("lockwallet", boost::bind(LockWallet, pwalletMain), nSleepTime);
return NullUniValue;
}
UniValue walletpassphrasechange(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 2))
throw std::runtime_error(
"walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n"
"\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n"
"\nArguments:\n"
"1. \"oldpassphrase\" (string) The current passphrase\n"
"2. \"newpassphrase\" (string) The new passphrase\n"
"\nExamples:\n"
+ HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"")
+ HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
if (request.fHelp)
return true;
if (!pwalletMain->IsCrypted())
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
// TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
SecureString strOldWalletPass;
strOldWalletPass.reserve(100);
strOldWalletPass = request.params[0].get_str().c_str();
SecureString strNewWalletPass;
strNewWalletPass.reserve(100);
strNewWalletPass = request.params[1].get_str().c_str();
if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1)
throw std::runtime_error(
"walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
"Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass))
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
return NullUniValue;
}
UniValue walletlock(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 0))
throw std::runtime_error(
"walletlock\n"
"\nRemoves the wallet encryption key from memory, locking the wallet.\n"
"After calling this method, you will need to call walletpassphrase again\n"
"before being able to call any methods which require the wallet to be unlocked.\n"
"\nExamples:\n"
"\nSet the passphrase for 2 minutes to perform a transaction\n"
+ HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") +
"\nPerform a send (requires passphrase set)\n"
+ HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 1.0") +
"\nClear the passphrase since we are done before 2 minutes is up\n"
+ HelpExampleCli("walletlock", "") +
"\nAs json rpc call\n"
+ HelpExampleRpc("walletlock", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
if (request.fHelp)
return true;
if (!pwalletMain->IsCrypted())
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
{
LOCK(cs_nWalletUnlockTime);
pwalletMain->Lock();
nWalletUnlockTime = 0;
}
return NullUniValue;
}
UniValue encryptwallet(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (!pwalletMain->IsCrypted() && (request.fHelp || request.params.size() != 1))
throw std::runtime_error(
"encryptwallet \"passphrase\"\n"
"\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n"
"After this, any calls that interact with private keys such as sending or signing \n"
"will require the passphrase to be set prior the making these calls.\n"
"Use the walletpassphrase call for this, and then walletlock call.\n"
"If the wallet is already encrypted, use the walletpassphrasechange call.\n"
"Note that this will shutdown the server.\n"
"\nArguments:\n"
"1. \"passphrase\" (string) The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long.\n"
"\nExamples:\n"
"\nEncrypt you wallet\n"
+ HelpExampleCli("encryptwallet", "\"my pass phrase\"") +
"\nNow set the passphrase to use the wallet, such as for signing or sending godlikeproducts\n"
+ HelpExampleCli("walletpassphrase", "\"my pass phrase\"") +
"\nNow we can so something like sign\n"
+ HelpExampleCli("signmessage", "\"address\" \"test message\"") +
"\nNow lock the wallet again by removing the passphrase\n"
+ HelpExampleCli("walletlock", "") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("encryptwallet", "\"my pass phrase\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
if (request.fHelp)
return true;
if (pwalletMain->IsCrypted())
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");
// TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string)
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
SecureString strWalletPass;
strWalletPass.reserve(100);
strWalletPass = request.params[0].get_str().c_str();
if (strWalletPass.length() < 1)
throw std::runtime_error(
"encryptwallet <passphrase>\n"
"Encrypts the wallet with <passphrase>.");
if (!pwalletMain->EncryptWallet(strWalletPass))
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");
// BDB seems to have a bad habit of writing old data into
// slack space in .dat files; that is bad if the old data is
// unencrypted private keys. So:
StartShutdown();
return "Wallet encrypted; GodLikeProducts Core server stopping, restart to run with encrypted wallet. The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup.";
}
UniValue lockunspent(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error(
"lockunspent unlock ([{\"txid\":\"txid\",\"vout\":n},...])\n"
"\nUpdates list of temporarily unspendable outputs.\n"
"Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
"If no transaction outputs are specified when unlocking then all current locked transaction outputs are unlocked.\n"
"A locked transaction output will not be chosen by automatic coin selection, when spending godlikeproductss.\n"
"Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list\n"
"is always cleared (by virtue of process exit) when a node stops or fails.\n"
"Also see the listunspent call\n"
"\nArguments:\n"
"1. unlock (boolean, required) Whether to unlock (true) or lock (false) the specified transactions\n"
"2. \"transactions\" (string, optional) A json array of objects. Each object the txid (string) vout (numeric)\n"
" [ (json array of json objects)\n"
" {\n"
" \"txid\":\"id\", (string) The transaction id\n"
" \"vout\": n (numeric) The output number\n"
" }\n"
" ,...\n"
" ]\n"
"\nResult:\n"
"true|false (boolean) Whether the command was successful or not\n"
"\nExamples:\n"
"\nList the unspent transactions\n"
+ HelpExampleCli("listunspent", "") +
"\nLock an unspent transaction\n"
+ HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
"\nList the locked transactions\n"
+ HelpExampleCli("listlockunspent", "") +
"\nUnlock the transaction again\n"
+ HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("lockunspent", "false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
if (request.params.size() == 1)
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VBOOL));
else
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VBOOL)(UniValue::VARR));
bool fUnlock = request.params[0].get_bool();
if (request.params.size() == 1) {
if (fUnlock)
pwalletMain->UnlockAllCoins();
return true;
}
UniValue outputs = request.params[1].get_array();
for (unsigned int idx = 0; idx < outputs.size(); idx++) {
const UniValue& output = outputs[idx];
if (!output.isObject())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected object");
const UniValue& o = output.get_obj();
RPCTypeCheckObj(o,
{
{"txid", UniValueType(UniValue::VSTR)},
{"vout", UniValueType(UniValue::VNUM)},
});
std::string txid = find_value(o, "txid").get_str();
if (!IsHex(txid))
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid");
int nOutput = find_value(o, "vout").get_int();
if (nOutput < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
COutPoint outpt(uint256S(txid), nOutput);
if (fUnlock)
pwalletMain->UnlockCoin(outpt);
else
pwalletMain->LockCoin(outpt);
}
return true;
}
UniValue listlockunspent(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 0)
throw std::runtime_error(
"listlockunspent\n"
"\nReturns list of temporarily unspendable outputs.\n"
"See the lockunspent call to lock and unlock transactions for spending.\n"
"\nResult:\n"
"[\n"
" {\n"
" \"txid\" : \"transactionid\", (string) The transaction id locked\n"
" \"vout\" : n (numeric) The vout value\n"
" }\n"
" ,...\n"
"]\n"
"\nExamples:\n"
"\nList the unspent transactions\n"
+ HelpExampleCli("listunspent", "") +
"\nLock an unspent transaction\n"
+ HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
"\nList the locked transactions\n"
+ HelpExampleCli("listlockunspent", "") +
"\nUnlock the transaction again\n"
+ HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") +
"\nAs a json rpc call\n"
+ HelpExampleRpc("listlockunspent", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
std::vector<COutPoint> vOutpts;
pwalletMain->ListLockedCoins(vOutpts);
UniValue ret(UniValue::VARR);
BOOST_FOREACH(COutPoint &outpt, vOutpts) {
UniValue o(UniValue::VOBJ);
o.push_back(Pair("txid", outpt.hash.GetHex()));
o.push_back(Pair("vout", (int)outpt.n));
ret.push_back(o);
}
return ret;
}
UniValue settxfee(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 1 || request.params.size() > 1)
throw std::runtime_error(
"settxfee amount\n"
"\nSet the transaction fee per kB. Overwrites the paytxfee parameter.\n"
"\nArguments:\n"
"1. amount (numeric or string, required) The transaction fee in " + CURRENCY_UNIT + "/kB\n"
"\nResult:\n"
"true|false (boolean) Returns true if successful\n"
"\nExamples:\n"
+ HelpExampleCli("settxfee", "0.00001")
+ HelpExampleRpc("settxfee", "0.00001")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
// Amount
CAmount nAmount = AmountFromValue(request.params[0]);
payTxFee = CFeeRate(nAmount, 1000);
return true;
}
UniValue getwalletinfo(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
"getwalletinfo\n"
"Returns an object containing various wallet state info.\n"
"\nResult:\n"
"{\n"
" \"walletversion\": xxxxx, (numeric) the wallet version\n"
" \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
+ (!fLiteMode ?
" \"privatesend_balance\": xxxxxx, (numeric) the anonymized godlikeproducts balance of the wallet in " + CURRENCY_UNIT + "\n" : "") +
" \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
" \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + "\n"
" \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
" \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool\n"
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated (only counts external keys)\n"
" \"keypoolsize_hd_internal\": xxxx, (numeric) how many new keys are pre-generated for internal use (used for change outputs, only appears if the wallet is using this feature, otherwise external keys are used)\n"
" \"keys_left\": xxxx, (numeric) how many new keys are left since last automatic backup\n"
" \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
" \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
" \"hdchainid\": \"<hash>\", (string) the ID of the HD chain\n"
" \"hdaccountcount\": xxx, (numeric) how many accounts of the HD chain are in this wallet\n"
" [\n"
" {\n"
" \"hdaccountindex\": xxx, (numeric) the index of the account\n"
" \"hdexternalkeyindex\": xxxx, (numeric) current external childkey index\n"
" \"hdinternalkeyindex\": xxxx, (numeric) current internal childkey index\n"
" }\n"
" ,...\n"
" ]\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getwalletinfo", "")
+ HelpExampleRpc("getwalletinfo", "")
);
LOCK2(cs_main, pwalletMain->cs_wallet);
CHDChain hdChainCurrent;
bool fHDEnabled = pwalletMain->GetHDChain(hdChainCurrent);
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
if(!fLiteMode)
obj.push_back(Pair("privatesend_balance", ValueFromAmount(pwalletMain->GetAnonymizedBalance())));
obj.push_back(Pair("unconfirmed_balance", ValueFromAmount(pwalletMain->GetUnconfirmedBalance())));
obj.push_back(Pair("immature_balance", ValueFromAmount(pwalletMain->GetImmatureBalance())));
obj.push_back(Pair("txcount", (int)pwalletMain->mapWallet.size()));
obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime()));
obj.push_back(Pair("keypoolsize", (int64_t)pwalletMain->KeypoolCountExternalKeys()));
if (fHDEnabled) {
obj.push_back(Pair("keypoolsize_hd_internal", (int64_t)(pwalletMain->KeypoolCountInternalKeys())));
}
obj.push_back(Pair("keys_left", pwalletMain->nKeysLeftSinceAutoBackup));
if (pwalletMain->IsCrypted())
obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
if (fHDEnabled) {
obj.push_back(Pair("hdchainid", hdChainCurrent.GetID().GetHex()));
obj.push_back(Pair("hdaccountcount", (int64_t)hdChainCurrent.CountAccounts()));
UniValue accounts(UniValue::VARR);
for (size_t i = 0; i < hdChainCurrent.CountAccounts(); ++i)
{
CHDAccount acc;
UniValue account(UniValue::VOBJ);
account.push_back(Pair("hdaccountindex", (int64_t)i));
if(hdChainCurrent.GetAccount(i, acc)) {
account.push_back(Pair("hdexternalkeyindex", (int64_t)acc.nExternalChainCounter));
account.push_back(Pair("hdinternalkeyindex", (int64_t)acc.nInternalChainCounter));
} else {
account.push_back(Pair("error", strprintf("account %d is missing", i)));
}
accounts.push_back(account);
}
obj.push_back(Pair("hdaccounts", accounts));
}
return obj;
}
UniValue keepass(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
std::string strCommand;
if (request.params.size() >= 1)
strCommand = request.params[0].get_str();
if (request.fHelp ||
(strCommand != "genkey" && strCommand != "init" && strCommand != "setpassphrase"))
throw std::runtime_error(
"keepass <genkey|init|setpassphrase>\n");
if (strCommand == "genkey")
{
SecureString sResult;
// Generate RSA key
SecureString sKey = CKeePassIntegrator::generateKeePassKey();
sResult = "Generated Key: ";
sResult += sKey;
return sResult.c_str();
}
else if(strCommand == "init")
{
// Generate base64 encoded 256 bit RSA key and associate with KeePassHttp
SecureString sResult;
SecureString sKey;
std::string strId;
keePassInt.rpcAssociate(strId, sKey);
sResult = "Association successful. Id: ";
sResult += strId.c_str();
sResult += " - Key: ";
sResult += sKey.c_str();
return sResult.c_str();
}
else if(strCommand == "setpassphrase")
{
if(request.params.size() != 2) {
return "setlogin: invalid number of parameters. Requires a passphrase";
}
SecureString sPassphrase = SecureString(request.params[1].get_str().c_str());
keePassInt.updatePassphrase(sPassphrase);
return "setlogin: Updated credentials.";
}
return "Invalid command";
}
UniValue resendwallettransactions(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
"resendwallettransactions\n"
"Immediately re-broadcast unconfirmed wallet transactions to all peers.\n"
"Intended only for testing; the wallet code periodically re-broadcasts\n"
"automatically.\n"
"Returns array of transaction ids that were re-broadcast.\n"
);
if (!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
LOCK2(cs_main, pwalletMain->cs_wallet);
std::vector<uint256> txids = pwalletMain->ResendWalletTransactionsBefore(GetTime(), g_connman.get());
UniValue result(UniValue::VARR);
BOOST_FOREACH(const uint256& txid, txids)
{
result.push_back(txid.ToString());
}
return result;
}
UniValue listunspent(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() > 4)
throw std::runtime_error(
"listunspent ( minconf maxconf [\"addresses\",...] [include_unsafe] )\n"
"\nReturns array of unspent transaction outputs\n"
"with between minconf and maxconf (inclusive) confirmations.\n"
"Optionally filter to only include txouts paid to specified addresses.\n"
"\nArguments:\n"
"1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n"
"2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n"
"3. \"addresses\" (string) A json array of godlikeproducts addresses to filter\n"
" [\n"
" \"address\" (string) godlikeproducts address\n"
" ,...\n"
" ]\n"
"4. include_unsafe (bool, optional, default=true) Include outputs that are not safe to spend\n"
" because they come from unconfirmed untrusted transactions or unconfirmed\n"
" replacement transactions (cases where we are less sure that a conflicting\n"
" transaction won't be mined).\n"
"\nResult:\n"
"[ (array of json object)\n"
" {\n"
" \"txid\" : \"txid\", (string) the transaction id \n"
" \"vout\" : n, (numeric) the vout value\n"
" \"address\" : \"address\", (string) the godlikeproducts address\n"
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
" \"scriptPubKey\" : \"key\", (string) the script key\n"
" \"amount\" : x.xxx, (numeric) the transaction output amount in " + CURRENCY_UNIT + "\n"
" \"confirmations\" : n, (numeric) The number of confirmations\n"
" \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n"
" \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n"
" \"solvable\" : xxx, (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
" \"ps_rounds\" : n (numeric) The number of PS rounds\n"
" }\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("listunspent", "")
+ HelpExampleCli("listunspent", "6 9999999 \"[\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\\\",\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcg\\\"]\"")
+ HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\\\",\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcg\\\"]\"")
);
int nMinDepth = 1;
if (request.params.size() > 0 && !request.params[0].isNull()) {
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
nMinDepth = request.params[0].get_int();
}
int nMaxDepth = 9999999;
if (request.params.size() > 1 && !request.params[1].isNull()) {
RPCTypeCheckArgument(request.params[1], UniValue::VNUM);
nMaxDepth = request.params[1].get_int();
}
std::set<CBitcoinAddress> setAddress;
if (request.params.size() > 2 && !request.params[2].isNull()) {
RPCTypeCheckArgument(request.params[2], UniValue::VARR);
UniValue inputs = request.params[2].get_array();
for (unsigned int idx = 0; idx < inputs.size(); idx++) {
const UniValue& input = inputs[idx];
CBitcoinAddress address(input.get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid GodLikeProducts address: ")+input.get_str());
if (setAddress.count(address))
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ")+input.get_str());
setAddress.insert(address);
}
}
bool include_unsafe = true;
if (request.params.size() > 3 && !request.params[3].isNull()) {
RPCTypeCheckArgument(request.params[3], UniValue::VBOOL);
include_unsafe = request.params[3].get_bool();
}
UniValue results(UniValue::VARR);
std::vector<COutput> vecOutputs;
assert(pwalletMain != NULL);
LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->AvailableCoins(vecOutputs, !include_unsafe, NULL, true);
BOOST_FOREACH(const COutput& out, vecOutputs) {
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
continue;
CTxDestination address;
const CScript& scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey;
bool fValidAddress = ExtractDestination(scriptPubKey, address);
if (setAddress.size() && (!fValidAddress || !setAddress.count(address)))
continue;
UniValue entry(UniValue::VOBJ);
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
entry.push_back(Pair("vout", out.i));
if (fValidAddress) {
entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
if (pwalletMain->mapAddressBook.count(address))
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
if (scriptPubKey.IsPayToScriptHash()) {
const CScriptID& hash = boost::get<CScriptID>(address);
CScript redeemScript;
if (pwalletMain->GetCScript(hash, redeemScript))
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
}
}
entry.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
entry.push_back(Pair("amount", ValueFromAmount(out.tx->tx->vout[out.i].nValue)));
entry.push_back(Pair("confirmations", out.nDepth));
entry.push_back(Pair("spendable", out.fSpendable));
entry.push_back(Pair("solvable", out.fSolvable));
entry.push_back(Pair("ps_rounds", pwalletMain->GetOutpointPrivateSendRounds(COutPoint(out.tx->GetHash(), out.i))));
results.push_back(entry);
}
return results;
}
UniValue fundrawtransaction(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error(
"fundrawtransaction \"hexstring\" ( options )\n"
"\nAdd inputs to a transaction until it has enough in value to meet its out value.\n"
"This will not modify existing inputs, and will add at most one change output to the outputs.\n"
"No existing outputs will be modified unless \"subtractFeeFromOutputs\" is specified.\n"
"Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.\n"
"The inputs added will not be signed, use signrawtransaction for that.\n"
"Note that all existing inputs must have their previous output transaction be in the wallet.\n"
"Note that all inputs selected must be of standard form and P2SH scripts must be\n"
"in the wallet using importaddress or addmultisigaddress (to calculate fees).\n"
"You can see whether this is the case by checking the \"solvable\" field in the listunspent output.\n"
"Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only\n"
"\nArguments:\n"
"1. \"hexstring\" (string, required) The hex string of the raw transaction\n"
"2. options (object, optional)\n"
" {\n"
" \"changeAddress\" (string, optional, default pool address) The godlikeproducts address to receive the change\n"
" \"changePosition\" (numeric, optional, default random) The index of the change output\n"
" \"includeWatching\" (boolean, optional, default false) Also select inputs which are watch only\n"
" \"lockUnspents\" (boolean, optional, default false) Lock selected unspent outputs\n"
" \"reserveChangeKey\" (boolean, optional, default true) Reserves the change output key from the keypool\n"
" \"feeRate\" (numeric, optional, default not set: makes wallet determine the fee) Set a specific feerate (" + CURRENCY_UNIT + " per KB)\n"
" \"subtractFeeFromOutputs\" (array, optional) A json array of integers.\n"
" The fee will be equally deducted from the amount of each specified output.\n"
" The outputs are specified by their zero-based index, before any change output is added.\n"
" Those recipients will receive less godlikeproducts than you enter in their corresponding amount field.\n"
" If no outputs are specified here, the sender pays the fee.\n"
" [vout_index,...]\n"
" }\n"
" for backward compatibility: passing in a true instead of an object will result in {\"includeWatching\":true}\n"
"\nResult:\n"
"{\n"
" \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n"
" \"fee\": n, (numeric) Fee in " + CURRENCY_UNIT + " the resulting transaction pays\n"
" \"changepos\": n (numeric) The position of the added change output, or -1\n"
"}\n"
"\nExamples:\n"
"\nCreate a transaction with no inputs\n"
+ HelpExampleCli("createrawtransaction", "\"[]\" \"{\\\"myaddress\\\":0.01}\"") +
"\nAdd sufficient unsigned inputs to meet the output value\n"
+ HelpExampleCli("fundrawtransaction", "\"rawtransactionhex\"") +
"\nSign the transaction\n"
+ HelpExampleCli("signrawtransaction", "\"fundedtransactionhex\"") +
"\nSend the transaction\n"
+ HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"")
);
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR));
CTxDestination changeAddress = CNoDestination();
int changePosition = -1;
bool includeWatching = false;
bool lockUnspents = false;
bool reserveChangeKey = true;
CFeeRate feeRate = CFeeRate(0);
bool overrideEstimatedFeerate = false;
UniValue subtractFeeFromOutputs;
std::set<int> setSubtractFeeFromOutputs;
if (request.params.size() > 1) {
if (request.params[1].type() == UniValue::VBOOL) {
// backward compatibility bool only fallback
includeWatching = request.params[1].get_bool();
}
else {
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR)(UniValue::VOBJ));
UniValue options = request.params[1];
RPCTypeCheckObj(options,
{
{"changeAddress", UniValueType(UniValue::VSTR)},
{"changePosition", UniValueType(UniValue::VNUM)},
{"includeWatching", UniValueType(UniValue::VBOOL)},
{"lockUnspents", UniValueType(UniValue::VBOOL)},
{"reserveChangeKey", UniValueType(UniValue::VBOOL)},
{"feeRate", UniValueType()}, // will be checked below
{"subtractFeeFromOutputs", UniValueType(UniValue::VARR)},
},
true, true);
if (options.exists("changeAddress")) {
CBitcoinAddress address(options["changeAddress"].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_PARAMETER, "changeAddress must be a valid godlikeproducts address");
changeAddress = address.Get();
}
if (options.exists("changePosition"))
changePosition = options["changePosition"].get_int();
if (options.exists("includeWatching"))
includeWatching = options["includeWatching"].get_bool();
if (options.exists("lockUnspents"))
lockUnspents = options["lockUnspents"].get_bool();
if (options.exists("reserveChangeKey"))
reserveChangeKey = options["reserveChangeKey"].get_bool();
if (options.exists("feeRate"))
{
feeRate = CFeeRate(AmountFromValue(options["feeRate"]));
overrideEstimatedFeerate = true;
}
if (options.exists("subtractFeeFromOutputs"))
subtractFeeFromOutputs = options["subtractFeeFromOutputs"].get_array();
}
}
// parse hex string from parameter
CMutableTransaction tx;
if (!DecodeHexTx(tx, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
if (tx.vout.size() == 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "TX must have at least one output");
if (changePosition != -1 && (changePosition < 0 || (unsigned int)changePosition > tx.vout.size()))
throw JSONRPCError(RPC_INVALID_PARAMETER, "changePosition out of bounds");
for (unsigned int idx = 0; idx < subtractFeeFromOutputs.size(); idx++) {
int pos = subtractFeeFromOutputs[idx].get_int();
if (setSubtractFeeFromOutputs.count(pos))
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, duplicated position: %d", pos));
if (pos < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, negative position: %d", pos));
if (pos >= int(tx.vout.size()))
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, position too large: %d", pos));
setSubtractFeeFromOutputs.insert(pos);
}
CAmount nFeeOut;
std::string strFailReason;
if(!pwalletMain->FundTransaction(tx, nFeeOut, overrideEstimatedFeerate, feeRate, changePosition, strFailReason, includeWatching, lockUnspents, setSubtractFeeFromOutputs, reserveChangeKey, changeAddress))
throw JSONRPCError(RPC_INTERNAL_ERROR, strFailReason);
UniValue result(UniValue::VOBJ);
result.push_back(Pair("hex", EncodeHexTx(tx)));
result.push_back(Pair("changepos", changePosition));
result.push_back(Pair("fee", ValueFromAmount(nFeeOut)));
return result;
}
UniValue setbip69enabled(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"setbip69enabled enable\n"
"\nEnable/Disable BIP69 input/output sorting (-regtest only)\n"
"\nArguments:\n"
"1. enable (bool, required) true or false"
);
if (Params().NetworkIDString() != CBaseChainParams::REGTEST)
throw std::runtime_error("setbip69enabled for regression testing (-regtest mode) only");
bBIP69Enabled = request.params[0].get_bool();
return NullUniValue;
}
extern UniValue dumpprivkey(const JSONRPCRequest& request); // in rpcdump.cpp
extern UniValue importprivkey(const JSONRPCRequest& request);
extern UniValue importaddress(const JSONRPCRequest& request);
extern UniValue importpubkey(const JSONRPCRequest& request);
extern UniValue dumpwallet(const JSONRPCRequest& request);
extern UniValue importwallet(const JSONRPCRequest& request);
extern UniValue importprunedfunds(const JSONRPCRequest& request);
extern UniValue removeprunedfunds(const JSONRPCRequest& request);
extern UniValue importmulti(const JSONRPCRequest& request);
extern UniValue dumphdinfo(const JSONRPCRequest& request);
extern UniValue importelectrumwallet(const JSONRPCRequest& request);
static const CRPCCommand commands[] =
{ // category name actor (function) okSafeMode
// --------------------- ------------------------ ----------------------- ----------
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, false, {"hexstring","options"} },
{ "hidden", "resendwallettransactions", &resendwallettransactions, true, {} },
{ "wallet", "abandontransaction", &abandontransaction, false, {"txid"} },
{ "wallet", "addmultisigaddress", &addmultisigaddress, true, {"nrequired","keys","account"} },
{ "wallet", "backupwallet", &backupwallet, true, {"destination"} },
{ "wallet", "dumpprivkey", &dumpprivkey, true, {"address"} },
{ "wallet", "dumpwallet", &dumpwallet, true, {"filename"} },
{ "wallet", "encryptwallet", &encryptwallet, true, {"passphrase"} },
{ "wallet", "getaccountaddress", &getaccountaddress, true, {"account"} },
{ "wallet", "getaccount", &getaccount, true, {"address"} },
{ "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true, {"account"} },
{ "wallet", "getbalance", &getbalance, false, {"account","minconf","addlockconf","include_watchonly"} },
{ "wallet", "getnewaddress", &getnewaddress, true, {"account"} },
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, true, {} },
{ "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false, {"account","minconf","addlockconf"} },
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false, {"address","minconf","addlockconf"} },
{ "wallet", "gettransaction", &gettransaction, false, {"txid","include_watchonly"} },
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false, {} },
{ "wallet", "getwalletinfo", &getwalletinfo, false, {} },
{ "wallet", "importmulti", &importmulti, true, {"requests","options"} },
{ "wallet", "importprivkey", &importprivkey, true, {"privkey","label","rescan"} },
{ "wallet", "importwallet", &importwallet, true, {"filename"} },
{ "wallet", "importaddress", &importaddress, true, {"address","label","rescan","p2sh"} },
{ "wallet", "importprunedfunds", &importprunedfunds, true, {"rawtransaction","txoutproof"} },
{ "wallet", "importpubkey", &importpubkey, true, {"pubkey","label","rescan"} },
{ "wallet", "keypoolrefill", &keypoolrefill, true, {"newsize"} },
{ "wallet", "listaccounts", &listaccounts, false, {"minconf","addlockconf","include_watchonly"} },
{ "wallet", "listaddressgroupings", &listaddressgroupings, false, {} },
{ "wallet", "listaddressbalances", &listaddressbalances, false, {"minamount"} },
{ "wallet", "listlockunspent", &listlockunspent, false, {} },
{ "wallet", "listreceivedbyaccount", &listreceivedbyaccount, false, {"minconf","addlockconf","include_empty","include_watchonly"} },
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, false, {"minconf","addlockconf","include_empty","include_watchonly"} },
{ "wallet", "listsinceblock", &listsinceblock, false, {"blockhash","target_confirmations","include_watchonly"} },
{ "wallet", "listtransactions", &listtransactions, false, {"account","count","skip","include_watchonly"} },
{ "wallet", "listunspent", &listunspent, false, {"minconf","maxconf","addresses","include_unsafe"} },
{ "wallet", "lockunspent", &lockunspent, true, {"unlock","transactions"} },
{ "wallet", "move", &movecmd, false, {"fromaccount","toaccount","amount","minconf","comment"} },
{ "wallet", "sendfrom", &sendfrom, false, {"fromaccount","toaddress","amount","minconf","addlockconf","comment","comment_to"} },
{ "wallet", "sendmany", &sendmany, false, {"fromaccount","amounts","minconf","addlockconf","comment","subtractfeefrom"} },
{ "wallet", "sendtoaddress", &sendtoaddress, false, {"address","amount","comment","comment_to","subtractfeefromamount"} },
{ "wallet", "setaccount", &setaccount, true, {"address","account"} },
{ "wallet", "settxfee", &settxfee, true, {"amount"} },
{ "wallet", "signmessage", &signmessage, true, {"address","message"} },
{ "wallet", "walletlock", &walletlock, true, {} },
{ "wallet", "walletpassphrasechange", &walletpassphrasechange, true, {"oldpassphrase","newpassphrase"} },
{ "wallet", "walletpassphrase", &walletpassphrase, true, {"passphrase","timeout","mixingonly"} },
{ "wallet", "removeprunedfunds", &removeprunedfunds, true, {"txid"} },
{ "wallet", "keepass", &keepass, true, {} },
{ "wallet", "instantsendtoaddress", &instantsendtoaddress, false, {"address","amount","comment","comment_to","subtractfeefromamount"} },
{ "wallet", "dumphdinfo", &dumphdinfo, true, {} },
{ "wallet", "importelectrumwallet", &importelectrumwallet, true, {"filename", "index"} },
{ "hidden", "setbip69enabled", &setbip69enabled, true, {} },
};
void RegisterWalletRPCCommands(CRPCTable &t)
{
if (GetBoolArg("-disablewallet", false))
return;
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
}
| [
"damalisullivan@yahoo.com"
] | damalisullivan@yahoo.com |
c8700e3acd21217ad57bfc7b0bc74c156b15d2eb | 7f4cc9d717fe4bbcb4616b331e0ec3766a76d395 | /eventlogger.cpp | 89336a82b91dd43db8bcbef4c9bef5f0fcc34bb1 | [] | no_license | zzy7896321/FishTank | dacd1c3769407a41a05fbff0aab2c16581ab11ba | 5186f0e21fad2fd68c4791394fcdb492e5f6872a | refs/heads/master | 2016-09-06T16:06:51.823867 | 2014-05-23T12:50:05 | 2014-05-23T12:50:05 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,700 | cpp | #include "eventlogger.h"
#include "host.h"
const char* pstrResultString[7] = {"Success.", //0
"Failure: invalid target coordinate.", //1
"Failure: target is already occupied.", //2
"Failure: target is out of range.", //3
"Failure: target is empty.", //4
"Failure: operation is allowed once each round." , //5
"Failure: it's not good to commit suicide." //6
};
EventLogger::EventLogger(const std::string& strId):strIdentifier(strId), host(RetrieveHost()){}
EventLoggerHub::EventLoggerHub():elList(){}
void EventLoggerHub::AddLogger(EventLogger* elLogger){
elList.push_back(elLogger);
}
unsigned EventLoggerHub::GetSize() const{
return elList.size();
}
const std::string EventLoggerHub::GetIdentifier(unsigned iIndex) const{
return (iIndex>=0 && iIndex<elList.size()) ? elList[iIndex]->strIdentifier : "INVALID_INDEX";
}
void EventLoggerHub::DeleteLogger(unsigned iIndex){
if (iIndex>=0 && iIndex<elList.size()){
EventLogger* elToDelete = elList[iIndex];
elList.erase(elList.begin() + iIndex);
delete elToDelete;
}
}
void EventLoggerHub::HostInitialized(time_t tmTime){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->HostInitialized(tmTime);
}
void EventLoggerHub::AISetup(time_t tmTime, int iCount){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->AISetup(tmTime, iCount);
}
void EventLoggerHub::GameStarted(time_t tmTime){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->GameStarted(tmTime);
}
void EventLoggerHub::GameEnded(time_t tmTime, const int* iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->GameEnded(tmTime, iId);
}
void EventLoggerHub::HostDestroyed(time_t tmTime){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->HostDestroyed(tmTime);
}
void EventLoggerHub::FishBorn(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishBorn(iId);
}
void EventLoggerHub::FoodRefreshed(const int* ipPosX, const int* ipPosY){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FoodRefreshed(ipPosX, ipPosY);
}
void EventLoggerHub::FishInitializing(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishInitializing(iId);
}
void EventLoggerHub::RoundStarted(int iRoundNumber){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->RoundStarted(iRoundNumber);
}
void EventLoggerHub::FishRevived(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishRevived(iId);
}
void EventLoggerHub::SequenceDecided(const int* iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->SequenceDecided(iId);
}
void EventLoggerHub::FishInAction(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishInAction(iId);
}
void EventLoggerHub::FishMove(int iId, int iFormerPosX, int iFormerPosY, int iTargetPosX, int iTargetPosY, int iResult){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishMove(iId, iFormerPosX, iFormerPosY, iTargetPosX, iTargetPosY, iResult);
}
void EventLoggerHub::FishAttack(int iId, int iTargetPosX, int iTargetPosY, int iTarget, int iResult){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishAttack(iId, iTargetPosX, iTargetPosY, iTarget, iResult);
}
void EventLoggerHub::FishDead(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishDead(iId);
}
void EventLoggerHub::FishExpIncreased(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishExpIncreased(iId);
}
void EventLoggerHub::FishLevelUp(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishLevelUp(iId);
}
void EventLoggerHub::FishHPModified(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishHPModified(iId);
}
void EventLoggerHub::FishActionFinished(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishActionFinished(iId);
}
void EventLoggerHub::FishTimeout(int iId, int iTimeUsage){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishTimeout(iId, iTimeUsage);
}
void EventLoggerHub::FishHealthIncreased(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishHealthIncreased(iId);
}
void EventLoggerHub::FishSpeedIncreased(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishSpeedIncreased(iId);
}
void EventLoggerHub::FishStrengthIncreased(int iId){
for (unsigned i=0; i<elList.size(); ++i)
elList[i]->FishStrengthIncreased(iId);
}
| [
"zzy7896321@163.com"
] | zzy7896321@163.com |
a97e4a45eebc97eb2353beb620a85f27b492dac7 | df56c3d9f44132d636c0cef1b70e40034ff09022 | /networksecurity/tlsprovider/source/swtlstokentypeplugin/swtlstokenprovider.cpp | bb22bedeeee43f4d17af4fcce5495f8c1d88c624 | [] | no_license | SymbianSource/oss.FCL.sf.os.networkingsrv | e6317d7ee0ebae163572127269c6cf40b98e3e1c | b283ce17f27f4a95f37cdb38c6ce79d38ae6ebf9 | refs/heads/master | 2021-01-12T11:29:50.765762 | 2010-10-14T06:50:50 | 2010-10-14T06:50:50 | 72,938,071 | 4 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 3,709 | cpp | // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
//
#include "swtlstokentypeplugin.h"
//
// CSwTLSTokenProvider
MCTToken& CSwTLSTokenProvider::Token()
{
return iToken;
}
const TDesC& CSwTLSTokenProvider::Label()
{
return iLabel;
}
void CSwTLSTokenProvider::GetSession(
const TTLSServerAddr& aServerName,
RArray<TTLSProtocolVersion>& aAcceptableProtVersions,
TTLSSessionData& aOutputSessionData,
TRequestStatus& aStatus)
{
SWTLSTOKEN_LOG( _L("CSwTLSTokenProvider::GetSession") )
iToken.GetCacheData(aServerName,
aAcceptableProtVersions,
aOutputSessionData);
TRequestStatus* status = &aStatus;
User::RequestComplete( status, KErrNone);
return;
}
void CSwTLSTokenProvider::ClearSessionCache(
const TTLSServerAddr& aServerName,
TTLSSessionId& aSession,
TBool& aResult,
TRequestStatus& aStatus)
{
SWTLSTOKEN_LOG( _L("CSwTLSTokenProvider::ClearSessionCache") )
aResult = iToken.RemoveFromCache( aServerName, aSession );
TRequestStatus* status = &aStatus;
if( EFalse == aResult )
User::RequestComplete( status, KTLSErrCacheEntryInUse);
else
User::RequestComplete( status, KErrNone);
return;
}
void CSwTLSTokenProvider::CryptoCapabilities(
RArray<TTLSProtocolVersion>& aProtocols,
RArray<TTLSKeyExchangeAlgorithm>& aKeyExchAlgs,
RArray<TTLSSignatureAlgorithm>& aSigAlgs,
TRequestStatus& aStatus)
{
SWTLSTOKEN_LOG( _L("CSwTLSTokenProvider::CryptoCapabilities") )
TRequestStatus* status = &aStatus;
aProtocols.Reset();
aKeyExchAlgs.Reset();
TInt i;
TInt err = KErrNone;
err = aProtocols.Append( KTLS1_0 );
if ( err != KErrNone )
User::RequestComplete( status, err );
err = aProtocols.Append( KSSL3_0 );
if ( err != KErrNone )
User::RequestComplete( status, err );
err = aKeyExchAlgs.Append( ERsa );
if ( err != KErrNone )
User::RequestComplete( status, err );
err = aKeyExchAlgs.Append( EDHE );
if ( err != KErrNone )
User::RequestComplete( status, err );
err = aKeyExchAlgs.Append( EPsk );
if ( err != KErrNone )
User::RequestComplete( status, err );
err = aSigAlgs.Append( ERsaSigAlg );
if ( err != KErrNone )
User::RequestComplete( status, err );
err = aSigAlgs.Append( EDsa );
if ( err != KErrNone )
User::RequestComplete( status, err );
err = aSigAlgs.Append( EPskSigAlg);
if ( err != KErrNone )
User::RequestComplete( status, err );
TInt max;
max = aProtocols.Count();
for(i=0; i<max; i++)
SWTLSTOKEN_LOG2( _L(" protocol version: 3.%d inserted into list"), aProtocols[i].iMinor );
max = aKeyExchAlgs.Count();
for(i=0; i<max; i++)
SWTLSTOKEN_LOG2( _L(" key exch alg: %d inserted into list"), aKeyExchAlgs[i] );
max = aSigAlgs.Count();
for(i=0; i<max; i++)
SWTLSTOKEN_LOG2( _L(" sign alg: %d inserted into list"), aSigAlgs[i] );
if ( status )
{
User::RequestComplete( status, KErrNone);
}
return;
}
void CSwTLSTokenProvider::CancelGetSession()
{
SWTLSTOKEN_LOG( _L("CSwTLSTokenProvider::CancelGetSession") )
return;
}
void CSwTLSTokenProvider::CancelCryptoCapabilities()
{
SWTLSTOKEN_LOG( _L("CSwTLSTokenProvider::CancelCryptoCapabilities") )
return;
}
void CSwTLSTokenProvider::CancelClearSessionCache()
{
SWTLSTOKEN_LOG( _L("CSwTLSTokenProvider::CancelClearSessionCache") )
return;
}
| [
"kirill.dremov@nokia.com"
] | kirill.dremov@nokia.com |
fabfff14529600da1b9673e9b6701ddaf4b9460f | 8de76d892940f42673e3bac14046482f206dbb6f | /src/Difficulty.cpp | 8f901e2fb78d9dc0e5243406a2dac30e9ecc4992 | [
"MIT"
] | permissive | vcahlik/pa2-pacman | 229c09cf1641dfc715bc432e6cb603d10f15625a | 511b4585a136508ddfacceca08b887cb512517c1 | refs/heads/master | 2021-05-26T07:22:00.674091 | 2021-01-04T09:43:56 | 2021-01-04T09:43:56 | 127,897,736 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,485 | cpp | #include <stdexcept>
#include "Difficulty.h"
#include "Config.h"
Difficulty::Difficulty(const Level level) {
ghostBaseSpeed = Config::PLAYER_BASE_SPEED;
ghostFrightenedDurationMsecs = Config::GHOST_FRIGHTENED_DEFAULT_DURATION_MSECS;
switch (level) {
case Level::Level1:
ghostBaseSpeed *= 0.6;
ghostFrightenedDurationMsecs *= 2;
initialRemainingLives = 4;
break;
case Level::Level2:
ghostBaseSpeed *= 0.7;
ghostFrightenedDurationMsecs *= 1.5;
initialRemainingLives = 3;
break;
case Level::Level3:
ghostBaseSpeed *= 0.8;
ghostFrightenedDurationMsecs *= 1;
initialRemainingLives = 2;
break;
case Level::Level4:
ghostBaseSpeed *= 0.9;
ghostFrightenedDurationMsecs *= 0.8;
initialRemainingLives = 1;
break;
case Level::Level5:
ghostBaseSpeed *= 1;
ghostFrightenedDurationMsecs *= 0.5;
initialRemainingLives = 0;
break;
default:
throw std::logic_error("level not handled");
}
}
const double Difficulty::getGhostBaseSpeed() const {
return ghostBaseSpeed;
}
const uint32_t Difficulty::getGhostFrightenedDurationMsecs() const {
return ghostFrightenedDurationMsecs;
}
const uint32_t Difficulty::getInitialRemainingLives() const {
return initialRemainingLives;
}
| [
"vojtech.cahlik@gmail.com"
] | vojtech.cahlik@gmail.com |
529bb30cd825e36eb5d7f2d0bd1727cba35b1a78 | 4ba5cb489798e58de4cb6661f159fef051055c6e | /085_242_E.cpp | b70ce5c8064a0b8f9b6ebe8ea9d937bf7bbe78eb | [] | no_license | FstJoker/ForCC | 50be0c99ea81fe5c6981f1d40a41cb43453a99d9 | ea2fb9db9cbb7dd936558553399c93439970759e | refs/heads/master | 2023-07-02T11:09:55.441211 | 2021-08-05T05:45:16 | 2021-08-05T05:45:16 | 350,537,703 | 3 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 360 | cpp | class Solution {
public:
bool isAnagram(string s, string t) {
if (s.length() != t.length()) {
return false;
}
vector<int> counts(26, 0);
for (int i = 0; i < s.length(); ++i) {
++counts[s[i] - 'a'];
--counts[t[i] - 'a'];
}
for (int i = 0; i < 26; ++i) {
if (counts[i]) {
return false;
}
}
return true;
}
}; | [
"noreply@github.com"
] | FstJoker.noreply@github.com |
e96596a7bf1cca4a3bf7c2bf08c4e2abeb87924d | 297a6efa719f1421f921f145a9190fb0006e315f | /09-CocheFantasticoMejorado/Ejercicio05-CocheFantasticoMejorado.ino | ee9f52036d550cf74e7ff92aca611c00f4dd8767 | [] | no_license | therobotacademy/iot-arduino | 690350053493f023ffe3aa58c213859f54eb66af | 3fe9163f557d5e464ad4b769e3b1dd13d0613265 | refs/heads/master | 2021-05-02T03:43:36.339678 | 2018-03-16T17:38:40 | 2018-03-16T17:38:40 | 120,903,461 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 1,149 | ino | /* Knight Rider 2
--------------
Reducing the amount of code using for(;;).
(cleft) 2005 K3, Malmo University
@author: David Cuartielles
@hardware: David Cuartielles, Aaron Hallborg
@modified by: aprendiendoarduino
*/
int pinArray[] = {3, 5, 8, 10, 12};
int count = 0;
int timer = 400;
void setup() {
Serial.begin(9600);
// we make all the declarations at once
for (count = 0; count < 5; count++) {
pinMode(pinArray[count], OUTPUT);
}
}
void loop() {
timer = analogRead(A0)/4; //El valor leido por analog read es el temporizador
Serial.print("timer= ");
Serial.println(timer);
for (count = 0; count < 5; count++) {
//timer = analogRead(A0);
digitalWrite(pinArray[count], HIGH);
Serial.print("Enciendo led ");
Serial.println(pinArray[count]);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer);
}
for (count = 4; count >= 0; count--) {
//timer = analogRead(A0);
digitalWrite(pinArray[count], HIGH);
Serial.print("Enciendo led ");
Serial.println(pinArray[count]);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer);
}
}
| [
"brjapon@therobotacademy.com"
] | brjapon@therobotacademy.com |
102151930973ebeed1f16c1cbac2af82e7175579 | 45e8b758cf6d2161ea627f0849335baffcbc00a1 | /Project_3/Project_3_QS/Project_3_QS/Source.cpp | 5d215bd81eb170b46b3661113c493f99fde47f2f | [] | no_license | usmcschloss/CIS-3501 | 885e044e942b05e0e5a4e64981cf015c216644b4 | 8c3e215e2e86098e999c346674847f26e736666b | refs/heads/master | 2020-07-29T13:46:11.065748 | 2020-02-03T19:47:08 | 2020-02-03T19:47:08 | 209,827,162 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,556 | cpp | #include <iostream>
#include <chrono>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <math.h>
/* help from: https://www.youtube.com/watch?v=Y2UpnCnMB-s
Programmer Name: Michael D. Schloss
Program Name: Quick Sorting Timer
Date: 11-9-19
Class: CIS-3501 / Fall 2019
Professor: John P. Baugh
*/
using namespace std;
// This will manage the partitions portion of the Quick Sort
// Conditions: Must have properly built the vectors.
int QSpartition(vector<int>& setVec, int begin, int end)
{
int temp, i, x, j;
x = setVec.at(end);
i = begin - 1;
for (j = begin; j <= end; j++)
{
if (setVec.at(j) < x)
{
i++;
temp = setVec.at(i);
setVec.at(i) = setVec.at(j);
setVec.at(j) = temp;
}
}
i++;
temp = setVec.at(i);
setVec.at(i) = setVec.at(end);
setVec.at(end) = temp;
return i;
}
// Partitions managed.
// This will do the overall Quick Sorting of the given vectors
// Conditions: Must have accurately executed the partitions.
void QuickSort(vector<int> &setVec, int begin, int end)
{
int partitionValue;
if (begin <= end)
{
partitionValue = QSpartition(setVec, begin, end);
QuickSort(setVec, begin, partitionValue - 1);
QuickSort(setVec, partitionValue + 1, end);
}
}
// Vectors have been sorted.
// This will display the given vectors before and after sorting
// Conditions: Must have accurately executed the Quick Sort.
void DisplaySort(vector<int> setVec)
{
cout << "Before sort: " << endl;
for (int i = 0; i < setVec.size(); i++)
{
cout << setVec.at(i) << " ";
}
QuickSort(setVec, 0, (setVec.size() - 1));
cout << endl << "After sort: " << endl;
for (int i = 0; i < setVec.size(); i++)
{
cout << setVec.at(i) << " ";
}
}
// Vectors displayed.
int main()
{
vector<int> set250, set500, set750, set1000, set2500;
//vector<int> test = { 15, 42, 3, 107, 47, 66, 13, 88, 1 };
srand(time(0));
//DisplaySort(test);
// The following 'for' loops will create the vectors.
// Conditions: element values must be >= 0 && <= 1000
for (int i = 0; i < 250; i++)
{
set250.push_back(1 + (rand() % 1000));
}
for (int i = 0; i < 500; i++)
{
set500.push_back(1 + (rand() % 1000));
}
for (int i = 0; i < 750; i++)
{
set750.push_back(1 + (rand() % 1000));
}
for (int i = 0; i < 1000; i++)
{
set1000.push_back(1 + (rand() % 1000));
}
for (int i = 0; i < 2500; i++)
{
set2500.push_back(1 + (rand() % 1000));
}
using namespace chrono;
// These record the duration of sorting and displaying the vectors
// Also calls the Display/Soring methods.
// No conditions required.
steady_clock::time_point t250_1 = steady_clock::now();
DisplaySort(set250);
steady_clock::time_point t250_2 = steady_clock::now();
duration<double> time_span250 = duration_cast<duration<double>>(t250_2 - t250_1);
cout << endl << endl << endl << endl;
steady_clock::time_point t500_1 = steady_clock::now();
DisplaySort(set500);
steady_clock::time_point t500_2 = steady_clock::now();
duration<double> time_span500 = duration_cast<duration<double>>(t500_2 - t500_1);
cout << endl << endl << endl << endl;
steady_clock::time_point t750_1 = steady_clock::now();
DisplaySort(set750);
steady_clock::time_point t750_2 = steady_clock::now();
duration<double> time_span750 = duration_cast<duration<double>>(t750_2 - t750_1);
cout << endl << endl << endl << endl;
steady_clock::time_point t1000_1 = steady_clock::now();
DisplaySort(set1000);
steady_clock::time_point t1000_2 = steady_clock::now();
duration<double> time_span1000 = duration_cast<duration<double>>(t1000_2 - t1000_1);
cout << endl << endl << endl << endl;
steady_clock::time_point t2500_1 = steady_clock::now();
DisplaySort(set2500);
steady_clock::time_point t2500_2 = steady_clock::now();
duration<double> time_span2500 = duration_cast<duration<double>>(t2500_2 - t2500_1);
cout << endl << endl << endl << endl;
// Sorting has been timed
// Vectors have been sorted and dispalyed
cout << "Total run time for set250: " << time_span250.count() << " seconds." << endl;
cout << "Total run time for set500: " << time_span500.count() << " seconds." << endl;
cout << "Total run time for set750: " << time_span750.count() << " seconds." << endl;
cout << "Total run time for set1000: " << time_span1000.count() << " seconds." << endl;
cout << "Total run time for set2500: " << time_span2500.count() << " seconds." << endl;
system("pause");
return 0;
} | [
"noreply@github.com"
] | usmcschloss.noreply@github.com |
4cdcd6b4237a5aa5527fba8435c344cec1fd23d1 | 03c7cf7a57a1a26bb21e0184642f0a5c8b0336ae | /Release/gen/webcore/bindings/V8SQLTransactionErrorCallback.cpp | 32377624f8f2e3dd8b30ee17b96c8d32e3e82898 | [] | no_license | sanyaade-embedded-systems/armhf-node-webkit | eb38a2a34e833310ee477592028905fd00a86e5a | 5bc4509c0e19cce1a64b7cab4f92f91edfa17944 | refs/heads/master | 2020-12-30T19:11:15.189923 | 2013-03-16T14:29:23 | 2013-03-16T14:29:23 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,336 | cpp | /*
This file is part of the WebKit open source project.
This file has been generated by generate-bindings.pl. DO NOT MODIFY!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "V8SQLTransactionErrorCallback.h"
#if ENABLE(SQL_DATABASE)
#include "ScriptExecutionContext.h"
#include "V8Binding.h"
#include "V8Callback.h"
#include "V8SQLError.h"
#include <wtf/GetPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/Assertions.h>
namespace WebCore {
V8SQLTransactionErrorCallback::V8SQLTransactionErrorCallback(v8::Handle<v8::Object> callback, ScriptExecutionContext* context)
: ActiveDOMCallback(context)
, m_callback(callback)
, m_worldContext(UseCurrentWorld)
{
}
V8SQLTransactionErrorCallback::~V8SQLTransactionErrorCallback()
{
}
// Functions
bool V8SQLTransactionErrorCallback::handleEvent(SQLError* error)
{
if (!canInvokeCallback())
return true;
v8::HandleScope handleScope;
v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext);
if (v8Context.IsEmpty())
return true;
v8::Context::Scope scope(v8Context);
v8::Handle<v8::Value> errorHandle = toV8(error);
if (errorHandle.IsEmpty()) {
if (!isScriptControllerTerminating())
CRASH();
return true;
}
v8::Handle<v8::Value> argv[] = {
errorHandle
};
bool callbackReturnValue = false;
return !invokeCallback(m_callback.get(), 1, argv, callbackReturnValue, scriptExecutionContext());
}
} // namespace WebCore
#endif // ENABLE(SQL_DATABASE)
| [
"marian.such@ackee.cz"
] | marian.such@ackee.cz |
ba449a9fe1b31be52650e846dc989051ce866e15 | 1fa6620e50dcc759e561904b0890c2f436b432fb | /OccFaceDetectFromSensor/main.cpp | 51f6540f9cec635b9e9cc0b61037bd581b26d38f | [] | no_license | brycezou/GroceryProjects | ee3f31a2f3538d45370a964c14d9f33fa093af6a | acd8d390692d42a648e6493cf1f7d3ebee124089 | refs/heads/master | 2021-08-10T09:21:27.005941 | 2017-11-12T12:59:05 | 2017-11-12T12:59:05 | 110,268,793 | 0 | 0 | null | null | null | null | GB18030 | C++ | false | false | 9,010 | cpp | #include <Windows.h>
#include "obtainForegroundMask.h"
#include "FourierTransform.h"
#include "LocateHeadRegion.h"
#include "registerColor2Depth.h"
#include "FindContours.h"
#include "GetHeadRegionRect.h"
#include <fstream>
#include "svm.h"
#include "KinectConnector.h"
using namespace std;
//在深度图像depthIpl和配准后的彩色图像regColorIpl上
//标记出人脸区域headRect
//说明:直接在原图上标记
void showHeadRectResult(IplImage *depthIpl, IplImage *regColorIpl, CvRect &headRect)
{
cvRectangle(depthIpl, cvPoint(2*headRect.x, 2*headRect.y), cvPoint(2*(headRect.x+headRect.width), 2*(headRect.y+headRect.height)), CV_RGB(0,0,128), 2);
cvShowImage("深度人头定位结果", depthIpl);
cvRectangle(regColorIpl, cvPoint(2*headRect.x, 2*headRect.y), cvPoint(2*(headRect.x+headRect.width), 2*(headRect.y+headRect.height)), CV_RGB(255,0,0), 2);
cvShowImage("彩色人头定位结果", regColorIpl);
}
//缩放输入图像src至新的尺寸
//缩放后的宽度为newWidth
//缩放后的高度为newHeight
//说明:会返回新的图像
IplImage* resizeInputImage(IplImage *src, int newWidth, int newHeight)
{
IplImage *newSizeImg = cvCreateImage(cvSize(newWidth, newHeight), src->depth, src->nChannels);
cvResize(src, newSizeImg, CV_INTER_LINEAR);
return newSizeImg;
}
//在48x56的人脸区域上预定义的区域
CvRect EYES_RECT = cvRect(6, 16, 36, 16); //眼睛区域
CvRect NOSE_RECT = cvRect(6, 24, 36, 16); //鼻子区域
CvRect MOUTH_RECT = cvRect(6, 32, 36, 16); //嘴巴区域
CvRect CHIN_RECT = cvRect(6, 48, 36, 8); //下巴区域
//高级人脸分块的特征向量
//彩色图像的彩色直方图, 彩色图像的灰度直方图
//彩色图像的Haar特征, 深度图像的Haar特征
int f_vc[4172];
//得到图像color_img的彩色直方图(每个通道取16级灰度), 保存在f_vc数组的[0:4095]位
//和灰度直方图(64级灰度), 保存在f_vc数组的[4096:4159]位
void getColorAndGrayHistogram(IplImage *color_img)
{
memset(f_vc, 0, sizeof(int)*4172);
for (int i = 0; i < color_img->height; i++)
{
for (int j = 0; j < color_img->width; j++)
{
int rr = ((uchar*)(color_img->imageData+i*color_img->widthStep))[j*color_img->nChannels+0];
int gg = ((uchar*)(color_img->imageData+i*color_img->widthStep))[j*color_img->nChannels+1];
int bb = ((uchar*)(color_img->imageData+i*color_img->widthStep))[j*color_img->nChannels+2];
f_vc[rr/16*256+gg/16*16+bb/16]++; //统计彩色直方图 [0:4095]
f_vc[((int)(0.30*rr+0.59*gg+0.11*bb))/4+4096]++; //统计灰度直方图 [4096:4159]
}
}
}
struct svm_model* eyes_model;
struct svm_model* nose_model;
struct svm_model* mouth_model;
int EYES_PREDICT;
int NOSE_PREDICT;
int MOUTH_PREDICT;
int predictOcclusionByColor(IplImage *color_roi)
{
//预测眼睛区域
cvSetImageROI(color_roi, EYES_RECT);
getColorAndGrayHistogram(color_roi);
//svm节点(index:value)
struct svm_node *eyes_node = (struct svm_node *) malloc(4173*sizeof(struct svm_node));
for (int i = 0; i < 4172; i++) {
eyes_node[i].index = i+1;
eyes_node[i].value = f_vc[i];
}
eyes_node[4172].index = -1;
int eyes_predict = (int)svm_predict(eyes_model, eyes_node);
free(eyes_node);
cvResetImageROI(color_roi);
//预测鼻子区域
cvSetImageROI(color_roi, NOSE_RECT);
getColorAndGrayHistogram(color_roi);
struct svm_node *nose_node = (struct svm_node *) malloc(4173*sizeof(struct svm_node));
for (int i = 0; i < 4172; i++) {
nose_node[i].index = i+1;
nose_node[i].value = f_vc[i];
}
nose_node[4172].index = -1;
int nose_predict = (int)svm_predict(nose_model, nose_node);
free(nose_node);
cvResetImageROI(color_roi);
//预测嘴巴区域
cvSetImageROI(color_roi, MOUTH_RECT);
getColorAndGrayHistogram(color_roi);
struct svm_node *mouth_node = (struct svm_node *) malloc(4173*sizeof(struct svm_node));
for (int i = 0; i < 4172; i++) {
mouth_node[i].index = i+1;
mouth_node[i].value = f_vc[i];
}
mouth_node[4172].index = -1;
int mouth_predict = (int)svm_predict(mouth_model, mouth_node);
free(mouth_node);
cvResetImageROI(color_roi);
EYES_PREDICT = eyes_predict;
NOSE_PREDICT = nose_predict;
MOUTH_PREDICT = mouth_predict;
cout<<eyes_predict<<", "<<nose_predict<<", "<<mouth_predict<<endl;
return eyes_predict+nose_predict+mouth_predict;
}
int predictOcclution(IplImage *depthIpl, IplImage *regColorIpl, CvRect &headRect)
{
//获得人脸感兴趣区域
CvRect rect_roi = cvRect(2*headRect.x, 2*headRect.y, 2*headRect.width, 2*headRect.height);
//将深度人脸图像缩放到48*56像素
cvSetImageROI(depthIpl, rect_roi);
IplImage *depth_roi = resizeInputImage(depthIpl, 48, 56);
cvResetImageROI(depthIpl);
//将彩色人脸图像缩放到48*56像素
cvSetImageROI(regColorIpl, rect_roi);
IplImage *color_roi = resizeInputImage(regColorIpl, 48, 56);
cvResetImageROI(regColorIpl);
int res = predictOcclusionByColor(color_roi);
cvReleaseImage(&color_roi);
cvReleaseImage(&depth_roi);
return res;
}
bool gbExit = false;
DWORD WINAPI handleThread(LPVOID lpParam)
{
gbExit = false;
//定义和创建读取下一帧的信号事件句柄,控制KINECT是否可以开始读取下一帧深度数据
HANDLE depthEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
//定义和创建读取下一帧的信号事件句柄,控制KINECT是否可以开始读取下一帧彩色数据
HANDLE colorEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
//保存深度图像数据流的句柄,用以提取数据
HANDLE depthStreamHandle = NULL;
//保存彩色图像数据流的句柄,用以提取数据
HANDLE colorStreamHandle = NULL;
if(!InitializeKinect(depthEvent, depthStreamHandle, colorEvent, colorStreamHandle))
{
gbExit = true;
return -1;
}
//加载SVM模型文件
cout<<"loading svm model ..."<<endl;
eyes_model = svm_load_model("eyes.model");
nose_model = svm_load_model("nose.model");
mouth_model = svm_load_model("mouth.model");
cout<<"svm model loaded"<<endl;
//定义和初始化深度图像
Mat depthMat(480, 640, CV_8UC1);
IplImage *depthIpl = cvCreateImage(cvSize(640, 480), 8, 1);
//定义和初始化彩色图像
Mat colorMat(480, 640, CV_8UC3);
IplImage *colorIpl = cvCreateImage(cvSize(640, 480), 8, 3);
IplImage *depth2show = NULL;
IplImage *color2show = NULL;
char sResultTxtOut[10];
char sDetalResult[10];
CvRect headRect;
//将结果保存到视频文件中
//CvVideoWriter *writer = cvCreateVideoWriter("test.avi",CV_FOURCC('M','J','P','G'), 20, cvGetSize(colorIpl));
while(true)
{
// 无限等待新的数据,等到后WaitForSingleObject为0,则返回
if(WAIT_OBJECT_0 == WaitForSingleObject(depthEvent, INFINITE))
{
if (WAIT_OBJECT_0 == WaitForSingleObject(colorEvent, INFINITE))
{
if(getDepthImage(depthEvent, depthStreamHandle, depthMat))
{
if (getColorImage(colorEvent, colorStreamHandle, colorMat))
{
depthIpl->imageData = (char *)depthMat.data;
colorIpl->imageData = (char *)colorMat.data;
depth2show = cvCloneImage(depthIpl);
IplImage *regColorIpl = GetHeadRegionRect(depthIpl, colorIpl, headRect, false);
if (regColorIpl != NULL)
{
color2show = cvCloneImage(regColorIpl);
int res = predictOcclution(depthIpl, regColorIpl, headRect);
if(res >= 1)
{
cout<<"!!!!!!!!!!!!!!!!!!!!Occluded"<<endl;
sprintf(sResultTxtOut, "Occluded");
}
else
{
cout<<"-----------------Safe"<<endl;
sprintf(sResultTxtOut, "Safe");
}
CvFont font;
cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, 1,1,0,2);
sprintf(sDetalResult, "%d, %d, %d", EYES_PREDICT, NOSE_PREDICT, MOUTH_PREDICT);
cvPutText(color2show,sDetalResult,cvPoint(10,50),&font,CV_RGB(255,0,0));
cvPutText(color2show,sResultTxtOut,cvPoint(10,100),&font,CV_RGB(255,0,0));
showHeadRectResult(depth2show, color2show, headRect);
//cvWriteFrame(writer, color2show);
cvReleaseImage(®ColorIpl);
cvReleaseImage(&color2show);
}
cvReleaseImage(&depth2show);
if(cvWaitKey(1) == 27)
break;
}
else
{
NuiShutdown();
if(!InitializeKinect(depthEvent, depthStreamHandle, colorEvent, colorStreamHandle))
{
cvReleaseImage(&colorIpl);
cvReleaseImage(&depthIpl);
gbExit = true;
return -1;
}
}
}
else
{
NuiShutdown();
if(!InitializeKinect(depthEvent, depthStreamHandle, colorEvent, colorStreamHandle))
{
cvReleaseImage(&colorIpl);
cvReleaseImage(&depthIpl);
gbExit = true;
return -1;
}
}
}
}
//cvWaitKey(0);
if(cvWaitKey(1) == 27)
break;
//cvReleaseVideoWriter(&writer);
}
NuiShutdown();
gbExit = true;
return 0;
}
int main(int argc, char **argv)
{
HANDLE handle = CreateThread(NULL, 0, handleThread, NULL, 0, 0);
if(!handle)
cout<<"Creating handleThread failed!"<<endl;
while (!gbExit)
Sleep(100);
return 0;
}
| [
"1574689068@qq.com"
] | 1574689068@qq.com |
b6a8a0f7d42f867af210b2547d5ad96bc8c0919a | 6b514ab0c3d714a60e65e42582e7cecf9366b4f4 | /include/web-socketz.h | f6c54037d20c5af2f03e9628b60314247ca542b7 | [] | no_license | zualex-zz/zRadio | 5356fd500b06c9faabef70406b2d7a8850039de6 | d1771c04ea8702c48516769d4e7fbf35f3fa6257 | refs/heads/main | 2023-03-20T20:46:30.224879 | 2021-03-09T14:06:16 | 2021-03-09T14:06:16 | 346,022,119 | 3 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 840 | h | #ifndef WEBSOCKETZ_H
#define WEBSOCKETZ_H
#include <WebSocketsServer.h>
WebSocketsServer webSocket = WebSocketsServer(81);
class WebSocketz {
// WebSocketServerEvent webSocketServerEvent;
public:
WebSocketz() {
Serial.print("WebSocketz constructor");
}
void begin() {
webSocket.begin();
// webSocket.onEvent(webSocketEvent);
}
// void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length){
// // Do something with the data from the client
// if(type == WStype_TEXT){
// Serial.print("webSocketEvent: ");
// Serial.println(payload);
// }
// }
void static broadcastTXT(String json) {
webSocket.broadcastTXT(json.c_str(), json.length());
}
void loop() {
webSocket.loop();
}
};
#endif | [
"alex.zupan@gpi.it"
] | alex.zupan@gpi.it |
b10f5717b21029b52c9508c48748355eff6845f9 | 04b1803adb6653ecb7cb827c4f4aa616afacf629 | /third_party/blink/renderer/platform/audio/audio_io_callback.h | cb9e87dcaeca4757c590d639a866dd630daecb11 | [
"BSD-3-Clause",
"LGPL-2.0-or-later",
"GPL-1.0-or-later",
"MIT",
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer",
"LGPL-2.1-only",
"GPL-2.0-only",
"LGPL-2.0-only",
"BSD-2-Clause",
"LicenseRef-scancode-other-copyleft"
] | permissive | Samsung/Castanets | 240d9338e097b75b3f669604315b06f7cf129d64 | 4896f732fc747dfdcfcbac3d442f2d2d42df264a | refs/heads/castanets_76_dev | 2023-08-31T09:01:04.744346 | 2021-07-30T04:56:25 | 2021-08-11T05:45:21 | 125,484,161 | 58 | 49 | BSD-3-Clause | 2022-10-16T19:31:26 | 2018-03-16T08:07:37 | null | UTF-8 | C++ | false | false | 2,988 | h | /*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_AUDIO_AUDIO_IO_CALLBACK_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_AUDIO_AUDIO_IO_CALLBACK_H_
#include "base/time/time.h"
namespace blink {
class AudioBus;
// For the calculation of "render capacity". The render capacity can be
// calculated by dividing |render_duration| by |callback_interval|.
struct AudioIOCallbackMetric {
// The time interval in seconds between the onset of previous callback
// function and the current one.
double callback_interval;
// The time duration spent on rendering render quanta (i.e. batch pulling of
// audio graph) per a device callback request.
double render_duration;
};
struct AudioIOPosition {
// Audio stream position in seconds.
double position;
// System timestamp in seconds corresponding to the contained |position|
// value.
double timestamp;
};
// Abstract base-class for isochronous audio I/O client.
class AudioIOCallback {
public:
// Called periodically to get the next render quantum of audio into
// |destination_bus|.
virtual void Render(AudioBus* destination_bus,
uint32_t frames_to_process,
const AudioIOPosition& output_position,
const AudioIOCallbackMetric& metric) = 0;
virtual ~AudioIOCallback() = default;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_AUDIO_AUDIO_IO_CALLBACK_H_
| [
"sunny.nam@samsung.com"
] | sunny.nam@samsung.com |
73cddd85e77924ff8f309948a2f0e4ac671a9790 | b8787d4781cd9de928daaa74df4ffadafbd13b2c | /8-2和为0的4个值.cpp | 36ff0108c7d6073c3f07bd598def60977eef6f10 | [] | no_license | li136/ZiShu | 4c4ed169cd689d3a14c73971201860575016e3aa | 7f31e682ccd980ace8c741b4d4b193ba25565c19 | refs/heads/master | 2020-09-02T02:53:31.536151 | 2019-11-02T07:10:53 | 2019-11-02T07:10:53 | 219,117,466 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 762 | cpp | // UVa1152 4 Values Whose Sum is Zero
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 4000 + 5;
int n, c, A[maxn], B[maxn], C[maxn], D[maxn], sums[maxn*maxn];
int main() {
int T;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
c = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
sums[c++] = A[i] + B[j];
sort(sums, sums+c);
long long cnt = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
cnt += upper_bound(sums, sums+c, -C[i]-D[j]) - lower_bound(sums, sums+c, -C[i]-D[j]);
printf("%lld\n", cnt);
if(T) printf("\n");
}
return 0;
}
| [
"noreply@github.com"
] | li136.noreply@github.com |
aafc427123fd7eae023412c1d845c3d60db0443a | 343be0148831bcc76cc69829815eacf5e72488a2 | /ast/operators/ASTAssignOperator.cpp | 620b1dd0aa13e4410354493a0f0a4942ce6652bc | [] | no_license | tranvanh/PJP_semestralwork | f281ce2697b1462fd82d827555d2dccb80b5a22f | 6687882620b2af3a5cd659d53af5596fbd67aee4 | refs/heads/master | 2022-12-27T03:58:32.307198 | 2020-09-10T20:16:03 | 2020-09-10T20:16:03 | 268,293,173 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 304 | cpp | //
// Created by Tomas Tran on 01/06/2020.
//
#include "ASTAssignOperator.hpp"
ASTAssignOperator::ASTAssignOperator(std::unique_ptr<ASTReference> variable,
std::unique_ptr<ASTExpression> value)
: m_Variable(std::move(variable)), m_Value(std::move(value)) {} | [
"tranvanh@fit.cvut.cz"
] | tranvanh@fit.cvut.cz |
3e8440cbc8382b5d7bc58099b8fc99a6abe69e06 | 8975b519d7dc2930e787e65e9505774557dfe982 | /IndoorGMLParser/Face.h | 7d75362e6bfc1139e6eb8a4e4ddbb0e6fdf9bd29 | [] | no_license | JungHam/IndoorGMLParser | 36ae477b8da1a34775d9810dba2170f04ecca910 | 26a76578e1ea1d49db7d358657f651a48755db51 | refs/heads/master | 2020-06-03T08:22:50.005011 | 2019-08-19T11:50:51 | 2019-08-19T11:50:51 | 191,506,101 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 765 | h | #pragma once
#include <iostream>
#include <vector>
#include "Vertex.h"
#include "Point3d.h"
#include "Polygon2D.h"
#include "Triangle.h"
using namespace std;
namespace geometry {
class Face {
vector<Vertex>vertexArray;
indoorgml::Point3D calculateNormal();
indoorgml::Point3D _normal;
bool hasNormalValue;
public :
Face();
void addVertex(Vertex a);
void setVertexArray(vector<Vertex> arr);
vector<Vertex> getVertexArray();
indoorgml::Point3D getNormal();
void setNormal();
int getBestFacePlaneTypeToProject();
Polygon2D getProjectedPolygon();
void calculateVerticesNormals();
vector<Triangle> getTessellatedTriangles();
vector<Triangle> getTrianglesConvex();
//void convertFromPolygon(shared_ptr<indoorgml::Polygon> p);
};
} | [
"hmjeong@gaia3d.com"
] | hmjeong@gaia3d.com |
81127547d3ab9b40b03ac350525546f3b0f9145c | 6e57bdc0a6cd18f9f546559875256c4570256c45 | /external/pdfium/xfa/fxfa/cxfa_ffpageview.cpp | fe1fbb517fb90fc7abceb24648da3d292926a235 | [
"BSD-3-Clause"
] | permissive | dongdong331/test | 969d6e945f7f21a5819cd1d5f536d12c552e825c | 2ba7bcea4f9d9715cbb1c4e69271f7b185a0786e | refs/heads/master | 2023-03-07T06:56:55.210503 | 2020-12-07T04:15:33 | 2020-12-07T04:15:33 | 134,398,935 | 2 | 1 | null | 2022-11-21T07:53:41 | 2018-05-22T10:26:42 | null | UTF-8 | C++ | false | false | 15,857 | cpp | // Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "xfa/fxfa/cxfa_ffpageview.h"
#include <algorithm>
#include <memory>
#include <vector>
#include "fxjs/xfa/cjx_object.h"
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
#include "xfa/fxfa/cxfa_ffcheckbutton.h"
#include "xfa/fxfa/cxfa_ffdoc.h"
#include "xfa/fxfa/cxfa_ffdocview.h"
#include "xfa/fxfa/cxfa_fffield.h"
#include "xfa/fxfa/cxfa_ffimageedit.h"
#include "xfa/fxfa/cxfa_ffpushbutton.h"
#include "xfa/fxfa/cxfa_ffwidget.h"
#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h"
#include "xfa/fxfa/parser/cxfa_node.h"
#include "xfa/fxfa/parser/cxfa_traversal.h"
#include "xfa/fxfa/parser/cxfa_traverse.h"
namespace {
CFX_Matrix GetPageMatrix(const CFX_RectF& docPageRect,
const CFX_Rect& devicePageRect,
int32_t iRotate,
uint32_t dwCoordinatesType) {
ASSERT(iRotate >= 0 && iRotate <= 3);
bool bFlipX = (dwCoordinatesType & 0x01) != 0;
bool bFlipY = (dwCoordinatesType & 0x02) != 0;
CFX_Matrix m((bFlipX ? -1.0f : 1.0f), 0, 0, (bFlipY ? -1.0f : 1.0f), 0, 0);
if (iRotate == 0 || iRotate == 2) {
m.a *= (float)devicePageRect.width / docPageRect.width;
m.d *= (float)devicePageRect.height / docPageRect.height;
} else {
m.a *= (float)devicePageRect.height / docPageRect.width;
m.d *= (float)devicePageRect.width / docPageRect.height;
}
m.Rotate(iRotate * 1.57079632675f);
switch (iRotate) {
case 0:
m.e = bFlipX ? (float)devicePageRect.right() : (float)devicePageRect.left;
m.f = bFlipY ? (float)devicePageRect.bottom() : (float)devicePageRect.top;
break;
case 1:
m.e = bFlipY ? (float)devicePageRect.left : (float)devicePageRect.right();
m.f = bFlipX ? (float)devicePageRect.bottom() : (float)devicePageRect.top;
break;
case 2:
m.e = bFlipX ? (float)devicePageRect.left : (float)devicePageRect.right();
m.f = bFlipY ? (float)devicePageRect.top : (float)devicePageRect.bottom();
break;
case 3:
m.e = bFlipY ? (float)devicePageRect.right() : (float)devicePageRect.left;
m.f = bFlipX ? (float)devicePageRect.top : (float)devicePageRect.bottom();
break;
default:
break;
}
return m;
}
bool PageWidgetFilter(CXFA_FFWidget* pWidget,
uint32_t dwFilter,
bool bTraversal,
bool bIgnorerelevant) {
CXFA_Node* pNode = pWidget->GetNode();
if (!!(dwFilter & XFA_WidgetStatus_Focused) &&
(!pNode || pNode->GetElementType() != XFA_Element::Field)) {
return false;
}
uint32_t dwStatus = pWidget->GetStatus();
if (bTraversal && (dwStatus & XFA_WidgetStatus_Disabled))
return false;
if (bIgnorerelevant)
return !!(dwStatus & XFA_WidgetStatus_Visible);
dwFilter &= (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable |
XFA_WidgetStatus_Printable);
return (dwFilter & dwStatus) == dwFilter;
}
bool IsLayoutElement(XFA_Element eElement, bool bLayoutContainer) {
switch (eElement) {
case XFA_Element::Draw:
case XFA_Element::Field:
case XFA_Element::InstanceManager:
return !bLayoutContainer;
case XFA_Element::Area:
case XFA_Element::Subform:
case XFA_Element::ExclGroup:
case XFA_Element::SubformSet:
case XFA_Element::PageArea:
case XFA_Element::Form:
return true;
default:
return false;
}
}
} // namespace
CXFA_FFPageView::CXFA_FFPageView(CXFA_FFDocView* pDocView, CXFA_Node* pPageArea)
: CXFA_ContainerLayoutItem(pPageArea), m_pDocView(pDocView) {}
CXFA_FFPageView::~CXFA_FFPageView() {}
CXFA_FFDocView* CXFA_FFPageView::GetDocView() const {
return m_pDocView.Get();
}
CFX_RectF CXFA_FFPageView::GetPageViewRect() const {
return CFX_RectF(0, 0, GetPageSize());
}
CFX_Matrix CXFA_FFPageView::GetDisplayMatrix(const CFX_Rect& rtDisp,
int32_t iRotate) const {
return GetPageMatrix(CFX_RectF(0, 0, GetPageSize()), rtDisp, iRotate, 0);
}
std::unique_ptr<IXFA_WidgetIterator> CXFA_FFPageView::CreateWidgetIterator(
uint32_t dwTraverseWay,
uint32_t dwWidgetFilter) {
switch (dwTraverseWay) {
case XFA_TRAVERSEWAY_Tranvalse:
return pdfium::MakeUnique<CXFA_FFTabOrderPageWidgetIterator>(
this, dwWidgetFilter);
case XFA_TRAVERSEWAY_Form:
return pdfium::MakeUnique<CXFA_FFPageWidgetIterator>(this,
dwWidgetFilter);
}
return nullptr;
}
CXFA_FFPageWidgetIterator::CXFA_FFPageWidgetIterator(CXFA_FFPageView* pPageView,
uint32_t dwFilter)
: m_pPageView(pPageView), m_dwFilter(dwFilter), m_sIterator(pPageView) {
m_bIgnorerelevant =
m_pPageView->GetDocView()->GetDoc()->GetXFADoc()->GetCurVersionMode() <
XFA_VERSION_205;
}
CXFA_FFPageWidgetIterator::~CXFA_FFPageWidgetIterator() {}
void CXFA_FFPageWidgetIterator::Reset() {
m_sIterator.Reset();
}
CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToFirst() {
m_sIterator.Reset();
for (CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent(); pLayoutItem;
pLayoutItem = m_sIterator.MoveToNext()) {
if (CXFA_FFWidget* hWidget = GetWidget(pLayoutItem)) {
return hWidget;
}
}
return nullptr;
}
CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToLast() {
m_sIterator.SetCurrent(nullptr);
return MoveToPrevious();
}
CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToNext() {
for (CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToNext(); pLayoutItem;
pLayoutItem = m_sIterator.MoveToNext()) {
if (CXFA_FFWidget* hWidget = GetWidget(pLayoutItem)) {
return hWidget;
}
}
return nullptr;
}
CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToPrevious() {
for (CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToPrev(); pLayoutItem;
pLayoutItem = m_sIterator.MoveToPrev()) {
if (CXFA_FFWidget* hWidget = GetWidget(pLayoutItem)) {
return hWidget;
}
}
return nullptr;
}
CXFA_FFWidget* CXFA_FFPageWidgetIterator::GetCurrentWidget() {
CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent();
return pLayoutItem ? XFA_GetWidgetFromLayoutItem(pLayoutItem) : nullptr;
}
bool CXFA_FFPageWidgetIterator::SetCurrentWidget(CXFA_FFWidget* hWidget) {
return hWidget && m_sIterator.SetCurrent(hWidget);
}
CXFA_FFWidget* CXFA_FFPageWidgetIterator::GetWidget(
CXFA_LayoutItem* pLayoutItem) {
CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem);
if (!pWidget)
return nullptr;
if (!PageWidgetFilter(pWidget, m_dwFilter, false, m_bIgnorerelevant))
return nullptr;
if (!pWidget->IsLoaded() &&
!!(pWidget->GetStatus() & XFA_WidgetStatus_Visible)) {
if (!pWidget->LoadWidget())
return nullptr;
}
return pWidget;
}
void CXFA_TabParam::AppendTabParam(CXFA_TabParam* pParam) {
m_Children.push_back(pParam->GetWidget());
m_Children.insert(m_Children.end(), pParam->GetChildren().begin(),
pParam->GetChildren().end());
}
void CXFA_TabParam::ClearChildren() {
m_Children.clear();
}
CXFA_FFTabOrderPageWidgetIterator::CXFA_FFTabOrderPageWidgetIterator(
CXFA_FFPageView* pPageView,
uint32_t dwFilter)
: m_pPageView(pPageView), m_dwFilter(dwFilter), m_iCurWidget(-1) {
m_bIgnorerelevant =
m_pPageView->GetDocView()->GetDoc()->GetXFADoc()->GetCurVersionMode() <
XFA_VERSION_205;
Reset();
}
CXFA_FFTabOrderPageWidgetIterator::~CXFA_FFTabOrderPageWidgetIterator() {}
void CXFA_FFTabOrderPageWidgetIterator::Reset() {
CreateTabOrderWidgetArray();
m_iCurWidget = -1;
}
CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToFirst() {
for (int32_t i = 0;
i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) {
if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
m_bIgnorerelevant)) {
m_iCurWidget = i;
return m_TabOrderWidgetArray[m_iCurWidget];
}
}
return nullptr;
}
CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToLast() {
for (int32_t i = pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray) - 1;
i >= 0; i--) {
if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
m_bIgnorerelevant)) {
m_iCurWidget = i;
return m_TabOrderWidgetArray[m_iCurWidget];
}
}
return nullptr;
}
CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToNext() {
for (int32_t i = m_iCurWidget + 1;
i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) {
if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
m_bIgnorerelevant)) {
m_iCurWidget = i;
return m_TabOrderWidgetArray[m_iCurWidget];
}
}
m_iCurWidget = -1;
return nullptr;
}
CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToPrevious() {
for (int32_t i = m_iCurWidget - 1; i >= 0; i--) {
if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
m_bIgnorerelevant)) {
m_iCurWidget = i;
return m_TabOrderWidgetArray[m_iCurWidget];
}
}
m_iCurWidget = -1;
return nullptr;
}
CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetCurrentWidget() {
return m_iCurWidget >= 0 ? m_TabOrderWidgetArray[m_iCurWidget] : nullptr;
}
bool CXFA_FFTabOrderPageWidgetIterator::SetCurrentWidget(
CXFA_FFWidget* hWidget) {
auto it = std::find(m_TabOrderWidgetArray.begin(),
m_TabOrderWidgetArray.end(), hWidget);
if (it == m_TabOrderWidgetArray.end())
return false;
m_iCurWidget = it - m_TabOrderWidgetArray.begin();
return true;
}
CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetTraverseWidget(
CXFA_FFWidget* pWidget) {
CXFA_Traversal* pTraversal = pWidget->GetNode()->GetChild<CXFA_Traversal>(
0, XFA_Element::Traversal, false);
if (pTraversal) {
CXFA_Traverse* pTraverse =
pTraversal->GetChild<CXFA_Traverse>(0, XFA_Element::Traverse, false);
if (pTraverse) {
Optional<WideString> traverseWidgetName =
pTraverse->JSObject()->TryAttribute(XFA_Attribute::Ref, true);
if (traverseWidgetName)
return FindWidgetByName(*traverseWidgetName, pWidget);
}
}
return nullptr;
}
CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::FindWidgetByName(
const WideString& wsWidgetName,
CXFA_FFWidget* pRefWidget) {
return pRefWidget->GetDocView()->GetWidgetByName(wsWidgetName, pRefWidget);
}
void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() {
m_TabOrderWidgetArray.clear();
std::vector<CXFA_FFWidget*> SpaceOrderWidgetArray;
CreateSpaceOrderWidgetArray(&SpaceOrderWidgetArray);
if (SpaceOrderWidgetArray.empty())
return;
int32_t nWidgetCount = pdfium::CollectionSize<int32_t>(SpaceOrderWidgetArray);
CXFA_FFWidget* hWidget = SpaceOrderWidgetArray[0];
while (pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray) <
nWidgetCount) {
if (!pdfium::ContainsValue(m_TabOrderWidgetArray, hWidget)) {
m_TabOrderWidgetArray.push_back(hWidget);
CXFA_WidgetAcc* pWidgetAcc = hWidget->GetNode()->GetWidgetAcc();
if (pWidgetAcc->GetUIType() == XFA_Element::ExclGroup) {
auto it = std::find(SpaceOrderWidgetArray.begin(),
SpaceOrderWidgetArray.end(), hWidget);
int32_t iWidgetIndex = it != SpaceOrderWidgetArray.end()
? it - SpaceOrderWidgetArray.begin() + 1
: 0;
while (true) {
CXFA_FFWidget* radio =
SpaceOrderWidgetArray[iWidgetIndex % nWidgetCount];
if (radio->GetNode()->GetExclGroupIfExists() != pWidgetAcc->GetNode())
break;
if (!pdfium::ContainsValue(m_TabOrderWidgetArray, hWidget))
m_TabOrderWidgetArray.push_back(radio);
iWidgetIndex++;
}
}
if (CXFA_FFWidget* hTraverseWidget = GetTraverseWidget(hWidget)) {
hWidget = hTraverseWidget;
continue;
}
}
auto it = std::find(SpaceOrderWidgetArray.begin(),
SpaceOrderWidgetArray.end(), hWidget);
int32_t iWidgetIndex = it != SpaceOrderWidgetArray.end()
? it - SpaceOrderWidgetArray.begin() + 1
: 0;
hWidget = SpaceOrderWidgetArray[iWidgetIndex % nWidgetCount];
}
}
void CXFA_FFTabOrderPageWidgetIterator::OrderContainer(
CXFA_LayoutItemIterator* sIterator,
CXFA_LayoutItem* pContainerItem,
CXFA_TabParam* pContainer,
bool& bCurrentItem,
bool& bContentArea,
bool bMarsterPage) {
std::vector<std::unique_ptr<CXFA_TabParam>> tabParams;
CXFA_LayoutItem* pSearchItem = sIterator->MoveToNext();
while (pSearchItem) {
if (!pSearchItem->IsContentLayoutItem()) {
bContentArea = true;
pSearchItem = sIterator->MoveToNext();
continue;
}
if (bMarsterPage && bContentArea) {
break;
}
if (bMarsterPage || bContentArea) {
CXFA_FFWidget* hWidget = GetWidget(pSearchItem);
if (!hWidget) {
pSearchItem = sIterator->MoveToNext();
continue;
}
if (pContainerItem && (pSearchItem->GetParent() != pContainerItem)) {
bCurrentItem = true;
break;
}
tabParams.push_back(pdfium::MakeUnique<CXFA_TabParam>(hWidget));
if (IsLayoutElement(pSearchItem->GetFormNode()->GetElementType(), true)) {
OrderContainer(sIterator, pSearchItem, tabParams.back().get(),
bCurrentItem, bContentArea, bMarsterPage);
}
}
if (bCurrentItem) {
pSearchItem = sIterator->GetCurrent();
bCurrentItem = false;
} else {
pSearchItem = sIterator->MoveToNext();
}
}
std::sort(tabParams.begin(), tabParams.end(),
[](const std::unique_ptr<CXFA_TabParam>& arg1,
const std::unique_ptr<CXFA_TabParam>& arg2) {
const CFX_RectF& rt1 = arg1->GetWidget()->GetWidgetRect();
const CFX_RectF& rt2 = arg2->GetWidget()->GetWidgetRect();
if (rt1.top - rt2.top >= XFA_FLOAT_PERCISION)
return rt1.top < rt2.top;
return rt1.left < rt2.left;
});
for (const auto& pParam : tabParams)
pContainer->AppendTabParam(pParam.get());
}
void CXFA_FFTabOrderPageWidgetIterator::CreateSpaceOrderWidgetArray(
std::vector<CXFA_FFWidget*>* WidgetArray) {
CXFA_LayoutItemIterator sIterator(m_pPageView);
auto pParam = pdfium::MakeUnique<CXFA_TabParam>(nullptr);
bool bCurrentItem = false;
bool bContentArea = false;
OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea);
WidgetArray->insert(WidgetArray->end(), pParam->GetChildren().begin(),
pParam->GetChildren().end());
sIterator.Reset();
bCurrentItem = false;
bContentArea = false;
pParam->ClearChildren();
OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea,
true);
WidgetArray->insert(WidgetArray->end(), pParam->GetChildren().begin(),
pParam->GetChildren().end());
}
CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetWidget(
CXFA_LayoutItem* pLayoutItem) {
if (CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem)) {
if (!pWidget->IsLoaded() &&
(pWidget->GetStatus() & XFA_WidgetStatus_Visible)) {
pWidget->LoadWidget();
}
return pWidget;
}
return nullptr;
}
CXFA_TabParam::CXFA_TabParam(CXFA_FFWidget* pWidget) : m_pWidget(pWidget) {}
CXFA_TabParam::~CXFA_TabParam() {}
| [
"dongdong331@163.com"
] | dongdong331@163.com |
90d091d130cff14bd091453c7ab5ecad397a9d13 | ac1c4bdfdc7445b1bf88cf4811162febf48f127e | /Chapter4/strtype3.cpp | 74d33a1b59d744175fb5f96958bdce06bd747a69 | [] | no_license | Linuslan/C-Primer-Plus | 8da4f4625f906225be3b4c6f4de7f0579472b826 | 1edeafb2e5d2c6ff5e6982973210a4115ef393d2 | refs/heads/master | 2021-09-06T18:12:28.914879 | 2018-02-09T14:12:15 | 2018-02-09T14:12:15 | 103,092,128 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 558 | cpp | #include <iostream>
#include <string>
#include <cstring>
int main() {
using namespace std;
char charr1[20];
char charr2[20] = "jaguar";
string str1;
string str2 = {"panther"};
str1 = str2;
strcpy(charr1, charr2);
str1 += " paste";
strcat(charr1, " juice");
int len1 = str1.size();
int len2 = strlen(charr1);
cout << "The string " << str1 << " contains "
<< len1 << " characters." << endl;
cout << "The string " << charr1 << " contains "
<< len2 << " characters." << endl;
return 0;
}
| [
"linuslan@sina.cn"
] | linuslan@sina.cn |
d04fd11e07068b8473e3132ea507684373f16379 | ec6ca197b7a6c6ec1fba5ad4365aa5f99d5ebf8f | /libgearman/aggregator.cc | e5b2727ef2fe098d80df23804075ef43e46486a5 | [
"BSD-3-Clause"
] | permissive | gearman/gearmand | 65e6ad6fbd06cf53f623bf1ea1174555e3b1210d | 56761cd7c6119cbfde81033f3371a551055390a3 | refs/heads/master | 2023-09-03T20:30:00.118647 | 2023-08-18T15:22:06 | 2023-08-18T15:22:06 | 62,418,058 | 765 | 174 | NOASSERTION | 2023-08-18T15:22:08 | 2016-07-01T20:26:20 | C++ | UTF-8 | C++ | false | false | 2,008 | cc | /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* Gearmand client and server library.
*
* Copyright (C) 2011 Data Differential, http://datadifferential.com/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* * The names of its contributors may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "gear_config.h"
#include <libgearman/common.h>
#include "libgearman/assert.hpp"
#include <cstdlib>
#include <limits>
#include <memory>
#include <libgearman/aggregator.hpp>
void *gearman_aggegator_context(gearman_aggregator_st *self)
{
if (not self)
return NULL;
return self->context;
}
| [
"brian@tangent.org"
] | brian@tangent.org |
b803eb862f4ced5c63fa3cf8d17dd9a7d6b8e1d2 | 7b32a691b428b8b158825f5d9f9719c533d4fa3e | /NumberDifferentSubstrings.cpp | fa864abdfbe7c19a1f9e0947b2ecfbdf831fa958 | [] | no_license | drexxcbba/ITMOCOURSE_CP | c378403e8de4382f13e925a92a6a30ecd2e209db | 8f4311f22d6b39ceb905eb64bf4a812cac61ee1b | refs/heads/master | 2022-12-07T21:01:09.611062 | 2020-09-03T05:25:22 | 2020-09-03T05:25:22 | 290,088,092 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,990 | cpp | #include <bits/stdc++.h>
using namespace std;
void countSort(vector<int> &p, vector<int> &c){
int n = p.size();
vector<int> count (n);
for (auto x: c){
count[x]++;
}
vector<int> new_p (n);
vector<int> pos (n);
pos[0] = 0;
for(int i = 1; i < n; i++) pos[i] = pos[i - 1] + count[i - 1];
for(auto x: p){
int i = c[x];
new_p[pos[i]] = x;
pos[i]++;
}
p = new_p;
}
int main(){
string s;
cin>>s;
s += '$';
int n = s.size();
//This array will contain the ordering of the strings
vector<int> p (n);
//This array will contain their equivalences of the class string
vector<int> c (n);
{
//k = 0;
vector< pair<char, int> > a (n);
for (int i = 0; i < n; i++) a[i] = { s[i], i };
sort(a.begin(), a.end());
for(int i = 0; i < n; i++) p[i] = a[i].second;
c[p[0]] = 0;
for(int i = 1; i < n; i++){
if(a[i].first == a[i - 1].first){
c[p[i]] = c[p[i - 1]];
}else{
c[p[i]] = c[p[i - 1]] + 1;
}
}
}
int k = 0;
while((1 << k) < n){
//k -> k + 1
for(int i = 0; i < n; i++){
p[i] = (p[i] - (1 << k)+ n) % n;
}
//Radix
countSort(p , c);
vector<int> new_c (n);
new_c[p[0]] = 0;
for(int i = 1; i < n; i++){
pair<int, int> now = { c[p[i]], c[(p[i] + (1 << k)) % n] };
pair<int, int> prev = { c[p[i - 1]], c[(p[i - 1] + (1 << k)) % n] };
if(now == prev){
new_c[p[i]] = new_c[p[i - 1]];
}else{
new_c[p[i]] = new_c[p[i - 1]] + 1;
}
}
c = new_c;
k++;
}
vector<int> lcp (n);
int common = 0;
for (int i = 0; i < n - 1; i++){
int pi = c[i];
int j = p[pi - 1];
// Now find lcp[i] = lcp(s[i..], s[j..])
while(s[i + common] == s[j + common]) common++;
lcp[pi] = common;
common = max(common - 1, 0);
}
long long dif = 0;
for(int i = 1; i < n; i++){
long long aux = ((s.substr(p[i], n - p[i]).size()) - 1 - lcp[i]);
long long zero = 0;
dif += max(aux, zero);
}
cout<<dif<<endl;
return 0;
} | [
"villarroel24kyle@gmail.com"
] | villarroel24kyle@gmail.com |
6a77f8a90306ecc4caf802ec2693da7a4bc3acd5 | 8944ff60725282eea466ae6004a7e6021496a8f9 | /xmlobj/xml_lexer.h | 3a6fdf66b75454c8b11b45ead304949e9c3c5c32 | [
"MIT"
] | permissive | yikailee/xmlobj | e33e9bce61bff95dd1c30b77c2cf7a5ce7491477 | cc6ab6dbf1ddbe39bc5fdcd8d61e1c2ed2b3e2e5 | refs/heads/master | 2021-01-17T18:35:04.582671 | 2016-08-17T09:04:19 | 2016-08-17T09:04:19 | 65,794,005 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,400 | h | /*
* XML lexer and token define
* a Token object should have its text,
* and atts(reserve for start of node which has attributes).
* 1. Xml declaration should be a T_COMMENT token start with "<?" and end with "?>";
* 2. A line a comment is a T_PROCINST token start with "<!--" and end with "-->";
* 3. Start of node should be a T_NODE_START token start with "<" and end with ">",
* if end with "/>", will break down into two token, T_NODE_START and T_NODE_END
* 4. End of node should be a T_NODE_END token
* 5. between a start node and end node should be a T_STRING token if there is no
* sub node inside.
* 6. end of xml should be a T_EOF node.
*/
#pragma once
#include <string>
#include <unordered_map>
#include <stdint.h>
namespace xml
{
//----------------------------------------------------------------
enum TokenType {
T_UNKNOWN,
T_NODE_START, // </ or <
T_NODE_END, // > or />
T_COMMENT,
T_PROCINST, // <? xxxx ?>
T_STRING,
T_EOF
};
//----------------------------------------------------------------
struct Token {
// defalut is a T_UNKNOWN token
Token() : type(T_UNKNOWN) {}
// if a T_NODE_START or T_NODE_END, will be node name
// if T_STRING, will be this string value.
std::string text;
// if start of node, save node attributes.
std::unordered_map<std::string, std::string> attrs;
// token type of a node
TokenType type;
};
} // end namespace
| [
"admin@example.com"
] | admin@example.com |
457f7c83206ec3590aaa5d4011a2efdf885b1fd6 | 945e7bf2e9aef413082e32616b0db1d77f5e4c7e | /StereoViewer/IGlut.cpp | ffdc9768ac4924ef7283269208a12011cec2683f | [] | no_license | basarugur/bu-medialab | 90495e391eda11cdaddfedac241c76f4c8ff243d | 45eb9aebb375427f8e247878bc602eaa5aab8e87 | refs/heads/master | 2020-04-18T21:01:41.722022 | 2015-03-15T16:49:29 | 2015-03-15T16:49:29 | 32,266,742 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 22,184 | cpp | #include "common.h"
#include "IGlut.h"
#include "HeadTrackerClient.h"
#include "cv.h"
#include "wiimote.h"
#include "GL/glui.h"
#include <fstream>
#include <stdexcept>
#include "../SceneModeller_API/src/core/gfxobject.h"
#include "../SceneModeller_API/src/core/rectangle.h"
#include "../SceneModeller_API/src/core/cube.h"
#include "../SceneModeller_API/src/core/cylinder.h"
extern char wii_msg[255]; // to use in opengl context
HeadTrackerClient* IGlut::p_htc;
Scene* IGlut::p_scene = NULL;
Camera* IGlut::p_camera = NULL;
CanvasGrid* IGlut::p_grid;
RenderController* IGlut::p_rc;
Light* IGlut::p_light;
Shader* IGlut::p_shader;
GLUI* glui = NULL;
GLUI_FileBrowser* fb;
int IGlut::submenus[1];
GLuint IGlut::textures[1];
using namespace glut_env;
IGlut::IGlut(int argc, char** argv)
{
full_screen = false;
cm_win_width = 85;
cm_win_height = 64;
px_win_width = PX_WIN_WIDTH;
px_win_height = PX_WIN_HEIGHT;
cm_user_height = 70;
cm_user_to_screen_center = 70;
deg_user_yaw = 0.0;
K = 0.5;
last_x = 0;
last_y = 0;
Buttons[0] = 0;
Buttons[1] = 0;
Buttons[2] = 0;
delta_t = 1.f;
use_stereo_camera = false;
use_wiimote = false;
use_shaders = false;
online_mode = false;
half_eye_sep_x = 0.f;
half_eye_sep_y = 0.f;
p_htc = NULL;
/// Notice: VRML file should be taken as program argument.
//CreateScene("res/chapel_97-5.wrl");
CreateScene("res/boxes.wrl");
p_grid = new CanvasGrid( XY_GRID );
p_grid->setAxesDrawn(false);
p_shader = new Shader();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STEREO);
glutInitWindowSize(px_win_width, px_win_height);
glutInitWindowPosition((glutGet(GLUT_SCREEN_WIDTH) - px_win_width) * 0.5,
(glutGet(GLUT_SCREEN_HEIGHT) - px_win_height) * 0.5 );
glutCreateWindow("Stereo VRML Viewer | BoUn CmpE Medialab");
}
IGlut::~IGlut()
{
if (p_htc != NULL)
CloseHeadTracker();
disconnect_wiimote();
delete p_scene;
delete p_camera;
delete p_grid;
delete p_rc;
delete p_light;
delete p_shader;
}
void IGlut::Init()
{
glutDisplayFunc(Display);
glutTimerFunc(20, Timer, 0);
glutReshapeFunc(Reshape);
glutMouseFunc(Mouse);
glutKeyboardFunc(Keyboard);
glutMotionFunc(Motion);
PrepareMenus();
// glutFullScreen();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, gl_light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, gl_ambient_intensity);
glLightfv(GL_LIGHT0, GL_DIFFUSE, gl_light_intensity);
glLightfv(GL_LIGHT0, GL_SPECULAR, gl_light_intensity);
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glDepthFunc(GL_LEQUAL);
glCullFace(GL_BACK);
glEnable(GL_COLOR_MATERIAL);
glShadeModel(GL_FLAT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
InitTextures();
p_shader->setShaders();
glutMainLoop();
}
void IGlut::InitTextures()
{
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &textures[0]);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexImage2D( GL_TEXTURE_2D, 0, 4, PX_WIN_WIDTH, PX_WIN_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, frame_buf);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
}
void IGlut::PrepareMenus()
{
submenus[0] = glutCreateMenu( SelectOption );
glutAddMenuEntry("Toggle fullscreen view", 0);
glutAddMenuEntry("Use wiimote", 1);
glutAddMenuEntry("Render the scene", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
void IGlut::Motion(int x, int y)
{
if (Buttons[0])
{
UpdateUserPositionByMouse(x, y);
}
else if (Buttons[2])
{
// right click + y movement: affects z
p_camera->setPosition( Point3(p_camera->position().x(),
p_camera->position().y(),
cm_user_height + (y - px_win_width*0.5) * 2) );
// cout << cam_pos.z << endl;
}
glutPostRedisplay();
}
void IGlut::SelectOption(int opt)
{
glutSetMenu( -1 );
switch (opt)
{
case TOGGLE_FULLSCREEN:
full_screen = !full_screen;
if ( full_screen && glutGameModeGet(GLUT_GAME_MODE_ACTIVE) == 0 ) //argc > 2 && strcmp(argv[2], "f") == 0)
{
// Enter game mode:
char mode_string[100];
// DOUBLE SCREEN:
// sprintf(mode_string, "%dx%d:%d@%d", 1024, 1536, 32, 120);
// SINGLE SCREEN:
sprintf(mode_string, "%dx%d:%d@%d", 1024, 768, 32, 120);
cout << "GLUT-Game-Mode: " << mode_string << endl;
glutGameModeString( mode_string );
glutEnterGameMode();
// register callbacks again
Init();
}
else
{
glutLeaveGameMode();
}
break;
case TOGGLE_WIIMOTE:
use_wiimote = !use_wiimote;
glutChangeToMenuEntry(2, use_wiimote ? "Disconnect Wiimote" : "Use Wiimote", TOGGLE_WIIMOTE);
if (!use_wiimote)
disconnect_wiimote();
break;
case RENDER_SCENE:
if (p_rc == NULL)
p_rc = new RenderController();
/// We use asymmetric frustum for off-axis projection in OpenGL;
/// therefore we have to correct the camera direction for rendering:
Point3 save_lookAtPoint( p_camera->lookAtPoint() );
Vector3 save_upVector( p_camera->upVector() );
p_camera->setLookAtPoint( Point3(0, 0, 0) );
p_camera->setUpVector( Vector3(0, 0, 1) );
p_rc->render(p_scene, p_camera);
p_camera->setLookAtPoint( save_lookAtPoint );
p_camera->setUpVector( save_upVector );
break;
}
}
void IGlut::GLUIControl(int ui_item_id)
{
switch (ui_item_id)
{
case 1:
char fn[127] = "res/";
strcat( fn, fb->get_file() );
CreateScene( fn );
glui->close();
glutTimerFunc(20, Timer, 0);
break;
}
}
void IGlut::Keyboard(unsigned char key, int x, int y)
{
if (key == 'f' || key == 'F')
{
SelectOption( TOGGLE_FULLSCREEN );
}
else if (key == 'o' || key == 'O')
{
glui = GLUI_Master.create_glui("Open File..", 0);
GLUI_Panel *ep = new GLUI_Panel(glui, "", true);
fb = new GLUI_FileBrowser(ep, "", GLUI_PANEL_EMBOSSED, 1, GLUIControl);
new GLUI_Button(ep, "Open..", 2, GLUIControl);
fb->set_w( 320 );
fb->set_h( 240 );
fb->fbreaddir( "res/" );
int main_window = glui->get_glut_window_id();
glui->set_main_gfx_window(main_window);
}
else if (key == 'c' || key == 'C')
{
use_stereo_camera = !use_stereo_camera;
if (use_stereo_camera) // Reinitialize head:
{
if (p_htc == NULL)
InitHeadTracker();
}
else
CloseHeadTracker();
}
else if (key == 'd' || key == 'D')
{
// let maximum delta_t be 1.f
if ( (delta_t = delta_t + 0.1f) > 1.f )
delta_t = 0.1f;
}
else if (key == 'w' || key == 'W')
{
SelectOption( TOGGLE_WIIMOTE );
}
else if (key == 'z' || key == 'Z')
{
cout << "Height: " << p_camera->position().z() << endl;
}
else if (key == 'r' || key == 'R')
{
SelectOption( RENDER_SCENE );
}
/*else if (key == 'f' || key == 'F')
FogEffect(.01);*/
else if (key == 27)
exit(0);
switch (key)//************************************
{
case '1':
FogEffect(20.0);
break;
case '2':
FogEffect(40.0);
break;
case '3':
FogEffect(60.0);
break;
case '4':
FogEffect(80.0);
break;
case '5':
FogEffect(100.0);
break;
case '6':
FogEffect(120.0);
break;
case '7':
FogEffect(500.0);
break;
/*case 'r': // Toggle grid
case 'R':
showgrid = !showgrid;
break;*/
}
}
void IGlut::Mouse(int button, int state, int x, int y)
{
last_x = x;
last_y = y;
switch(button)
{
case GLUT_LEFT_BUTTON:
Buttons[0] = (int)(state == GLUT_DOWN);
UpdateUserPositionByMouse(x, y);
break;
case GLUT_MIDDLE_BUTTON:
Buttons[1] = (int)(state == GLUT_DOWN);
break;
case GLUT_RIGHT_BUTTON:
Buttons[2] = (int)(state == GLUT_DOWN);
//cam_pos.z = user_height + (y-px_win_width*0.5);
p_camera->position().setZ( cm_user_height + (y-px_win_width*0.5)*2 );
break;
default:
break;
}
glutPostRedisplay();
}
void IGlut::Reshape(int w, int h)
{
// prevent divide by 0 error when minimized
if (w==0)
h = 1;
px_win_width = w;
px_win_height = h;
/*glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,(float)w/h,0.1,100);
//glFrustum(-.20, .20, .1, .4, 0.15, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();*/
}
void IGlut::CreateScene(string VRMLfile)
{
/*GfxObject* new_obj1 = new GfxObject(new RectangleShape(),new Material(),new Transformation());
new_obj1->getMaterial()->enableTexture(true);
new_obj1->getMaterial()->getTexture().m_scale_x = 30 ;
new_obj1->getMaterial()->getTexture().m_scale_y = 30 ;
if (new_obj1->getShape()->type() == RECTANGLE)
{
RectangleShape* rct_ = static_cast<RectangleShape*>(new_obj1->getShape());
rct_->m_x = 100 ;
rct_->m_y = 100 ;
}
GfxObject* new_obj2 = new GfxObject(new Cube(),new Material(),new Transformation());
new_obj2->getLocalTransform()->scale(4,6,0.5);
new_obj2->getLocalTransform()->translate(4,0,6.5);
new_obj2->getMaterial()->setDiffColor(TRadiance(0,0.5,0));
GfxObject* new_obj3 = new GfxObject(new Cylinder(),new Material(),new Transformation());
GfxObject* new_obj4 = new GfxObject(new Cylinder(),new Material(),new Transformation());
GfxObject* new_obj5 = new GfxObject(new Cylinder(),new Material(),new Transformation());
GfxObject* new_obj6 = new GfxObject(new Cylinder(),new Material(),new Transformation());
new_obj3->getMaterial()->setDiffColor(TRadiance(1,0,0));
new_obj4->getMaterial()->setDiffColor(TRadiance(1,0,0));
new_obj5->getMaterial()->setDiffColor(TRadiance(1,0,0));
new_obj6->getMaterial()->setDiffColor(TRadiance(1,0,0));
// new_obj3->getLocalTransform()->scale(0.25, 0.16666, 2);
// new_obj3->getLocalTransform()->translate(0.25, 4/3, -13);
// new_obj4->getLocalTransform()->translate(1,-8,0);
// new_obj5->getLocalTransform()->translate(-5,-8,0);
// new_obj6->getLocalTransform()->translate(-5,8,0);
Cylinder* tmp_ = static_cast<Cylinder*>(new_obj3->getShape());
tmp_->m_h = 6 ;
tmp_->m_r = 1;
tmp_ = static_cast<Cylinder*>(new_obj4->getShape());
tmp_->m_h = 6 ;
tmp_->m_r = 1;
tmp_ = static_cast<Cylinder*>(new_obj5->getShape());
tmp_->m_h = 6 ;
tmp_->m_r = 1;
tmp_ = static_cast<Cylinder*>(new_obj6->getShape());
tmp_->m_h = 6 ;
tmp_->m_r = 1;
new_obj2->addChild(new_obj3);
new_obj2->addChild(new_obj4);
new_obj2->addChild(new_obj5);
new_obj2->addChild(new_obj6);
*p_scene += new_obj1;
*p_scene += new_obj2;
// *p_scene += new_obj3;
//*p_scene += new_obj4;
// *p_scene += new_obj5;
// *p_scene += new_obj6;
*/
if (p_scene != NULL)
{
delete p_scene;
delete p_camera;
}
p_scene = new Scene();
VrmlDevice vrml_dev;
vrml_dev.loadScene(VRMLfile, p_scene);
// Add GL lights to the Scene;
Point3 l_pos( gl_light_position[0], gl_light_position[2], gl_light_position[1] );
Vector3 l_dir( -gl_light_position[0], -gl_light_position[2], -gl_light_position[1] );
p_light = new PointLight( l_pos, l_dir );
if ( p_scene->lights().empty() )
p_scene->lights().push_back( p_light );
else
p_scene->lights()[0] = p_light;
cout << "OBJS:" << p_scene->objects().size() << endl;
for (int i = 0; i<p_scene->objects().size(); i++)
{
GfxObject* gobj = p_scene->objects()[i];
cout << "CN: " << gobj->getChildList().size() << endl;
}
/// skip this part;
/*if (p_scene->cameras().size() != 0)
{
// blender setup
p_camera = p_scene->cameras()[0];
cout << "CFR: " << p_camera->position().x() << " * " << p_camera->position().y() << " * " << p_camera->position().z() << endl;
cout << "CTO: " << p_camera->lookAtPoint().x() << " * " << p_camera->lookAtPoint().y() << " * " << p_camera->lookAtPoint().z() << endl;
cout << "CUP: " << p_camera->upVector().x() << " * " << p_camera->upVector().y() << " * " << p_camera->upVector().z() << endl;
cout << "OBJ::" << p_scene->objects()[0]->getName() << endl;
}
else
{
p_camera = new Camera();
// serhat's setup:
p_camera->setPosition(Point3(30,30,10));
p_camera->setLookAtPoint(Point3(0,0,0));
p_camera->setUpVector(Vector3(-0.5,-0.5,6).normalize());
// basar's manual setup: for chapel.wrl
//p_camera->setPosition( Point3(0, 5, 5) );
//p_camera->setLookAtPoint( Point3(0, 0, 0) );
//p_camera->setUpVector( Vector3(0, 1, 0).normalize() );
}*/
p_camera = new Camera( Point3(0, -cm_user_to_screen_center, cm_user_height) );
// vrml_dev.saveToFile("output.wrl", p_scene);
}
void IGlut::Timer(int timer_id)
{
if (use_wiimote)
update_scene_by_wiimote( p_scene, last_x, last_y );
if (use_stereo_camera && p_htc != NULL)
{
try
{
if ( online_mode ) // network client mode
p_htc->read_online();
else
p_htc->read_offline();
UpdateUserPositionByTracking();
}
catch (runtime_error e)
{
cout << e.what() << endl;
CloseHeadTracker();
return;
}
}
if ( glutGetWindow() == 1 )
{
glutPostRedisplay(); // triggers a display event
glutSwapBuffers();
}
else
glutSetWindow( 1 );
glutTimerFunc(20, Timer, 0);
}
void IGlut::Display(void)
{
//usleep(25000);
glDrawBuffer(GL_BACK_LEFT);
if (use_shaders)
{
glReadBuffer(GL_BACK_LEFT);
DrawToOneBuffer(half_eye_sep_x, half_eye_sep_y, 1, 2, true);
DrawTextureWithShader(half_eye_sep_x, half_eye_sep_y);
DrawToOneBuffer(half_eye_sep_x, half_eye_sep_y, 0.1, 1, false);
}
else
DrawToOneBuffer(half_eye_sep_x, half_eye_sep_y, 0.1, 2, true);
/*GLenum e;
while ( (e=glGetError()) != GL_NO_ERROR )
cout << "Error " << e << endl;*/
glDrawBuffer(GL_BACK_RIGHT);
if (use_shaders)
{
glReadBuffer(GL_BACK_RIGHT);
DrawToOneBuffer(-half_eye_sep_x, -half_eye_sep_y, 1, 2, true);
DrawTextureWithShader(-half_eye_sep_x, -half_eye_sep_y);
DrawToOneBuffer(-half_eye_sep_x, -half_eye_sep_y, 0.1, 1, false);
}
else
DrawToOneBuffer(-half_eye_sep_x, -half_eye_sep_y, 0.1, 2, true);
}
void IGlut::CopyFrameBufferToTexture()
{
/// Get a copy of framebuffer to texture0
glActiveTexture( GL_TEXTURE0 );
glBindTexture(GL_TEXTURE_2D, textures[0]);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, px_win_width, px_win_height);
glBindTexture(GL_TEXTURE_2D, 0);
}
void IGlut::DrawTextureWithShader(float cm_camera_tilt_x, float cm_camera_tilt_y)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram( p_shader->sh_prog[BLUR] );
/// Prepare orthographic 2D projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, px_win_width, 0, px_win_height, 0, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
/// Use texture0 with the last frame buffer
glActiveTexture( GL_TEXTURE0 );
glBindTexture(GL_TEXTURE_2D, textures[0]);
/// Parameter for translating orthographic coordinates to perspective projection
float o2p = 5.f;
glTranslatef(cm_camera_tilt_x * o2p, cm_camera_tilt_y * o2p, 0.f);
glNormal3f(0.f, 0.f, 1.f);
glBegin(GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0, 0, 0); glVertex2f( 0.f, 0.f );
glMultiTexCoord2f(GL_TEXTURE0, 1, 0); glVertex2f( px_win_width, 0.f );
glMultiTexCoord2f(GL_TEXTURE0, 1, 1); glVertex2f( px_win_width, px_win_height );
glMultiTexCoord2f(GL_TEXTURE0, 0, 1); glVertex2f( 0.f, px_win_height );
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glPopMatrix();
}
float z_h = 16;
void IGlut::DrawToOneBuffer(float cm_camera_tilt_x, float cm_camera_tilt_y,
float frustum_z_start, float frustum_z_end,
bool first_pass)
{
if (first_pass)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram( p_shader->sh_prog[SAME] );
/** Here, t is used as both the frustum z direction start (= near clipping),
* and scaling parameter for x and y directions
* frustum z direction end is "far clipping" parameter
*/
float frusLeft, frusRight, frusBottom, frusTop, frusNear, frusFar,
t = frustum_z_start;
/* glViewport(0, win_h/2, win_w, win_h/2);
glScissor(0, win_h/2, win_w, win_h/2); */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
frusLeft = ( - p_camera->position().x()
- cm_win_width * .5
- cm_camera_tilt_x ) * t;
frusRight = (- p_camera->position().x()
+ cm_win_width * .5
- cm_camera_tilt_x ) * t;
frusBottom = (- p_camera->position().y()
- cm_win_height * .5
- cm_camera_tilt_y ) * t;
frusTop = ( - p_camera->position().y()
+ cm_win_height * .5
- cm_camera_tilt_y ) * t;
/*
frusBottom = (-(cam_pos.z-cm_win_height * .5) - cm_win_height * .5) * 0.1;
frusTop = (-(cam_pos.z-cm_win_height * .5) + cm_win_height * .5) * 0.1;
*/
frusNear = p_camera->position().z() * frustum_z_start;
frusFar = p_camera->position().z() * frustum_z_end;
/// Define the frustum
glFrustum( frusLeft, frusRight, frusBottom, frusTop, frusNear, frusFar);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
((PointLight*)p_scene->lights()[0])->position() =
Point3(gl_light_position[0],
gl_light_position[2],
gl_light_position[1]);
// Assign camera values for gluLookAt
Point3 glEyePos(p_camera->position().x() + cm_camera_tilt_x,
p_camera->position().y() + cm_camera_tilt_y,
p_camera->position().z() );
Point3 glCenterPos(p_camera->position().x() + cm_camera_tilt_x,
p_camera->position().y() + cm_camera_tilt_y,
0.0);
Vector3 glUpVector(0, 1, 0);
p_camera->setPosition( glEyePos );
p_camera->setLookAtPoint( glCenterPos );
p_camera->setUpVector( glUpVector );
glTranslatef(0, 0, -z_h);
p_scene->draw(p_camera, NULL, SHADED);
/// Display Wiimote text message if exists
glColor3f(0.0f, 1.0f, 0.0f);
renderString(-cm_win_width * 0.5 + 5, -cm_win_height * 0.5 + 5, 0, wii_msg);
glPopMatrix();
if (use_shaders && first_pass)
CopyFrameBufferToTexture();
}
void IGlut::UpdateUserPositionByMouse(int mouse_x, int mouse_y)
{
float user_vector_x = mouse_x - px_win_width* 0.5,
user_vector_y = px_win_height* 0.5 - mouse_y;
deg_user_yaw = atan2( user_vector_y, user_vector_x );
p_camera->setPosition( Point3( user_vector_x * PX_2_CM, // cm_user_to_screen_center * cos(deg_user_yaw);
user_vector_y * PX_2_CM, // cm_user_to_screen_center * sin(deg_user_yaw);
cm_user_height + z_h ) );
half_eye_sep_x = HALF_EYE_SEP_CM * -sin(deg_user_yaw);
half_eye_sep_y = HALF_EYE_SEP_CM * cos(deg_user_yaw);
// cout << cam_pos.z << endl;
}
void IGlut::UpdateUserPositionByTracking()
{
deg_user_yaw = atan2( p_htc->lookVector->y, p_htc->lookVector->x );
/**
* DO NOT ASSIGN NEW VALUES DIRECTLY
* add the difference with a delta
*/
//cam_pos.x += ( p_htc->headPosition->x - cam_pos.x ) * delta_t;
//cout << p_htc->lookVector->x() << ", " << p_htc->lookVector->y() << endl;
/// constant x;
// p_camera->position().setX( -80 );
p_camera->position().setX( p_camera->position().x() +
( p_htc->headPosition->x - p_camera->position().x() ) * delta_t );
p_camera->position().setY( p_camera->position().y() +
( p_htc->headPosition->y - p_camera->position().y() ) * delta_t );
//cam_pos.z += ( p_htc->headPosition->z - cam_pos.z ) * delta_t;
half_eye_sep_x = HALF_EYE_SEP_CM * sin(deg_user_yaw);
half_eye_sep_y = HALF_EYE_SEP_CM * -cos(deg_user_yaw);
//cout << cam_pos.z << endl;
}
void IGlut::FogEffect(float fogkey)
{
int fogMode[] = {GL_EXP, GL_EXP2, GL_LINEAR};
int fogfilter = 2;
float fogColor[4] = {0.0f, 0.0f, 0.0f, 1.f};
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, fogMode[fogfilter]);
glFogfv(GL_FOG_COLOR, fogColor);
//glFogf(GL_FOG_COORD_SRC, GL_FOG_COORD);
glFogf(GL_FOG_DENSITY, .1f);
glFogf(GL_FOG_START, p_camera->position().z()-140);//cam_pos[2]
glFogf(GL_FOG_END, p_camera->position().z() + fogkey);//* 2 - 8000);
glHint(GL_FOG_HINT,GL_FASTEST);
}
void IGlut::InitHeadTracker()
{
try
{
p_htc = new HeadTrackerClient(SERVER_IP, online_mode);
}
catch (runtime_error e)
{
cout << e.what() << endl;
p_htc = NULL;
}
}
void IGlut::CloseHeadTracker()
{
use_stereo_camera = false;
delete p_htc;
p_htc = NULL;
}
| [
"basarugur@19b6b63a-0a50-11de-97d8-e990b0f60ea0"
] | basarugur@19b6b63a-0a50-11de-97d8-e990b0f60ea0 |
374618ec44e22dd44ab5decd0cd8e99c29330904 | bc163b3de90994860566a6ce2355c9d36b2b4604 | /MyApplication_17/TouchGFX/generated/images/src/miniDOWN.cpp | b48bd11a8171de52cdfe39d3cd1e3ff0badf8e08 | [] | no_license | mfkiwl/CoolSmif | 6831a89c5470bd37907672f71927d8f0da618e63 | 0db24b78d9f55a53fd61007aa05246dee4ad14b5 | refs/heads/master | 2023-03-19T07:33:19.147816 | 2020-06-04T12:50:32 | 2020-06-04T12:50:32 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 99,002 | cpp | // 4.13.0 dither_algorithm=2 alpha_dither=yes layout_rotation=0 opaque_image_format=RGB888 non_opaque_image_format=ARGB8888 section=ExtFlashSection extra_section=ExtFlashSection generate_png=no 0x90414c59
// Generated by imageconverter. Please, do not edit!
#include <touchgfx/hal/Config.hpp>
LOCATION_PRAGMA("ExtFlashSection")
KEEP extern const unsigned char _minidown[] LOCATION_ATTRIBUTE("ExtFlashSection") = // 98x55 RGB888 pixels.
{
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x04, 0x02, 0xfa,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x4e, 0x4e, 0xff, 0x6c, 0x6c, 0xff, 0x69, 0x69, 0xff, 0x69, 0x69, 0xff, 0x68, 0x68, 0xff, 0x51, 0x51, 0xff, 0x15, 0x15, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x5b, 0x5b, 0xff, 0x9a, 0x9a, 0xff, 0xac, 0xac, 0xff, 0x9f, 0x9f, 0xff, 0x6f, 0x6f, 0xff, 0x11, 0x11, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x14, 0x14, 0xff, 0x80, 0x80, 0xff, 0x80, 0x80, 0xff, 0x18, 0x18, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x4c, 0x4c, 0xff, 0x7f, 0x7f, 0xff, 0x6f, 0x6f, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x71, 0x71, 0xff, 0x83, 0x83, 0xff, 0x27, 0x27, 0xff, 0x00, 0x00, 0xff,
0x15, 0x15, 0xff, 0x71, 0x71, 0xff, 0x6f, 0x6f, 0xff, 0x38, 0x38, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x0b, 0x0b, 0xff, 0x7a, 0x7a, 0xff, 0x6d, 0x6d, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xea, 0xea, 0xff, 0x33, 0x33, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x4a, 0x4a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa2, 0xa2, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x34, 0x34, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x95, 0x95, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x28, 0x28, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x21, 0x21, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x5a, 0x5a, 0xff, 0x00, 0x00, 0xff,
0xc0, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x41, 0x41, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x54, 0x54, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe1, 0xe1, 0xff, 0xa1, 0xa1, 0xff, 0xab, 0xab, 0xff, 0xe3, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x51, 0x51, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x39, 0x39, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xad, 0xad, 0xff, 0x80, 0x80, 0xff, 0xa0, 0xa0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x95, 0x95, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x28, 0x28, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7c, 0x7c, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x69, 0x69, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xb9, 0xb9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xfb, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x4c, 0x4c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa0, 0xa0, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x3c, 0x3c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x18, 0x18, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x04, 0x04, 0xff, 0x00, 0x00, 0xff, 0xc5, 0xc5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x76, 0x76, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xce, 0xce, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xb5, 0xb5, 0xff, 0xff, 0xff, 0xff, 0xe6, 0xe6, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xb8, 0xb8, 0xff, 0xff, 0xff, 0xff, 0xeb, 0xeb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x60, 0x60, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x4c, 0x4c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa8, 0xa8, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x6e, 0x6e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7b, 0x7b, 0xff, 0x00, 0x00, 0xff, 0x42, 0x42, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x83, 0x83, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x70, 0x70, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x65, 0x65, 0xff, 0x00, 0x00, 0xff, 0x6e, 0x6e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x34, 0x34, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xc6, 0xc6, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x90, 0x90, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xb8, 0xb8, 0xff, 0xff, 0xff, 0xff, 0x96, 0x96, 0xff, 0xea, 0xea, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x4c, 0x4c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa8, 0xa8, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xbf, 0xff, 0x00, 0x00, 0xff, 0x89, 0x89, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x2c, 0x2c, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x22, 0x22, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9d, 0x9d, 0xff, 0x00, 0x00, 0xff, 0x16, 0x16, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x7f, 0x7f, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x75, 0x75, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x2c, 0x2c, 0xff, 0x00, 0x00, 0xff, 0x08, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x39, 0x39, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xb8, 0xb8, 0xff, 0xff, 0xff, 0xff, 0xae, 0xae, 0xff, 0x4d, 0x4d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7c, 0x7c, 0xff, 0x00, 0x00, 0xff, 0x4c, 0x4c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa8, 0xa8, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdc, 0xdc, 0xff, 0x00, 0x00, 0xff, 0xa5, 0xa5, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x05, 0x05, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x0c, 0x0c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb0, 0xb0, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xcd, 0xcd, 0xff, 0x00, 0x00, 0xff, 0x24, 0x24, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x80, 0xff, 0x00, 0x00, 0xff, 0x52, 0x52, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xb8, 0xb8, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xbf, 0xff, 0x00, 0x00, 0xff, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x4a, 0x4a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa8, 0xa8, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd9, 0xd9, 0xff, 0x00, 0x00, 0xff, 0xae, 0xae, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x05, 0x05, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x0b, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa9, 0xa9, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xb0, 0xb0, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x6f, 0x6f, 0xff, 0xff, 0xff, 0xff, 0xd9, 0xd9, 0xff, 0x00, 0x00, 0xff, 0xd7, 0xd7, 0xff, 0xff, 0xff, 0xff, 0xcd, 0xcd, 0xff, 0x00, 0x00, 0xff, 0xa2, 0xa2, 0xff, 0xff, 0xff, 0xff, 0xd2, 0xd2, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xb8, 0xb8, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xbf, 0xff, 0x00, 0x00, 0xff, 0x4c, 0x4c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0x87, 0xff, 0x36, 0x36, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa8, 0xa8, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb2, 0xb2, 0xff, 0x00, 0x00, 0xff, 0x9c, 0x9c, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x28, 0x28, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x2a, 0x2a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8e, 0x8e, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x5a, 0x5a, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x04, 0x04, 0xff, 0xb8, 0xb8, 0xff, 0xff, 0xff, 0xff, 0x8d, 0x8d, 0xff, 0x00, 0x00, 0xff, 0x86, 0x86, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xe9, 0xe9, 0xff, 0xff, 0xff, 0xff, 0x79, 0x79, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xb8, 0xb8, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xbf, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xec, 0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa8, 0xa8, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x75, 0x75, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6c, 0x6c, 0xff, 0x00, 0x00, 0xff, 0x66, 0x66, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x73, 0x73, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x85, 0x85, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x40, 0x40, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x05, 0x05, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x53, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3a, 0x3a, 0xff, 0x00, 0x00, 0xff, 0x2f, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x25, 0x25, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x24, 0x24, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xb8, 0xb8, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xbf, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x31, 0x31, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xca, 0xca, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa0, 0xa0, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x38, 0x38, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x05, 0x05, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x0e, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xf0, 0xf0, 0xff,
0xff, 0xff, 0xff, 0xdb, 0xdb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc5, 0xc5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xb8, 0xb8, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xbf, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xd2, 0xd2, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xdf, 0xff, 0x9c, 0x9c, 0xff, 0xaf, 0xaf, 0xff, 0xe9, 0xe9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x43, 0x43, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9d, 0x9d, 0xff, 0x79, 0x79, 0xff, 0xa7, 0xa7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x42, 0x42, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x9b, 0x9b, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0xe3, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xcf, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xba, 0xba, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xb8, 0xb8, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xbf, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x1b, 0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xee, 0xee, 0xff, 0x2d, 0x2d, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0xab, 0xab, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x51, 0x51, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x49, 0x49, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9a, 0x9a, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x7a, 0x7a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x67, 0x67, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0xc5, 0xc5, 0xff, 0xff, 0xff, 0xff, 0xcd, 0xcd, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xb3, 0xb3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x51, 0x51, 0xff, 0x6c, 0x6c, 0xff, 0x69, 0x69, 0xff, 0x69, 0x69, 0xff, 0x6a, 0x6a, 0xff, 0x4e, 0x4e, 0xff, 0x0e, 0x0e, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x14, 0x14, 0xff, 0x74, 0x74, 0xff, 0xa5, 0xa5, 0xff, 0xb3, 0xb3, 0xff, 0xa0, 0xa0, 0xff, 0x5f, 0x5f, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x71, 0x71, 0xff, 0x7d, 0x7d, 0xff, 0x7b, 0x7b, 0xff, 0x09, 0x09, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x02, 0x02, 0xff, 0x78, 0x78, 0xff, 0x7d, 0x7d, 0xff, 0x75, 0x75, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x3e, 0x3e, 0xff, 0x87, 0x87, 0xff, 0x40, 0x40, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x67, 0x67, 0xff, 0x74, 0x74, 0xff, 0x48, 0x48, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff
};
| [
"coolab.strousset@gmail.com"
] | coolab.strousset@gmail.com |
edd401d32889e3862267797b16e95a837164fe51 | 547a31c6d098df866be58befd8642ab773b32226 | /vc/DataLogger/PDFLib/except.cpp | 27cc6a57375c6a083714494715dce488274d5291 | [] | no_license | neirons/pythondatalogger | 64634d97eaa724a04707e4837dced51bcf750146 | f1cd1aea4d63407c3d4156ddccd02339dc96dcec | refs/heads/master | 2020-05-17T07:48:33.707106 | 2010-08-08T13:37:33 | 2010-08-08T13:37:33 | 41,642,510 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,555 | cpp | /*---------------------------------------------------------------------------*
| PDFlib - A library for generating PDF on the fly |
+---------------------------------------------------------------------------+
| Copyright (c) 1997-2002 PDFlib GmbH and Thomas Merz. All rights reserved. |
+---------------------------------------------------------------------------+
| This software is NOT in the public domain. It can be used under two |
| substantially different licensing terms: |
| |
| The commercial license is available for a fee, and allows you to |
| - ship a commercial product based on PDFlib |
| - implement commercial Web services with PDFlib |
| - distribute (free or commercial) software when the source code is |
| not made available |
| Details can be found in the file PDFlib-license.pdf. |
| |
| The "Aladdin Free Public License" doesn't require any license fee, |
| and allows you to |
| - develop and distribute PDFlib-based software for which the complete |
| source code is made available |
| - redistribute PDFlib non-commercially under certain conditions |
| - redistribute PDFlib on digital media for a fee if the complete |
| contents of the media are freely redistributable |
| Details can be found in the file aladdin-license.pdf. |
| |
| These conditions extend to ports to other programming languages. |
| PDFlib is distributed with no warranty of any kind. Commercial users, |
| however, will receive warranty and support statements in writing. |
*---------------------------------------------------------------------------*/
/* $Id: except.c,v 1.1.2.6 2002/01/07 18:26:29 tm Exp $ */
#include "stdafx.h"
#include <string.h>
#include "pdflib.h"
#include "except.h"
void pdf_cpp_errorhandler(PDF *p, int type, const char *msg)
{
pdf_err_info *ei = (pdf_err_info *) PDF_get_opaque(p);
ei->type = type;
strcpy(ei->msg, msg);
longjmp(ei->jbuf, 1);
}
| [
"shixiaoping79@5c1c4db6-e7b1-408c-73c2-e61316242a6a"
] | shixiaoping79@5c1c4db6-e7b1-408c-73c2-e61316242a6a |
fe99ee52f6bf18aa43bce9f1bfe7d6dfdacdf8b8 | c8a08848741a8827ea54cc34e48d16697734e2bf | /Beach/Road/main.cpp | f98f700f31862a8bf984d632f22d447f4948b564 | [] | no_license | aaryasharma2/robomanipal | 49b31cfc19ce23823f64f76f6287512d7fd80109 | b50ec51ed2de5ae3b1e72f187fc8f51029db34f2 | refs/heads/master | 2023-02-21T23:06:22.792732 | 2019-07-31T16:59:21 | 2019-07-31T16:59:21 | 154,561,378 | 1 | 0 | null | 2023-02-09T07:30:02 | 2018-10-24T19:58:19 | C++ | UTF-8 | C++ | false | false | 35,041 | cpp | #include <windows.h>
#include<GL/gl.h>
#include<GL/glut.h>
#include<math.h>
#define PI 3.141592653589793238
float add_r,add_g,add_b;
void circle(float x_value,float y_value, float radious_value)
{
float x =x_value;
float y =y_value;
float radious = radious_value;
float twicePI = 2.0f*PI;
int racmax=50;
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x,y);
for(int i=0; i<=racmax; i++)
{
glVertex2f(
x+(radious*cos(i*twicePI/racmax)),
y+(radious*sin(i*twicePI/racmax))
);
}
glEnd();
}
//////Sun & Moon//////////
float sun_y_position =80;
float moon_y_position=400;
float sun_color_g=1.0;
bool night = false;
bool evening=false;
void Sun()
{
float x =680;
float y = 300;
float radious = 100;
float twicePI = 2.0f*PI;
int racmax=50;
glBegin(GL_TRIANGLE_FAN);
glColor3f(1.0f,sun_color_g,0.0f);
glVertex2f(x,y);
for(int i=0; i<=racmax; i++)
{
glVertex2f(
x+(radious*cos(i*twicePI/racmax)),
y+(radious*sin(i*twicePI/racmax))
);
}
glEnd();
}
void Moon()
{
float x =680;
float y = 300;
float radious = 100;
float twicePI = 2.0f*PI;
int racmax=50;
glBegin(GL_TRIANGLE_FAN);
glColor3f(1.0f,1.0f,1.0f);
glVertex2f(x,y);
for(int i=0; i<=racmax; i++)
{
glVertex2f(
x+(radious*cos(i*twicePI/racmax)),
y+(radious*sin(i*twicePI/racmax))
);
}
glEnd();
}
/////////Sky///////////
float sky_r=0.3019,sky_g=0.9568,sky_b=1.0;
void Sky()
{
glBegin(GL_QUADS);
if(night==true)
glColor3f(0.282353,0.282353,0.941176);
else
glColor3f(sky_r,sky_g,sky_b);
glVertex2f(0,50);
if(night==true)
glColor3f(0.282353,0.282353,0.941176);
else
glColor3f(sky_r,sky_g,sky_b);
glVertex2f(1900,50);
if (evening==true)
glColor3f(0.980392,0.627451,0.137255);
else
glColor3f(sky_r,sky_g,sky_b);
glVertex2f(1900,528);
if (evening==true)
glColor3f(0.980392,0.627451,0.137255);
else
glColor3f(sky_r,sky_g,sky_b);
glVertex2f(0,528);
glEnd();
}
///////////////////////////
////////Clouds/////////////
float Cloud_1_x_pos=0;
void Cloud_1()
{
if(evening)
glColor3f(1,0.843137,0.568627);
else if(night)
glColor3f(0.509804,0.564706,0.619608);
else
glColor3f(1,1,1);
circle(200,200,40);
circle(210,209,40);
circle(230,200,40);
circle(220,190,40);
circle(250,230,40);
circle(260,180,40);
circle(220,200,40);
circle(190,195,40);
circle(280,200,40);
circle(300,197,40);
}
float Cloud_1cpy_x_pos=0;
void Cloud_1cpy()
{
if(evening)
glColor3f(1,0.843137,0.568627);
else if(night)
glColor3f(0.509804,0.564706,0.619608);
else
glColor3f(1,1,1);
circle(200,400,40);
circle(210,409,40);
circle(230,400,40);
circle(220,390,40);
circle(250,430,40);
circle(260,380,40);
circle(220,400,40);
circle(190,395,40);
circle(280,400,40);
circle(300,397,40);
}
float Cloud_2_x_pos =0;
void Cloud_2()
{
if(evening)
glColor3f(1,0.843137,0.568627);
else if(night)
glColor3f(0.509804,0.564706,0.619608);
else
glColor3f(1,1,1);
circle(400,300,40);
circle(410,309,40);
circle(430,300,40);
circle(420,290,40);
circle(450,330,40);
circle(460,280,40);
circle(420,300,40);
circle(390,295,40);
circle(480,300,40);
circle(500,297,40);
circle(380,300,40);
circle(520,300,40);
circle(515,310,40);
circle(530,295,40);
circle(360,310,40);
circle(550,300,40);
circle(581,315,40);
}
float Cloud_3_x_pos=0;
void Cloud_3()
{
if(evening)
glColor3f(1,0.843137,0.568627);
else if(night)
glColor3f(0.509804,0.564706,0.619608);
else
glColor3f(1,1,1);
circle(100,430,40);
circle(110,439,40);
circle(130,420,40);
circle(120,420,40);
circle(150,460,40);
circle(160,410,40);
circle(120,430,40);
circle(90,425,40);
circle(180,420,40);
circle(200,407,40);
circle(80,420,40);
circle(220,430,40);
circle(215,440,40);
circle(230,405,40);
circle(60,450,40);
circle(250,430,40);
circle(281,425,40);
circle(70,430,40);
}
void cloud_movement_timer(int)
{
glutTimerFunc(1000/90,cloud_movement_timer,0);
if(Cloud_1_x_pos<1600)
{
Cloud_1_x_pos+=0.6;///cloud_1speed
}
else if (Cloud_1_x_pos>=1600)
{
Cloud_1_x_pos=(0);
}
if (Cloud_1cpy_x_pos<1600)
Cloud_1cpy_x_pos+=0.8;///speed
else if(Cloud_1cpy_x_pos>=1600)
Cloud_1cpy_x_pos=0;
if (Cloud_2_x_pos<1600)
Cloud_2_x_pos+=0.3;///speed
else if (Cloud_2_x_pos>=1600)
Cloud_2_x_pos=-100;
if(Cloud_3_x_pos<1600)
Cloud_3_x_pos+=0.25;///speed
else if(Cloud_3_x_pos>=1600)
Cloud_3_x_pos=0;
glutPostRedisplay();
}
///////////////////////////
///////Buildings///////////
void Building_1()
{
glColor3f(0.054902,0.105882,0.141176);
glBegin(GL_POLYGON);
glVertex2f(435,528);
glVertex2f(450,528);
glVertex2f(450,-150);
glVertex2f(435,-150);
glEnd();
glColor3f(0.627451+add_r,0.921569+add_g,0.980392+add_b);
glBegin(GL_POLYGON);
glVertex2f(365,528);
glVertex2f(390,528);
glVertex2f(390,500);
glVertex2f(365,500);
glEnd();
float glass_y=45;
for(int i = 0; i<14; i++)
{
if(night==true &&(i==1||i==3||i==4||i==5||i==10))
glColor3f(0.984314,1,0);
else
glColor3f(0.627451+add_r,0.921569+add_g,0.980392+add_b);
glBegin(GL_POLYGON);
glVertex2f(365,528-glass_y);
glVertex2f(390,528-glass_y);
glVertex2f(390,500-glass_y);
glVertex2f(365,500-glass_y);
glEnd();
glass_y+=45;
}
glColor3f(0.2+add_r,0.054902+add_g,0.145098+add_b);
glBegin(GL_POLYGON);
glVertex2f(355,528);
glVertex2f(400,528);
glVertex2f(400,-150);
glVertex2f(355,-150);
glEnd();
glColor3f(0.054902+add_r,0.105882+add_g,0.141176+add_b);
glBegin(GL_POLYGON);
glVertex2f(305,528);
glVertex2f(355,528);
glVertex2f(355,-150);
glVertex2f(305,-150);
glEnd();
glColor3f(0.631373+add_r,0.486275+add_g,0.384314+add_b);
glBegin(GL_POLYGON);
glVertex2f(205,528);
glVertex2f(305,528);
glVertex2f(305,450);
glVertex2f(205,450);
glEnd();
glColor3f(0.054902+add_r,0.105882+add_g,0.141176+add_b);
glBegin(GL_POLYGON);
glVertex2f(195,528);
glVertex2f(205,528);
glVertex2f(205,-150);
glVertex2f(195,-150);
glEnd();
glColor3f(0.054902+add_r,0.105882+add_g,0.141176+add_b);
glBegin(GL_POLYGON);
glVertex2f(155,528);
glVertex2f(195,528);
glVertex2f(195,508);
glVertex2f(155,508);
glEnd();
float yx = 40;
for (int i = 0; i<16; i++)
{
glBegin(GL_POLYGON);
glVertex2f(155,528-yx);
glVertex2f(195,528-yx);
glVertex2f(195,508-yx);
glVertex2f(155,508-yx);
glEnd();
yx=yx+40;
}
glColor3f(0.631373+add_r,0.486275+add_g,0.384314+add_b);
glBegin(GL_POLYGON);
glVertex2f(110,528);
glVertex2f(150,528);
glVertex2f(150,450);
glVertex2f(110,450);
glEnd();
glColor3f(0.054902+add_r,0.105882+add_g,0.141176+add_b);
glBegin(GL_POLYGON);
glVertex2f(90,528);
glVertex2f(105,528);
glVertex2f(105,-150);
glVertex2f(90,-150);
glEnd();
glColor3f(0.631373+add_r,0.486275+add_g,0.384314+add_b);
glBegin(GL_POLYGON);
glVertex2f(22,528);
glVertex2f(85,528);
glVertex2f(85,450);
glVertex2f(22,450);
glEnd();
glColor3f(0.631373+add_r,0.486275+add_g,0.384314+add_b);
glBegin(GL_POLYGON);
glVertex2f(0,528);
glVertex2f(20,528);
glVertex2f(20,-150);
glVertex2f(0,-150);
glEnd();
glColor3f(0.929412+add_r,0.611765+add_g,0.380392+add_b);
glBegin(GL_POLYGON);
glVertex2f(0,528);
glVertex2f(450,528);
glVertex2f(450,-150);
glVertex2f(0,-150);
glEnd();
}
void Building_2()
{
glColor3f(0.627451+add_r,0.921569+add_g,0.980392+add_b);
glBegin(GL_POLYGON);
glVertex2f(460,330);
glVertex2f(528,330);
glVertex2f(528,280);
glVertex2f(460,280);
glEnd();
glPushMatrix();
float glass_y=70;
for(int i=0; i<5; i++)
{
if(night==true &&(i==0||i==1||i==3||i==4))
glColor3f(0.984314,1,0);
else
glColor3f(0.627451+add_r,0.921569+add_g,0.980392+add_b);
glTranslatef(0,-glass_y,0);
glBegin(GL_POLYGON);
glVertex2f(460,330);
glVertex2f(528,330);
glVertex2f(528,280);
glVertex2f(460,280);
glEnd();
}
glPopMatrix();
glColor3f(0.211765+add_r,0.321569+add_g,0.490196+add_b);
glBegin(GL_POLYGON);
glVertex2f(450,358);
glVertex2f(538,358);
glVertex2f(538,-80);
glVertex2f(450,-80);
glEnd();
glColor3f(0.498039+add_r,0.654902+add_g,0.890196+add_b);
glBegin(GL_POLYGON);
glVertex2f(450,428);
glVertex2f(550,428);
glVertex2f(550,438);
glVertex2f(450,438);
glEnd();
glColor3f(0.498039+add_r,0.654902+add_g,0.890196+add_b);
glBegin(GL_POLYGON);
glVertex2f(450,378);
glVertex2f(550,378);
glVertex2f(550,388);
glVertex2f(450,388);
glEnd();
glColor3f(0.309804+add_r,0.490196+add_g,0.760784+add_b);
glBegin(GL_POLYGON);
glVertex2f(450,428);
glVertex2f(550,428);
glVertex2f(550,-80);
glVertex2f(450,-80);
glEnd();
}
void Building_3()
{
float x_div=0,y_div=0;
glColor3f(0.501961+add_r,0.415686+add_g,0.27451+add_b);
for (int i=0; i<8; i++)
{
for(int j=0; j<7; j++)
{
glBegin(GL_POLYGON);
glVertex2f(1000+x_div,20-y_div);
glVertex2f(1040+x_div,20-y_div);
glVertex2f(1040+x_div,17-y_div);
glVertex2f(1000+x_div,17-y_div);
glEnd();
y_div+=30;
}
y_div=0;
x_div+=50;
}
glColor3f(0.054902,0.0509804,0.14902);
glBegin(GL_POLYGON);
glVertex2f(1000,50);
glVertex2f(1040,50);
glVertex2f(1040,-200);
glVertex2f(1000,-200);
glEnd();
float x_pos=50;
for(int i=0; i<7; i++)
{
glBegin(GL_POLYGON);
glVertex2f(1000+x_pos,50);
glVertex2f(1040+x_pos,50);
glVertex2f(1040+x_pos,-200);
glVertex2f(1000+x_pos,-200);
glEnd();
x_pos+=50;
}
glColor3f(1,0.819608,0.6);
glBegin(GL_POLYGON);
glVertex2f(1030,60);
glVertex2f(1370,60);
glVertex2f(1370,95);
glVertex2f(1030,95);
glEnd();
glColor3f(0.929412,0.733333,0.494118);
glBegin(GL_POLYGON);
glVertex2f(1000,-200);
glVertex2f(1400,-200);
glVertex2f(1400,50);
glVertex2f(1000,50);
glEnd();
}
void Building_4()
{
float y_pos=0,y_pos_1=0;
glPushMatrix();
glTranslatef(110,0,0);
for(int i=0; i<13; i++)
{
if(night==true && (i==1||i==10||i==7||i==6||i==3))
glColor3f(0.984314,1,0);
else
glColor3f(0.266667+add_r,0.345098+add_g,0.580392+add_b);
glBegin(GL_POLYGON);
glVertex2f(962,528-y_pos_1);
glVertex2f(999,528-y_pos_1);
glVertex2f(999,483-y_pos_1);
glVertex2f(962,483-y_pos_1);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1048,528-y_pos_1);
glVertex2f(1011,528-y_pos_1);
glVertex2f(1011,483-y_pos_1);
glVertex2f(1048,483-y_pos_1);
glEnd();
y_pos_1+=52;
}
glPopMatrix();
for(int i=0; i<13; i++)
{
if(night==true && (i==2||i==11||i==4||i==8||i==7))
glColor3f(0.984314,1,0);
else
glColor3f(0.266667+add_r,0.345098+add_g,0.580392+add_b);
glBegin(GL_POLYGON);
glVertex2f(962,528-y_pos);
glVertex2f(999,528-y_pos);
glVertex2f(999,483-y_pos);
glVertex2f(962,483-y_pos);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1048,528-y_pos);
glVertex2f(1011,528-y_pos);
glVertex2f(1011,483-y_pos);
glVertex2f(1048,483-y_pos);
glEnd();
y_pos+=52.00;
}
glColor3f(0.929412,0.733333,0.494118);
glBegin(GL_POLYGON);
glVertex2f(1200,528);
glVertex2f(1180,528);
glVertex2f(1180,-150);
glVertex2f(1200,-150);
glEnd();
glColor3f(0.0156863,0.054902,0.168627);
glBegin(GL_POLYGON);
glVertex2f(900,528);
glVertex2f(950,528);
glVertex2f(950,-150);
glVertex2f(900,-150);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(955,528);
glVertex2f(1055,528);
glVertex2f(1055,-150);
glVertex2f(955,-150);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1065,528);
glVertex2f(1165,528);
glVertex2f(1165,-150);
glVertex2f(1065,-150);
glEnd();
glColor3f(0.862745,0.886275,0.960784);
glBegin(GL_POLYGON);
glVertex2f(900,528);
glVertex2f(1200,528);
glVertex2f(1200,-150);
glVertex2f(900,-150);
glEnd();
}
void Building_5()
{
float y_pos=0;
for (int i=0; i<10; i++)
{
if(night==true&&(i==0||i==3||i==5||i==6||i==9))
glColor3f(0.984314,1,0);
else
glColor3f(0.266667+add_r,0.345098+add_g,0.580392+add_b);
glBegin(GL_POLYGON);
glVertex2f(830,325-y_pos);
glVertex2f(950,325-y_pos);
glVertex2f(950,290-y_pos);
glVertex2f(830,290-y_pos);
glEnd();
y_pos+=40;
}
glColor3f(0.0156863,0.054902,0.168627);
glBegin(GL_POLYGON);
glVertex2f(820,328);
glVertex2f(1000,328);
glVertex2f(1000,348);
glVertex2f(820,348);
glEnd();
glColor3f(0.941176,0.435294,0.282353);
glBegin(GL_POLYGON);
glVertex2f(820,328);
glVertex2f(1000,328);
glVertex2f(1000,-100);
glVertex2f(820,-100);
glEnd();
}
void Building_6()
{
glColor3f(0.309804+add_r,0.490196+add_g,0.760784+add_b);
glBegin(GL_POLYGON);
glVertex2f(1280,428);
glVertex2f(1360,428);
glVertex2f(1360,490);
glVertex2f(1280,490);
glEnd();
float x_pos=0;
glColor3f(0.541176+add_r,0.705882+add_g,0.831373+add_b);
for(int i=0; i<9; i++)
{
glBegin(GL_POLYGON);
glVertex2f(1285+x_pos,328);
glVertex2f(1290+x_pos,328);
glVertex2f(1290+x_pos,400);
glVertex2f(1285+x_pos,400);
glEnd();
x_pos+=10;
}
glColor3f(0.156863+add_r,0.345098+add_g,0.490196+add_b);
glBegin(GL_POLYGON);
glVertex2f(1280,328);
glVertex2f(1375,328);
glVertex2f(1375,400);
glVertex2f(1280,400);
glEnd();
float y_pos=0;
//glass
for (int i=0; i<6; i++)
{
if(night==true)
glColor3f(0.984314,1,0);
else
glColor3f(0.337255+add_r,0.662745+add_g,0.909804+add_b);
glBegin(GL_POLYGON);
glVertex2f(1210,318-y_pos);
glVertex2f(1270,318-y_pos);
glVertex2f(1270,278-y_pos);
glVertex2f(1210,278-y_pos);
glEnd();
y_pos+=50;
}
glColor3f(0.156863+add_r,0.345098+add_g,0.490196+add_b);
glBegin(GL_POLYGON);
glVertex2f(1000,328);
glVertex2f(1280,328);
glVertex2f(1280,-100);
glVertex2f(1000,-100);
glEnd();
float y_pos_1=0;
//glass
for(int i=0; i<6; i++)
{
if(night==true&&(i==2||i==4||i==5))
glColor3f(0.984314,1,0);
else
glColor3f(0.490196+add_r,0.627451+add_g,0.729412+add_b);
glBegin(GL_POLYGON);
glVertex2f(1285,318-y_pos_1);
glVertex2f(1370,318-y_pos_1);
glVertex2f(1370,278-y_pos_1);
glVertex2f(1285,278-y_pos_1);
glEnd();
y_pos_1+=50;
}
glColor3f(0.109804+add_r,0.223529+add_g,0.309804+add_b);
glBegin(GL_POLYGON);
glVertex2f(1280,328);
glVertex2f(1375,328);
glVertex2f(1375,-100);
glVertex2f(1280,-100);
glEnd();
glColor3f(0.309804+add_r,0.490196+add_g,0.760784+add_b);
glBegin(GL_POLYGON);
glVertex2f(1000,428);
glVertex2f(1380,428);
glVertex2f(1380,-100);
glVertex2f(1000,-100);
glEnd();
}
void Building_7()
{
float x_pos=0,y_pos=0;
for(int y =0; y<16; y++)
{
for(int x=0; x<5; x++)
{
if(night==true&&((y==2&&(x==3||x==2))||(y==4&&(x==1||x==4))||(y==5&&x==0)||(y==1&&(x==0||x==2))||(y==6&&x==2)||(y==7&&(x==0||x==4))
||(y==8&&(x==0||x==4))||(y==11)||y==13||(y==15&&(x==0||x==2))))
glColor3f(0.984314,1,0);
else
glColor3f(0.568627+add_r,0.180392+add_g,0.121569+add_b);
glBegin(GL_POLYGON);
glVertex2f(1710+x_pos,528-y_pos);
glVertex2f(1742+x_pos,528-y_pos);
glVertex2f(1742+x_pos,498-y_pos);
glVertex2f(1710+x_pos,498-y_pos);
glEnd();
x_pos+=40;
}
x_pos=0;
y_pos+=40;
}
glColor3f(0.580392+add_r,0.545098+add_g,0.282353+add_b);
glBegin(GL_POLYGON);
glVertex2f(1700,-130);
glVertex2f(1900,-130);
glVertex2f(1900,528);
glVertex2f(1700,528);
glEnd();
}
void Building_8()
{
float y_pos=0;
for(int x=0; x<10; x++)
{
glColor3f(0.74902+add_r,0.588235+add_g,0.427451+add_b);
glBegin(GL_POLYGON);
glVertex2f(1643,420-y_pos);
glVertex2f(1700,420-y_pos);
glVertex2f(1700,427-y_pos);
glVertex2f(1643,427-y_pos);
glEnd();
glColor3f(0.431373+add_r,0.364706+add_g,0.329412+add_b);
glBegin(GL_POLYGON);
glVertex2f(1643,420-y_pos);
glVertex2f(1700,420-y_pos);
glVertex2f(1700,417-y_pos);
glVertex2f(1643,417-y_pos);
glEnd();
y_pos+=50;
}
glColor3f(0.0509804+add_r,0,0.219608+add_b);
glBegin(GL_POLYGON);
glVertex2f(1635,-80);
glVertex2f(1645,-80);
glVertex2f(1645,420);
glVertex2f(1635,420);
glEnd();
glColor3f(0.568627+add_r,0.247059+add_g,0.0980392+add_b);
glBegin(GL_POLYGON);
glVertex2f(1600,-80);
glVertex2f(1635,-80);
glVertex2f(1635,420);
glVertex2f(1600,420);
glEnd();
glColor3f(0.811765+add_r,0.333333+add_g,0.113725+add_b);
glBegin(GL_POLYGON);
glVertex2f(1600,-80);
glVertex2f(1700,-80);
glVertex2f(1700,420);
glVertex2f(1600,420);
glEnd();
}
void Building_9()
{
if(night||evening)
{
float point_x=0;
glPointSize(4);
glColor3f(0.152941,0.729412,0.768627);
glBegin(GL_POINTS);
for(int i=0; i<11; i++)
{
glVertex2f(660+point_x,30);
point_x+=6;
}
glVertex2f(560,140);
glVertex2f(590,120);
glVertex2f(575,100);
glVertex2f(560,80);
glVertex2f(670,180);
glVertex2f(680,180);
glVertex2f(690,180);
glVertex2f(700,160);
glVertex2f(710,160);
glVertex2f(720,160);
glVertex2f(730,160);
glVertex2f(700,140);
glVertex2f(690,140);
glVertex2f(670,120);
glVertex2f(730,100);
glVertex2f(670,80);
glVertex2f(710,80);
glVertex2f(720,80);
glVertex2f(730,80);
glVertex2f(570,80);
glVertex2f(610,80);
glVertex2f(570,60);
glVertex2f(580,60);
glVertex2f(590,60);
glVertex2f(600,60);
glVertex2f(610,60);
glVertex2f(740,100);
glVertex2f(780,100);
glVertex2f(740,150);
glVertex2f(780,50);
glVertex2f(790,50);
glVertex2f(800,50);
glVertex2f(800,150);
glVertex2f(820,200);
glVertex2f(810,200);
glVertex2f(800,200);
glVertex2f(810,250);
glVertex2f(1500,200);
glVertex2f(1450,200);
glVertex2f(1400,200);
glVertex2f(1390,200);
glVertex2f(1410,200);
glVertex2f(1420,200);
glVertex2f(1400,250);
glVertex2f(1390,300);
glVertex2f(1530,250);
glVertex2f(1520,250);
glVertex2f(1510,250);
glVertex2f(1500,250);
glVertex2f(1450,250);
glVertex2f(1440,250);
glVertex2f(1500,230);
glVertex2f(1480,230);
glVertex2f(1480,210);
glVertex2f(1490,210);
glVertex2f(1470,210);
glVertex2f(1430,180);
glVertex2f(1440,180);
glVertex2f(1380,180);
glVertex2f(1470,180);
glVertex2f(1460,180);
glVertex2f(1530,180);
glVertex2f(1510,180);
glVertex2f(1430,160);
glVertex2f(1440,160);
glVertex2f(1450,160);
glVertex2f(1460,160);
glVertex2f(1530,140);
glVertex2f(1520,140);
glVertex2f(1510,140);
glVertex2f(1500,140);
glVertex2f(1430,140);
glVertex2f(1420,140);
glVertex2f(1390,100);
glVertex2f(1490,100);
glVertex2f(1480,100);
glVertex2f(1470,100);
glVertex2f(1460,100);
glVertex2f(1410,60);
glVertex2f(1420,60);
glVertex2f(1430,60);
glVertex2f(1510,60);
glVertex2f(1440,30);
glVertex2f(1450,30);
glVertex2f(1460,30);
glEnd();
}
if(evening)
glColor3f(0.00784314,0.25098,0.639216);
else if(night)
glColor3f(0,0,0.529412);
else
glColor3f(0.454902,0.686275,0.94902);
glBegin(GL_POLYGON);
glVertex2f(550,150);
glVertex2f(600,150);
glVertex2f(600,-10);
glVertex2f(550,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(600,100);
glVertex2f(650,100);
glVertex2f(650,-10);
glVertex2f(600,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(650,180);
glVertex2f(655,180);
glVertex2f(655,-10);
glVertex2f(650,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(655,190);
glVertex2f(670,190);
glVertex2f(670,-10);
glVertex2f(655,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(670,250);
glVertex2f(700,250);
glVertex2f(700,-10);
glVertex2f(670,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(700,200);
glVertex2f(750,200);
glVertex2f(750,-10);
glVertex2f(700,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(750,170);
glVertex2f(780,170);
glVertex2f(780,-10);
glVertex2f(750,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(780,280);
glVertex2f(820,280);
glVertex2f(820,-10);
glVertex2f(780,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1350,320);
glVertex2f(1410,320);
glVertex2f(1410,-10);
glVertex2f(1350,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1350,320);
glVertex2f(1410,320);
glVertex2f(1410,-10);
glVertex2f(1350,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1410,260);
glVertex2f(1470,260);
glVertex2f(1470,-10);
glVertex2f(1410,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1470,290);
glVertex2f(1510,290);
glVertex2f(1510,-10);
glVertex2f(1470,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1510,320);
glVertex2f(1550,320);
glVertex2f(1550,-10);
glVertex2f(1510,-10);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1550,380);
glVertex2f(1650,380);
glVertex2f(1650,-10);
glVertex2f(1550,-10);
glEnd();
}
//////////////////////////
////////Slab//////////////
void slab_1()
{
glColor3f(0.309804+add_r,0.368627+add_g,0.333333+add_b);
glBegin(GL_POLYGON);
glVertex2f(0,50);
glVertex2f(650,50);
glVertex2f(540,-250);
glVertex2f(0,-250);
glEnd();
}
void slab_2()
{
glColor3f(0.309804+add_r,0.368627+add_g,0.333333+add_b);
glBegin(GL_QUADS);
glVertex2f(730,50);
glVertex2f(1100,50);
glVertex2f(1590,-250);
glVertex2f(850,-250);
glEnd();
}
void slab_3()
{
glColor3f(0.309804+add_r,0.368627+add_g,0.333333+add_b);
glBegin(GL_QUADS);
glVertex2f(1300,50);
glVertex2f(1900,50);
glVertex2f(1900,-250);
glVertex2f(1900,-250);
glEnd();
}
///////road//////
void road()
{
glColor3f(1,1,1);
float x_r_p=0,y_r_p=0;
for(int i=0; i<6; i++)
{
glBegin(GL_POLYGON);
glVertex2f(0+x_r_p,-346);
glVertex2f(250+x_r_p,-346);
glVertex2f(250+x_r_p,-352);
glVertex2f(0+x_r_p,-352);
glEnd();
x_r_p+=350;
}
for(int i=0; i<2; i++)
{
glBegin(GL_POLYGON);
glVertex2f(685,-250+y_r_p);
glVertex2f(691,-250+y_r_p);
glVertex2f(691,-100+y_r_p);
glVertex2f(685,-100+y_r_p);
glEnd();
y_r_p+=180;
}
glColor3f(0.258824,0.258824,0.258824);
glBegin(GL_POLYGON);
glVertex2f(0,-10);
glVertex2f(1900,-10);
glVertex2f(1900,-528);
glVertex2f(0,-528);
glEnd();
}
////tree///
void tree()
{
glColor3f(0.337255,0.54902,0.152941);
glBegin(GL_TRIANGLES);
glVertex2f(50,-40);
glVertex2f(25,-160);
glVertex2f(50,-170);
glEnd();
glColor3f(0.188235,0.329412,0.0627451);
glBegin(GL_TRIANGLES);
glVertex2f(50,-40);
glVertex2f(75,-160);
glVertex2f(50,-170);
glEnd();
glColor3f(0.180392,0.0627451,0.0627451);
glBegin(GL_POLYGON);
glVertex2f(46,-167);
glVertex2f(56,-167);
glVertex2f(56,-180);
glVertex2f(46,-180);
glEnd();
}
void tree_1()
{
glColor3f(0.403922,0.541176,0.227451);
glBegin(GL_POLYGON);
glVertex2f(840,-40);
glVertex2f(910,-40);
glVertex2f(910,-100);
glVertex2f(840,-100);
glEnd();
glColor3f(0.231373,0.341176,0.0862745);
glBegin(GL_POLYGON);
glVertex2f(800,-70);
glVertex2f(860,-70);
glVertex2f(860,-120);
glVertex2f(800,-120);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(890,-70);
glVertex2f(950,-70);
glVertex2f(950,-120);
glVertex2f(890,-120);
glEnd();
glColor3f(0.501961,0.278431,0.0980392);
glBegin(GL_POLYGON);
glVertex2f(870,-180);
glVertex2f(880,-180);
glVertex2f(880,-100);
glVertex2f(870,-100);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(840,-100);
glVertex2f(850,-100);
glVertex2f(870,-140);
glVertex2f(880,-140);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(900,-100);
glVertex2f(910,-100);
glVertex2f(870,-137);
glVertex2f(880,-137);
glEnd();
}
////////car///////
float car_1_xpos=0;
void Car_1()
{
if(night==true)
glColor3f(0.984314,1,0);
else
glColor3f(0.537255,0.537255,0.533333);
glBegin(GL_QUADS);
glVertex2f(450,-250);
glVertex2f(440,-250);
glVertex2f(440,-230);
glVertex2f(450,-230);
glEnd();
glColor3f(0.686275+add_r,0.839216+add_g,0.509804+add_b);
circle(200,-180,60);
glColor3f(0.129412+add_r,0.129412+add_g,0.129412+add_b);
glBegin(GL_QUADS);
glVertex2f(450,-270);
glVertex2f(440,-270);
glVertex2f(440,-260);
glVertex2f(450,-260);
glEnd();
glColor3f(0.129412+add_r,0.129412+add_g,0.129412+add_b);
circle(170,-280,35);
glColor3f(0.129412,0.129412,0.129412);
circle(400,-280,35);
glColor3f(0.2,0.2,0.2);
glBegin(GL_POLYGON);
glVertex2f(100,-270);
glVertex2f(130,-280);
glVertex2f(420,-280);
glVertex2f(450,-270);
glEnd();
glColor3f(0.34902+add_r,0.431373+add_g,0.431373+add_b);
glLineWidth(5);
glBegin(GL_LINES);
glVertex2f(300,-270);
glVertex2f(300,-100);
glEnd();
glBegin(GL_LINES);
glVertex2f(300,-100);
glVertex2f(100,-100);
glEnd();
glBegin(GL_LINES);
glVertex2f(100,-100);
glVertex2f(100,-270);
glEnd();
glColor3f(0.603922+add_r,0.721569+add_g,0.705882+add_b);
glBegin(GL_POLYGON);
glVertex2f(300,-270);
glVertex2f(300,-100);
glVertex2f(100,-100);
glVertex2f(100,-270);
glEnd();
glColor3f(0.227451+add_r,0.231373+add_g,0.231373+add_b);
glBegin(GL_POLYGON);
glVertex2f(305,-155);
glVertex2f(345,-155);
glVertex2f(395,-205);
glVertex2f(305,-205);
glEnd();
glColor3f(0.603922+add_r,0.721569+add_g,0.705882+add_b);
glBegin(GL_POLYGON);
glVertex2f(300,-150);
glVertex2f(350,-150);
glVertex2f(400,-200);
glVertex2f(450,-230);
glVertex2f(450,-270);
glVertex2f(300,-270);
glEnd();
glColor3f(0.34902+add_r,0.431373+add_g,0.431373+add_b);
circle(310,-150,36);
}
void Car_1_move(int)
{
glutTimerFunc(1000/90,Car_1_move,1);
if(car_1_xpos<=1950)
car_1_xpos+=3;
else
car_1_xpos=-450;
glutPostRedisplay();
}
void Car_2()
{
if(night==true)
glColor3f(0.984314,1,0);
else
glColor3f(0.537255,0.537255,0.533333);
glBegin(GL_QUADS);
glVertex2f(450,-250);
glVertex2f(440,-250);
glVertex2f(440,-230);
glVertex2f(450,-230);
glEnd();
glColor3f(0.686275+add_r,0.839216+add_g,0.509804+add_b);
circle(200,-180,60);
glColor3f(0.129412+add_r,0.129412+add_g,0.129412+add_b);
glBegin(GL_QUADS);
glVertex2f(450,-270);
glVertex2f(440,-270);
glVertex2f(440,-260);
glVertex2f(450,-260);
glEnd();
glColor3f(0.129412+add_r,0.129412+add_g,0.129412+add_b);
circle(170,-280,35);
glColor3f(0.129412,0.129412,0.129412);
circle(400,-280,35);
glColor3f(0.2,0.2,0.2);
glBegin(GL_POLYGON);
glVertex2f(100,-270);
glVertex2f(130,-280);
glVertex2f(420,-280);
glVertex2f(450,-270);
glEnd();
glColor3f(0.34902+add_r,0.431373+add_g,0.431373+add_b);
glLineWidth(5);
glBegin(GL_LINES);
glVertex2f(300,-270);
glVertex2f(300,-100);
glEnd();
glBegin(GL_LINES);
glVertex2f(300,-100);
glVertex2f(100,-100);
glEnd();
glBegin(GL_LINES);
glVertex2f(100,-100);
glVertex2f(100,-270);
glEnd();
glColor3f(0.878431+add_r,0.835294+add_g,0.00784314+add_b);
glBegin(GL_POLYGON);
glVertex2f(300,-270);
glVertex2f(300,-100);
glVertex2f(100,-100);
glVertex2f(100,-270);
glEnd();
glColor3f(0.227451+add_r,0.231373+add_g,0.231373+add_b);
glBegin(GL_POLYGON);
glVertex2f(305,-155);
glVertex2f(345,-155);
glVertex2f(395,-205);
glVertex2f(305,-205);
glEnd();
glColor3f(0.878431+add_r,0.835294+add_g,0.00784314+add_b);
glBegin(GL_POLYGON);
glVertex2f(300,-150);
glVertex2f(350,-150);
glVertex2f(400,-200);
glVertex2f(450,-230);
glVertex2f(450,-270);
glVertex2f(300,-270);
glEnd();
glColor3f(0.34902+add_r,0.431373+add_g,0.431373+add_b);
circle(310,-150,36);
}
float car_2_xpos=10;
void Car_2_perfectPlace()
{
glPushMatrix();
glTranslatef(0,-110,0);
Car_2();
glPopMatrix();
}
void car_2_move(int)
{
glutTimerFunc(1000/90,car_2_move,1);
if(car_2_xpos<=1950)
car_2_xpos+=1.5;
else
car_2_xpos=-450;
glutPostRedisplay();
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,1900,-528,528);
glMatrixMode(GL_MODELVIEW);
}
void init()
{
glClearColor(0,0,0,1.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 'd':
{
night=false;
evening=false;
sun_y_position=80;
sky_r=0.3019;
sky_g=0.9538;
sky_b=1.0;
sun_color_g=1.0;
add_r=0;
add_g=0;
add_b=0;
glClear(GL_COLOR_BUFFER_BIT);
glutPostRedisplay();
break;
}
case 'e':
{
night=false;
evening=true;
sun_y_position=-100;
sun_color_g=.9;
add_r=-0.0588235;
add_g=-0.0588235;
add_b=-0.0588235;
glutPostRedisplay();
break;
}
case 'n':
{
night = true;
evening=false;
sky_r=0;
sky_g=0.0823529;
sky_b=0.278431;
add_r=-0.117647;
add_g=-0.117647;
add_b=-0.117647;
glutPostRedisplay();
break;
}
}
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
///car///
glPushMatrix();
glTranslatef(car_2_xpos,0,0);
Car_2_perfectPlace();
glPopMatrix();
glPushMatrix();
glTranslatef(car_1_xpos,0,0);
Car_1();
glPopMatrix();
///buildings///
glPushMatrix();
glTranslatef(-350,0,0);
tree_1();
glPopMatrix();
glPushMatrix();
glTranslatef(-20,0,0);
tree_1();
glPopMatrix();
float tree_1_x_pos=0;
for(int i=0; i<6; i++)
{
glPushMatrix();
glTranslatef(tree_1_x_pos,0,0);
tree();
glPopMatrix();
tree_1_x_pos+=70;
}
tree_1_x_pos=0;
glPushMatrix();
glTranslatef(2000,0,0);
glScalef(-.8,0.8,0);
for(int i=0; i<5; i++)
{
glPushMatrix();
glTranslatef(tree_1_x_pos,0,0);
tree();
glPopMatrix();
tree_1_x_pos+=70;
}
glPopMatrix();
Building_1();
glPushMatrix();
glScalef(0.8,0.8,0);
glTranslatef(-180,40,0);
tree_1();
glPopMatrix();
Building_2();
glPushMatrix();
glScalef(0.6,0.6,0);
glTranslatef(90,90,0);
tree_1();
glPopMatrix();
Building_3();
Building_4();
glPushMatrix();
glScalef(0.8,0.8,0);
glTranslatef(150,40,0);
tree_1();
glPopMatrix();
Building_5();
Building_6();
glPushMatrix();
glScalef(0.6,0.6,0);
glTranslatef(450,90,0);
tree_1();
glPopMatrix();
Building_7();
Building_8();
glPushMatrix();
glTranslatef(720,50,0);
Building_5();
glPopMatrix();
Building_9();
///Slabs//
slab_1();
slab_2();
slab_3();
///road///
road();
///Clouds//
glPushMatrix();
glTranslatef(Cloud_2_x_pos,0,0);
Cloud_2();
glPopMatrix();
glPushMatrix();
glTranslatef(Cloud_1_x_pos,0,0);
Cloud_1();
glPopMatrix();
glPushMatrix();
glTranslatef(Cloud_1cpy_x_pos,0,0);
Cloud_1cpy();
glPopMatrix();
glPushMatrix();
glTranslatef(Cloud_3_x_pos,0,0);
Cloud_3();
glPopMatrix();
///Sun&Moon///
if(night == false)
{
glPushMatrix();
glTranslatef(0.0,sun_y_position,0.0);
Sun();
glPopMatrix();
}
else if(night = true)
{
glPushMatrix();
glTranslatef(0.0,80,0.0);
Moon();
glPopMatrix();
}
///Sky//
Sky();
glFlush();
glutSwapBuffers();
}
void TimerHolder(int)
{
cloud_movement_timer(0);
Car_1_move(0);
car_2_move(0);
}
int main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowSize(1900,1060);
glutInitWindowPosition(0,0);
glutCreateWindow("City view");
glutReshapeFunc(reshape);
glutDisplayFunc(Display);
glutKeyboardFunc(keyboard);
init();
glutIdleFunc(Display);
glutTimerFunc(0,TimerHolder,0);
glutMainLoop();
}
| [
"iamamysharma@gmail.com"
] | iamamysharma@gmail.com |
c16c3e86228fff9051dc2bb967ac56e170b9e94f | 8d86eda47e545fd8e928cd7b49c2a8bc49c6e70e | /LeetCode0029.cpp | 3ddf2de8a80013319a7e5813aa62417a32f2702a | [
"Unlicense"
] | permissive | chibai/LeetCodeInCPP | 912628698cb6426480b958a4bef34077b1b68e7e | 36e82087e5608181471b2fec99a771ab03c78b3e | refs/heads/master | 2022-08-27T19:41:03.581004 | 2021-12-12T17:05:31 | 2021-12-12T17:05:31 | 75,583,686 | 1 | 0 | null | 2019-11-30T10:45:35 | 2016-12-05T03:06:46 | C++ | UTF-8 | C++ | false | false | 1,737 | cpp | #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
//Definition for singly linked list
struct ListNode {
int val;
ListNode *next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode *next) : val(x), next(next) {}
};
class Solution {
public:
int myDivide(int dividend, int divisor) {
if (dividend == 0)
return 0;
else if (divisor == 1)
return dividend;
else if (divisor == -1)
return dividend == INT32_MIN ? INT32_MAX : -dividend;
else if (divisor == INT32_MIN)
return dividend == divisor ? 1 : 0;
////////////////////
bool isDividendPositive = dividend > 0;
bool isDivisorPositive = divisor > 0;
int extraOne = 0;
if (!isDividendPositive)
{
if (dividend == INT32_MIN)
{
dividend = INT32_MAX;
extraOne = 1;
}
else
{
dividend = -dividend;
}
}
divisor = isDivisorPositive ? divisor : -divisor;
int result = 0;
while (dividend >= divisor - extraOne)
{
int tmp_divisor = divisor;
int tmp_result = 1;
while (tmp_divisor < (INT32_MAX>>2) && dividend >= ((tmp_divisor<<2) - extraOne))
{
tmp_result = tmp_result << 2;
tmp_divisor = tmp_divisor << 2;
}
if (extraOne == 1)
{
dividend = dividend - tmp_divisor + extraOne;
extraOne = 0;
}
else
dividend -= tmp_divisor;
result += tmp_result;
}
return isDividendPositive ^ isDivisorPositive?-result : result;
}
int divide(int dividend, int divisor)
{
}
};
int main()
{
Solution solution = Solution();
auto result = solution.divide(INT32_MIN, 2);
std::cout << result;
return 0;
} | [
"470598003@qq.com"
] | 470598003@qq.com |
492b3e40f9bccaf0aa4c7f7dbe05ebcb3b909102 | 731baff7404d53beb53e34eb4897cae2d5a190b3 | /src/wallet.cpp | 1704e5a73154adccdb375972bf6b5d1e610f3fd4 | [
"MIT"
] | permissive | bitvier/bitvier | 65c762fd74ae8a1b9fe799d6cabf855bc33dcdf3 | 253c13ca839e2e738fc31d74a50b34a2e0179fda | refs/heads/master | 2021-09-08T19:14:44.684034 | 2018-03-11T21:28:55 | 2018-03-11T21:28:55 | 124,801,209 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 89,153 | cpp | // Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "txdb.h"
#include "wallet.h"
#include "walletdb.h"
#include "crypter.h"
#include "ui_interface.h"
#include "base58.h"
#include "kernel.h"
#include "coincontrol.h"
#include <boost/algorithm/string/replace.hpp>
using namespace std;
unsigned int nStakeSplitAge = 1 * 24 * 60 * 60;
int64_t nStakeCombineThreshold = 1000 * COIN;
//////////////////////////////////////////////////////////////////////////////
//
// mapWallet
//
struct CompareValueOnly
{
bool operator()(const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t1,
const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t2) const
{
return t1.first < t2.first;
}
};
CPubKey CWallet::GenerateNewKey()
{
bool fCompressed = CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets
RandAddSeedPerfmon();
CKey key;
key.MakeNewKey(fCompressed);
// Compressed public keys were introduced in version 0.6.0
if (fCompressed)
SetMinVersion(FEATURE_COMPRPUBKEY);
CPubKey pubkey = key.GetPubKey();
// Create new metadata
int64_t nCreationTime = GetTime();
mapKeyMetadata[pubkey.GetID()] = CKeyMetadata(nCreationTime);
if (!nTimeFirstKey || nCreationTime < nTimeFirstKey)
nTimeFirstKey = nCreationTime;
if (!AddKey(key))
throw std::runtime_error("CWallet::GenerateNewKey() : AddKey failed");
return key.GetPubKey();
}
bool CWallet::AddKey(const CKey& key)
{
CPubKey pubkey = key.GetPubKey();
if (!CCryptoKeyStore::AddKey(key))
return false;
if (!fFileBacked)
return true;
if (!IsCrypted())
return CWalletDB(strWalletFile).WriteKey(pubkey, key.GetPrivKey(), mapKeyMetadata[pubkey.GetID()]);
return true;
}
bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const vector<unsigned char> &vchCryptedSecret)
{
if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret))
return false;
if (!fFileBacked)
return true;
{
LOCK(cs_wallet);
if (pwalletdbEncryption)
return pwalletdbEncryption->WriteCryptedKey(vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.GetID()]);
else
return CWalletDB(strWalletFile).WriteCryptedKey(vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.GetID()]);
}
return false;
}
bool CWallet::LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &meta)
{
if (meta.nCreateTime && (!nTimeFirstKey || meta.nCreateTime < nTimeFirstKey))
nTimeFirstKey = meta.nCreateTime;
mapKeyMetadata[pubkey.GetID()] = meta;
return true;
}
bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
{
return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret);
}
bool CWallet::AddCScript(const CScript& redeemScript)
{
if (!CCryptoKeyStore::AddCScript(redeemScript))
return false;
if (!fFileBacked)
return true;
return CWalletDB(strWalletFile).WriteCScript(Hash160(redeemScript), redeemScript);
}
// optional setting to unlock wallet for staking only
// serves to disable the trivial sendmoney when OS account compromised
// provides no real security
bool fWalletUnlockStakingOnly = false;
bool CWallet::Unlock(const SecureString& strWalletPassphrase)
{
if (!IsLocked())
return false;
CCrypter crypter;
CKeyingMaterial vMasterKey;
{
LOCK(cs_wallet);
BOOST_FOREACH(const MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
{
if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
return false;
if (CCryptoKeyStore::Unlock(vMasterKey))
return true;
}
}
return false;
}
bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase)
{
bool fWasLocked = IsLocked();
{
LOCK(cs_wallet);
Lock();
CCrypter crypter;
CKeyingMaterial vMasterKey;
BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
{
if(!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
return false;
if (CCryptoKeyStore::Unlock(vMasterKey))
{
int64_t nStartTime = GetTimeMillis();
crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
pMasterKey.second.nDeriveIterations = pMasterKey.second.nDeriveIterations * (100 / ((double)(GetTimeMillis() - nStartTime)));
nStartTime = GetTimeMillis();
crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + pMasterKey.second.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime))) / 2;
if (pMasterKey.second.nDeriveIterations < 25000)
pMasterKey.second.nDeriveIterations = 25000;
printf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations);
if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
if (!crypter.Encrypt(vMasterKey, pMasterKey.second.vchCryptedKey))
return false;
CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second);
if (fWasLocked)
Lock();
return true;
}
}
}
return false;
}
void CWallet::SetBestChain(const CBlockLocator& loc)
{
CWalletDB walletdb(strWalletFile);
walletdb.WriteBestBlock(loc);
}
// This class implements an addrIncoming entry that causes pre-0.4
// clients to crash on startup if reading a private-key-encrypted wallet.
class CCorruptAddress
{
public:
IMPLEMENT_SERIALIZE
(
if (nType & SER_DISK)
READWRITE(nVersion);
)
};
bool CWallet::SetMinVersion(enum WalletFeature nVersion, CWalletDB* pwalletdbIn, bool fExplicit)
{
if (nWalletVersion >= nVersion)
return true;
// when doing an explicit upgrade, if we pass the max version permitted, upgrade all the way
if (fExplicit && nVersion > nWalletMaxVersion)
nVersion = FEATURE_LATEST;
nWalletVersion = nVersion;
if (nVersion > nWalletMaxVersion)
nWalletMaxVersion = nVersion;
if (fFileBacked)
{
CWalletDB* pwalletdb = pwalletdbIn ? pwalletdbIn : new CWalletDB(strWalletFile);
if (nWalletVersion >= 40000)
{
// Versions prior to 0.4.0 did not support the "minversion" record.
// Use a CCorruptAddress to make them crash instead.
CCorruptAddress corruptAddress;
pwalletdb->WriteSetting("addrIncoming", corruptAddress);
}
if (nWalletVersion > 40000)
pwalletdb->WriteMinVersion(nWalletVersion);
if (!pwalletdbIn)
delete pwalletdb;
}
return true;
}
bool CWallet::SetMaxVersion(int nVersion)
{
// cannot downgrade below current version
if (nWalletVersion > nVersion)
return false;
nWalletMaxVersion = nVersion;
return true;
}
bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
{
if (IsCrypted())
return false;
CKeyingMaterial vMasterKey;
RandAddSeedPerfmon();
vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
RAND_bytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);
CMasterKey kMasterKey(nDerivationMethodIndex);
RandAddSeedPerfmon();
kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE);
RAND_bytes(&kMasterKey.vchSalt[0], WALLET_CRYPTO_SALT_SIZE);
CCrypter crypter;
int64_t nStartTime = GetTimeMillis();
crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, 25000, kMasterKey.nDerivationMethod);
kMasterKey.nDeriveIterations = 2500000 / ((double)(GetTimeMillis() - nStartTime));
nStartTime = GetTimeMillis();
crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod);
kMasterKey.nDeriveIterations = (kMasterKey.nDeriveIterations + kMasterKey.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime))) / 2;
if (kMasterKey.nDeriveIterations < 25000)
kMasterKey.nDeriveIterations = 25000;
printf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations);
if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod))
return false;
if (!crypter.Encrypt(vMasterKey, kMasterKey.vchCryptedKey))
return false;
{
LOCK(cs_wallet);
mapMasterKeys[++nMasterKeyMaxID] = kMasterKey;
if (fFileBacked)
{
pwalletdbEncryption = new CWalletDB(strWalletFile);
if (!pwalletdbEncryption->TxnBegin())
return false;
pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
}
if (!EncryptKeys(vMasterKey))
{
if (fFileBacked)
pwalletdbEncryption->TxnAbort();
exit(1); //We now probably have half of our keys encrypted in memory, and half not...die and let the user reload their unencrypted wallet.
}
// Encryption was introduced in version 0.4.0
SetMinVersion(FEATURE_WALLETCRYPT, pwalletdbEncryption, true);
if (fFileBacked)
{
if (!pwalletdbEncryption->TxnCommit())
exit(1); //We now have keys encrypted in memory, but no on disk...die to avoid confusion and let the user reload their unencrypted wallet.
delete pwalletdbEncryption;
pwalletdbEncryption = NULL;
}
Lock();
Unlock(strWalletPassphrase);
NewKeyPool();
Lock();
// Need to completely rewrite the wallet file; if we don't, bdb might keep
// bits of the unencrypted private key in slack space in the database file.
CDB::Rewrite(strWalletFile);
}
NotifyStatusChanged(this);
return true;
}
int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
{
int64_t nRet = nOrderPosNext++;
if (pwalletdb) {
pwalletdb->WriteOrderPosNext(nOrderPosNext);
} else {
CWalletDB(strWalletFile).WriteOrderPosNext(nOrderPosNext);
}
return nRet;
}
CWallet::TxItems CWallet::OrderedTxItems(std::list<CAccountingEntry>& acentries, std::string strAccount)
{
CWalletDB walletdb(strWalletFile);
// First: get all CWalletTx and CAccountingEntry into a sorted-by-order multimap.
TxItems txOrdered;
// Note: maintaining indices in the database of (account,time) --> txid and (account, time) --> acentry
// would make this much faster for applications that do this a lot.
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
CWalletTx* wtx = &((*it).second);
txOrdered.insert(make_pair(wtx->nOrderPos, TxPair(wtx, (CAccountingEntry*)0)));
}
acentries.clear();
walletdb.ListAccountCreditDebit(strAccount, acentries);
BOOST_FOREACH(CAccountingEntry& entry, acentries)
{
txOrdered.insert(make_pair(entry.nOrderPos, TxPair((CWalletTx*)0, &entry)));
}
return txOrdered;
}
void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock)
{
// Anytime a signature is successfully verified, it's proof the outpoint is spent.
// Update the wallet spent flag if it doesn't know due to wallet.dat being
// restored from backup or the user making copies of wallet.dat.
{
LOCK(cs_wallet);
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
map<uint256, CWalletTx>::iterator mi = mapWallet.find(txin.prevout.hash);
if (mi != mapWallet.end())
{
CWalletTx& wtx = (*mi).second;
if (txin.prevout.n >= wtx.vout.size())
printf("WalletUpdateSpent: bad wtx %s\n", wtx.GetHash().ToString().c_str());
else if (!wtx.IsSpent(txin.prevout.n) && IsMine(wtx.vout[txin.prevout.n]))
{
printf("WalletUpdateSpent found spent coin %s BC %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
wtx.MarkSpent(txin.prevout.n);
wtx.WriteToDisk();
NotifyTransactionChanged(this, txin.prevout.hash, CT_UPDATED);
}
}
}
if (fBlock)
{
uint256 hash = tx.GetHash();
map<uint256, CWalletTx>::iterator mi = mapWallet.find(hash);
CWalletTx& wtx = (*mi).second;
BOOST_FOREACH(const CTxOut& txout, tx.vout)
{
if (IsMine(txout))
{
wtx.MarkUnspent(&txout - &tx.vout[0]);
wtx.WriteToDisk();
NotifyTransactionChanged(this, hash, CT_UPDATED);
}
}
}
}
}
void CWallet::MarkDirty()
{
{
LOCK(cs_wallet);
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
item.second.MarkDirty();
}
}
bool CWallet::AddToWallet(const CWalletTx& wtxIn)
{
uint256 hash = wtxIn.GetHash();
{
LOCK(cs_wallet);
// Inserts only if not already there, returns tx inserted or tx found
pair<map<uint256, CWalletTx>::iterator, bool> ret = mapWallet.insert(make_pair(hash, wtxIn));
CWalletTx& wtx = (*ret.first).second;
wtx.BindWallet(this);
bool fInsertedNew = ret.second;
if (fInsertedNew)
{
wtx.nTimeReceived = GetAdjustedTime();
wtx.nOrderPos = IncOrderPosNext();
wtx.nTimeSmart = wtx.nTimeReceived;
if (wtxIn.hashBlock != 0)
{
if (mapBlockIndex.count(wtxIn.hashBlock))
{
unsigned int latestNow = wtx.nTimeReceived;
unsigned int latestEntry = 0;
{
// Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future
int64_t latestTolerated = latestNow + 300;
std::list<CAccountingEntry> acentries;
TxItems txOrdered = OrderedTxItems(acentries);
for (TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
{
CWalletTx *const pwtx = (*it).second.first;
if (pwtx == &wtx)
continue;
CAccountingEntry *const pacentry = (*it).second.second;
int64_t nSmartTime;
if (pwtx)
{
nSmartTime = pwtx->nTimeSmart;
if (!nSmartTime)
nSmartTime = pwtx->nTimeReceived;
}
else
nSmartTime = pacentry->nTime;
if (nSmartTime <= latestTolerated)
{
latestEntry = nSmartTime;
if (nSmartTime > latestNow)
latestNow = nSmartTime;
break;
}
}
}
unsigned int& blocktime = mapBlockIndex[wtxIn.hashBlock]->nTime;
wtx.nTimeSmart = std::max(latestEntry, std::min(blocktime, latestNow));
}
else
printf("AddToWallet() : found %s in block %s not in index\n",
wtxIn.GetHash().ToString().substr(0,10).c_str(),
wtxIn.hashBlock.ToString().c_str());
}
}
bool fUpdated = false;
if (!fInsertedNew)
{
// Merge
if (wtxIn.hashBlock != 0 && wtxIn.hashBlock != wtx.hashBlock)
{
wtx.hashBlock = wtxIn.hashBlock;
fUpdated = true;
}
if (wtxIn.nIndex != -1 && (wtxIn.vMerkleBranch != wtx.vMerkleBranch || wtxIn.nIndex != wtx.nIndex))
{
wtx.vMerkleBranch = wtxIn.vMerkleBranch;
wtx.nIndex = wtxIn.nIndex;
fUpdated = true;
}
if (wtxIn.fFromMe && wtxIn.fFromMe != wtx.fFromMe)
{
wtx.fFromMe = wtxIn.fFromMe;
fUpdated = true;
}
fUpdated |= wtx.UpdateSpent(wtxIn.vfSpent);
}
//// debug print
printf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString().substr(0,10).c_str(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : ""));
// Write to disk
if (fInsertedNew || fUpdated)
if (!wtx.WriteToDisk())
return false;
#ifndef QT_GUI
// If default receiving address gets used, replace it with a new one
if (vchDefaultKey.IsValid()) {
CScript scriptDefaultKey;
scriptDefaultKey.SetDestination(vchDefaultKey.GetID());
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
{
if (txout.scriptPubKey == scriptDefaultKey)
{
CPubKey newDefaultKey;
if (GetKeyFromPool(newDefaultKey, false))
{
SetDefaultKey(newDefaultKey);
SetAddressBookName(vchDefaultKey.GetID(), "");
}
}
}
}
#endif
// since AddToWallet is called directly for self-originating transactions, check for consumption of own coins
WalletUpdateSpent(wtx, (wtxIn.hashBlock != 0));
// Notify UI of new or updated transaction
NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED);
// notify an external script when a wallet transaction comes in or is updated
std::string strCmd = GetArg("-walletnotify", "");
if ( !strCmd.empty())
{
boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
boost::thread t(runCommand, strCmd); // thread runs free
}
}
return true;
}
// Add a transaction to the wallet, or update it.
// pblock is optional, but should be provided if the transaction is known to be in a block.
// If fUpdate is true, existing transactions will be updated.
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate, bool fFindBlock)
{
uint256 hash = tx.GetHash();
{
LOCK(cs_wallet);
bool fExisted = mapWallet.count(hash);
if (fExisted && !fUpdate) return false;
if (fExisted || IsMine(tx) || IsFromMe(tx))
{
CWalletTx wtx(this,tx);
// Get merkle branch if transaction was found in a block
if (pblock)
wtx.SetMerkleBranch(pblock);
return AddToWallet(wtx);
}
else
WalletUpdateSpent(tx);
}
return false;
}
bool CWallet::EraseFromWallet(uint256 hash)
{
if (!fFileBacked)
return false;
{
LOCK(cs_wallet);
if (mapWallet.erase(hash))
CWalletDB(strWalletFile).EraseTx(hash);
}
return true;
}
bool CWallet::IsMine(const CTxIn &txin) const
{
{
LOCK(cs_wallet);
map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.prevout.hash);
if (mi != mapWallet.end())
{
const CWalletTx& prev = (*mi).second;
if (txin.prevout.n < prev.vout.size())
if (IsMine(prev.vout[txin.prevout.n]))
return true;
}
}
return false;
}
int64_t CWallet::GetDebit(const CTxIn &txin) const
{
{
LOCK(cs_wallet);
map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.prevout.hash);
if (mi != mapWallet.end())
{
const CWalletTx& prev = (*mi).second;
if (txin.prevout.n < prev.vout.size())
if (IsMine(prev.vout[txin.prevout.n]))
return prev.vout[txin.prevout.n].nValue;
}
}
return 0;
}
bool CWallet::IsChange(const CTxOut& txout) const
{
CTxDestination address;
// TODO: fix handling of 'change' outputs. The assumption is that any
// payment to a TX_PUBKEYHASH that is mine but isn't in the address book
// is change. That assumption is likely to break when we implement multisignature
// wallets that return change back into a multi-signature-protected address;
// a better way of identifying which outputs are 'the send' and which are
// 'the change' will need to be implemented (maybe extend CWalletTx to remember
// which output, if any, was change).
if (ExtractDestination(txout.scriptPubKey, address) && ::IsMine(*this, address))
{
LOCK(cs_wallet);
if (!mapAddressBook.count(address))
return true;
}
return false;
}
int64_t CWalletTx::GetTxTime() const
{
int64_t n = nTimeSmart;
return n ? n : nTimeReceived;
}
int CWalletTx::GetRequestCount() const
{
// Returns -1 if it wasn't being tracked
int nRequests = -1;
{
LOCK(pwallet->cs_wallet);
if (IsCoinBase() || IsCoinStake())
{
// Generated block
if (hashBlock != 0)
{
map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock);
if (mi != pwallet->mapRequestCount.end())
nRequests = (*mi).second;
}
}
else
{
// Did anyone request this transaction?
map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(GetHash());
if (mi != pwallet->mapRequestCount.end())
{
nRequests = (*mi).second;
// How about the block it's in?
if (nRequests == 0 && hashBlock != 0)
{
map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock);
if (mi != pwallet->mapRequestCount.end())
nRequests = (*mi).second;
else
nRequests = 1; // If it's in someone else's block it must have got out
}
}
}
}
return nRequests;
}
void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
list<pair<CTxDestination, int64_t> >& listSent, int64_t& nFee, string& strSentAccount) const
{
nFee = 0;
listReceived.clear();
listSent.clear();
strSentAccount = strFromAccount;
// Compute fee:
int64_t nDebit = GetDebit();
if (nDebit > 0) // debit>0 means we signed/sent this transaction
{
int64_t nValueOut = GetValueOut();
nFee = nDebit - nValueOut;
}
// Sent/received.
BOOST_FOREACH(const CTxOut& txout, vout)
{
// Skip special stake out
if (txout.scriptPubKey.empty())
continue;
bool fIsMine;
// Only need to handle txouts if AT LEAST one of these is true:
// 1) they debit from us (sent)
// 2) the output is to us (received)
if (nDebit > 0)
{
// Don't report 'change' txouts
if (pwallet->IsChange(txout))
continue;
fIsMine = pwallet->IsMine(txout);
}
else if (!(fIsMine = pwallet->IsMine(txout)))
continue;
// In either case, we need to get the destination address
CTxDestination address;
if (!ExtractDestination(txout.scriptPubKey, address))
{
printf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
this->GetHash().ToString().c_str());
address = CNoDestination();
}
// If we are debited by the transaction, add the output as a "sent" entry
if (nDebit > 0)
listSent.push_back(make_pair(address, txout.nValue));
// If we are receiving the output, add it as a "received" entry
if (fIsMine)
listReceived.push_back(make_pair(address, txout.nValue));
}
}
void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nReceived,
int64_t& nSent, int64_t& nFee) const
{
nReceived = nSent = nFee = 0;
int64_t allFee;
string strSentAccount;
list<pair<CTxDestination, int64_t> > listReceived;
list<pair<CTxDestination, int64_t> > listSent;
GetAmounts(listReceived, listSent, allFee, strSentAccount);
if (strAccount == strSentAccount)
{
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& s, listSent)
nSent += s.second;
nFee = allFee;
}
{
LOCK(pwallet->cs_wallet);
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived)
{
if (pwallet->mapAddressBook.count(r.first))
{
map<CTxDestination, string>::const_iterator mi = pwallet->mapAddressBook.find(r.first);
if (mi != pwallet->mapAddressBook.end() && (*mi).second == strAccount)
nReceived += r.second;
}
else if (strAccount.empty())
{
nReceived += r.second;
}
}
}
}
void CWalletTx::AddSupportingTransactions(CTxDB& txdb)
{
vtxPrev.clear();
const int COPY_DEPTH = 3;
if (SetMerkleBranch() < COPY_DEPTH)
{
vector<uint256> vWorkQueue;
BOOST_FOREACH(const CTxIn& txin, vin)
vWorkQueue.push_back(txin.prevout.hash);
// This critsect is OK because txdb is already open
{
LOCK(pwallet->cs_wallet);
map<uint256, const CMerkleTx*> mapWalletPrev;
set<uint256> setAlreadyDone;
for (unsigned int i = 0; i < vWorkQueue.size(); i++)
{
uint256 hash = vWorkQueue[i];
if (setAlreadyDone.count(hash))
continue;
setAlreadyDone.insert(hash);
CMerkleTx tx;
map<uint256, CWalletTx>::const_iterator mi = pwallet->mapWallet.find(hash);
if (mi != pwallet->mapWallet.end())
{
tx = (*mi).second;
BOOST_FOREACH(const CMerkleTx& txWalletPrev, (*mi).second.vtxPrev)
mapWalletPrev[txWalletPrev.GetHash()] = &txWalletPrev;
}
else if (mapWalletPrev.count(hash))
{
tx = *mapWalletPrev[hash];
}
else if (!fClient && txdb.ReadDiskTx(hash, tx))
{
;
}
else
{
printf("ERROR: AddSupportingTransactions() : unsupported transaction\n");
continue;
}
int nDepth = tx.SetMerkleBranch();
vtxPrev.push_back(tx);
if (nDepth < COPY_DEPTH)
{
BOOST_FOREACH(const CTxIn& txin, tx.vin)
vWorkQueue.push_back(txin.prevout.hash);
}
}
}
}
reverse(vtxPrev.begin(), vtxPrev.end());
}
bool CWalletTx::WriteToDisk()
{
return CWalletDB(pwallet->strWalletFile).WriteTx(GetHash(), *this);
}
// Scan the block chain (starting in pindexStart) for transactions
// from or to us. If fUpdate is true, found transactions that already
// exist in the wallet will be updated.
int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
{
int ret = 0;
CBlockIndex* pindex = pindexStart;
{
LOCK(cs_wallet);
while (pindex)
{
// no need to read and scan block, if block was created before
// our wallet birthday (as adjusted for block time variability)
if (nTimeFirstKey && (pindex->nTime < (nTimeFirstKey - 7200))) {
pindex = pindex->pnext;
continue;
}
CBlock block;
block.ReadFromDisk(pindex, true);
BOOST_FOREACH(CTransaction& tx, block.vtx)
{
if (AddToWalletIfInvolvingMe(tx, &block, fUpdate))
ret++;
}
pindex = pindex->pnext;
}
}
return ret;
}
int CWallet::ScanForWalletTransaction(const uint256& hashTx)
{
CTransaction tx;
tx.ReadFromDisk(COutPoint(hashTx, 0));
if (AddToWalletIfInvolvingMe(tx, NULL, true, true))
return 1;
return 0;
}
void CWallet::ReacceptWalletTransactions()
{
CTxDB txdb("r");
bool fRepeat = true;
while (fRepeat)
{
LOCK(cs_wallet);
fRepeat = false;
vector<CDiskTxPos> vMissingTx;
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
{
CWalletTx& wtx = item.second;
if ((wtx.IsCoinBase() && wtx.IsSpent(0)) || (wtx.IsCoinStake() && wtx.IsSpent(1)))
continue;
CTxIndex txindex;
bool fUpdated = false;
if (txdb.ReadTxIndex(wtx.GetHash(), txindex))
{
// Update fSpent if a tx got spent somewhere else by a copy of wallet.dat
if (txindex.vSpent.size() != wtx.vout.size())
{
printf("ERROR: ReacceptWalletTransactions() : txindex.vSpent.size() %" PRIszu " != wtx.vout.size() %" PRIszu "\n", txindex.vSpent.size(), wtx.vout.size());
continue;
}
for (unsigned int i = 0; i < txindex.vSpent.size(); i++)
{
if (wtx.IsSpent(i))
continue;
if (!txindex.vSpent[i].IsNull() && IsMine(wtx.vout[i]))
{
wtx.MarkSpent(i);
fUpdated = true;
vMissingTx.push_back(txindex.vSpent[i]);
}
}
if (fUpdated)
{
printf("ReacceptWalletTransactions found spent coin %s BC %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
wtx.MarkDirty();
wtx.WriteToDisk();
}
}
else
{
// Re-accept any txes of ours that aren't already in a block
if (!(wtx.IsCoinBase() || wtx.IsCoinStake()))
wtx.AcceptWalletTransaction(txdb);
}
}
if (!vMissingTx.empty())
{
// TODO: optimize this to scan just part of the block chain?
if (ScanForWalletTransactions(pindexGenesisBlock))
fRepeat = true; // Found missing transactions: re-do re-accept.
}
}
}
void CWalletTx::RelayWalletTransaction(CTxDB& txdb)
{
BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
{
if (!(tx.IsCoinBase() || tx.IsCoinStake()))
{
uint256 hash = tx.GetHash();
if (!txdb.ContainsTx(hash))
RelayTransaction((CTransaction)tx, hash);
}
}
if (!(IsCoinBase() || IsCoinStake()))
{
uint256 hash = GetHash();
if (!txdb.ContainsTx(hash))
{
printf("Relaying wtx %s\n", hash.ToString().substr(0,10).c_str());
RelayTransaction((CTransaction)*this, hash);
}
}
}
void CWalletTx::RelayWalletTransaction()
{
CTxDB txdb("r");
RelayWalletTransaction(txdb);
}
void CWallet::ResendWalletTransactions(bool fForce)
{
if (!fForce)
{
// Do this infrequently and randomly to avoid giving away
// that these are our transactions.
static int64_t nNextTime;
if (GetTime() < nNextTime)
return;
bool fFirst = (nNextTime == 0);
nNextTime = GetTime() + GetRand(30 * 60);
if (fFirst)
return;
// Only do it if there's been a new block since last time
static int64_t nLastTime;
if (nTimeBestReceived < nLastTime)
return;
nLastTime = GetTime();
}
// Rebroadcast any of our txes that aren't in a block yet
printf("ResendWalletTransactions()\n");
CTxDB txdb("r");
{
LOCK(cs_wallet);
// Sort them in chronological order
multimap<unsigned int, CWalletTx*> mapSorted;
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
{
CWalletTx& wtx = item.second;
// Don't rebroadcast until it's had plenty of time that
// it should have gotten in already by now.
if (fForce || nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60)
mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx));
}
BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)
{
CWalletTx& wtx = *item.second;
if (wtx.CheckTransaction())
wtx.RelayWalletTransaction(txdb);
else
printf("ResendWalletTransactions() : CheckTransaction failed for transaction %s\n", wtx.GetHash().ToString().c_str());
}
}
}
//////////////////////////////////////////////////////////////////////////////
//
// Actions
//
int64_t CWallet::GetBalance() const
{
int64_t nTotal = 0;
{
LOCK(cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx* pcoin = &(*it).second;
if (pcoin->IsTrusted())
nTotal += pcoin->GetAvailableCredit();
}
}
return nTotal;
}
int64_t CWallet::GetUnconfirmedBalance() const
{
int64_t nTotal = 0;
{
LOCK(cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx* pcoin = &(*it).second;
if (!pcoin->IsFinal() || !pcoin->IsTrusted())
nTotal += pcoin->GetAvailableCredit();
}
}
return nTotal;
}
int64_t CWallet::GetImmatureBalance() const
{
int64_t nTotal = 0;
{
LOCK(cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx& pcoin = (*it).second;
if (pcoin.IsCoinBase() && pcoin.GetBlocksToMaturity() > 0 && pcoin.IsInMainChain())
nTotal += GetCredit(pcoin);
}
}
return nTotal;
}
// populate vCoins with vector of spendable COutputs
void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl) const
{
vCoins.clear();
{
LOCK(cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx* pcoin = &(*it).second;
if (!pcoin->IsFinal())
continue;
if (fOnlyConfirmed && !pcoin->IsTrusted())
continue;
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0)
continue;
if(pcoin->IsCoinStake() && pcoin->GetBlocksToMaturity() > 0)
continue;
int nDepth = pcoin->GetDepthInMainChain();
if (nDepth < 0)
continue;
for (unsigned int i = 0; i < pcoin->vout.size(); i++)
if (!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i]) && pcoin->vout[i].nValue >= nMinimumInputValue &&
(!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i)))
vCoins.push_back(COutput(pcoin, i, nDepth));
}
}
}
void CWallet::AvailableCoinsMinConf(vector<COutput>& vCoins, int nConf) const
{
vCoins.clear();
{
LOCK(cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx* pcoin = &(*it).second;
if (!pcoin->IsFinal())
continue;
if(pcoin->GetDepthInMainChain() < nConf)
continue;
for (unsigned int i = 0; i < pcoin->vout.size(); i++)
if (!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i]) && pcoin->vout[i].nValue >= nMinimumInputValue)
vCoins.push_back(COutput(pcoin, i, pcoin->GetDepthInMainChain()));
}
}
}
static void ApproximateBestSubset(vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > >vValue, int64_t nTotalLower, int64_t nTargetValue,
vector<char>& vfBest, int64_t& nBest, int iterations = 1000)
{
vector<char> vfIncluded;
vfBest.assign(vValue.size(), true);
nBest = nTotalLower;
for (int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++)
{
vfIncluded.assign(vValue.size(), false);
int64_t nTotal = 0;
bool fReachedTarget = false;
for (int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
{
for (unsigned int i = 0; i < vValue.size(); i++)
{
if (nPass == 0 ? rand() % 2 : !vfIncluded[i])
{
nTotal += vValue[i].first;
vfIncluded[i] = true;
if (nTotal >= nTargetValue)
{
fReachedTarget = true;
if (nTotal < nBest)
{
nBest = nTotal;
vfBest = vfIncluded;
}
nTotal -= vValue[i].first;
vfIncluded[i] = false;
}
}
}
}
}
}
// ppcoin: total coins staked (non-spendable until maturity)
int64_t CWallet::GetStake() const
{
int64_t nTotal = 0;
LOCK(cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx* pcoin = &(*it).second;
if (pcoin->IsCoinStake() && pcoin->GetBlocksToMaturity() > 0 && pcoin->GetDepthInMainChain() > 0)
nTotal += CWallet::GetCredit(*pcoin);
}
return nTotal;
}
int64_t CWallet::GetNewMint() const
{
int64_t nTotal = 0;
LOCK(cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx* pcoin = &(*it).second;
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0 && pcoin->GetDepthInMainChain() > 0)
nTotal += CWallet::GetCredit(*pcoin);
}
return nTotal;
}
bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, vector<COutput> vCoins, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
{
setCoinsRet.clear();
nValueRet = 0;
// List of values less than target
pair<int64_t, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
coinLowestLarger.first = std::numeric_limits<int64_t>::max();
coinLowestLarger.second.first = NULL;
vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > > vValue;
int64_t nTotalLower = 0;
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
BOOST_FOREACH(COutput output, vCoins)
{
const CWalletTx *pcoin = output.tx;
if (output.nDepth < (pcoin->IsFromMe() ? nConfMine : nConfTheirs))
continue;
int i = output.i;
// Follow the timestamp rules
if (pcoin->nTime > nSpendTime)
continue;
int64_t n = pcoin->vout[i].nValue;
pair<int64_t,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i));
if (n == nTargetValue)
{
setCoinsRet.insert(coin.second);
nValueRet += coin.first;
return true;
}
else if (n < nTargetValue + CENT)
{
vValue.push_back(coin);
nTotalLower += n;
}
else if (n < coinLowestLarger.first)
{
coinLowestLarger = coin;
}
}
if (nTotalLower == nTargetValue)
{
for (unsigned int i = 0; i < vValue.size(); ++i)
{
setCoinsRet.insert(vValue[i].second);
nValueRet += vValue[i].first;
}
return true;
}
if (nTotalLower < nTargetValue)
{
if (coinLowestLarger.second.first == NULL)
return false;
setCoinsRet.insert(coinLowestLarger.second);
nValueRet += coinLowestLarger.first;
return true;
}
// Solve subset sum by stochastic approximation
sort(vValue.rbegin(), vValue.rend(), CompareValueOnly());
vector<char> vfBest;
int64_t nBest;
ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest, 1000);
if (nBest != nTargetValue && nTotalLower >= nTargetValue + CENT)
ApproximateBestSubset(vValue, nTotalLower, nTargetValue + CENT, vfBest, nBest, 1000);
// If we have a bigger coin and (either the stochastic approximation didn't find a good solution,
// or the next bigger coin is closer), return the bigger coin
if (coinLowestLarger.second.first &&
((nBest != nTargetValue && nBest < nTargetValue + CENT) || coinLowestLarger.first <= nBest))
{
setCoinsRet.insert(coinLowestLarger.second);
nValueRet += coinLowestLarger.first;
}
else {
for (unsigned int i = 0; i < vValue.size(); i++)
if (vfBest[i])
{
setCoinsRet.insert(vValue[i].second);
nValueRet += vValue[i].first;
}
if (fDebug && GetBoolArg("-printpriority"))
{
//// debug print
printf("SelectCoins() best subset: ");
for (unsigned int i = 0; i < vValue.size(); i++)
if (vfBest[i])
printf("%s ", FormatMoney(vValue[i].first).c_str());
printf("total %s\n", FormatMoney(nBest).c_str());
}
}
return true;
}
bool CWallet::SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet, const CCoinControl* coinControl) const
{
vector<COutput> vCoins;
AvailableCoins(vCoins, true, coinControl);
// coin control -> return all selected outputs (we want all selected to go into the transaction for sure)
if (coinControl && coinControl->HasSelected())
{
BOOST_FOREACH(const COutput& out, vCoins)
{
nValueRet += out.tx->vout[out.i].nValue;
setCoinsRet.insert(make_pair(out.tx, out.i));
}
return (nValueRet >= nTargetValue);
}
return (SelectCoinsMinConf(nTargetValue, nSpendTime, 1, 6, vCoins, setCoinsRet, nValueRet) ||
SelectCoinsMinConf(nTargetValue, nSpendTime, 1, 1, vCoins, setCoinsRet, nValueRet) ||
SelectCoinsMinConf(nTargetValue, nSpendTime, 0, 1, vCoins, setCoinsRet, nValueRet));
}
// Select some coins without random shuffle or best subset approximation
bool CWallet::SelectCoinsSimple(int64_t nTargetValue, unsigned int nSpendTime, int nMinConf, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
{
vector<COutput> vCoins;
AvailableCoinsMinConf(vCoins, nMinConf);
setCoinsRet.clear();
nValueRet = 0;
BOOST_FOREACH(COutput output, vCoins)
{
const CWalletTx *pcoin = output.tx;
int i = output.i;
// Stop if we've chosen enough inputs
if (nValueRet >= nTargetValue)
break;
// Follow the timestamp rules
if (pcoin->nTime > nSpendTime)
continue;
int64_t n = pcoin->vout[i].nValue;
pair<int64_t,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i));
if (n >= nTargetValue)
{
// If input value is greater or equal to target then simply insert
// it into the current subset and exit
setCoinsRet.insert(coin.second);
nValueRet += coin.first;
break;
}
else if (n < nTargetValue + CENT)
{
setCoinsRet.insert(coin.second);
nValueRet += coin.first;
}
}
return true;
}
bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, int nSplitBlock, const CCoinControl* coinControl)
{
int64_t nValue = 0;
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend)
{
if (nValue < 0)
return false;
nValue += s.second;
}
if (vecSend.empty() || nValue < 0)
return false;
wtxNew.BindWallet(this);
{
LOCK2(cs_main, cs_wallet);
// txdb must be opened before the mapWallet lock
CTxDB txdb("r");
{
nFeeRet = nTransactionFee;
if(fSplitBlock)
nFeeRet = 1 * COIN;
while (true)
{
wtxNew.vin.clear();
wtxNew.vout.clear();
wtxNew.fFromMe = true;
int64_t nTotalValue = nValue + nFeeRet;
double dPriority = 0;
if( nSplitBlock < 1 )
nSplitBlock = 1;
// vouts to the payees
if (!fSplitBlock)
{
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend)
wtxNew.vout.push_back(CTxOut(s.second, s.first));
}
else
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend)
{
for(int nCount = 0; nCount < nSplitBlock; nCount++)
{
if(nCount == nSplitBlock -1)
{
uint64_t nRemainder = s.second % nSplitBlock;
wtxNew.vout.push_back(CTxOut((s.second / nSplitBlock) + nRemainder, s.first));
}
else
wtxNew.vout.push_back(CTxOut(s.second / nSplitBlock, s.first));
}
}
// Choose coins to use
set<pair<const CWalletTx*,unsigned int> > setCoins;
int64_t nValueIn = 0;
if (!SelectCoins(nTotalValue, wtxNew.nTime, setCoins, nValueIn, coinControl))
return false;
CTxDestination utxoAddress;
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
{
int64_t nCredit = pcoin.first->vout[pcoin.second].nValue;
dPriority += (double)nCredit * pcoin.first->GetDepthInMainChain();
ExtractDestination(pcoin.first->vout[pcoin.second].scriptPubKey, utxoAddress);
}
int64_t nChange = nValueIn - nValue - nFeeRet;
// if sub-cent change is required, the fee must be raised to at least MIN_TX_FEE
// or until nChange becomes zero
// NOTE: this depends on the exact behaviour of GetMinFee
if (nFeeRet < MIN_TX_FEE && nChange > 0 && nChange < CENT)
{
int64_t nMoveToFee = min(nChange, MIN_TX_FEE - nFeeRet);
nChange -= nMoveToFee;
nFeeRet += nMoveToFee;
}
if (nChange > 0)
{
// Fill a vout to ourself
// TODO: pass in scriptChange instead of reservekey so
// change transaction isn't always pay-to-bitcoin-address
CScript scriptChange;
// coin control: send change to custom address
if (coinControl && coinControl->fReturnChange == true)
scriptChange.SetDestination(utxoAddress);
else if (coinControl && !boost::get<CNoDestination>(&coinControl->destChange))
scriptChange.SetDestination(coinControl->destChange);
// no coin control: send change to newly generated address
else
{
// Note: We use a new key here to keep it from being obvious which side is the change.
// The drawback is that by not reusing a previous key, the change may be lost if a
// backup is restored, if the backup doesn't have the new private key for the change.
// If we reused the old key, it would be possible to add code to look for and
// rediscover unknown transactions that were written with keys of ours to recover
// post-backup change.
// Reserve a new key pair from key pool
CPubKey vchPubKey;
assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked
scriptChange.SetDestination(vchPubKey.GetID());
}
// Insert change txn at random position:
vector<CTxOut>::iterator position = wtxNew.vout.begin()+GetRandInt(wtxNew.vout.size());
wtxNew.vout.insert(position, CTxOut(nChange, scriptChange));
}
else
reservekey.ReturnKey();
// Fill vin
BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins)
wtxNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second));
// Sign
int nIn = 0;
BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins)
if (!SignSignature(*this, *coin.first, wtxNew, nIn++))
return false;
// Limit size
unsigned int nBytes = ::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK, PROTOCOL_VERSION);
if (nBytes >= MAX_BLOCK_SIZE_GEN/5)
return false;
dPriority /= nBytes;
// Check that enough fee is included
int64_t nPayFee = nTransactionFee * (1 + (int64_t)nBytes / 1000);
int64_t nMinFee = wtxNew.GetMinFee(1, GMF_SEND, nBytes);
if (nFeeRet < max(nPayFee, nMinFee))
{
nFeeRet = max(nPayFee, nMinFee);
continue;
}
// Fill vtxPrev by copying from previous transactions vtxPrev
wtxNew.AddSupportingTransactions(txdb);
wtxNew.fTimeReceivedIsTxTime = true;
break;
}
}
}
return true;
}
bool CWallet::CreateTransaction(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl)
{
vector< pair<CScript, int64_t> > vecSend;
vecSend.push_back(make_pair(scriptPubKey, nValue));
return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, 1, coinControl);
}
// NovaCoin: get current stake weight
bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64_t& nMinWeight, uint64_t& nMaxWeight, uint64_t& nWeight)
{
// Choose coins to use
int64_t nBalance = GetBalance();
if (nBalance <= nReserveBalance)
return false;
vector<const CWalletTx*> vwtxPrev;
set<pair<const CWalletTx*,unsigned int> > setCoins;
int64_t nValueIn = 0;
if (!SelectCoinsSimple(nBalance - nReserveBalance, GetTime(), nCoinbaseMaturity + 10, setCoins, nValueIn))
return false;
if (setCoins.empty())
return false;
CTxDB txdb("r");
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
{
CTxIndex txindex;
{
LOCK2(cs_main, cs_wallet);
if (!txdb.ReadTxIndex(pcoin.first->GetHash(), txindex))
continue;
}
int64_t nTimeWeight = GetWeight((int64_t)pcoin.first->nTime, (int64_t)GetTime());
CBigNum bnCoinDayWeight = CBigNum(pcoin.first->vout[pcoin.second].nValue) * nTimeWeight / COIN / (24 * 60 * 60);
// Weight is greater than zero
if (nTimeWeight > 0)
{
nWeight += bnCoinDayWeight.getuint64();
}
// Weight is greater than zero, but the maximum value isn't reached yet
if (nTimeWeight > 0 && nTimeWeight < nStakeMaxAge)
{
nMinWeight += bnCoinDayWeight.getuint64();
}
// Maximum weight was reached
if (nTimeWeight == nStakeMaxAge)
{
nMaxWeight += bnCoinDayWeight.getuint64();
}
}
return true;
}
bool CWallet::GetStakeWeightFromValue(const int64_t& nTime, const int64_t& nValue, uint64_t& nWeight)
{
// This is a negative value when there is no weight. But set it to zero
// so the user is not confused. Used in reporting in Coin Control.
// Descisions based on this function should be used with care.
int64_t nTimeWeight = GetWeight(nTime, (int64_t)GetTime());
if (nTimeWeight < 0 )
nTimeWeight=0;
CBigNum bnCoinDayWeight = CBigNum(nValue) * nTimeWeight / COIN / (24 * 60 * 60);
nWeight = bnCoinDayWeight.getuint64();
return true;
}
bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, int64_t nFees, CTransaction& txNew, CKey& key)
{
CBlockIndex* pindexPrev = pindexBest;
CBigNum bnTargetPerCoinDay;
bnTargetPerCoinDay.SetCompact(nBits);
txNew.vin.clear();
txNew.vout.clear();
// Mark coin stake transaction
CScript scriptEmpty;
scriptEmpty.clear();
txNew.vout.push_back(CTxOut(0, scriptEmpty));
// Choose coins to use
int64_t nBalance = GetBalance();
if (nBalance <= nReserveBalance)
return false;
vector<const CWalletTx*> vwtxPrev;
set<pair<const CWalletTx*,unsigned int> > setCoins;
int64_t nValueIn = 0;
// Select coins with suitable depth
if (!SelectCoinsSimple(nBalance - nReserveBalance, txNew.nTime, nCoinbaseMaturity + 10, setCoins, nValueIn))
return false;
if (setCoins.empty())
return false;
int64_t nCredit = 0;
CScript scriptPubKeyKernel;
CTxDB txdb("r");
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
{
CTxIndex txindex;
{
LOCK2(cs_main, cs_wallet);
if (!txdb.ReadTxIndex(pcoin.first->GetHash(), txindex))
continue;
}
// Read block header
CBlock block;
{
LOCK2(cs_main, cs_wallet);
if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
continue;
}
static int nMaxStakeSearchInterval = 60;
if (block.GetBlockTime() + nStakeMinAge > txNew.nTime - nMaxStakeSearchInterval)
continue; // only count coins meeting min age requirement
bool fKernelFound = false;
for (unsigned int n=0; n<min(nSearchInterval,(int64_t)nMaxStakeSearchInterval) && !fKernelFound && !fShutdown && pindexPrev == pindexBest; n++)
{
// Search backward in time from the given txNew timestamp
// Search nSearchInterval seconds back up to nMaxStakeSearchInterval
uint256 hashProofOfStake = 0, targetProofOfStake = 0;
COutPoint prevoutStake = COutPoint(pcoin.first->GetHash(), pcoin.second);
if (CheckStakeKernelHash(nBits, block, txindex.pos.nTxPos - txindex.pos.nBlockPos, *pcoin.first, prevoutStake, txNew.nTime - n, hashProofOfStake, targetProofOfStake))
{
// Found a kernel
if (fDebug && GetBoolArg("-printcoinstake"))
printf("CreateCoinStake : kernel found\n");
vector<valtype> vSolutions;
txnouttype whichType;
CScript scriptPubKeyOut;
scriptPubKeyKernel = pcoin.first->vout[pcoin.second].scriptPubKey;
if (!Solver(scriptPubKeyKernel, whichType, vSolutions))
{
if (fDebug && GetBoolArg("-printcoinstake"))
printf("CreateCoinStake : failed to parse kernel\n");
break;
}
if (fDebug && GetBoolArg("-printcoinstake"))
printf("CreateCoinStake : parsed kernel type=%d\n", whichType);
if (whichType != TX_PUBKEY && whichType != TX_PUBKEYHASH)
{
if (fDebug && GetBoolArg("-printcoinstake"))
printf("CreateCoinStake : no support for kernel type=%d\n", whichType);
break; // only support pay to public key and pay to address
}
if (whichType == TX_PUBKEYHASH) // pay to address type
{
// convert to pay to public key type
if (!keystore.GetKey(uint160(vSolutions[0]), key))
{
if (fDebug && GetBoolArg("-printcoinstake"))
printf("CreateCoinStake : failed to get key for kernel type=%d\n", whichType);
break; // unable to find corresponding public key
}
scriptPubKeyOut << key.GetPubKey() << OP_CHECKSIG;
}
if (whichType == TX_PUBKEY)
{
valtype& vchPubKey = vSolutions[0];
if (!keystore.GetKey(Hash160(vchPubKey), key))
{
if (fDebug && GetBoolArg("-printcoinstake"))
printf("CreateCoinStake : failed to get key for kernel type=%d\n", whichType);
break; // unable to find corresponding public key
}
if (key.GetPubKey() != vchPubKey)
{
if (fDebug && GetBoolArg("-printcoinstake"))
printf("CreateCoinStake : invalid key for kernel type=%d\n", whichType);
break; // keys mismatch
}
scriptPubKeyOut = scriptPubKeyKernel;
}
txNew.nTime -= n;
txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
nCredit += pcoin.first->vout[pcoin.second].nValue;
vwtxPrev.push_back(pcoin.first);
txNew.vout.push_back(CTxOut(0, scriptPubKeyOut));
uint64_t nCoinAge;
CTxDB txdb("r");
if (txNew.GetCoinAge(txdb, nCoinAge))
{
uint64_t nTotalSize = pcoin.first->vout[pcoin.second].nValue + GetProofOfStakeReward(nCoinAge, 0, txNew.nTime);
if (nTotalSize / 2 > nStakeSplitThreshold * COIN)
txNew.vout.push_back(CTxOut(0, scriptPubKeyOut)); //split stake
}
if (fDebug && GetBoolArg("-printcoinstake"))
printf("CreateCoinStake : added kernel type=%d\n", whichType);
fKernelFound = true;
break;
}
}
if (fKernelFound || fShutdown)
break; // if kernel is found stop searching
}
if (nCredit == 0 || nCredit > nBalance - nReserveBalance)
return false;
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
{
// Attempt to add more inputs
// Only add coins of the same key/address as kernel
if (txNew.vout.size() == 2 && ((pcoin.first->vout[pcoin.second].scriptPubKey == scriptPubKeyKernel || pcoin.first->vout[pcoin.second].scriptPubKey == txNew.vout[1].scriptPubKey))
&& pcoin.first->GetHash() != txNew.vin[0].prevout.hash)
{
int64_t nTimeWeight = GetWeight((int64_t)pcoin.first->nTime, (int64_t)txNew.nTime);
// Stop adding more inputs if already too many inputs
if (txNew.vin.size() >= 100)
break;
// Stop adding more inputs if value is already pretty significant
if (nCredit >= nStakeCombineThreshold)
break;
// Stop adding inputs if reached reserve limit
if (nCredit + pcoin.first->vout[pcoin.second].nValue > nBalance - nReserveBalance)
break;
// Do not add additional significant input
if (pcoin.first->vout[pcoin.second].nValue >= nStakeCombineThreshold)
continue;
// Do not add input that is still too young
if (nTimeWeight < nStakeMinAge)
continue;
txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
nCredit += pcoin.first->vout[pcoin.second].nValue;
vwtxPrev.push_back(pcoin.first);
}
}
// Calculate coin age reward
{
uint64_t nCoinAge;
CTxDB txdb("r");
if (!txNew.GetCoinAge(txdb, nCoinAge))
return error("CreateCoinStake : failed to calculate coin age");
int64_t nReward = GetProofOfStakeReward(nCoinAge, nFees, txNew.nTime);
if (nReward <= 0)
return false;
nCredit += nReward;
}
// Set output amount
if (txNew.vout.size() == 3)
{
txNew.vout[1].nValue = (nCredit / 2 / CENT) * CENT;
txNew.vout[2].nValue = nCredit - txNew.vout[1].nValue;
}
else
txNew.vout[1].nValue = nCredit;
// Sign
int nIn = 0;
BOOST_FOREACH(const CWalletTx* pcoin, vwtxPrev)
{
if (!SignSignature(*this, *pcoin, txNew, nIn++))
return error("CreateCoinStake : failed to sign coinstake");
}
// Limit size
unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
if (nBytes >= MAX_BLOCK_SIZE_GEN/5)
return error("CreateCoinStake : exceeded coinstake size limit");
// Successfully generated coinstake
return true;
}
// Call after CreateTransaction unless you want to abort
bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
{
{
LOCK2(cs_main, cs_wallet);
printf("CommitTransaction:\n%s", wtxNew.ToString().c_str());
{
// This is only to keep the database open to defeat the auto-flush for the
// duration of this scope. This is the only place where this optimization
// maybe makes sense; please don't do it anywhere else.
CWalletDB* pwalletdb = fFileBacked ? new CWalletDB(strWalletFile,"r") : NULL;
// Take key pair from key pool so it won't be used again
reservekey.KeepKey();
// Add tx to wallet, because if it has change it's also ours,
// otherwise just for transaction history.
AddToWallet(wtxNew);
// Mark old coins as spent
set<CWalletTx*> setCoins;
BOOST_FOREACH(const CTxIn& txin, wtxNew.vin)
{
CWalletTx &coin = mapWallet[txin.prevout.hash];
coin.BindWallet(this);
coin.MarkSpent(txin.prevout.n);
coin.WriteToDisk();
NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED);
}
if (fFileBacked)
delete pwalletdb;
}
// Track how many getdata requests our transaction gets
mapRequestCount[wtxNew.GetHash()] = 0;
// Broadcast
if (!wtxNew.AcceptToMemoryPool())
{
// This must not fail. The transaction has already been signed and recorded.
printf("CommitTransaction() : Error: Transaction not valid\n");
return false;
}
wtxNew.RelayWalletTransaction();
}
return true;
}
string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee)
{
CReserveKey reservekey(this);
int64_t nFeeRequired;
if (IsLocked())
{
string strError = _("Error: Wallet locked, unable to create transaction ");
printf("SendMoney() : %s", strError.c_str());
return strError;
}
if (fWalletUnlockStakingOnly)
{
string strError = _("Error: Wallet unlocked for staking only, unable to create transaction.");
printf("SendMoney() : %s", strError.c_str());
return strError;
}
if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired))
{
string strError;
if (nValue + nFeeRequired > GetBalance())
strError = strprintf(_("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds "), FormatMoney(nFeeRequired).c_str());
else
strError = _("Error: Transaction creation failed ");
printf("SendMoney() : %s", strError.c_str());
return strError;
}
if (fAskFee && !uiInterface.ThreadSafeAskFee(nFeeRequired, _("Sending...")))
return "ABORTED";
if (!CommitTransaction(wtxNew, reservekey))
return _("Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here.");
return "";
}
string CWallet::SendMoneyToDestination(const CTxDestination& address, int64_t nValue, CWalletTx& wtxNew, bool fAskFee)
{
// Check amount
if (nValue <= 0)
return _("Invalid amount");
if (nValue + nTransactionFee > GetBalance())
return _("Insufficient funds");
// Parse Bitcoin address
CScript scriptPubKey;
scriptPubKey.SetDestination(address);
return SendMoney(scriptPubKey, nValue, wtxNew, fAskFee);
}
DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
{
if (!fFileBacked)
return DB_LOAD_OK;
fFirstRunRet = false;
DBErrors nLoadWalletRet = CWalletDB(strWalletFile,"cr+").LoadWallet(this);
if (nLoadWalletRet == DB_NEED_REWRITE)
{
if (CDB::Rewrite(strWalletFile, "\x04pool"))
{
setKeyPool.clear();
// Note: can't top-up keypool here, because wallet is locked.
// User will be prompted to unlock wallet the next operation
// the requires a new key.
}
}
if (nLoadWalletRet != DB_LOAD_OK)
return nLoadWalletRet;
fFirstRunRet = !vchDefaultKey.IsValid();
NewThread(ThreadFlushWalletDB, &strWalletFile);
return DB_LOAD_OK;
}
bool CWallet::SetAddressBookName(const CTxDestination& address, const string& strName)
{
std::map<CTxDestination, std::string>::iterator mi = mapAddressBook.find(address);
mapAddressBook[address] = strName;
NotifyAddressBookChanged(this, address, strName, ::IsMine(*this, address), (mi == mapAddressBook.end()) ? CT_NEW : CT_UPDATED);
if (!fFileBacked)
return false;
return CWalletDB(strWalletFile).WriteName(CBitcoinAddress(address).ToString(), strName);
}
bool CWallet::DelAddressBookName(const CTxDestination& address)
{
mapAddressBook.erase(address);
NotifyAddressBookChanged(this, address, "", ::IsMine(*this, address), CT_DELETED);
if (!fFileBacked)
return false;
return CWalletDB(strWalletFile).EraseName(CBitcoinAddress(address).ToString());
}
void CWallet::PrintWallet(const CBlock& block)
{
{
LOCK(cs_wallet);
if (block.IsProofOfWork() && mapWallet.count(block.vtx[0].GetHash()))
{
CWalletTx& wtx = mapWallet[block.vtx[0].GetHash()];
printf(" mine: %d %d %" PRId64 "", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit());
}
if (block.IsProofOfStake() && mapWallet.count(block.vtx[1].GetHash()))
{
CWalletTx& wtx = mapWallet[block.vtx[1].GetHash()];
printf(" stake: %d %d %" PRId64 "", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit());
}
}
printf("\n");
}
bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx)
{
{
LOCK(cs_wallet);
map<uint256, CWalletTx>::iterator mi = mapWallet.find(hashTx);
if (mi != mapWallet.end())
{
wtx = (*mi).second;
return true;
}
}
return false;
}
bool CWallet::SetDefaultKey(const CPubKey &vchPubKey)
{
if (fFileBacked)
{
if (!CWalletDB(strWalletFile).WriteDefaultKey(vchPubKey))
return false;
}
vchDefaultKey = vchPubKey;
return true;
}
bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut)
{
if (!pwallet->fFileBacked)
return false;
strWalletFileOut = pwallet->strWalletFile;
return true;
}
//
// Mark old keypool keys as used,
// and generate all new keys
//
bool CWallet::NewKeyPool()
{
{
LOCK(cs_wallet);
CWalletDB walletdb(strWalletFile);
BOOST_FOREACH(int64_t nIndex, setKeyPool)
walletdb.ErasePool(nIndex);
setKeyPool.clear();
if (IsLocked())
return false;
int64_t nKeys = max(GetArg("-keypool", 100), (int64_t)0);
for (int i = 0; i < nKeys; i++)
{
int64_t nIndex = i+1;
walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey()));
setKeyPool.insert(nIndex);
}
printf("CWallet::NewKeyPool wrote %" PRId64 " new keys\n", nKeys);
}
return true;
}
bool CWallet::TopUpKeyPool(unsigned int nSize)
{
{
LOCK(cs_wallet);
if (IsLocked())
return false;
CWalletDB walletdb(strWalletFile);
// Top up key pool
unsigned int nTargetSize;
if (nSize > 0)
nTargetSize = nSize;
else
nTargetSize = max(GetArg("-keypool", 100), (int64_t)0);
while (setKeyPool.size() < (nTargetSize + 1))
{
int64_t nEnd = 1;
if (!setKeyPool.empty())
nEnd = *(--setKeyPool.end()) + 1;
if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey())))
throw runtime_error("TopUpKeyPool() : writing generated key failed");
setKeyPool.insert(nEnd);
printf("keypool added key %" PRId64 ", size=%" PRIszu "\n", nEnd, setKeyPool.size());
}
}
return true;
}
void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool)
{
nIndex = -1;
keypool.vchPubKey = CPubKey();
{
LOCK(cs_wallet);
if (!IsLocked())
TopUpKeyPool();
// Get the oldest key
if(setKeyPool.empty())
return;
CWalletDB walletdb(strWalletFile);
nIndex = *(setKeyPool.begin());
setKeyPool.erase(setKeyPool.begin());
if (!walletdb.ReadPool(nIndex, keypool))
throw runtime_error("ReserveKeyFromKeyPool() : read failed");
if (!HaveKey(keypool.vchPubKey.GetID()))
throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool");
assert(keypool.vchPubKey.IsValid());
if (fDebug && GetBoolArg("-printkeypool"))
printf("keypool reserve %" PRId64 "\n", nIndex);
}
}
int64_t CWallet::AddReserveKey(const CKeyPool& keypool)
{
{
LOCK2(cs_main, cs_wallet);
CWalletDB walletdb(strWalletFile);
int64_t nIndex = 1 + *(--setKeyPool.end());
if (!walletdb.WritePool(nIndex, keypool))
throw runtime_error("AddReserveKey() : writing added key failed");
setKeyPool.insert(nIndex);
return nIndex;
}
return -1;
}
void CWallet::KeepKey(int64_t nIndex)
{
// Remove from key pool
if (fFileBacked)
{
CWalletDB walletdb(strWalletFile);
walletdb.ErasePool(nIndex);
}
if(fDebug)
printf("keypool keep %" PRId64 "\n", nIndex);
}
void CWallet::ReturnKey(int64_t nIndex)
{
// Return to key pool
{
LOCK(cs_wallet);
setKeyPool.insert(nIndex);
}
if(fDebug)
printf("keypool return %" PRId64 "\n", nIndex);
}
bool CWallet::GetKeyFromPool(CPubKey& result, bool fAllowReuse)
{
int64_t nIndex = 0;
CKeyPool keypool;
{
LOCK(cs_wallet);
ReserveKeyFromKeyPool(nIndex, keypool);
if (nIndex == -1)
{
if (fAllowReuse && vchDefaultKey.IsValid())
{
result = vchDefaultKey;
return true;
}
if (IsLocked()) return false;
result = GenerateNewKey();
return true;
}
KeepKey(nIndex);
result = keypool.vchPubKey;
}
return true;
}
int64_t CWallet::GetOldestKeyPoolTime()
{
int64_t nIndex = 0;
CKeyPool keypool;
ReserveKeyFromKeyPool(nIndex, keypool);
if (nIndex == -1)
return GetTime();
ReturnKey(nIndex);
return keypool.nTime;
}
std::map<CTxDestination, int64_t> CWallet::GetAddressBalances()
{
map<CTxDestination, int64_t> balances;
{
LOCK(cs_wallet);
BOOST_FOREACH(PAIRTYPE(uint256, CWalletTx) walletEntry, mapWallet)
{
CWalletTx *pcoin = &walletEntry.second;
if (!pcoin->IsFinal() || !pcoin->IsTrusted())
continue;
if ((pcoin->IsCoinBase() || pcoin->IsCoinStake()) && pcoin->GetBlocksToMaturity() > 0)
continue;
int nDepth = pcoin->GetDepthInMainChain();
if (nDepth < (pcoin->IsFromMe() ? 0 : 1))
continue;
for (unsigned int i = 0; i < pcoin->vout.size(); i++)
{
CTxDestination addr;
if (!IsMine(pcoin->vout[i]))
continue;
if(!ExtractDestination(pcoin->vout[i].scriptPubKey, addr))
continue;
int64_t n = pcoin->IsSpent(i) ? 0 : pcoin->vout[i].nValue;
if (!balances.count(addr))
balances[addr] = 0;
balances[addr] += n;
}
}
}
return balances;
}
set< set<CTxDestination> > CWallet::GetAddressGroupings()
{
set< set<CTxDestination> > groupings;
set<CTxDestination> grouping;
BOOST_FOREACH(PAIRTYPE(uint256, CWalletTx) walletEntry, mapWallet)
{
CWalletTx *pcoin = &walletEntry.second;
if (pcoin->vin.size() > 0 && IsMine(pcoin->vin[0]))
{
// group all input addresses with each other
BOOST_FOREACH(CTxIn txin, pcoin->vin)
{
CTxDestination address;
if(!ExtractDestination(mapWallet[txin.prevout.hash].vout[txin.prevout.n].scriptPubKey, address))
continue;
grouping.insert(address);
}
// group change with input addresses
BOOST_FOREACH(CTxOut txout, pcoin->vout)
if (IsChange(txout))
{
CWalletTx tx = mapWallet[pcoin->vin[0].prevout.hash];
CTxDestination txoutAddr;
if(!ExtractDestination(txout.scriptPubKey, txoutAddr))
continue;
grouping.insert(txoutAddr);
}
groupings.insert(grouping);
grouping.clear();
}
// group lone addrs by themselves
for (unsigned int i = 0; i < pcoin->vout.size(); i++)
if (IsMine(pcoin->vout[i]))
{
CTxDestination address;
if(!ExtractDestination(pcoin->vout[i].scriptPubKey, address))
continue;
grouping.insert(address);
groupings.insert(grouping);
grouping.clear();
}
}
set< set<CTxDestination>* > uniqueGroupings; // a set of pointers to groups of addresses
map< CTxDestination, set<CTxDestination>* > setmap; // map addresses to the unique group containing it
BOOST_FOREACH(set<CTxDestination> grouping, groupings)
{
// make a set of all the groups hit by this new group
set< set<CTxDestination>* > hits;
map< CTxDestination, set<CTxDestination>* >::iterator it;
BOOST_FOREACH(CTxDestination address, grouping)
if ((it = setmap.find(address)) != setmap.end())
hits.insert((*it).second);
// merge all hit groups into a new single group and delete old groups
set<CTxDestination>* merged = new set<CTxDestination>(grouping);
BOOST_FOREACH(set<CTxDestination>* hit, hits)
{
merged->insert(hit->begin(), hit->end());
uniqueGroupings.erase(hit);
delete hit;
}
uniqueGroupings.insert(merged);
// update setmap
BOOST_FOREACH(CTxDestination element, *merged)
setmap[element] = merged;
}
set< set<CTxDestination> > ret;
BOOST_FOREACH(set<CTxDestination>* uniqueGrouping, uniqueGroupings)
{
ret.insert(*uniqueGrouping);
delete uniqueGrouping;
}
return ret;
}
// ppcoin: check 'spent' consistency between wallet and txindex
// ppcoin: fix wallet spent state according to txindex
void CWallet::FixSpentCoins(int& nMismatchFound, int64_t& nBalanceInQuestion, bool fCheckOnly)
{
nMismatchFound = 0;
nBalanceInQuestion = 0;
LOCK(cs_wallet);
vector<CWalletTx*> vCoins;
vCoins.reserve(mapWallet.size());
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
vCoins.push_back(&(*it).second);
CTxDB txdb("r");
BOOST_FOREACH(CWalletTx* pcoin, vCoins)
{
// Find the corresponding transaction index
CTxIndex txindex;
if (!txdb.ReadTxIndex(pcoin->GetHash(), txindex))
continue;
for (unsigned int n=0; n < pcoin->vout.size(); n++)
{
if (IsMine(pcoin->vout[n]) && pcoin->IsSpent(n) && (txindex.vSpent.size() <= n || txindex.vSpent[n].IsNull()))
{
printf("FixSpentCoins found lost coin %s bitvier %s[%d], %s\n",
FormatMoney(pcoin->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n, fCheckOnly? "repair not attempted" : "repairing");
nMismatchFound++;
nBalanceInQuestion += pcoin->vout[n].nValue;
if (!fCheckOnly)
{
pcoin->MarkUnspent(n);
pcoin->WriteToDisk();
}
}
else if (IsMine(pcoin->vout[n]) && !pcoin->IsSpent(n) && (txindex.vSpent.size() > n && !txindex.vSpent[n].IsNull()))
{
printf("FixSpentCoins found spent coin %s bitvier %s[%d], %s\n",
FormatMoney(pcoin->vout[n].nValue).c_str(), pcoin->GetHash().ToString().c_str(), n, fCheckOnly? "repair not attempted" : "repairing");
nMismatchFound++;
nBalanceInQuestion += pcoin->vout[n].nValue;
if (!fCheckOnly)
{
pcoin->MarkSpent(n);
pcoin->WriteToDisk();
}
}
}
}
}
// ppcoin: disable transaction (only for coinstake)
void CWallet::DisableTransaction(const CTransaction &tx)
{
if (!tx.IsCoinStake() || !IsFromMe(tx))
return; // only disconnecting coinstake requires marking input unspent
LOCK(cs_wallet);
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
map<uint256, CWalletTx>::iterator mi = mapWallet.find(txin.prevout.hash);
if (mi != mapWallet.end())
{
CWalletTx& prev = (*mi).second;
if (txin.prevout.n < prev.vout.size() && IsMine(prev.vout[txin.prevout.n]))
{
prev.MarkUnspent(txin.prevout.n);
prev.WriteToDisk();
}
}
}
}
bool CReserveKey::GetReservedKey(CPubKey& pubkey)
{
if (nIndex == -1)
{
CKeyPool keypool;
pwallet->ReserveKeyFromKeyPool(nIndex, keypool);
if (nIndex != -1)
vchPubKey = keypool.vchPubKey;
else {
if (pwallet->vchDefaultKey.IsValid()) {
printf("CReserveKey::GetReservedKey(): Warning: Using default key instead of a new key, top up your keypool!");
vchPubKey = pwallet->vchDefaultKey;
} else
return false;
}
}
assert(vchPubKey.IsValid());
pubkey = vchPubKey;
return true;
}
void CReserveKey::KeepKey()
{
if (nIndex != -1)
pwallet->KeepKey(nIndex);
nIndex = -1;
vchPubKey = CPubKey();
}
void CReserveKey::ReturnKey()
{
if (nIndex != -1)
pwallet->ReturnKey(nIndex);
nIndex = -1;
vchPubKey = CPubKey();
}
void CWallet::GetAllReserveKeys(set<CKeyID>& setAddress) const
{
setAddress.clear();
CWalletDB walletdb(strWalletFile);
LOCK2(cs_main, cs_wallet);
BOOST_FOREACH(const int64_t& id, setKeyPool)
{
CKeyPool keypool;
if (!walletdb.ReadPool(id, keypool))
throw runtime_error("GetAllReserveKeyHashes() : read failed");
assert(keypool.vchPubKey.IsValid());
CKeyID keyID = keypool.vchPubKey.GetID();
if (!HaveKey(keyID))
throw runtime_error("GetAllReserveKeyHashes() : unknown key in key pool");
setAddress.insert(keyID);
}
}
void CWallet::UpdatedTransaction(const uint256 &hashTx)
{
{
LOCK(cs_wallet);
// Only notify UI if this transaction is in this wallet
map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(hashTx);
if (mi != mapWallet.end())
NotifyTransactionChanged(this, hashTx, CT_UPDATED);
}
}
void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
mapKeyBirth.clear();
// get birth times for keys with metadata
for (std::map<CKeyID, CKeyMetadata>::const_iterator it = mapKeyMetadata.begin(); it != mapKeyMetadata.end(); it++)
if (it->second.nCreateTime)
mapKeyBirth[it->first] = it->second.nCreateTime;
// map in which we'll infer heights of other keys
CBlockIndex *pindexMax = FindBlockByHeight(std::max(0, nBestHeight - 144)); // the tip can be reorganised; use a 144-block safety margin
std::map<CKeyID, CBlockIndex*> mapKeyFirstBlock;
std::set<CKeyID> setKeys;
GetKeys(setKeys);
BOOST_FOREACH(const CKeyID &keyid, setKeys) {
if (mapKeyBirth.count(keyid) == 0)
mapKeyFirstBlock[keyid] = pindexMax;
}
setKeys.clear();
// if there are no such keys, we're done
if (mapKeyFirstBlock.empty())
return;
// find first block that affects those keys, if there are any left
std::vector<CKeyID> vAffected;
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); it++) {
// iterate over all wallet transactions...
const CWalletTx &wtx = (*it).second;
std::map<uint256, CBlockIndex*>::const_iterator blit = mapBlockIndex.find(wtx.hashBlock);
if (blit != mapBlockIndex.end() && blit->second->IsInMainChain()) {
// ... which are already in a block
int nHeight = blit->second->nHeight;
BOOST_FOREACH(const CTxOut &txout, wtx.vout) {
// iterate over all their outputs
::ExtractAffectedKeys(*this, txout.scriptPubKey, vAffected);
BOOST_FOREACH(const CKeyID &keyid, vAffected) {
// ... and all their affected keys
std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid);
if (rit != mapKeyFirstBlock.end() && nHeight < rit->second->nHeight)
rit->second = blit->second;
}
vAffected.clear();
}
}
}
// Extract block timestamps for those keys
for (std::map<CKeyID, CBlockIndex*>::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++)
mapKeyBirth[it->first] = it->second->nTime - 7200; // block times can be 2h off
}
bool CWallet::MultiSend()
{
if ( IsInitialBlockDownload() || IsLocked() )
return false;
int64_t nAmount = 0;
{
LOCK(cs_wallet);
std::vector<COutput> vCoins;
AvailableCoins(vCoins);
BOOST_FOREACH(const COutput& out, vCoins)
{
CTxDestination address;
if(!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) continue;
if (nBestHeight <= nLastMultiSendHeight )
return false;
if (out.tx->IsCoinStake() && out.tx->GetBlocksToMaturity() == 0 && out.tx->GetDepthInMainChain() == nCoinbaseMaturity+20)
{
//Disabled Addresses won't send MultiSend transactions
if(vDisabledAddresses.size() > 0)
{
for(unsigned int i = 0; i < vDisabledAddresses.size(); i++)
{
if(vDisabledAddresses[i] == CBitcoinAddress(address).ToString())
{
return false;
}
}
}
// create new coin control, populate it with the selected utxo, create sending vector
CCoinControl* cControl = new CCoinControl();
uint256 txhash = out.tx->GetHash();
COutPoint outpt(txhash, out.i);
cControl->Select(outpt);
CWalletTx wtx;
cControl->fReturnChange = true;
CReserveKey keyChange(this); // this change address does not end up being used, because change is returned with coin control switch
int64_t nFeeRet = 0;
vector<pair<CScript, int64_t> > vecSend;
// loop through multisend vector and add amounts and addresses to the sending vector
for(unsigned int i = 0; i < vMultiSend.size(); i++)
{
// MultiSend vector is a pair of 1)Address as a std::string 2) Percent of stake to send as an int
nAmount = ( ( out.tx->GetCredit() - out.tx->GetDebit() ) * vMultiSend[i].second )/100;
CBitcoinAddress strAddSend(vMultiSend[i].first);
CScript scriptPubKey;
scriptPubKey.SetDestination(strAddSend.Get());
vecSend.push_back(make_pair(scriptPubKey, nAmount));
}
//make sure splitblock is off
fSplitBlock = false;
// Create the transaction and commit it to the network
bool fCreated = CreateTransaction(vecSend, wtx, keyChange, nFeeRet, 1, cControl);
if (!fCreated)
printf("MultiSend createtransaction failed");
if(!CommitTransaction(wtx, keyChange))
printf("MultiSend transaction commit failed");
else
fMultiSendNotify = true;
delete cControl;
//write nLastMultiSendHeight to DB
CWalletDB walletdb(strWalletFile);
nLastMultiSendHeight = nBestHeight;
if(!walletdb.WriteMSettings(fMultiSend, nLastMultiSendHeight))
printf("Failed to write MultiSend setting to DB");
}
}
}
return true;
}
| [
"support@bitvier.tech"
] | support@bitvier.tech |
d72df24c7357ddf0e78a6b33b398ad9ace5833de | 603a949023236ff5ebb9863b90a1ad4c148946c7 | /com/sstl.h | 3b74422b1f3910b488ef6ee65e1ae98be2f9c075 | [
"BSD-3-Clause",
"LicenseRef-scancode-generic-cla"
] | permissive | clear-wing/xoc | 108636919d70a9445b444af198f3012864343323 | b89d4e207cf3382e85d19b733566e296018958ba | refs/heads/master | 2021-05-12T17:26:34.568544 | 2018-01-07T10:28:52 | 2018-01-07T10:28:52 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 129,504 | h | /*@
XOC Release License
Copyright (c) 2013-2014, Alibaba Group, All rights reserved.
compiler@aliexpress.com
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Su Zhenyu nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
author: Su Zhenyu
@*/
#ifndef __SSTL_H__
#define __SSTL_H__
namespace xcom {
template <class T> class allocator {
public:
allocator() throw() {}
allocator (allocator const& alloc) throw() {}
template <class U> allocator (allocator<U> const& alloc) throw() {}
~allocator() {}
};
} //namespace xcom
template <class T>
void * operator new(size_t size, xcom::allocator<T> * pool)
{
DUMMYUSE(pool);
return ::operator new(size);
}
template <class T>
void operator delete(void * ptr, xcom::allocator<T> * pool)
{
DUMMYUSE(pool);
::operator delete(ptr);
}
namespace xcom {
#define NO_BASIC_MAT_DUMP //Default option
#define MAX_SHASH_BUCKET 97 //Default option
typedef void* OBJTY;
//Structure chain operations.
//For easing implementation, there must be 2 fields declared in T
// 1. T * next
// 2. T * prev
template <class T>
inline UINT find_position(T const* list, T const* t)
{
for (UINT c = 0; list != NULL; c++, list = list->next) {
if (list == t) { return c; }
}
UNREACH(); //not find.
return 0;
}
template <class T>
inline UINT cnt_list(T const* t)
{
UINT c = 0;
while (t != NULL) { c++; t = t->next; }
return c;
}
//Return true if p is in current list.
template <class T>
bool in_list(T const* head, T const* p)
{
if (p == NULL) { return true; }
T const* t = head;
while (t != NULL) {
if (t == p) { return true; }
t = t->next;
}
return false;
}
template <class T>
inline T * get_last(T * t)
{
while (t != NULL && t->next != NULL) { t = t->next; }
return t;
}
template <class T>
inline T * get_first(T * t)
{
while (t != NULL && t->prev != NULL) { t = t->prev; }
return t;
}
template <class T>
inline void add_next(T ** pheader, T * t)
{
if (pheader == NULL || t == NULL) return ;
T * p = NULL;
t->prev = NULL;
if ((*pheader) == NULL) {
*pheader = t;
} else {
p = (*pheader)->next;
ASSERT(t != *pheader, ("\n<add_next> : overlap list member\n"));
if (p == NULL) {
(*pheader)->next = t;
t->prev = *pheader;
} else {
while (p->next != NULL) {
p = p->next;
ASSERT(p != t, ("\n<add_next> : overlap list member\n"));
}
p->next = t;
t->prev = p;
}
}
}
template <class T>
inline void add_next(IN OUT T ** pheader, IN OUT T ** last, IN T * t)
{
if (pheader == NULL || t == NULL) { return ; }
t->prev = NULL;
if ((*pheader) == NULL) {
*pheader = t;
while (t->next != NULL) { t = t->next; }
*last = t;
} else {
ASSERT0(last != NULL && *last != NULL && (*last)->next == NULL);
(*last)->next = t;
t->prev = *last;
while (t->next != NULL) { t = t->next; }
*last = t;
}
}
template <class T>
inline void remove(T ** pheader, T * t)
{
if (pheader == NULL || t == NULL) { return; }
if (t == *pheader) {
*pheader = t->next;
if (*pheader != NULL) {
(*pheader)->prev = NULL;
}
t->next = t->prev = NULL;
return;
}
ASSERT(t->prev, ("t is not in list"));
t->prev->next = t->next;
if (t->next != NULL) {
t->next->prev = t->prev;
}
t->next = t->prev = NULL;
}
//Swap t1 t2 in list.
template <class T>
inline void swap(T ** pheader, T * t1, T * t2)
{
ASSERT0(pheader);
T * t1p = t1->prev;
T * t1n = t1->next;
T * t2p = t2->prev;
T * t2n = t2->next;
if (t2 == t1n) {
t2->next = t1;
} else {
t2->next = t1n;
}
if (t2 == t1p) {
t2->prev = t1;
} else {
t2->prev = t1p;
}
if (t1 == t2n) {
t1->next = t2;
} else {
t1->next = t2n;
}
if (t1 == t2p) {
t1->prev = t2;
} else {
t1->prev = t2p;
}
if (t1p != NULL && t1p != t2) {
t1p->next = t2;
}
if (t1n != NULL && t1n != t2) {
t1n->prev = t2;
}
if (t2p != NULL && t2p != t1) {
t2p->next = t1;
}
if (t2n != NULL && t2n != t1) {
t2n->prev = t1;
}
if (*pheader == t1) {
*pheader = t2;
} else if (*pheader == t2) {
*pheader = t1;
}
}
template <class T>
inline void replace(T ** pheader, T * olds, T * news)
{
if (pheader == NULL || olds == NULL) return;
if (olds == news) { return; }
if (news == NULL) {
xcom::remove(pheader, olds);
return;
}
#ifdef _DEBUG_
bool find = false;
T * p = *pheader;
while (p != NULL) {
if (p == olds) {
find = true;
break;
}
p = p->next;
}
ASSERT(find, ("'olds' is not inside in pheader"));
#endif
news->prev = olds->prev;
news->next = olds->next;
if (olds->prev != NULL) {
olds->prev->next = news;
}
if (olds->next != NULL) {
olds->next->prev = news;
}
if (olds == *pheader) {
*pheader = news;
}
olds->next = olds->prev = NULL;
}
template <class T>
inline T * removehead(T ** pheader)
{
if (pheader == NULL || *pheader == NULL) return NULL;
T * t = *pheader;
*pheader = t->next;
if (*pheader != NULL) {
(*pheader)->prev = NULL;
}
t->next = t->prev = NULL;
return t;
}
template <class T>
inline T * removehead_single_list(T ** pheader)
{
if (pheader == NULL || *pheader == NULL) return NULL;
T * t = *pheader;
*pheader = t->next;
t->next = NULL;
return t;
}
template <class T>
inline T * removetail(T ** pheader)
{
if (pheader == NULL || *pheader == NULL) { return NULL; }
T * t = *pheader;
while (t->next != NULL) { t = t->next; }
remove(pheader, t);
return t;
}
//Insert one elem 't' before 'marker'.
template <class T>
inline void insertbefore_one(T ** head, T * marker, T * t)
{
if (t == NULL) return;
ASSERT(head, ("absent parameter"));
if (t == marker) return;
if (*head == NULL) {
ASSERT(marker == NULL, ("marker must be NULL"));
*head = t;
return;
}
if (marker == *head) {
//'marker' is head, and replace head.
t->prev = NULL;
t->next = marker;
marker->prev = t;
*head = t;
return;
}
ASSERT(marker->prev != NULL, ("marker is head"));
marker->prev->next = t;
t->prev = marker->prev;
t->next = marker;
marker->prev = t;
}
//Insert a list that leading by 't' before 'marker'.
//'head': function might modify the header of list.
//'t': the head element of list, that to be inserted.
template <class T>
inline void insertbefore(T ** head, T * marker, T * t)
{
if (t == NULL) { return; }
ASSERT(head, ("absent parameter"));
if (t == marker) { return; }
if (*head == NULL) {
ASSERT(marker == NULL, ("marker must be NULL"));
*head = t;
return;
}
if (marker == *head) {
//'marker' is head, and replace head.
ASSERT(t->prev == NULL, ("t is not the first element"));
add_next(&t, *head);
*head = t;
return;
}
ASSERT(marker->prev != NULL, ("marker should not be head"));
if (marker->prev != NULL) {
marker->prev->next = t;
t->prev = marker->prev;
}
t = get_last(t);
t->next = marker;
marker->prev = t;
}
//Insert t into list immediately that following 'marker'.
//e.g: a->maker->b->c
// output is: a->maker->t->b->c
//Return header in 'marker' if list is empty.
template <class T>
inline void insertafter_one(T ** marker, T * t)
{
if (marker == NULL || t == NULL) return;
if (t == *marker) return;
if (*marker == NULL) {
*marker = t;
return;
}
T * last = get_last(t);
if ((*marker)->next != NULL) {
(*marker)->next->prev = last;
last->next = (*marker)->next;
}
(*marker)->next = t;
t->prev = *marker;
}
//Append t into head of list.
//e.g: given head->a->b->c, and t1->t2.
// output is: t1->t2->a->b->c
//This function will update the head of list.
template <class T>
inline void append_head(T ** head, T * t)
{
if (*head == NULL) {
*head = t;
return;
}
T * last = get_last(t);
(*head)->prev = last;
last->next = *head;
*head = t;
}
//Insert t into marker's list as the subsequent element.
//e.g: a->maker->b->c, and t->x->y
//output is: a->maker->t->x->y->b->c.
template <class T>
inline void insertafter(T ** marker, T * t)
{
if (marker == NULL || t == NULL) return;
if (t == *marker) return;
if (*marker == NULL) {
*marker = t;
return;
}
if ((*marker)->next != NULL) {
T * last = get_last(t);
(*marker)->next->prev = last;
last->next = (*marker)->next;
}
t->prev = *marker;
(*marker)->next = t;
}
//Reverse list, return the new list-head.
template <class T>
inline T * reverse_list(T * t)
{
T * head = t;
while (t != NULL) {
T * tmp = t->prev;
t->prev = t->next;
t->next = tmp;
head = t;
t = t->prev;
}
return head;
}
//Double Chain Container.
#define C_val(c) ((c)->value)
#define C_next(c) ((c)->next)
#define C_prev(c) ((c)->prev)
template <class T> class C {
public:
C<T> * prev;
C<T> * next;
T value;
public:
C() { init(); }
COPY_CONSTRUCTOR(C<T>);
void init()
{
prev = next = NULL;
value = T(0); //The default value of container.
}
T val() { return value; }
};
//Single Chain Container.
#define SC_val(c) ((c)->value)
#define SC_next(c) ((c)->next)
template <class T> class SC {
public:
SC<T> * next;
T value;
public:
SC() { init(); }
COPY_CONSTRUCTOR(SC<T>);
void init()
{
next = NULL;
value = T(0);
}
T val() { return value; }
};
//FREE-List
//
//T refer to basis element type.
// e.g: Suppose variable type is 'VAR*', then T is 'VAR'.
//
//For easing implementation, there are 2 fields should be declared in T,
// struct T {
// T * next;
// T * prev;
// ... //other field
// }
template <class T>
class FreeList {
public:
BOOL m_is_clean;
T * m_tail;
public:
FreeList()
{
m_is_clean = true;
m_tail = NULL;
}
COPY_CONSTRUCTOR(FreeList);
~FreeList()
{ m_tail = NULL; }
UINT count_mem() const { return sizeof(FreeList<T>); }
//Note the element in list should be freed by user.
void clean()
{ m_tail = NULL; }
//True if invoke ::memset when user query free element.
void set_clean(bool is_clean)
{ m_is_clean = (BYTE)is_clean; }
//Add t to tail of the list.
//Do not clean t's content.
inline void add_free_elem(T * t)
{
if (t == NULL) {return;}
ASSERT0(t->next == NULL && t->prev == NULL); //clean by user.
if (m_tail == NULL) {
m_tail = t;
return;
}
t->prev = m_tail;
m_tail->next = t;
m_tail = t;
}
//Remove an element from tail of list.
inline T * get_free_elem()
{
if (m_tail == NULL) { return NULL; }
T * t = m_tail;
m_tail = m_tail->prev;
if (m_tail != NULL) {
ASSERT0(t->next == NULL);
m_tail->next = NULL;
m_is_clean ? ::memset(t, 0, sizeof(T)) : t->prev = NULL;
} else {
ASSERT0(t->prev == NULL && t->next == NULL);
if (m_is_clean) {
::memset(t, 0, sizeof(T));
}
}
return t;
}
};
//END FreeList
//Dual Linked List.
//NOTICE:
// The following operations are the key points which you should
// pay attention to:
// 1. If you REMOVE one element, its container will be collect by FREE-List.
// So if you need a new container, please check the FREE-List first,
// accordingly, you should first invoke 'get_free_list' which get free
// containers out from 'm_free_list'.
// 2. If you want to invoke APPEND, please call 'newc' first to
// allocate a new container memory space, record your elements in
// container, then APPEND it at list.
template <class T, class Allocator = allocator<T> > class List {
protected:
UINT m_elem_count;
C<T> * m_head;
C<T> * m_tail;
Allocator pool;
//It is a marker that used internally by List. Some function will
//update the variable, see comments.
C<T> * m_cur;
//Hold the freed containers for next request.
FreeList<C<T> > m_free_list;
public:
List() { init(); }
COPY_CONSTRUCTOR(List);
~List() { destroy(); }
void init()
{
m_elem_count = 0;
m_head = m_tail = m_cur = NULL;
m_free_list.clean();
m_free_list.set_clean(false);
}
void destroy()
{
C<T> * ct = m_free_list.m_tail;
while (ct != NULL) {
C<T> * t = ct;
ct = ct->prev;
//Do not need to invoke destructor of C<T>.
operator delete(t, &pool);
}
ct = m_head;
while (ct != NULL) {
C<T> * t = ct;
ct = ct->next;
//Do not need to invoke destructor of C<T>.
operator delete(t, &pool);
}
m_free_list.clean();
m_elem_count = 0;
m_head = m_tail = m_cur = NULL;
}
//Return the end of the list.
C<T> const* end() const { return NULL; }
inline C<T> * newc()
{
//allocator<T> p;
C<T> * c = m_free_list.get_free_elem();
if (c == NULL) {
return new (&pool) C<T>();
} else {
C_val(c) = T(0);
}
return c;
}
//Clean list, and add element containers to free list.
void clean()
{
C<T> * c = m_head;
while (c != NULL) {
C<T> * next = C_next(c);
C_prev(c) = C_next(c) = NULL;
m_free_list.add_free_elem(c);
c = next;
}
m_elem_count = 0;
m_head = m_tail = m_cur = NULL;
}
void copy(IN List<T> & src)
{
clean();
T t = src.get_head();
for (INT n = src.get_elem_count(); n > 0; n--) {
append_tail(t);
t = src.get_next();
}
}
UINT count_mem() const
{
UINT count = 0;
count += sizeof(m_elem_count);
count += sizeof(m_head);
count += sizeof(m_tail);
count += sizeof(m_cur);
count += m_free_list.count_mem();
C<T> * ct = m_free_list.m_tail;
while (ct != NULL) {
count += sizeof(C<T>);
ct = ct->next;
}
ct = m_head;
while (ct != NULL) {
count += sizeof(C<T>);
ct = ct->next;
}
return count;
}
C<T> * append_tail(T t)
{
C<T> * c = newc();
ASSERT(c != NULL, ("newc return NULL"));
C_val(c) = t;
append_tail(c);
return c;
}
void append_tail(C<T> * c)
{
if (m_head == NULL) {
ASSERT(m_tail == NULL, ("tail should be NULL"));
m_head = m_tail = c;
C_next(m_head) = C_prev(m_head) = NULL;
m_elem_count = 1;
return;
}
C_prev(c) = m_tail;
C_next(m_tail) = c;
m_tail = c;
ASSERT0(C_next(c) == NULL);
m_elem_count++;
return;
}
//This function will remove all elements in 'src' and
//append to tail of current list.
//Note 'src' will be clean.
void append_tail(IN OUT List<T> & src)
{
if (src.m_head == NULL) { return; }
if (m_tail == NULL) {
m_head = src.m_head;
m_tail = src.m_tail;
m_elem_count = src.m_elem_count;
src.m_head = NULL;
src.m_tail = NULL;
src.m_elem_count = 0;
return;
}
C_next(m_tail) = src.m_head;
C_prev(src.m_head) = m_tail;
m_elem_count += src.m_elem_count;
ASSERT0(src.m_tail != NULL);
m_tail = src.m_tail;
src.m_head = NULL;
src.m_tail = NULL;
src.m_elem_count = 0;
}
//This function copy elements in 'src' and
//append to tail of current list.
//'src' is unchanged.
void append_and_copy_to_tail(List<T> const& src)
{
C<T> * t = src.m_head;
if (t == NULL) { return; }
if (m_head == NULL) {
C<T> * c = newc();
ASSERT0(c);
C_val(c) = C_val(t);
ASSERT(m_tail == NULL, ("tail should be NULL"));
m_head = m_tail = c;
ASSERT0(C_next(c) == NULL && C_prev(c) == NULL);
t = C_next(t);
}
for (; t != T(0); t = C_next(t)) {
C<T> * c = newc();
ASSERT0(c);
C_val(c) = C_val(t);
C_prev(c) = m_tail;
C_next(m_tail) = c;
m_tail = c;
}
C_next(m_tail) = NULL;
m_elem_count += src.get_elem_count();
}
//Append value t to head of list.
C<T> * append_head(T t)
{
C<T> * c = newc();
ASSERT(c, ("newc return NULL"));
C_val(c) = t;
append_head(c);
return c;
}
//Append container to head of list.
void append_head(C<T> * c)
{
if (m_head == NULL) {
ASSERT(m_tail == NULL, ("tail should be NULL"));
m_head = m_tail = c;
C_next(m_head) = C_prev(m_head) = NULL;
m_elem_count = 1;
return;
}
C_next(c) = m_head;
C_prev(m_head) = c;
m_head = c;
ASSERT0(C_prev(c) == NULL);
//C_prev(m_head) = NULL;
m_elem_count++;
return;
}
//This function will remove all elements in 'src' and
//append to current list head.
//Note 'src' will be clean.
void append_head(IN OUT List<T> & src)
{
if (src.m_head == NULL) { return; }
if (m_tail == NULL) {
m_head = src.m_head;
m_tail = src.m_tail;
m_elem_count = src.m_elem_count;
src.m_head = NULL;
src.m_tail = NULL;
src.m_elem_count = 0;
return;
}
ASSERT0(src.m_tail);
C_prev(m_head) = src.m_tail;
C_next(src.m_tail) = m_head;
m_elem_count += src.m_elem_count;
m_head = src.m_head;
src.m_head = NULL;
src.m_tail = NULL;
src.m_elem_count = 0;
}
//This function copy all elements in 'src' and
//append to current list head.
void append_and_copy_to_head(List<T> const& src)
{
C<T> * t = src.m_tail;
if (t == NULL) { return; }
if (m_head == NULL) {
C<T> * c = newc();
ASSERT0(c);
C_val(c) = C_val(t);
ASSERT(m_tail == NULL, ("tail should be NULL"));
m_head = m_tail = c;
ASSERT0(C_next(c) == NULL && C_prev(c) == NULL);
t = C_prev(t);
}
for (; t != T(0); t = C_prev(t)) {
C<T> * c = newc();
ASSERT0(c);
C_val(c) = C_val(t);
C_next(c) = m_head;
C_prev(m_head) = c;
m_head = c;
}
C_prev(m_head) = NULL;
m_elem_count += src.get_elem_count();
}
//Return true if p is in current list.
bool in_list(C<T> const* p) const
{
if (p == NULL) { return true; }
C<T> const* t = m_head;
while (t != NULL) {
if (t == p) { return true; }
t = C_next(t);
}
return false;
}
//Insert value t before marker.
//Note this function will do searching for t and marker, so it is
//a costly function, and used it be carefully.
C<T> * insert_before(T t, T marker)
{
ASSERT(t != marker, ("element of list cannot be identical"));
if (m_head == NULL || marker == C_val(m_head)) {
return append_head(t);
}
C<T> * c = newc();
ASSERT0(c);
C_val(c) = t;
ASSERT0(m_tail);
if (marker == m_tail->val()) {
if (C_prev(m_tail) != NULL) {
C_next(C_prev(m_tail)) = c;
C_prev(c) = C_prev(m_tail);
}
C_next(c) = m_tail;
C_prev(m_tail) = c;
} else {
//find marker
C<T> * mc = m_head;
while (mc != NULL) {
if (mc->val() == marker) {
break;
}
mc = C_next(mc);
}
if (mc == NULL) { return NULL; }
if (C_prev(mc) != NULL) {
C_next(C_prev(mc)) = c;
C_prev(c) = C_prev(mc);
}
C_next(c) = mc;
C_prev(mc) = c;
}
m_elem_count++;
return c;
}
//Insert container 'c' into list before the 'marker'.
void insert_before(IN C<T> * c, IN C<T> * marker)
{
ASSERT0(marker && c && C_prev(c) == NULL && C_next(c) == NULL);
ASSERT0(c != marker);
ASSERT0(m_tail);
#ifdef _SLOW_CHECK_
ASSERT0(in_list(marker));
#endif
if (C_prev(marker) != NULL) {
C_next(C_prev(marker)) = c;
C_prev(c) = C_prev(marker);
}
C_next(c) = marker;
C_prev(marker) = c;
m_elem_count++;
if (marker == m_head) {
m_head = c;
}
}
//Insert 't' into list before the 'marker'.
C<T> * insert_before(T t, IN C<T> * marker)
{
C<T> * c = newc();
ASSERT(c, ("newc return NULL"));
C_val(c) = t;
insert_before(c, marker);
return c;
}
//Insert 'src' before 'marker', and return the CONTAINER
//of src head and src tail.
//This function move all element in 'src' into current list.
void insert_before(
IN OUT List<T> & src,
IN C<T> * marker,
OUT C<T> ** list_head_ct = NULL,
OUT C<T> ** list_tail_ct = NULL)
{
if (src.m_head == NULL) { return; }
ASSERT0(m_head && marker);
#ifdef _SLOW_CHECK_
ASSERT0(in_list(marker));
#endif
ASSERT0(src.m_tail);
if (C_prev(marker) != NULL) {
C_next(C_prev(marker)) = src.m_head;
C_prev(src.m_head) = C_prev(marker);
}
C_next(src.m_tail) = marker;
C_prev(marker) = src.m_tail;
m_elem_count += src.m_elem_count;
if (marker == m_head) {
m_head = src.m_head;
}
if (list_head_ct != NULL) {
*list_head_ct = src.m_head;
}
if (list_tail_ct != NULL) {
*list_tail_ct = src.m_tail;
}
src.m_head = NULL;
src.m_tail = NULL;
src.m_elem_count = 0;
}
//Insert 'list' before 'marker', and return the CONTAINER
//of list head and list tail.
void insert_and_copy_before(
List<T> const& list,
T marker,
OUT C<T> ** list_head_ct = NULL,
OUT C<T> ** list_tail_ct = NULL)
{
C<T> * ct = NULL;
find(marker, &ct);
insert_before(list, ct, list_head_ct, list_tail_ct);
}
//Insert 'list' before 'marker', and return the CONTAINER
//of list head and list tail.
void insert_and_copy_before(
List<T> const& list,
IN C<T> * marker,
OUT C<T> ** list_head_ct = NULL,
OUT C<T> ** list_tail_ct = NULL)
{
if (list.m_head == NULL) { return; }
ASSERT0(marker);
C<T> * list_ct = list.m_tail;
marker = insert_before(list_ct->val(), marker);
if (list_tail_ct != NULL) {
*list_tail_ct = marker;
}
list_ct = C_prev(list_ct);
C<T> * prev_ct = marker;
for (; list_ct != NULL; list_ct = C_prev(list_ct)) {
marker = insert_before(list_ct->val(), marker);
prev_ct = marker;
}
if (list_head_ct != NULL) {
*list_head_ct = prev_ct;
}
}
C<T> * insert_after(T t, T marker)
{
ASSERT(t != marker,("element of list cannot be identical"));
if (m_tail == NULL || marker == m_tail->val()) {
append_tail(t);
return m_tail;
}
ASSERT(m_head != NULL, ("Tail is non empty, but head is NULL!"));
C<T> * c = newc();
ASSERT(c != NULL, ("newc return NULL"));
C_val(c) = t;
if (marker == m_head->val()) {
if (C_next(m_head) != NULL) {
C_prev(C_next(m_head)) = c;
C_next(c) = C_next(m_head);
}
C_prev(c) = m_head;
C_next(m_head) = c;
} else {
//find marker
C<T> * mc = m_head;
while (mc != NULL) {
if (mc->val() == marker) {
break;
}
mc = C_next(mc);
}
if (mc == NULL) return NULL;
if (C_next(mc) != NULL) {
C_prev(C_next(mc)) = c;
C_next(c) = C_next(mc);
}
C_prev(c) = mc;
C_next(mc) = c;
}
m_elem_count++;
return c;
}
//Insert 'c' into list after the 'marker'.
void insert_after(IN C<T> * c, IN C<T> * marker)
{
ASSERT0(marker && c && C_prev(c) == NULL && C_next(c) == NULL);
if (c == marker) { return; }
ASSERT0(m_head);
#ifdef _SLOW_CHECK_
ASSERT0(in_list(marker));
#endif
if (C_next(marker) != NULL) {
C_prev(C_next(marker)) = c;
C_next(c) = C_next(marker);
}
C_prev(c) = marker;
C_next(marker) = c;
if (marker == m_tail) {
m_tail = c;
}
m_elem_count++;
}
//Insert 't' into list after the 'marker'.
C<T> * insert_after(T t, IN C<T> * marker)
{
C<T> * c = newc();
ASSERT(c != NULL, ("newc return NULL"));
C_val(c) = t;
insert_after(c, marker);
return c;
}
//Insert 'src' after 'marker', and return the CONTAINER
//of src head and src tail.
//This function move all element in 'src' into current list.
void insert_after(
IN OUT List<T> & src,
IN C<T> * marker,
OUT C<T> ** list_head_ct = NULL,
OUT C<T> ** list_tail_ct = NULL)
{
if (src.m_head == NULL) { return; }
ASSERT0(m_head && marker);
#ifdef _SLOW_CHECK_
ASSERT0(in_list(marker));
#endif
ASSERT0(src.m_tail);
if (C_next(marker) != NULL) {
C_prev(C_next(marker)) = src.m_tail;
C_next(src.m_tail) = C_next(marker);
}
C_prev(src.m_head) = marker;
C_next(marker) = src.m_head;
m_elem_count += src.m_elem_count;
if (marker == m_tail) {
m_tail = src.m_tail;
}
if (list_head_ct != NULL) {
*list_head_ct = src.m_head;
}
if (list_tail_ct != NULL) {
*list_tail_ct = src.m_tail;
}
src.m_head = NULL;
src.m_tail = NULL;
src.m_elem_count = 0;
}
//Insert 'list' after 'marker', and return the CONTAINER
//of list head and list tail.
void insert_and_copy_after(
List<T> const& list,
T marker,
OUT C<T> ** list_head_ct = NULL,
OUT C<T> ** list_tail_ct = NULL)
{
C<T> * ct = NULL;
find(marker, &ct);
insert_after(list, ct, list_head_ct, list_tail_ct);
}
//Insert 'list' after 'marker', and return the CONTAINER
//of head and tail of members in 'list'.
void insert_and_copy_after(
List<T> const& list,
IN C<T> * marker,
OUT C<T> ** list_head_ct = NULL,
OUT C<T> ** list_tail_ct = NULL)
{
if (list.m_head == NULL) { return; }
ASSERT0(marker);
C<T> * list_ct = list.m_head;
marker = insert_after(list_ct->val(), marker);
if (list_head_ct != NULL) {
*list_head_ct = marker;
}
list_ct = C_next(list_ct);
C<T> * prev_ct = marker;
for (; list_ct != NULL; list_ct = C_next(list_ct)) {
marker = insert_after(list_ct->val(), marker);
prev_ct = marker;
}
if (list_tail_ct != NULL) {
*list_tail_ct = prev_ct;
}
}
UINT get_elem_count() const { return m_elem_count; }
T get_cur() const
{
if (m_cur == NULL) { return T(0); }
return m_cur->val();
}
//Return m_cur and related container, and it does not modify m_cur.
T get_cur(IN OUT C<T> ** holder) const
{
if (m_cur == NULL) {
*holder = NULL;
return T(0);
}
ASSERT0(holder != NULL);
*holder = m_cur;
return m_cur->val();
}
//Get tail of list, return the CONTAINER.
//This function does not modify m_cur.
T get_tail(OUT C<T> ** holder) const
{
ASSERT0(holder);
*holder = m_tail;
if (m_tail != NULL) {
return m_tail->val();
}
return T(0);
}
//Get tail of list, return the CONTAINER.
//This function will modify m_cur.
T get_tail()
{
m_cur = m_tail;
if (m_tail != NULL) {
return m_tail->val();
}
return T(0);
}
//Get head of list, return the CONTAINER.
//This function will modify m_cur.
T get_head()
{
m_cur = m_head;
if (m_head != NULL) {
return m_head->val();
}
return T(0);
}
//Get head of list, return the CONTAINER.
//This function does not modify m_cur.
T get_head(OUT C<T> ** holder) const
{
ASSERT0(holder);
*holder = m_head;
if (m_head != NULL) {
return m_head->val();
}
return T(0);
}
//Get element next to m_cur.
//This function will modify m_cur.
T get_next()
{
if (m_cur == NULL || m_cur->next == NULL) {
m_cur = NULL;
return T(0);
}
m_cur = m_cur->next;
return m_cur->val();
}
//Return next container.
//Caller could get the element via C_val or val().
//This function does not modify m_cur.
C<T> * get_next(IN C<T> * holder) const
{
ASSERT0(holder);
return C_next(holder);
}
//Return list member and update holder to next member.
//This function does not modify m_cur.
T get_next(IN OUT C<T> ** holder) const
{
ASSERT0(holder && *holder);
*holder = C_next(*holder);
if (*holder != NULL) {
return C_val(*holder);
}
return T(0);
}
//Get element previous to m_cur.
//This function will modify m_cur.
T get_prev()
{
if (m_cur == NULL || m_cur->prev == NULL) {
m_cur = NULL;
return T(0);
}
m_cur = m_cur->prev;
return m_cur->val();
}
//Return list member and update holder to prev member.
//This function does not modify m_cur.
T get_prev(IN OUT C<T> ** holder) const
{
ASSERT0(holder && *holder);
*holder = C_prev(*holder);
if (*holder != NULL) {
return C_val(*holder);
}
return T(0);
}
//Return prev container.
//Caller could get the element via C_val or val().
//This function does not modify m_cur.
C<T> * get_prev(IN C<T> * holder) const
{
ASSERT0(holder);
return C_prev(holder);
}
//Get element for nth at tail.
//'n': starting at 0.
//This function will modify m_cur.
T get_tail_nth(UINT n, IN OUT C<T> ** holder = NULL)
{
ASSERT(n < m_elem_count,("Access beyond list"));
m_cur = NULL;
if (m_elem_count == 0) { return T(0); }
C<T> * c;
if (n <= (m_elem_count >> 1)) { // n<floor(elem_count,2)
c = m_tail;
while (n > 0) {
c = C_prev(c);
n--;
}
} else {
return get_head_nth(m_elem_count - n - 1);
}
m_cur = c;
if (holder != NULL) {
*holder = c;
}
return c->val();
}
//Get element for nth at head.
//'n': getting start with zero.
//This function will modify m_cur.
T get_head_nth(UINT n, IN OUT C<T> ** holder = NULL)
{
ASSERT(n < m_elem_count,("Access beyond list"));
m_cur = NULL;
if (m_head == NULL) {
return T(0);
}
C<T> * c;
if (n <= (m_elem_count >> 1)) { // n<floor(elem_count,2)
c = m_head;
while (n > 0) {
c = C_next(c);
n--;
}
} else {
return get_tail_nth(m_elem_count - n - 1);
}
m_cur = c;
if (holder != NULL) {
*holder = c;
}
return c->val();
}
bool find(IN T t, OUT C<T> ** holder = NULL) const
{
C<T> * c = m_head;
while (c != NULL) {
if (c->val() == t) {
if (holder != NULL) {
*holder = c;
}
return true;
}
c = C_next(c);
}
if (holder != NULL) {
*holder = NULL;
}
return false;
}
//Reverse list.
void reverse()
{
C<T> * next_ct;
for (C<T> * ct = m_head; ct != NULL; ct = next_ct) {
next_ct = ct->next;
ct->next = ct->prev;
ct->prev = next_ct;
}
next_ct = m_head;
m_head = m_tail;
m_tail = next_ct;
}
//Remove from list directly.
T remove(C<T> * holder)
{
ASSERT0(holder);
if (holder == m_cur) {
m_cur = m_cur->next;
}
ASSERT(m_head, ("list is empty"));
if (m_head == holder) {
return remove_head();
}
if (m_tail == holder) {
return remove_tail();
}
ASSERT(C_prev(holder) && C_next(holder), ("illegal t in list"));
C_next(C_prev(holder)) = C_next(holder);
C_prev(C_next(holder)) = C_prev(holder);
m_elem_count--;
C_prev(holder) = C_next(holder) = NULL;
m_free_list.add_free_elem(holder);
return holder->val();
}
//Remove from list, and searching for 't' begin at head
T remove(T t)
{
if (m_head == NULL) { return T(0); }
if (m_head->val() == t) { return remove_head(); }
if (m_tail->val() == t) { return remove_tail(); }
C<T> * c = m_head;
while (c != NULL) {
if (c->val() == t) { break; }
c = C_next(c);
}
if (c == NULL) { return T(0); }
return remove(c);
}
//Remove from tail.
T remove_tail()
{
if (m_tail == NULL) { return T(0); }
C<T> * c = NULL;
if (C_prev(m_tail) == NULL) {
//tail is the only one
ASSERT(m_tail == m_head && m_elem_count == 1,
("illegal list-remove"));
c = m_tail;
m_head = m_tail = m_cur = NULL;
} else {
c = m_tail;
if (m_cur == m_tail) {
m_cur = C_prev(m_tail);
}
m_tail = C_prev(m_tail);
C_next(m_tail) = NULL;
C_prev(c) = NULL;
}
m_elem_count--;
m_free_list.add_free_elem(c);
return c->val();
}
//Remove from head.
T remove_head()
{
C<T> * c = NULL;
if (m_head == NULL) { return T(0); }
if (C_next(m_head) == NULL) {
//list_head is the only one
ASSERT(m_tail == m_head && m_elem_count == 1,
("illegal list-remove"));
c = m_head;
m_head = m_tail = m_cur = NULL;
} else {
c = m_head;
if (m_cur == m_head) {
m_cur = C_next(m_head);
}
m_head = C_next(m_head);
C_prev(m_head) = NULL;
C_prev(c) = C_next(c) = NULL;
}
m_free_list.add_free_elem(c);
m_elem_count--;
return c->val();
}
};
//Single Linked List Core.
//Encapsulate most operations for single list.
//Note:
// 1. You must invoke init() if the SListCore allocated in mempool.
// 2. The single linked list is different with dual linked list.
// the dual linked list does not use mempool to hold the container.
// Compared to dual linked list, single linked list allocate containers
// in a const size pool.
// 3. Before going to the destructor, even if the containers have
// been allocated in memory pool, you should invoke clean() to free
// all of them back to a free list to reuse them.
template <class T> class SListCore {
protected:
UINT m_elem_count; //list elements counter.
SC<T> m_head; //list head.
protected:
SC<T> * new_sc_container(SMemPool * pool)
{
ASSERT(pool, ("need mem pool"));
ASSERT(MEMPOOL_type(pool) == MEM_CONST_SIZE, ("need const size pool"));
SC<T> * p = (SC<T>*)smpoolMallocConstSize(sizeof(SC<T>), pool);
ASSERT0(p != NULL);
::memset(p, 0, sizeof(SC<T>));
return p;
}
//Check p is the element in list.
bool in_list(SC<T> const* p) const
{
ASSERT0(p);
if (p == &m_head) { return true; }
SC<T> const* t = m_head.next;
while (t != &m_head) {
if (t == p) { return true; }
t = t->next;
}
return false;
}
SC<T> * get_freed_sc(SC<T> ** free_list)
{
if (free_list == NULL || *free_list == NULL) { return NULL; }
SC<T> * t = *free_list;
*free_list = (*free_list)->next;
t->next = NULL;
return t;
}
//Find the last element, and return the CONTAINER.
//This is a costly operation. Use it carefully.
inline SC<T> * get_tail() const
{
SC<T> * c = m_head.next;
SC<T> * tail = NULL;
while (c != &m_head) {
tail = c;
c = c->next;
}
return tail;
}
void free_sc(SC<T> * sc, SC<T> ** free_list)
{
ASSERT0(free_list);
sc->next = *free_list;
*free_list = sc;
}
SC<T> * newsc(SC<T> ** free_list, SMemPool * pool)
{
SC<T> * c = get_freed_sc(free_list);
if (c == NULL) {
c = new_sc_container(pool);
}
return c;
}
public:
SListCore() { init(); }
COPY_CONSTRUCTOR(SListCore);
~SListCore()
{
//Note: Before invoked the destructor, even if the containers have
//been allocated in memory pool, you should invoke clean() to
//free all of them back to a free list to reuse them.
}
void init()
{
m_elem_count = 0;
m_head.next = &m_head;
}
SC<T> * append_head(T t, SC<T> ** free_list, SMemPool * pool)
{
SC<T> * c = newsc(free_list, pool);
ASSERT(c != NULL, ("newsc return NULL"));
SC_val(c) = t;
append_head(c);
return c;
}
void append_head(IN SC<T> * c) { insert_after(c, &m_head); }
//Find the last element, and add 'c' after it.
//This is a costly operation. Use it carefully.
void append_tail(IN SC<T> * c)
{
SC<T> * cur = m_head.next;
SC<T> * prev = &m_head;
while (cur != &m_head) {
cur = cur->next;
prev = cur;
}
insert_after(c, prev);
}
void copy(IN SListCore<T> & src, SC<T> ** free_list, SMemPool * pool)
{
clean(free_list);
SC<T> * tgt_st = get_head();
for (SC<T> * src_st = src.get_head();
src_st != src.end();
src_st = src.get_next(src_st), tgt_st = get_next(tgt_st)) {
T t = src_st->val();
insert_after(t, tgt_st, free_list, pool);
}
}
void clean(SC<T> ** free_list)
{
ASSERT0(free_list);
SC<T> * tail = get_tail();
if (tail != NULL) {
tail->next = *free_list;
*free_list = m_head.next;
m_head.next = &m_head;
m_elem_count = 0;
}
ASSERT0(m_elem_count == 0);
}
UINT count_mem() const
{
UINT count = sizeof(m_elem_count);
count += sizeof(m_head);
//Do not count SC, they belong to input pool.
return count;
}
//Insert container 'c' after the 'marker'.
inline void insert_after(IN SC<T> * c, IN SC<T> * marker)
{
ASSERT0(marker && c && c != marker);
#ifdef _SLOW_CHECK_
ASSERT0(in_list(marker));
#endif
c->next = marker->next;
marker->next = c;
m_elem_count++;
}
//Insert value 't' after the 'marker'.
//free_list: a list record free containers.
//pool: memory pool which is used to allocate container.
inline SC<T> * insert_after(
T t,
IN SC<T> * marker,
SC<T> ** free_list,
SMemPool * pool)
{
ASSERT0(marker);
#ifdef _SLOW_CHECK_
ASSERT0(in_list(marker));
#endif
SC<T> * c = newsc(free_list, pool);
ASSERT(c != NULL, ("newc return NULL"));
SC_val(c) = t;
insert_after(c, marker);
return c;
}
UINT get_elem_count() const { return m_elem_count; }
//Return the end of the list.
SC<T> const * end() const { return &m_head; }
//Get head of list, return the CONTAINER.
//You could iterate the list via comparing the container with end().
SC<T> * get_head() const { return m_head.next; }
//Return the next container.
SC<T> * get_next(IN SC<T> * holder) const
{
ASSERT0(holder);
return SC_next(holder);
}
//Find 't' in list, return the container in 'holder' if 't' existed.
//The function is regular list search, and has O(n) complexity.
//Note that this is costly operation. Use it carefully.
bool find(IN T t, OUT SC<T> ** holder = NULL) const
{
SC<T> * c = m_head.next;
while (c != &m_head) {
if (c->val() == t) {
if (holder != NULL) {
*holder = c;
}
return true;
}
c = c->next;
}
if (holder != NULL) {
*holder = NULL;
}
return false;
}
//Remove 't' out of list, return true if find t, otherwise return false.
//Note that this is costly operation. Use it carefully.
bool remove(T t, SC<T> ** free_list)
{
SC<T> * c = m_head.next;
SC<T> * prev = &m_head;
while (c != &m_head) {
if (c->val() == t) { break; }
prev = c;
c = c->next;
}
if (c == &m_head) { return false; }
remove(prev, c, free_list);
return true;
}
//Return the element removed.
//'prev': the previous one element of 'holder'.
T remove(SC<T> * prev, SC<T> * holder, SC<T> ** free_list)
{
ASSERT0(holder);
ASSERT(m_head.next != &m_head, ("list is empty"));
ASSERT0(prev);
ASSERT(prev->next == holder, ("not prev one"));
prev->next = holder->next;
m_elem_count--;
T t = SC_val(holder);
free_sc(holder, free_list);
return t;
}
//Return the element removed.
T remove_head(SC<T> ** free_list)
{
if (m_head.next == &m_head) { return T(0); }
SC<T> * c = m_head.next;
m_head.next = c->next;
T t = c->val();
free_sc(c, free_list);
m_elem_count--;
return t;
}
};
//END SListCore
//Single List
//NOTICE:
// The following operations are the key points which you should attention to:
//
// 1. You must invoke init() if the SList allocated in mempool.
// 2. Before going to the destructor, even if the containers have
// been allocated in memory pool, you should invoke clean() to free
// all of them back to a free list to reuse them.
// 3. If you REMOVE one element, its container will be collect by FREE-List.
// So if you need a new container, please check the FREE-List first,
// accordingly, you should first invoke 'get_free_list' which get free
// containers out from 'm_free_list'.
// 4. The single linked list is different with dual linked list.
// the dual linked list does not use mempool to hold the container.
// Compared to dual linked list, single linked list allocate containers
// in a const size pool.
// Invoke init() to do initialization if you allocate SList by malloc().
// 5. Compare the iterator with end() to determine if meeting the end of list.
// 6. Byte size of element in Const Pool is equal to sizeof(SC<T>).
//
// Usage:SMemPool * pool = smpoolCreate(sizeof(SC<T>) * n, MEM_CONST_SIZE);
// SList<T> list(pool);
// SList<T> * list2 = smpoolMalloc();
// list2->init(pool);
// ...
// smpoolDelete(pool);
template <class T> class SList : public SListCore<T> {
protected:
SMemPool * m_free_list_pool;
SC<T> * m_free_list; //Hold for available containers
public:
SList(SMemPool * pool = NULL)
{
//Invoke init() explicitly if SList is allocated from mempool.
set_pool(pool);
}
COPY_CONSTRUCTOR(SList);
~SList()
{
//destroy() do the same things as the parent class's destructor.
//So it is not necessary to double call destroy().
//Note: Before going to the destructor, even if the containers have
//been allocated in memory pool, you should invoke clean() to
//free all of them back to a free list to reuse them.
}
void init(SMemPool * pool)
{
SListCore<T>::init();
set_pool(pool);
}
void set_pool(SMemPool * pool)
{
ASSERT(pool == NULL || MEMPOOL_type(pool) == MEM_CONST_SIZE,
("need const size pool"));
m_free_list_pool = pool;
m_free_list = NULL;
}
SMemPool * get_pool() { return m_free_list_pool; }
SC<T> * append_head(T t)
{
ASSERT0(m_free_list_pool);
return SListCore<T>::append_head(t, &m_free_list, m_free_list_pool);
}
void copy(IN SList<T> & src)
{ SListCore<T>::copy(src, &m_free_list, m_free_list_pool); }
void clean() { SListCore<T>::clean(&m_free_list); }
UINT count_mem() const
{
//Do not count SC containers, they belong to input pool.
return SListCore<T>::count_mem();
}
//Insert 't' into list after the 'marker'.
SC<T> * insert_after(T t, IN SC<T> * marker)
{
ASSERT0(m_free_list_pool);
return SListCore<T>::insert_after(t,
marker, &m_free_list, m_free_list_pool);
}
//Remove 't' out of list, return true if find t, otherwise return false.
//Note that this is costly operation.
bool remove(T t)
{
ASSERT0(m_free_list_pool);
return SListCore<T>::remove(t, &m_free_list);
}
//Return element removed.
//'prev': the previous one element of 'holder'.
T remove(SC<T> * prev, SC<T> * holder)
{
ASSERT0(m_free_list_pool);
return SListCore<T>::remove(prev, holder, &m_free_list);
}
//Return element removed.
T remove_head()
{
ASSERT0(m_free_list_pool);
return SListCore<T>::remove_head(&m_free_list);
}
};
//END SList
//The Extended Single List.
//
//This kind of single list has a tail pointer that allows you access
//tail element directly via get_tail(). This will be useful if you
//are going to append element at the tail of list.
//
//Encapsulate most operations for single list.
//
//Note the single linked list is different with dual linked list.
//the dual linked list does not use mempool to hold the container.
//Compared to dual linked list, single linked list allocate containers
//in a const size pool.
template <class T> class SListEx {
protected:
UINT m_elem_count;
SC<T> * m_head;
SC<T> * m_tail;
protected:
SC<T> * new_sc_container(SMemPool * pool)
{
ASSERT(pool, ("need mem pool"));
ASSERT(MEMPOOL_type(pool) == MEM_CONST_SIZE, ("need const size pool"));
SC<T> * p = (SC<T>*)smpoolMallocConstSize(sizeof(SC<T>), pool);
ASSERT0(p);
::memset(p, 0, sizeof(SC<T>));
return p;
}
SC<T> * get_freed_sc(SC<T> ** free_list)
{
if (free_list == NULL || *free_list == NULL) { return NULL; }
SC<T> * t = *free_list;
*free_list = (*free_list)->next;
t->next = NULL;
return t;
}
void free_sc(SC<T> * sc, SC<T> ** free_list)
{
ASSERT0(free_list);
sc->next = *free_list;
*free_list = sc;
}
SC<T> * newsc(SC<T> ** free_list, SMemPool * pool)
{
SC<T> * c = get_freed_sc(free_list);
if (c == NULL) {
c = new_sc_container(pool);
}
return c;
}
//Check p is the element in list.
bool in_list(SC<T> const* p) const
{
if (p == NULL) { return true; }
SC<T> const* t = m_head;
while (t != NULL) {
if (t == p) { return true; }
t = t->next;
}
return false;
}
public:
SListEx() { init(); }
COPY_CONSTRUCTOR(SListEx);
~SListEx()
{
//Note: Before going to the destructor, even if the containers have
//been allocated in memory pool, you should free all of them
//back to a free list to reuse them.
}
void init()
{
m_elem_count = 0;
m_head = NULL;
m_tail = NULL;
}
//Return the end of the list.
SC<T> const* end() const { return NULL; }
SC<T> * append_tail(T t, SC<T> ** free_list, SMemPool * pool)
{
SC<T> * c = newsc(free_list, pool);
ASSERT(c != NULL, ("newsc return NULL"));
SC_val(c) = t;
append_tail(c);
return c;
}
void append_tail(IN SC<T> * c)
{
if (m_head == NULL) {
ASSERT(m_tail == NULL, ("tail should be NULL"));
ASSERT0(SC_next(c) == NULL);
m_head = m_tail = c;
m_elem_count++;
return;
}
SC_next(m_tail) = c;
m_tail = c;
ASSERT0(SC_next(c) == NULL);
m_elem_count++;
return;
}
SC<T> * append_head(T t, SC<T> ** free_list, SMemPool * pool)
{
SC<T> * c = newsc(free_list, pool);
ASSERT(c != NULL, ("newsc return NULL"));
SC_val(c) = t;
append_head(c);
return c;
}
void append_head(IN SC<T> * c)
{
#ifdef _DEBUG_
if (m_head == NULL) {
ASSERT(m_tail == NULL, ("tail should be NULL"));
ASSERT0(m_elem_count == 0);
}
#endif
c->next = m_head;
m_head = c;
m_elem_count++;
return;
}
void copy(IN SListCore<T> & src, SC<T> ** free_list, SMemPool * pool)
{
clean(free_list);
SC<T> * sct;
T t = src.get_head(&sct);
for (INT n = src.get_elem_count(); n > 0; n--) {
append_tail(t, free_list, pool);
t = src.get_next(&sct);
}
}
void clean(SC<T> ** free_list)
{
ASSERT0(free_list);
if (m_tail != NULL) {
m_tail->next = *free_list;
ASSERT0(m_head);
*free_list = m_head;
m_head = m_tail = NULL;
m_elem_count = 0;
}
ASSERT0(m_head == m_tail && m_head == NULL && m_elem_count == 0);
}
UINT count_mem() const
{
UINT count = sizeof(m_elem_count);
count += sizeof(m_head);
count += sizeof(m_tail);
//Do not count SC, they has been involved in pool.
return count;
}
//Insert 'c' into list after the 'marker'.
inline void insert_after(IN SC<T> * c, IN SC<T> * marker)
{
ASSERT0(marker && c && c != marker);
#ifdef _SLOW_CHECK_
ASSERT0(in_list(marker));
#endif
c->next = marker->next;
marker->next = c;
m_elem_count++;
}
//Insert 't' into list after the 'marker'.
inline SC<T> * insert_after(
T t,
IN SC<T> * marker,
SC<T> ** free_list,
SMemPool * pool)
{
ASSERT0(marker);
#ifdef _SLOW_CHECK_
ASSERT0(in_list(marker));
#endif
SC<T> * c = newsc(free_list, pool);
ASSERT(c, ("newc return NULL"));
SC_val(c) = t;
insert_after(c, marker);
return c;
}
UINT get_elem_count() const { return m_elem_count; }
//Get tail of list, return the CONTAINER.
SC<T> * get_tail() const { return m_tail; }
//Get head of list, return the CONTAINER.
SC<T> * get_head() const { return m_head; }
//Return the next container.
SC<T> * get_next(IN SC<T> * holder) const
{
ASSERT0(holder);
return SC_next(holder);
}
//Find 't' in list, return the container in 'holder' if 't' existed.
//The function is regular list search, and has O(n) complexity.
bool find(IN T t, OUT SC<T> ** holder = NULL) const
{
SC<T> * c = m_head;
while (c != NULL) {
if (c->val() == t) {
if (holder != NULL) {
*holder = c;
}
return true;
}
c = c->next;
}
if (holder != NULL) {
*holder = NULL;
}
return false;
}
//Remove 't' out of list, return true if find t, otherwise return false.
//Note that this is costly operation.
bool remove(T t, SC<T> ** free_list)
{
if (m_head == NULL) { return false; }
if (m_head->val() == t) {
remove_head(free_list);
return true;
}
SC<T> * c = m_head->next;
SC<T> * prev = m_head;
while (c != NULL) {
if (c->val() == t) { break; }
prev = c;
c = c->next;
}
if (c == NULL) { return false; }
remove(prev, c, free_list);
return true;
}
//Return the element removed.
//'prev': the previous one element of 'holder'.
T remove(SC<T> * prev, SC<T> * holder, SC<T> ** free_list)
{
ASSERT0(holder);
ASSERT(m_head != NULL, ("list is empty"));
#ifdef _SLOW_CHECK_
ASSERT0(in_list(prev));
ASSERT0(in_list(holder));
#endif
if (prev == NULL) {
ASSERT0(holder == m_head);
m_head = m_head->next;
if (m_head == NULL) {
ASSERT0(m_elem_count == 1);
m_tail = NULL;
}
} else {
ASSERT(prev->next == holder, ("not prev one"));
prev->next = holder->next;
}
if (holder == m_tail) {
m_tail = prev;
}
m_elem_count--;
T t = SC_val(holder);
free_sc(holder, free_list);
return t;
}
//Return the element removed.
T remove_head(SC<T> ** free_list)
{
if (m_head == NULL) { return T(0); }
SC<T> * c = m_head;
m_head = m_head->next;
if (m_head == NULL) {
m_tail = NULL;
}
T t = c->val();
free_sc(c, free_list);
m_elem_count--;
return t;
}
};
//END SListEx
//The Extended List
//
//Add a hash-mapping table upon List in order to speed up the process
//when inserting or removing an element if a 'marker' given.
//
//NOTICE: User must define a mapping class bewteen.
template <class T, class MapTypename2Holder> class EList : public List<T> {
protected:
MapTypename2Holder m_typename2holder; //map typename 'T' to its list holder.
public:
EList() {}
COPY_CONSTRUCTOR(EList);
virtual ~EList() {} //MapTypename2Holder has virtual function.
void copy(IN List<T> & src)
{
clean();
T t = src.get_head();
for (INT n = src.get_elem_count(); n > 0; n--) {
append_tail(t);
t = src.get_next();
}
}
void clean()
{
List<T>::clean();
m_typename2holder.clean();
}
size_t count_mem() const
{
size_t count = m_typename2holder.count_mem();
count += ((List<T>*)this)->count_mem();
return count;
}
C<T> * append_tail(T t)
{
C<T> * c = List<T>::append_tail(t);
m_typename2holder.setAlways(t, c);
return c;
}
C<T> * append_head(T t)
{
C<T> * c = List<T>::append_head(t);
m_typename2holder.setAlways(t, c);
return c;
}
void append_tail(IN List<T> & list)
{
UINT i = 0;
C<T> * c;
for (T t = list.get_head(); i < list.get_elem_count();
i++, t = list.get_next()) {
c = List<T>::append_tail(t);
m_typename2holder.setAlways(t, c);
}
}
void append_head(IN List<T> & list)
{
UINT i = 0;
C<T> * c;
for (T t = list.get_tail(); i < list.get_elem_count();
i++, t = list.get_prev()) {
c = List<T>::append_head(t);
m_typename2holder.setAlways(t, c);
}
}
T remove(T t)
{
C<T> * c = m_typename2holder.get(t);
if (c == NULL) {
return T(0);
}
T tt = List<T>::remove(c);
m_typename2holder.setAlways(t, NULL);
return tt;
}
T remove(C<T> * holder)
{
ASSERT0(m_typename2holder.get(holder->val()) == holder);
T t = List<T>::remove(holder);
m_typename2holder.setAlways(t, NULL);
return t;
}
T remove_tail()
{
T t = List<T>::remove_tail();
m_typename2holder.setAlways(t, NULL);
return t;
}
T remove_head()
{
T t = List<T>::remove_head();
m_typename2holder.setAlways(t, NULL);
return t;
}
//NOTICE: 'marker' should have been in the list.
C<T> * insert_before(T t, T marker)
{
C<T> * marker_holder = m_typename2holder.get(marker);
if (marker_holder == NULL) {
ASSERT0(List<T>::get_elem_count() == 0);
C<T> * t_holder = List<T>::append_head(t);
m_typename2holder.setAlways(t, t_holder);
return t_holder;
}
C<T> * t_holder = List<T>::insert_before(t, marker_holder);
m_typename2holder.setAlways(t, t_holder);
return t_holder;
}
//NOTICE: 'marker' should have been in the list,
//and marker will be modified.
C<T> * insert_before(T t, C<T> * marker)
{
ASSERT0(marker && m_typename2holder.get(marker->val()) == marker);
C<T> * t_holder = List<T>::insert_before(t, marker);
m_typename2holder.setAlways(t, t_holder);
return t_holder;
}
//NOTICE: 'marker' should have been in the list.
void insert_before(C<T> * c, C<T> * marker)
{
ASSERT0(c && marker && m_typename2holder.get(marker->val()) == marker);
List<T>::insert_before(c, marker);
m_typename2holder.setAlways(c->val(), c);
}
//NOTICE: 'marker' should have been in the list.
C<T> * insert_after(T t, T marker)
{
C<T> * marker_holder = m_typename2holder.get(marker);
if (marker_holder == NULL) {
ASSERT0(List<T>::get_elem_count() == 0);
C<T> * t_holder = List<T>::append_tail(t);
m_typename2holder.setAlways(t, t_holder);
return t_holder;
}
C<T> * t_holder = List<T>::insert_after(t, marker_holder);
m_typename2holder.setAlways(t, t_holder);
return t_holder;
}
//NOTICE: 'marker' should have been in the list.
C<T> * insert_after(T t, C<T> * marker)
{
ASSERT0(marker && m_typename2holder.get(marker->val()) == marker);
C<T> * marker_holder = marker;
C<T> * t_holder = List<T>::insert_after(t, marker_holder);
m_typename2holder.setAlways(t, t_holder);
return t_holder;
}
//NOTICE: 'marker' should have been in the list.
void insert_after(C<T> * c, C<T> * marker)
{
ASSERT0(c && marker && m_typename2holder.get(marker->val()) == marker);
List<T>::insert_after(c, marker);
m_typename2holder.setAlways(c->val(), c);
}
bool find(T t, C<T> ** holder = NULL) const
{
C<T> * c = m_typename2holder.get(t);
if (c == NULL) {
return false;
}
if (holder != NULL) {
*holder = c;
}
return true;
}
MapTypename2Holder * get_holder_map() const { return &m_typename2holder; }
T get_cur() const //Do NOT update 'm_cur'
{ return List<T>::get_cur(); }
T get_cur(IN OUT C<T> ** holder) const //Do NOT update 'm_cur'
{ return List<T>::get_cur(holder); }
T get_next() //Update 'm_cur'
{ return List<T>::get_next(); }
T get_prev() //Update 'm_cur'
{ return List<T>::get_prev(); }
T get_next(IN OUT C<T> ** holder) const //Do NOT update 'm_cur'
{ return List<T>::get_next(holder); }
C<T> * get_next(IN C<T> * holder) const //Do NOT update 'm_cur'
{ return List<T>::get_next(holder); }
T get_prev(IN OUT C<T> ** holder) const //Do NOT update 'm_cur'
{ return List<T>::get_prev(holder); }
C<T> * get_prev(IN C<T> * holder) const //Do NOT update 'm_cur'
{ return List<T>::get_prev(holder); }
T get_next(T marker) const //not update 'm_cur'
{
C<T> * holder;
find(marker, &holder);
ASSERT0(holder != NULL);
return List<T>::get_next(&holder);
}
T get_prev(T marker) const //not update 'm_cur'
{
C<T> * holder;
find(marker, &holder);
ASSERT0(holder != NULL);
return List<T>::get_prev(&holder);
}
//Return the container of 'newt'.
C<T> * replace(T oldt, T newt)
{
C<T> * old_holder = m_typename2holder.get(oldt);
ASSERT(old_holder != NULL, ("old elem not exist"));
//add new one
C<T> * new_holder = List<T>::insert_before(newt, old_holder);
m_typename2holder.setAlways(newt, new_holder);
//remove old one
m_typename2holder.setAlways(oldt, NULL);
List<T>::remove(old_holder);
return new_holder;
}
};
//END EList
//STACK
template <class T> class Stack : public List<T> {
public:
Stack() {}
COPY_CONSTRUCTOR(Stack);
void push(T t) { List<T>::append_tail(t); }
T pop() { return List<T>::remove_tail(); }
T get_bottom() { return List<T>::get_head(); }
T get_top() { return List<T>::get_tail(); }
T get_top_nth(INT n) { return List<T>::get_tail_nth(n); }
T get_bottom_nth(INT n) { return List<T>::get_head_nth(n); }
};
//END Stack
//Vector
//
//T refer to element type.
//NOTE: zero is reserved and regard it as the default NULL when we
//determine whether an element is exist.
//The vector grow dynamic.
#define SVEC_init(s) ((s)->m_is_init)
template <class T, UINT GrowSize = 8> class Vector {
protected:
UINT m_elem_num:31; //The number of element in vector.
//The number of element when vector is growing.
UINT m_is_init:1;
INT m_last_idx; //Last element idx
public:
T * m_vec;
Vector()
{
SVEC_init(this) = false;
init();
}
explicit Vector(INT size)
{
SVEC_init(this) = false;
init();
grow(size);
}
Vector(Vector const& vec) { copy(vec); }
Vector const& operator = (Vector const&);
~Vector() { destroy(); }
void add(T t)
{
ASSERT(is_init(), ("VECTOR not yet initialized."));
set(m_last_idx < 0 ? 0 : m_last_idx, t);
}
inline void init()
{
if (SVEC_init(this)) { return; }
m_elem_num = 0;
m_vec = NULL;
m_last_idx = -1;
SVEC_init(this) = true;
}
inline void init(UINT size)
{
if (SVEC_init(this)) { return; }
ASSERT0(size != 0);
m_vec = (T*)::malloc(sizeof(T) * size);
ASSERT0(m_vec);
::memset(m_vec, 0, sizeof(T) * size);
m_elem_num = size;
m_last_idx = -1;
SVEC_init(this) = true;
}
bool is_init() const { return SVEC_init(this); }
inline void destroy()
{
if (!SVEC_init(this)) { return; }
m_elem_num = 0;
if (m_vec != NULL) {
::free(m_vec);
}
m_vec = NULL;
m_last_idx = -1;
SVEC_init(this) = false;
}
//The function often invoked by destructor, to speed up destruction time.
//Since reset other members is dispensable.
void destroy_vec()
{
if (m_vec != NULL) {
::free(m_vec);
}
}
T get(UINT index) const
{
ASSERT(is_init(), ("VECTOR not yet initialized."));
return (index >= (UINT)m_elem_num) ? T(0) : m_vec[index];
}
T * get_vec() { return m_vec; }
//Overloaded [] for CONST array reference create an rvalue.
//Similar to 'get()', the difference between this operation
//and get() is [] opeartion does not allow index is greater than
//or equal to m_elem_num.
//Note this operation can not be used to create lvalue.
//e.g: Vector<int> const v;
// int ex = v[i];
T const operator[](UINT index) const
{
ASSERT(is_init(), ("VECTOR not yet initialized."));
ASSERT(index < (UINT)m_elem_num, ("array subscript over boundary."));
return m_vec[index];
}
//Overloaded [] for non-const array reference create an lvalue.
//Similar to set(), the difference between this operation
//and set() is [] opeartion does not allow index is greater than
//or equal to m_elem_num.
inline T & operator[](UINT index)
{
ASSERT(is_init(), ("VECTOR not yet initialized."));
ASSERT(index < (UINT)m_elem_num, ("array subscript over boundary."));
m_last_idx = MAX((INT)index, m_last_idx);
return m_vec[index];
}
//Copy each elements of 'list' into vector.
//NOTE: The default termination factor is '0'.
// While we traversing elements of List one by one, or from head to
// tail or on opposition way, one can copy list into vector first and
// iterating the vector instead of travering list.
void copy(List<T> & list)
{
INT count = 0;
set(list.get_elem_count() - 1, 0); //Alloc memory right away.
for (T elem = list.get_head();
elem != T(0); elem = list.get_next(), count++) {
set(count, elem);
}
}
void copy(Vector const& vec)
{
ASSERT0(vec.m_elem_num > 0 ||
(vec.m_elem_num == 0 && vec.m_last_idx == -1));
UINT n = vec.m_elem_num;
if (m_elem_num < n) {
destroy();
init(n);
}
if (n > 0) {
::memcpy(m_vec, vec.m_vec, sizeof(T) * n);
}
m_last_idx = vec.m_last_idx;
}
//Clean to zero(default) till 'last_idx'.
void clean()
{
ASSERT(is_init(), ("VECTOR not yet initialized."));
if (m_last_idx < 0) {
return;
}
::memset(m_vec, 0, sizeof(T) * (m_last_idx + 1));
m_last_idx = -1; //No any elements
}
UINT count_mem() const { return m_elem_num * sizeof(T) + sizeof(Vector<T>); }
//Place elem to vector according to index.
//Growing vector if 'index' is greater than m_elem_num.
void set(UINT index, T elem)
{
ASSERT(is_init(), ("VECTOR not yet initialized."));
if (index >= (UINT)m_elem_num) {
grow(getNearestPowerOf2(index) + 2);
}
m_last_idx = MAX((INT)index, m_last_idx);
m_vec[index] = elem;
return;
}
//Return the number of element the vector could hold.
UINT get_capacity() const
{
ASSERT(is_init(), ("VECTOR not yet initialized."));
return m_elem_num;
}
INT get_last_idx() const
{
ASSERT(is_init(), ("VECTOR not yet initialized."));
ASSERT(m_last_idx < (INT)m_elem_num,
("Last index ran over Vector's size."));
return m_last_idx;
}
//Growing vector up to hold the most num_of_elem elements.
//If 'm_elem_num' is 0 , alloc vector to hold num_of_elem elements.
//Reallocate memory if necessory.
void grow(UINT num_of_elem)
{
ASSERT(is_init(), ("VECTOR not yet initialized."));
if (num_of_elem == 0) { return; }
if (m_elem_num == 0) {
ASSERT(m_vec == NULL, ("vector should be NULL if size is zero."));
m_vec = (T*)::malloc(sizeof(T) * num_of_elem);
ASSERT0(m_vec);
::memset(m_vec, 0, sizeof(T) * num_of_elem);
m_elem_num = num_of_elem;
return;
}
ASSERT0(num_of_elem > (UINT)m_elem_num);
T * tmp = (T*)::malloc(num_of_elem * sizeof(T));
ASSERT0(tmp);
::memcpy(tmp, m_vec, m_elem_num * sizeof(T));
::memset(((CHAR*)tmp) + m_elem_num * sizeof(T), 0,
(num_of_elem - m_elem_num)* sizeof(T));
::free(m_vec);
m_vec = tmp;
m_elem_num = num_of_elem;
}
//Return true if there is not any element.
bool is_empty() const { return get_last_idx() == -1; }
};
//END Vector
//The extented class to Vector.
//This class maintains an index which call Free Index of Vector.
//User can use the Free Index to get to know which slot of vector
//is T(0).
//
//e.g: assume Vector<INT> has 6 elements, {0, 3, 4, 0, 5, 0}.
//Three of them are 0, where T(0) served as default NULL and these
//elements indicate free slot.
//In the case, the first free index is 0, the second is 3, and the
//third is 5.
template <class T, UINT GrowSize = 8>
class VectorWithFreeIndex : public Vector<T, GrowSize> {
protected:
//Always refers to free space to Vector,
//and the first free space position is '0'
UINT m_free_idx;
public:
VectorWithFreeIndex()
{
SVEC_init(this) = false;
init();
}
COPY_CONSTRUCTOR(VectorWithFreeIndex);
inline void init()
{
Vector<T, GrowSize>::init();
m_free_idx = 0;
}
inline void init(UINT size)
{
Vector<T, GrowSize>::init(size);
m_free_idx = 0;
}
void copy(VectorWithFreeIndex const& vec)
{
Vector<T, GrowSize>::copy(vec);
m_free_idx = vec.m_free_idx;
}
//Clean to zero(default) till 'last_idx'.
void clean()
{
Vector<T, GrowSize>::clean();
m_free_idx = 0;
}
//Return index of free-slot into Vector, and allocate memory
//if there are not any free-slots.
//
//v: default NULL value.
//
//NOTICE:
// The condition that we considered a slot is free means the
// value of that slot is equal to v.
UINT get_free_idx(T v = T(0))
{
ASSERT((Vector<T, GrowSize>::is_init()),
("VECTOR not yet initialized."));
if (Vector<T, GrowSize>::m_elem_num == 0) {
//VECTOR is empty.
ASSERT((Vector<T, GrowSize>::m_last_idx < 0 &&
Vector<T, GrowSize>::m_vec == NULL),
("exception occur in Vector"));
grow(GrowSize);
//Free space is started at position '0',
//so next free space is position '1'.
m_free_idx = 1;
return 0;
}
//VECTOR is not empty.
UINT ret = m_free_idx;
//Seaching in second-half Vector to find the next free idx.
for (UINT i = m_free_idx + 1; i < Vector<T, GrowSize>::m_elem_num; i++) {
if (v == Vector<T, GrowSize>::m_vec[i]) {
m_free_idx = i;
return ret;
}
}
//Seaching in first-half Vector to find the next free idx.
for (UINT i = 0; i < m_free_idx; i++) {
if (v == Vector<T, GrowSize>::m_vec[i]) {
m_free_idx = i;
return ret;
}
}
m_free_idx = Vector<T, GrowSize>::m_elem_num;
grow(Vector<T, GrowSize>::m_elem_num * 2);
return ret;
}
//Growing vector by size, if 'm_size' is NULL , alloc vector.
//Reallocate memory if necessory.
void grow(UINT size)
{
if (Vector<T, GrowSize>::m_elem_num == 0) {
m_free_idx = 0;
}
Vector<T, GrowSize>::grow(size);
}
};
//Simply Vector.
//
//T: refer to element type.
//NOTE: Zero is treated as the default NULL when we
//determine the element existence.
#define SVEC_elem_num(s) ((s)->s1.m_elem_num)
template <class T, UINT GrowSize> class SimpleVec {
protected:
struct {
UINT m_elem_num:31; //The number of element in vector.
UINT m_is_init:1;
} s1;
public:
T * m_vec;
public:
SimpleVec()
{
s1.m_is_init = false;
init();
}
explicit SimpleVec(INT size)
{
s1.m_is_init = false;
init(size);
}
SimpleVec(SimpleVec const& src) { copy(src); }
SimpleVec const& operator = (SimpleVec const&);
~SimpleVec() { destroy(); }
inline void init()
{
if (s1.m_is_init) { return; }
SVEC_elem_num(this) = 0;
m_vec = NULL;
s1.m_is_init = true;
}
inline void init(UINT size)
{
if (s1.m_is_init) { return; }
ASSERT0(size != 0);
m_vec = (T*)::malloc(sizeof(T) * size);
ASSERT0(m_vec);
::memset(m_vec, 0, sizeof(T) * size);
SVEC_elem_num(this) = size;
s1.m_is_init = true;
}
inline void destroy()
{
if (!s1.m_is_init) { return; }
SVEC_elem_num(this) = 0;
if (m_vec != NULL) {
::free(m_vec);
m_vec = NULL;
}
s1.m_is_init = false;
}
//The function often invoked by destructor, to speed up destruction time.
//Since reset other members is dispensable.
void destroy_vec()
{
if (m_vec != NULL) {
::free(m_vec);
m_vec = NULL;
SVEC_elem_num(this) = 0;
}
}
T get(UINT i) const
{
ASSERT(s1.m_is_init, ("SimpleVec not yet initialized."));
if (i >= SVEC_elem_num(this)) { return T(0); }
return m_vec[i];
}
T * get_vec() { return m_vec; }
void copy(SimpleVec const& vec)
{
UINT n = SVEC_elem_num(&vec);
if (SVEC_elem_num(this) < n) {
destroy();
init(n);
}
if (n > 0) {
::memcpy(m_vec, vec.m_vec, sizeof(T) * n);
}
}
//Clean to zero(default) till 'last_idx'.
void clean()
{
ASSERT(s1.m_is_init, ("SimpleVec not yet initialized."));
::memset(m_vec, 0, sizeof(T) * SVEC_elem_num(this));
}
UINT count_mem() const { return SVEC_elem_num(this) + sizeof(Vector<T>); }
//Return NULL if 'i' is illegal, otherwise return 'elem'.
void set(UINT i, T elem)
{
ASSERT(is_init(), ("SimpleVec not yet initialized."));
if (i >= SVEC_elem_num(this)) {
grow(i * 2 + 1);
}
m_vec[i] = elem;
return;
}
//Return the number of element the vector could hold.
UINT get_capacity() const
{
ASSERT(is_init(), ("SimpleVec not yet initialized."));
return SVEC_elem_num(this);
}
//Growing vector by size, if 'm_size' is NULL , alloc vector.
//Reallocate memory if necessory.
void grow(UINT size)
{
ASSERT(is_init(), ("SimpleVec not yet initialized."));
if (size == 0) { return; }
if (SVEC_elem_num(this) == 0) {
ASSERT(m_vec == NULL,
("SimpleVec should be NULL if size is zero."));
m_vec = (T*)::malloc(sizeof(T) * size);
ASSERT0(m_vec);
::memset(m_vec, 0, sizeof(T) * size);
SVEC_elem_num(this) = size;
return;
}
ASSERT0(size > SVEC_elem_num(this));
T * tmp = (T*)::malloc(size * sizeof(T));
ASSERT0(tmp);
::memcpy(tmp, m_vec, SVEC_elem_num(this) * sizeof(T));
::memset(((CHAR*)tmp) + SVEC_elem_num(this) * sizeof(T),
0, (size - SVEC_elem_num(this))* sizeof(T));
::free(m_vec);
m_vec = tmp;
SVEC_elem_num(this) = size;
}
bool is_init() const { return s1.m_is_init; }
};
//Hash
//
//Hash element recorded not only in hash table but also in Vector,
//which is used in order to speed up accessing hashed elements.
//
//NOTICE:
// 1.T(0) is defined as default NULL in Hash, so do not use T(0) as element.
//
// 2.There are four hash function classes are given as default, and
// if you are going to define you own hash function class, the
// following member functions you should supply according to your needs.
//
// * Return hash-key deduced from 'val'.
// UINT get_hash_value(OBJTY val) const
//
// * Return hash-key deduced from 't'.
// UINT get_hash_value(T * t) const
//
// * Compare t1, t2 when inserting a new element.
// bool compare(T * t1, T * t2) const
//
// * Compare t1, val when inserting a new element.
// bool compare(T * t1, OBJTY val) const
//
// 3.Use 'new'/'delete' operator to allocate/free the memory
// of dynamic object and the virtual function pointers.
#define HC_val(c) (c)->val
#define HC_vec_idx(c) (c)->vec_idx
#define HC_next(c) (c)->next
#define HC_prev(c) (c)->prev
template <class T> struct HC {
HC<T> * prev;
HC<T> * next;
UINT vec_idx;
T val;
};
#define HB_member(hm) (hm).hash_member
#define HB_count(hm) (hm).hash_member_count
class HashBucket {
public:
void * hash_member; //hash member list
UINT hash_member_count; //
};
template <class T> class HashFuncBase {
public:
UINT get_hash_value(T t, UINT bucket_size) const
{
ASSERT0(bucket_size != 0);
return ((UINT)(size_t)t) % bucket_size;
}
UINT get_hash_value(OBJTY val, UINT bucket_size) const
{
ASSERT0(bucket_size != 0);
return ((UINT)(size_t)val) % bucket_size;
}
bool compare(T t1, T t2) const
{ return t1 == t2; }
bool compare(T t1, OBJTY val) const
{ return t1 == (T)val; }
};
template <class T> class HashFuncBase2 : public HashFuncBase<T> {
public:
UINT get_hash_value(T t, UINT bucket_size) const
{
ASSERT0(bucket_size != 0);
ASSERT0(isPowerOf2(bucket_size));
return hash32bit((UINT)(size_t)t) & (bucket_size - 1);
}
UINT get_hash_value(OBJTY val, UINT bucket_size) const
{
ASSERT0(bucket_size != 0);
ASSERT0(isPowerOf2(bucket_size));
return hash32bit((UINT)(size_t)val) & (bucket_size - 1);
}
};
class HashFuncString {
public:
UINT get_hash_value(CHAR const* s, UINT bucket_size) const
{
ASSERT0(bucket_size != 0);
UINT v = 0;
while (*s++) {
v += (UINT)(*s);
}
return hash32bit(v) % bucket_size;
}
UINT get_hash_value(OBJTY v, UINT bucket_size) const
{
ASSERT_DUMMYUSE(sizeof(OBJTY) == sizeof(CHAR*),
("exception will taken place in type-cast"));
return get_hash_value((CHAR const*)v, bucket_size);
}
bool compare(CHAR const* s1, CHAR const* s2) const
{ return strcmp(s1, s2) == 0; }
bool compare(CHAR const* s, OBJTY val) const
{
ASSERT_DUMMYUSE(sizeof(OBJTY) == sizeof(CHAR const*),
("exception will taken place in type-cast"));
return (strcmp(s, (CHAR const*)val) == 0);
}
};
class HashFuncString2 : public HashFuncString {
public:
UINT get_hash_value(CHAR const* s, UINT bucket_size) const
{
ASSERT0(bucket_size != 0);
UINT v = 0;
while (*s++) {
v += (UINT)(*s);
}
ASSERT0(isPowerOf2(bucket_size));
return hash32bit(v) & (bucket_size - 1);
}
};
//'T': the element type.
//'HF': Hash function type.
template <class T, class HF = HashFuncBase<T> > class Hash {
protected:
HF m_hf;
SMemPool * m_free_list_pool;
FreeList<HC<T> > m_free_list; //Hold for available containers
UINT m_bucket_size;
HashBucket * m_bucket;
VectorWithFreeIndex<T, 8> m_elem_vector;
UINT m_elem_count;
inline HC<T> * newhc() //Allocate hash container.
{
ASSERT(m_bucket != NULL, ("HASH not yet initialized."));
ASSERT0(m_free_list_pool);
HC<T> * c = m_free_list.get_free_elem();
if (c == NULL) {
c = (HC<T>*)smpoolMallocConstSize(sizeof(HC<T>), m_free_list_pool);
ASSERT0(c);
::memset(c, 0, sizeof(HC<T>));
}
return c;
}
//Insert element into hash table.
//Return true if 't' already exist.
inline bool insert_v(OUT HC<T> ** bucket_entry, OUT HC<T> ** hc, OBJTY val)
{
HC<T> * elemhc = *bucket_entry;
HC<T> * prev = NULL;
while (elemhc != NULL) {
ASSERT(HC_val(elemhc) != T(0),
("Hash element has so far as to be overrided!"));
if (m_hf.compare(HC_val(elemhc), val)) {
*hc = elemhc;
return true;
}
prev = elemhc;
elemhc = HC_next(elemhc);
} //end while
elemhc = newhc();
ASSERT(elemhc, ("newhc() return NULL"));
HC_val(elemhc) = create(val);
if (prev != NULL) {
//Append on element-list
HC_next(prev) = elemhc;
HC_prev(elemhc) = prev;
} else {
*bucket_entry = elemhc;
}
*hc = elemhc;
return false;
}
//Insert element into hash table.
//Return true if 't' already exist.
inline bool insert_t(IN OUT HC<T> ** bucket_entry, OUT HC<T> ** hc, IN T t)
{
HC<T> * prev = NULL;
HC<T> * elemhc = *bucket_entry;
while (elemhc != NULL) {
ASSERT(HC_val(elemhc) != T(0), ("Container is empty"));
if (m_hf.compare(HC_val(elemhc), t)) {
t = HC_val(elemhc);
*hc = elemhc;
return true;
}
prev = elemhc;
elemhc = HC_next(elemhc);
}
elemhc = newhc();
ASSERT(elemhc, ("newhc() return NULL"));
HC_val(elemhc) = t;
if (prev != NULL) {
//Append on elem-list in the bucket.
HC_next(prev) = elemhc;
HC_prev(elemhc) = prev;
} else {
*bucket_entry = elemhc;
}
*hc = elemhc;
return false;
}
virtual T create(OBJTY v)
{
ASSERT(0, ("Inherited class need to implement"));
DUMMYUSE(v);
return T(0);
}
public:
Hash(UINT bsize = MAX_SHASH_BUCKET)
{
m_bucket = NULL;
m_bucket_size = 0;
m_free_list_pool = NULL;
m_elem_count = 0;
init(bsize);
}
COPY_CONSTRUCTOR(Hash);
virtual ~Hash() { destroy(); }
//Append 't' into hash table and record its reference into
//Vector in order to walk through the table rapidly.
//If 't' already exists, return the element immediately.
//'find': set to true if 't' already exist.
//
//NOTE:
// Do NOT append 0 to table.
// Maximum size of T equals sizeof(void*).
T append(T t, OUT HC<T> ** hct = NULL, bool * find = NULL)
{
ASSERT(m_bucket != NULL, ("Hash not yet initialized."));
if (t == T(0)) return T(0);
UINT hashv = m_hf.get_hash_value(t, m_bucket_size);
ASSERT(hashv < m_bucket_size,
("hash value must less than bucket size"));
HC<T> * elemhc = NULL;
if (!insert_t((HC<T>**)&HB_member(m_bucket[hashv]), &elemhc, t)) {
HB_count(m_bucket[hashv])++;
m_elem_count++;
//Get a free slot in elem-vector
HC_vec_idx(elemhc) = m_elem_vector.get_free_idx();
m_elem_vector.set(HC_vec_idx(elemhc), t);
if (find != NULL) {
*find = false;
}
} else if (find != NULL) {
*find = true;
}
if (hct != NULL) {
*hct = elemhc;
}
return HC_val(elemhc);
}
//Append 'val' into hash table.
//More comment see above function.
//'find': set to true if 't' already exist.
//
//NOTE: Do NOT append T(0) to table.
T append(OBJTY val, OUT HC<T> ** hct = NULL, bool * find = NULL)
{
ASSERT(m_bucket != NULL, ("Hash not yet initialized."));
UINT hashv = m_hf.get_hash_value(val, m_bucket_size);
ASSERT(hashv < m_bucket_size, ("hash value must less than bucket size"));
HC<T> * elemhc = NULL;
if (!insert_v((HC<T>**)&HB_member(m_bucket[hashv]), &elemhc, val)) {
HB_count(m_bucket[hashv])++;
m_elem_count++;
//Get a free slot in elem-vector
HC_vec_idx(elemhc) = m_elem_vector.get_free_idx();
m_elem_vector.set(HC_vec_idx(elemhc), HC_val(elemhc));
if (find != NULL) {
*find = false;
}
} else if (find != NULL) {
*find = true;
}
if (hct != NULL) {
*hct = elemhc;
}
return HC_val(elemhc);
}
//Count up the memory which hash table used.
size_t count_mem() const
{
size_t count = smpoolGetPoolSize(m_free_list_pool);
count += m_free_list.count_mem();
count += sizeof(m_bucket_size);
count += sizeof(m_bucket);
count += m_bucket_size;
count += m_elem_vector.count_mem();
count += sizeof(m_elem_count);
return count;
}
//Clean the data structure but not destroy.
void clean()
{
if (m_bucket == NULL) return;
::memset(m_bucket, 0, sizeof(HashBucket) * m_bucket_size);
m_elem_count = 0;
m_elem_vector.clean();
}
//Get the hash bucket size.
UINT get_bucket_size() const { return m_bucket_size; }
//Get the hash bucket.
HashBucket const* get_bucket() const { return m_bucket; }
//Get the memory pool handler of free_list.
//Note this pool is const size.
SMemPool * get_free_list_pool() const { return m_free_list_pool; };
//Get the number of element in hash table.
UINT get_elem_count() const { return m_elem_count; }
//This function return the first element if it exists, and initialize
//the iterator, otherwise return T(0), where T is the template parameter.
//
//When T is type of integer, return zero may be fuzzy and ambiguous.
//Invoke get_next() to get the next element.
//
//'iter': iterator, when the function return, cur will be updated.
// If the first element exist, cur is a value that great and equal 0,
// or is -1.
T get_first(INT & iter) const
{
ASSERT(m_bucket != NULL, ("Hash not yet initialized."));
T t = T(0);
iter = -1;
if (m_elem_count <= 0) return T(0);
INT l = m_elem_vector.get_last_idx();
for (INT i = 0; i <= l; i++) {
if ((t = m_elem_vector.get((UINT)i)) != T(0)) {
iter = i;
return t;
}
}
return T(0);
}
//This function return the next element of given iterator.
//If it exists, record its index at 'iter' and return the element,
//otherwise set 'iter' to -1, and return T(0), where T is the
//template parameter.
//
//'iter': iterator, when the function return, cur will be updated.
// If the first element exist, cur is a value that great and equal 0,
// or is -1.
T get_next(INT & iter) const
{
ASSERT(m_bucket != NULL && iter >= -1, ("Hash not yet initialized."));
T t = T(0);
if (m_elem_count <= 0) return T(0);
INT l = m_elem_vector.get_last_idx();
for (INT i = iter + 1; i <= l; i++) {
if ((t = m_elem_vector.get((UINT)i)) != T(0)) {
iter = i;
return t;
}
}
iter = -1;
return T(0);
}
//This function return the last element if it exists, and initialize
//the iterator, otherwise return T(0), where T is the template parameter.
//When T is type of integer, return zero may be fuzzy and ambiguous.
//Invoke get_prev() to get the prev element.
//
//'iter': iterator, when the function return, cur will be updated.
// If the first element exist, cur is a value that great and equal 0,
// or is -1.
T get_last(INT & iter) const
{
ASSERT(m_bucket != NULL, ("Hash not yet initialized."));
T t = T(0);
iter = -1;
if (m_elem_count <= 0) return T(0);
INT l = m_elem_vector.get_last_idx();
for (INT i = l; i >= 0; i--) {
if ((t = m_elem_vector.get((UINT)i)) != T(0)) {
iter = i;
return t;
}
}
return T(0);
}
//This function return the previous element of given iterator.
//If it exists, record its index at 'iter' and return the element,
//otherwise set 'iter' to -1, and return T(0), where T is the
//template parameter.
//
//'iter': iterator, when the function return, cur will be updated.
// If the first element exist, cur is a value that great and equal 0,
// or is -1.
T get_prev(INT & iter) const
{
ASSERT(m_bucket != NULL, ("Hash not yet initialized."));
T t = T(0);
if (m_elem_count <= 0) return T(0);
for (INT i = iter - 1; i >= 0; i--) {
if ((t = m_elem_vector.get((UINT)i)) != T(0)) {
iter = i;
return t;
}
}
iter = -1;
return T(0);
}
void init(UINT bsize = MAX_SHASH_BUCKET)
{
if (m_bucket != NULL || bsize == 0) { return; }
m_bucket = (HashBucket*)::malloc(sizeof(HashBucket) * bsize);
::memset(m_bucket, 0, sizeof(HashBucket) * bsize);
m_bucket_size = bsize;
m_elem_count = 0;
m_free_list_pool = smpoolCreate(sizeof(HC<T>) * 4, MEM_CONST_SIZE);
m_free_list.clean();
m_free_list.set_clean(true);
m_elem_vector.init();
}
//Free all memory objects.
void destroy()
{
if (m_bucket == NULL) return;
::free(m_bucket);
m_bucket = NULL;
m_bucket_size = 0;
m_elem_count = 0;
m_elem_vector.destroy();
smpoolDelete(m_free_list_pool);
m_free_list_pool = NULL;
}
//Dump the distribution of element in hash.
void dump_intersp(FILE * h) const
{
if (h == NULL) return;
UINT bsize = get_bucket_size();
HashBucket const* bucket = get_bucket();
fprintf(h, "\n=== Hash ===");
for (UINT i = 0; i < bsize; i++) {
HC<T> * elemhc = (HC<T>*)bucket[i].hash_member;
fprintf(h, "\nENTRY[%d]:", i);
while (elemhc != NULL) {
fprintf(h, "*");
elemhc = HC_next(elemhc);
if (elemhc != NULL) {
//fprintf(g_tfile, ",");
}
}
}
fflush(h);
}
//This function remove one element, and return the removed one.
//Note that 't' may be different with the return one accroding to
//the behavior of user's defined HF class.
//
//Do NOT change the order that elements in m_elem_vector and the
//value of m_cur. Because it will impact the effect of get_first(),
//get_next(), get_last() and get_prev().
T removed(T t)
{
ASSERT(m_bucket != NULL, ("Hash not yet initialized."));
if (t == 0) return T(0);
UINT hashv = m_hf.get_hash_value(t, m_bucket_size);
ASSERT(hashv < m_bucket_size,
("hash value must less than bucket size"));
HC<T> * elemhc = (HC<T>*)HB_member(m_bucket[hashv]);
if (elemhc != NULL) {
while (elemhc != NULL) {
ASSERT(HC_val(elemhc) != T(0),
("Hash element has so far as to be overrided!"));
if (m_hf.compare(HC_val(elemhc), t)) {
break;
}
elemhc = HC_next(elemhc);
}
if (elemhc != NULL) {
m_elem_vector.set(HC_vec_idx(elemhc), T(0));
remove((HC<T>**)&HB_member(m_bucket[hashv]), elemhc);
m_free_list.add_free_elem(elemhc);
HB_count(m_bucket[hashv])--;
m_elem_count--;
return t;
}
}
return T(0);
}
//Grow hash to 'bsize' and rehash all elements in the table.
//The default grow size is twice as the current bucket size.
//
//'bsize': expected bucket size, the size can not less than current size.
//
//NOTE: Extending hash table is costly.
//The position of element in m_elem_vector is unchanged.
void grow(UINT bsize = 0)
{
ASSERT(m_bucket != NULL, ("Hash not yet initialized."));
if (bsize != 0) {
ASSERT0(bsize > m_bucket_size);
} else {
bsize = m_bucket_size * 2;
}
HashBucket * new_bucket =
(HashBucket*)::malloc(sizeof(HashBucket) * bsize);
::memset(new_bucket, 0, sizeof(HashBucket) * bsize);
if (m_elem_count == 0) {
::free(m_bucket);
m_bucket = new_bucket;
m_bucket_size = bsize;
return;
}
//Free HC containers.
for (UINT i = 0; i < m_bucket_size; i++) {
HC<T> * hc = NULL;
while ((hc = xcom::removehead((HC<T>**)&HB_member(m_bucket[i]))) != NULL) {
m_free_list.add_free_elem(hc);
}
}
//Free bucket.
::free(m_bucket);
m_bucket = new_bucket;
m_bucket_size = bsize;
//Rehash all elements, and the position in m_elem_vector is unchanged.
INT l = m_elem_vector.get_last_idx();
for (INT i = 0; i <= l; i++) {
T t = m_elem_vector.get((UINT)i);
if (t == T(0)) { continue; }
UINT hashv = m_hf.get_hash_value(t, m_bucket_size);
ASSERT(hashv < m_bucket_size,
("hash value must less than bucket size"));
HC<T> * elemhc = NULL;
bool doit = insert_t((HC<T>**)&HB_member(m_bucket[hashv]),
&elemhc, t);
ASSERT0(!doit);
DUMMYUSE(doit); //to avoid -Werror=unused-variable.
HC_vec_idx(elemhc) = (UINT)i;
HB_count(m_bucket[hashv])++;
}
}
//Find element accroding to specific 'val'.
//You can implement your own find(), but do NOT
//change the order that elements in m_elem_vector and the value of m_cur.
//Because it will impact the effect of get_first(), get_next(),
//get_last() and get_prev().
T find(OBJTY val) const
{
ASSERT(m_bucket != NULL, ("Hash not yet initialized."));
UINT hashv = m_hf.get_hash_value(val, m_bucket_size);
ASSERT(hashv < m_bucket_size, ("hash value must less than bucket size"));
HC<T> const* elemhc = (HC<T> const*)HB_member(m_bucket[hashv]);
if (elemhc != NULL) {
while (elemhc != NULL) {
ASSERT(HC_val(elemhc) != T(0),
("Hash element has so far as to be overrided!"));
if (m_hf.compare(HC_val(elemhc), val)) {
return HC_val(elemhc);
}
elemhc = HC_next(elemhc);
}
}
return T(0);
}
//Find one element and return the container.
//Return true if t exist, otherwise return false.
//You can implement your own find(), but do NOT
//change the order that elements in m_elem_vector and the value of m_cur.
//Because it will impact the effect of get_first(), get_next(),
//get_last() and get_prev().
bool find(T t, HC<T> const** ct = NULL) const
{
ASSERT(m_bucket != NULL, ("Hash not yet initialized."));
if (t == T(0)) { return false; }
UINT hashv = m_hf.get_hash_value(t, m_bucket_size);
ASSERT(hashv < m_bucket_size,
("hash value must less than bucket size"));
HC<T> const* elemhc = (HC<T> const*)HB_member(m_bucket[hashv]);
if (elemhc != NULL) {
while (elemhc != NULL) {
ASSERT(HC_val(elemhc) != T(0),
("Hash element has so far as to be overrided!"));
if (m_hf.compare(HC_val(elemhc), t)) {
if (ct != NULL) {
*ct = elemhc;
}
return true;
}
elemhc = HC_next(elemhc);
}
}
return false;
}
//Find one element and return the element which record in hash table.
//Note t may be different with the return one.
//
//You can implement your own find(), but do NOT
//change the order that elements in m_elem_vector and the value of m_cur.
//Because it will impact the effect of get_first(), get_next(),
//get_last() and get_prev().
//
//'ot': output the element if found it.
bool find(T t, OUT T * ot) const
{
HC<T> const* hc;
if (find(t, &hc)) {
ASSERT0(ot != NULL);
*ot = HC_val(hc);
return true;
}
return false;
}
};
//END Hash
//
//START RBTNode
//
typedef enum _RBT_RED {
RBT_NON = 0,
RBRED = 1,
RBBLACK = 2,
} RBCOL;
template <class T, class Ttgt>
class RBTNode {
public:
RBTNode * parent;
union {
RBTNode * lchild;
RBTNode * prev;
};
union {
RBTNode * rchild;
RBTNode * next;
};
T key;
Ttgt mapped;
RBCOL color;
RBTNode() { clean(); }
void clean()
{
parent = NULL;
lchild = NULL;
rchild = NULL;
key = T(0);
mapped = Ttgt(0);
color = RBBLACK;
}
};
template <class T> class CompareKeyBase {
public:
bool is_less(T t1, T t2) const { return t1 < t2; }
bool is_equ(T t1, T t2) const { return t1 == t2; }
T createKey(T t) { return t; }
};
template <class T, class Ttgt, class CompareKey = CompareKeyBase<T> >
class RBT {
protected:
typedef RBTNode<T, Ttgt> RBTNType;
UINT m_num_of_tn;
RBTNType * m_root;
SMemPool * m_pool;
RBTNType * m_free_list;
CompareKey m_ck;
RBTNType * new_tn()
{
RBTNType * p = (RBTNType*)smpoolMallocConstSize(sizeof(RBTNType), m_pool);
ASSERT0(p);
::memset(p, 0, sizeof(RBTNType));
return p;
}
inline RBTNType * new_tn(T t, RBCOL c)
{
RBTNType * x = xcom::removehead(&m_free_list);
if (x == NULL) {
x = new_tn();
} else {
x->lchild = NULL;
x->rchild = NULL;
}
x->key = m_ck.createKey(t);
x->color = c;
return x;
}
void free_rbt(RBTNType * t)
{
if (t == NULL) return;
t->prev = t->next = t->parent = NULL;
t->key = T(0);
t->mapped = Ttgt(0);
insertbefore_one(&m_free_list, m_free_list, t);
}
void rleft(RBTNType * x)
{
ASSERT0(x->rchild != NULL);
RBTNType * y = x->rchild;
y->parent = x->parent;
x->parent = y;
x->rchild = y->lchild;
if (y->lchild != NULL) {
y->lchild->parent = x;
}
y->lchild = x;
if (y->parent == NULL) {
m_root = y;
} else if (y->parent->lchild == x) {
y->parent->lchild = y;
} else if (y->parent->rchild == x) {
y->parent->rchild = y;
}
}
void rright(RBTNType * y)
{
ASSERT0(y->lchild != NULL);
RBTNType * x = y->lchild;
x->parent = y->parent;
y->parent = x;
y->lchild = x->rchild;
if (x->rchild != NULL) {
x->rchild->parent = y;
}
x->rchild = y;
if (x->parent == NULL) {
m_root = x;
} else if (x->parent->lchild == y) {
x->parent->lchild = x;
} else if (x->parent->rchild == y) {
x->parent->rchild = x;
}
}
bool is_lchild(RBTNType const* z) const
{
ASSERT0(z && z->parent);
return z == z->parent->lchild;
}
bool is_rchild(RBTNType const* z) const
{
ASSERT0(z && z->parent);
return z == z->parent->rchild;
}
void fixup(RBTNType * z)
{
RBTNType * y = NULL;
while (z->parent != NULL && z->parent->color == RBRED) {
if (is_lchild(z->parent)) {
y = z->parent->parent->rchild;
if (y != NULL && y->color == RBRED) {
z->parent->color = RBBLACK;
z->parent->parent->color = RBRED;
y->color = RBBLACK;
z = z->parent->parent;
} else if (is_rchild(z)) {
z = z->parent;
rleft(z);
} else {
ASSERT0(is_lchild(z));
z->parent->color = RBBLACK;
z->parent->parent->color = RBRED;
rright(z->parent->parent);
}
} else {
ASSERT0(is_rchild(z->parent));
y = z->parent->parent->lchild;
if (y != NULL && y->color == RBRED) {
z->parent->color = RBBLACK;
z->parent->parent->color = RBRED;
y->color = RBBLACK;
z = z->parent->parent;
} else if (is_lchild(z)) {
z = z->parent;
rright(z);
} else {
ASSERT0(is_rchild(z));
z->parent->color = RBBLACK;
z->parent->parent->color = RBRED;
rleft(z->parent->parent);
}
}
}
m_root->color = RBBLACK;
}
public:
RBT()
{
m_pool = NULL;
init();
}
COPY_CONSTRUCTOR(RBT);
~RBT() { destroy(); }
void init()
{
if (m_pool != NULL) { return; }
m_pool = smpoolCreate(sizeof(RBTNType) * 4, MEM_CONST_SIZE);
m_root = NULL;
m_num_of_tn = 0;
m_free_list = NULL;
}
void destroy()
{
if (m_pool == NULL) { return; }
smpoolDelete(m_pool);
m_pool = NULL;
m_num_of_tn = 0;
m_root = NULL;
m_free_list = NULL;
}
size_t count_mem() const
{
size_t c = sizeof(m_num_of_tn);
c += sizeof(m_root);
c += sizeof(m_pool);
c += sizeof(m_free_list);
c += smpoolGetPoolSize(m_pool);
return c;
}
void clean()
{
List<RBTNType*> wl;
if (m_root != NULL) {
wl.append_tail(m_root);
m_root = NULL;
}
while (wl.get_elem_count() != 0) {
RBTNType * x = wl.remove_head();
if (x->rchild != NULL) {
wl.append_tail(x->rchild);
}
if (x->lchild != NULL) {
wl.append_tail(x->lchild);
}
free_rbt(x);
}
m_num_of_tn = 0;
}
UINT get_elem_count() const { return m_num_of_tn; }
SMemPool * get_pool() { return m_pool; }
RBTNType * get_root() { return m_root; }
RBTNType * find_with_key(T keyt) const
{
if (m_root == NULL) { return NULL; }
RBTNType * x = m_root;
while (x != NULL) {
if (m_ck.is_equ(keyt, x->key)) {
return x;
} else if (m_ck.is_less(keyt, x->key)) {
x = x->lchild;
} else {
x = x->rchild;
}
}
return NULL;
}
inline RBTNType * find_rbtn(T t) const
{
if (m_root == NULL) { return NULL; }
return find_with_key(t);
}
RBTNType * insert(T t, bool * find = NULL)
{
if (m_root == NULL) {
RBTNType * z = new_tn(t, RBBLACK);
m_num_of_tn++;
m_root = z;
if (find != NULL) {
*find = false;
}
return z;
}
RBTNType * mark = NULL;
RBTNType * x = m_root;
while (x != NULL) {
mark = x;
if (m_ck.is_equ(t, x->key)) {
break;
} else if (m_ck.is_less(t, x->key)) {
x = x->lchild;
} else {
x = x->rchild;
}
}
if (x != NULL) {
ASSERT0(m_ck.is_equ(t, x->key));
if (find != NULL) {
*find = true;
}
return x;
}
if (find != NULL) {
*find = false;
}
//Add new.
RBTNType * z = new_tn(t, RBRED);
z->parent = mark;
if (mark == NULL) {
//The first node.
m_root = z;
} else {
if (m_ck.is_less(t, mark->key)) {
mark->lchild = z;
} else {
mark->rchild = z;
}
}
ASSERT0(z->lchild == NULL && z->rchild == NULL);
m_num_of_tn++;
fixup(z);
return z;
}
RBTNType * find_min(RBTNType * x)
{
ASSERT0(x);
while (x->lchild != NULL) { x = x->lchild; }
return x;
}
RBTNType * find_succ(RBTNType * x)
{
if (x->rchild != NULL) { return find_min(x->rchild); }
RBTNType * y = x->parent;
while (y != NULL && x == y->rchild) {
x = y;
y = y->parent;
}
return y;
}
inline bool both_child_black(RBTNType * x)
{
if (x->lchild != NULL && x->lchild->color == RBRED) {
return false;
}
if (x->rchild != NULL && x->rchild->color == RBRED) {
return false;
}
return true;
}
void rmfixup(RBTNType * x)
{
ASSERT0(x);
while (x != m_root && x->color == RBBLACK) {
if (is_lchild(x)) {
RBTNType * bro = x->parent->rchild;
ASSERT0(bro);
if (bro->color == RBRED) {
bro->color = RBBLACK;
x->parent->color = RBRED;
rleft(x->parent);
bro = x->parent->rchild;
}
if (both_child_black(bro)) {
bro->color = RBRED;
x = x->parent;
continue;
} else if (bro->rchild == NULL ||
bro->rchild->color == RBBLACK) {
ASSERT0(bro->lchild && bro->lchild->color == RBRED);
bro->lchild->color = RBBLACK;
bro->color = RBRED;
rright(bro);
bro = x->parent->rchild;
}
bro->color = x->parent->color;
x->parent->color = RBBLACK;
bro->rchild->color = RBBLACK;
rleft(x->parent);
x = m_root;
} else {
ASSERT0(is_rchild(x));
RBTNType * bro = x->parent->lchild;
if (bro->color == RBRED) {
bro->color = RBBLACK;
x->parent->color = RBRED;
rright(x->parent);
bro = x->parent->lchild;
}
if (both_child_black(bro)) {
bro->color = RBRED;
x = x->parent;
continue;
} else if (bro->lchild == NULL ||
bro->lchild->color == RBBLACK) {
ASSERT0(bro->rchild && bro->rchild->color == RBRED);
bro->rchild->color = RBBLACK;
bro->color = RBRED;
rleft(bro);
bro = x->parent->lchild;
}
bro->color = x->parent->color;
x->parent->color = RBBLACK;
bro->lchild->color = RBBLACK;
rright(x->parent);
x = m_root;
}
}
x->color = RBBLACK;
}
void remove(T t)
{
RBTNType * z = find_rbtn(t);
if (z == NULL) { return; }
remove(z);
}
void remove(RBTNType * z)
{
if (z == NULL) { return; }
if (m_num_of_tn == 1) {
ASSERT(z == m_root, ("z is not the node of tree"));
ASSERT(z->rchild == NULL && z->lchild == NULL,
("z is the last node"));
free_rbt(z);
m_num_of_tn--;
m_root = NULL;
return;
}
RBTNType * y;
if (z->lchild == NULL || z->rchild == NULL) {
y = z;
} else {
y = find_min(z->rchild);
}
RBTNType * x = y->lchild != NULL ? y->lchild : y->rchild;
RBTNType holder;
if (x != NULL) {
x->parent = y->parent;
} else {
holder.parent = y->parent;
}
if (y->parent == NULL) {
m_root = x;
} else if (is_lchild(y)) {
if (x != NULL) {
y->parent->lchild = x;
} else {
y->parent->lchild = &holder;
}
} else {
if (x != NULL) {
y->parent->rchild = x;
} else {
y->parent->rchild = &holder;
}
}
if (y != z) {
z->key = y->key;
z->mapped = y->mapped;
}
if (y->color == RBBLACK) {
//Need to keep RB tree property: the number
//of black must be same in all path.
if (x != NULL) {
rmfixup(x);
} else {
rmfixup(&holder);
if (is_rchild(&holder)) {
holder.parent->rchild = NULL;
} else {
ASSERT0(is_lchild(&holder));
holder.parent->lchild = NULL;
}
}
} else if (holder.parent != NULL) {
if (is_rchild(&holder)) {
holder.parent->rchild = NULL;
} else {
ASSERT0(is_lchild(&holder));
holder.parent->lchild = NULL;
}
}
free_rbt(y);
m_num_of_tn--;
}
//iter should be clean by caller.
T get_first(List<RBTNType*> & iter, Ttgt * mapped = NULL) const
{
if (m_root == NULL) {
if (mapped != NULL) { *mapped = Ttgt(0); }
return T(0);
}
iter.append_tail(m_root);
if (mapped != NULL) { *mapped = m_root->mapped; }
return m_root->key;
}
T get_next(List<RBTNType*> & iter, Ttgt * mapped = NULL) const
{
RBTNType * x = iter.remove_head();
if (x == NULL) {
if (mapped != NULL) { *mapped = Ttgt(0); }
return T(0);
}
if (x->rchild != NULL) {
iter.append_tail(x->rchild);
}
if (x->lchild != NULL) {
iter.append_tail(x->lchild);
}
x = iter.get_head();
if (x == NULL) {
if (mapped != NULL) { *mapped = Ttgt(0); }
return T(0);
}
if (mapped != NULL) { *mapped = x->mapped; }
return x->key;
}
};
//END RBTNode
//TMap Iterator based on Double Linked List.
//This class is used to iterate elements in TMap.
//You should call clean() to initialize the iterator.
template <class Tsrc, class Ttgt>
class TMapIter : public List<RBTNode<Tsrc, Ttgt>*> {
public:
TMapIter() {}
COPY_CONSTRUCTOR(TMapIter);
};
//TMap Iterator based on Single Linked List.
//This class is used to iterate elements in TMap.
//You should call clean() to initialize the iterator.
template <class Tsrc, class Ttgt>
class TMapIter2 : public SList<RBTNode<Tsrc, Ttgt>*> {
public:
typedef RBTNode<Tsrc, Ttgt>* Container;
public:
TMapIter2(SMemPool * pool) : SList<RBTNode<Tsrc, Ttgt>*>(pool)
{ ASSERT0(pool); }
COPY_CONSTRUCTOR(TMapIter2);
};
//TMap
//
//Make a map between Tsrc and Ttgt.
//
//Tsrc: the type of keys maintained by this map.
//Ttgt: the type of mapped values.
//
//Usage: Make a mapping from SRC* to TGT*.
// class SRC2TGT_MAP : public TMap<SRC*, TGT*> {
// public:
// };
//
//NOTICE:
// 1. Tsrc(0) is defined as default NULL in TMap, do NOT use T(0) as element.
// 2. Keep the key *UNIQUE* .
// 3. Overload operator == and operator < if Tsrc is neither basic type
// nor pointer type.
template <class Tsrc, class Ttgt, class CompareKey = CompareKeyBase<Tsrc> >
class TMap : public RBT<Tsrc, Ttgt, CompareKey> {
public:
typedef RBT<Tsrc, Ttgt, CompareKey> BaseType;
typedef RBTNode<Tsrc, Ttgt> RBTNType;
TMap() {}
COPY_CONSTRUCTOR(TMap);
~TMap() {}
//This function should be invoked if TMap is initialized manually.
void init() { RBT<Tsrc, Ttgt, CompareKey>::init(); }
//This function should be invoked if TMap is destroied manually.
void destroy() { RBT<Tsrc, Ttgt, CompareKey>::destroy(); }
//Alway set new mapping even if it has done.
//This function will enforce mapping between t and mapped.
Tsrc setAlways(Tsrc t, Ttgt mapped)
{
RBTNType * z = BaseType::insert(t, NULL);
ASSERT0(z);
z->mapped = mapped;
return z->key; //key may be different with t.
}
//Establishing mapping in between 't' and 'mapped'.
Tsrc set(Tsrc t, Ttgt mapped)
{
bool find = false;
RBTNType * z = BaseType::insert(t, &find);
ASSERT0(z);
ASSERT(!find, ("already mapped"));
z->mapped = mapped;
return z->key; //key may be different with t.
}
//Get mapped element of 't'. Set find to true if t is already be mapped.
//Note this function is readonly.
Ttgt get(Tsrc t, bool * f = NULL) const
{
RBTNType * z = BaseType::find_rbtn(t);
if (z == NULL) {
if (f != NULL) {
*f = false;
}
return Ttgt(0);
}
if (f != NULL) {
*f = true;
}
return z->mapped;
}
//iter should be clean by caller.
Tsrc get_first(TMapIter<Tsrc, Ttgt> & iter, Ttgt * mapped = NULL) const
{ return BaseType::get_first(iter, mapped); }
Tsrc get_next(TMapIter<Tsrc, Ttgt> & iter, Ttgt * mapped = NULL) const
{ return BaseType::get_next(iter, mapped); }
bool find(Tsrc t) const
{
bool f;
get(t, &f);
return f;
}
void remove(Tsrc t) { BaseType::remove(t); }
};
//END TMap
//TTab
//
//NOTICE:
// 1. T(0) is defined as default NULL in TTab, do not use T(0) as element.
// 2. Keep the key *UNIQUE*.
// 3. Overload operator == and operator < if Tsrc is neither basic type
// nor pointer type.
//
// e.g: Make a table to record OPND.
// class OPND_TAB : public TTab<OPND*> {
// public:
// };
//TTab Iterator.
//This class is used to iterate elements in TTab.
//You should call clean() to initialize the iterator.
template <class T>
class TabIter : public List<RBTNode<T, T>*> {
public:
TabIter() {}
COPY_CONSTRUCTOR(TabIter);
};
template <class T, class CompareKey = CompareKeyBase<T> >
class TTab : public TMap<T, T, CompareKey> {
public:
TTab() {}
COPY_CONSTRUCTOR(TTab);
typedef RBT<T, T, CompareKey> BaseTypeofTMap;
typedef TMap<T, T, CompareKey> BaseTMap;
//Add element into table.
//Note: the element in the table must be unqiue.
T append(T t)
{
ASSERT0(t != T(0));
#ifdef _DEBUG_
//Mapped element may not same with 't'.
//bool find = false;
//T mapped = BaseTMap::get(t, &find);
//if (find) {
// ASSERT0(mapped == t);
//}
#endif
return BaseTMap::setAlways(t, t);
}
//Add element into table, if it is exist, return the exist one.
T append_and_retrieve(T t)
{
ASSERT0(t != T(0));
bool find = false;
T mapped = BaseTMap::get(t, &find);
if (find) {
return mapped;
}
return BaseTMap::setAlways(t, t);
}
void remove(T t)
{
ASSERT0(t != T(0));
BaseTMap::remove(t);
}
bool find(T t) const { return BaseTMap::find(t); }
//iter should be clean by caller.
T get_first(TabIter<T> & iter) const
{ return BaseTypeofTMap::get_first(iter, NULL); }
T get_next(TabIter<T> & iter) const
{ return BaseTypeofTMap::get_next(iter, NULL); }
};
//END TTab
//Unidirectional Hashed Map
//
//Tsrc: the type of keys maintained by this map.
//Ttgt: the type of mapped values.
//
//Usage: Make a mapping from OPND to OPER.
// typedef HMap<OPND*, OPER*, HashFuncBase<OPND*> > OPND2OPER_MAP;
//
//NOTICE:
// 1. Tsrc(0) is defined as default NULL in HMap, so do not use T(0) as element.
// 2. The map is implemented base on Hash, and one hash function class
// have been given.
//
// 3. Must use 'new'/'delete' operator to allocate/free the
// memory of dynamic object of MAP, because the
// virtual-function-pointers-table is needed.
template <class Tsrc, class Ttgt, class HF = HashFuncBase<Tsrc> >
class HMap : public Hash<Tsrc, HF> {
protected:
Vector<Ttgt> m_mapped_elem_table;
//Find hash container
HC<Tsrc> * findhc(Tsrc t) const
{
if (t == Tsrc(0)) { return NULL; }
UINT hashv = Hash<Tsrc, HF>::m_hf.get_hash_value(t,
Hash<Tsrc, HF>::m_bucket_size);
ASSERT((hashv < Hash<Tsrc, HF>::m_bucket_size),
("hash value must less than bucket size"));
HC<Tsrc> * elemhc =
(HC<Tsrc>*)HB_member((Hash<Tsrc, HF>::m_bucket[hashv]));
if (elemhc != NULL) {
while (elemhc != NULL) {
ASSERT(HC_val(elemhc) != Tsrc(0),
("Hash element has so far as to be overrided!"));
if (Hash<Tsrc, HF>::m_hf.compare(HC_val(elemhc), t)) {
return elemhc;
}
elemhc = HC_next(elemhc);
} //end while
}
return NULL;
}
public:
HMap(UINT bsize = MAX_SHASH_BUCKET) : Hash<Tsrc, HF>(bsize)
{ m_mapped_elem_table.init(); }
COPY_CONSTRUCTOR(HMap);
virtual ~HMap() { destroy(); }
//Alway set new mapping even if it has done.
void setAlways(Tsrc t, Ttgt mapped)
{
ASSERT((Hash<Tsrc, HF>::m_bucket != NULL), ("not yet initialize."));
if (t == Tsrc(0)) { return; }
HC<Tsrc> * elemhc = NULL;
Hash<Tsrc, HF>::append(t, &elemhc, NULL);
ASSERT(elemhc != NULL, ("Element does not append into hash table."));
m_mapped_elem_table.set(HC_vec_idx(elemhc), mapped);
}
SMemPool * get_pool() { return Hash<Tsrc, HF>::get_free_list_pool(); }
//Get mapped pointer of 't'
Ttgt get(Tsrc t, bool * find = NULL)
{
ASSERT((Hash<Tsrc, HF>::m_bucket != NULL), ("not yet initialize."));
HC<Tsrc> * elemhc = findhc(t);
if (elemhc != NULL) {
if (find != NULL) { *find = true; }
return m_mapped_elem_table.get(HC_vec_idx(elemhc));
}
if (find != NULL) { *find = false; }
return Ttgt(0);
}
Vector<Ttgt> * get_tgt_elem_vec() { return &m_mapped_elem_table; }
void clean()
{
ASSERT((Hash<Tsrc, HF>::m_bucket != NULL), ("not yet initialize."));
Hash<Tsrc, HF>::clean();
m_mapped_elem_table.clean();
}
UINT count_mem() const
{
UINT count = m_mapped_elem_table.count_mem();
count += ((Hash<Tsrc, HF>*)this)->count_mem();
return count;
}
void init(UINT bsize = MAX_SHASH_BUCKET)
{
//Only do initialization while m_bucket is NULL.
Hash<Tsrc, HF>::init(bsize);
m_mapped_elem_table.init();
}
void destroy()
{
Hash<Tsrc, HF>::destroy();
m_mapped_elem_table.destroy();
}
//This function iterate mappped elements.
//Note Ttgt(0) will be served as default NULL.
Ttgt get_first_elem(INT & pos) const
{
for (INT i = 0; i <= m_mapped_elem_table.get_last_idx(); i++) {
Ttgt t = m_mapped_elem_table.get((UINT)i);
if (t != Ttgt(0)) {
pos = i;
return t;
}
}
pos = -1;
return Ttgt(0);
}
//This function iterate mappped elements.
//Note Ttgt(0) will be served as default NULL.
Ttgt get_next_elem(INT & pos) const
{
ASSERT0(pos >= 0);
for (INT i = pos + 1; i <= m_mapped_elem_table.get_last_idx(); i++) {
Ttgt t = m_mapped_elem_table.get((UINT)i);
if (t != Ttgt(0)) {
pos = i;
return t;
}
}
pos = -1;
return Ttgt(0);
}
//Establishing mapping in between 't' and 'mapped'.
void set(Tsrc t, Ttgt mapped)
{
ASSERT((Hash<Tsrc, HF>::m_bucket != NULL), ("not yet initialize."));
if (t == Tsrc(0)) { return; }
HC<Tsrc> * elemhc = NULL;
Hash<Tsrc, HF>::append(t, &elemhc, NULL);
ASSERT(elemhc != NULL,
("Element does not append into hash table yet."));
ASSERT(Ttgt(0) == m_mapped_elem_table.get(HC_vec_idx(elemhc)),
("Already be mapped"));
m_mapped_elem_table.set(HC_vec_idx(elemhc), mapped);
}
void setv(OBJTY v, Ttgt mapped)
{
ASSERT((Hash<Tsrc, HF>::m_bucket != NULL), ("not yet initialize."));
if (v == 0) { return; }
HC<Tsrc> * elemhc = NULL;
Hash<Tsrc, HF>::append(v, &elemhc, NULL);
ASSERT(elemhc != NULL,
("Element does not append into hash table yet."));
ASSERT(Ttgt(0) == m_mapped_elem_table.get(HC_vec_idx(elemhc)),
("Already be mapped"));
m_mapped_elem_table.set(HC_vec_idx(elemhc), mapped);
}
};
//END MAP
//Dual directional Map
//
//MAP_Tsrc2Ttgt: class derive from HMap<Tsrc, Ttgt>
//MAP_Ttgt2Tsrc: class derive from HMap<Ttgt, Tsrc>
//
//Usage: Mapping OPND to corresponding OPER.
// class MAP1 : public HMap<OPND*, OPER*> {
// public:
// };
//
// class MAP2 : public HMap<OPER*, OPND*>{
// public:
// };
//
// DMap<OPND*, OPER*, MAP1, MAP2> opnd2oper_dmap;
//
//NOTICE:
// 1. Tsrc(0) is defined as default NULL in DMap, so do not use T(0) as element.
// 2. DMap Object's memory can be allocated by malloc() dynamically.
template <class Tsrc, class Ttgt, class MAP_Tsrc2Ttgt, class MAP_Ttgt2Tsrc>
class DMap {
protected:
MAP_Tsrc2Ttgt m_src2tgt_map;
MAP_Ttgt2Tsrc m_tgt2src_map;
public:
DMap() {}
COPY_CONSTRUCTOR(DMap);
~DMap() {}
//Alway overlap the old value by new 'mapped' value.
void setAlways(Tsrc t, Ttgt mapped)
{
if (t == Tsrc(0)) { return; }
m_src2tgt_map.setAlways(t, mapped);
m_tgt2src_map.setAlways(mapped, t);
}
UINT count_mem() const
{
UINT count = m_src2tgt_map.count_mem();
count += m_tgt2src_map.count_mem();
return count;
}
//Establishing mapping in between 't' and 'mapped'.
void set(Tsrc t, Ttgt mapped)
{
if (t == Tsrc(0)) { return; }
m_src2tgt_map.set(t, mapped);
m_tgt2src_map.set(mapped, t);
}
//Get mapped pointer of 't'
Ttgt get(Tsrc t)
{ return m_src2tgt_map.get(t); }
//Inverse mapping
Tsrc geti(Ttgt t)
{ return m_tgt2src_map.get(t); }
};
//END DMap
//Multiple Target Map
//
//Map src with type Tsrc to many tgt elements with type Ttgt.
//
//'TAB_Ttgt': records tgt elements.
// e.g: We implement TAB_Ttgt via deriving from Hash.
//
// class TAB_Ttgt: public Hash<Ttgt, HashFuncBase<Ttgt> > {
// public:
// };
//
// or deriving from List, typedef List<Ttgt> TAB_Ttgt;
//
//NOTICE:
// 1. Tsrc(0) is defined as default NULL in MMap, do not use T(0) as element.
//
// 2. MMap allocate memory for 'TAB_Ttgt' and return 'TAB_Ttgt *'
// when get(Tsrc) be invoked. DO NOT free these objects yourself.
//
// 3. TAB_Ttgt should be pointer type.
// e.g: Given type of tgt's table is a class that
// OP_HASH : public Hash<OPER*>,
// then type MMap<OPND*, OPER*, OP_HASH> is ok, but
// type MMap<OPND*, OPER*, OP_HASH*> is not expected.
//
// 4. Do not use DMap directly, please overload following functions optionally:
// * create hash-element container.
// T * create(OBJTY v)
//
// e.g: Mapping one OPND to a number of OPERs.
// class OPND2OPER_MMAP : public MMap<OPND*, OPER*, OP_TAB> {
// public:
// virtual T create(OBJTY id)
// {
// //Allocate OPND.
// return new OPND(id);
// }
// };
//
// 4. Please use 'new'/'delete' operator to allocate/free
// the memory of dynamic object of MMap, because the
// virtual-function-pointers-table is needed.
template <class Tsrc, class Ttgt, class TAB_Ttgt,
class HF = HashFuncBase<Tsrc> >
class MMap : public HMap<Tsrc, TAB_Ttgt*, HF> {
protected:
bool m_is_init;
public:
MMap()
{
m_is_init = false;
init();
}
COPY_CONSTRUCTOR(MMap);
virtual ~MMap() { destroy(); }
UINT count_mem() const
{
return ((HMap<Tsrc, TAB_Ttgt*, HF>*)this)->count_mem() +
sizeof(m_is_init);
}
//Establishing mapping in between 't' and 'mapped'.
void set(Tsrc t, Ttgt mapped)
{
if (t == Tsrc(0)) return;
TAB_Ttgt * tgttab = HMap<Tsrc, TAB_Ttgt*, HF>::get(t);
if (tgttab == NULL) {
//Do NOT use Hash::xmalloc(sizeof(TAB_Ttgt)) to allocate memory,
//because __vfptr is NULL. __vfptr points to TAB_Ttgt::vftable.
tgttab = new TAB_Ttgt;
HMap<Tsrc, TAB_Ttgt*, HF>::set(t, tgttab);
}
tgttab->append_node(mapped);
}
//Get mapped elements of 't'
TAB_Ttgt * get(Tsrc t)
{ return HMap<Tsrc, TAB_Ttgt*, HF>::get(t); }
void init()
{
if (m_is_init) { return; }
HMap<Tsrc, TAB_Ttgt*, HF>::init();
m_is_init = true;
}
void destroy()
{
if (!m_is_init) { return; }
TAB_Ttgt * tgttab = get(HMap<Tsrc, TAB_Ttgt*, HF>::get_first());
UINT n = HMap<Tsrc, TAB_Ttgt*, HF>::get_elem_count();
for (UINT i = 0; i < n; i++) {
ASSERT0(tgttab);
delete tgttab;
tgttab = HMap<Tsrc, TAB_Ttgt*, HF>::
get(HMap<Tsrc, TAB_Ttgt*, HF>::get_next());
}
HMap<Tsrc, TAB_Ttgt*, HF>::destroy();
m_is_init = false;
}
};
} //namespace xcom
#endif
| [
"steven.known@gmail.com"
] | steven.known@gmail.com |
cac6dd88f6b881a02e542a075a874d678293135c | 650f32ec6c8a83646a043133fd95f0f3d6269aa3 | /book/CH08/S12_Creating_a_pipeline_layout.cpp | 0b94fd4cd1b1a1110bea4d4bdb762219c3562443 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | THISISAGOODNAME/vkCookBook | 0478b3eb80dec179f38dc2812416f3c3f4cb22f8 | d022b4151a02c33e5c58534dc53ca39610eee7b5 | refs/heads/master | 2021-01-25T11:49:37.695292 | 2017-07-23T14:28:52 | 2017-07-23T14:28:52 | 93,948,327 | 9 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 1,805 | cpp | //
// Created by aicdg on 2017/6/22.
//
//
// Chapter: 08 Graphics and Compute Pipelines
// Recipe: 12 Creating a pipeline layout
#include "S12_Creating_a_pipeline_layout.h"
namespace VKCookbook {
bool CreatePipelineLayout( VkDevice logical_device,
std::vector<VkDescriptorSetLayout> const & descriptor_set_layouts,
std::vector<VkPushConstantRange> const & push_constant_ranges,
VkPipelineLayout & pipeline_layout ){
VkPipelineLayoutCreateInfo pipeline_layout_create_info = {
VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType
nullptr, // const void * pNext
0, // VkPipelineLayoutCreateFlags flags
static_cast<uint32_t>(descriptor_set_layouts.size()), // uint32_t setLayoutCount
descriptor_set_layouts.data(), // const VkDescriptorSetLayout * pSetLayouts
static_cast<uint32_t>(push_constant_ranges.size()), // uint32_t pushConstantRangeCount
push_constant_ranges.data() // const VkPushConstantRange * pPushConstantRanges
};
VkResult result = vkCreatePipelineLayout( logical_device, &pipeline_layout_create_info, nullptr, &pipeline_layout );
if( VK_SUCCESS != result ) {
std::cout << "Could not create pipeline layout." << std::endl;
return false;
}
return true;
}
} | [
"yangyj19931231@gmail.com"
] | yangyj19931231@gmail.com |
aecdd06ea0d82ac6c6c79d54bdd16f0d2cccd919 | 284d841aa85d0b1731ca28f50bbf838868b5c0f7 | /source/ncm/ncm.cpp | 11baa542d185f723c5ed718df43f6c3723201ff9 | [
"MIT"
] | permissive | blawar/nn | 9e6b91d31ede1faea98f78098bbae1025913ee24 | cfd66e0071ddd2756efe9171d2b7a876cc51fde7 | refs/heads/master | 2020-06-03T03:49:21.520485 | 2019-06-12T21:45:26 | 2019-06-12T21:45:26 | 191,426,129 | 3 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 498 | cpp | #include "nn.h"
namespace nn::ncm
{
Service service()
{
Service s;
return s;
}
Result OpenContentStorage(ContentStorage* contentStorage, const StorageId storageId)
{
return Request<4, ResponseS<ContentStorage>>().send(service()).result(contentStorage);
}
Result OpenContentMetaDatabase(ContentMetaDatabase* contentMetaDatabase, const StorageId storageId)
{
return Request<5, ResponseS<ContentMetaDatabase>>().send(service()).result(contentMetaDatabase);
}
}
| [
"blake@null3d.com"
] | blake@null3d.com |
1e08f1cf9603a7ed30b5a59f6485341ef26f815d | c1af58fee7b7bd833c74cc9affd4e2d30e6b1476 | /POP_2018_12_12_projekt_1_Żukowska_Eliza_EIT_2_175469.cpp | 478341ddbf5559ded771ec108e3f055601f3931e | [] | no_license | ElizaZukowska/Sokoban | 3babb5a207bfc6fa0a40d4d7428bb00aed615a1a | 860777555ae69016b36843d66cc6dfa2ee7a2afd | refs/heads/main | 2023-06-10T23:34:12.495377 | 2021-07-06T20:15:39 | 2021-07-06T20:15:39 | 383,586,113 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 17,577 | cpp | #include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
const int n = 20;
const int m = 50;
void rysujMape(char tab[n][m])
{
cout<<setw(25)<<"SOKOBAN"<<endl;
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < m ; j++)
{
cout<<tab[i][j];
}
cout<<endl;
}
}
char pion = 0xBA;
char poziom = 0xCD;
char gl = 0xC9;
char gp = 0xBB;
char dl = 0xC8;
char dp = 0xBC;
char tlo = ' ';
char R = 'R';
char P = 'x';
char M = 'O';
char Koniec = 'X';
int x;
struct obiekt
{
int pozy;
int pozx;
char znakObiektu;
};
obiekt gracz;
obiekt paczka;
obiekt meta;
bool czyObiektWjechalWSciane(char sciana)
{
return sciana==pion||sciana==poziom||sciana==gl||sciana==gp||sciana==dl||sciana==dp;
}
bool czyObiekt1NadObiektem2(obiekt obiekt1,obiekt obiekt2,char mapa[n][m])
{
return obiekt1.znakObiektu==mapa[obiekt2.pozy-1][obiekt2.pozx];
}
bool czyObiekt1PodObiektem2(obiekt obiekt1, obiekt obiekt2,char mapa[n][m])
{
return obiekt1.znakObiektu==mapa[obiekt2.pozy+1][obiekt2.pozx];
}
bool czyObiekt1PoLewejObiektu2(obiekt obiekt1, obiekt obiekt2,char mapa[n][m])
{
return obiekt1.znakObiektu==mapa[obiekt2.pozy][obiekt2.pozx-1];
}
bool czyObiekt1PoPrawejObiektu2(obiekt obiekt1, obiekt obiekt2,char mapa[n][m])
{
return obiekt1.znakObiektu==mapa[obiekt2.pozy][obiekt2.pozx+1];
}
void rysujObiekt1ZamiastObiektu2(obiekt obiekt1, obiekt obiekt2, char mapa[n][m])
{
mapa[obiekt2.pozy][obiekt2.pozx]=obiekt1.znakObiektu;
}
void rysujKoniec(obiekt paczka,char mapa[n][m])
{
mapa[paczka.pozy][paczka.pozx]=Koniec;
}
void przesunGracza(char mapa[n][m], int przesunieciey, int przesunieciex)
{
mapa[gracz.pozy][gracz.pozx]=tlo;
gracz.pozy+=przesunieciey;
gracz.pozx+=przesunieciex;
mapa[gracz.pozy][gracz.pozx]=R;
}
void przesunPaczke(char mapa[n][m], int przesunieciey, int przesunieciex)
{
mapa[paczka.pozy][paczka.pozx]=R;
paczka.pozy+=przesunieciey;
paczka.pozx+=przesunieciex;
mapa[paczka.pozy][paczka.pozx]=P;
}
void ruch(char mapa[n][m])
{
char przyciskKtoryWcisnalGracz;
while(true)
{
cin>>przyciskKtoryWcisnalGracz;
if(przyciskKtoryWcisnalGracz == 'w')
{
if(czyObiektWjechalWSciane(mapa[gracz.pozy-1][gracz.pozx]))
{
continue;
}
else if(czyObiektWjechalWSciane(mapa[paczka.pozy-1][paczka.pozx]))
{
if(czyObiekt1NadObiektem2(paczka,gracz,mapa))
{
continue;
}
else
{
przesunGracza(mapa,-1,0);
}
break;
}
else if(czyObiekt1NadObiektem2(paczka,gracz,mapa))
{
if(czyObiekt1NadObiektem2(meta,paczka,mapa))
{
przesunPaczke(mapa,-1,0);
rysujKoniec(paczka,mapa);
przesunGracza(mapa,-1,0);
}
else
{
przesunPaczke(mapa,-1,0);
przesunGracza(mapa,-1,0);
}
break;
}
else if(czyObiekt1NadObiektem2(meta,gracz,mapa))
{
continue;
}
else
{
przesunGracza(mapa,-1,0);
break;
}
}
else if(przyciskKtoryWcisnalGracz == 's')
{
if(czyObiektWjechalWSciane(mapa[gracz.pozy+1][gracz.pozx]))
{
continue;
}
else if(czyObiektWjechalWSciane(mapa[paczka.pozy+1][paczka.pozx]))
{
if(czyObiekt1PodObiektem2(paczka,gracz,mapa))
{
continue;
}
else
{
przesunGracza(mapa,1,0);
}
break;
}
else if(czyObiekt1PodObiektem2(paczka,gracz,mapa))
{
if(czyObiekt1PodObiektem2(meta,paczka,mapa))
{
przesunPaczke(mapa,1,0);
rysujKoniec(paczka,mapa);
przesunGracza(mapa,1,0);
}
else
{
przesunPaczke(mapa,1,0);
przesunGracza(mapa,1,0);
}
break;
}
else if(czyObiekt1PodObiektem2(meta,gracz,mapa))
{
continue;
}
else
{
przesunGracza(mapa,1,0);
break;
}
}
else if(przyciskKtoryWcisnalGracz == 'a')
{
if(czyObiektWjechalWSciane(mapa[gracz.pozy][gracz.pozx-1]))
{
continue;
}
else if(czyObiektWjechalWSciane(mapa[paczka.pozy][paczka.pozx-1]))
{
if(czyObiekt1PoLewejObiektu2(paczka,gracz,mapa))
{
continue;
}
else
{
przesunGracza(mapa,0,-1);
}
break;
}
else if(czyObiekt1PoLewejObiektu2(paczka,gracz,mapa))
{
if(czyObiekt1PoLewejObiektu2(meta,paczka,mapa))
{
przesunPaczke(mapa,0,-1);
rysujKoniec(paczka,mapa);
przesunGracza(mapa,0,-1);
}
else
{
przesunPaczke(mapa,0,-1);
przesunGracza(mapa,0,-1);
}
break;
}
else if(czyObiekt1PoLewejObiektu2(meta,gracz,mapa))
{
continue;
}
else
{
przesunGracza(mapa,0,-1);
break;
}
}
else if(przyciskKtoryWcisnalGracz == 'd')
{
if(czyObiektWjechalWSciane(mapa[gracz.pozy][gracz.pozx+1]))
{
continue;
}
else if(czyObiektWjechalWSciane(mapa[paczka.pozy][paczka.pozx+1]))
{
if(czyObiekt1PoPrawejObiektu2(paczka,gracz,mapa))
{
continue;
}
else
{
przesunGracza(mapa,0,1);
}
break;
}
else if(czyObiekt1PoPrawejObiektu2(paczka,gracz,mapa))
{
if(czyObiekt1PoPrawejObiektu2(meta,paczka,mapa))
{
przesunPaczke(mapa,0,1);
rysujKoniec(paczka,mapa);
przesunGracza(mapa,0,1);
}
else
{
przesunPaczke(mapa,0,1);
przesunGracza(mapa,0,1);
}
break;
}
else if(czyObiekt1PoPrawejObiektu2(meta,gracz,mapa))
{
continue;
}
else
{
przesunGracza(mapa,0,1);
break;
}
}
else if(przyciskKtoryWcisnalGracz == 'q')
{
exit(0);
}
else if(przyciskKtoryWcisnalGracz == '?')
{
cout<<"Sokoban polega na poruszaniu sie robotnikiem po magazynie. Robotnik moze pchac paczki (x). Wygrywasz gre, gdy wszystkie paczki beda na mecie (O)."<<endl;
}
else
{
cout<<"Nieprawidlowy znak"<<endl;
}
}
}
bool czyGraSkonczona(char mapa[n][m])
{
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < m ; j++)
{
if(mapa[i][j]==Koniec)
{
return true;
}
}
}
return false;
}
void graj(char mapa[n][m])
{
while(!czyGraSkonczona(mapa))
{
system( "cls" );
rysujMape(mapa);
ruch(mapa);
}
system( "cls" );
rysujMape(mapa);
cout<<"Gratulacje!"<<endl;
}
int main()
{
gracz.znakObiektu=R;
paczka.znakObiektu=P;
meta.znakObiektu=M;
char t[n][m]= {{gl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,gp},
{pion,R,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,M,tlo,tlo,tlo,tlo,P,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{dl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,dp}
};
char t1[n][m]= {{tlo,tlo,tlo,tlo,tlo,gl,poziom,poziom,poziom,poziom,gp},
{tlo,tlo,tlo,tlo,tlo,pion,R,tlo,tlo,tlo,pion},
{gl,poziom,poziom,poziom,poziom,dp,tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,gp},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,P,tlo,tlo,tlo,gl,poziom,poziom,poziom,poziom,gp,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{dl,poziom,poziom,poziom,gp,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,dp,tlo,tlo,tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,gp},
{tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,M,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,dp},
};
char t2[n][m]= {{tlo,tlo,tlo,tlo,tlo,gl,poziom,poziom,poziom,poziom,gp,tlo,tlo,tlo,tlo,tlo,tlo,gl,poziom,poziom,poziom,poziom,poziom,gp},
{tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,pion},
{gl,poziom,poziom,poziom,poziom,dp,tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,poziom,dp,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,gp},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,gl,poziom,poziom,poziom,poziom,gp,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,gp},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,P,tlo,tlo,tlo,tlo,tlo,pion},
{dl,poziom,poziom,poziom,gp,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,dp},
{tlo,tlo,tlo,tlo,pion,tlo,tlo,R,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,gp},
{tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,M,tlo,pion},
{tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,dp},
};
char t3[n][m]= {{tlo,tlo,tlo,tlo,tlo,tlo,tlo,gl,poziom,poziom,poziom,poziom,poziom,poziom,gp,tlo,tlo,tlo,gl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,gp},
{tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,P,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,gl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,gp},
{gl,poziom,poziom,poziom,poziom,poziom,poziom,dp,tlo,tlo,tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,dp,tlo,tlo,tlo,gl,poziom,poziom,poziom,gp,tlo,tlo,tlo,pion,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,M,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,gl,poziom,gp,tlo,tlo,tlo,gl,poziom,poziom,poziom,gp,tlo,tlo,tlo,tlo,tlo,tlo,tlo,dl,poziom,poziom,poziom,dp,tlo,tlo,tlo,pion,tlo,dl,poziom,gp,tlo,tlo,gl,poziom,poziom,poziom,dp},
{pion,tlo,tlo,tlo,pion,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,pion},
{pion,tlo,tlo,tlo,pion,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,pion},
{pion,tlo,tlo,tlo,pion,tlo,pion,tlo,R,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion,tlo,tlo,tlo,pion,tlo,tlo,pion},
{pion,tlo,tlo,tlo,pion,tlo,dl,poziom,poziom,poziom,dp,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,dp,tlo,tlo,tlo,pion,tlo,tlo,pion},
{pion,tlo,tlo,tlo,dl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,dp,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{pion,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,tlo,pion},
{dl,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,poziom,dp}
};
int numer;
cout<<setw(25)<<"SOKOBAN"<<endl;
cout<<"Sterowanie [w,s,a,d]"<<endl;
cout<<"Wyjscie z gry [q]"<<endl;
cout<<"Pomoc [?]"<<endl;
cout<<"Wybierz mape(1,2,3): ";
cin>>numer;
if(numer == 1)
{
meta.pozy=9;
meta.pozx=22;
gracz.pozy=1;
gracz.pozx=6;
paczka.pozy=5;
paczka.pozx=7;
graj(t1);
}
else if(numer == 2)
{
meta.pozy=10;
meta.pozx=40;
paczka.pozy=6;
paczka.pozx=33;
gracz.pozy=9;
gracz.pozx=7;
graj(t2);
}
else if(numer == 11)
{
meta.pozx=2;
meta.pozy=4;
paczka.pozx=7;
paczka.pozy=4;
gracz.pozy=1;
gracz.pozx=1;
graj(t);
}
else if(numer == 3)
{
meta.pozy=3;
meta.pozx=40;
paczka.pozy=2;
paczka.pozx=20;
gracz.pozy=9;
gracz.pozx=8;
graj(t3);
}
else
{
cout<<"Nie ma takiej mapy"<<endl;
}
return 0;
}
| [
"noreply@github.com"
] | ElizaZukowska.noreply@github.com |
e6ac8e2603f7912e8931b47184828b14b75bc4c6 | 48298469e7d828ab1aa54a419701c23afeeadce1 | /Common/Packets/GCPlayerShopMoney.h | 8dcdee4afadf93dada3f8e8bfeb6133f45986499 | [] | no_license | brock7/TianLong | c39fccb3fd2aa0ad42c9c4183d67a843ab2ce9c2 | 8142f9ccb118e76a5cd0a8b168bcf25e58e0be8b | refs/heads/master | 2021-01-10T14:19:19.850859 | 2016-02-20T13:58:55 | 2016-02-20T13:58:55 | 52,155,393 | 5 | 3 | null | null | null | null | GB18030 | C++ | false | false | 2,165 | h | // GCPlayerShopMoney.h
//
// 通知客户端金钱存取
//
//////////////////////////////////////////////////////
#ifndef __GCPLAYERSHOPMONEY_H__
#define __GCPLAYERSHOPMONEY_H__
#include "Type.h"
#include "Packet.h"
#include "PacketFactory.h"
namespace Packets
{
class GCPlayerShopMoney : public Packet
{
public:
enum
{
TYPE_BASE_MONEY = 0,
TYPE_PROFIT_MONEY,
};
public:
GCPlayerShopMoney( )
{
m_Type = TYPE_BASE_MONEY; //存到哪
m_Amount = 0; //数量
m_nShopSerial= 0; //商店序列号
};
virtual ~GCPlayerShopMoney( ){};
//公用继承接口
virtual BOOL Read( SocketInputStream& iStream ) ;
virtual BOOL Write( SocketOutputStream& oStream )const ;
virtual UINT Execute( Player* pPlayer ) ;
virtual PacketID_t GetPacketID()const { return PACKET_GC_PLAYERSHOPMONEY; }
virtual UINT GetPacketSize()const { return sizeof(_PLAYERSHOP_GUID) +
sizeof(BYTE) +
sizeof(BYTE) +
sizeof(UINT);}
_PLAYERSHOP_GUID GetShopID(VOID) const {return m_ShopID;}
VOID SetShopID(_PLAYERSHOP_GUID nShopID) {m_ShopID = nShopID;}
BYTE GetType(VOID) const {return m_Type;}
VOID SetType(BYTE nType) {m_Type = nType;}
UINT GetAmount(VOID) const {return m_Amount;}
VOID SetAmount(UINT nAmount) {m_Amount = nAmount;}
BYTE GetShopSerial(VOID) const {return m_nShopSerial;}
VOID SetShopSerial(BYTE nSerial) {m_nShopSerial = nSerial;}
private:
_PLAYERSHOP_GUID m_ShopID; //商店ID
BYTE m_Type; //存到哪
UINT m_Amount; //数量
BYTE m_nShopSerial; //商店序列号
};
class GCPlayerShopMoneyFactory : public PacketFactory
{
public:
Packet* CreatePacket() { return new GCPlayerShopMoney() ; }
PacketID_t GetPacketID()const { return PACKET_GC_PLAYERSHOPMONEY; };
UINT GetPacketMaxSize()const { return sizeof(_PLAYERSHOP_GUID) +
sizeof(BYTE) +
sizeof(BYTE) +
sizeof(UINT);}
};
class GCPlayerShopMoneyHandler
{
public:
static UINT Execute( GCPlayerShopMoney* pPacket, Player* pPlayer ) ;
};
}
using namespace Packets;
#endif
| [
"xiaowave@gmail.com"
] | xiaowave@gmail.com |
01f3213402afcf86032331bb99ed80140e7c8429 | 80dbff2ef81196130a254738e27568385f1eaa88 | /MFCApplicationSPC2/CalculatorDlg.h | 7ea2439dabfe7c3a1f9512e6a3acd00cf98a459e | [] | no_license | RoyKo222/Calculator001 | 8934db705de909519f2c82f8caef120e6ae5adf0 | 7575263291ab38657af671e0512e0427d2e23b3c | refs/heads/master | 2020-04-01T07:26:02.207079 | 2018-10-14T15:53:22 | 2018-10-14T15:53:22 | 152,989,824 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,141 | h | #pragma once
#include "afxwin.h"
#include <memory>
#include "CalculatorDlg.h"
class CCalculatorDlg : public CDialogEx
{
public:
CCalculatorDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_CALCULATOR_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedButton2();
afx_msg void OnBnClickedButton3();
afx_msg void OnBnClickedButton0();
afx_msg void OnBnClickedButton4();
afx_msg void OnBnClickedButton5();
afx_msg void OnBnClickedButton6();
afx_msg void OnBnClickedButton7();
afx_msg void OnBnClickedButton8();
afx_msg void OnBnClickedButton9();
afx_msg void OnBnClickedButtonPlus();
afx_msg void OnBnClickedButtonEquals();
afx_msg void OnBnClickedButtonC();
afx_msg void OnBnClickedButtonDivide();
afx_msg void OnBnClickedButtonMultiply();
afx_msg void OnBnClickedButtonMinus();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
private:
bool m_errorInput = false;
const CString m_outputResetString{"0"};
void resetOutput();
void reset();
void addDigit(char digit);
void doOperation(Calculator::ActionType operation, bool handleNumber=true);
void createHistoryText();
void addDigit(char digit);
Calculator m_calculator;
CString m_output;
CFont m_font;
CFont m_historyFont;
BOOL m_firstDigitEntered = FALSE;
CEdit m_editResult;
CButton m_button0;
CButton m_button1;
CButton m_button2;
CButton m_button3;
CButton m_button4;
CButton m_button5;
CButton m_button6;
CButton m_button7;
CButton m_button8;
CButton m_button9;
CButton m_buttonPlus;
CButton m_buttonEquals;
CButton m_buttonC;
CButton m_buttonMinus;
CButton m_buttonMultiply;
CButton m_buttonDivide;
CEdit m_editHistory;
CString m_historyText;
std::unique_ptr<CBrush> m_historyBkBrush;
COLORREF m_historyBkColor;
};
| [
"Roy@DESKTOP-B880FOR"
] | Roy@DESKTOP-B880FOR |
2b03b16b76044b48e71da74a4ef7889eeb6581bf | c093f943bfab59db2f4f64c3893db06ee1738c77 | /Guitar/Guitar.cpp | 45775f3789a2fbb90e7e862a1c7a4ccc2b80c9a3 | [] | no_license | TheodorSergeev/WaveSolver | c7ce68677b710d8187e66a44523f02f7ff8d8a39 | d2564c28fe9fbf35697479afba607ab85d8257cc | refs/heads/master | 2020-05-19T14:45:36.806107 | 2019-05-13T16:04:06 | 2019-05-13T16:04:06 | 185,067,649 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,147 | cpp | #include "Guitar.h"
double Guitar::InitCoord(double x)
{
//return 0.0;
CheckX(x);
return (x < X0) ? a * x / X0 : a / (length - X0) * (length - x);
}
double Guitar::WaveSpeed(double x)
{
CheckX(x);
//if(x > length * 0.1 && x < length * 0.4)
// return wavespeed * 2.0;
return wavespeed;
}
Guitar::Guitar()
{
length = 0.75;
freq = 440;
wavelength = 2 * length;
wavespeed = freq * wavelength;
omega = 2 * M_PI * freq;
periods = 4.0;
time_lim = 2 * M_PI / omega * periods;
t_step = length / 100.0 / wavespeed;
courant_num = 0.85;
x_step = wavespeed * t_step / courant_num; // !!!
a = 0.005;
X0 = 0.8 * length;
mesh_size = (int)(round(length / x_step));
curr_sol_arr.assign(mesh_size, 0.0);
next_sol_arr = curr_sol_arr;
prev_sol_arr = curr_sol_arr;
t_st_sq = t_step * t_step;
coef_sq = t_st_sq / (x_step * x_step);
left_bound_cond = DIRICHLET;
right_bound_cond = DIRICHLET;
Check();
//Dump();
}
double Guitar::DirL(double t)
{
return 0.0;
}
double Guitar::DirR(double t)
{
return 0.0;
}
| [
"sergeev.fi@phystech.edu"
] | sergeev.fi@phystech.edu |
1129fa85e7266bed065689b5d637d57e4da00a42 | 708539d6d01fc5de5681effd747dd171e0dab2f5 | /src/ast.cpp | dd8c3ec7fe34b639c76771c83bf9447f7b61c3f3 | [] | no_license | AlexGibson12/c-style-lang-compiler- | 706e61c0a093c6c54f460a50ca1ff18855b231f5 | 8d1297f2dbf25e37e3c66401eb3d099d7ba35553 | refs/heads/main | 2023-08-30T22:16:01.378152 | 2021-10-06T17:15:26 | 2021-10-06T17:15:26 | 412,627,658 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 11,307 | cpp | #include "../headers/ast.h"
#include "../headers/scope.h"
CompoundStatement::CompoundStatement(Statement* initcurrentstatement,CompoundStatement* initnextstatements){
currentstatement = initcurrentstatement;
nextstatements = initnextstatements;
statementtype = STATCOMPOUND;
}
AssignStatement::AssignStatement(string initidentifier,Expression* initexpression){
identifier = initidentifier;
expression = initexpression;
statementtype = STATASSIGN;
}
PrintStatement::PrintStatement(Expression* initexpression){
expression = initexpression;
statementtype = STATPRINT;
}
IfStatement::IfStatement(Expression* initcondition,CompoundStatement* initstatements){
condition = initcondition;
statements = initstatements;
statementtype = STATIF;
}
IfElseStatement::IfElseStatement(Expression* initcondition,CompoundStatement* initvalid,CompoundStatement* initinvalid){
condition = initcondition;
valid = initvalid;
invalid = initinvalid;
statementtype = STATIFELSE;
}
WhileStatement::WhileStatement(Expression* initcondition,CompoundStatement* initstatements){
condition = initcondition;
statements = initstatements;
statementtype = STATWHILE;
}
ForStatement::ForStatement(AssignStatement* initinitializer, Expression* initcondition,AssignStatement* initnext,CompoundStatement* initstatements){
initializer = initinitializer;
condition = initcondition;
next = initnext;
statements = initstatements;
statementtype = STATFOR;
}
Literal::Literal(int initvalue){
type =INT;
expressiontype = EXPRLITERAL;
value = initvalue;
}
Identifier::Identifier(string initidentifier){
identifier = initidentifier;
expressiontype = EXPRIDENTIFIER;
}
BinOp::BinOp(Operation* initoperation,Expression* initexpr1,Expression* initexpr2){
type = UNCOMPLETE;
expressiontype = EXPRBINARYOP;
operation = initoperation;
expr1 = initexpr1;
expr2 = initexpr2;
}
void TrickleSymbolTableDown(Expression* expression){
if(expression){
switch(expression->expressiontype){
case EXPRBINARYOP:{
(expression->expr1)->symboltable = expression->symboltable;
(expression->expr2)->symboltable = expression->symboltable;
TrickleSymbolTableDown(expression->expr1);
TrickleSymbolTableDown(expression->expr2);
break;
}
}
}
}
void TrickleSymbolTableDown(Statement* statement){ // Trickles symbol table down
if(statement){
switch(statement->statementtype){
case STATCOMPOUND:{
Statement* compoundstatement = statement;
(compoundstatement->currentstatement)->symboltable = compoundstatement->symboltable;
if(compoundstatement->nextstatements){
(compoundstatement->nextstatements)->symboltable = compoundstatement->symboltable;
}
TrickleSymbolTableDown(compoundstatement->currentstatement);
if(compoundstatement->nextstatements){
TrickleSymbolTableDown(compoundstatement->nextstatements);
}
break;
}
case STATASSIGN:{
Statement* assignstatement = statement;
Expression* expr = assignstatement->expression;
for(auto x: (assignstatement->symboltable).maintable){
}
(assignstatement->expression)->symboltable = assignstatement->symboltable;
TrickleSymbolTableDown(assignstatement->expression);
break;
}
case STATWHILE:{
Statement* whilestatement = statement;
(whilestatement->condition)->symboltable = whilestatement->symboltable;
(whilestatement->statements)->symboltable = whilestatement->symboltable;
TrickleSymbolTableDown(whilestatement->condition);
TrickleSymbolTableDown(whilestatement->statements);
break;
}
case STATPRINT:{
Statement* printstatement = statement;
(printstatement->expression)->symboltable = printstatement->symboltable;
TrickleSymbolTableDown(printstatement->expression);
break;
}
case STATIF:{
Statement* ifstatement = statement;
(ifstatement->condition)->symboltable = ifstatement->symboltable;
(ifstatement->statements)->symboltable = ifstatement->symboltable;
TrickleSymbolTableDown(ifstatement->condition);
TrickleSymbolTableDown(ifstatement->statements);
break;
}
case STATIFELSE:{
Statement* ifelsestatement = statement;
(ifelsestatement->condition)->symboltable = ifelsestatement->symboltable;
(ifelsestatement->valid)->symboltable = ifelsestatement->symboltable;
(ifelsestatement->invalid)->symboltable = ifelsestatement->symboltable;
TrickleSymbolTableDown(ifelsestatement->condition);
TrickleSymbolTableDown(ifelsestatement->valid);
TrickleSymbolTableDown(ifelsestatement->invalid);
break;
}
case STATFOR:{
Statement* forstatement = statement;
(forstatement->initializer)->symboltable = forstatement->symboltable;
(forstatement->condition)->symboltable = forstatement->symboltable;
(forstatement->next)->symboltable = forstatement->symboltable;
(forstatement->statements)->symboltable = forstatement->symboltable;
TrickleSymbolTableDown(forstatement->initializer);
TrickleSymbolTableDown(forstatement->condition);
TrickleSymbolTableDown(forstatement->next);
TrickleSymbolTableDown(forstatement->statements);
break;
}
}
}
}
void TrickleStartSymbolTable(Statement* statement){
if(statement){
switch(statement->statementtype){
case STATCOMPOUND:{
Statement* compoundstatement =statement;
if((compoundstatement->currentstatement)->statementtype == STATASSIGN){
if(compoundstatement->nextstatements){
(compoundstatement->nextstatements)->symboltable = (compoundstatement->symboltable);
TrickleSymbolTableDown(compoundstatement->nextstatements);
}
}else{
(compoundstatement->currentstatement)->symboltable = compoundstatement->symboltable;
if(compoundstatement->nextstatements){
(compoundstatement->nextstatements)->symboltable = compoundstatement->symboltable;
}
TrickleSymbolTableDown(compoundstatement->currentstatement);
if(compoundstatement->nextstatements){
TrickleSymbolTableDown(compoundstatement->nextstatements);
}
}
break;
}
case STATASSIGN:{
Statement* assignstatement = statement;
(assignstatement->expression)->symboltable = assignstatement->symboltable;
TrickleSymbolTableDown(assignstatement->expression);
break;
}
case STATWHILE:{
Statement* whilestatement =statement;
(whilestatement->condition)->symboltable = whilestatement->symboltable;
if(whilestatement->statements){
(whilestatement->statements)->symboltable = whilestatement->symboltable;
}
TrickleSymbolTableDown(whilestatement->condition);
if(whilestatement->statements){
CompleteSymbolTables(whilestatement->statements);
}
break;
}
case STATPRINT:{
Statement* printstatement = statement;
(printstatement->expression)->symboltable = printstatement->symboltable;
TrickleSymbolTableDown(printstatement->expression);
break;
}
case STATIF:{
Statement* ifstatement = statement;
(ifstatement->condition)->symboltable = ifstatement->symboltable;
(ifstatement->statements)->symboltable = ifstatement->symboltable;
TrickleSymbolTableDown(ifstatement->condition);
CompleteSymbolTables(ifstatement->statements);
break;
}
case STATIFELSE:{
Statement* ifelsestatement =statement;
(ifelsestatement->condition)->symboltable = ifelsestatement->symboltable;
(ifelsestatement->valid)->symboltable = ifelsestatement->symboltable;
(ifelsestatement->invalid)->symboltable = ifelsestatement->symboltable;
TrickleSymbolTableDown(ifelsestatement->condition);
CompleteSymbolTables(ifelsestatement->valid);
CompleteSymbolTables(ifelsestatement->invalid);
break;
}
case STATFOR:{
Statement* forstatement = statement;
(forstatement->condition)->symboltable = forstatement->symboltable;
(forstatement->next)->symboltable = forstatement->symboltable;
(forstatement->statements)->symboltable = forstatement->symboltable;
TrickleSymbolTableDown(forstatement->condition);
TrickleSymbolTableDown(forstatement->next);
CompleteSymbolTables(forstatement->statements);
break;
}
}
}
}
void CompleteSymbolTables(Statement* statement){
if(statement){
Statement* compoundstatement = statement;
switch(statement->statementtype){
case STATCOMPOUND:{
if((compoundstatement->currentstatement)->statementtype == STATASSIGN){
Statement* currentstatement = (compoundstatement->currentstatement);
compoundstatement->symboltable.appendsymbol(currentstatement->identifier);
TrickleStartSymbolTable(compoundstatement);
if(compoundstatement->nextstatements){
CompleteSymbolTables(compoundstatement->nextstatements);
}
}else{
CompleteSymbolTables(compoundstatement->currentstatement);
if(compoundstatement->nextstatements){
CompleteSymbolTables(compoundstatement->nextstatements);
}
}
break;
}
case STATFOR:{
Statement* forstatement = statement;
Statement* currentstatement = (compoundstatement->currentstatement);
forstatement->symboltable.appendsymbol(currentstatement->identifier);
TrickleStartSymbolTable(forstatement);
if(forstatement->statements){
CompleteSymbolTables(forstatement->statements);
}
break;
}
default:{
TrickleStartSymbolTable(statement);
break;
}
}
}
}
| [
"afg9000@gmail.com"
] | afg9000@gmail.com |
58f473811da92d69b93a777f0bc32a4d5915dd4b | cee40740786d05833f67dbf57c9a2fb76ff12168 | /Cmpe226/HW2/queue.h | 8dd7650d4306a9d1a27e421bf29971f3ae08b59c | [] | no_license | mcakici/Coding-HWs | 76251e47a2b7c2bd666b584b53f785eb6a31e094 | e4da3e3c97178842d53082fd6c97d7a0929bb50a | refs/heads/master | 2022-12-15T18:22:24.641353 | 2022-11-27T17:44:33 | 2022-11-27T17:44:33 | 259,754,141 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 966 | h | #define QUEUE_H
#include <iostream>
#include <cassert>
template <typename T>
class Queue{
private:
int maxsize;
int count;
int front,rear;
T *data;
public:
Queue(int sz=100){
maxsize = sz;
data = new T[maxsize];
front = 0;
rear = maxsize-1;
count = 0;
}
~Queue(){
delete[] data;
}
bool isEmpty(){
return count==0;
}
bool isFull(){
return count==maxsize;
}
T getFront(){
assert(!isEmpty());
return data[front];
}
T getRear(){
assert(!isEmpty());
return data[rear];
}
void push(const T &item){
if(!isFull()){
rear = (rear+1) % maxsize;
data[rear] = item;
count++;
}else{
std::cout<<"Queue is full";
}
}
T pop(){
assert(!isEmpty());
T tmp = data[front];
front = (front+1)%maxsize;
count--;
return tmp;
}
int size(){
return count;
}
int capacity(){
return maxsize;
}
void destroyQueue(){
front=count=0;
rear=maxsize-1;
}
};
| [
"glikoz@live.com"
] | glikoz@live.com |
6f45de6022e801d1622681ae8d035726a6fe0aa7 | 4aaf7fe1e7500b879f27321124be9f629bb4e6bc | /src/qt/sendcoinsentry.cpp | d2d38f0ab77a6f3856e88f04024cc8e527023512 | [
"MIT"
] | permissive | xscaverx/dextro | 5307e95b7f0726e501fb336730b33d326df6c948 | 71514bc58170e65168e72925af85c3479bec873b | refs/heads/master | 2022-03-24T12:16:44.074014 | 2019-11-15T13:36:00 | 2019-11-15T13:36:00 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 7,379 | cpp | // Copyright (c) 2011-2014 The Bitcoin developers
// Copyright (c) 2014-2015 The Dash developers
// Copyright (c) 2015-2017 The PIVX developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "sendcoinsentry.h"
#include "ui_sendcoinsentry.h"
#include "addressbookpage.h"
#include "addresstablemodel.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "walletmodel.h"
#include <QApplication>
#include <QClipboard>
SendCoinsEntry::SendCoinsEntry(QWidget* parent) : QStackedWidget(parent),
ui(new Ui::SendCoinsEntry),
model(0)
{
ui->setupUi(this);
setCurrentWidget(ui->SendCoins);
#ifdef Q_OS_MAC
ui->payToLayout->setSpacing(4);
#endif
#if QT_VERSION >= 0x040700
ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
#endif
// normal dxo address field
GUIUtil::setupAddressWidget(ui->payTo, this);
// just a label for displaying dxo address(es)
ui->payTo_is->setFont(GUIUtil::bitcoinAddressFont());
// Connect signals
connect(ui->payAmount, SIGNAL(valueChanged()), this, SIGNAL(payAmountChanged()));
connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));
}
SendCoinsEntry::~SendCoinsEntry()
{
delete ui;
}
void SendCoinsEntry::on_pasteButton_clicked()
{
// Paste text from clipboard into recipient field
ui->payTo->setText(QApplication::clipboard()->text());
}
void SendCoinsEntry::on_addressBookButton_clicked()
{
if (!model)
return;
AddressBookPage dlg(AddressBookPage::ForSelection, AddressBookPage::SendingTab, this);
dlg.setModel(model->getAddressTableModel());
if (dlg.exec()) {
ui->payTo->setText(dlg.getReturnValue());
ui->payAmount->setFocus();
}
}
void SendCoinsEntry::on_payTo_textChanged(const QString& address)
{
updateLabel(address);
}
void SendCoinsEntry::setModel(WalletModel* model)
{
this->model = model;
if (model && model->getOptionsModel())
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
clear();
}
void SendCoinsEntry::clear()
{
// clear UI elements for normal payment
ui->payTo->clear();
ui->addAsLabel->clear();
ui->payAmount->clear();
ui->messageTextLabel->clear();
ui->messageTextLabel->hide();
ui->messageLabel->hide();
// clear UI elements for insecure payment request
ui->payTo_is->clear();
ui->memoTextLabel_is->clear();
ui->payAmount_is->clear();
// clear UI elements for secure payment request
ui->payTo_s->clear();
ui->memoTextLabel_s->clear();
ui->payAmount_s->clear();
// update the display unit, to not use the default ("DXO")
updateDisplayUnit();
}
void SendCoinsEntry::deleteClicked()
{
emit removeEntry(this);
}
bool SendCoinsEntry::validate()
{
if (!model)
return false;
// Check input validity
bool retval = true;
// Skip checks for payment request
if (recipient.paymentRequest.IsInitialized())
return retval;
if (!model->validateAddress(ui->payTo->text())) {
ui->payTo->setValid(false);
retval = false;
}
if (!ui->payAmount->validate()) {
retval = false;
}
// Sending a zero amount is invalid
if (ui->payAmount->value(0) <= 0) {
ui->payAmount->setValid(false);
retval = false;
}
// Reject dust outputs:
if (retval && GUIUtil::isDust(ui->payTo->text(), ui->payAmount->value())) {
ui->payAmount->setValid(false);
retval = false;
}
return retval;
}
SendCoinsRecipient SendCoinsEntry::getValue()
{
// Payment request
if (recipient.paymentRequest.IsInitialized())
return recipient;
// Normal payment
recipient.address = ui->payTo->text();
recipient.label = ui->addAsLabel->text();
recipient.amount = ui->payAmount->value();
recipient.message = ui->messageTextLabel->text();
return recipient;
}
QWidget* SendCoinsEntry::setupTabChain(QWidget* prev)
{
QWidget::setTabOrder(prev, ui->payTo);
QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
QWidget* w = ui->payAmount->setupTabChain(ui->addAsLabel);
QWidget::setTabOrder(w, ui->addressBookButton);
QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
return ui->deleteButton;
}
void SendCoinsEntry::setValue(const SendCoinsRecipient& value)
{
recipient = value;
if (recipient.paymentRequest.IsInitialized()) // payment request
{
if (recipient.authenticatedMerchant.isEmpty()) // insecure
{
ui->payTo_is->setText(recipient.address);
ui->memoTextLabel_is->setText(recipient.message);
ui->payAmount_is->setValue(recipient.amount);
ui->payAmount_is->setReadOnly(true);
setCurrentWidget(ui->SendCoins_InsecurePaymentRequest);
} else // secure
{
ui->payTo_s->setText(recipient.authenticatedMerchant);
ui->memoTextLabel_s->setText(recipient.message);
ui->payAmount_s->setValue(recipient.amount);
ui->payAmount_s->setReadOnly(true);
setCurrentWidget(ui->SendCoins_SecurePaymentRequest);
}
} else // normal payment
{
// message
ui->messageTextLabel->setText(recipient.message);
ui->messageTextLabel->setVisible(!recipient.message.isEmpty());
ui->messageLabel->setVisible(!recipient.message.isEmpty());
ui->addAsLabel->clear();
ui->payTo->setText(recipient.address); // this may set a label from addressbook
if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, dont overwrite with an empty label
ui->addAsLabel->setText(recipient.label);
ui->payAmount->setValue(recipient.amount);
}
}
void SendCoinsEntry::setAddress(const QString& address)
{
ui->payTo->setText(address);
ui->payAmount->setFocus();
}
bool SendCoinsEntry::isClear()
{
return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
}
void SendCoinsEntry::setFocus()
{
ui->payTo->setFocus();
}
void SendCoinsEntry::updateDisplayUnit()
{
if (model && model->getOptionsModel()) {
// Update payAmount with the current unit
ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
}
}
bool SendCoinsEntry::updateLabel(const QString& address)
{
if (!model)
return false;
// Fill in label from address book, if address has an associated label
QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
if (!associatedLabel.isEmpty()) {
ui->addAsLabel->setText(associatedLabel);
return true;
}
return false;
}
| [
"xclubber2@gmail.com"
] | xclubber2@gmail.com |
0ce2630c694774c24d532bf513017420c8472306 | 2ea73cf4cac9eabf982d637035e1838644e38d3f | /(里面有好多页面测试的包括手机调用的页面)htdocs/htdocs/data/tplcache/61e2be2f17130918ff2045e187805efd.inc | 15a7edd588f86212f3b331f20171a7ec2dce2651 | [] | no_license | patool/100etechDEDE | 273772d5a27cee4fef2469e0661173bbd39adfe0 | 7a9e39b0710a7bbdd09f946e13537414ea66bf95 | refs/heads/master | 2021-01-10T22:36:06.617896 | 2016-08-16T02:34:16 | 2016-08-16T02:34:16 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 422 | inc | {dede:list pagesize='500' col='1' titlelen='60' orderby='pubdate' orderway='desc'
}<url>
<loc>[field:arcurl function="Gmapurl(@me)"/]</loc>
<title>[field:title function="HtmlReplace(@me)"/]</title>
<news:news>
<news:keywords>[field:keywords/]</news:keywords>
<news:publication_date>[field:senddate function="strftime("%Y-%m-%d",@me)"/]</news:publication_date>
</news:news>
</url>{/dede:list} | [
"wulu@100etech.com"
] | wulu@100etech.com |
d30b52f7009e10b49db6e885a72b5d3bfc1bea6c | edd733efe798cf751ded322c0af8c5891d1e229d | /Tek2/B4-semestre/Maths/201yams/bonus/sources/reglepart/fenetreprincipal.cpp | 0689872a148bd7d6dc11f7a31f26eb5d53b78c2b | [] | no_license | Barathan-Somasundram/Epitech | 6e60666205a919397fef41469fe7726861086346 | 96eabeb7a23518433a483bf374189257720a7e38 | refs/heads/master | 2016-09-06T12:51:32.934375 | 2015-05-18T16:00:41 | 2015-05-18T16:00:41 | 32,335,665 | 1 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 1,361 | cpp | #include <QWidget>
#include <QGridLayout>
#include <cstdlib>
#include "fenetreprincipale.hpp"
FenetrePrincipale::FenetrePrincipale(QWidget *parent): QMainWindow(parent)
{
QWidget* content = new QWidget();
QGridLayout* layout = new QGridLayout();
QPixmap pic("./img/regle.jpg");
QPixmap scaled = pic.scaled(1900, 1000, Qt::IgnoreAspectRatio, Qt::FastTransformation);
QLabel *label = new QLabel();
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint);
setWindowTitle("Yams");
setWindowIcon(QIcon("Des/5.png"));
setPalette(QPalette(Qt::lightGray));
sonMenuPrincipal =new MenuPrincipal(this);
label->setPixmap(scaled);
// layout->addWidget(sonMenuPrincipal, 0, 1);
layout->addWidget(label, 0, 0);
// saPageAPropos =new PageAPropos(this);
content->setLayout(layout);
setCentralWidget(content);
setFixedSize(sizeHint());
}
FenetrePrincipale::~FenetrePrincipale()
{
}
void FenetrePrincipale::game(void)
{
system("./sources//playpart/yams");
}
void FenetrePrincipale::regle(void)
{
system("./sources/reglepart/yams");
}
void FenetrePrincipale::changerMenuPrincipal()
{
// setCentralWidget(this);
// setFixedSize(sizeHint());
}
void FenetrePrincipale::changerPageAPropos()
{
// setCentralWidget(saPageAPropos);
// setFixedSize(sizeHint());
}
| [
"barathan.somasundram@epitech.eu"
] | barathan.somasundram@epitech.eu |
8600e296a302aad25f8c01b6f8dd1fb30ed1054e | 3c4f86f7d74b388cb9197fba66728e9023b40e29 | /UNIVERSIDAD/programacion/matrices/uni1.cpp | 3a0028eddb2691c2b73451a78379c6a893a46d3a | [] | no_license | andoporto/Programacion2014 | a05058b8ec7e06e7f75c412f345dca234c67746b | 2a1d860813c85b1c618a61c29833af2662636693 | refs/heads/master | 2021-01-23T21:39:08.697914 | 2015-02-16T23:17:48 | 2015-02-16T23:17:48 | 30,872,534 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 836 | cpp | #include <stdio.h>
#include<conio.h>
#define FIL 5
#define COL 4
void main()
{
clrscr();
int i,j,notas[FIL][COL];
float prom1,prom2,suma;
printf("Promedios por estudiante; \n");
for (i=0; i<FIL;i++)
{
printf("\n Ingrese las %d notas del estudiante: %d \n\n",COL, i+1);
suma=0;
for (j=0;j<COL;j++)
{
printf("Materia: %d ", j+1);
scanf("%d",¬as[i][j]);
suma=suma+notas[i][j];
}
prom1=suma/COL;
printf("\n La nota promedio del estudiante %d es: %.2f",i+1,prom1);
}
/*recorremos ahora la matriz por columna para responder al segundo punto*/
printf(" \n Promedios por columna \n");
for (j=0;j<COL;j++)
{
suma=0;
for (i=0;i<COL;i++)
suma=suma+notas[i][j];
prom2=suma/FIL;
printf("\n La nota promedio de la asignatura %d es: %.2f ",j+1,prom2);
}
}
| [
"andoporto@gmail.com"
] | andoporto@gmail.com |
b0cfd5e042fb6f96f795079a7b7fb48207f86894 | 175aa9134b6c0e7bf075a85e3901e46121d47a1c | /soapy/src/bindjs/CToJavascript.hpp | d6b179d6cf91e5d94ad632cd701b3571cd231347 | [
"BSD-3-Clause"
] | permissive | siglabsoss/s-modem | 63d3b2e65f83388e7cd636a360b14fdc592bd698 | 0a259b4f3207dd043c198b76a4bc18c8529bcf44 | refs/heads/master | 2023-06-16T08:58:07.127993 | 2021-07-04T12:42:45 | 2021-07-04T12:42:45 | 382,846,435 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,529 | hpp | #include <napi.h>
#include <iostream>
#include <chrono>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <vector>
using namespace Napi;
// #define CTJS_PRINT
template <typename T>
class CToJavascript : public Napi::AsyncWorker {
private:
std::mutex& mut;
std::vector<T>& work;
std::condition_variable& outputReadyCondition;
std::atomic<bool> requestShutdown;
std::function<void()> afterCompleteCallback;
public:
CToJavascript(Function& callback, std::mutex& m, std::vector<T>& w, std::condition_variable& c, std::function<void()> complete)
: AsyncWorker(callback), mut(m), work(w), outputReadyCondition(c), requestShutdown(false), afterCompleteCallback(complete){}
#ifdef CTJS_PRINT
~CToJavascript() {
std::cout << "~CToJavascript()" << std::endl;
}
#endif
// This code will be executed on the worker thread
void Execute() {
// std::cout << "Execute()" << std::endl;
std::unique_lock<std::mutex> lk(mut);
outputReadyCondition.wait(lk, [this]{return (work.size() > 0)||requestShutdown;});
lk.unlock();
// std::cout << "Execute() finished" << std::endl;
}
// For each templatized version of CToJavascript we use
// we need to make a dispatchType() for that type
void dispatchType(const uint32_t& word) {
napi_value val;
napi_create_uint32(Env(), word, &val);
Callback().Call({val});
}
void dispatchType(const std::vector<uint32_t>& vec) {
Napi::Env env = Env();
napi_value val;
auto status = napi_create_array_with_length(env, vec.size(), &val);
(void)status;
unsigned i = 0;
for(auto w : vec) {
status = napi_set_element(env, val, i, Napi::Number::New(env,w));
i++;
}
Callback().Call({val});
}
void OnOK() {
#ifdef CTJS_PRINT
std::cout << "OnOK()" << std::endl;
#endif
// echo = "fooooo";
HandleScope scope(Env());
std::vector<T> workCopy; // on stack
{
std::lock_guard<std::mutex> lk(mut);
// take lock, copy to the stack, and empty the shared one
workCopy = work;
work.resize(0);
}
for(const auto &theT : workCopy) {
// Call overloaded function
dispatchType(theT);
}
afterCompleteCallback();
}
// private:
// std::string echo;
}; | [
"siglabsoss@outlook.com"
] | siglabsoss@outlook.com |
f43792e9bfb8f3a00d74ac6395fd0ac4ae3019e3 | fb59dcedeb1aae73e92afebeb6cb2e51b13d5c22 | /middleware/src/app/BrowserBridge/Huawei/C10/CTC/BrowserPlayerCTC.h | 46c5f4b6158c2ee3792f9f948e1c649ca3be705e | [] | no_license | qrsforever/yxstb | a04a7c7c814b7a5647f9528603bd0c5859406631 | 78bbbae07aa7513adc66d6f18ab04cd7c3ea30d5 | refs/heads/master | 2020-06-18T20:13:38.214225 | 2019-07-11T16:40:14 | 2019-07-11T16:40:14 | 196,431,357 | 0 | 1 | null | 2020-03-08T00:54:09 | 2019-07-11T16:38:29 | C | GB18030 | C++ | false | false | 2,602 | h | #ifndef _BrowserPlayerCTC_H_
#define _BrowserPlayerCTC_H_
#include "BrowserPlayerC10.h"
#include "ProgramList.h"
#ifdef __cplusplus
namespace Hippo {
class BrowserPlayerCTC : public BrowserPlayerC10 {
public:
BrowserPlayerCTC(int id, player_type_e playerInstanceType);
~BrowserPlayerCTC();
virtual int joinChannel(int channelNumber);
virtual int leaveChannel();
virtual int play(int startTime, time_type_e timeType);
virtual int fastForward(int speed, unsigned long playTime, time_type_e timeType);
virtual int fastRewind(int speed, unsigned long playTime, time_type_e timeType);
virtual int seekTo(unsigned long playTime, time_type_e timeType);
virtual int seekTo(const char*, time_type_e);
virtual int pause();
virtual int resume();
virtual int stop();
virtual int close();
virtual int setProperty(player_property_type_e aType, HPlayerProperty& aValue);
virtual int getProperty(player_property_type_e aType, HPlayerProperty& aResult);
virtual int addSingleMedia(media_info_type_e, int, const char *);
virtual int removePlayNode(playlist_op_type_e, HPlaylistProperty& aValue);
virtual int movePlayNode(playlist_op_type_e, HPlaylistProperty& aValue);
virtual int selectPlayNode(playlist_op_type_e, HPlaylistProperty& aValue);
/*
int addBatchMedia(const char*);
int removeMediaByEntryID(const char*);
int removeMediaByIndex(int);
int selectFirst();
int selectLast();
int selectNext();
int selectPrevious();
int selectMediaByEntryId(const char*);
int selectMediaByIndex(int);
int selectMediaByOffset(int);
int moveMediaByEntryID(const char*, int);
int moveMediaByEntryIDOffset(const char*, int);
int moveMediaByIndex(int, int);
int moveMediaByIndexOffset(int, int);
int moveMediaToNextByEntryID(const char*);
int moveMediaToPreviousByEntryID(const char*);
int moveMediaToFirstByEntryID(const char*);
int moveMediaToLastByEntryID(const char*);
int moveMediaToNextByIndex(int);
int moveMediaToPreviousByIndex(int);
int moveMediaToFirstByIndex(int);
int moveMediaToLastByIndex(int);
*/
//统计和回显
int getMediaCount();
int getCurrentIndex();
const char* getCurrentEntryID();
int getPlaylist();
//播放
int playFromStart();
virtual void clearForRecycle();
virtual int refreshVideoDisplay();
private:
ProgramList *mProgramList;
player_mode_e mPlayrMode;
};
} // namespace Hippo
#endif // __cplusplus
#endif // _BrowserPlayerC10_H_
| [
"lidong8@le.com"
] | lidong8@le.com |
8601b4f7598baaa17af58e36e294da57e2ec2e08 | 5bde31d6164b5896041546e841852360c2617164 | /SM-CompetitionPlusC++/CompPlus_Extensions/ManiaExt.cpp | a0b39c9c098a6d92690035ec38d69539c1585891 | [] | no_license | CarJem/CompetitionPlusCode | 96cc9e5ee7d93ab8a89fb5f0316d3df82a26aa37 | edcd9e4a6094f37eec2fe9853edf7e907531941e | refs/heads/master | 2023-01-15T20:43:49.657277 | 2020-11-10T01:59:26 | 2020-11-10T01:59:26 | 287,567,803 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,938 | cpp | #include "stdafx.h"
#include "ManiaExt.h"
#include <string>
#include <vector>
using namespace SonicMania;
int DevFontSpriteID = 0;
bool DevFontLoaded = false;
SonicMania::EntityPlayer GetPlayer(int RealID)
{
switch (RealID)
{
case 1:
return SonicMania::Player1;
case 2:
return SonicMania::Player2;
case 3:
return SonicMania::Player3;
case 4:
return SonicMania::Player4;
default:
return SonicMania::Player1;
}
}
void WarpWithCamera(SonicMania::EntityPlayer& Player, int x, int y)
{
Player.Position.X = x;
Player.Position.Y = y;
if (Player.Camera != nullptr)
{
Player.CameraOffset = 0;
//Player.Camera->PanType = 1;
Player.Camera->Position.X = x;
Player.Camera->Position.Y = y;
//Player.Camera->BoundPanningSpeedX = INT_MAX;
//Player.Camera->BoundPanningSpeedY = INT_MAX;
//Player.Camera->PanSpeed = INT_MAX;
//Player.Camera->PanProgress = INT_MAX;
//Player.Camera->MinX = INT_MIN;
//Player.Camera->MinY = INT_MIN;
//Player.Camera->MaxX = INT_MAX;
//Player.Camera->MaxY = INT_MAX;
//Player.Camera->AdjustY = 0;
//Player.Camera->DestinationOffsetX = 0;
//Player.Camera->DestinationOffsetY = 0;
Player.Camera->LastXPos = x;
Player.Camera->LastYPos = y;
//Player.Camera->XVelocity = INT_MAX;
// Player.Camera->YVelocity = INT_MAX;
Player.Camera->PanToPositionSTart.X = x;
Player.Camera->PanToPositionSTart.Y = y;
Player.Camera->PanToPositionEnd.X = x;
Player.Camera->PanToPositionEnd.Y = y;
}
}
void StorePalette(std::string filepath, SHORT(&PaletteStorage)[256], int& PaletteStorage_Length)
{
unsigned int size = 0;
FILE* file;
fopen_s(&file, filepath.c_str(), "rb");
fseek(file, 0, SEEK_END);
size = ftell(file);
char* act = (char*)malloc(size);
fseek(file, 0, SEEK_SET);
fread(act, 1, size, file);
int actCount = size / 3;
memset(PaletteStorage, 0, sizeof(PaletteStorage));
for (int i = 0; i < actCount; ++i)
{
int red = (BYTE)act[i * 3 + 0];
int green = (BYTE)act[i * 3 + 1];
int blue = (BYTE)act[i * 3 + 2];
PaletteStorage[i] = SonicMania::ToRGB565(red, green, blue);
}
PaletteStorage_Length = actCount;
delete act;
}
bool IsPlayerActive(SonicMania::EntityPlayer Player)
{
return (Player.Camera != nullptr && Player.Grounded && Player.XVelocity == 0 && Player.YVelocity == 0);
}
BYTE* GetUIButtonPointer(int slot)
{
return *(BYTE**)((baseAddress + 0x0047B010) + (slot * 0x458));
}
void SetUIPictureFrame(int slotID, int frameID)
{
WriteData(GetEntityFromSceneSlot<BYTE>(slotID) + 0x70, (BYTE)frameID);
}
EntityUIPicture* GetEntity(int slotID)
{
return GetEntityFromSceneSlot<EntityUIPicture>(slotID);
} | [
"Cwallacecs@Gmail.com"
] | Cwallacecs@Gmail.com |
9bd315b8cc849d47daba49d6cc545f15d1d0577d | e08573437f49380c58b26cf84d90230a356f8cc0 | /include/art/detail/art_node_base.h | 0b7b9e8b5645de94e090896b7b1ec5a154de16e7 | [
"BSL-1.0"
] | permissive | justinasvd/art_map | 823d74707483de2fbb7f573b9c83eab5ddb85549 | 499779762bc33385002db8853fe6ad1641f62af4 | refs/heads/master | 2023-06-28T22:24:41.178976 | 2021-07-14T11:19:19 | 2021-07-14T11:19:38 | 357,594,763 | 11 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,156 | h | #ifndef ART_DETAIL_ART_NODE_BASE_HEADER_INCLUDED
#define ART_DETAIL_ART_NODE_BASE_HEADER_INCLUDED
#include "dump_byte.h"
#include <cassert>
#include <cstdint>
namespace art
{
namespace detail
{
// Common base for various node types and leaves. This common base ensures that
// common functionality could be achieved though the base pointer.
template <typename BitwiseKey> struct art_node_base {
using bitwise_key = BitwiseKey;
using key_size_type = typename BitwiseKey::size_type;
explicit constexpr art_node_base(bitwise_key key) noexcept
: header(key)
{
}
[[nodiscard]] constexpr bitwise_key prefix() const noexcept { return header; }
[[nodiscard]] constexpr std::uint8_t front() const noexcept { return header.front(); }
// This is meaningful for internal nodes only
[[nodiscard]] constexpr key_size_type prefix_length() const noexcept { return header.size(); }
[[nodiscard]] constexpr key_size_type shared_prefix_length(bitwise_key key) const noexcept
{
return bitwise_key::shared_len(key, header, header.size());
}
[[nodiscard]] bitwise_key shared_prefix(bitwise_key key) const noexcept
{
return bitwise_key::partial_key(key, shared_prefix_length(key));
}
// Prefix manipulation routines
constexpr void shift_right(key_size_type size) noexcept { header.shift_right_resize(size); }
constexpr void shift_left(std::uint8_t key) noexcept { header.shift_left_resize(key); }
constexpr void shift_left(bitwise_key key) noexcept { header.shift_left_resize(key); }
// Dump bitwise key prefix
static void dump(std::ostream& os, bitwise_key key, key_size_type len)
{
for (key_size_type i = 0; i != len; ++i)
dump_byte(os, key[i]);
}
static void dump(std::ostream& os, bitwise_key key)
{
os << "key prefix len = " << static_cast<std::size_t>(key.size());
if (key.size()) {
os << ", key prefix =";
dump(os, key, key.size());
}
}
private:
BitwiseKey header;
};
} // namespace detail
} // namespace art
#endif // ART_DETAIL_ART_NODE_BASE_HEADER_INCLUDED
| [
"justinas@videntifier.com"
] | justinas@videntifier.com |
d83bcea7d4e85dc3ca5341138c9a326e8a72313d | dba99c936163ced1fdff7fb37a5f20a181636315 | /GShr/LibMfc.cpp | 77ba0bd59ad161c27782b9212144b82eae68db95 | [
"MIT"
] | permissive | BrentEaston/cbwindows | 4aab69b63bc0153f23b7e2d141cefbaf29a5ff71 | 51b44d2e71aec0c9fe41795bc8c99cc905668517 | refs/heads/master | 2023-02-04T18:26:25.657907 | 2020-11-22T19:32:27 | 2020-11-22T21:35:56 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 17,840 | cpp | // LibMfc.cpp - Miscellaneous MFC Support Functions
//
// Copyright (c) 1994-2020 By Dale L. Larson, All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#include "stdafx.h"
#include <WTYPES.H>
#include "LibMfc.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
/////////////////////////////////////////////////////////////////////////////
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
LPDWORD pdwPidOrHandle = (LPDWORD)lParam;
DWORD dwPid;
GetWindowThreadProcessId(hwnd, &dwPid);
if (dwPid == *pdwPidOrHandle)
{
*pdwPidOrHandle = (DWORD)hwnd;
return FALSE;
}
return TRUE;
}
HWND FindWindowForProcessID(DWORD dwProcessID)
{
DWORD dwProcIDorHandle = dwProcessID;
if (EnumWindows(EnumWindowsProc, (LPARAM)&dwProcIDorHandle) != 0)
return NULL; // Didn't find one
return (HWND)dwProcIDorHandle;
}
// Returns TRUE if succeeded
BOOL FindWindowForProcessIDAndBringToFront(DWORD dwProcessID)
{
HWND hWnd = FindWindowForProcessID(dwProcessID);
if (hWnd == NULL)
return FALSE;
BringWindowToTop(hWnd);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
BOOL AppendStringToEditBox(CEdit& edit, CString strAppend,
BOOL bEnsureNewline /* = FALSE */)
{
if (bEnsureNewline)
{
CString str;
edit.GetWindowText(str);
if (str != "" && str.GetAt(str.GetLength() - 1) != '\n')
AppendStringToEditBox(edit, "\r\n", FALSE);
}
int nLen = edit.GetWindowTextLength();
edit.SetSel(nLen, nLen);
edit.ReplaceSel(strAppend);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
BOOL GetMaximumTextExtent(HDC hDC, LPCTSTR pszStr, int nStringLen, int nMaxWidth,
int* pnFit)
{
int nStrLen = nStringLen == -1 ? lstrlen(pszStr) : nStringLen;
SIZE size;
// Determine the largest string that can fit in the cell...
if (GetTextExtentExPoint(hDC, pszStr, nStrLen, nMaxWidth,
pnFit, NULL, &size))
return TRUE;
// If it failed (probably due to running on Win32s) do it the hard way!
//
// First try entire string extent to save time.
if (!GetTextExtentPoint(hDC, pszStr, nStrLen, &size))
return FALSE;
if (size.cx <= nMaxWidth)
{
*pnFit = nStrLen;
return TRUE;
}
// Use brute force approach. Perhaps this can be made more clever when
// the product ship data isn't looming.
int nChar;
for (nChar = 0; nChar < nStrLen; nChar++)
{
if (!GetTextExtentPoint(hDC, pszStr, nChar + 1, &size))
return FALSE;
if (size.cx > nMaxWidth)
break;
}
ASSERT(nChar < nStrLen); // Should always bail out before end string!
*pnFit = nChar;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
CDisableMainWindow::CDisableMainWindow(BOOL bDisable /* = TRUE */)
{
DisableMainWindow(bDisable);
}
CDisableMainWindow::~CDisableMainWindow()
{
DisableMainWindow(FALSE);
}
void CDisableMainWindow::DisableMainWindow(BOOL bDisable /* = TRUE */)
{
ASSERT(AfxGetApp() != NULL);
ASSERT(AfxGetApp()->m_pMainWnd != NULL);
AfxGetApp()->m_pMainWnd->EnableWindow(!bDisable);
}
///////////////////////////////////////////////////////////////////////
// This routine will simply create a unique temporary filename.
void GetTemporaryFileName(LPCTSTR lpPrefixString, CString& strTempName)
{
TCHAR szTempName[_MAX_PATH];
TCHAR szPath[_MAX_PATH];
// Save to temporary path
VERIFY(GetTempPath(sizeof(szPath)/sizeof(TCHAR), szPath) != 0);
VERIFY(GetTempFileName(szPath, lpPrefixString, 0, szTempName) != 0);
strTempName = szTempName;
}
///////////////////////////////////////////////////////////////////////
// TruncatedAnsiStringWithEllipses() - This function shortens a string
// to fit within a target width. The shortened string has "..." at the
// end of it.
void TruncatedAnsiStringWithEllipses(CDC* pRefDC, int nTargWidth, CString& str)
{
CString strWrk = "..." + str; // Ellipse is prefix for size calc
int nFitWidth;
VERIFY(GetMaximumTextExtent(pRefDC->m_hAttribDC, strWrk, strWrk.GetLength(),
nTargWidth, &nFitWidth));
ASSERT(nFitWidth > 0);
str = str.Left(nFitWidth - 3) + "...";
}
///////////////////////////////////////////////////////////////////////
// This routine will scan the supplied menu for an entry hooked to
// a submenu. It then checks to see if the ID of the first item in
// submenu matches the specified ID. If it does, the submenu's index is
// returned. Otherwise -1 is returned.
UINT LocateSubMenuIndexOfMenuHavingStartingID(CMenu* pMenu, UINT nID)
{
for (UINT nIndex = 0;
pMenu->GetMenuState(nIndex, MF_BYPOSITION) != -1;
nIndex++)
{
CMenu* pSubMenu = pMenu->GetSubMenu(nIndex);
// Support two levels of checking.
if (pSubMenu != NULL)
{
if (pSubMenu->GetMenuItemID(0) == nID)
return nIndex;
// Try the next level...
pSubMenu = pSubMenu->GetSubMenu(0);
if (pSubMenu != NULL && pSubMenu->GetMenuItemID(0) == nID)
return nIndex;
}
// if (pSubMenu != NULL && pSubMenu->GetMenuItemID(0) == nID)
// return nIndex;
}
return (UINT)-1;
}
///////////////////////////////////////////////////////////////////////
// This routine appends a list of strings to the supplied menu. The first
// string is assigned ID 'nBaseID'. The second ID is 'nBaseID' + 1 and so
// on. You can optionally provide a UINT array which specifies which
// indexes of the string array you wish to have added to the menu (i.e.,
// it allows you to specify a subset of the string array. Finally, since
// the menu could be quite large you can specify how many items are stacked
// vertically before a menu break is forced. The default break value
// is 20 menu items.
void CreateSequentialSubMenuIDs(CMenu& menu, UINT nBaseID, CStringArray& tblNames,
CUIntArray* pTblSelections /* = NULL */, UINT nBreaksAt /* = 20 */)
{
if (tblNames.GetSize() > 0)
{
int nMenuEntries = pTblSelections != NULL ? pTblSelections->GetSize() :
tblNames.GetSize();
for (int i = 0; i < nMenuEntries; i++)
{
int nNameIdx = pTblSelections != NULL ? pTblSelections->GetAt(i) : i;
ASSERT(nNameIdx < tblNames.GetSize());
// Break the menu every 'nBreaksAt' lines since Windows
// won't automatically break the menu if it is
// too tall.
UINT nFlags = MF_ENABLED | MF_STRING |
(i % nBreaksAt == 0 && i != 0 ? MF_MENUBARBREAK : 0);
VERIFY(menu.AppendMenu(nFlags, nBaseID + i, tblNames.GetAt(nNameIdx)));
}
}
}
///////////////////////////////////////////////////////////////////////
// This routine maps key codes to scrollbar messages. The scroll
// message is sent to the supplied window. Returns FALSE if
// no key mapping was found.
BOOL TranslateKeyToScrollBarMessage(CWnd* pWnd, UINT nChar)
{
UINT nCmd = WM_VSCROLL;
UINT nSBCode = (UINT)-1;
BOOL bControl = GetKeyState(VK_CONTROL) < 0;
switch(nChar)
{
case VK_UP: nSBCode = SB_LINEUP; break;
case VK_DOWN: nSBCode = SB_LINEDOWN; break;
case VK_LEFT: nSBCode = SB_LINELEFT; nCmd = WM_HSCROLL; break;
case VK_RIGHT: nSBCode = SB_LINERIGHT; nCmd = WM_HSCROLL; break;
case VK_PRIOR:
nSBCode = SB_PAGEUP; if (bControl) nCmd = WM_HSCROLL; break;
case VK_NEXT:
nSBCode = SB_PAGEDOWN; if (bControl) nCmd = WM_HSCROLL; break;
case VK_HOME:
nSBCode = SB_TOP; if (bControl) nCmd = WM_HSCROLL; break;
case VK_END:
nSBCode = SB_BOTTOM; if (bControl) nCmd = WM_HSCROLL; break;
default: break;
}
if (nSBCode != (UINT)-1)
{
pWnd->SendMessage(nCmd, MAKELONG(nSBCode, 0));
return TRUE;
}
return FALSE;
}
namespace {
class CPaneContainerManagerCb : public CPaneContainerManager
{
DECLARE_DYNCREATE(CPaneContainerManagerCb)
public:
virtual BOOL Create(CWnd* pParentWnd, CPaneDivider* pDefaultSlider, CRuntimeClass* pContainerRTC = NULL);
void AddHiddenPanesToList(CObList* plstControlBars, CObList* plstSliders);
};
class CPaneContainerCb : public CPaneContainer
{
DECLARE_DYNCREATE(CPaneContainerCb)
public:
virtual void Resize(CRect rect, HDWP& hdwp, BOOL bRedraw = FALSE);
};
class CPaneDividerCb : public CPaneDivider
{
DECLARE_DYNCREATE(CPaneDividerCb)
public:
virtual void OnShowPane(CDockablePane* pBar, BOOL bShow);
void GetHiddenPanes(CObList& lstBars);
};
IMPLEMENT_DYNCREATE(CPaneContainerManagerCb, CPaneContainerManager)
BOOL CPaneContainerManagerCb::Create(CWnd* pParentWnd, CPaneDivider* pDefaultSlider, CRuntimeClass* pContainerRTC /*= NULL*/)
{
ASSERT(!pContainerRTC);
return CPaneContainerManager::Create(pParentWnd, pDefaultSlider, RUNTIME_CLASS(CPaneContainerCb));
}
// based on CPaneContainerManager::AddPanesToList
void CPaneContainerManagerCb::AddHiddenPanesToList(CObList* plstControlBars, CObList* plstSliders)
{
ASSERT_VALID(this);
if (plstControlBars != NULL)
{
for (POSITION pos = m_lstControlBars.GetHeadPosition(); pos != NULL;)
{
CWnd* pWnd = DYNAMIC_DOWNCAST(CWnd, m_lstControlBars.GetNext(pos));
ASSERT_VALID(pWnd);
if (!(pWnd->GetStyle() & WS_VISIBLE))
{
plstControlBars->AddTail(pWnd);
}
}
}
if (plstSliders != NULL)
{
for (POSITION pos = m_lstSliders.GetHeadPosition(); pos != NULL;)
{
CWnd* pWnd = DYNAMIC_DOWNCAST(CWnd, m_lstSliders.GetNext(pos));
ASSERT_VALID(pWnd);
if (!(pWnd->GetStyle() & WS_VISIBLE))
{
plstSliders->AddTail(pWnd);
}
}
}
}
IMPLEMENT_DYNCREATE(CPaneContainerCb, CPaneContainer)
void CPaneContainerCb::Resize(CRect rect, HDWP& hdwp, BOOL bRedraw /*= FALSE*/)
{
CPaneContainer::Resize(rect, hdwp, bRedraw);
/* if hidden panes larger than rect, shrink them to fit rect
(fix issue #16) */
CPaneContainerManagerCb* mgr = DYNAMIC_DOWNCAST(CPaneContainerManagerCb, m_pContainerManager);
ASSERT(mgr);
CWnd* frame = mgr->GetDockSiteFrameWnd();
// rect is client coords, but client of what?
CRect screenRect = rect;
// best guess: client of docksite
frame->ClientToScreen(screenRect);
CObList panes;
mgr->AddHiddenPanesToList(&panes, NULL);
for (POSITION pos = panes.GetHeadPosition() ; pos ; )
{
CDockablePane* pane = DYNAMIC_DOWNCAST(CDockablePane, panes.GetNext(pos));
ASSERT(pane && !pane->IsVisible());
CRect paneRect;
pane->GetWindowRect(paneRect);
CRect newRect;
newRect.SetRectEmpty();
if (paneRect.Width() > rect.Width())
{
if (newRect.IsRectEmpty())
{
newRect = paneRect;
}
newRect.left = screenRect.left;
newRect.right = screenRect.right;
}
if (paneRect.Height() > rect.Height())
{
if (newRect.IsRectEmpty())
{
newRect = paneRect;
}
newRect.top = screenRect.top;
newRect.bottom = screenRect.bottom;
}
if (!newRect.IsRectEmpty())
{
pane->GetParent()->ScreenToClient(newRect);
pane->MoveWindow(newRect, FALSE, hdwp);
}
}
}
IMPLEMENT_DYNCREATE(CPaneDividerCb, CPaneDivider)
void CPaneDividerCb::OnShowPane(CDockablePane* pBar, BOOL bShow)
{
if (bShow)
{
// ensure pBar is at least as big as its minimum size
CSize minSize;
pBar->GetMinSize(minSize);
CRect paneRect;
pBar->GetWindowRect(paneRect);
bool update = false;
if (paneRect.Width() < minSize.cx)
{
paneRect.right = paneRect.left + minSize.cx;
update = true;
}
if (paneRect.Height() < minSize.cy)
{
paneRect.bottom = paneRect.top + minSize.cy;
update = true;
}
if (update)
{
pBar->GetParent()->ScreenToClient(paneRect);
pBar->MoveWindow(paneRect, FALSE);
}
}
CPaneDivider::OnShowPane(pBar, bShow);
}
void CPaneDividerCb::GetHiddenPanes(CObList& lstBars)
{
if (m_pContainerManager != NULL)
{
(DYNAMIC_DOWNCAST(CPaneContainerManagerCb, m_pContainerManager))->AddHiddenPanesToList(&lstBars, NULL);
}
}
}
IMPLEMENT_DYNAMIC(CMDIFrameWndExCb, CMDIFrameWndEx)
BEGIN_MESSAGE_MAP(CMDIFrameWndExCb, CMDIFrameWndEx)
ON_UPDATE_COMMAND_UI(ID_WINDOW_TILE_HORZ, OnUpdateWindowTile)
ON_UPDATE_COMMAND_UI(ID_WINDOW_TILE_VERT, OnUpdateWindowTile)
ON_COMMAND_EX(ID_WINDOW_TILE_HORZ, OnWindowTile)
ON_COMMAND_EX(ID_WINDOW_TILE_VERT, OnWindowTile)
END_MESSAGE_MAP()
CMDIFrameWndExCb::CMDIFrameWndExCb()
{
CPaneDivider::m_pContainerManagerRTC = RUNTIME_CLASS(CPaneContainerManagerCb);
CPaneDivider::m_pSliderRTC = RUNTIME_CLASS(CPaneDividerCb);
}
// KLUDGE: dirty trick to get access to CMDIClientAreaWnd members
class CMDIFrameWndExCb::CMDIClientAreaWndCb : public CMDIClientAreaWnd
{
public:
void OnUpdateWindowTile(CCmdUI* pCmdUI)
{
BOOL vert = pCmdUI->m_nID == ID_WINDOW_TILE_VERT;
// allow switching between horz and vert split
if (!vert && m_groupAlignment == GROUP_VERT_ALIGN ||
vert && m_groupAlignment == GROUP_HORZ_ALIGN) {
pCmdUI->Enable(TRUE);
return;
}
// if active tab is in a multiple-tab group, allow split
CMFCTabCtrl* activeTabWnd = FindActiveTabWnd();
if (!activeTabWnd)
{
pCmdUI->Enable(FALSE);
return;
}
pCmdUI->Enable(activeTabWnd->GetTabsNum() >= 2);
}
BOOL OnWindowTile(UINT nID)
{
BOOL vert = nID == ID_WINDOW_TILE_VERT;
// no reason to show intermediate window changes
SetRedraw(FALSE);
// see comment in CMDIClientAreaWnd::MDITabNewGroup
if (vert && m_groupAlignment == GROUP_HORZ_ALIGN ||
!vert && m_groupAlignment == GROUP_VERT_ALIGN)
{
Unsplit();
}
MDITabNewGroup(vert);
// show final state
SetRedraw(TRUE);
UpdateTabs(TRUE);
RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
return TRUE;
}
protected:
void Unsplit()
{
CMFCTabCtrl* activeTabWnd = FindActiveTabWnd();
CWnd* activeWnd = activeTabWnd ? activeTabWnd->GetActiveWnd() : NULL;
CMFCTabCtrl* pFirstTabWnd = NULL;
for (POSITION pos = m_lstTabbedGroups.GetHeadPosition() ; pos != NULL ; )
{
CMFCTabCtrl* pNextTabWnd = DYNAMIC_DOWNCAST(CMFCTabCtrl, m_lstTabbedGroups.GetNext(pos));
ASSERT_VALID(pNextTabWnd);
if (!pFirstTabWnd)
{
pFirstTabWnd = pNextTabWnd;
}
else
{
int tabs = pNextTabWnd->GetTabsNum();
for (int i = 0; i < tabs; ++i)
{
MoveWindowToTabGroup(pNextTabWnd, pFirstTabWnd, 0);
}
}
}
if (activeWnd)
{
SetActiveTab(activeWnd->GetSafeHwnd());
}
}
};
void CMDIFrameWndExCb::OnUpdateWindowTile(CCmdUI* pCmdUI)
{
GetMDIClient().OnUpdateWindowTile(pCmdUI);
}
BOOL CMDIFrameWndExCb::OnWindowTile(UINT nID)
{
return GetMDIClient().OnWindowTile(nID);
}
const CMDIFrameWndExCb::CMDIClientAreaWndCb& CMDIFrameWndExCb::GetMDIClient() const
{
return const_cast<CMDIFrameWndExCb*>(this)->GetMDIClient();
}
CMDIFrameWndExCb::CMDIClientAreaWndCb& CMDIFrameWndExCb::GetMDIClient()
{
return static_cast<CMDIClientAreaWndCb&>(m_wndClientArea);
}
| [
"dlarson42@gmail.com"
] | dlarson42@gmail.com |
2e96b02975cd26a66fd357aa94cfe23b619ca1eb | 3724e8cb069a4ba90731bd3a268757138124aec1 | /viewport.cpp | 8836c4a86e9c94841a1e329ac9e5e11a7787254e | [] | no_license | UnmeshK25/Scooby-Doo-2D-game-2D-game-development-with-c- | e8eca7e8e4362a56416443389954c35db61221a0 | 142ec4e0abfb9e1537db21d6fa4f568f2a200dae | refs/heads/master | 2021-09-01T23:12:28.715040 | 2017-12-29T04:09:44 | 2017-12-29T04:09:44 | 115,684,548 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,480 | cpp | #include <sstream>
#include "viewport.h"
#include "ioMod.h"
Viewport& Viewport::getInstance() {
static Viewport viewport;
return viewport;
}
Viewport::Viewport() :
gdata(Gamedata::getInstance()),
position(0, 0),
worldWidth(gdata.getXmlInt("world/width")),
worldHeight(gdata.getXmlInt("world/height")),
viewWidth(gdata.getXmlInt("view/width")),
viewHeight(gdata.getXmlInt("view/height")),
objWidth(0), objHeight(0),
objectToTrack(NULL)
{}
void Viewport::setObjectToTrack(const Drawable *obj) {
objectToTrack = obj;
objWidth = objectToTrack->getFrame()->getWidth();
objHeight = objectToTrack->getFrame()->getHeight();
}
void Viewport::draw() const {
SDL_Color textFontColor({0xff, 0xa5, 0, 0});
SDL_Color textColor({0xff, 0xff, 0xff, 0});
IOmod::getInstance().
writeText(gdata.getXmlStr("screenTitle/title"), gdata.getXmlInt("screenTitle/locationx"), gdata.getXmlInt("screenTitle/locationy"),textFontColor);
}
void Viewport::update() {
const float x = objectToTrack->getX();
const float y = objectToTrack->getY();
position[0] = (x + objWidth/2) - viewWidth/2;
position[1] = (y + objHeight/2) - viewHeight/2;
if (position[0] < 0) position[0] = 0;
if (position[1] < 0) position[1] = 0;
if (position[0] > (worldWidth - viewWidth)) {
position[0] = worldWidth-viewWidth;
}
if (position[1] > (worldHeight - viewHeight)) {
position[1] = worldHeight-viewHeight;
}
}
| [
"noreply@github.com"
] | UnmeshK25.noreply@github.com |
d04f4b966f3d28f0a825fb3249738b0174816c29 | bbcda48854d6890ad029d5973e011d4784d248d2 | /trunk/win/Source/Includes/QtIncludes/src/3rdparty/webkit/WebCore/bridge/runtime_array.h | d5696ed476cf45b6c55d0dbbb37cb788934e2dc8 | [
"BSD-2-Clause",
"LGPL-2.0-only",
"LGPL-2.1-only",
"MIT",
"curl",
"LGPL-2.1-or-later",
"BSD-3-Clause",
"BSL-1.0",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"Zlib",
"LicenseRef-scancode-unknown",
"LicenseRef-scancode-unknown-license-reference",
"MS-LPL"
] | permissive | dyzmapl/BumpTop | 9c396f876e6a9ace1099b3b32e45612a388943ff | 1329ea41411c7368516b942d19add694af3d602f | refs/heads/master | 2020-12-20T22:42:55.100473 | 2020-01-25T21:00:08 | 2020-01-25T21:00:08 | 236,229,087 | 0 | 0 | Apache-2.0 | 2020-01-25T20:58:59 | 2020-01-25T20:58:58 | null | UTF-8 | C++ | false | false | 3,144 | h | /*
* Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef RUNTIME_ARRAY_H_
#define RUNTIME_ARRAY_H_
#include "Bridge.h"
#include <runtime/ArrayPrototype.h>
namespace JSC {
class RuntimeArray : public JSArray {
public:
RuntimeArray(ExecState*, Bindings::Array*);
virtual ~RuntimeArray();
virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
virtual bool getOwnPropertySlot(ExecState*, unsigned, PropertySlot&);
virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
virtual void put(ExecState*, unsigned propertyName, JSValue);
virtual bool deleteProperty(ExecState* exec, const Identifier &propertyName);
virtual bool deleteProperty(ExecState* exec, unsigned propertyName);
virtual const ClassInfo* classInfo() const { return &s_info; }
unsigned getLength() const { return getConcreteArray()->getLength(); }
Bindings::Array* getConcreteArray() const { return static_cast<Bindings::Array*>(subclassData()); }
static const ClassInfo s_info;
static ArrayPrototype* createPrototype(ExecState*, JSGlobalObject* globalObject)
{
return globalObject->arrayPrototype();
}
private:
static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesGetPropertyNames | JSObject::StructureFlags;
static JSValue lengthGetter(ExecState*, JSValue, const Identifier&);
static JSValue indexGetter(ExecState*, JSValue, unsigned);
};
} // namespace JSC
#endif // RUNTIME_ARRAY_H_
| [
"anandx@google.com"
] | anandx@google.com |
6a5aa90b37f2c5b629bfaa83f4e9bf3314387e00 | c7eef555bde856d68575dfc05e1417e7c3f175ba | /Codeforces/1185B.cpp | 8fc729dbc26dc827e35c440544d0b2f83a22cf70 | [] | no_license | JonathanChavezTamales/Programacion_competitiva | e84e7914e16edf4fe800f784b1807236b78a3b0a | 9c3717ed6bef9c0fe0c6d871993c054d975fed2b | refs/heads/master | 2021-06-25T09:27:18.892438 | 2020-11-25T22:56:28 | 2020-11-25T22:56:28 | 153,844,483 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 654 | cpp | #include <iostream>
#include <map>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
string a, b;
bool bq = true;
cin>>a>>b;
vector <char> aset(a.length());
for(int i=0; i<a.length(); i++){
aset[i] = a[i];
}
for(int i=0; i<b.length(); i++){
if(a.find(b[i]) == a.npos || ){
bq=false;
}
auto it = find(aset.begin(), aset.end(),b[i]);
if(it != aset.end()){
aset.erase(it);
}
}
for(int i=0; i<aset.size(); i++)
clog<<aset[i];
if(aset.size() == 0 && bq){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
}
| [
"jonathanchatab@hotmail.com"
] | jonathanchatab@hotmail.com |
0c8d16d180995ad202b40363a407071ff236cfb9 | e7738b77c28f26f7a641414dd84c6e95bfbb4363 | /Backtrack4.cpp | 51b32fe9e2a57e30e55676e9c2033c1a441db6b1 | [] | no_license | ankurmoh/CodeSignal | 2a98e8be1265ed73c55a94cd6b7849adda4ffebb | baf28e3b89fffaf034ef673cc1e2a9c9100dc5dd | refs/heads/main | 2023-01-01T14:42:07.087296 | 2020-10-30T04:51:44 | 2020-10-30T04:51:44 | 307,859,682 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,382 | cpp | vector<vector<int>>dir = {{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{-1,1},{1,-1},{1,1}};
bool dfs(string temp,int pos,int len,vector<vector<char>>& board,int i,int j,int sz1,int sz2)
{
if(pos == len)
return true;
if((i<0)||(i>=sz1)||(j<0)||(j>=sz2)||(board[i][j]!=temp[pos]))
return false;
int k,x,y;
char ch = board[i][j];
board[i][j]='*';
bool res = false;
for(k=0;k<8;k++)
{
x = i + dir[k][0];
y = j + dir[k][1];
res = res || dfs(temp,pos+1,len,board,x,y,sz1,sz2);
}
board[i][j]=ch;
return res;
}
bool valid(string temp,int len,vector<vector<char>>& board,int sz1,int sz2)
{
int i,j;
for(i=0;i<sz1;i++)
{
for(j=0;j<sz2;j++)
{
if(board[i][j] == temp[0])
{
if(dfs(temp,0,len,board,i,j,sz1,sz2))
return true;
}
}
}
return false;
}
std::vector<std::string> wordBoggle(std::vector<std::vector<char>> board, std::vector<std::string> words) {
int i,sz1=words.size(),sz2 = board.size(),sz3,len;
vector<string>res;
string temp;
if((sz1 == 0) || (sz2 == 0))
return res;
sz3 = board[0].size();
sort(words.begin(),words.end());
for(i=0;i<sz1;i++)
{
temp = words[i];
len = temp.length();
if(valid(temp,len,board,sz2,sz3))
{
res.push_back(temp);
}
}
return res;
}
| [
"noreply@github.com"
] | ankurmoh.noreply@github.com |
7e3fb290cc6315ab09307751a5ea9f81352d1056 | 663e4a69f1307ee97b1116ba12b9b366e2ba3184 | /tests/typing/bad/testfile-assign-30.cpp | 1d650eb90f7889710eb1336efb4c9000e44e77b6 | [] | no_license | jonathan-laurent/minicpp | 10c416a910572223e4290aa35861762f2ff464c4 | f21f495803d45ffe9d0ee7321c6d20d767ebe011 | refs/heads/master | 2021-01-23T06:45:29.706235 | 2014-10-04T17:41:41 | 2014-10-04T17:41:41 | 24,796,112 | 2 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 40 | cpp |
void foo() {}
int main() { +(foo()); }
| [
"jonathan.laurent@ens.fr"
] | jonathan.laurent@ens.fr |
615cd450ce03d149843890433104d22f13259396 | 80b8dc83b90d441e709a8e2dd336aeb47d970f98 | /examples/CELLSTICK_test/CELLSTICK_test.ino | 1cdc2b7536471435f4b609b72f70047fd1de1b44 | [] | no_license | tinkeringtech/Cellstick | 326a6be44700dc6d44555b107113161d6eabaa23 | cb9b4cbc0643875b4faa2f1a99513998f1a38275 | refs/heads/master | 2021-05-15T01:47:21.645263 | 2017-11-23T16:45:39 | 2017-11-23T16:45:39 | 28,522,083 | 3 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 19,838 | ino | /***************************************************
This is a test library for the TinkeringTech CellStick
This library is based on the Adafruit FONA library written by Limor Fried/Ladyada for Adafruit Industries. Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing products from Adafruit and Tinkeringtech.
www.adafruit.com
www.tinkeringtech.com
BSD license, all text above must be included in any redistribution
****************************************************/
/*
THIS CODE IS STILL IN PROGRESS!
Open up the serial console on the Arduino at 115200 baud to interact with CELLSTICK
Note that if you need to set a GPRS APN, username, and password scroll down to
the commented section below at the end of the setup() function.
*/
#include <SoftwareSerial.h>
#include "Tinkeringtech_CELLSTICK.h"
#define CELLSTICK_RX 2
#define CELLSTICK_TX 3
#define CELLSTICK_RST 4
// this is a large buffer for replies
char replybuffer[255];
SoftwareSerial cellstickSS = SoftwareSerial(CELLSTICK_TX, CELLSTICK_RX);
Tinkeringtech_CELLSTICK cellstick = Tinkeringtech_CELLSTICK(&cellstickSS, CELLSTICK_RST);
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
void setup() {
Serial.begin(115200);
Serial.println(F("CELLSTICK test"));
Serial.println(F("Initializing....(May take 3 seconds)"));
// See if the CELLSTICK is responding
if (! cellstick.begin(4800)) { // make it slow so its easy to read!
Serial.println(F("Couldn't find CELLSTICK"));
while (1);
}
Serial.println(F("CELLSTICK is OK"));
// Print SIM card IMEI number.
char imei[15] = {0}; // MUST use a 16 character buffer for IMEI!
uint8_t imeiLen = cellstick.getIMEI(imei);
if (imeiLen > 0) {
Serial.print("SIM card IMEI: "); Serial.println(imei);
}
// Optionally configure a GPRS APN, username, and password.
// You might need to do this to access your network's GPRS/data
// network. Contact your provider for the exact APN, username,
// and password values. Username and password are optional and
// can be removed, but APN is required.
//cellstick.setGPRSNetworkSettings(F("your APN"), F("your username"), F("your password"));
// Optionally configure HTTP gets to follow redirects over SSL.
// Default is not to follow SSL redirects, however if you uncomment
// the following line then redirects over SSL will be followed.
//cellstick.setHTTPSRedirect(true);
printMenu();
}
void printMenu(void) {
Serial.println(F("-------------------------------------"));
Serial.println(F("[?] Print this menu"));
Serial.println(F("[a] read the ADC (2.8V max)"));
Serial.println(F("[b] read the Battery V and % charged"));
Serial.println(F("[C] read the SIM CCID"));
Serial.println(F("[U] Unlock SIM with PIN code"));
Serial.println(F("[i] read RSSI"));
Serial.println(F("[n] get Network status"));
Serial.println(F("[v] set audio Volume"));
Serial.println(F("[V] get Volume"));
Serial.println(F("[H] set Headphone audio"));
Serial.println(F("[e] set External audio"));
Serial.println(F("[T] play audio Tone"));
Serial.println(F("[f] tune FM radio"));
Serial.println(F("[F] turn off FM"));
Serial.println(F("[m] set FM volume"));
Serial.println(F("[M] get FM volume"));
Serial.println(F("[q] get FM station signal level"));
Serial.println(F("[P] PWM/Buzzer out"));
Serial.println(F("[c] make phone Call"));
Serial.println(F("[h] Hang up phone"));
Serial.println(F("[p] Pick up phone"));
Serial.println(F("[N] Number of SMSs"));
Serial.println(F("[r] Read SMS #"));
Serial.println(F("[R] Read All SMS"));
Serial.println(F("[d] Delete SMS #"));
Serial.println(F("[s] Send SMS"));
Serial.println(F("[y] Enable network time sync"));
Serial.println(F("[Y] Enable NTP time sync (GPRS)"));
Serial.println(F("[t] Get network time"));
Serial.println(F("[G] Enable GPRS"));
Serial.println(F("[g] Disable GPRS"));
Serial.println(F("[l] Query GSMLOC (GPRS)"));
Serial.println(F("[w] Read webpage (GPRS)"));
Serial.println(F("[W] Post to website (GPRS)"));
Serial.println(F("[S] create Serial passthru tunnel"));
Serial.println(F("-------------------------------------"));
Serial.println(F(""));
}
void loop() {
Serial.print(F("CELLSTICK> "));
while (! Serial.available() );
char command = Serial.read();
Serial.println(command);
switch (command) {
case '?': {
printMenu();
break;
}
case 'a': {
// read the ADC
uint16_t adc;
if (! cellstick.getADCVoltage(&adc)) {
Serial.println(F("Failed to read ADC"));
} else {
Serial.print(F("ADC = ")); Serial.print(adc); Serial.println(F(" mV"));
}
break;
}
case 'b': {
// read the battery voltage and percentage
uint16_t vbat;
if (! cellstick.getBattVoltage(&vbat)) {
Serial.println(F("Failed to read Batt"));
} else {
Serial.print(F("VBat = ")); Serial.print(vbat); Serial.println(F(" mV"));
}
if (! cellstick.getBattPercent(&vbat)) {
Serial.println(F("Failed to read Batt"));
} else {
Serial.print(F("VPct = ")); Serial.print(vbat); Serial.println(F("%"));
}
break;
}
case 'U': {
// Unlock the SIM with a PIN code
char PIN[5];
flushSerial();
Serial.println(F("Enter 4-digit PIN"));
readline(PIN, 3);
Serial.println(PIN);
Serial.print(F("Unlocking SIM card: "));
if (! cellstick.unlockSIM(PIN)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
break;
}
case 'C': {
// read the CCID
cellstick.getSIMCCID(replybuffer); // make sure replybuffer is at least 21 bytes!
Serial.print(F("SIM CCID = ")); Serial.println(replybuffer);
break;
}
case 'i': {
// read the RSSI
uint8_t n = cellstick.getRSSI();
int8_t r;
Serial.print(F("RSSI = ")); Serial.print(n); Serial.print(": ");
if (n == 0) r = -115;
if (n == 1) r = -111;
if (n == 31) r = -52;
if ((n >= 2) && (n <= 30)) {
r = map(n, 2, 30, -110, -54);
}
Serial.print(r); Serial.println(F(" dBm"));
break;
}
case 'n': {
// read the network/cellular status
uint8_t n = cellstick.getNetworkStatus();
Serial.print(F("Network status "));
Serial.print(n);
Serial.print(F(": "));
if (n == 0) Serial.println(F("Not registered"));
if (n == 1) Serial.println(F("Registered (home)"));
if (n == 2) Serial.println(F("Not registered (searching)"));
if (n == 3) Serial.println(F("Denied"));
if (n == 4) Serial.println(F("Unknown"));
if (n == 5) Serial.println(F("Registered roaming"));
break;
}
/*** Audio ***/
case 'v': {
// set volume
flushSerial();
Serial.print(F("Set Vol %"));
uint8_t vol = readnumber();
Serial.println();
if (! cellstick.setVolume(vol)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
break;
}
case 'V': {
uint8_t v = cellstick.getVolume();
Serial.print(v); Serial.println("%");
break;
}
case 'H': {
// Set Headphone output
if (! cellstick.setAudio(CELLSTICK_HEADSETAUDIO)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
cellstick.setMicVolume(CELLSTICK_HEADSETAUDIO, 15);
break;
}
case 'e': {
// Set External output
if (! cellstick.setAudio(CELLSTICK_EXTAUDIO)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
cellstick.setMicVolume(CELLSTICK_EXTAUDIO, 10);
break;
}
case 'T': {
// play tone
flushSerial();
Serial.print(F("Play tone #"));
uint8_t kittone = readnumber();
Serial.println();
// play for 1 second (1000 ms)
if (! cellstick.playToolkitTone(kittone, 1000)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
break;
}
/*** FM Radio ***/
case 'f': {
// get freq
flushSerial();
Serial.print(F("FM Freq (eg 1011 == 101.1 MHz): "));
uint16_t station = readnumber();
Serial.println();
// FM radio ON using headset
if (cellstick.FMradio(true, CELLSTICK_HEADSETAUDIO)) {
Serial.println(F("Opened"));
}
if (! cellstick.tuneFMradio(station)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("Tuned"));
}
break;
}
case 'F': {
// FM radio off
if (! cellstick.FMradio(false)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
break;
}
case 'm': {
// Set FM volume.
flushSerial();
Serial.print(F("Set FM Vol [0-6]:"));
uint8_t vol = readnumber();
Serial.println();
if (!cellstick.setFMVolume(vol)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
break;
}
case 'M': {
// Get FM volume.
uint8_t fmvol = cellstick.getFMVolume();
if (fmvol < 0) {
Serial.println(F("Failed"));
} else {
Serial.print(F("FM volume: "));
Serial.println(fmvol, DEC);
}
break;
}
case 'q': {
// Get FM station signal level (in decibels).
flushSerial();
Serial.print(F("FM Freq (eg 1011 == 101.1 MHz): "));
uint16_t station = readnumber();
Serial.println();
int8_t level = cellstick.getFMSignalLevel(station);
if (level < 0) {
Serial.println(F("Failed! Make sure FM radio is on (tuned to station)."));
} else {
Serial.print(F("Signal level (dB): "));
Serial.println(level, DEC);
}
break;
}
/*** PWM ***/
case 'P': {
// PWM Buzzer output @ 2KHz max
flushSerial();
Serial.print(F("PWM Freq, 0 = Off, (1-2000): "));
uint16_t freq= readnumber();
Serial.println();
if (! cellstick.PWM(freq)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
break;
}
/*** Call ***/
case 'c': {
// call a phone!
char number[30];
flushSerial();
Serial.print(F("Call #"));
readline(number, 30);
Serial.println();
Serial.print(F("Calling ")); Serial.println(number);
if (!cellstick.callPhone(number)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}
break;
}
case 'h': {
// hang up!
if (! cellstick.hangUp()) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
break;
}
case 'p': {
// pick up!
if (! cellstick.pickUp()) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
break;
}
/*** SMS ***/
case 'N': {
// read the number of SMS's!
int8_t smsnum = cellstick.getNumSMS();
if (smsnum < 0) {
Serial.println(F("Could not read # SMS"));
} else {
Serial.print(smsnum);
Serial.println(F(" SMS's on SIM card!"));
}
break;
}
case 'r': {
// read an SMS
flushSerial();
Serial.print(F("Read #"));
uint8_t smsn = readnumber();
Serial.print(F("\n\rReading SMS #")); Serial.println(smsn);
// Retrieve SMS sender address/phone number.
if (! cellstick.getSMSSender(smsn, replybuffer, 250)) {
Serial.println("Failed!");
break;
}
Serial.print(F("FROM: ")); Serial.println(replybuffer);
// Retrieve SMS value.
uint16_t smslen;
if (! cellstick.readSMS(smsn, replybuffer, 250, &smslen)) { // pass in buffer and max len!
Serial.println("Failed!");
break;
}
Serial.print(F("***** SMS #")); Serial.print(smsn);
Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****"));
Serial.println(replybuffer);
Serial.println(F("*****"));
break;
}
case 'R': {
// read all SMS
int8_t smsnum = cellstick.getNumSMS();
uint16_t smslen;
for (int8_t smsn=1; smsn<=smsnum; smsn++) {
Serial.print(F("\n\rReading SMS #")); Serial.println(smsn);
if (!cellstick.readSMS(smsn, replybuffer, 250, &smslen)) { // pass in buffer and max len!
Serial.println(F("Failed!"));
break;
}
// if the length is zero, its a special case where the index number is higher
// so increase the max we'll look at!
if (smslen == 0) {
Serial.println(F("[empty slot]"));
smsnum++;
continue;
}
Serial.print(F("***** SMS #")); Serial.print(smsn);
Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****"));
Serial.println(replybuffer);
Serial.println(F("*****"));
}
break;
}
case 'd': {
// delete an SMS
flushSerial();
Serial.print(F("Delete #"));
uint8_t smsn = readnumber();
Serial.print(F("\n\rDeleting SMS #")); Serial.println(smsn);
if (cellstick.deleteSMS(smsn)) {
Serial.println(F("OK!"));
} else {
Serial.println(F("Couldn't delete"));
}
break;
}
case 's': {
// send an SMS!
char sendto[21], message[141];
flushSerial();
Serial.print(F("Send to #"));
readline(sendto, 20);
Serial.println(sendto);
Serial.print(F("Type out one-line message (140 char): "));
readline(message, 140);
Serial.println(message);
if (!cellstick.sendSMS(sendto, message)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}
break;
}
/*** Time ***/
case 'y': {
// enable network time sync
if (!cellstick.enableNetworkTimeSync(true))
Serial.println(F("Failed to enable"));
break;
}
case 'Y': {
// enable NTP time sync
if (!cellstick.enableNTPTimeSync(true, F("pool.ntp.org")))
Serial.println(F("Failed to enable"));
break;
}
case 't': {
// read the time
char buffer[23];
cellstick.getTime(buffer, 23); // make sure replybuffer is at least 23 bytes!
Serial.print(F("Time = ")); Serial.println(buffer);
break;
}
/*********************************** GPRS */
case 'g': {
// turn GPRS off
if (!cellstick.enableGPRS(false))
Serial.println(F("Failed to turn off"));
break;
}
case 'G': {
// turn GPRS on
if (!cellstick.enableGPRS(true))
Serial.println(F("Failed to turn on"));
break;
}
case 'l': {
// check for GSMLOC (requires GPRS)
uint16_t returncode;
if (!cellstick.getGSMLoc(&returncode, replybuffer, 250))
Serial.println(F("Failed!"));
if (returncode == 0) {
Serial.println(replybuffer);
} else {
Serial.print(F("Fail code #")); Serial.println(returncode);
}
break;
}
case 'w': {
// read website URL
uint16_t statuscode;
int16_t length;
char url[80];
flushSerial();
Serial.println(F("NOTE: in beta! Use small webpages to read!"));
Serial.println(F("URL to read (e.g. www.adafruit.com/testwifi/index.html):"));
Serial.print(F("http://")); readline(url, 79);
Serial.println(url);
Serial.println(F("****"));
if (!cellstick.HTTP_GET_start(url, &statuscode, (uint16_t *)&length)) {
Serial.println("Failed!");
break;
}
while (length > 0) {
while (cellstick.available()) {
char c = cellstick.read();
// Serial.write is too slow, we'll write directly to Serial register!
loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */
UDR0 = c;
length--;
if (! length) break;
}
}
Serial.println(F("\n****"));
cellstick.HTTP_GET_end();
break;
}
case 'W': {
// Post data to website
uint16_t statuscode;
int16_t length;
char url[80];
char data[80];
flushSerial();
Serial.println(F("NOTE: in beta! Use simple websites to post!"));
Serial.println(F("URL to post (e.g. httpbin.org/post):"));
Serial.print(F("http://")); readline(url, 79);
Serial.println(url);
Serial.println(F("Data to post (e.g. \"foo\" or \"{\"simple\":\"json\"}\"):"));
readline(data, 79);
Serial.println(data);
Serial.println(F("****"));
if (!cellstick.HTTP_POST_start(url, F("text/plain"), (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) {
Serial.println("Failed!");
break;
}
while (length > 0) {
while (cellstick.available()) {
char c = cellstick.read();
// Serial.write is too slow, we'll write directly to Serial register!
loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */
UDR0 = c;
length--;
if (! length) break;
}
}
Serial.println(F("\n****"));
cellstick.HTTP_POST_end();
break;
}
/*****************************************/
case 'S': {
Serial.println(F("Creating SERIAL TUBE"));
while (1) {
while (Serial.available()) {
cellstick.write(Serial.read());
}
if (cellstick.available()) {
Serial.write(cellstick.read());
}
}
break;
}
default: {
Serial.println(F("Unknown command"));
printMenu();
break;
}
}
// flush input
flushSerial();
while (cellstick.available()) {
Serial.write(cellstick.read());
}
}
void flushSerial() {
while (Serial.available())
Serial.read();
}
char readBlocking() {
while (!Serial.available());
return Serial.read();
}
uint16_t readnumber() {
uint16_t x = 0;
char c;
while (! isdigit(c = readBlocking())) {
//Serial.print(c);
}
Serial.print(c);
x = c - '0';
while (isdigit(c = readBlocking())) {
Serial.print(c);
x *= 10;
x += c - '0';
}
return x;
}
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout) {
uint16_t buffidx = 0;
boolean timeoutvalid = true;
if (timeout == 0) timeoutvalid = false;
while (true) {
if (buffidx > maxbuff) {
//Serial.println(F("SPACE"));
break;
}
while(Serial.available()) {
char c = Serial.read();
//Serial.print(c, HEX); Serial.print("#"); Serial.println(c);
if (c == '\r') continue;
if (c == 0xA) {
if (buffidx == 0) // the first 0x0A is ignored
continue;
timeout = 0; // the second 0x0A is the end of the line
timeoutvalid = true;
break;
}
buff[buffidx] = c;
buffidx++;
}
if (timeoutvalid && timeout == 0) {
//Serial.println(F("TIMEOUT"));
break;
}
delay(1);
}
buff[buffidx] = 0; // null term
return buffidx;
} | [
"lalindra.jayatilleke@gmail.com"
] | lalindra.jayatilleke@gmail.com |
988737a1d392ad0dc72a0c67e54e16ef51e14db6 | 0a9410ef6897bec58a5c5d2a080aad5bc75bb386 | /benchmark/point-correlation/dual-tree/src/tree.h | df08f03fffe31545c4594ab6e1c3cdbedb24ea94 | [] | no_license | kirshanthans/twisted-interchanger | 47e24ea945b993e006ae1a32a6f290a66896d0b2 | 4219af25ab3e5978df31ccffef6560c9bce45ebd | refs/heads/master | 2021-05-01T12:38:55.762960 | 2017-01-21T04:06:49 | 2017-01-21T04:06:49 | 79,527,532 | 5 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 2,994 | h | /* Copyright (c) 2017, Kirshanthan Sundararajah, Laith Sakka and Milind Kulkarni
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Purdue University nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#ifndef TREE_H_
#define TREE_H_
#include <cstdlib>
#include <cstdint>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <fstream>
#include "defines.h"
using namespace std;
//Constants
const int MAX_POINTS_IN_CELL = 1;
//Point Data Structure
class Point{
public:
Point();
~Point();
//float coord[DIM];
float *coord;
int corr;
#ifdef DEBUG
int pid;
static int pcount;
#endif
};
//Tree Data Structure
class Node{
public:
Node();
~Node();
//Point in the node
Point *data;
Point *points[MAX_POINTS_IN_CELL];
//splitting dimentions
int axis;
//splitting value
float splitval;
//#successors below
int succnum;
//Root flag
bool isRoot;
//Links to subtrees and parents
Node *l;
Node *r;
//bounding boxes
float *min;
float *max;
//truncation flag
long long vtrunc;
long long vsubtrunc;
#ifdef DEBUG
int nid;
static int ncount;
#endif
};
//Traversal Terminating Conditions
bool isLeaf(Node *n);
bool isEnd(Node *n);
bool isInner(Node *n);
//Tree Building
Node * buildTrees(Point *points, int lb, int ub, int depth);
void destroyTrees(Node *n);
//Point Utility Functions
float distanceAxis(Point *a, Point *b, int axis);
float distanceEuclid(Point *a, Point *b);
int comparePoint(const void *a, const void *b);
bool canCorrelate(Node *p, Node *n);
void drawTree(Node* n, ofstream& file);
#endif
/*TREE_H_*/
| [
"kirshanthans.14@cse.mrt.ac.lk"
] | kirshanthans.14@cse.mrt.ac.lk |
324756179c398875a971f8b2bacf7be8d4b6c05f | f7f7c85b445f56234001ec2177fac4732e39ab9a | /lang_integration/cpp_so_from_ruby/code.h | 35112eb1d5f30944d611147f7c1624ae94cb8e2d | [] | no_license | datsoftlyngby/soft2018fall-si-teaching-material | f706009bea7799452f1314829922f07b9e7d0b48 | b81400a4004a6bd02db812f9c65a596c0b4db034 | refs/heads/master | 2020-03-27T04:55:47.470852 | 2018-12-14T11:08:16 | 2018-12-14T11:08:16 | 145,979,494 | 3 | 7 | null | null | null | null | UTF-8 | C++ | false | false | 94 | h | #include <vector>
std::vector<double> average (std::vector< std::vector<double> > i_matrix);
| [
"rhp@cphbusiness.dk"
] | rhp@cphbusiness.dk |
6cb7fc94ba531ea48203ff079132e180551344cf | 509188c494f909d72aa57becba412aada304a121 | /MFCApplication1Dlg.h | e3f5ffba6fd3ec234f8eb1bd68df05aba97db23c | [] | no_license | takabus/ddcci-mfc | 533c8a37d26f4f4fefe087345bb0194f1ade8a8d | f3fbf4845eed1d331feb286fe00d3b15c6145207 | refs/heads/main | 2023-09-04T04:06:54.925958 | 2021-11-05T05:09:45 | 2021-11-05T05:09:45 | 407,435,554 | 1 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 1,373 | h |
// MFCApplication1Dlg.h : ヘッダー ファイル
//
#pragma once
// CMFCApplication1Dlg ダイアログ
class CMFCApplication1Dlg : public CDialogEx
{
// コンストラクション
public:
CMFCApplication1Dlg(CWnd* pParent = nullptr); // 標準コンストラクター
// ダイアログ データ
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_MFCAPPLICATION1_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV サポート
// 実装
protected:
HICON m_hIcon;
// 生成された、メッセージ割り当て関数
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnTRBNThumbPosChangingSlider1(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnBnClickedButtonapplay();
afx_msg void OnBnClickedOk();
afx_msg void OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnEnChangeEdit1();
afx_msg void OnBnClickedCancel();
afx_msg void OnNMCustomdrawSlider1(NMHDR *pNMHDR, LRESULT *pResult);
};
void GethMonitorsAndhPhysicalMonitors();
BOOL GetDDCCIMonitorBrightness(int Index, LPDWORD pdwMinimumBrightness, LPDWORD pdwCurrentBrightness, LPDWORD pdwMaximumBrightness);
BOOL ApplyDisplaySetting(); | [
"zetros1833@gmail.com"
] | zetros1833@gmail.com |
b328f51675e3ff8cf210ebcb8ac4528082908462 | 643c0fce80d3ae2891bc526d08e3c75a480503b2 | /createaccounts.cpp | 758e10de3e32f2aa9070bc72bcb300f3fe4d2b70 | [
"MIT"
] | permissive | API-market/CreateEscrow | 8fc8ae761efbfaa8df009b19e07ba0001377109a | a414db3905e77f275228b4c2a48b4ad324198350 | refs/heads/master | 2023-01-30T03:08:17.658594 | 2020-01-21T19:17:15 | 2020-01-21T19:17:15 | 230,813,444 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 9,894 | cpp | #include "createescrow.hpp"
#include "lib/common.h"
#include "models/accounts.h"
#include "models/balances.h"
#include "models/registry.h"
#include "models/bandwidth.h"
#include "airdrops.cpp"
#include "contributions.cpp"
#include "constants.cpp"
#include "rex.cpp"
namespace createescrow
{
using namespace eosio;
using namespace std;
/***
* Creates a new user account.
* It also airdrops custom dapp tokens to the new user account if a dapp owner has opted for airdrops
* memo: name of the account paying for the balance left after getting the donation from the dapp contributors
* account: name of the account to be created
* ownerkey,activekey: key pair for the new account
* origin: the string representing the dapp to create the new user account for. For ex- everipedia.org, lumeos
* For new user accounts, it follows the following steps:
* 1. Choose a contributor, if any, for the dapp to fund the cost for new account creation
* 2. Check if the contributor is funding 100 %. If not, check if the "memo" account has enough to fund the remaining cost of account creation
*/
void create_escrow::create(string &memo, name &account, public_key &ownerkey, public_key &activekey, string &origin, name referral)
{
auto iterator = dapps.find(toUUID(origin));
// Only owner/whitelisted account for the dapp can create accounts
if (iterator != dapps.end())
{
if (name(memo) == iterator->owner)
require_auth(iterator->owner);
else if (create_escrow::checkIfWhitelisted(name(memo), origin))
require_auth(name(memo));
else if (origin == "free")
print("using globally available free funds to create account");
else
check(false, ("only owner or whitelisted accounts can create new user accounts for " + origin).c_str());
}
else
{
check(false, ("no owner account found for " + origin).c_str());
}
authority owner{.threshold = 1, .keys = {key_weight{ownerkey, 1}}, .accounts = {}, .waits = {}};
authority active{.threshold = 1, .keys = {key_weight{activekey, 1}}, .accounts = {}, .waits = {}};
create_escrow::createJointAccount(memo, account, origin, owner, active, referral);
}
/***
* Checks if an account is whitelisted for a dapp by the owner of the dapp
* @return
*/
void create_escrow::createJointAccount(string &memo, name &account, string &origin, accounts::authority &ownerAuth, accounts::authority &activeAuth, name referral)
{
// memo is the account that pays the remaining balance i.e
// balance needed for new account creation - (balance contributed by the contributors)
vector<balance::chosen_contributors> contributors;
name freeContributor;
asset balance;
asset requiredBalance;
bool useOwnerCpuBalance = false;
bool useOwnerNetBalance = false;
symbol coreSymbol = create_escrow::getCoreSymbol();
asset ramFromDapp = asset(0'0000, coreSymbol);
balance::Balances balances(_self, _self.value);
registry::Registry dapps(_self, _self.value);
// gets the ram, net and cpu requirements for the new user accounts from the dapp registry
auto iterator = dapps.find(common::toUUID(origin));
string owner = iterator->owner.to_string();
uint64_t ram_bytes = iterator->ram_bytes;
bool isfixed = false;
if (ram_bytes == 0)
{
isfixed = true;
}
// cost of required ram
asset ram = create_escrow::getRamCost(ram_bytes, iterator->pricekey);
asset net;
asset net_balance;
asset cpu;
asset cpu_balance;
// isfixed - if a fixed tier pricing is offered for accounts. For ex - 5 SYS for 4096 bytes RAM, 1 SYS CPU and 1 SYS net
if (!isfixed)
{
net = iterator->use_rex ? iterator->rex->net_loan_payment + iterator->rex->net_loan_fund : iterator->net;
cpu = iterator->use_rex ? iterator->rex->cpu_loan_payment + iterator->rex->cpu_loan_fund : iterator->cpu;
// if using rex, then the net balance to be deducted will be the same as net_loan_payment + net_loan_fund. Similar for cpu
net_balance = create_escrow::findContribution(origin, name(memo), "net");
if (net_balance == asset(0'0000, coreSymbol))
{
net_balance = create_escrow::findContribution(origin, iterator->owner, "net");
useOwnerNetBalance = true;
}
cpu_balance = create_escrow::findContribution(origin, name(memo), "cpu");
if (cpu_balance == asset(0'0000, coreSymbol))
{
cpu_balance = create_escrow::findContribution(origin, iterator->owner, "cpu");
useOwnerCpuBalance = true;
}
if (cpu > cpu_balance || net > net_balance)
{
check(false, ("Not enough cpu or net balance in " + memo + "for " + origin + " to pay for account's bandwidth.").c_str());
}
if (useOwnerNetBalance)
{
create_escrow::subCpuOrNetBalance(owner, origin, net, iterator->use_rex);
}
else
{
create_escrow::subCpuOrNetBalance(memo, origin, net, iterator->use_rex);
}
if (useOwnerCpuBalance)
{
create_escrow::subCpuOrNetBalance(owner, origin, cpu, iterator->use_rex);
}
else
{
create_escrow::subCpuOrNetBalance(memo, origin, cpu, iterator->use_rex);
}
}
else
{
net = create_escrow::getFixedNet(iterator->pricekey);
cpu = create_escrow::getFixedCpu(iterator->pricekey);
}
asset ramFromPayer = ram;
if (memo != origin && create_escrow::hasBalance(origin, ram))
{
uint64_t originId = common::toUUID(origin);
auto dapp = balances.find(originId);
if (dapp != balances.end())
{
uint64_t seed = account.value;
uint64_t value = name(memo).value;
contributors = create_escrow::getContributors(origin, memo, seed, value, ram);
for (std::vector<balance::chosen_contributors>::iterator itr = contributors.begin(); itr != contributors.end(); ++itr)
{
ramFromDapp += itr->rampay;
}
ramFromPayer -= ramFromDapp;
}
}
// find the balance of the "memo" account for the origin and check if it has balance >= total balance for RAM, CPU and net - (balance payed by the contributors)
if (ramFromPayer > asset(0'0000, coreSymbol))
{
asset balance = create_escrow::findContribution(origin, name(memo), "ram");
requiredBalance = ramFromPayer;
// if the "memo" account doesn't have enough fund, check globally available "free" pool
if (balance < requiredBalance)
{
check(false, ("Not enough balance in " + memo + " or donated by the contributors for " + origin + " to pay for account creation.").c_str());
}
}
create_escrow::createAccount(origin, account, ownerAuth, activeAuth, ram, net, cpu, iterator->pricekey, iterator->use_rex, isfixed, referral);
// subtract the used balance
if (ramFromPayer.amount > 0)
{
create_escrow::subBalance(memo, origin, requiredBalance);
}
if (ramFromDapp.amount > 0)
{
for (std::vector<balance::chosen_contributors>::iterator itr = contributors.begin(); itr != contributors.end(); ++itr)
{
// check if the memo account and the dapp contributor is the same. If yes, only increament accounts created by 1
if (itr->contributor == name{memo} && ramFromPayer.amount > 0)
{
create_escrow::subBalance(itr->contributor.to_string(), origin, itr->rampay, true);
}
else
{
create_escrow::subBalance(itr->contributor.to_string(), origin, itr->rampay);
}
}
}
// airdrop dapp tokens if requested
create_escrow::airdrop(origin, account);
}
/***
* Calls the chain to create a new account
*/
void create_escrow::createAccount(string dapp, name &account, accounts::authority &ownerauth, accounts::authority &activeauth, asset &ram, asset &net, asset &cpu, uint64_t pricekey, bool use_rex, bool isfixed, name referral)
{
accounts::newaccount new_account = accounts::newaccount{
.creator = _self,
.name = account,
.owner = ownerauth,
.active = activeauth};
name newAccountContract = create_escrow::getNewAccountContract();
name newAccountAction = create_escrow::getNewAccountAction();
if (isfixed)
{ // check if the account creation is fixed
action(
permission_level{_self, "active"_n},
newAccountContract,
newAccountAction,
make_tuple(_self, account, ownerauth.keys[0].key, activeauth.keys[0].key, pricekey, referral))
.send();
}
else
{
action(
permission_level{_self, "active"_n},
newAccountContract,
name("newaccount"),
new_account)
.send();
action(
permission_level{_self, "active"_n},
newAccountContract,
name("buyram"),
make_tuple(_self, account, ram))
.send();
if (use_rex == true)
{
create_escrow::rentrexnet(dapp, account);
create_escrow::rentrexcpu(dapp, account);
}
else
{
if (net + cpu > asset(0'0000, create_escrow::getCoreSymbol()))
{
action(
permission_level{_self, "active"_n},
newAccountContract,
name("delegatebw"),
make_tuple(_self, account, net, cpu, false))
.send();
}
}
}
};
} // namespace createescrow | [
"surabhil@usc.edu"
] | surabhil@usc.edu |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.