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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0fad73d750e0bbafaf7fcc2f6db6b0a78f80fd49 | ea14e5771af1f099aac4011e680f67acf622f0f8 | /regen/Parser.hpp | d0b4b2ca9ea05f20430791ebbeddff05379000b8 | [
"MIT"
] | permissive | nobody0702/libRegen | 4c57e96bcbe2694802afe29e7d9a998807903334 | 8037fcefffe6d511065cba81c1e050aaab07ccf4 | refs/heads/master | 2021-05-22T18:11:34.480790 | 2018-04-18T00:01:47 | 2018-04-18T00:01:47 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 15,825 | hpp | /**
* MIT License
*
* Copyright (c) 2018 Sébastien Débia
*
* 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.
*/
#pragma once
#include <memory>
#include <boost/lexical_cast.hpp>
namespace regen
{
/*
<RE> ::= <union> | <simple-RE>
<union> ::= <RE> "|" <simple-RE>
<simple-RE> ::= <concatenation> | <basic-RE>
<concatenation> ::= <simple-RE> <basic-RE>
<basic-RE> ::= <star> | <plus> | <elementary-RE>
<star> ::= <elementary-RE> "*"
<plus> ::= <elementary-RE> "+"
<elementary-RE> ::= <group> | <any> | <eos> | <char> | <set>
<group> ::= "(" <RE> ")"
<any> ::= "."
<eos> ::= "$"
<char> ::= any non metacharacter | "\" metacharacter
<set> ::= <positive-set> | <negative-set>
<positive-set> ::= "[" <set-items> "]"
<negative-set> ::= "[^" <set-items> "]"
<set-items> ::= <set-item> | <set-item> <set-items>
<set-items> ::= <range> | <char>
<range> ::= <char> "-" <char>
<<< without left recursion >>>
<RE> ::= <simple-RE> <RE'>
<RE'> ::= "|" <simple-RE> <RE'> | Epsilon
<simple-RE> ::= <basic-RE> <simple-RE'>
<simple-RE'>::= <basic-RE> <simple-RE'> | Epsilon
<basic-RE> ::= <star> | <plus> | <question> | <elementary-RE>
<star> ::= <elementary-RE> "*"
<plus> ::= <elementary-RE> "+"
<question> ::= <elementary-RE> "?"
<numericRange> ::= <elementary-RE> "{" <integer> "} | <elementary-RE> "{" <integer> "," "}" | <elementary-RE> "{" <integer> "," <integer> "}"
<elementary-RE> ::= <group> | <any> | <eos> | <char> | <set>
<group> ::= "(" <RE> ")"
<any> ::= "."
<eos> ::= "$"
<char> ::= any non metacharacter | "\" metacharacter
<set> ::= <positive-set> | <negative-set>
<positive-set> ::= "[" <set-items> "]"
<negative-set> ::= "[^" <set-items> "]"
<set-items> ::= <set-item> | <set-item> <set-items>
<set-item> ::= <range> | <char>
<range> ::= <char> "-" <char>
*/
struct SimpleRe;
struct Re
{
std::vector<SimpleRe> unionRes;
};
struct SetItem
{
virtual ~SetItem() {};
};
struct Range : public SetItem
{
Range( char s, char e ) : start( s ), end( e ) {}
char start;
char end;
};
struct CharItem : public SetItem
{
CharItem( char c ) : c( c ) {}
char c;
};
struct BasicReSub
{
virtual ~BasicReSub() {};
};
struct ElementaryRe : public BasicReSub
{
virtual ~ElementaryRe() {};
};
struct Star : public BasicReSub
{
Star(std::unique_ptr<ElementaryRe>&& er) : re(std::move(er)) {}
std::unique_ptr<ElementaryRe> re;
};
struct Plus : public BasicReSub
{
Plus(std::unique_ptr<ElementaryRe>&& er) : re(std::move(er)) {}
std::unique_ptr<ElementaryRe> re;
};
struct Question : public BasicReSub
{
Question(std::unique_ptr<ElementaryRe>&& er) : re(std::move(er)) {}
std::unique_ptr<ElementaryRe> re;
};
struct NumericRange : public BasicReSub
{
NumericRange(std::unique_ptr<ElementaryRe>&& er, std::size_t mi, std::size_t ma)
: re(std::move(er)), min(mi), max(ma)
{}
std::unique_ptr<ElementaryRe> re;
std::size_t min;
std::size_t max;
};
struct Group : public ElementaryRe
{
Re re;
};
struct Any : public ElementaryRe
{
};
struct Char : public ElementaryRe
{
Char( char c ) : c( c ) {}
char c;
};
struct Set : public ElementaryRe
{
bool negative = false;
std::vector<std::unique_ptr<SetItem>> items;
};
struct BasicRe
{
std::unique_ptr<BasicReSub> sub;
};
struct SimpleRe
{
std::vector<BasicRe> concatRes;
};
/**
* Parses a list of tokens containing a regex into an AST.
*
* The list of token must be first created with a lexer.
* @see regen::lexer
*/
class Parser
{
public:
/**
* parses a list of tokens containing a regex into an AST.
*
* @param tokens list of token built with a regen::lexer
*
* @return the AST root for the regex
*/
Re parse( TokenList& tokens )
{
return parseRe( tokens );
}
/**
* parses a single set, e.g. [a-zA-Z].
*
* <set> ::= <positive-set> | <negative-set>
* <positive-set> ::= "[" <set-items> "]"
* <negative-set> ::= "[^" <set-items> "]"
* <set-items> ::= <set-item> | <set-item> <set-items>
* <set-items> ::= <range> | <char>
* <range> ::= <char> "-" <char>
*
* @param tokens list of token built with a regen::lexer
*
* @return the AST root for the regex
*/
Set parseStandAloneSet( TokenList& tokens )
{
return Set( std::move( *parseSet( tokens ) ) );
}
private:
std::unique_ptr<Group> parseGroup( TokenList& tokens )
{
std::unique_ptr<Group> res = std::make_unique<Group>();
tokens.eat( "(" );
res->re = parseRe( tokens );
tokens.eat( ")" );
return res;
}
std::unique_ptr<SetItem> parsetSetItem( TokenList& tokens )
{
// <set-items> ::= <set-item> | <set-item> <set-items>
// <set-items> ::= <range> | <char>
// <range> ::= <char> "-" <char>
std::unique_ptr<SetItem> res;
if( tokens.peak().type == Token::CHAR && tokens.peak(1).type == Token::MINUS )
{
char start = tokens.eat().data;
tokens.eat();
char end = tokens.eat().data;
if( end < start )
throw std::runtime_error( "Invalid range: " + std::string(1, start) + "-" + std::string(1, end) );
res = std::make_unique<Range>( start, end );
}
else
{
res = std::make_unique<CharItem>( tokens.eat().data );
}
return res;
}
std::vector<std::unique_ptr<SetItem>> expandCharClass( TokenList& tokens )
{
std::vector<std::unique_ptr<SetItem>> res;
// \w A-Za-z0-9_
// \d 0-9
// \s \t\r\n\v\f
//
// \t \x09
// \r \x0d
// \n \x0a
// \v \x0b
// \f \x0c
auto tok = tokens.eat();
if( tok.data == 'w' )
{
res.push_back( std::make_unique<Range>( 'A', 'Z' ) );
res.push_back( std::make_unique<Range>( 'a', 'z' ) );
res.push_back( std::make_unique<Range>( '0', '9' ) );
res.push_back( std::make_unique<CharItem>( '_' ) );
}
else if( tok.data == 'd' )
{
res.push_back( std::make_unique<Range>( '0', '9' ) );
}
else if( tok.data == 's' )
{
res.push_back( std::make_unique<CharItem>( '\t' ) );
res.push_back( std::make_unique<CharItem>( '\r' ) );
res.push_back( std::make_unique<CharItem>( '\n' ) );
res.push_back( std::make_unique<CharItem>( '\v' ) );
res.push_back( std::make_unique<CharItem>( '\f' ) );
}
else if( tok.data == 't' )
res.push_back( std::make_unique<CharItem>( '\t' ) );
else if( tok.data == 'r' )
res.push_back( std::make_unique<CharItem>( '\r' ) );
else if( tok.data == 'n' )
res.push_back( std::make_unique<CharItem>( '\n' ) );
else if( tok.data == 'v' )
res.push_back( std::make_unique<CharItem>( '\v' ) );
else if( tok.data == 'f' )
res.push_back( std::make_unique<CharItem>( '\f' ) );
return res;
}
std::unique_ptr<Set> parseSet( TokenList& tokens )
{
// <set> ::= <positive-set> | <negative-set>
// <positive-set> ::= "[" <set-items> "]"
// <negative-set> ::= "[^" <set-items> "]"
std::unique_ptr<Set> res = std::make_unique<Set>();
tokens.eat( "[" );
if( tokens.peak().type == Token::HAT )
{
res->negative = true;
tokens.eat( "^" );
}
if( tokens.peak().type != Token::CHAR && tokens.peak().type != Token::CHARCLASS )
throw std::runtime_error( "Expected <" + token2str(Token::CHAR) + "> or <" + token2str(Token::CHARCLASS) + "> got <" + token2str(tokens.peak().type) + ">" );
while( tokens.peak().type != Token::CBRACKET )
{
if( tokens.peak().type == Token::CHAR )
res->items.push_back( parsetSetItem( tokens ) );
else // CHARCLASS
{
auto vRanges = expandCharClass( tokens );
std::move(vRanges.begin(), vRanges.end(), std::back_inserter(res->items));
}
}
tokens.eat( "]" );
return res;
}
std::unique_ptr<ElementaryRe> parseElementaryRe( TokenList& tokens )
{
// <elementary-RE> ::= <group> | <any> ( | <eos> ) | <char> | <set>
std::unique_ptr<ElementaryRe> res;
if( tokens.peak().type == Token::OPAREN )
{
res = parseGroup( tokens );
}
else if( tokens.peak().type == Token::DOT )
{
tokens.eat();
res = std::make_unique<Any>();
}
else if( tokens.peak().type == Token::OBRACKET )
{
res = parseSet( tokens );
}
else if( tokens.peak().type == Token::CHARCLASS )
{
auto set = std::make_unique<Set>();
set->items = expandCharClass( tokens );
res = std::move( set );
}
else if( tokens.peak().type == Token::CHAR || tokens.peak().type == Token::MINUS )
{
res = std::make_unique<Char>( tokens.eat().data );
}
else
{
throw std::logic_error( "Expected <" + token2str(Token::OPAREN) + "> or <"
+ token2str(Token::DOT) + "> or <"
+ token2str(Token::OBRACKET) + "> or <"
+ token2str(Token::CHARCLASS) + "> or <"
+ token2str(Token::CHAR) + ">" );
}
return res;
}
int readInteger( TokenList& tokens )
{
std::string str;
while( tokens.peak().type == Token::CHAR && tokens.peak().data >= '0' && tokens.peak().data <= '9' )
str += std::string(1,tokens.eat().data);
try
{
return boost::lexical_cast<int>( str );
}
catch( ... )
{
throw std::runtime_error( "Expected <integer>" );
}
}
BasicRe parseBasicRe( TokenList& tokens )
{
// <basic-RE> ::= <star> | <plus> | <elementary-RE>
// <star> ::= <elementary-RE> "*"
// <plus> ::= <elementary-RE> "+"
BasicRe res;
auto elementaryRe = parseElementaryRe( tokens );
if( !tokens.eof() )
{
if( tokens.peak().data == '*' )
{
tokens.eat();
res.sub = std::make_unique<Star>( std::move(elementaryRe) );
}
else if( tokens.peak().data == '+' )
{
tokens.eat();
res.sub = std::make_unique<Plus>( std::move(elementaryRe) );
}
else if( tokens.peak().data == '?' )
{
tokens.eat();
res.sub = std::make_unique<Question>( std::move(elementaryRe) );
}
else if( tokens.peak().data == '{' )
{
tokens.eat();
int min, max;
min = readInteger( tokens );
max = min;
if( tokens.peak().type == Token::CHAR && tokens.peak().data == ',' )
{
tokens.eat();
if( tokens.peak().type == Token::CSB && tokens.peak().data == '}' )
max = min + 5;
else
{
max = readInteger( tokens );
}
}
auto tok = tokens.eat( "}" );
if( tok.data != '}' )
throw std::runtime_error( "expected <" + token2str(Token::CSB) + "> got <" + token2str(tok.type) + ">" );
res.sub = std::make_unique<NumericRange>( std::move(elementaryRe), min, max );
}
else
res.sub = std::move(elementaryRe);
}
else
res.sub = std::move(elementaryRe);
return res;
}
SimpleRe parseSimpleRe( TokenList& tokens )
{
SimpleRe res;
res.concatRes.push_back( parseBasicRe(tokens) );
while( !tokens.eof() )
{
try
{
res.concatRes.push_back( parseBasicRe(tokens) );
}
catch( ... )
{
break;
}
}
return res;
}
Re parseRe( TokenList& tokens )
{
Re res;
res.unionRes.push_back( parseSimpleRe(tokens) );
while( !tokens.eof() && tokens.peak().type == Token::PIPE )
{
tokens.eat();
res.unionRes.push_back( parseSimpleRe(tokens) );
}
if( !tokens.eof() && tokens.peak().type != Token::CPAREN ) // hack
throw std::runtime_error( "invalid regex caused parsing to stop prematurely" );
return res;
}
};
} | [
"sebastien.debia@æmail.com"
] | sebastien.debia@æmail.com |
c81d4d376b21a2e958ab18c28f710e4024969cd0 | 114287fa3fdcebef15694c44abd110be2217c5aa | /Even(cpp)/349. Odd/main.cpp | ec31fe99fa87e0f6ebf7c260a9b9d8ce26656dd4 | [
"MIT"
] | permissive | touir1/ProblemSolving_Stuff | 6bcd7f84ba7927944f90d0c76db806823488e9ce | 231b5581818edb3309d88520b5a7649403052376 | refs/heads/master | 2020-03-26T19:21:38.218991 | 2018-09-04T20:46:30 | 2018-09-04T20:46:30 | 145,261,231 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 160 | cpp | #include <iostream>
using namespace std;
int main()
{
int x;
cin >> x;
string rep=(x%2==0)?"Even":"Odd";
cout << rep << endl;
return 0;
}
| [
"touir.mat@gmail.com"
] | touir.mat@gmail.com |
8975cab5c19d96804d9e8950bdae038eda1504a3 | 2cf838b54b556987cfc49f42935f8aa7563ea1f4 | /aws-cpp-sdk-iotwireless/include/aws/iotwireless/model/SidewalkDevice.h | 72898bcdcee520b7a1c61eb36a8fc9e60a394f03 | [
"MIT",
"Apache-2.0",
"JSON"
] | permissive | QPC-database/aws-sdk-cpp | d11e9f0ff6958c64e793c87a49f1e034813dac32 | 9f83105f7e07fe04380232981ab073c247d6fc85 | refs/heads/main | 2023-06-14T17:41:04.817304 | 2021-07-09T20:28:20 | 2021-07-09T20:28:20 | 384,714,703 | 1 | 0 | Apache-2.0 | 2021-07-10T14:16:41 | 2021-07-10T14:16:41 | null | UTF-8 | C++ | false | false | 6,185 | h | /**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/iotwireless/IoTWireless_EXPORTS.h>
#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/core/utils/memory/stl/AWSVector.h>
#include <aws/iotwireless/model/CertificateList.h>
#include <utility>
namespace Aws
{
namespace Utils
{
namespace Json
{
class JsonValue;
class JsonView;
} // namespace Json
} // namespace Utils
namespace IoTWireless
{
namespace Model
{
/**
* <p>Sidewalk device object.</p><p><h3>See Also:</h3> <a
* href="http://docs.aws.amazon.com/goto/WebAPI/iotwireless-2020-11-22/SidewalkDevice">AWS
* API Reference</a></p>
*/
class AWS_IOTWIRELESS_API SidewalkDevice
{
public:
SidewalkDevice();
SidewalkDevice(Aws::Utils::Json::JsonView jsonValue);
SidewalkDevice& operator=(Aws::Utils::Json::JsonView jsonValue);
Aws::Utils::Json::JsonValue Jsonize() const;
/**
* <p>The sidewalk device identification.</p>
*/
inline const Aws::String& GetSidewalkId() const{ return m_sidewalkId; }
/**
* <p>The sidewalk device identification.</p>
*/
inline bool SidewalkIdHasBeenSet() const { return m_sidewalkIdHasBeenSet; }
/**
* <p>The sidewalk device identification.</p>
*/
inline void SetSidewalkId(const Aws::String& value) { m_sidewalkIdHasBeenSet = true; m_sidewalkId = value; }
/**
* <p>The sidewalk device identification.</p>
*/
inline void SetSidewalkId(Aws::String&& value) { m_sidewalkIdHasBeenSet = true; m_sidewalkId = std::move(value); }
/**
* <p>The sidewalk device identification.</p>
*/
inline void SetSidewalkId(const char* value) { m_sidewalkIdHasBeenSet = true; m_sidewalkId.assign(value); }
/**
* <p>The sidewalk device identification.</p>
*/
inline SidewalkDevice& WithSidewalkId(const Aws::String& value) { SetSidewalkId(value); return *this;}
/**
* <p>The sidewalk device identification.</p>
*/
inline SidewalkDevice& WithSidewalkId(Aws::String&& value) { SetSidewalkId(std::move(value)); return *this;}
/**
* <p>The sidewalk device identification.</p>
*/
inline SidewalkDevice& WithSidewalkId(const char* value) { SetSidewalkId(value); return *this;}
/**
* <p>The Sidewalk manufacturing series number.</p>
*/
inline const Aws::String& GetSidewalkManufacturingSn() const{ return m_sidewalkManufacturingSn; }
/**
* <p>The Sidewalk manufacturing series number.</p>
*/
inline bool SidewalkManufacturingSnHasBeenSet() const { return m_sidewalkManufacturingSnHasBeenSet; }
/**
* <p>The Sidewalk manufacturing series number.</p>
*/
inline void SetSidewalkManufacturingSn(const Aws::String& value) { m_sidewalkManufacturingSnHasBeenSet = true; m_sidewalkManufacturingSn = value; }
/**
* <p>The Sidewalk manufacturing series number.</p>
*/
inline void SetSidewalkManufacturingSn(Aws::String&& value) { m_sidewalkManufacturingSnHasBeenSet = true; m_sidewalkManufacturingSn = std::move(value); }
/**
* <p>The Sidewalk manufacturing series number.</p>
*/
inline void SetSidewalkManufacturingSn(const char* value) { m_sidewalkManufacturingSnHasBeenSet = true; m_sidewalkManufacturingSn.assign(value); }
/**
* <p>The Sidewalk manufacturing series number.</p>
*/
inline SidewalkDevice& WithSidewalkManufacturingSn(const Aws::String& value) { SetSidewalkManufacturingSn(value); return *this;}
/**
* <p>The Sidewalk manufacturing series number.</p>
*/
inline SidewalkDevice& WithSidewalkManufacturingSn(Aws::String&& value) { SetSidewalkManufacturingSn(std::move(value)); return *this;}
/**
* <p>The Sidewalk manufacturing series number.</p>
*/
inline SidewalkDevice& WithSidewalkManufacturingSn(const char* value) { SetSidewalkManufacturingSn(value); return *this;}
/**
* <p>The sidewalk device certificates for Ed25519 and P256r1.</p>
*/
inline const Aws::Vector<CertificateList>& GetDeviceCertificates() const{ return m_deviceCertificates; }
/**
* <p>The sidewalk device certificates for Ed25519 and P256r1.</p>
*/
inline bool DeviceCertificatesHasBeenSet() const { return m_deviceCertificatesHasBeenSet; }
/**
* <p>The sidewalk device certificates for Ed25519 and P256r1.</p>
*/
inline void SetDeviceCertificates(const Aws::Vector<CertificateList>& value) { m_deviceCertificatesHasBeenSet = true; m_deviceCertificates = value; }
/**
* <p>The sidewalk device certificates for Ed25519 and P256r1.</p>
*/
inline void SetDeviceCertificates(Aws::Vector<CertificateList>&& value) { m_deviceCertificatesHasBeenSet = true; m_deviceCertificates = std::move(value); }
/**
* <p>The sidewalk device certificates for Ed25519 and P256r1.</p>
*/
inline SidewalkDevice& WithDeviceCertificates(const Aws::Vector<CertificateList>& value) { SetDeviceCertificates(value); return *this;}
/**
* <p>The sidewalk device certificates for Ed25519 and P256r1.</p>
*/
inline SidewalkDevice& WithDeviceCertificates(Aws::Vector<CertificateList>&& value) { SetDeviceCertificates(std::move(value)); return *this;}
/**
* <p>The sidewalk device certificates for Ed25519 and P256r1.</p>
*/
inline SidewalkDevice& AddDeviceCertificates(const CertificateList& value) { m_deviceCertificatesHasBeenSet = true; m_deviceCertificates.push_back(value); return *this; }
/**
* <p>The sidewalk device certificates for Ed25519 and P256r1.</p>
*/
inline SidewalkDevice& AddDeviceCertificates(CertificateList&& value) { m_deviceCertificatesHasBeenSet = true; m_deviceCertificates.push_back(std::move(value)); return *this; }
private:
Aws::String m_sidewalkId;
bool m_sidewalkIdHasBeenSet;
Aws::String m_sidewalkManufacturingSn;
bool m_sidewalkManufacturingSnHasBeenSet;
Aws::Vector<CertificateList> m_deviceCertificates;
bool m_deviceCertificatesHasBeenSet;
};
} // namespace Model
} // namespace IoTWireless
} // namespace Aws
| [
"aws-sdk-cpp-automation@github.com"
] | aws-sdk-cpp-automation@github.com |
5f49a8e46c4b5b2dce3a01c3b86195f6dd577899 | 10d57ce051ca936f6822724a4e996d35f7cd269c | /ash/shelf/login_shelf_view.cc | 44b10082b681f684384627b1c3efbd5b2298bf00 | [
"BSD-3-Clause"
] | permissive | billti/chromium | aea73afa192266460538df692e80dd3f749d2751 | 94fde1ddc4a9db7488fd646443688a88c178c158 | refs/heads/master | 2023-02-02T05:00:23.474800 | 2020-09-24T16:57:28 | 2020-09-24T16:57:28 | 298,350,654 | 0 | 0 | BSD-3-Clause | 2020-09-24T17:37:58 | 2020-09-24T17:37:57 | null | UTF-8 | C++ | false | false | 34,399 | cc | // Copyright 2017 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.
#include "ash/shelf/login_shelf_view.h"
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include "ash/focus_cycler.h"
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "ash/lock_screen_action/lock_screen_action_background_state.h"
#include "ash/login/login_screen_controller.h"
#include "ash/login/ui/lock_screen.h"
#include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/login_accelerators.h"
#include "ash/public/cpp/login_constants.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_popup_utils.h"
#include "ash/wm/lock_state_controller.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/metrics/user_metrics.h"
#include "base/sequence_checker.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "skia/ext/image_operations.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/image_model.h"
#include "ui/base/models/menu_model.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icon_types.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/menu/menu_types.h"
#include "ui/views/focus/focus_search.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h"
using session_manager::SessionState;
namespace ash {
namespace {
const char* kLoginShelfButtonClassName = "LoginShelfButton";
SkColor GetButtonTextColor() {
return AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kButtonLabelColor);
}
SkColor GetButtonIconColor() {
return AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kButtonIconColor);
}
SkColor GetButtonBackgroundColor() {
if (Shell::Get()->session_controller()->GetSessionState() ==
session_manager::SessionState::OOBE) {
return SkColorSetA(SK_ColorBLACK, 16); // 6% opacity
}
return AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kControlBackgroundColorInactive);
}
LoginMetricsRecorder::ShelfButtonClickTarget GetUserClickTarget(int button_id) {
switch (button_id) {
case LoginShelfView::kShutdown:
return LoginMetricsRecorder::ShelfButtonClickTarget::kShutDownButton;
case LoginShelfView::kRestart:
return LoginMetricsRecorder::ShelfButtonClickTarget::kRestartButton;
case LoginShelfView::kSignOut:
return LoginMetricsRecorder::ShelfButtonClickTarget::kSignOutButton;
case LoginShelfView::kCloseNote:
return LoginMetricsRecorder::ShelfButtonClickTarget::kCloseNoteButton;
case LoginShelfView::kBrowseAsGuest:
return LoginMetricsRecorder::ShelfButtonClickTarget::kBrowseAsGuestButton;
case LoginShelfView::kAddUser:
return LoginMetricsRecorder::ShelfButtonClickTarget::kAddUserButton;
case LoginShelfView::kCancel:
return LoginMetricsRecorder::ShelfButtonClickTarget::kCancelButton;
case LoginShelfView::kParentAccess:
return LoginMetricsRecorder::ShelfButtonClickTarget::kParentAccessButton;
case LoginShelfView::kEnterpriseEnrollment:
return LoginMetricsRecorder::ShelfButtonClickTarget::
kEnterpriseEnrollmentButton;
}
return LoginMetricsRecorder::ShelfButtonClickTarget::kTargetCount;
}
// The margins of the button contents.
constexpr int kButtonMarginTopDp = 18;
constexpr int kButtonMarginLeftDp = 18;
constexpr int kButtonMarginBottomDp = 18;
constexpr int kButtonMarginRightDp = 16;
// Spacing between the button image and label.
constexpr int kImageLabelSpacingDp = 10;
// The color of the button text during OOBE.
constexpr SkColor kButtonTextColorOobe = gfx::kGoogleGrey700;
void AnimateButtonOpacity(ui::Layer* layer,
float target_opacity,
base::TimeDelta animation_duration,
gfx::Tween::Type type) {
ui::ScopedLayerAnimationSettings animation_setter(layer->GetAnimator());
animation_setter.SetTransitionDuration(animation_duration);
animation_setter.SetTweenType(type);
animation_setter.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
layer->SetOpacity(target_opacity);
}
// TODO(crbug.com/1051293): The highlight or ink drop will be incorrect if the
// values returned by |ShelfConfig| change midway.
gfx::Insets GetButtonInsets() {
const int height_inset =
(ShelfConfig::Get()->shelf_size() - ShelfConfig::Get()->control_size()) /
2;
return gfx::Insets(height_inset, ShelfConfig::Get()->button_spacing(),
height_inset, 0);
}
SkPath GetButtonHighlightPath(const views::View* view) {
gfx::Rect rect(view->GetLocalBounds());
rect.Inset(GetButtonInsets());
const int border_radius = ShelfConfig::Get()->control_border_radius();
return SkPath().addRoundRect(gfx::RectToSkRect(rect), border_radius,
border_radius);
}
class LoginShelfButton : public views::LabelButton {
public:
LoginShelfButton(views::ButtonListener* listener,
int text_resource_id,
const gfx::VectorIcon& icon)
: LabelButton(listener, l10n_util::GetStringUTF16(text_resource_id)),
text_resource_id_(text_resource_id),
icon_(icon) {
SetAccessibleName(GetText());
SkColor button_icon_color = GetButtonIconColor();
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(icon, button_icon_color));
SetImage(views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(
icon, SkColorSetA(button_icon_color,
login_constants::kButtonDisabledAlpha)));
SetFocusBehavior(FocusBehavior::ALWAYS);
SetInstallFocusRingOnFocus(true);
views::InstallRoundRectHighlightPathGenerator(
this, GetButtonInsets(), ShelfConfig::Get()->control_border_radius());
focus_ring()->SetColor(ShelfConfig::Get()->shelf_focus_border_color());
SetFocusPainter(nullptr);
SetInkDropMode(InkDropMode::ON);
SetHasInkDropActionOnClick(true);
AshColorProvider::RippleAttributes ripple_attributes =
ShelfConfig::Get()->GetInkDropRippleAttributes();
SetInkDropBaseColor(ripple_attributes.base_color);
SetInkDropVisibleOpacity(ripple_attributes.inkdrop_opacity);
// Layer rendering is required when the shelf background is visible, which
// happens when the wallpaper is not blurred.
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
SetTextSubpixelRenderingEnabled(false);
SetImageLabelSpacing(kImageLabelSpacingDp);
SkColor button_text_color = GetButtonTextColor();
SetEnabledTextColors(button_text_color);
SetTextColor(
views::Button::STATE_DISABLED,
SkColorSetA(button_text_color, login_constants::kButtonDisabledAlpha));
label()->SetFontList(views::Label::GetDefaultFontList().Derive(
1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::NORMAL));
}
~LoginShelfButton() override = default;
int text_resource_id() const { return text_resource_id_; }
// views::LabelButton:
gfx::Insets GetInsets() const override {
return gfx::Insets(0, kButtonMarginLeftDp, 0, kButtonMarginRightDp);
}
const char* GetClassName() const override {
return kLoginShelfButtonClassName;
}
void PaintButtonContents(gfx::Canvas* canvas) override {
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(GetButtonBackgroundColor());
flags.setStyle(cc::PaintFlags::kFill_Style);
canvas->DrawPath(GetButtonHighlightPath(this), flags);
}
std::unique_ptr<views::InkDrop> CreateInkDrop() override {
auto ink_drop = std::make_unique<views::InkDropImpl>(this, size());
ink_drop->SetShowHighlightOnHover(false);
ink_drop->SetShowHighlightOnFocus(false);
return ink_drop;
}
base::string16 GetTooltipText(const gfx::Point& p) const override {
if (label()->IsDisplayTextTruncated())
return label()->GetText();
return base::string16();
}
void PaintDarkColors() {
SetEnabledTextColors(kButtonTextColorOobe);
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(icon_, kButtonTextColorOobe));
SchedulePaint();
}
void PaintLightColors() {
SkColor button_text_color = GetButtonTextColor();
SetEnabledTextColors(button_text_color);
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(icon_, button_text_color));
SchedulePaint();
}
void OnFocus() override {
auto* const keyboard_controller = keyboard::KeyboardUIController::Get();
keyboard_controller->set_keyboard_locked(false /*lock*/);
keyboard_controller->HideKeyboardImplicitlyByUser();
}
private:
const int text_resource_id_;
const gfx::VectorIcon& icon_;
DISALLOW_COPY_AND_ASSIGN(LoginShelfButton);
};
void StartAddUser() {
Shell::Get()->login_screen_controller()->ShowGaiaSignin(
EmptyAccountId() /*prefilled_account*/);
}
bool DialogStateGuestAllowed(OobeDialogState state) {
return state == OobeDialogState::GAIA_SIGNIN ||
state == OobeDialogState::ERROR || state == OobeDialogState::HIDDEN ||
state == OobeDialogState::USER_CREATION;
}
bool ShutdownButtonHidden(OobeDialogState state) {
return state == OobeDialogState::MIGRATION ||
state == OobeDialogState::ENROLLMENT ||
state == OobeDialogState::ONBOARDING ||
state == OobeDialogState::KIOSK_LAUNCH ||
state == OobeDialogState::PASSWORD_CHANGED;
}
} // namespace
class KioskAppsButton : public views::MenuButton,
public views::ButtonListener,
public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate {
public:
KioskAppsButton()
: MenuButton(this, l10n_util::GetStringUTF16(IDS_ASH_SHELF_APPS_BUTTON)),
ui::SimpleMenuModel(this) {
SetFocusBehavior(FocusBehavior::ALWAYS);
SetInstallFocusRingOnFocus(true);
views::InstallRoundRectHighlightPathGenerator(
this, GetButtonInsets(), ShelfConfig::Get()->control_border_radius());
focus_ring()->SetColor(ShelfConfig::Get()->shelf_focus_border_color());
SetFocusPainter(nullptr);
SetInkDropMode(InkDropMode::ON);
SetHasInkDropActionOnClick(true);
AshColorProvider::RippleAttributes ripple_attributes =
ShelfConfig::Get()->GetInkDropRippleAttributes();
SetInkDropBaseColor(ripple_attributes.base_color);
SetInkDropVisibleOpacity(ripple_attributes.inkdrop_opacity);
// Layer rendering is required when the shelf background is visible, which
// happens when the wallpaper is not blurred.
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
SetTextSubpixelRenderingEnabled(false);
SetImage(views::Button::STATE_NORMAL,
CreateVectorIcon(kShelfAppsButtonIcon, GetButtonIconColor()));
SetImageLabelSpacing(kImageLabelSpacingDp);
SetEnabledTextColors(GetButtonTextColor());
label()->SetFontList(views::Label::GetDefaultFontList().Derive(
1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::NORMAL));
}
bool LaunchAppForTesting(const std::string& app_id) {
for (size_t i = 0; i < kiosk_apps_.size(); ++i) {
if (kiosk_apps_[i].app_id == app_id) {
ExecuteCommand(i, 0);
return true;
}
}
return false;
}
// Replace the existing items list with a new list of kiosk app menu items.
void SetApps(
const std::vector<KioskAppMenuEntry>& kiosk_apps,
const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
const base::RepeatingClosure& on_show_menu) {
launch_app_callback_ = launch_app;
on_show_menu_ = on_show_menu;
kiosk_apps_ = kiosk_apps;
Clear();
const gfx::Size kAppIconSize(16, 16);
for (size_t i = 0; i < kiosk_apps_.size(); ++i) {
gfx::ImageSkia icon = gfx::ImageSkiaOperations::CreateResizedImage(
kiosk_apps_[i].icon, skia::ImageOperations::RESIZE_GOOD,
kAppIconSize);
AddItemWithIcon(i, kiosk_apps_[i].name,
ui::ImageModel::FromImageSkia(icon));
}
// If the menu is being shown, update it.
if (menu_runner_ && menu_runner_->IsRunning()) {
DisplayMenu(this);
}
}
bool HasApps() const { return !kiosk_apps_.empty(); }
// views::MenuButton:
gfx::Insets GetInsets() const override {
return gfx::Insets(kButtonMarginTopDp, kButtonMarginLeftDp,
kButtonMarginBottomDp, kButtonMarginRightDp);
}
void PaintButtonContents(gfx::Canvas* canvas) override {
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(ShelfConfig::Get()->GetShelfControlButtonColor());
flags.setStyle(cc::PaintFlags::kFill_Style);
canvas->DrawPath(GetButtonHighlightPath(this), flags);
}
void SetVisible(bool visible) override {
MenuButton::SetVisible(visible);
if (visible)
is_launch_enabled_ = true;
}
std::unique_ptr<views::InkDrop> CreateInkDrop() override {
auto ink_drop = std::make_unique<views::InkDropImpl>(this, size());
ink_drop->SetShowHighlightOnHover(false);
ink_drop->SetShowHighlightOnFocus(false);
return ink_drop;
}
void PaintDarkColors() {
SetEnabledTextColors(kButtonTextColorOobe);
SetImage(views::Button::STATE_NORMAL,
CreateVectorIcon(kShelfAppsButtonIcon, kButtonTextColorOobe));
SchedulePaint();
}
void PaintLightColors() {
SetEnabledTextColors(GetButtonTextColor());
SetImage(views::Button::STATE_NORMAL,
CreateVectorIcon(kShelfAppsButtonIcon, GetButtonIconColor()));
SchedulePaint();
}
void DisplayMenu(Button* source) {
const gfx::Point point = source->GetMenuPosition();
const gfx::Point origin(point.x() - source->width(),
point.y() - source->height());
menu_runner_.reset(
new views::MenuRunner(this, views::MenuRunner::HAS_MNEMONICS));
menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(),
button_controller(), gfx::Rect(origin, gfx::Size()),
views::MenuAnchorPosition::kTopLeft,
ui::MENU_SOURCE_NONE);
}
// views::ButtonListener:
void ButtonPressed(Button* source, const ui::Event& event) override {
if (!is_launch_enabled_)
return;
DisplayMenu(source);
}
// ui::SimpleMenuModel:
void ExecuteCommand(int command_id, int event_flags) override {
DCHECK(command_id >= 0 &&
base::checked_cast<size_t>(command_id) < kiosk_apps_.size());
// Once an app is clicked on, don't allow any additional clicks until
// the state is reset (when login screen reappears).
is_launch_enabled_ = false;
launch_app_callback_.Run(kiosk_apps_[command_id]);
}
void OnMenuWillShow(SimpleMenuModel* source) override { on_show_menu_.Run(); }
bool IsCommandIdChecked(int command_id) const override { return false; }
bool IsCommandIdEnabled(int command_id) const override { return true; }
private:
base::RepeatingCallback<void(const KioskAppMenuEntry&)> launch_app_callback_;
base::RepeatingCallback<void()> on_show_menu_;
std::unique_ptr<views::MenuRunner> menu_runner_;
std::vector<KioskAppMenuEntry> kiosk_apps_;
bool is_launch_enabled_ = true;
DISALLOW_COPY_AND_ASSIGN(KioskAppsButton);
};
// Class that temporarily disables Guest login buttin on shelf.
class LoginShelfView::ScopedGuestButtonBlockerImpl
: public ScopedGuestButtonBlocker {
public:
ScopedGuestButtonBlockerImpl(base::WeakPtr<LoginShelfView> shelf_view)
: shelf_view_(shelf_view) {
++(shelf_view_->scoped_guest_button_blockers_);
if (shelf_view_->scoped_guest_button_blockers_ == 1)
shelf_view_->UpdateUi();
}
~ScopedGuestButtonBlockerImpl() override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!shelf_view_)
return;
DCHECK_GT(shelf_view_->scoped_guest_button_blockers_, 0);
--(shelf_view_->scoped_guest_button_blockers_);
if (!shelf_view_->scoped_guest_button_blockers_)
shelf_view_->UpdateUi();
}
private:
SEQUENCE_CHECKER(sequence_checker_);
// ScopedGuestButtonBlockerImpl is not owned by the LoginShelfView,
// so they could be independently destroyed.
base::WeakPtr<LoginShelfView> shelf_view_;
};
LoginShelfView::TestUiUpdateDelegate::~TestUiUpdateDelegate() = default;
LoginShelfView::LoginShelfView(
LockScreenActionBackgroundController* lock_screen_action_background)
: lock_screen_action_background_(lock_screen_action_background) {
// We reuse the focusable state on this view as a signal that focus should
// switch to the lock screen or status area. This view should otherwise not
// be focusable.
SetFocusBehavior(FocusBehavior::ALWAYS);
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal));
auto add_button = [this](ButtonId id, int text_resource_id,
const gfx::VectorIcon& icon) {
LoginShelfButton* button =
new LoginShelfButton(this, text_resource_id, icon);
button->SetID(id);
AddChildView(button);
};
add_button(kShutdown, IDS_ASH_SHELF_SHUTDOWN_BUTTON,
kShelfShutdownButtonIcon);
add_button(kRestart, IDS_ASH_SHELF_RESTART_BUTTON, kShelfShutdownButtonIcon);
add_button(kSignOut, IDS_ASH_SHELF_SIGN_OUT_BUTTON, kShelfSignOutButtonIcon);
kiosk_apps_button_ = new KioskAppsButton();
kiosk_apps_button_->SetID(kApps);
AddChildView(kiosk_apps_button_);
add_button(kCloseNote, IDS_ASH_SHELF_UNLOCK_BUTTON, kShelfUnlockButtonIcon);
add_button(kCancel, IDS_ASH_SHELF_CANCEL_BUTTON, kShelfCancelButtonIcon);
add_button(kBrowseAsGuest, IDS_ASH_BROWSE_AS_GUEST_BUTTON,
kShelfBrowseAsGuestButtonIcon);
add_button(kAddUser, IDS_ASH_ADD_USER_BUTTON, kShelfAddPersonButtonIcon);
add_button(kParentAccess, IDS_ASH_PARENT_ACCESS_BUTTON, kPinRequestLockIcon);
add_button(kEnterpriseEnrollment, IDS_ASH_ENTERPRISE_ENROLLMENT_BUTTON,
kLoginScreenEnterpriseIcon);
// Adds observers for states that affect the visiblity of different buttons.
tray_action_observer_.Add(Shell::Get()->tray_action());
shutdown_controller_observer_.Add(Shell::Get()->shutdown_controller());
lock_screen_action_background_observer_.Add(lock_screen_action_background);
login_data_dispatcher_observer_.Add(
Shell::Get()->login_screen_controller()->data_dispatcher());
UpdateUi();
}
LoginShelfView::~LoginShelfView() = default;
void LoginShelfView::UpdateAfterSessionChange() {
UpdateUi();
}
const char* LoginShelfView::GetClassName() const {
return "LoginShelfView";
}
void LoginShelfView::OnFocus() {
LOG(WARNING) << "LoginShelfView was focused, but this should never happen. "
"Forwarded focus to shelf widget with an unknown direction.";
Shell::Get()->focus_cycler()->FocusWidget(
Shelf::ForWindow(GetWidget()->GetNativeWindow())->shelf_widget());
}
void LoginShelfView::AboutToRequestFocusFromTabTraversal(bool reverse) {
if (reverse) {
// Focus should leave the system tray.
Shell::Get()->system_tray_notifier()->NotifyFocusOut(reverse);
} else {
// Focus goes to status area.
StatusAreaWidget* status_area_widget =
Shelf::ForWindow(GetWidget()->GetNativeWindow())->GetStatusAreaWidget();
status_area_widget->status_area_widget_delegate()
->set_default_last_focusable_child(reverse);
Shell::Get()->focus_cycler()->FocusWidget(status_area_widget);
}
}
void LoginShelfView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
if (LockScreen::HasInstance()) {
GetViewAccessibility().OverridePreviousFocus(LockScreen::Get()->widget());
}
Shelf* shelf = Shelf::ForWindow(GetWidget()->GetNativeWindow());
GetViewAccessibility().OverrideNextFocus(shelf->GetStatusAreaWidget());
node_data->role = ax::mojom::Role::kToolbar;
node_data->SetName(l10n_util::GetStringUTF8(IDS_ASH_SHELF_ACCESSIBLE_NAME));
}
void LoginShelfView::Layout() {
views::View::Layout();
UpdateButtonUnionBounds();
}
void LoginShelfView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
UserMetricsRecorder::RecordUserClickOnShelfButton(
GetUserClickTarget(sender->GetID()));
switch (sender->GetID()) {
case kShutdown:
case kRestart:
// |ShutdownController| will further distinguish the two cases based on
// shutdown policy.
Shell::Get()->lock_state_controller()->RequestShutdown(
ShutdownReason::LOGIN_SHUT_DOWN_BUTTON);
break;
case kSignOut:
base::RecordAction(base::UserMetricsAction("ScreenLocker_Signout"));
Shell::Get()->session_controller()->RequestSignOut();
break;
case kCloseNote:
Shell::Get()->tray_action()->CloseLockScreenNote(
mojom::CloseLockScreenNoteReason::kUnlockButtonPressed);
break;
case kCancel:
// If the Cancel button has focus, clear it. Otherwise the shelf within
// active session may still be focused.
GetFocusManager()->ClearFocus();
Shell::Get()->login_screen_controller()->CancelAddUser();
break;
case kBrowseAsGuest:
Shell::Get()->login_screen_controller()->LoginAsGuest();
break;
case kAddUser:
StartAddUser();
break;
case kParentAccess:
// TODO(https://crbug.com/999387): Remove this when handling touch
// cancellation is fixed for system modal windows.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce([]() {
LockScreen::Get()->ShowParentAccessDialog();
}));
break;
case kEnterpriseEnrollment:
Shell::Get()->login_screen_controller()->HandleAccelerator(
ash::LoginAcceleratorAction::kStartEnrollment);
break;
default:
NOTREACHED();
}
}
bool LoginShelfView::LaunchAppForTesting(const std::string& app_id) {
return kiosk_apps_button_->GetEnabled() &&
kiosk_apps_button_->LaunchAppForTesting(app_id);
}
bool LoginShelfView::SimulateButtonPressedForTesting(
LoginShelfView::ButtonId button_id) {
views::View* button = GetViewByID(button_id);
if (!button->GetEnabled())
return false;
ButtonPressed(static_cast<LoginShelfButton*>(button),
ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(),
gfx::PointF(), base::TimeTicks(), 0, 0));
return true;
}
void LoginShelfView::InstallTestUiUpdateDelegate(
std::unique_ptr<TestUiUpdateDelegate> delegate) {
DCHECK(!test_ui_update_delegate_.get());
test_ui_update_delegate_ = std::move(delegate);
}
void LoginShelfView::SetKioskApps(
const std::vector<KioskAppMenuEntry>& kiosk_apps,
const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
const base::RepeatingCallback<void()>& on_show_menu) {
kiosk_apps_button_->SetApps(kiosk_apps, launch_app, on_show_menu);
UpdateUi();
}
void LoginShelfView::SetLoginDialogState(OobeDialogState state) {
dialog_state_ = state;
UpdateUi();
}
void LoginShelfView::SetAllowLoginAsGuest(bool allow_guest) {
allow_guest_ = allow_guest;
UpdateUi();
}
void LoginShelfView::ShowParentAccessButton(bool show) {
show_parent_access_ = show;
UpdateUi();
}
void LoginShelfView::ShowGuestButtonInOobe(bool show) {
allow_guest_in_oobe_ = show;
UpdateUi();
}
void LoginShelfView::SetAddUserButtonEnabled(bool enable_add_user) {
GetViewByID(kAddUser)->SetEnabled(enable_add_user);
}
void LoginShelfView::SetShutdownButtonEnabled(bool enable_shutdown_button) {
GetViewByID(kShutdown)->SetEnabled(enable_shutdown_button);
}
void LoginShelfView::SetButtonOpacity(float target_opacity) {
static constexpr ButtonId kButtonIds[] = {
kShutdown,
kRestart,
kSignOut,
kCloseNote,
kCancel,
kParentAccess,
kBrowseAsGuest,
kAddUser,
kEnterpriseEnrollment
};
for (const auto& button_id : kButtonIds) {
AnimateButtonOpacity(GetViewByID(button_id)->layer(), target_opacity,
ShelfConfig::Get()->DimAnimationDuration(),
ShelfConfig::Get()->DimAnimationTween());
}
AnimateButtonOpacity(kiosk_apps_button_->layer(), target_opacity,
ShelfConfig::Get()->DimAnimationDuration(),
ShelfConfig::Get()->DimAnimationTween());
}
std::unique_ptr<ScopedGuestButtonBlocker>
LoginShelfView::GetScopedGuestButtonBlocker() {
return std::make_unique<LoginShelfView::ScopedGuestButtonBlockerImpl>(
weak_ptr_factory_.GetWeakPtr());
}
void LoginShelfView::OnLockScreenNoteStateChanged(
mojom::TrayActionState state) {
UpdateUi();
}
void LoginShelfView::OnLockScreenActionBackgroundStateChanged(
LockScreenActionBackgroundState state) {
UpdateUi();
}
void LoginShelfView::OnShutdownPolicyChanged(bool reboot_on_shutdown) {
UpdateUi();
}
void LoginShelfView::OnUsersChanged(const std::vector<LoginUserInfo>& users) {
login_screen_has_users_ = !users.empty();
UpdateUi();
}
void LoginShelfView::OnOobeDialogStateChanged(OobeDialogState state) {
SetLoginDialogState(state);
}
void LoginShelfView::HandleLocaleChange() {
for (views::View* child : children()) {
if (child->GetClassName() == kLoginShelfButtonClassName) {
auto* button = static_cast<LoginShelfButton*>(child);
button->SetText(l10n_util::GetStringUTF16(button->text_resource_id()));
button->SetAccessibleName(button->GetText());
}
}
}
bool LoginShelfView::LockScreenActionBackgroundAnimating() const {
return lock_screen_action_background_->state() ==
LockScreenActionBackgroundState::kShowing ||
lock_screen_action_background_->state() ==
LockScreenActionBackgroundState::kHiding;
}
void LoginShelfView::UpdateUi() {
// Make sure observers are notified.
base::ScopedClosureRunner fire_observer(base::BindOnce(
[](LoginShelfView* self) {
if (self->test_ui_update_delegate())
self->test_ui_update_delegate()->OnUiUpdate();
},
base::Unretained(this)));
SessionState session_state =
Shell::Get()->session_controller()->GetSessionState();
if (session_state == SessionState::ACTIVE) {
// The entire view was set invisible. The buttons are also set invisible
// to avoid affecting calculation of the shelf size.
for (auto* child : children())
child->SetVisible(false);
return;
}
bool show_reboot = Shell::Get()->shutdown_controller()->reboot_on_shutdown();
mojom::TrayActionState tray_action_state =
Shell::Get()->tray_action()->GetLockScreenNoteState();
bool is_locked = (session_state == SessionState::LOCKED);
bool is_lock_screen_note_in_foreground =
(tray_action_state == mojom::TrayActionState::kActive ||
tray_action_state == mojom::TrayActionState::kLaunching) &&
!LockScreenActionBackgroundAnimating();
GetViewByID(kShutdown)->SetVisible(!show_reboot &&
!is_lock_screen_note_in_foreground &&
!ShutdownButtonHidden(dialog_state_));
GetViewByID(kRestart)->SetVisible(show_reboot &&
!is_lock_screen_note_in_foreground &&
!ShutdownButtonHidden(dialog_state_));
GetViewByID(kSignOut)->SetVisible(is_locked &&
!is_lock_screen_note_in_foreground);
GetViewByID(kCloseNote)
->SetVisible(is_locked && is_lock_screen_note_in_foreground);
GetViewByID(kCancel)->SetVisible(session_state ==
SessionState::LOGIN_SECONDARY);
GetViewByID(kParentAccess)->SetVisible(is_locked && show_parent_access_);
bool is_login_primary = (session_state == SessionState::LOGIN_PRIMARY);
bool dialog_visible = dialog_state_ != OobeDialogState::HIDDEN;
bool is_oobe = (session_state == SessionState::OOBE);
GetViewByID(kBrowseAsGuest)->SetVisible(ShouldShowGuestButton());
GetViewByID(kEnterpriseEnrollment)
->SetVisible(ShouldShowEnterpriseEnrollmentButton());
// Show add user button when it's in login screen and Oobe UI dialog is not
// visible. The button should not appear if the device is not connected to a
// network.
GetViewByID(kAddUser)->SetVisible(!dialog_visible && is_login_primary);
// Show kiosk apps button if:
// 1. It's in login screen.
// 2. There are Kiosk apps available.
kiosk_apps_button_->SetVisible(kiosk_apps_button_->HasApps() &&
(is_login_primary || is_oobe));
// If there is no visible (and thus focusable) buttons, we shouldn't focus
// LoginShelfView. We update it here, so we don't need to check visibility
// every time we move focus to system tray.
bool is_anything_focusable = false;
for (auto* child : children()) {
if (child->IsFocusable()) {
is_anything_focusable = true;
break;
}
}
SetFocusBehavior(is_anything_focusable ? views::View::FocusBehavior::ALWAYS
: views::View::FocusBehavior::NEVER);
UpdateButtonColors(is_oobe);
Layout();
}
void LoginShelfView::UpdateButtonColors(bool use_dark_colors) {
if (use_dark_colors) {
static_cast<LoginShelfButton*>(GetViewByID(kShutdown))->PaintDarkColors();
static_cast<LoginShelfButton*>(GetViewByID(kRestart))->PaintDarkColors();
static_cast<LoginShelfButton*>(GetViewByID(kSignOut))->PaintDarkColors();
static_cast<LoginShelfButton*>(GetViewByID(kCloseNote))->PaintDarkColors();
static_cast<LoginShelfButton*>(GetViewByID(kCancel))->PaintDarkColors();
static_cast<LoginShelfButton*>(GetViewByID(kParentAccess))
->PaintDarkColors();
static_cast<LoginShelfButton*>(GetViewByID(kBrowseAsGuest))
->PaintDarkColors();
static_cast<LoginShelfButton*>(GetViewByID(kAddUser))->PaintDarkColors();
static_cast<LoginShelfButton*>(GetViewByID(kEnterpriseEnrollment))
->PaintDarkColors();
kiosk_apps_button_->PaintDarkColors();
} else {
static_cast<LoginShelfButton*>(GetViewByID(kShutdown))->PaintLightColors();
static_cast<LoginShelfButton*>(GetViewByID(kRestart))->PaintLightColors();
static_cast<LoginShelfButton*>(GetViewByID(kSignOut))->PaintLightColors();
static_cast<LoginShelfButton*>(GetViewByID(kCloseNote))->PaintLightColors();
static_cast<LoginShelfButton*>(GetViewByID(kCancel))->PaintLightColors();
static_cast<LoginShelfButton*>(GetViewByID(kParentAccess))
->PaintLightColors();
static_cast<LoginShelfButton*>(GetViewByID(kBrowseAsGuest))
->PaintLightColors();
static_cast<LoginShelfButton*>(GetViewByID(kAddUser))->PaintLightColors();
static_cast<LoginShelfButton*>(GetViewByID(kEnterpriseEnrollment))
->PaintLightColors();
kiosk_apps_button_->PaintLightColors();
}
}
void LoginShelfView::UpdateButtonUnionBounds() {
button_union_bounds_ = gfx::Rect();
View::Views children = GetChildrenInZOrder();
for (auto* child : children) {
if (child->GetVisible())
button_union_bounds_.Union(child->bounds());
}
}
// Show guest button if:
// 1. Guest login is allowed.
// 2. OOBE UI dialog is currently showing the login UI or error.
// 3. No users sessions have started. Button is hidden from all post login
// screens like sync consent, etc.
// 4. It's in login screen or OOBE. Note: In OOBE, the guest button visibility
// is manually controlled by the WebUI.
// 5. OOBE UI dialog is not currently showing gaia signin screen, or if there
// are no user views available. If there are no user pods (i.e. Gaia is the
// only signin option), the guest button should be shown if allowed by policy
// and OOBE.
// 6. There are no scoped guest buttons blockers active.
bool LoginShelfView::ShouldShowGuestButton() const {
if (!allow_guest_)
return false;
if (scoped_guest_button_blockers_ > 0)
return false;
if (!DialogStateGuestAllowed(dialog_state_))
return false;
const bool user_session_started =
Shell::Get()->session_controller()->NumberOfLoggedInUsers() != 0;
if (user_session_started)
return false;
const SessionState session_state =
Shell::Get()->session_controller()->GetSessionState();
if (session_state == SessionState::OOBE)
return allow_guest_in_oobe_;
if (session_state != SessionState::LOGIN_PRIMARY)
return false;
if (dialog_state_ == OobeDialogState::USER_CREATION ||
dialog_state_ == OobeDialogState::GAIA_SIGNIN)
return !login_screen_has_users_ && allow_guest_in_oobe_;
return true;
}
bool LoginShelfView::ShouldShowEnterpriseEnrollmentButton() const {
const SessionState session_state =
Shell::Get()->session_controller()->GetSessionState();
return session_state == SessionState::OOBE &&
dialog_state_ == OobeDialogState::USER_CREATION;
}
} // namespace ash
| [
"commit-bot@chromium.org"
] | commit-bot@chromium.org |
aee6b02c401f01084e2be746ec2dbee39333d264 | 424d9d65e27cd204cc22e39da3a13710b163f4e7 | /ash/system/unified/feature_pod_button.cc | a2dba2594c47d2319f42a7f48f63a0d56231dd87 | [
"BSD-3-Clause"
] | permissive | bigben0123/chromium | 7c5f4624ef2dacfaf010203b60f307d4b8e8e76d | 83d9cd5e98b65686d06368f18b4835adbab76d89 | refs/heads/master | 2023-01-10T11:02:26.202776 | 2020-10-30T09:47:16 | 2020-10-30T09:47:16 | 275,543,782 | 0 | 0 | BSD-3-Clause | 2020-10-30T09:47:18 | 2020-06-28T08:45:11 | null | UTF-8 | C++ | false | false | 15,162 | cc | // Copyright 2018 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.
#include "ash/system/unified/feature_pod_button.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/system/tray/tray_popup_utils.h"
#include "ash/system/unified/feature_pod_controller_base.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/border.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/view_class_properties.h"
namespace ash {
using ContentLayerType = AshColorProvider::ContentLayerType;
using ControlsLayerType = AshColorProvider::ControlsLayerType;
namespace {
void ConfigureFeaturePodLabel(views::Label* label,
int line_height,
int font_size) {
label->SetAutoColorReadabilityEnabled(false);
label->SetSubpixelRenderingEnabled(false);
label->SetCanProcessEventsWithinSubtree(false);
label->SetLineHeight(line_height);
gfx::Font default_font;
gfx::Font label_font =
default_font.Derive(font_size - default_font.GetFontSize(),
gfx::Font::NORMAL, gfx::Font::Weight::NORMAL);
gfx::FontList font_list(label_font);
label->SetFontList(font_list);
}
} // namespace
FeaturePodIconButton::FeaturePodIconButton(PressedCallback callback,
bool is_togglable)
: views::ImageButton(std::move(callback)), is_togglable_(is_togglable) {
SetPreferredSize(kUnifiedFeaturePodIconSize);
SetBorder(views::CreateEmptyBorder(kUnifiedFeaturePodIconPadding));
SetImageHorizontalAlignment(ALIGN_CENTER);
SetImageVerticalAlignment(ALIGN_MIDDLE);
GetViewAccessibility().OverrideIsLeaf(true);
// Focus ring is around the whole view's bounds, but the ink drop should be
// the same size as the content.
TrayPopupUtils::ConfigureTrayPopupButton(this);
focus_ring()->SetPathGenerator(
std::make_unique<views::CircleHighlightPathGenerator>(gfx::Insets()));
views::InstallCircleHighlightPathGenerator(this,
kUnifiedFeaturePodIconPadding);
}
FeaturePodIconButton::FeaturePodIconButton(views::ButtonListener* listener,
bool is_togglable)
: FeaturePodIconButton(PressedCallback(listener, this), is_togglable) {}
FeaturePodIconButton::~FeaturePodIconButton() = default;
void FeaturePodIconButton::SetToggled(bool toggled) {
if (!is_togglable_ || toggled_ == toggled)
return;
toggled_ = toggled;
UpdateVectorIcon();
}
void FeaturePodIconButton::SetVectorIcon(const gfx::VectorIcon& icon) {
icon_ = &icon;
UpdateVectorIcon();
}
void FeaturePodIconButton::PaintButtonContents(gfx::Canvas* canvas) {
gfx::Rect rect(GetContentsBounds());
cc::PaintFlags flags;
flags.setAntiAlias(true);
const AshColorProvider* color_provider = AshColorProvider::Get();
SkColor color = color_provider->GetControlsLayerColor(
ControlsLayerType::kControlBackgroundColorInactive);
if (GetEnabled()) {
if (toggled_) {
color = color_provider->GetControlsLayerColor(
ControlsLayerType::kControlBackgroundColorActive);
}
} else {
color = AshColorProvider::GetDisabledColor(color);
}
flags.setColor(color);
flags.setStyle(cc::PaintFlags::kFill_Style);
canvas->DrawCircle(gfx::PointF(rect.CenterPoint()), rect.width() / 2, flags);
views::ImageButton::PaintButtonContents(canvas);
}
std::unique_ptr<views::InkDrop> FeaturePodIconButton::CreateInkDrop() {
return TrayPopupUtils::CreateInkDrop(this);
}
std::unique_ptr<views::InkDropRipple>
FeaturePodIconButton::CreateInkDropRipple() const {
return TrayPopupUtils::CreateInkDropRipple(
TrayPopupInkDropStyle::FILL_BOUNDS, this,
GetInkDropCenterBasedOnLastEvent());
}
std::unique_ptr<views::InkDropHighlight>
FeaturePodIconButton::CreateInkDropHighlight() const {
return TrayPopupUtils::CreateInkDropHighlight(this);
}
void FeaturePodIconButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
ImageButton::GetAccessibleNodeData(node_data);
node_data->SetName(GetTooltipText(gfx::Point()));
if (is_togglable_) {
node_data->role = ax::mojom::Role::kToggleButton;
node_data->SetCheckedState(toggled_ ? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kFalse);
} else {
node_data->role = ax::mojom::Role::kButton;
}
}
const char* FeaturePodIconButton::GetClassName() const {
return "FeaturePodIconButton";
}
void FeaturePodIconButton::OnThemeChanged() {
views::ImageButton::OnThemeChanged();
focus_ring()->SetColor(AshColorProvider::Get()->GetControlsLayerColor(
ControlsLayerType::kFocusRingColor));
UpdateVectorIcon();
SchedulePaint();
}
void FeaturePodIconButton::UpdateVectorIcon() {
if (!icon_)
return;
AshColorProvider::Get()->DecorateIconButton(this, *icon_, toggled_,
kUnifiedFeaturePodVectorIconSize);
}
FeaturePodLabelButton::FeaturePodLabelButton(PressedCallback callback)
: Button(std::move(callback)),
label_(new views::Label),
sub_label_(new views::Label),
detailed_view_arrow_(new views::ImageView) {
SetBorder(views::CreateEmptyBorder(kUnifiedFeaturePodHoverPadding));
GetViewAccessibility().OverrideIsLeaf(true);
label_->SetLineHeight(kUnifiedFeaturePodLabelLineHeight);
ConfigureFeaturePodLabel(label_, kUnifiedFeaturePodLabelLineHeight,
kUnifiedFeaturePodLabelFontSize);
ConfigureFeaturePodLabel(sub_label_, kUnifiedFeaturePodSubLabelLineHeight,
kUnifiedFeaturePodSubLabelFontSize);
sub_label_->SetVisible(false);
detailed_view_arrow_->SetCanProcessEventsWithinSubtree(false);
detailed_view_arrow_->SetVisible(false);
AddChildView(label_);
AddChildView(detailed_view_arrow_);
AddChildView(sub_label_);
TrayPopupUtils::ConfigureTrayPopupButton(this);
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
focus_ring()->SetColor(AshColorProvider::Get()->GetControlsLayerColor(
ControlsLayerType::kFocusRingColor));
views::InstallRoundRectHighlightPathGenerator(
this, gfx::Insets(), kUnifiedFeaturePodHoverCornerRadius);
}
FeaturePodLabelButton::~FeaturePodLabelButton() = default;
void FeaturePodLabelButton::Layout() {
DCHECK(focus_ring());
focus_ring()->Layout();
LayoutInCenter(label_, GetContentsBounds().y());
LayoutInCenter(sub_label_, GetContentsBounds().CenterPoint().y() +
kUnifiedFeaturePodInterLabelPadding);
if (!detailed_view_arrow_->GetVisible())
return;
// We need custom Layout() because |label_| is first laid out in the center
// without considering |detailed_view_arrow_|, then |detailed_view_arrow_| is
// placed on the right side of |label_|.
gfx::Size arrow_size = detailed_view_arrow_->GetPreferredSize();
detailed_view_arrow_->SetBoundsRect(gfx::Rect(
gfx::Point(label_->bounds().right() + kUnifiedFeaturePodArrowSpacing,
label_->bounds().CenterPoint().y() - arrow_size.height() / 2),
arrow_size));
}
gfx::Size FeaturePodLabelButton::CalculatePreferredSize() const {
// Minimum width of the button
int width = kUnifiedFeaturePodLabelWidth + GetInsets().width();
if (detailed_view_arrow_->GetVisible()) {
const int label_width = std::min(kUnifiedFeaturePodLabelWidth,
label_->GetPreferredSize().width());
// Symmetrically increase the width to accommodate the arrow
const int extra_space_for_arrow =
2 * (kUnifiedFeaturePodArrowSpacing +
detailed_view_arrow_->GetPreferredSize().width());
width = std::max(width,
label_width + extra_space_for_arrow + GetInsets().width());
}
// Make sure there is sufficient margin around the label.
int horizontal_margin = width - label_->GetPreferredSize().width();
if (horizontal_margin < 2 * kUnifiedFeaturePodMinimumHorizontalMargin)
width += 2 * kUnifiedFeaturePodMinimumHorizontalMargin - horizontal_margin;
int height = label_->GetPreferredSize().height() + GetInsets().height();
if (sub_label_->GetVisible()) {
height += kUnifiedFeaturePodInterLabelPadding +
sub_label_->GetPreferredSize().height();
}
return gfx::Size(width, height);
}
std::unique_ptr<views::InkDrop> FeaturePodLabelButton::CreateInkDrop() {
auto ink_drop = TrayPopupUtils::CreateInkDrop(this);
ink_drop->SetShowHighlightOnHover(true);
return ink_drop;
}
std::unique_ptr<views::InkDropRipple>
FeaturePodLabelButton::CreateInkDropRipple() const {
return TrayPopupUtils::CreateInkDropRipple(
TrayPopupInkDropStyle::FILL_BOUNDS, this,
GetInkDropCenterBasedOnLastEvent());
}
std::unique_ptr<views::InkDropHighlight>
FeaturePodLabelButton::CreateInkDropHighlight() const {
return TrayPopupUtils::CreateInkDropHighlight(this);
}
const char* FeaturePodLabelButton::GetClassName() const {
return "FeaturePodLabelButton";
}
void FeaturePodLabelButton::OnThemeChanged() {
views::Button::OnThemeChanged();
OnEnabledChanged();
}
void FeaturePodLabelButton::SetLabel(const base::string16& label) {
label_->SetText(label);
InvalidateLayout();
}
const base::string16& FeaturePodLabelButton::GetLabelText() const {
return label_->GetText();
}
void FeaturePodLabelButton::SetSubLabel(const base::string16& sub_label) {
sub_label_->SetText(sub_label);
sub_label_->SetVisible(true);
InvalidateLayout();
}
const base::string16& FeaturePodLabelButton::GetSubLabelText() const {
return sub_label_->GetText();
}
void FeaturePodLabelButton::ShowDetailedViewArrow() {
detailed_view_arrow_->SetVisible(true);
InvalidateLayout();
}
void FeaturePodLabelButton::OnEnabledChanged() {
const AshColorProvider* color_provider = AshColorProvider::Get();
const SkColor primary_text_color =
color_provider->GetContentLayerColor(ContentLayerType::kTextColorPrimary);
const SkColor secondary_text_color = color_provider->GetContentLayerColor(
ContentLayerType::kTextColorSecondary);
label_->SetEnabledColor(
GetEnabled() ? primary_text_color
: AshColorProvider::GetDisabledColor(primary_text_color));
sub_label_->SetEnabledColor(
GetEnabled() ? secondary_text_color
: AshColorProvider::GetDisabledColor(secondary_text_color));
const SkColor icon_color =
color_provider->GetContentLayerColor(ContentLayerType::kIconColorPrimary);
detailed_view_arrow_->SetImage(gfx::CreateVectorIcon(
kUnifiedMenuMoreIcon,
GetEnabled() ? icon_color
: AshColorProvider::GetDisabledColor(icon_color)));
}
void FeaturePodLabelButton::LayoutInCenter(views::View* child, int y) {
gfx::Rect contents_bounds = GetContentsBounds();
gfx::Size preferred_size = child->GetPreferredSize();
int child_width =
std::min(kUnifiedFeaturePodLabelWidth, preferred_size.width());
child->SetBounds(
contents_bounds.x() + (contents_bounds.width() - child_width) / 2, y,
child_width, preferred_size.height());
}
FeaturePodButton::FeaturePodButton(FeaturePodControllerBase* controller,
bool is_togglable)
: icon_button_(new FeaturePodIconButton(
base::BindRepeating(&FeaturePodControllerBase::OnIconPressed,
base::Unretained(controller)),
is_togglable)),
label_button_(new FeaturePodLabelButton(
base::BindRepeating(&FeaturePodControllerBase::OnLabelPressed,
base::Unretained(controller)))) {
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(),
kUnifiedFeaturePodSpacing));
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
AddChildView(icon_button_);
AddChildView(label_button_);
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
}
FeaturePodButton::~FeaturePodButton() = default;
double FeaturePodButton::GetOpacityForExpandedAmount(double expanded_amount) {
// TODO(amehfooz): Confirm the animation curve with UX.
return std::max(0., 5. * expanded_amount - 4.);
}
void FeaturePodButton::SetVectorIcon(const gfx::VectorIcon& icon) {
icon_button_->SetVectorIcon(icon);
}
void FeaturePodButton::SetLabel(const base::string16& label) {
if (label_button_->GetLabelText() == label)
return;
label_button_->SetLabel(label);
Layout();
label_button_->SchedulePaint();
}
void FeaturePodButton::SetSubLabel(const base::string16& sub_label) {
if (label_button_->GetSubLabelText() == sub_label)
return;
label_button_->SetSubLabel(sub_label);
Layout();
label_button_->SchedulePaint();
}
void FeaturePodButton::SetIconTooltip(const base::string16& text) {
icon_button_->SetTooltipText(text);
}
void FeaturePodButton::SetLabelTooltip(const base::string16& text) {
label_button_->SetTooltipText(text);
}
void FeaturePodButton::SetIconAndLabelTooltips(const base::string16& text) {
SetIconTooltip(text);
SetLabelTooltip(text);
}
void FeaturePodButton::ShowDetailedViewArrow() {
label_button_->ShowDetailedViewArrow();
Layout();
label_button_->SchedulePaint();
}
void FeaturePodButton::DisableLabelButtonFocus() {
label_button_->SetFocusBehavior(FocusBehavior::NEVER);
}
void FeaturePodButton::SetToggled(bool toggled) {
icon_button_->SetToggled(toggled);
}
void FeaturePodButton::SetExpandedAmount(double expanded_amount,
bool fade_icon_button) {
label_button_->SetVisible(expanded_amount > 0.0);
label_button_->layer()->SetOpacity(
GetOpacityForExpandedAmount(expanded_amount));
if (fade_icon_button)
layer()->SetOpacity(GetOpacityForExpandedAmount(expanded_amount));
else
layer()->SetOpacity(1.0);
}
void FeaturePodButton::SetVisibleByContainer(bool visible) {
View::SetVisible(visible);
}
void FeaturePodButton::SetVisible(bool visible) {
visible_preferred_ = visible;
View::SetVisible(visible);
}
bool FeaturePodButton::HasFocus() const {
return icon_button_->HasFocus() || label_button_->HasFocus();
}
void FeaturePodButton::RequestFocus() {
label_button_->RequestFocus();
}
const char* FeaturePodButton::GetClassName() const {
return "FeaturePodButton";
}
void FeaturePodButton::OnEnabledChanged() {
icon_button_->SetEnabled(GetEnabled());
label_button_->SetEnabled(GetEnabled());
}
} // namespace ash
| [
"commit-bot@chromium.org"
] | commit-bot@chromium.org |
b8b4b676f8624eb7899169865636b169c0383892 | ef284a36d7ec9474e462cdb82d80dc705a83379a | /src/alert.cpp | fbf2ae9296d2d69faaa88da32b61a09968c8c5c4 | [
"MIT"
] | permissive | bctscoin/SHOP | 4cb32c1e888bcab360695b710a2776ac61875a4e | 94715c1167d4711affddcc1a9a32dd944f7e47e5 | refs/heads/master | 2020-04-27T09:01:22.062069 | 2014-05-28T19:54:24 | 2014-05-28T19:54:24 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,011 | cpp | //
// Alert system
//
#include <algorithm>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/foreach.hpp>
#include <map>
#include "alert.h"
#include "key.h"
#include "net.h"
#include "sync.h"
#include "ui_interface.h"
using namespace std;
map<uint256, CAlert> mapAlerts;
CCriticalSection cs_mapAlerts;
static const char* pszMainKey = "04d118553268ce85f98515a760e0b7093cc09655e3b83279a84e17cad62b45c79aebed70d27175afcb6c1d942417b18c1d0f232bde5074aef88fe7a558e8fa703b";
// TestNet alerts pubKey
static const char* pszTestKey = "04547b5476f132a6139c201d1b05eccc7148bdba82e9643dc3b03efc3e947722b9360658361eed18e1ebcdff231b60317a708b1fa62045c116f77f4b063ca14505";
void CUnsignedAlert::SetNull()
{
nVersion = 1;
nRelayUntil = 0;
nExpiration = 0;
nID = 0;
nCancel = 0;
setCancel.clear();
nMinVer = 0;
nMaxVer = 0;
setSubVer.clear();
nPriority = 0;
strComment.clear();
strStatusBar.clear();
strReserved.clear();
}
std::string CUnsignedAlert::ToString() const
{
std::string strSetCancel;
BOOST_FOREACH(int n, setCancel)
strSetCancel += strprintf("%d ", n);
std::string strSetSubVer;
BOOST_FOREACH(std::string str, setSubVer)
strSetSubVer += "\"" + str + "\" ";
return strprintf(
"CAlert(\n"
" nVersion = %d\n"
" nRelayUntil = %"PRId64"\n"
" nExpiration = %"PRId64"\n"
" nID = %d\n"
" nCancel = %d\n"
" setCancel = %s\n"
" nMinVer = %d\n"
" nMaxVer = %d\n"
" setSubVer = %s\n"
" nPriority = %d\n"
" strComment = \"%s\"\n"
" strStatusBar = \"%s\"\n"
")\n",
nVersion,
nRelayUntil,
nExpiration,
nID,
nCancel,
strSetCancel.c_str(),
nMinVer,
nMaxVer,
strSetSubVer.c_str(),
nPriority,
strComment.c_str(),
strStatusBar.c_str());
}
void CUnsignedAlert::print() const
{
printf("%s", ToString().c_str());
}
void CAlert::SetNull()
{
CUnsignedAlert::SetNull();
vchMsg.clear();
vchSig.clear();
}
bool CAlert::IsNull() const
{
return (nExpiration == 0);
}
uint256 CAlert::GetHash() const
{
return Hash(this->vchMsg.begin(), this->vchMsg.end());
}
bool CAlert::IsInEffect() const
{
return (GetAdjustedTime() < nExpiration);
}
bool CAlert::Cancels(const CAlert& alert) const
{
if (!IsInEffect())
return false; // this was a no-op before 31403
return (alert.nID <= nCancel || setCancel.count(alert.nID));
}
bool CAlert::AppliesTo(int nVersion, std::string strSubVerIn) const
{
// TODO: rework for client-version-embedded-in-strSubVer ?
return (IsInEffect() &&
nMinVer <= nVersion && nVersion <= nMaxVer &&
(setSubVer.empty() || setSubVer.count(strSubVerIn)));
}
bool CAlert::AppliesToMe() const
{
return AppliesTo(PROTOCOL_VERSION, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<std::string>()));
}
bool CAlert::RelayTo(CNode* pnode) const
{
if (!IsInEffect())
return false;
// returns true if wasn't already contained in the set
if (pnode->setKnown.insert(GetHash()).second)
{
if (AppliesTo(pnode->nVersion, pnode->strSubVer) ||
AppliesToMe() ||
GetAdjustedTime() < nRelayUntil)
{
pnode->PushMessage("alert", *this);
return true;
}
}
return false;
}
bool CAlert::CheckSignature() const
{
CKey key;
if (!key.SetPubKey(ParseHex(fTestNet ? pszTestKey : pszMainKey)))
return error("CAlert::CheckSignature() : SetPubKey failed");
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
return error("CAlert::CheckSignature() : verify signature failed");
// Now unserialize the data
CDataStream sMsg(vchMsg, SER_NETWORK, PROTOCOL_VERSION);
sMsg >> *(CUnsignedAlert*)this;
return true;
}
CAlert CAlert::getAlertByHash(const uint256 &hash)
{
CAlert retval;
{
LOCK(cs_mapAlerts);
map<uint256, CAlert>::iterator mi = mapAlerts.find(hash);
if(mi != mapAlerts.end())
retval = mi->second;
}
return retval;
}
bool CAlert::ProcessAlert(bool fThread)
{
if (!CheckSignature())
return false;
if (!IsInEffect())
return false;
// alert.nID=max is reserved for if the alert key is
// compromised. It must have a pre-defined message,
// must never expire, must apply to all versions,
// and must cancel all previous
// alerts or it will be ignored (so an attacker can't
// send an "everything is OK, don't panic" version that
// cannot be overridden):
int maxInt = std::numeric_limits<int>::max();
if (nID == maxInt)
{
if (!(
nExpiration == maxInt &&
nCancel == (maxInt-1) &&
nMinVer == 0 &&
nMaxVer == maxInt &&
setSubVer.empty() &&
nPriority == maxInt &&
strStatusBar == "URGENT: Alert key compromised, upgrade required"
))
return false;
}
{
LOCK(cs_mapAlerts);
// Cancel previous alerts
for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
{
const CAlert& alert = (*mi).second;
if (Cancels(alert))
{
printf("cancelling alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else if (!alert.IsInEffect())
{
printf("expiring alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else
mi++;
}
// Check if this alert has been cancelled
BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts)
{
const CAlert& alert = item.second;
if (alert.Cancels(*this))
{
printf("alert already cancelled by %d\n", alert.nID);
return false;
}
}
// Add to mapAlerts
mapAlerts.insert(make_pair(GetHash(), *this));
// Notify UI and -alertnotify if it applies to me
if(AppliesToMe())
{
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
std::string strCmd = GetArg("-alertnotify", "");
if (!strCmd.empty())
{
// Alert text should be plain ascii coming from a trusted source, but to
// be safe we first strip anything not in safeChars, then add single quotes around
// the whole string before passing it to the shell:
std::string singleQuote("'");
// safeChars chosen to allow simple messages/URLs/email addresses, but avoid anything
// even possibly remotely dangerous like & or >
std::string safeChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 .,;_/:?@");
std::string safeStatus;
for (std::string::size_type i = 0; i < strStatusBar.size(); i++)
{
if (safeChars.find(strStatusBar[i]) != std::string::npos)
safeStatus.push_back(strStatusBar[i]);
}
safeStatus = singleQuote+safeStatus+singleQuote;
boost::replace_all(strCmd, "%s", safeStatus);
if (fThread)
boost::thread t(runCommand, strCmd); // thread runs free
else
runCommand(strCmd);
}
}
}
printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
return true;
}
| [
"josh.eaker@gmail.com"
] | josh.eaker@gmail.com |
826591d5a3ff3b4fcb77b06f0e23eabc235dd3ce | 7e5be101928eb7ea43bc1a335d3475536f8a5bb2 | /2016 Training/10.1 (弱校联萌)/Taiwan2016/J.cpp | b94cdaa3700d972251c230b5462718c50366ceef | [] | no_license | TaoSama/ICPC-Code-Library | f94d4df0786a8a1c175da02de0a3033f9bd103ec | ec80ec66a94a5ea1d560c54fe08be0ecfcfc025e | refs/heads/master | 2020-04-04T06:19:21.023777 | 2018-11-05T18:22:32 | 2018-11-05T18:22:32 | 54,618,194 | 0 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 1,525 | cpp | //
// Created by TaoSama on 2016-10-05
// Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
const int N = 2e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n;
int a[N], b[N], c[N];
int pa[N], pb[N];
int main() {
#ifdef LOCAL
freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d", a + i);
pa[a[i]] = i;
}
for(int i = 0; i < n; ++i) {
scanf("%d", b + i);
pb[b[i]] = i;
}
int filled = 0;
memset(c, -1, sizeof c);
for(int d = 2 * n - 1; filled != n; --d) {
for(int i = n - 1; ~i; --i) {
int j = d - i;
if(j < 0) continue;
if(j >= n) break;
int x = pa[i], y = pb[j];
if(c[(x + y) % n] == -1) {
c[(x + y) % n] = d;
if(++filled == n) break;
}
}
}
for(int i = 0; i < n; ++i)
printf("%d%c", c[i], " \n"[i + 1 == n]);
return 0;
}
| [
"lwt1367@gmail.com"
] | lwt1367@gmail.com |
b4754606a78b64cb9eb20e0425b0a2640fb142fa | 501feca3b6f4ea1e21f97103deea006d16c5cf1b | /pluginapp/dependence/halcon/include/halconcpp/HSystem.h | 6b5bc5b51eccf9e0e1a9f0708d687b40f16b8f25 | [] | no_license | wondron/frameTest | 86b35b403ed46f27a7308e109a23f7a79f61080a | 4b3471493965eabaabfd1212df1ec4cd9d2a77a4 | refs/heads/master | 2023-06-06T11:57:19.632024 | 2021-06-25T14:25:18 | 2021-06-25T14:25:18 | 358,648,156 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 7,928 | h | /***********************************************************
* File generated by the HALCON-Compiler hcomp version 18.05
* Usage: Interface to C++
*
* Software by: MVTec Software GmbH, www.mvtec.com
***********************************************************/
#ifndef HCPP_HSYSTEM
#define HCPP_HSYSTEM
namespace HalconCpp
{
// Class grouping system information and manipulation related functionality.
class LIntExport HSystem
{
public:
/***************************************************************************
* Operators *
***************************************************************************/
// Delaying the execution of the program.
static void WaitSeconds(double Seconds);
// Execute a system command.
static void SystemCall(const HString& Command);
// Execute a system command.
static void SystemCall(const char* Command);
// Set HALCON system parameters.
static void SetSystem(const HTuple& SystemParameter, const HTuple& Value);
// Set HALCON system parameters.
static void SetSystem(const HString& SystemParameter, const HString& Value);
// Set HALCON system parameters.
static void SetSystem(const char* SystemParameter, const char* Value);
// Activating and deactivating of HALCON control modes.
static void SetCheck(const HTuple& Check);
// Activating and deactivating of HALCON control modes.
static void SetCheck(const HString& Check);
// Activating and deactivating of HALCON control modes.
static void SetCheck(const char* Check);
// Initialization of the HALCON system.
static void ResetObjDb(Hlong DefaultImageWidth, Hlong DefaultImageHeight, Hlong DefaultChannels);
// Get current value of HALCON system parameters.
static HTuple GetSystem(const HTuple& Query);
// Get current value of HALCON system parameters.
static HTuple GetSystem(const HString& Query);
// Get current value of HALCON system parameters.
static HTuple GetSystem(const char* Query);
// State of the HALCON control modes.
static HTuple GetCheck();
// Inquiry after the error text of a HALCON error number.
static HString GetErrorText(Hlong ErrorCode);
// Passed Time.
static double CountSeconds();
// Number of entries in the HALCON database.
static Hlong CountRelation(const HString& RelationName);
// Number of entries in the HALCON database.
static Hlong CountRelation(const char* RelationName);
// Returns the extended error information for the calling thread's last HALCON error.
static HString GetExtendedErrorInfo(Hlong* ErrorCode, HString* ErrorMessage);
// Query of used modules and the module key.
static HTuple GetModules(Hlong* ModuleKey);
// Inquiring for possible settings of the HALCON debugging tool.
static HTuple QuerySpy(HTuple* Values);
// Control of the HALCON Debugging Tools.
static void SetSpy(const HString& Class, const HTuple& Value);
// Control of the HALCON Debugging Tools.
static void SetSpy(const HString& Class, const HString& Value);
// Control of the HALCON Debugging Tools.
static void SetSpy(const char* Class, const char* Value);
// Current configuration of the HALCON debugging-tool.
static HTuple GetSpy(const HString& Class);
// Current configuration of the HALCON debugging-tool.
static HTuple GetSpy(const char* Class);
// Set AOP information for operators.
static void SetAopInfo(const HTuple& OperatorName, const HTuple& IndexName, const HTuple& IndexValue, const HString& InfoName, const HTuple& InfoValue);
// Set AOP information for operators.
static void SetAopInfo(const HString& OperatorName, const HString& IndexName, const HString& IndexValue, const HString& InfoName, Hlong InfoValue);
// Set AOP information for operators.
static void SetAopInfo(const char* OperatorName, const char* IndexName, const char* IndexValue, const char* InfoName, Hlong InfoValue);
// Return AOP information for operators.
static HTuple GetAopInfo(const HTuple& OperatorName, const HTuple& IndexName, const HTuple& IndexValue, const HString& InfoName);
// Return AOP information for operators.
static HString GetAopInfo(const HString& OperatorName, const HTuple& IndexName, const HTuple& IndexValue, const HString& InfoName);
// Return AOP information for operators.
static HString GetAopInfo(const char* OperatorName, const HTuple& IndexName, const HTuple& IndexValue, const char* InfoName);
// Query indexing structure of AOP information for operators.
static HTuple QueryAopInfo(const HTuple& OperatorName, const HTuple& IndexName, const HTuple& IndexValue, HTuple* Value);
// Query indexing structure of AOP information for operators.
static HTuple QueryAopInfo(const HString& OperatorName, const HString& IndexName, const HString& IndexValue, HTuple* Value);
// Query indexing structure of AOP information for operators.
static HTuple QueryAopInfo(const char* OperatorName, const char* IndexName, const char* IndexValue, HTuple* Value);
// Check hardware regarding its potential for automatic operator parallelization.
static void OptimizeAop(const HTuple& OperatorName, const HTuple& IconicType, const HTuple& FileName, const HTuple& GenParamName, const HTuple& GenParamValue);
// Check hardware regarding its potential for automatic operator parallelization.
static void OptimizeAop(const HString& OperatorName, const HString& IconicType, const HString& FileName, const HTuple& GenParamName, const HTuple& GenParamValue);
// Check hardware regarding its potential for automatic operator parallelization.
static void OptimizeAop(const char* OperatorName, const char* IconicType, const char* FileName, const HTuple& GenParamName, const HTuple& GenParamValue);
// Write knowledge about hardware dependent behavior of automatic operator parallelization to file.
static void WriteAopKnowledge(const HString& FileName, const HTuple& GenParamName, const HTuple& GenParamValue);
// Write knowledge about hardware dependent behavior of automatic operator parallelization to file.
static void WriteAopKnowledge(const HString& FileName, const HString& GenParamName, const HString& GenParamValue);
// Write knowledge about hardware dependent behavior of automatic operator parallelization to file.
static void WriteAopKnowledge(const char* FileName, const char* GenParamName, const char* GenParamValue);
// Load knowledge about hardware dependent behavior of automatic operator parallelization.
static HTuple ReadAopKnowledge(const HString& FileName, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* OperatorNames);
// Load knowledge about hardware dependent behavior of automatic operator parallelization.
static HTuple ReadAopKnowledge(const HString& FileName, const HString& GenParamName, const HString& GenParamValue, HString* OperatorNames);
// Load knowledge about hardware dependent behavior of automatic operator parallelization.
static HTuple ReadAopKnowledge(const char* FileName, const char* GenParamName, const char* GenParamValue, HString* OperatorNames);
// Specify a window type.
static void SetWindowType(const HString& WindowType);
// Specify a window type.
static void SetWindowType(const char* WindowType);
// Get window characteristics.
static HTuple GetWindowAttr(const HString& AttributeName);
// Get window characteristics.
static HTuple GetWindowAttr(const char* AttributeName);
// Set window characteristics.
static void SetWindowAttr(const HString& AttributeName, const HTuple& AttributeValue);
// Set window characteristics.
static void SetWindowAttr(const HString& AttributeName, const HString& AttributeValue);
// Set window characteristics.
static void SetWindowAttr(const char* AttributeName, const char* AttributeValue);
// Query all available window types.
static HTuple QueryWindowType();
};
}
#endif
| [
"472024264@qq.com"
] | 472024264@qq.com |
b522afb7c18188fd0d18c510491aacd59f6d45be | 48ebb9aa139b70ed9d8411168c9bd073741393f5 | /Classes/Native/mscorlib_System_Predicate_1_gen552504511.h | b5bb717a18c0ada6a7dc1b2d69ee0765dcd53ba5 | [] | no_license | JasonRy/0.9.1 | 36cae42b24faa025659252293d8c7f8bfa8ee529 | b72ec7b76d3e26eb055574712a5150b1123beaa5 | refs/heads/master | 2021-07-22T12:25:04.214322 | 2017-11-02T07:42:18 | 2017-11-02T07:42:18 | 109,232,088 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 803 | h | #pragma once
#include "il2cpp-config.h"
#ifndef _MSC_VER
# include <alloca.h>
#else
# include <malloc.h>
#endif
#include <stdint.h>
#include "mscorlib_System_MulticastDelegate3201952435.h"
// ConsoleApplication.Program/departureData
struct departureData_t2109534396;
// System.IAsyncResult
struct IAsyncResult_t1999651008;
// System.AsyncCallback
struct AsyncCallback_t163412349;
// System.Object
struct Il2CppObject;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// System.Predicate`1<ConsoleApplication.Program/departureData>
struct Predicate_1_t552504511 : public MulticastDelegate_t3201952435
{
public:
public:
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
| [
"renxiaoyi@me.com"
] | renxiaoyi@me.com |
3ad0230577b00a9509f14afa83dd91a7b10584ec | 84283cea46b67170bb50f22dcafef2ca6ddaedff | /Algorithm/树链剖分/template.cpp | 5c018fdca39cfe9daee13cd208ffcf1ca08ebc98 | [] | no_license | ssyze/Codes | b36fedf103c18118fd7375ce7a40e864dbef7928 | 1376c40318fb67a7912f12765844f5eefb055c13 | refs/heads/master | 2023-01-09T18:36:05.417233 | 2020-11-03T15:45:45 | 2020-11-03T15:45:45 | 282,236,294 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,428 | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
int fa[maxn], dep[maxn], maxson[maxn], son[maxn], siz[maxn]; // dfs数组
int top[maxn], dfn[maxn], tot, has[maxn]; // link数组
int a[maxn], Sum[maxn << 2], lazy[maxn << 2];
int head[maxn], cnt, val[maxn];
struct e {
int to, nxt;
} edge[maxn];
int n, m, r, mod;
void addedge(int u, int v)
{
edge[cnt].to = v;
edge[cnt].nxt = head[u];
head[u] = cnt++;
}
int dfs(int u)
{
int ret = 0;
siz[u] = 1;
for (int i = head[u]; i != -1; i = edge[i].nxt) {
int v = edge[i].to;
if (v == fa[u]) continue;
fa[v] = u;
dep[v] = dep[u] + 1;
int sz = dfs(v);
siz[u] += siz[v];
ret += sz;
if (sz > maxson[u]) {
maxson[u] = sz;
son[u] = v;
}
}
return ret + 1;
}
void link(int u, int t)
{
dfn[u] = ++tot;
has[tot] = u;
top[u] = t;
if (son[u]) link(son[u], t);
for (int i = head[u]; i != -1; i = edge[i].nxt) {
int v = edge[i].to;
if (v == fa[u] || v == son[u]) continue;
link(v, v);
}
}
void hld()
{
dfs(r);
link(r, r);
}
//更新当前节点
void pushup(int& rt, int l, int r) { rt = l + r; }
//下传函数
void pushdown(int l, int r, int rt)
{
//区间改值
/* if (lazy[rt]) {
int m = (l + r) >> 1;
lazy[rt << 1] = lazy[rt];
lazy[rt << 1 | 1] = lazy[rt];
Sum[rt << 1] = lazy[rt] * (m - l + 1);
Sum[rt << 1 | 1] = lazy[rt] * (r - m);
lazy[rt] = 0;
} */
//区间增减
if (lazy[rt]) {
int m = (l + r) >> 1;
lazy[rt << 1] += lazy[rt];
lazy[rt << 1 | 1] += lazy[rt];
Sum[rt << 1] += lazy[rt] * (m - l + 1);
Sum[rt << 1 | 1] += lazy[rt] * (r - m);
Sum[rt << 1] %= mod;
Sum[rt << 1 | 1] %= mod;
lazy[rt] = 0;
}
}
// l:当前节点的左端点 r:当前节点的右端点 rt:当前节点的编号
void build(int l, int r, int rt)
{
if (l == r) {
Sum[rt] = val[has[l]];
return;
}
int m = (l + r) >> 1;
build(l, m, rt << 1);
build(m + 1, r, rt << 1 | 1);
pushup(Sum[rt], Sum[rt << 1], Sum[rt << 1 | 1]);
}
// l:当前节点的左端点 r:当前节点的右端点 rt:当前节点的编号 [L,R]查询的区间
int query(int L, int R, int l, int r, int rt)
{
if (L <= l && R >= r) return Sum[rt];
int m = (l + r) >> 1;
pushdown(l, r, rt);
if (R <= m)
return query(L, R, l, m, rt << 1) % mod;
else if (L >= m + 1)
return query(L, R, m + 1, r, rt << 1 | 1) % mod;
else {
int res = 0;
pushup(res, query(L, R, l, m, rt << 1), query(L, R, m + 1, r, rt << 1 | 1));
return res % mod;
}
}
// l:当前节点的左端点 r:当前节点的右端点 rt:当前节点的编号 将L的值改为V
void update(int L, int V, int l, int r, int rt)
{
if (l == r) {
Sum[rt] = V;
return;
}
int m = (l + r) >> 1;
pushdown(l, r, rt);
if (L <= m)
update(L, V, l, m, rt << 1);
else
update(L, V, m + 1, r, rt << 1 | 1);
pushup(Sum[rt], Sum[rt << 1], Sum[rt << 1 | 1]);
}
void segupdate(int L, int R, int l, int r, int rt, int lzy)
{
if (L <= l && R >= r) {
//区间改值
/* lazy[rt] = lzy;
Sum[rt] = (r - l + 1) * lzy; */
//区间加减
lazy[rt] += lzy;
Sum[rt] += (r - l + 1) * lzy;
Sum[rt] %= mod;
return;
}
int m = (l + r) >> 1;
pushdown(l, r, rt);
if (L <= m) segupdate(L, R, l, m, rt << 1, lzy);
if (R > m) segupdate(L, R, m + 1, r, rt << 1 | 1, lzy);
pushup(Sum[rt], Sum[rt << 1], Sum[rt << 1 | 1]);
return;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
memset(head, -1, sizeof(head));
cin >> n >> m >> r >> mod;
for (int i = 1; i <= n; i++) cin >> val[i];
for (int i = 1, x, y; i < n; i++) {
cin >> x >> y;
addedge(x, y);
addedge(y, x);
}
hld();
build(1, n, 1);
for (int i = 1, op, x, y, z; i <= m; i++) {
cin >> op;
if (op == 1) {
cin >> x >> y >> z;
z %= mod;
int l, r;
while (top[x] != top[y]) {
if (dep[top[x]] < dep[top[y]]) swap(x, y);
l = dfn[top[x]], r = dfn[x];
segupdate(l, r, 1, n, 1, z);
x = fa[top[x]];
}
if (dfn[x] > dfn[y]) swap(x, y);
segupdate(dfn[x], dfn[y], 1, n, 1, z);
}
else if (op == 2) {
cin >> x >> y;
int ans = 0, l, r;
while (top[x] != top[y]) {
if (dep[top[x]] < dep[top[y]]) swap(x, y);
l = dfn[top[x]], r = dfn[x];
ans = (ans + query(l, r, 1, n, 1)) % mod;
x = fa[top[x]];
}
if (dfn[x] > dfn[y]) swap(x, y);
ans = (ans + query(dfn[x], dfn[y], 1, n, 1)) % mod;
cout << ans << '\n';
}
else if (op == 3) {
cin >> x >> z;
z %= mod;
// cout << dfn[x] << ' ' << dfn[x] + maxson[x] << '\n';
segupdate(dfn[x], dfn[x] + siz[x] - 1, 1, n, 1, z);
}
else if (op == 4) {
cin >> x;
cout << query(dfn[x], dfn[x] + siz[x] - 1, 1, n, 1) % mod << '\n';
}
}
} | [
"46869158+shu-ssyze@users.noreply.github.com"
] | 46869158+shu-ssyze@users.noreply.github.com |
87e50117866dfb7cf53ad5944bd0ab8780f33ec0 | bcd7dbd328302b983ad6a8b9245be570a5a740ec | /turf/impl/Affinity_Linux.h | 4ba557767c9dd459c07f87acd16ee6a2ff35c042 | [
"BSD-2-Clause"
] | permissive | tycho/turf | 59e59a0c191e7248d29df13a88b39b4d43a2eca9 | 8bdbf44028db9f7d4ad9ee3b0fe60e9a4df51282 | refs/heads/master | 2021-01-18T07:58:55.841503 | 2016-03-16T14:52:16 | 2016-03-16T14:52:16 | 54,028,337 | 1 | 0 | null | 2016-03-16T12:04:11 | 2016-03-16T12:04:11 | null | UTF-8 | C++ | false | false | 1,406 | h | /*------------------------------------------------------------------------
Turf: Configurable C++ platform adapter
Copyright (c) 2016 Jeff Preshing
Distributed under the Simplified BSD License.
Original location: https://github.com/preshing/turf
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the LICENSE file for more information.
------------------------------------------------------------------------*/
#ifndef TURF_IMPL_AFFINITY_LINUX_H
#define TURF_IMPL_AFFINITY_LINUX_H
#include <turf/Core.h>
#include <pthread.h>
#include <sched.h>
#include <vector>
namespace turf {
class Affinity_Linux {
private:
struct CoreInfo {
std::vector<u32> hwThreadIndexToLogicalProcessor;
};
bool m_isAccurate;
std::vector<CoreInfo> m_coreIndexToInfo;
u32 m_numHWThreads;
public:
Affinity_Linux();
bool isAccurate() const {
return m_isAccurate;
}
u32 getNumPhysicalCores() const {
return m_coreIndexToInfo.size();
}
u32 getNumHWThreads() const {
return m_numHWThreads;
}
u32 getNumHWThreadsForCore(ureg core) const {
return m_coreIndexToInfo[core].hwThreadIndexToLogicalProcessor.size();
}
bool setAffinity(ureg core, ureg hwThread);
};
} // namespace turf
#endif // TURF_IMPL_AFFINITY_LINUX_H
| [
"filter-github@preshing.com"
] | filter-github@preshing.com |
890c7be179adb946cb54bbef4d1a4a584c4dfe7e | 12b15a6f8f99b8b4259e537af73075995b7d04bf | /lab/lab2_structure/struct.cpp | eb6b6180896f230d7f0112b62b951183770673e7 | [] | no_license | PraveshPandey23/cpp_project | 48cdfee60e9537a3d0cc7552d6e4f30e47f34ace | f08ded410d984d5906a8e8aceed96c4b1e332b2b | refs/heads/main | 2023-06-05T22:04:35.318902 | 2021-06-24T11:44:34 | 2021-06-24T11:44:34 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 431 | cpp | #include<iostream>
#include<stdio.h>
using namespace std;
struct student{
char name[20];
char address[20];
int roll;
};
int main()
{
student s;
cout<<"enter name"<<endl;
gets(s.name);
cout<<"enter roll"<<endl;
cin>>s.roll;
cout<<"enter address"<<endl;
cin>>s.address;
cout<<"entered information"<<endl;
//puts(s.name);
cout<<(s.name<<"\t"<<s.roll<<"\t"<<s.address<<endl;
}
| [
"nitishrocker220@gmailcom"
] | nitishrocker220@gmailcom |
edc9a8b7b7f7b93ff290dd5be19c98d5b38b7e8e | a54188c3302fce4372c30c9fa973394614c2ca33 | /include/objtools/data_loaders/genbank/pubseq2/reader_pubseq2.hpp | 3c34f78178a2a53c1179844791cc90d384f2767d | [] | no_license | DmitrySigaev/ncbi | 5747f36076a80bf4080c09315ab3e95a4ea0dc58 | 088aa1b09693e1b6241582f017f859b8e5600e8a | refs/heads/master | 2021-01-01T05:07:57.992119 | 2016-05-10T18:23:57 | 2016-05-10T18:23:57 | 58,489,985 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,728 | hpp | #ifndef READER_PUBSEQ2__HPP_INCLUDED
#define READER_PUBSEQ2__HPP_INCLUDED
/* $Id$
* ===========================================================================
* PUBLIC DOMAIN NOTICE
* National Center for Biotechnology Information
*
* This software/database is a "United States Government Work" under the
* terms of the United States Copyright Act. It was written as part of
* the author's official duties as a United States Government employee and
* thus cannot be copyrighted. This software/database is freely available
* to the public for use. The National Library of Medicine and the U.S.
* Government have not placed any restriction on its use or reproduction.
*
* Although all reasonable efforts have been taken to ensure the accuracy
* and reliability of the software and data, the NLM and the U.S.
* Government do not and cannot warrant the performance or results that
* may be obtained by using this software or data. The NLM and the U.S.
* Government disclaim all warranties, express or implied, including
* warranties of performance, merchantability or fitness for any particular
* purpose.
*
* Please cite the author in any work or product based on this material.
* ===========================================================================
*
* Author: Anton Butanaev, Eugene Vasilchenko
*
* File Description: Data reader from Pubseq_OS
*
*/
#include <objtools/data_loaders/genbank/impl/reader_id2_base.hpp>
BEGIN_NCBI_SCOPE
class CDB_Connection;
class CDB_Result;
class CDB_RPCCmd;
class I_DriverContext;
class I_BaseCmd;
BEGIN_SCOPE(objects)
class CId2ReaderBase;
class NCBI_XREADER_PUBSEQOS2_EXPORT CPubseq2Reader : public CId2ReaderBase
{
public:
CPubseq2Reader(int max_connections = 0,
const string& server = kEmptyStr,
const string& user = kEmptyStr,
const string& pswd = kEmptyStr,
const string& dbapi_driver = kEmptyStr);
CPubseq2Reader(const TPluginManagerParamTree* params,
const string& driver_name);
~CPubseq2Reader();
int GetMaximumConnectionsLimit(void) const;
void x_InitConnection(CDB_Connection& db_conn, TConn conn);
protected:
virtual void x_AddConnectionSlot(TConn conn);
virtual void x_RemoveConnectionSlot(TConn conn);
virtual void x_DisconnectAtSlot(TConn conn, bool failed);
virtual void x_ConnectAtSlot(TConn conn);
virtual string x_ConnDescription(TConn conn) const;
virtual void x_SendPacket(TConn conn, const CID2_Request_Packet& packet);
virtual void x_ReceiveReply(TConn conn, CID2_Reply& reply);
virtual void x_EndOfPacket(TConn conn);
CDB_Connection& x_GetConnection(TConn conn);
AutoPtr<CObjectIStream> x_SendPacket(CDB_Connection& db_conn,
TConn conn,
const CID2_Request_Packet& packet);
CObjectIStream& x_GetCurrentResult(TConn conn);
void x_SetCurrentResult(TConn conn, AutoPtr<CObjectIStream> result);
private:
string m_Server;
string m_User;
string m_Password;
string m_DbapiDriver;
I_DriverContext* m_Context;
int m_Timeout;
int m_OpenTimeout;
struct SConnection
{
AutoPtr<CDB_Connection> m_Connection;
AutoPtr<CObjectIStream> m_Result;
};
typedef map<TConn, SConnection> TConnections;
TConnections m_Connections;
bool m_ExclWGSMaster;
};
END_SCOPE(objects)
END_NCBI_SCOPE
#endif // READER_PUBSEQ2__HPP_INCLUDED
| [
"vasilche@112efe8e-fc92-43c6-89b6-d25c299ce97b"
] | vasilche@112efe8e-fc92-43c6-89b6-d25c299ce97b |
11e997e33ee4228fa1d0dd073f4b7ac1872794e1 | 5c02f0b981ea8545d164ae67027b6003b80b042b | /OLD/Source/clock4pins/clock4pins.ino | 60fbc8987e4b4b926a34a6a1be9ab9ced1a54f00 | [] | no_license | alexma7/Z_arduino | 8ee86af378ab734e762f5db7f30e9b9e66696c55 | a5b08e92fa846c2aedc5c17015beef9fd9cbd757 | refs/heads/master | 2023-03-21T20:58:44.293341 | 2021-03-10T08:14:04 | 2021-03-10T08:14:04 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,131 | ino |
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>
void setup()
{
Serial.begin(9600);
while (!Serial) ; // ожидаем ответа порта
delay(200);
Serial.println("DS1307RTC Read Test");
Serial.println("-------------------");
}
void loop()
{
tmElements_t tm;
if (RTC.read(tm))
{
Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
}
else
{
if (RTC.chipPresent())
{
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
}
else
{
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(1000);
}
void print2digits(int number)
{
if (number >= 0 && number < 10)
{
Serial.write('0');
}
Serial.print(number);
}
| [
"alexma7@rambler.ru"
] | alexma7@rambler.ru |
abef8fae2b6dbbd969e5697f8681aff5ab210983 | f1aaed1e27416025659317d1f679f7b3b14d654e | /Office/Source/Connections.cpp | cecbd2afdeecfbc37f83f785102eb7d11e4e3445 | [] | no_license | radtek/Pos | cee37166f89a7fcac61de9febb3760d12b823ce5 | f117845e83b41d65f18a4635a98659144d66f435 | refs/heads/master | 2020-11-25T19:49:37.755286 | 2016-09-16T14:55:17 | 2016-09-16T14:55:17 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 14,270 | cpp | //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Connections.h"
#include "Consts.h"
#include "MMRegistry.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
TConnectionDetails CurrentConnection;
//---------------------------------------------------------------------------
bool TConnectionDetails::LoadSettings()
{
if (RegistryKeyExists(OfficeKey + "\\" + CompanyName))
{
AnsiString Key = OfficeKey + "\\" + CompanyName;
AnsiString Text;
Text = "";
RegistryRead(Key, "MMDataFile", Text);
CurrentConnection.MenuMateDB.DBName = Text;
Text = "";
RegistryRead(Key, "StockDataFile", Text);
CurrentConnection.StockDB.DBName = Text;
Text = "";
RegistryRead(Key, "ChefMateDataFile", Text);
CurrentConnection.ChefMateDB.DBName = Text;
Text = "";
RegistryRead(Key, "CompanyDetails", Text);
CurrentConnection.ReportHeader = Text;
Text = "";
RegistryRead(Key, "DeliveryAddress", Text);
CurrentConnection.DeliveryAddress = Text;
Text = "";
RegistryRead(Key, "OrderInstructions", Text);
CurrentConnection.OrderInstructions = Text;
Text = "";
RegistryRead(Key, "MenuCommitPath", Text);
CurrentConnection.ServerPath = Text;
Text = "";
RegistryRead(Key, "MenuSavePath", Text);
CurrentConnection.MenuSavePath = Text;
Text = "";
RegistryRead(Key + "\\Payroll", "PayrollSystem", Text);
CurrentConnection.PayrollSystem = Text;
Text = "";
RegistryRead(Key + "\\Payroll", "ExportPath", Text);
CurrentConnection.PayrollExportPath = Text;
Text = "";
RegistryRead(Key + "\\MYOB", "AccountSystem", Text);
CurrentConnection.AccountSystem = Text;
Text = "";
RegistryRead(Key + "\\MYOB", "MYOBPath", Text);
CurrentConnection.MYOBPath = Text;
Text = "";
RegistryRead(Key + "\\MYOB", "MYOBJobCode", Text);
CurrentConnection.MYOBJobCode = Text;
Text = "";
RegistryRead(Key + "\\MYOB", "SalesInvoiceExportAccount", Text);
CurrentConnection.SalesInvoiceExportAccount = Text;
Text = "";
RegistryRead(Key + "\\MYOB", "SalesInvoiceExportType", Text);
CurrentConnection.SalesInvoiceExportType = Text;
Text = "";
RegistryRead(Key + "\\Stocktake", "StocktakePath", Text);
CurrentConnection.StocktakePath = Text;
Text = "Product.txt";
RegistryRead(Key + "\\Stocktake", "StocktakeExportFile", Text);
CurrentConnection.StocktakeExportFile = Text;
Text = "Stock.txt";
RegistryRead(Key + "\\Stocktake", "StocktakeImportFile", Text);
CurrentConnection.StocktakeImportFile = Text;
Text = "-1";
RegistryRead(Key + "\\Stocktake", "StocktakeBarcodePos", Text);
CurrentConnection.StocktakeBarcodePos = StrToInt(Text);
Text = "-1";
RegistryRead(Key + "\\Stocktake", "StocktakeQtyPos", Text);
CurrentConnection.StocktakeQtyPos = StrToInt(Text);
// Text = "0";
// RegistryRead(Key, "IncludeGST", Text);
// CurrentConnection.IncludeGST = (Text == "1");
Text = "0";
RegistryRead(Key, "UseSerialBarcodeReader", Text);
CurrentConnection.UseSerialBarcodeReader = (Text == "1");
Text = "-1";
RegistryRead(Key, "SerialBarcodeReaderPort", Text);
CurrentConnection.SerialBarcodeReaderPort = StrToInt(Text);
Text = ""; // cww
RegistryRead(Key, "VIPCreditName", Text);
CurrentConnection.VIPCreditName = Text;
Text = "0";
RegistryRead(Key, "HideStocktakeOnHand", Text);
CurrentConnection.HideStocktakeOnHand = (Text == "1");
Text = "15";
RegistryRead(Key, "DefaultMenuGST", Text);
CurrentConnection.DefaultMenuGST = StrToFloat(Text);
Text = "15";
RegistryRead(Key, "DefaultStockGST", Text);
CurrentConnection.DefaultStockGST = StrToFloat(Text);
Text = "";
RegistryRead(Key, "GSTNumber", Text);
CurrentConnection.GSTNumber = Text;
Text = "0";
RegistryRead(Key, "SingleLocation", Text);
CurrentConnection.SingleLocation = (Text == "1");
Text = "";
RegistryRead(Key, "DefaultLocation", Text);
CurrentConnection.DefaultLocation = Text;
Text = "0";
RegistryRead(Key, "RemoteMM", Text);
CurrentConnection.MenuMateDB.RemoteConnection = (Text == "1");
Text = "";
RegistryRead(Key, "RemoteMMEntry", Text);
CurrentConnection.MenuMateDB.RASEntry = Text;
Text = "";
RegistryRead(Key, "RemoteMMUsername", Text);
CurrentConnection.MenuMateDB.RASUserName = Text;
Text = "";
RegistryRead(Key, "RemoteMMPassword", Text);
CurrentConnection.MenuMateDB.RASPassword = Text;
Text = "0";
RegistryRead(Key, "RemoteStock", Text);
CurrentConnection.StockDB.RemoteConnection = (Text == "1");
Text = "";
RegistryRead(Key, "RemoteStockEntry", Text);
CurrentConnection.StockDB.RASEntry = Text;
Text = "";
RegistryRead(Key, "RemoteStockUsername", Text);
CurrentConnection.StockDB.RASUserName = Text;
Text = "";
RegistryRead(Key, "RemoteStockPassword", Text);
CurrentConnection.StockDB.RASPassword = Text;
Text = "0";
RegistryRead(Key, "RemoteChefMate", Text);
CurrentConnection.ChefMateDB.RemoteConnection = (Text == "1");
Text = "";
RegistryRead(Key, "RemoteChefMateEntry", Text);
CurrentConnection.ChefMateDB.RASEntry = Text;
Text = "";
RegistryRead(Key, "RemoteChefMateUsername", Text);
CurrentConnection.ChefMateDB.RASUserName = Text;
Text = "";
RegistryRead(Key, "RemoteChefMatePassword", Text);
CurrentConnection.ChefMateDB.RASPassword = Text;
Text = "0";
RegistryRead(Key , "SettingDecimalPlaces", Text);
CurrentConnection.SettingDecimalPlaces = StrToInt(Text);
RegistryRead(Key, "DontShowItemCost",
CurrentConnection.DontShowItemCostInPurchaseOrder);
Text = "0";
RegistryRead(Key, "AutoPrintStockTransferAudit", Text);
CurrentConnection.AutoPrintStockTransferAudit = (Text == "1");
Text = "";
Text = "0";
RegistryRead(Key, "AutoPrintReceiveTransferAudit", Text);
CurrentConnection.AutoPrintReceiveTransferAudit = (Text == "1");
Text = "";
Text = "0";
RegistryRead(Key, "SuppliersFromDefaultLocationsOnly", Text);
CurrentConnection.SuppliersFromDefaultLocationsOnly = (Text == "1");
Text = "";
/* Text = "15";
RegistryRead(Key, "NoOfPriceLevels", Text);
CurrentConnection.NoOfPriceLevels = StrToInt(Text); */
return true;
}
else
{
return false;
}
}
//---------------------------------------------------------------------------
bool TConnectionDetails::RASGetEntries(TStrings *Strings)
{
return RASDial.GetEntries(Strings);
}
//---------------------------------------------------------------------------
bool TConnectionDetails::RASCreateEntry()
{
return RASDial.CreateEntry();
}
//---------------------------------------------------------------------------
bool TDBDetails::Dial(AnsiString &ErrorMsg)
{
HRASCONN Handle = RASDial.Dial(RASEntry, RASUserName, RASPassword, ErrorMsg);
ClientIP = RASDial.ClientIP;
ServerIP = RASDial.ServerIP;
return (Handle != 0);
}
//---------------------------------------------------------------------------
HRASCONN TDBDetails::GetRASHandle()
{
return RASDial.GetConnected(RASEntry);
}
//---------------------------------------------------------------------------
bool TDBDetails::HangUp()
{
return RASDial.HangUp(RASHandle);
}
//---------------------------------------------------------------------------
bool TDBDetails::GetConnected()
{
return RASDial.GetConnected(RASEntry);
}
//---------------------------------------------------------------------------
bool TDBDetails::GetEntryDetails(AnsiString &UserName, AnsiString &Password)
{
return RASDial.GetEntryDetails(RASEntry, UserName, Password);
}
//---------------------------------------------------------------------------
AnsiString TDBDetails::GetDBFilePath()
{
AnsiString SubSection = DBName.SubString(DBName.Pos(":")+1, DBName.Length() - DBName.Pos(":") + 1);
if (SubSection.Pos(":") == 0)
{
return ExtractFilePath(DBName);
}
else
{
return ExtractFilePath(SubSection);
}
}
//---------------------------------------------------------------------------
TRASDial::TRASDial()
{
hLib = LoadLibrary("rasapi32.dll");
if (hLib != NULL)
{
RasGetEntryDialParams = (TRasGetEntryDialParams) GetProcAddress(hLib, "RasGetEntryDialParamsA");
RasSetEntryDialParams = (TRasSetEntryDialParams) GetProcAddress(hLib, "RasSetEntryDialParamsA");
RasDial = (TRasDial) GetProcAddress(hLib, "RasDialA");
RasGetProjectionInfo = (TRasGetProjectionInfo) GetProcAddress(hLib, "RasGetProjectionInfoA");
RasGetErrorString = (TRasGetErrorString) GetProcAddress(hLib, "RasGetErrorStringA");
RasHangUp = (TRasHangUp) GetProcAddress(hLib, "RasHangUpA");
RasGetConnectStatus = (TRasGetConnectStatus) GetProcAddress(hLib, "RasGetConnectStatusA");
RasEnumEntries = (TRasEnumEntries) GetProcAddress(hLib, "RasEnumEntriesA");
RasEnumConnections = (TRasEnumConnections) GetProcAddress(hLib, "RasEnumConnectionsA");
RasCreatePhonebookEntry = (TRasCreatePhonebookEntry) GetProcAddress(hLib, "RasCreatePhonebookEntryA");
FreeLibrary(hLib);
}
else
{
RasGetEntryDialParams = NULL;
RasSetEntryDialParams = NULL;
RasDial = NULL;
RasGetProjectionInfo = NULL;
RasGetErrorString = NULL;
RasHangUp = NULL;
RasGetConnectStatus = NULL;
RasEnumEntries = NULL;
RasEnumConnections = NULL;
RasCreatePhonebookEntry = NULL;
}
}
//---------------------------------------------------------------------------
TRASDial::~TRASDial()
{
if (hLib != NULL)
{
FreeLibrary(hLib);
}
}
//---------------------------------------------------------------------------
HRASCONN TRASDial::Dial(AnsiString Entry, AnsiString UserName, AnsiString Password, AnsiString &ErrorMsg)
{
if (!hLib || !RasGetEntryDialParams || !RasGetProjectionInfo || !RasDial || !RasGetErrorString)
{
return NULL;
}
RASDIALPARAMS DialParams;
BOOL RetrievePassword;
HRASCONN Handle=0;
memset(&DialParams, sizeof(RASDIALPARAMS), 0);
DialParams.dwSize = sizeof(RASDIALPARAMS);
StrPCopy(DialParams.szEntryName, Entry);
if (RasGetEntryDialParams(NULL, &DialParams, &RetrievePassword) == 0)
{
StrPCopy(DialParams.szUserName, UserName);
StrPCopy(DialParams.szPassword, Password);
// if (RasSetEntryDialParams(NULL, DialParams, false))
// {
// }
int Result = RasDial(NULL, NULL, &DialParams, 0, NULL, &Handle);
if (Result == 0)
{
RASPPPIP RASPppIp;
DWORD lpcb;
memset(&RASPppIp, sizeof(RASPPPIP), 0);
RASPppIp.dwSize = sizeof(RASPPPIP);
lpcb = RASPppIp.dwSize;
if (RasGetProjectionInfo(Handle, RASP_PppIp, &RASPppIp, &lpcb) == 0)
{
ClientIP = RASPppIp.szIpAddress;
ServerIP = RASPppIp.szServerIpAddress;
}
else
{
ClientIP = "";
ServerIP = "";
}
}
else
{
char TempMessage[256];
RasGetErrorString(Result, TempMessage, 256);
ErrorMsg = TempMessage;
if (Handle != 0)
{
HangUp(Handle);
Handle = 0;
}
}
}
return Handle;
}
//---------------------------------------------------------------------------
bool TRASDial::HangUp(HRASCONN Handle)
{
if (!hLib || !RasHangUp || !RasGetConnectStatus)
{
return false;
}
RASCONNSTATUS Status;
memset(&Status, sizeof(RASCONNSTATUS), 0);
Status.dwSize = sizeof(RASCONNSTATUS);
if (RasHangUp(Handle) != 0)
{
return false;
}
// DWORD Result = RasGetConnectStatus(Handle, &Status);
while (RasGetConnectStatus(Handle, &Status) != ERROR_INVALID_HANDLE)
{
// char TempMessage[256];
// RasGetErrorString(Result, TempMessage, 256);
Sleep(0);
Application->ProcessMessages();
}
return true;
}
//---------------------------------------------------------------------------
bool TRASDial::GetEntries(TStrings *Strings)
{
if (!hLib || !RasEnumEntries)
{
return false;
}
bool Success = false;
RASENTRYNAME Entries[MaxEntries];
DWORD BufferSize;
DWORD EntryCount;
Strings->Clear();
Entries[0].dwSize = sizeof(RASENTRYNAME);
BufferSize = sizeof(RASENTRYNAME) * MaxEntries;
if (RasEnumEntries(NULL, NULL, Entries, &BufferSize, &EntryCount) == 0)
{
Success = true;
for (DWORD i=0; i<EntryCount; i++)
{
Strings->Add(Entries[i].szEntryName);
}
}
return Success;
}
//---------------------------------------------------------------------------
HRASCONN TRASDial::GetConnected(AnsiString Entry)
{
if (!hLib || !RasEnumConnections)
{
return NULL;
}
bool Success = false;
HRASCONN Handle;//hrasconn
RASCONN Entries[MaxEntries];
DWORD BufferSize;
DWORD EntryCount;
RASCONNSTATUS Status;
Entries[0].dwSize = sizeof(RASCONN);
BufferSize = sizeof(RASCONN) * MaxEntries;
DWORD RasResult = RasEnumConnections(Entries, &BufferSize, &EntryCount);
if (RasResult == 0)
{
for (DWORD i=0; i<EntryCount; i++)
{
if (Entry == Entries[i].szEntryName)
{
// RasGetConnectStatus(Entries[i].hrasconn, &Status);
// if (Status.rasconnstate == RASCS_Connected)
// {
Success = true;
Handle = Entries[i].hrasconn;
break;
// }
}
}
}
else
{
Application->MessageBox(AnsiString("RasEnumConnections failed - Err:" + IntToStr(RasResult)).c_str(), "Error", MB_OK + MB_ICONERROR);
}
if (Success) return Handle;
else return 0;
}
//---------------------------------------------------------------------------
bool TRASDial::GetEntryDetails(AnsiString Entry, AnsiString &UserName, AnsiString &Password)
{
if (!hLib || !RasGetEntryDialParams)
{
return false;
}
bool Success = false;
RASDIALPARAMS DialParams;
BOOL RetrievePassword;
memset(&DialParams, sizeof(RASDIALPARAMS), 0);
DialParams.dwSize = sizeof(RASDIALPARAMS);
StrPCopy(DialParams.szEntryName, Entry);
if (RasGetEntryDialParams(NULL, &DialParams, &RetrievePassword) == 0)
{
UserName = DialParams.szUserName;
if (RetrievePassword)
{
Password = DialParams.szPassword;
}
else
{
Password = "";
}
Success = true;
}
return Success;
}
//---------------------------------------------------------------------------
bool TRASDial::CreateEntry()
{
if (!hLib || !RasCreatePhonebookEntry)
{
return false;
}
return RasCreatePhonebookEntry(NULL, NULL);
}
//---------------------------------------------------------------------------
| [
"ravish.sharma@menumate.com"
] | ravish.sharma@menumate.com |
93b3074deb4b76562dadac7ced7df0fb57fa0627 | 8c31a1fbb0653f2b7a1af5a098ba2961510764e0 | /chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.cc | d4fd1214719e4012a4d3f54b4b23550f1392b76a | [
"BSD-3-Clause"
] | permissive | tahini/chromium | 282892abfbf6889a13e3fc41aed85a222d4cb837 | 88fd72c512fcd2dccca0f47d9bdb5af1bf754f98 | refs/heads/master | 2023-03-10T09:04:27.252094 | 2020-01-27T21:08:40 | 2020-01-27T21:08:40 | 236,600,353 | 0 | 0 | BSD-3-Clause | 2020-01-27T21:35:33 | 2020-01-27T21:35:33 | null | UTF-8 | C++ | false | false | 25,591 | cc | // Copyright (c) 2019 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.
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h"
#include <algorithm>
#include <numeric>
#include <string>
#include <utility>
#include "base/feature_list.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/platform_file.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router.h"
#include "chrome/browser/file_util_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_views.h"
#include "chrome/browser/safe_browsing/dm_token_utils.h"
#include "chrome/browser/safe_browsing/download_protection/check_client_download_request.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/services/file_util/public/cpp/sandboxed_rar_analyzer.h"
#include "chrome/services/file_util/public/cpp/sandboxed_zip_analyzer.h"
#include "components/policy/core/browser/url_blacklist_manager.h"
#include "components/policy/core/browser/url_util.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/features.h"
#include "components/safe_browsing/core/proto/webprotect.pb.h"
#include "components/url_matcher/url_matcher.h"
#include "content/public/browser/web_contents.h"
#include "crypto/sha2.h"
#include "net/base/mime_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_types.h"
namespace safe_browsing {
// TODO(rogerta): keeping this disabled by default until UX is finalized.
const base::Feature kDeepScanningOfUploadsUI{
"SafeBrowsingDeepScanningOfUploadsUI", base::FEATURE_DISABLED_BY_DEFAULT};
namespace {
// Global pointer of factory function (RepeatingCallback) used to create
// instances of DeepScanningDialogDelegate in tests. !is_null() only in tests.
DeepScanningDialogDelegate::Factory* GetFactoryStorage() {
static base::NoDestructor<DeepScanningDialogDelegate::Factory> factory;
return factory.get();
}
// Determines if the completion callback should be called only after all the
// scan requests have finished and the verdicts known.
bool WaitForVerdict() {
int state = g_browser_process->local_state()->GetInteger(
prefs::kDelayDeliveryUntilVerdict);
return state == DELAY_UPLOADS || state == DELAY_UPLOADS_AND_DOWNLOADS;
}
struct FileContents {
FileContents() : result(BinaryUploadService::Result::UNKNOWN) {}
explicit FileContents(BinaryUploadService::Result result) : result(result) {}
FileContents(FileContents&&) = default;
FileContents& operator=(FileContents&&) = default;
BinaryUploadService::Result result;
BinaryUploadService::Request::Data data;
std::string sha256;
};
// Callback used by FileSourceRequest to read file data on a blocking thread.
FileContents GetFileContentsSHA256Blocking(const base::FilePath& path) {
base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
if (!file.IsValid())
return FileContents();
size_t file_size = file.GetLength();
if (file_size > BinaryUploadService::kMaxUploadSizeBytes)
return FileContents(BinaryUploadService::Result::FILE_TOO_LARGE);
FileContents file_contents;
file_contents.result = BinaryUploadService::Result::SUCCESS;
file_contents.data.contents.resize(file_size);
size_t bytes_read = 0;
while (bytes_read < file_size) {
int64_t bytes_currently_read = file.ReadAtCurrentPos(
&file_contents.data.contents[bytes_read], file_size - bytes_read);
if (bytes_currently_read == -1)
return FileContents();
bytes_read += bytes_currently_read;
}
file_contents.sha256 = crypto::SHA256HashString(file_contents.data.contents);
return file_contents;
}
// A BinaryUploadService::Request implementation that gets the data to scan
// from a string.
class StringSourceRequest : public BinaryUploadService::Request {
public:
StringSourceRequest(std::string text, BinaryUploadService::Callback callback);
~StringSourceRequest() override;
StringSourceRequest(const StringSourceRequest&) = delete;
StringSourceRequest& operator=(const StringSourceRequest&) = delete;
// BinaryUploadService::Request implementation.
void GetRequestData(DataCallback callback) override;
private:
Data data_;
BinaryUploadService::Result result_ =
BinaryUploadService::Result::FILE_TOO_LARGE;
};
StringSourceRequest::StringSourceRequest(std::string text,
BinaryUploadService::Callback callback)
: Request(std::move(callback)) {
// Only remember strings less than the maximum allowed.
if (text.size() < BinaryUploadService::kMaxUploadSizeBytes) {
data_.contents = std::move(text);
result_ = BinaryUploadService::Result::SUCCESS;
}
}
StringSourceRequest::~StringSourceRequest() = default;
void StringSourceRequest::GetRequestData(DataCallback callback) {
std::move(callback).Run(result_, data_);
}
bool DlpTriggeredRulesOK(
const ::safe_browsing::DlpDeepScanningVerdict& verdict) {
// No status returns true since this function is called even when the server
// doesn't return a DLP scan verdict.
if (!verdict.has_status())
return true;
if (verdict.status() != DlpDeepScanningVerdict::SUCCESS)
return false;
for (int i = 0; i < verdict.triggered_rules_size(); ++i) {
if (verdict.triggered_rules(i).action() ==
DlpDeepScanningVerdict::TriggeredRule::BLOCK) {
return false;
}
}
return true;
}
std::string GetFileMimeType(base::FilePath path) {
// TODO(crbug.com/1013252): Obtain a more accurate MimeType by parsing the
// file content.
std::string mime_type;
net::GetMimeTypeFromFile(path, &mime_type);
return mime_type;
}
} // namespace
// A BinaryUploadService::Request implementation that gets the data to scan
// from the contents of a file.
class DeepScanningDialogDelegate::FileSourceRequest
: public BinaryUploadService::Request {
public:
FileSourceRequest(base::WeakPtr<DeepScanningDialogDelegate> delegate,
base::FilePath path,
BinaryUploadService::Callback callback);
FileSourceRequest(const FileSourceRequest&) = delete;
FileSourceRequest& operator=(const FileSourceRequest&) = delete;
~FileSourceRequest() override = default;
private:
// BinaryUploadService::Request implementation.
void GetRequestData(DataCallback callback) override;
void OnGotFileContents(DataCallback callback, FileContents file_contents);
base::WeakPtr<DeepScanningDialogDelegate> delegate_;
base::FilePath path_;
base::WeakPtrFactory<FileSourceRequest> weakptr_factory_{this};
};
DeepScanningDialogDelegate::FileSourceRequest::FileSourceRequest(
base::WeakPtr<DeepScanningDialogDelegate> delegate,
base::FilePath path,
BinaryUploadService::Callback callback)
: Request(std::move(callback)),
delegate_(delegate),
path_(std::move(path)) {}
void DeepScanningDialogDelegate::FileSourceRequest::GetRequestData(
DataCallback callback) {
base::PostTaskAndReplyWithResult(
FROM_HERE,
{base::ThreadPool(), base::TaskPriority::USER_VISIBLE, base::MayBlock()},
base::BindOnce(&GetFileContentsSHA256Blocking, path_),
base::BindOnce(&FileSourceRequest::OnGotFileContents,
weakptr_factory_.GetWeakPtr(), std::move(callback)));
}
void DeepScanningDialogDelegate::FileSourceRequest::OnGotFileContents(
DataCallback callback,
FileContents file_contents) {
if (delegate_)
delegate_->SetFileInfo(path_, std::move(file_contents.sha256),
file_contents.data.contents.length());
std::move(callback).Run(file_contents.result, file_contents.data);
}
DeepScanningDialogDelegate::Data::Data() = default;
DeepScanningDialogDelegate::Data::Data(Data&& other) = default;
DeepScanningDialogDelegate::Data::~Data() = default;
DeepScanningDialogDelegate::Result::Result() = default;
DeepScanningDialogDelegate::Result::Result(Result&& other) = default;
DeepScanningDialogDelegate::Result::~Result() = default;
DeepScanningDialogDelegate::FileInfo::FileInfo() = default;
DeepScanningDialogDelegate::FileInfo::FileInfo(FileInfo&& other) = default;
DeepScanningDialogDelegate::FileInfo::~FileInfo() = default;
DeepScanningDialogDelegate::~DeepScanningDialogDelegate() = default;
void DeepScanningDialogDelegate::Cancel() {
if (callback_.is_null())
return;
if (access_point_.has_value()) {
RecordDeepScanMetrics(access_point_.value(),
base::TimeTicks::Now() - upload_start_time_, 0,
"CancelledByUser", false);
}
// Make sure to reject everything.
FillAllResultsWith(false);
RunCallback();
}
bool DeepScanningDialogDelegate::ResultShouldAllowDataUse(
BinaryUploadService::Result result) {
// Keep this implemented as a switch instead of a simpler if statement so that
// new values added to BinaryUploadService::Result cause a compiler error.
switch (result) {
case BinaryUploadService::Result::SUCCESS:
case BinaryUploadService::Result::UPLOAD_FAILURE:
case BinaryUploadService::Result::TIMEOUT:
case BinaryUploadService::Result::FAILED_TO_GET_TOKEN:
// UNAUTHORIZED allows data usage since it's a result only obtained if the
// browser is not authorized to perform deep scanning. It does not make
// sense to block data in this situation since no actual scanning of the
// data was performed, so it's allowed.
case BinaryUploadService::Result::UNAUTHORIZED:
case BinaryUploadService::Result::UNKNOWN:
return true;
case BinaryUploadService::Result::FILE_TOO_LARGE:
case BinaryUploadService::Result::FILE_ENCRYPTED:
return false;
}
}
// static
bool DeepScanningDialogDelegate::IsEnabled(Profile* profile,
GURL url,
Data* data) {
// If this is an incognitio profile, don't perform scans.
if (profile->IsOffTheRecord())
return false;
// If there's no valid DM token, the upload will fail.
if (!GetDMToken(profile).is_valid())
return false;
// See if content compliance checks are needed.
int state = g_browser_process->local_state()->GetInteger(
prefs::kCheckContentCompliance);
data->do_dlp_scan =
base::FeatureList::IsEnabled(kContentComplianceEnabled) &&
(state == CHECK_UPLOADS || state == CHECK_UPLOADS_AND_DOWNLOADS);
if (url.is_valid())
data->url = url.spec();
if (data->do_dlp_scan &&
g_browser_process->local_state()->HasPrefPath(
prefs::kURLsToNotCheckComplianceOfUploadedContent)) {
const base::ListValue* filters = g_browser_process->local_state()->GetList(
prefs::kURLsToNotCheckComplianceOfUploadedContent);
url_matcher::URLMatcher matcher;
policy::url_util::AddAllowFilters(&matcher, filters);
data->do_dlp_scan = matcher.MatchURL(url).empty();
}
// See if malware checks are needed.
state = profile->GetPrefs()->GetInteger(
prefs::kSafeBrowsingSendFilesForMalwareCheck);
data->do_malware_scan =
base::FeatureList::IsEnabled(kMalwareScanEnabled) &&
(state == SEND_UPLOADS || state == SEND_UPLOADS_AND_DOWNLOADS);
if (data->do_malware_scan) {
if (g_browser_process->local_state()->HasPrefPath(
prefs::kURLsToCheckForMalwareOfUploadedContent)) {
const base::ListValue* filters =
g_browser_process->local_state()->GetList(
prefs::kURLsToCheckForMalwareOfUploadedContent);
url_matcher::URLMatcher matcher;
policy::url_util::AddAllowFilters(&matcher, filters);
data->do_malware_scan = !matcher.MatchURL(url).empty();
} else {
data->do_malware_scan = false;
}
}
return data->do_dlp_scan || data->do_malware_scan;
}
// static
void DeepScanningDialogDelegate::ShowForWebContents(
content::WebContents* web_contents,
Data data,
CompletionCallback callback,
base::Optional<DeepScanAccessPoint> access_point) {
Factory* testing_factory = GetFactoryStorage();
bool wait_for_verdict = WaitForVerdict();
// Using new instead of std::make_unique<> to access non public constructor.
auto delegate = testing_factory->is_null()
? std::unique_ptr<DeepScanningDialogDelegate>(
new DeepScanningDialogDelegate(
web_contents, std::move(data),
std::move(callback), access_point))
: testing_factory->Run(web_contents, std::move(data),
std::move(callback));
bool work_being_done = delegate->UploadData();
// Only show UI if work is being done in the background, the user must
// wait for a verdict, and the UI feature is enabled.
bool show_ui = work_being_done && wait_for_verdict &&
base::FeatureList::IsEnabled(kDeepScanningOfUploadsUI);
// If the UI is enabled, create the modal dialog.
if (show_ui) {
DeepScanningDialogDelegate* delegate_ptr = delegate.get();
bool is_file_scan = !delegate_ptr->data_.paths.empty();
delegate_ptr->dialog_ =
new DeepScanningDialogViews(std::move(delegate), web_contents,
std::move(access_point), is_file_scan);
return;
}
if (!wait_for_verdict || !work_being_done) {
// The UI will not be shown but the policy is set to not wait for the
// verdict, or no scans need to be performed. Inform the caller that they
// may proceed.
//
// Supporting "wait for verdict" while not showing a UI makes writing tests
// for callers of this code easier.
delegate->FillAllResultsWith(true);
delegate->RunCallback();
}
// Upload service callback will delete the delegate.
if (work_being_done)
delegate.release();
}
// static
void DeepScanningDialogDelegate::SetFactoryForTesting(Factory factory) {
*GetFactoryStorage() = factory;
}
DeepScanningDialogDelegate::DeepScanningDialogDelegate(
content::WebContents* web_contents,
Data data,
CompletionCallback callback,
base::Optional<DeepScanAccessPoint> access_point)
: web_contents_(web_contents),
data_(std::move(data)),
callback_(std::move(callback)),
access_point_(access_point) {
DCHECK(web_contents_);
result_.text_results.resize(data_.text.size(), false);
result_.paths_results.resize(data_.paths.size(), false);
file_info_.resize(data_.paths.size());
}
void DeepScanningDialogDelegate::StringRequestCallback(
BinaryUploadService::Result result,
DeepScanningClientResponse response) {
int64_t content_size = 0;
for (const base::string16& entry : data_.text)
content_size += (entry.size() * sizeof(base::char16));
if (access_point_.has_value()) {
RecordDeepScanMetrics(access_point_.value(),
base::TimeTicks::Now() - upload_start_time_,
content_size, result, response);
}
MaybeReportDeepScanningVerdict(
Profile::FromBrowserContext(web_contents_->GetBrowserContext()),
web_contents_->GetLastCommittedURL(), "Text data", std::string(),
"text/plain",
extensions::SafeBrowsingPrivateEventRouter::kTriggerWebContentUpload,
content_size, result, response);
text_request_complete_ = true;
bool text_complies = ResultShouldAllowDataUse(result) &&
DlpTriggeredRulesOK(response.dlp_scan_verdict());
std::fill(result_.text_results.begin(), result_.text_results.end(),
text_complies);
MaybeCompleteScanRequest();
}
void DeepScanningDialogDelegate::CompleteFileRequestCallback(
size_t index,
base::FilePath path,
BinaryUploadService::Result result,
DeepScanningClientResponse response,
std::string mime_type) {
MaybeReportDeepScanningVerdict(
Profile::FromBrowserContext(web_contents_->GetBrowserContext()),
web_contents_->GetLastCommittedURL(), path.AsUTF8Unsafe(),
base::HexEncode(file_info_[index].sha256.data(),
file_info_[index].sha256.size()),
mime_type, extensions::SafeBrowsingPrivateEventRouter::kTriggerFileUpload,
file_info_[index].size, result, response);
bool dlp_ok = DlpTriggeredRulesOK(response.dlp_scan_verdict());
bool malware_ok = true;
if (response.has_malware_scan_verdict()) {
malware_ok = response.malware_scan_verdict().status() ==
MalwareDeepScanningVerdict::SUCCESS &&
response.malware_scan_verdict().verdict() !=
MalwareDeepScanningVerdict::UWS &&
response.malware_scan_verdict().verdict() !=
MalwareDeepScanningVerdict::MALWARE;
}
bool file_complies = ResultShouldAllowDataUse(result) && dlp_ok && malware_ok;
result_.paths_results[index] = file_complies;
++file_result_count_;
MaybeCompleteScanRequest();
}
void DeepScanningDialogDelegate::FileRequestCallback(
base::FilePath path,
BinaryUploadService::Result result,
DeepScanningClientResponse response) {
// Find the path in the set of files that are being scanned.
auto it = std::find(data_.paths.begin(), data_.paths.end(), path);
DCHECK(it != data_.paths.end());
size_t index = std::distance(data_.paths.begin(), it);
if (access_point_.has_value()) {
RecordDeepScanMetrics(access_point_.value(),
base::TimeTicks::Now() - upload_start_time_,
file_info_[index].size, result, response);
}
base::PostTaskAndReplyWithResult(
FROM_HERE,
{base::ThreadPool(), base::TaskPriority::USER_VISIBLE, base::MayBlock()},
base::BindOnce(&GetFileMimeType, path),
base::BindOnce(&DeepScanningDialogDelegate::CompleteFileRequestCallback,
weak_ptr_factory_.GetWeakPtr(), index, path, result,
response));
}
bool DeepScanningDialogDelegate::UploadData() {
upload_start_time_ = base::TimeTicks::Now();
if (data_.do_dlp_scan) {
// Create a string data source based on all the text.
std::string full_text;
for (const auto& text : data_.text)
full_text.append(base::UTF16ToUTF8(text));
text_request_complete_ = full_text.empty();
if (!text_request_complete_) {
auto request = std::make_unique<StringSourceRequest>(
std::move(full_text),
base::BindOnce(&DeepScanningDialogDelegate::StringRequestCallback,
weak_ptr_factory_.GetWeakPtr()));
PrepareRequest(DlpDeepScanningClientRequest::WEB_CONTENT_UPLOAD,
request.get());
UploadTextForDeepScanning(std::move(request));
}
} else {
// Text data sent only for content compliance.
text_request_complete_ = true;
}
// Create a file request for each file.
for (size_t i = 0; i < data_.paths.size(); ++i) {
if (FileTypeSupported(data_.do_malware_scan, data_.do_dlp_scan,
data_.paths[i])) {
PrepareFileRequest(
data_.paths[i],
base::BindOnce(&DeepScanningDialogDelegate::AnalyzerCallback,
base::Unretained(this), i));
} else {
++file_result_count_;
result_.paths_results[i] = true;
// TODO(crbug/1013584): Handle unsupported types appropriately.
}
}
return !text_request_complete_ || file_result_count_ != data_.paths.size();
}
void DeepScanningDialogDelegate::PrepareFileRequest(base::FilePath path,
AnalyzeCallback callback) {
base::FilePath::StringType ext(path.FinalExtension());
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
if (ext == FILE_PATH_LITERAL(".zip")) {
auto analyzer = base::MakeRefCounted<SandboxedZipAnalyzer>(
path, std::move(callback), LaunchFileUtilService());
analyzer->Start();
} else if (ext == FILE_PATH_LITERAL(".rar")) {
auto analyzer = base::MakeRefCounted<SandboxedRarAnalyzer>(
path, std::move(callback), LaunchFileUtilService());
analyzer->Start();
} else {
std::move(callback).Run(safe_browsing::ArchiveAnalyzerResults());
}
}
void DeepScanningDialogDelegate::AnalyzerCallback(
int index,
const safe_browsing::ArchiveAnalyzerResults& results) {
bool contains_encrypted_parts = std::any_of(
results.archived_binary.begin(), results.archived_binary.end(),
[](const auto& binary) { return binary.is_encrypted(); });
// If the file contains encrypted parts and the user is not allowed to use
// them, fail the request.
if (contains_encrypted_parts) {
int state = g_browser_process->local_state()->GetInteger(
prefs::kAllowPasswordProtectedFiles);
BinaryUploadService::Result result =
state == ALLOW_UPLOADS || state == ALLOW_UPLOADS_AND_DOWNLOADS
? BinaryUploadService::Result::SUCCESS
: BinaryUploadService::Result::FILE_ENCRYPTED;
FileRequestCallback(data_.paths[index], result,
DeepScanningClientResponse());
return;
}
auto request = std::make_unique<FileSourceRequest>(
weak_ptr_factory_.GetWeakPtr(), data_.paths[index],
base::BindOnce(&DeepScanningDialogDelegate::FileRequestCallback,
weak_ptr_factory_.GetWeakPtr(), data_.paths[index]));
PrepareRequest(DlpDeepScanningClientRequest::FILE_UPLOAD, request.get());
UploadFileForDeepScanning(data_.paths[index], std::move(request));
}
void DeepScanningDialogDelegate::PrepareRequest(
DlpDeepScanningClientRequest::ContentSource trigger,
BinaryUploadService::Request* request) {
if (data_.do_dlp_scan) {
DlpDeepScanningClientRequest dlp_request;
dlp_request.set_content_source(trigger);
dlp_request.set_url(data_.url);
request->set_request_dlp_scan(std::move(dlp_request));
}
if (data_.do_malware_scan) {
MalwareDeepScanningClientRequest malware_request;
malware_request.set_population(
MalwareDeepScanningClientRequest::POPULATION_ENTERPRISE);
request->set_request_malware_scan(std::move(malware_request));
}
request->set_dm_token(GetDMToken(Profile::FromBrowserContext(
web_contents_->GetBrowserContext()))
.value());
}
void DeepScanningDialogDelegate::FillAllResultsWith(bool status) {
std::fill(result_.text_results.begin(), result_.text_results.end(), status);
std::fill(result_.paths_results.begin(), result_.paths_results.end(), status);
}
void DeepScanningDialogDelegate::UploadTextForDeepScanning(
std::unique_ptr<BinaryUploadService::Request> request) {
DCHECK_EQ(
DlpDeepScanningClientRequest::WEB_CONTENT_UPLOAD,
request->deep_scanning_request().dlp_scan_request().content_source());
BinaryUploadService* upload_service =
g_browser_process->safe_browsing_service()->GetBinaryUploadService(
Profile::FromBrowserContext(web_contents_->GetBrowserContext()));
if (upload_service)
upload_service->MaybeUploadForDeepScanning(std::move(request));
}
void DeepScanningDialogDelegate::UploadFileForDeepScanning(
const base::FilePath& path,
std::unique_ptr<BinaryUploadService::Request> request) {
DCHECK(
!data_.do_dlp_scan ||
(DlpDeepScanningClientRequest::FILE_UPLOAD ==
request->deep_scanning_request().dlp_scan_request().content_source()));
BinaryUploadService* upload_service =
g_browser_process->safe_browsing_service()->GetBinaryUploadService(
Profile::FromBrowserContext(web_contents_->GetBrowserContext()));
if (upload_service)
upload_service->MaybeUploadForDeepScanning(std::move(request));
}
bool DeepScanningDialogDelegate::CloseTabModalDialog() {
if (!dialog_)
return false;
auto is_true = [](bool x) { return x; };
bool success = std::all_of(result_.text_results.begin(),
result_.text_results.end(), is_true) &&
std::all_of(result_.paths_results.begin(),
result_.paths_results.end(), is_true);
dialog_->ShowResult(success);
return true;
}
void DeepScanningDialogDelegate::MaybeCompleteScanRequest() {
if (!text_request_complete_ || file_result_count_ < data_.paths.size())
return;
RunCallback();
if (!CloseTabModalDialog()) {
// No UI was shown. Delete |this| to cleanup.
delete this;
}
}
void DeepScanningDialogDelegate::RunCallback() {
if (!callback_.is_null())
std::move(callback_).Run(data_, result_);
}
void DeepScanningDialogDelegate::SetFileInfo(const base::FilePath& path,
std::string sha256,
int64_t size) {
auto it = std::find(data_.paths.begin(), data_.paths.end(), path);
DCHECK(it != data_.paths.end());
size_t index = std::distance(data_.paths.begin(), it);
file_info_[index].sha256 = std::move(sha256);
file_info_[index].size = size;
}
} // namespace safe_browsing
| [
"commit-bot@chromium.org"
] | commit-bot@chromium.org |
dfcc1d52ce46e564a408e97c0bc882ae73151283 | 48895fe9628b4a21a122242d31ab8099884a973b | /trunk/RacingCenter/libDataCore/src/cCar.cpp | 5d50cbf1279a03cb7105c565b02a9f269830960d | [] | no_license | blue5555/RacingCenter | b28f89d8fdb7666712512e660f0fd51dc1690711 | 4ca170423b8506ce35ca2c089769b9633c2d68df | refs/heads/master | 2021-01-21T17:29:16.226827 | 2017-07-02T17:15:16 | 2017-07-02T17:15:16 | 91,955,076 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,935 | cpp | #include <cCar.h>
#include "libDatabase/cDatabase.h"
#define BLICK_LEVEL 10
#define BLINK_TIME 2000
#define _FILENAME_ "cCar: "
using namespace RacingCenter;
cCar::cCar(const std::string& i_strName) :
cDatabaseCar(cDatabase::instance()->GetCar(i_strName))
,m_nLastFuelTimeStamp(0)
,m_nLastSendFlashLight(0)
,m_opConfig(cConfig::instance())
,m_eCarState(CARSTATE_NORMAL)
,m_f64FuelFactor(1.0)
{
Init();
}
cCar::~cCar()
{
}
void cCar::Init()
{
m_bDebug = m_opConfig->m_oDebugMessages.bCar;
m_nProgSpeed = m_n8Speed;
m_f64TankLevel = m_f64TankCapacity;
m_nLastFuelTimeStamp = 0;
m_nLastSendFlashLight = 0;
m_bIsInBox = false;
m_bFlashOn = false;
m_bBlinkInit = false;
}
tBool cCar::SetCarState(eCarState i_eCarState)
{
m_eCarState = i_eCarState;
return true;
}
eCarState cCar::GetCarState() const
{
return m_eCarState;
}
tBool cCar::SetFuelFactor(const tFloat64& i_f64FuelFactor)
{
m_f64FuelFactor = i_f64FuelFactor;
return true;
}
tBool cCar::UpdateBox(const bool i_bIsInBox, const tTimeStamp& i_oTimeStamp)
{
m_bIsInBox = i_bIsInBox;
return true;
}
tBool cCar::UpdateFuel(const sController& i_oController, const tTimeStamp& i_nTimeStamp)
{
if(m_nLastFuelTimeStamp == 0) {
m_nLastFuelTimeStamp = i_nTimeStamp;
} else {
if(!m_bIsInBox)
{
m_f64TankLevel -= m_f64FuelFactor * m_f64Consumption[i_oController.m_Speed] * static_cast<tFloat32>(i_nTimeStamp-m_nLastFuelTimeStamp) / (1000);
if(m_f64TankLevel < 0)
{
m_f64TankLevel = 0;
}
} else if(i_oController.m_Button && i_oController.m_Speed == 0 && m_bIsInBox) {
m_f64TankLevel += m_f64TankSpeed * (i_nTimeStamp-m_nLastFuelTimeStamp) / (1000);
if(m_f64TankLevel > m_f64TankCapacity)
{
m_f64TankLevel = m_f64TankCapacity;
}
}
tUInt8 nFuel = static_cast<tUInt8>( m_f64TankLevel / m_f64TankCapacity * 100 );
if(nFuel < 100 /* m_opConfig->m_oFuelConfig.nValueYellow*/)
{
if(m_nLastSendFlashLight == 0)
{
m_nLastSendFlashLight = i_nTimeStamp;
m_bFlashOn = true;
}
else if ( (i_nTimeStamp - m_nLastSendFlashLight) > BLINK_TIME )
{
m_nLastSendFlashLight = i_nTimeStamp;
m_bFlashOn = true;
}
}
else
{
m_bFlashOn = false;
}
}
m_nLastFuelTimeStamp = i_nTimeStamp;
return true;
}
tBool cCar::UpdateFuel(const tUInt& i_nFuelLevel, const tTimeStamp& i_nTimeStamp)
{
m_f64TankLevel = static_cast<tFloat64>(i_nFuelLevel);
m_f64TankCapacity = 15.0f;
return true;
}
tUInt cCar::GetSpeed() const
{
tUInt nSpeed = 0;
switch(m_eCarState)
{
case CARSTATE_NORMAL:
nSpeed = m_oSpeed[ static_cast<tUInt8>(15 * m_f64TankLevel / m_f64TankCapacity)];
break;
case CARSTATE_TIRE_DAMAGE:
nSpeed = 0;
break;
}
return nSpeed;
}
tBool cCar::UpdateProgSpeed(const tUInt8 i_nProgSpeed)
{
m_nProgSpeed = i_nProgSpeed;
return true;
}
tBool cCar::IsFlashing()
{
if(m_bFlashOn)
{
m_bFlashOn = false;
return true;
}
else
{
return false;
}
} | [
"xx@xx.de"
] | xx@xx.de |
415455728c583af1d9f3fe02e5c582c6285b01dc | 0d9076293349241af62d00eff4c4107e51426ea5 | /normal problems/tree/rebuild_tree.cpp | eab849f1d7e8fde433fbb97a90fb1b61c5b0d645 | [] | no_license | zonasse/Algorithm | f6445616d0cde04e5ef5f475e7f9c8ec68638dd0 | cda4ba606b66040a54c44d95db51220a2df47414 | refs/heads/master | 2020-03-23T12:12:00.525247 | 2019-08-10T03:42:53 | 2019-08-10T03:42:53 | 141,543,243 | 1 | 1 | null | null | null | null | GB18030 | C++ | false | false | 1,763 | cpp | #include <bits/stdc++.h>
using namespace std;
struct tNode{
int data;
tNode *left;
tNode *right;
tNode(int x):data(x),left(NULL),right(NULL){}
};
class Solution{
public:
//由先序遍历和中序遍历序列重建二叉树
tNode* rebuild_tree(vector<int> &preorder,vector<int> &inorder){
if(inorder.empty() || preorder.empty()){
return NULL;
}
tNode *ret = rebuild(preorder,0,preorder.size()-1,inorder,0,inorder.size()-1);
return ret;
}
tNode* rebuild(vector<int> &preorder,int preLeft,int preRight,
vector<int> &inorder,int inLeft,int inRight){
if(preLeft > preRight || inLeft > inRight){
return NULL;
}
tNode *newRoot = new tNode(preorder[preLeft]);
int idx;
for(idx = inLeft; idx <= inRight; ++idx){
if(preorder[preLeft] == inorder[idx]){
break;
}
}
int leftLen = idx-inLeft;
int rightLen = inRight-idx;
newRoot->left = rebuild(preorder,preLeft+1,preLeft+leftLen,inorder,inLeft,idx-1);
newRoot->right = rebuild(preorder,preRight-rightLen+1,preRight,inorder,idx+1,inRight);
return newRoot;
}
//对结果进行后序遍历
void postTravel(tNode *root){
if(!root){
return;
}
postTravel(root->left);
postTravel(root->right);
printf("%d ",root->data);
}
};
int main(){
Solution handle;
int preorder[] = {1,2,4,5,6,3,7};
int inorder[] = {4,2,5,6,1,3,7};
vector<int> pre_vec(preorder,preorder+7);
vector<int> in_vec(inorder,inorder+7);
tNode *root = handle.rebuild_tree(pre_vec,in_vec);
handle.postTravel(root);
return 0;
}
| [
"992903713@qq.com"
] | 992903713@qq.com |
e6f73337e4e3bc1619528a9e591d89a6bc14d165 | 4af428b2e0812ed4a56454952e365ac66e5166d0 | /Paparazzi_Gennady.cpp | c8a19681885ff5b45a4ff6fc17d6e9c3398eb1a3 | [] | no_license | harshit774/cpp | fb18f10290e13dae512e15b8e476db9e877343dc | c6a77d6a8329be33c2b2973c6855a61ae4810f1a | refs/heads/master | 2023-08-16T00:13:17.133627 | 2021-10-14T12:19:50 | 2021-10-14T12:19:50 | 367,886,289 | 3 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,220 | cpp | #include<bits/stdc++.h>
#include<cmath>
#define ll long long int
using namespace std;
int main()
{
ll t;cin>>t;
while(t--)
{
ll n;cin>>n;
//ll h[n];
vector<pair<ll,ll>> v;
vector<pair<ll,ll>> p;
for(int i=0;i<n;i++)
{
int s;cin>>s;
v.push_back({i+1,s});
}
if(n==2){
cout<<"1\n";continue;
}
p.push_back(v[0]);
p.push_back(v[1]);
ll ans=1;
ll sz=p.size();
for(int i=2;i<n;i++)
{
while(p.size()>1)
{
double s1=((double)p[sz-1].second - (double)p[sz-2].second)/((double)p[sz-1].first - (double)p[sz-2].first);
double s2=((double)v[i].second - (double)p[sz-1].second)/((double)v[i].first - (double)p[sz-1].first);
if(s1<=s2)
{
p.pop_back();
sz-=1;
}
else{
break;
}
}
p.push_back(v[i]);sz+=1;
ans=max(ans,p[sz-1].first - p[sz-2].first);
}
cout<< ans <<'\n';
}
return 0;
//cout<< int(ans) <<endl;
} | [
"harshitvarshney774@gmail.com"
] | harshitvarshney774@gmail.com |
6bb7dc51fdab02a2a850b7a96522d113faf1ad52 | 1901bdbaf57584e7c5ec21643db340f9d98d6807 | /training/src/compiler/training/base/loss/MSELoss.cpp | 4c22de7e9c5bac93a6d023d54d0a1acdaed891fc | [
"MIT"
] | permissive | huawei-noah/bolt | 2a4febe5f5cce64e3589c2782c489d59975eb6a3 | cf4ca8f8646a8e30ddf91c29a18743d75ac1c172 | refs/heads/master | 2023-08-28T13:36:34.815244 | 2023-06-12T01:24:41 | 2023-06-12T01:24:41 | 225,365,905 | 889 | 168 | MIT | 2023-06-12T01:24:42 | 2019-12-02T12:06:12 | C++ | UTF-8 | C++ | false | false | 3,516 | cpp | // Copyright (C) 2022. Huawei Technologies Co., Ltd. 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 "MSELoss.h"
#include "impl/MSELossCPU.h"
namespace raul
{
MSELoss::MSELoss(const Name& name, const LossParams& params, NetworkParameters& networkParameters)
: BasicLayer(name, "MSELoss", params, networkParameters)
, mIsFinal(params.mIsFinal)
{
auto prefix = mTypeName + "[" + mName + "::ctor]: ";
if (mInputs.size() != 2 && mInputs.size() != 3)
{
THROW(mTypeName, mName, "wrong number of input names");
}
if (mOutputs.size() != 1)
{
THROW(mTypeName, mName, "wrong number of output names");
}
mInputName = mInputs[0];
mLabelName = mInputs[1];
mOutputName = mOutputs[0];
DECLARE_IMPL(MSELoss, MSELossLayerCPU<MemoryManager>, MSELossLayerCPU<MemoryManagerFP16>)
if (params.reduction != LossParams::Reduction::None || mInputs.size() == 3)
{
LossParams paramsWrap = params;
paramsWrap.getOutputs()[0] = mOutputName / "Wrap";
mInputName = paramsWrap.getOutputs()[0];
wrapper = std::make_unique<LossWrapper<MSELoss>>(mName, paramsWrap, networkParameters);
mNetworkParams.mWorkflow.copyDeclaration(mName, mInputName, raul::Workflow::Usage::Forward, raul::Workflow::Mode::Read);
mNetworkParams.mWorkflow.copyDeclaration(mName, mInputName, mOutputName, DEC_FORW_WRIT_NOMEMOPT);
if (!mIsFinal)
{
mNetworkParams.mWorkflow.copyDeclaration(mName, mOutputName, mOutputName.grad(), DEC_BACK_READ);
mNetworkParams.mWorkflow.copyDeclaration(mName, mInputName, mInputName.grad(), DEC_BACK_WRIT_ZERO);
}
}
else
{
mNetworkParams.mWorkflow.copyDeclaration(mName, mInputName, raul::Workflow::Usage::ForwardAndBackward, raul::Workflow::Mode::Read);
mNetworkParams.mWorkflow.copyDec(mName, mInputName, mInputName.grad(), DEC_BACK_WRIT_ZERO);
mNetworkParams.mWorkflow.copyDeclaration(mName, mInputName, mOutputName, DEC_FORW_WRIT_NOMEMOPT);
mNetworkParams.mWorkflow.copyDeclaration(mName, mInputName, mOutputName.grad(), DEC_BACK_READ);
mNetworkParams.mWorkflow.copyDeclaration(mName, mLabelName, raul::Workflow::Usage::ForwardAndBackward, raul::Workflow::Mode::Read);
}
mDepth = mNetworkParams.mWorkflow.getDepth(mInputName);
mHeight = mNetworkParams.mWorkflow.getHeight(mInputName);
mWidth = mNetworkParams.mWorkflow.getWidth(mInputName);
}
} // namespace raul | [
"jianfeifeng@outlook.com"
] | jianfeifeng@outlook.com |
983689b537d7d61f4fac3c13ff1af526d1884c5f | f31de1a567b462dbefd658c1f9823c80b7637511 | /clients/sos-tests/reduce_in_place.cpp | a5a804f9c1d5c7c16d620695ca0f3b54e40e9d7b | [
"MIT"
] | permissive | jrmadsen/ROC_SHMEM | 505ad6fc927b1a7949b58cace9508b263aba7e30 | d83bc49f37b266576ce9775af9ce8c66e51ee85d | refs/heads/master | 2023-08-01T03:46:25.321511 | 2021-09-21T14:34:32 | 2021-09-21T14:34:32 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,367 | cpp | /*
* Copyright (c) 2017 Intel Corporation. All rights reserved.
* This software is available to you under the BSD license below:
*
* 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 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 <stdio.h>
#include <roc_shmem.hpp>
#define NELEM 10
int main(void)
{
int me, npes;
int errors = 0;
long *psync, *pwrk, *src;
roc_shmem_init();
me = roc_shmem_my_pe();
npes = roc_shmem_n_pes();
src = (long *) roc_shmem_malloc(NELEM * sizeof(long));
for (int i = 0; i < NELEM; i++)
src[i] = me;
psync = (long *) roc_shmem_malloc(ROC_SHMEM_REDUCE_SYNC_SIZE * sizeof(long));
for (int i = 0; i < ROC_SHMEM_REDUCE_SYNC_SIZE; i++)
psync[i] = ROC_SHMEM_SYNC_VALUE;
pwrk = (long *) roc_shmem_malloc((NELEM/2 + ROC_SHMEM_REDUCE_MIN_WRKDATA_SIZE) * sizeof(long));
roc_shmem_barrier_all();
roc_shmem_ctx_long_max_to_all(ROC_SHMEM_CTX_DEFAULT, src, src, NELEM, 0, 0, npes, pwrk, psync);
/* Validate reduced data */
for (int j = 0; j < NELEM; j++) {
long expected = npes-1;
if (src[j] != expected) {
printf("%d: Expected src[%d] = %ld, got src[%d] = %ld\n", me, j, expected, j, src[j]);
errors++;
}
}
roc_shmem_free(src);
roc_shmem_free(psync);
roc_shmem_free(pwrk);
roc_shmem_finalize();
return errors != 0;
}
| [
"Khaled.Hamidouche@amd.com"
] | Khaled.Hamidouche@amd.com |
41892212d342265a0a707f4acfde43705e01f0b4 | 9f63112ccc5c1a2083b7a90a5ab0c88be539f291 | /src/parser.cpp | c022049eec3cb9ff388c7a058352dcaeb0c78d94 | [] | no_license | JelixLi/Calculator | e41da26cea4db7f60c64d8743719c684ef7e72d5 | 235cca667d07723feb9b201ca96f23a4e03ed008 | refs/heads/master | 2020-03-27T11:24:22.069636 | 2018-08-28T17:50:09 | 2018-08-28T17:50:09 | 146,484,770 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,424 | cpp | #include <iostream>
#include <assert.h>
#include <ctype.h>
#include <cstdlib>
#include "parser.h"
using std::cin;
using std::cout;
using std::endl;
// Parser::Parser(Scanner &scanner,SymbolTable &symTab):_scanner(scanner),_symTab(symTab) {
// cout<<"Parser Created"<<endl;
// }
// Parser::~Parser() {
// cout<<"Destroying Parser"<<endl;
// }
// Status Parser::Eval() {
// cout<<"Parser Eval"<<endl;
// for(Etoken token=_scanner.Token();token!=tEnd;_scanner.Accept()) {
// token = _scanner.Token();
// switch(token) {
// case tMult:
// cout<<"Times\n";
// break;
// case tPlus:
// cout<<"Plus\n";
// break;
// case tNumber:
// cout<<"Number: "<<_scanner.Number()<<endl;
// break;
// case tEnd:
// cout<<"End\n";
// return stQuit;
// case tError:
// cout<<"Error\n";
// return stQuit;
// default:
// cout<<"Error: Bad Token\n";
// return stQuit;
// }
// }
// return stOK;
// }
Parser::Parser(Scanner &scanner,Store &store,FunctionTable &funTab,SymbolTable &symTab):_scanner(scanner),
_pTree(0),_status(stOK),_funTab(funTab),_store(store),_symTab(symTab){}
Parser::~Parser() {
delete _pTree;
}
Status Parser::Eval() {
Parse();
if(_status==stOK)
Execute();
else
_status=stQuit;
return _status;
}
void Parser::Execute() {
if(_pTree) {
double result = _pTree->Calc();
std::cout<<" "<<result<<std::endl;
}
}
void Parser::Parse() {
_pTree = Expr();
}
Node *Parser::Expr() {
Node *pNode = Term();
Etoken token = _scanner.Token();
if(token==tPlus) {
_scanner.Accept();
Node *pRight = Expr();
pNode = new AddNode(pNode,pRight);
} else if(token==tMinus) {
_scanner.Accept();
Node *pRight = Expr();
pNode = new SubNode(pNode,pRight);
} else if(token==tAssign) {
_scanner.Accept();
Node *pRight = Expr();
if(pNode->IsLvalue()) {
pNode = new AssignNode(pNode,pRight);
} else {
_status = stError;
delete pNode;
pNode = Expr();
}
}
return pNode;
}
Node *Parser::Term() {
Node *pNode=Factor();
if(_scanner.Token()==tMult) {
_scanner.Accept();
Node *pRight=Term();
pNode=new MultNode(pNode,pRight);
} else if(_scanner.Token()==tDivide) {
_scanner.Accept();
Node *pRight=Term();
pNode=new DivideNode(pNode,pRight);
}
return pNode;
}
Node *Parser::Factor() {
Node *pNode;
Etoken token=_scanner.Token();
if(token==tLParen) {
_scanner.Accept();
pNode=Expr();
if(_scanner.Token()!=tRParen)
_status=stError;
else
_scanner.Accept();
} else if(token==tNumber) {
pNode = new NumNode(_scanner.Number());
_scanner.Accept();
} else if(token==tIdent) {
int maxSymlen=100; //note here..
char strSymbol[maxSymlen];
int lenSym=maxSymlen;
_scanner.GetSymbolName(strSymbol,lenSym);
int id = _symTab.Find(strSymbol);
_scanner.Accept();
if(_scanner.Token()==tLParen) {
_scanner.Accept();
pNode = Expr();
if(_scanner.Token()==tRParen)
_scanner.Accept();
else
_status=stError;
if(id!=idNotFound && id<_funTab.Size()) {
pNode=new FunNode(_funTab.GetFun(id),pNode);
} else {
std::cout<<"Unknown function\"";
std::cout<<strSymbol<<"\"\n";
}
} else {
if(id==idNotFound)
id=_symTab.ForceAdd(strSymbol,lenSym);
pNode=new VarNode(id,_store);
}
} else if(token==tMinus) {
_scanner.Accept();
pNode = new UMinusNode(Factor());
} else {
_scanner.Accept();
_status=stError;
pNode=0;
}
return pNode;
}
| [
"1512510237@qq.com"
] | 1512510237@qq.com |
072a49fc107df59e2d891d98252427dc2b213abc | 1e415bc27eee0e78cd659c4cd319a61cff793da5 | /src/traderlib/apiclient/HitBTC/tickersdependenciesfactory.cpp | 7bbdecc2453c9352ad45d8f64998ba841dae42e9 | [
"MIT"
] | permissive | The-Software-Academy/Trader | c618852080d328276784e405f4b83e00d7672174 | 6a1dffe3fbbf3c7d6c89a517d1f3f1b995a20723 | refs/heads/master | 2020-09-05T12:38:39.850438 | 2019-11-11T10:04:30 | 2019-11-11T10:04:30 | 220,107,246 | 0 | 1 | MIT | 2019-11-11T10:04:31 | 2019-11-06T23:07:04 | null | UTF-8 | C++ | false | false | 839 | cpp | #include "tickersdependenciesfactory.hpp"
#include "tickersrequestbuilder.hpp"
#include "tickersresponsebuilder.hpp"
#include <core/apiclient/apirequestbuilder.hpp>
#include <core/apiclient/apiresponsebuilder.hpp>
namespace bitinvest {
namespace apiclient {
namespace hitbtc {
TickersDependenciesFactory::TickersDependenciesFactory()
{
}
const QSharedPointer<const core::apiclient::ApiRequestBuilder> TickersDependenciesFactory::getRequestBuilder() const
{
return QSharedPointer<TickersRequestBuilder>::create();
}
const QSharedPointer<const core::apiclient::ApiResponseBuilder> TickersDependenciesFactory::getResponseBuilder() const
{
return QSharedPointer<TickersResponseBuilder>::create();
}
core::apiclient::HttpMethod TickersDependenciesFactory::getHttpMethod() const
{
return &QNetworkAccessManager::get;
}
}
}
}
| [
"andrea.citrolo@disco.unimib.it"
] | andrea.citrolo@disco.unimib.it |
50150889dcd6f6c6af7f09ecf1983b529423ad37 | 259f2bc205bb1e1f4485ec42117f03cdcb085c6f | /acwing/矩阵连乘.cpp | b268eb08e5c389116265b29dd233078c832579f9 | [] | no_license | czjczj/Leetcode_Cplus | 346bf0a77b1481f4d1bc301ba21293488270da4e | 9fa8b5c7c27fb6b350d8859c51608c54fc6347f3 | refs/heads/master | 2020-07-04T16:33:48.542349 | 2019-12-30T06:21:08 | 2019-12-30T06:21:08 | 202,341,121 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 490 | cpp | /*
* Author:czj
* Time :2019/12/19 08:59
* Email :zj_cheng@csu.edu.cn
*/
#include <iostream>
#include <algorithm>
using namespace std;
int N = 4;
int a[] = {3,4,5,6,7};
int dp[N][N];
int dfs(int l, int r){
if(l==r)
return 0;
if(dp[l][r] != 0)
return dp[l][r];
for(int i=l; i<r; ++i){
int tmp = dfs(l,i)+dfs(i+1,r)+a[l-1]*a[i]*a[r];
dp[l][r] = max(dp[l][r], tmp)
}
return dp[l][r];
}
int main() {
cout<<dfs(1,4);
return 0;
}
| [
"2838588360@qq.com"
] | 2838588360@qq.com |
c1c76b80962f40d7d5712559058c5a3e269f2bbd | 7b5ce257b59af8b6c9c971103e242579b4bd1544 | /juliakernel/sandbox/qt_webkit/qt-qtwebkit-examples/examples/webkitwidgets/framecapture/framecapture.cpp | 0b3441c1470d3479c05de23bb2f01a710347b869 | [
"BSD-3-Clause"
] | permissive | ruslancheb/juliakernel | c6221deba7ce33072ea2383dfccca4da7895b6e4 | f458f21d8e6e533a21b0612fda340b692d610ae2 | refs/heads/master | 2021-03-12T23:34:21.469877 | 2014-08-11T17:44:08 | 2014-08-11T17:44:08 | 17,984,214 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 4,161 | cpp | /****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "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 Digia Plc and its Subsidiary(-ies) 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."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "framecapture.h"
#include <iostream>
FrameCapture::FrameCapture(): QObject(), m_percent(0)
{
connect(&m_page, SIGNAL(loadProgress(int)), this, SLOT(printProgress(int)));
connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool)));
}
void FrameCapture::load(const QUrl &url, const QString &outputFileName)
{
std::cout << "Loading " << qPrintable(url.toString()) << std::endl;
m_percent = 0;
int index = outputFileName.lastIndexOf('.');
m_fileName = (index == -1) ? outputFileName + ".png" : outputFileName;
m_page.mainFrame()->load(url);
m_page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
m_page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
m_page.setViewportSize(QSize(1024, 768));
}
void FrameCapture::printProgress(int percent)
{
if (m_percent >= percent)
return;
while (m_percent++ < percent)
std::cout << "#" << std::flush;
}
void FrameCapture::saveResult(bool ok)
{
std::cout << std::endl;
// crude error-checking
if (!ok) {
std::cerr << "Failed loading " << qPrintable(m_page.mainFrame()->url().toString()) << std::endl;
emit finished();
return;
}
// save each frame in different image files
saveFrame(m_page.mainFrame());
emit finished();
}
void FrameCapture::saveFrame(QWebFrame *frame)
{
static int frameCounter = 0;
QString fileName(m_fileName);
if (frameCounter) {
int index = m_fileName.lastIndexOf('.');
fileName = fileName.insert(index, "_frame" + QString::number(frameCounter));
}
QImage image(frame->contentsSize(), QImage::Format_ARGB32_Premultiplied);
image.fill(Qt::transparent);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::TextAntialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
frame->documentElement().render(&painter);
painter.end();
image.save(fileName);
++frameCounter;
foreach(QWebFrame *childFrame, frame->childFrames())
saveFrame(childFrame);
}
| [
"kuzminruslan@mail.ru"
] | kuzminruslan@mail.ru |
2325f9fe915e24300a08163a423c5c548e48ef59 | 3e69cf84f66b759301471c2adb2efd5290cf7ac3 | /DynamicProgramming/2_EditDistance.cpp | f9867256b934817be9cf56990293f44db0340d6e | [] | no_license | mayank-tripathik/Geeksforgeeks | 37c5f09ce1f4a5be380df70b3b770bbc9fe64ec5 | 4079aaa94b9c08960160a0bff61db81f0cd651fa | refs/heads/master | 2021-01-17T07:35:55.606124 | 2019-06-13T17:50:33 | 2019-06-13T17:50:33 | 83,764,060 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,238 | cpp | /*
* Given two strings str1 and str2 and below operations that can performed on str2. Find minimum number of edits (operations)
* required to convert one string to another. Three operations that are allowed are: Insert, Remove, Replace.
* All of the above operations are of equal cost.
* Example:
Input: str1 = "geek", str2 = "gesek"
Output: 1
We can convert str1 into str2 by inserting a 's'.
Input: str1 = "cat", str2 = "cut"
Output: 1
We can convert str1 into str2 by replacing 'a' with 'u'.
* Suppose we want to convert str2 to str1
* Think of base case. If one of the string is empty, then cost required is always equal to the length of other string. Why?
* because we can either add all the char of non empty string to empty string, or we can remove all chars of nonempty string to
* make it empty. Since cost of both removal and add is same!
* What about non empty strings? Well, their are two cases. Start from either left or right. Say right. So if their last chars
* are same, nothing to do, we can safely remove last chars of both and recur for the remaining string. Size of both thus
* decreases by 1.
* If the last chars are not same, we can use the three allowed operations to make them same. Suppose last char of both string1
* and string2 are char1 and char2 respectively. Three operations are:
* Replace: Replace char2 by char1, and remove the last chars of both which are equal now. Both string length decreases by 1.
* Remove: Remove last char2. This make string1 length same, but string2 length decreases by 1.
* Add: Add char1 at last index of string2, and remove last chars of both which are equal now. While size of string1 decreases,
* size of string2 effectively remains the same (first increases by one and then decreases)
* After applying one of the three operations(all of cost 1) on last chars of both strings, we can recur for the remaining
* strings and take minimum of the three cost we get.
* Time complexity? The time complexity of above solution is exponential. In worst case, we may end up doing O(3^m) operations.
* The worst case happens when none of characters of two strings match.
* Consider the two strings "abcd", "efgh". At every position, we have 3 choices: Insert, Update, Delete. This makes 3^n steps.
* If we draw recursive call graph, we can see that many subproblems are solved again and again,
* Since same suproblems are called again, this problem has Overlapping Subprolems property.
* So Edit Distance problem has both properties of a dynamic programming problem.
* Like other typical Dynamic Programming(DP) problems, recomputations of same subproblems can be avoided by constructing a
* temporary array that stores results of subpriblems.
* We can avoid using 2D array of size O(n*m) because we need only two rows at each stage.Two array will thus suffices.
* TC:O(m*n), Extra Space:O(2*n) if we just want length. Tracking requires whole matrix of size O(n*m)
* Application : Applications: There are many practical applications of edit distance algorithm, refer Lucene API for sample.
* Another example, display all the words in a dictionary that are near proximity to a given word\incorrectly spelled word.
*/
#include <bits/stdc++.h>
using namespace std;
int editDistanceRecursive(string str1, string str2, int i, int j){
// If first string is empty, only option is to remove all characters of second string
// Whose cost is equal to current size of second string
if(i<0)
return j+1;
// If second string is empty, only option is to add all characters of first string
// Whose cost is equal to current size of first string
else if(j<0)
return i+1;
// If last characters are same, recur for the remaining string
else if(str1[i]==str2[j])
return editDistanceRecursive(str1,str2,i-1,j-1);
// If last char are not same, apply all three operations and choose the one
// that uncurs minimum cost
else
return min(editDistanceRecursive(str1,str2,i-1,j-1),
min(editDistanceRecursive(str1,str2,i,j-1),editDistanceRecursive(str1,str2,i-1,j)))+1;
}
int editDistanceDP(string str1, string str2){
// Instead of having complete space of size O(n*m), we can just size two arrays, because all we want
// at any time is current and upper row.
vector<int> dpUpper(str1.size()+1);
vector<int> dpLower(str1.size()+1);
// Initialize first row. Since second string is empty here, cost will be equal to length of
// string at that index ((similar to first base case of above recursion))
for(int i=0;i<dpUpper.size();i++)
dpUpper[i]=i;
// Now start from first char of second string and go till last char of it
for(int k=0;k<str2.size();k++){
// dpLower[0] indicates first string with no characters being considered. Thus cost of
// converting from second string to first will be just removing all characters of second string
// which is equal to the current length of second string (similar to second base case of above recursion)
dpLower[0]=k+1;
// start from first character of first string and go till last
for(int j=1;j<dpUpper.size();j++){
// If current char of first string is equal to current char of second string, we can remove both of
// these chars and cost will be as same as the cost for two strings we get after after removing last chars
if(str2[k]==str1[j-1])
dpLower[j]=dpUpper[j-1];
// If last chars are not same
else{
// We can replace char2 by char 1, and after replacing we can remove both last chars
int replace=dpUpper[j-1];
// We can just remove char2
int remove=dpUpper[j];
// We can just add char1 at last index of string2 and them remove both last chars
int add=dpLower[j-1];
// Take minimum of all the three operations, +1 indicates cost of each operation
dpLower[j]=min(replace,min(remove,add))+1;
}
}
// Copy lower row to upper row
for(int j=0;j<dpUpper.size();j++){
dpUpper[j]=dpLower[j];
}
}
// return last value of lower of upper row(both will be same because of the last copy step)
return dpUpper[dpUpper.size()-1];
}
int main() {
int test;
cin>>test;
while(test--){
string str1,str2;
cin>>str1>>str2;
cout<<editDistanceDP(str1,str2)<<endl;
}
return 0;
}
| [
"noreply@github.com"
] | mayank-tripathik.noreply@github.com |
c9b1b011bf307c297ad65f3e71be5fea88e19436 | 859785282e385c49c7a6ad11a233e7f5a9d0c9e7 | /c++/Inorder-Successor-in-BST.cpp | 938a33cbc15b0599f26bd0eb7b25ac978c2af999 | [] | no_license | tejeswinegi/DSA-Solved-Problems | eaacfd939ef08208f73854c2bae2b4e739d6c4c5 | 9c4947fecea1f8b66ee2405c2d537961465ea479 | refs/heads/master | 2023-08-30T19:49:06.935389 | 2021-10-06T02:07:47 | 2021-10-06T02:07:47 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 341 | cpp | Node * inOrderSuccessor(Node *root, Node *x) {
if(root== NULL || x==NULL) return NULL;
Node* suc = NULL;
while(root != NULL) {
if(root->data > x->data) {
suc = root;
root = root->left;
}
else {
root = root->right;
}
}
return suc;
} | [
"nkits9@gmail.com"
] | nkits9@gmail.com |
e19d5e6fc5323fa724a6d4b3ef4b2ac059d02e64 | 8947812c9c0be1f0bb6c30d1bb225d4d6aafb488 | /01_Develop/libXMCocos2D-v3/Source/gui/UIWidgets/UILabelBMFont.cpp | 59b72210c08dba765a3355d6ad3ffd05eae4b1a8 | [
"MIT"
] | permissive | alissastanderwick/OpenKODE-Framework | cbb298974e7464d736a21b760c22721281b9c7ec | d4382d781da7f488a0e7667362a89e8e389468dd | refs/heads/master | 2021-10-25T01:33:37.821493 | 2016-07-12T01:29:35 | 2016-07-12T01:29:35 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,688 | cpp | /* -----------------------------------------------------------------------------------
*
* File UILabelBMFont.cpp
* Ported By Young-Hwan Mun
* Contact xmsoft77@gmail.com
*
* -----------------------------------------------------------------------------------
*
* Copyright (c) 2010-2014 XMSoft
* Copyright (c) 2013 cocos2d-x.org
*
* 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.
*
* --------------------------------------------------------------------------------- */
#include "gui/UIWidgets/UILabelBMFont.h"
namespace gui {
UILabelBMFont::UILabelBMFont():
m_pLabelBMFontRenderer(nullptr),
m_bFntFileHasInit(false),
m_sFntFileName(""),
m_sStringValue("")
{
}
UILabelBMFont::~UILabelBMFont()
{
}
UILabelBMFont* UILabelBMFont::create()
{
UILabelBMFont* widget = new UILabelBMFont();
if (widget && widget->init())
{
widget->autorelease();
return widget;
}
CC_SAFE_DELETE(widget);
return nullptr;
}
void UILabelBMFont::initRenderer()
{
UIWidget::initRenderer();
m_pLabelBMFontRenderer = cocos2d::LabelBMFont::create();
m_pRenderer->addChild(m_pLabelBMFontRenderer);
}
void UILabelBMFont::setFntFile(const char *fileName)
{
if (!fileName || strcmp(fileName, "") == 0)
{
return;
}
m_sFntFileName = fileName;
m_pLabelBMFontRenderer->initWithString("", fileName);
updateAnchorPoint();
labelBMFontScaleChangedWithSize();
m_bFntFileHasInit = true;
setText(m_sStringValue.c_str());
}
void UILabelBMFont::setText(const char* value)
{
if (!value)
{
return;
}
m_sStringValue = value;
if (!m_bFntFileHasInit)
{
return;
}
m_pLabelBMFontRenderer->setString(value);
labelBMFontScaleChangedWithSize();
}
const char* UILabelBMFont::getStringValue()
{
return m_sStringValue.c_str();
}
void UILabelBMFont::setAnchorPoint(const cocos2d::Point &pt)
{
UIWidget::setAnchorPoint(pt);
m_pLabelBMFontRenderer->setAnchorPoint(pt);
}
void UILabelBMFont::onSizeChanged()
{
labelBMFontScaleChangedWithSize();
}
const cocos2d::Size& UILabelBMFont::getContentSize() const
{
return m_pLabelBMFontRenderer->getContentSize();
}
cocos2d::Node* UILabelBMFont::getVirtualRenderer()
{
return m_pLabelBMFontRenderer;
}
void UILabelBMFont::labelBMFontScaleChangedWithSize()
{
if (m_bIgnoreSize)
{
m_pLabelBMFontRenderer->setScale(1.0f);
m_tSize = m_pLabelBMFontRenderer->getContentSize();
}
else
{
cocos2d::Size textureSize = m_pLabelBMFontRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
m_pLabelBMFontRenderer->setScale(1.0f);
return;
}
float scaleX = m_tSize.width / textureSize.width;
float scaleY = m_tSize.height / textureSize.height;
m_pLabelBMFontRenderer->setScaleX(scaleX);
m_pLabelBMFontRenderer->setScaleY(scaleY);
}
}
const char* UILabelBMFont::getDescription() const
{
return "LabelBMFont";
}
UIWidget* UILabelBMFont::createCloneInstance()
{
return UILabelBMFont::create();
}
void UILabelBMFont::copySpecialProperties(UIWidget *widget)
{
UILabelBMFont* labelBMFont = dynamic_cast<UILabelBMFont*>(widget);
if (labelBMFont)
{
setFntFile(labelBMFont->m_sFntFileName.c_str());
setText(labelBMFont->m_sStringValue.c_str());
}
}
} | [
"mcodegeeks@gmail.com"
] | mcodegeeks@gmail.com |
40bf0500bad0480a04eb94dad7efabd4b9e752d9 | 6c00103d9e292a79511771d3b3790c3bb0676df7 | /Greedy/Greedy.Florist.cpp | 5b419b3c89bb610a6788b30b628766edfadb6cd0 | [] | no_license | avinashw50w/Coding-problems | 8410388a2808d032617b6087de6422c87af6d524 | 9e6948cdf5de4d59483545562b3a536f13f5bbc6 | refs/heads/master | 2021-01-12T09:10:28.960488 | 2016-12-18T13:58:35 | 2016-12-18T13:58:35 | 76,782,911 | 0 | 0 | null | null | null | null | ISO-8859-1 | C++ | false | false | 2,217 | cpp | /* You and K-1K-1 friends want to buy NN flowers. Each flower fifi has some cost cici. The florist is greedy and wants to maximize his number of new customers, so he increases the sale price of flowers for repeat customers; more precisely, if a customer has already purchased xx flowers, price PP for fifi is Pfi=(x+1)×ciPfi=(x+1)×ci.
Find and print the minimum cost for your group to purchase NN flowers.
Note: You can purchase the flowers in any order.
Input Format
The first line contains two integers, NN (number of flowers to purchase) and KK (the size of your group of friends, including you).
The second line contains NN space-separated positive integers describing the cost (c0,c1,...,cN-2,cN-1c0,c1,...,cN-2,cN-1) for each flower fifi .
Constraints
1=N,K=1001=N,K=100
1=ci=1061=ci=106
answer<231answer<231
0=i=N-10=i=N-1
Output Format
Print the minimum cost for buying NN flowers.
Sample Input 0
3 3
2 5 6
Sample Output 0
13
Sample Input 1
3 2
2 5 6
Sample Output 1
15
Explanation
Sample Case 0:
There are 33 flowers and 33 people in your group. Each person buys one flower and the sum of prices paid is 1313 dollars, so we print 1313.
Sample Case 1:
There are 33 flowers and 22 people in your group. The first person purchases 22 flowers, f0f0 and f1f1, in order of decreasing price;
this means they buy the more expensive flower first at price Pf1=(0+1)×5=5 dollarsPf1=(0+1)×5=5 dollars and the less expensive flower second
at price Pf0=(1+1)×2=4 dollarsPf0=(1+1)×2=4 dollars. The second person buys the most expensive flower at price Pf2=(0+1)×6=6
dollarsPf2=(0+1)×6=6 dollars. We print the sum of these purchases (5+4+65+4+6), which is 1515. */
#include<iostream>
#include <algorithm>
using namespace std;
int solve(int c[],int n,int k){
int sum=0;
sort(c,c+n,greater<int>());
int x=0,i=0;
while(i<n){
for(int j=i;j<i+k && j<n;j++){
sum+=(x+1)*c[j];
}
i+=k;
x++;
}
return sum;
}
int main(void){
//Helpers for input and output
int N, K;
cin >> N >> K;
int C[N];
for(int i = 0; i < N; i++){
cin >> C[i];
}
int result=solve(C,N,K);
cout << result << "\n";
return 0;
}
| [
"avinashw50w@gmail.com"
] | avinashw50w@gmail.com |
a0145ea14ce1afb14cfdc19e63465d635e14e80c | add9e7e72ca98aa21817ebe25d856cb7e2d6888e | /lab5/src/DLoad/Vector.hpp | b6e6b2ad768344d0b89cda4be1b1e15e1d27a161 | [] | no_license | AlexN1ght/sem3os | 195e04c2d0c78620dc29227114fe8c17d42d8e37 | e6598878993903cc37a4efa6e1f0f72816a93599 | refs/heads/master | 2020-08-05T06:49:51.693592 | 2019-12-30T10:04:29 | 2019-12-30T10:04:29 | 212,436,561 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 764 | hpp | #ifndef __vector_h__
#define __vector_h__
#include <iostream>
#include <algorithm>
#include <cassert>
using value_type = int;
using iterator = value_type*;
typedef struct vector {
int already_used_;
int storage_size_;
value_type* storage_;
} vector;
extern "C" vector* vector_create();
vector* vector_create_n(int size, const value_type& default_value = value_type());
int vector_size(vector* in);
bool vector_is_empty(vector* in);
iterator vector_begin(vector* in);
iterator vector_end(vector* in);
void vector_swap(vector* lhs, vector* rhs);
extern "C" void vector_destroy(vector** in);
extern "C" void vector_push_back(vector* in, const value_type& value);
extern "C" value_type& vector_at(vector* in, int index);
#endif
| [
"alexiscom@icloud.com"
] | alexiscom@icloud.com |
d6558d01c77e9e1155eb29bf9464bf8ab79e8046 | c0f7050daec2fea7592d418498e8d2cb69aa8074 | /src/test/DemoEchoClient.cpp | c1fabf487136e00f25e085d2a502fe303d259eab | [] | no_license | bdgong/netsimul | b4cefe45938144aede9b2e62939d92ddb078b59b | 52d7994c986dbb06c8a448382fabba7eed185b0e | refs/heads/master | 2022-04-18T13:34:37.019713 | 2018-06-21T02:58:00 | 2018-06-21T02:58:00 | 258,258,790 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,355 | cpp |
/*
* DemoEchoClient - TCP Demo
*
* Send something like "hello" to echo server, print the reply.
* */
#include <cstdio>
#include <cstring>
#include <string>
#include "Socket.h"
const char * const cDstAddrStr = "211.67.27.254";
const unsigned short cDstPort = 2333;
void usage(const char *appName)
{
printf("Default address use %s:%d\n", cDstAddrStr, cDstPort);
printf("To change it use addtional parameters:\n\t%s <ip> <port>\n", appName);
printf("\n----------\n\n");
}
int main(int argc, char *argv[])
{
usage(argv[0]);
// create a socket
CSocket socket;
int sockfd;
if ( (sockfd = socket.socket(AF_INET, SOCK_STREAM, 0)) <= 0) {
fprintf(stderr, "Failed socket().\n");
return -1;
}
// set server address
struct sockaddr_in svrAddr;
svrAddr.sin_family = AF_INET;
char svrAddrStr[20];
unsigned short svrPort;
strncpy(svrAddrStr, cDstAddrStr, strlen(cDstAddrStr) + 1);
svrPort = cDstPort;
if (argc > 1) {
strncpy(svrAddrStr, argv[1], strlen(argv[1]) + 1);
}
if (argc > 2) {
svrPort = std::stoi(argv[2]);
}
if (inet_aton(svrAddrStr, &svrAddr.sin_addr) <= 0) {
fprintf(stderr, "Invalid address: %s\n", svrAddrStr);
return -1;
}
svrAddr.sin_port = htons(svrPort);
printf("Target %s:%d.\n", svrAddrStr, svrPort);
// connect
printf("Connecting server...");
int success = socket.connect((const sockaddr*)&svrAddr, sizeof(svrAddr));
if (success != -1) {
// send
printf("connected, will send 'hello'.\n");
const char *text = "hello";
int len = strlen(text);
int byteSend = socket.send(text, len, 0);
if (byteSend > 0) {
printf("Send out 'hello'.\n");
char buf[1024 + 1];
socklen_t socklen = sizeof(svrAddr);
printf("Receiving...\n");
int byteRecv = socket.recv(buf, 1024, 0);
if (byteRecv > 0) {
buf[byteRecv] = '\0';
printf("received: %s\n", buf);
}
else {
printf("failed recv().\n");
}
}
else {
printf("Send out 'hello' failed.\n");
}
socket.close();
}
else {
printf("failed connect().\n");
}
return 0;
}
| [
"bardongong@163.com"
] | bardongong@163.com |
0984afce1f8175ca41acdd11b20bbb91a402db44 | d450535426fa0ee9c1616d76a2268dae065b70a0 | /src/YarnBall.cpp | f9c7d503257db01d6f8fbc3b912856541b37b0b8 | [] | no_license | pestalella/yarnball | 0dd14a797a49a12dc7319a753d1e5d38d0b198c7 | fcffda18a9be98a85a92930dab92c21327617cd8 | refs/heads/main | 2023-03-26T00:52:31.700760 | 2021-03-16T20:53:57 | 2021-03-16T20:53:57 | 330,376,992 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 12,742 | cpp | #ifdef _WIN32
#include <Windows.h>
#endif
#include "Point.h"
#include "YarnBall.h"
#include <GL/gl.h>
#include <fstream>
#include <iostream>
#include <cmath>
#include <sstream>
YarnBall::YarnBall() :
lineWidth(1)
{
}
void YarnBall::setupRender()
{
std::vector<float>().swap(interleavedVertices);
std::size_t count = vertCoords.size();
for (size_t i = 0; i < count; i += 3) {
// Positions
interleavedVertices.push_back(vertCoords[i]);
interleavedVertices.push_back(vertCoords[i+1]);
interleavedVertices.push_back(vertCoords[i+2]);
// Normals
interleavedVertices.push_back(vertCoords[i]);
interleavedVertices.push_back(vertCoords[i+1]);
interleavedVertices.push_back(vertCoords[i+2]);
// Colors
interleavedVertices.push_back(vertColors[i]);
interleavedVertices.push_back(vertColors[i+1]);
interleavedVertices.push_back(vertColors[i+2]);
}
std::vector<float>().swap(interleavedLineVertices);
for (size_t i = 0; i < lineVertCoords.size(); i += 3) {
// Positions
interleavedLineVertices.push_back(lineVertCoords[i]);
interleavedLineVertices.push_back(lineVertCoords[i+1]);
interleavedLineVertices.push_back(lineVertCoords[i+2]);
// Colors
interleavedLineVertices.push_back(lineVertColors[i]);
interleavedLineVertices.push_back(lineVertColors[i+1]);
interleavedLineVertices.push_back(lineVertColors[i+2]);
}
}
std::vector<float> divideTri(
float x0, float y0,
float x1, float y1,
float x2, float y2)
{
std::vector<float> subTris;
const float eps = 5.0;
if (std::abs(x1 - x0) > eps ||
std::abs(y1 - y0) > eps ||
std::abs(x2 - x0) > eps ||
std::abs(y2 - y0) > eps ||
std::abs(x2 - x1) > eps ||
std::abs(y2 - y1) > eps)
{
float x01 = 0.5*(x0+x1);
float y01 = 0.5*(y0+y1);
float x02 = 0.5*(x0+x2);
float y02 = 0.5*(y0+y2);
float x12 = 0.5*(x2+x1);
float y12 = 0.5*(y2+y1);
std::vector<float> sub0 = divideTri(x0, y0, x01, y01, x02, y02);
std::vector<float> sub1 = divideTri(x01, y01, x1, y1, x12, y12);
std::vector<float> sub2 = divideTri(x02, y02, x12, y12, x2, y2);
std::vector<float> sub3 = divideTri(x01, y01, x12, y12, x02, y02);
subTris.insert(subTris.end(), sub0.begin(), sub0.end());
subTris.insert(subTris.end(), sub1.begin(), sub1.end());
subTris.insert(subTris.end(), sub2.begin(), sub2.end());
subTris.insert(subTris.end(), sub3.begin(), sub3.end());
} else {
subTris.push_back(x0);
subTris.push_back(y0);
subTris.push_back(x1);
subTris.push_back(y1);
subTris.push_back(x2);
subTris.push_back(y2);
}
return subTris;
}
struct TriangleMesh {
std::vector<Vec3> vertices;
std::vector<int> indices;
};
// TriangleMesh meshSubdivide(const Vec3 &v0, const Vec3 &v1, const Vec3 &v2, int subdivLevel)
// {
// TriangleMesh mesh;
// // std::vector<Vec3> subTris;
// if (subdivLevel > 0) {
// Vec3 m01 = (v0 + v1)*0.5f;
// Vec3 m02 = (v0 + v2)*0.5f;
// Vec3 m12 = (v1 + v2)*0.5f;
// m01 = m01*(1.0f/sqrt(m01*m01)) * v0.len();
// m02 = m02*(1.0f/sqrt(m02*m02)) * v2.len();
// m12 = m12*(1.0f/sqrt(m12*m12)) * v1.len();
// TriangleMesh sub0 = meshSubdivide(v0, m01, m02, subdivLevel - 1);
// TriangleMesh sub1 = meshSubdivide(m01, v1, m12, subdivLevel - 1);
// TriangleMesh sub2 = meshSubdivide(m02, m12, v2, subdivLevel - 1);
// TriangleMesh sub3 = meshSubdivide(m01, m12, m02, subdivLevel - 1);
// subTris.insert(subTris.end(), sub0.begin(), sub0.end());
// subTris.insert(subTris.end(), sub1.begin(), sub1.end());
// subTris.insert(subTris.end(), sub2.begin(), sub2.end());
// subTris.insert(subTris.end(), sub3.begin(), sub3.end());
// } else {
// subTris.push_back(v0);
// subTris.push_back(v1);
// subTris.push_back(v2);
// }
// return mesh;
// // return subTris;
// }
std::vector<Vec3> subdivide(const Vec3 &v0, const Vec3 &v1, const Vec3 &v2, int subdivLevel)
{
std::vector<Vec3> subTris;
if (subdivLevel > 0) {
Vec3 m01 = (v0 + v1)*0.5f;
Vec3 m02 = (v0 + v2)*0.5f;
Vec3 m12 = (v1 + v2)*0.5f;
m01 = m01*(1.0f/sqrt(m01*m01)) * v0.len();
m02 = m02*(1.0f/sqrt(m02*m02)) * v2.len();
m12 = m12*(1.0f/sqrt(m12*m12)) * v1.len();
std::vector<Vec3> sub0 = subdivide(v0, m01, m02, subdivLevel - 1);
std::vector<Vec3> sub1 = subdivide(m01, v1, m12, subdivLevel - 1);
std::vector<Vec3> sub2 = subdivide(m02, m12, v2, subdivLevel - 1);
std::vector<Vec3> sub3 = subdivide(m01, m12, m02, subdivLevel - 1);
subTris.insert(subTris.end(), sub0.begin(), sub0.end());
subTris.insert(subTris.end(), sub1.begin(), sub1.end());
subTris.insert(subTris.end(), sub2.begin(), sub2.end());
subTris.insert(subTris.end(), sub3.begin(), sub3.end());
} else {
subTris.push_back(v0);
subTris.push_back(v1);
subTris.push_back(v2);
}
return subTris;
}
std::vector<Vec3> subdivideLine(const Vec3 &v0, const Vec3 &v1, int subdivLevel)
{
std::vector<Vec3> subLines;
if (subdivLevel > 0) {
Vec3 m01 = (v0 + v1)*0.5f;
m01 = m01*(v0.len()/sqrt(m01*m01));
std::vector<Vec3> sub0 = subdivideLine(v0, m01, subdivLevel - 1);
std::vector<Vec3> sub1 = subdivideLine(m01, v1, subdivLevel - 1);
subLines.insert(subLines.end(), sub0.begin(), sub0.end());
subLines.insert(subLines.end(), sub1.begin(), sub1.end());
} else {
subLines.push_back(v0);
subLines.push_back(v1);
}
return subLines;
}
std::vector<Vec3> createWideLine(const Vec3 &p0, const Vec3 &p1, float width)
{
Vec3 yDir = (p1-p0).normalized();
Vec3 zDir = p0.normalized();
Vec3 xDir = (yDir^zDir).normalized();
float halfWidth = width*0.5;
Vec3 bottomLeft = p0 - xDir*halfWidth;
Vec3 bottomRight = p0 + xDir*halfWidth;
Vec3 topLeft = p1 - xDir*halfWidth;
Vec3 topRight = p1 + xDir*halfWidth;
return std::vector<Vec3>({bottomLeft, bottomRight, topLeft, bottomRight, topRight, topLeft});
}
YarnBall YarnBall::fromFile(std::string fileName, int subdivLevel, int lineWidth)
{
std::ifstream inFile(fileName);
if (!inFile) {
std::cerr << "Couldn't open file [" << fileName << "]" << std::endl;
return YarnBall();
}
YarnBall ball;
std::string line;
// Read color palette
std::vector<float> palette(256*3);
int numColors = 0;
while (std::getline(inFile, line)) {
std::istringstream iss(line);
float r, g, b;
int idx;
if (iss >> idx >> r >> g >> b) {
palette[3*idx + 0] = r;
palette[3*idx + 1] = g;
palette[3*idx + 2] = b;
numColors++;
} else {
break;
}
}
std::cout << "Loaded " << numColors << " colors" << std::endl;
// Read colored triangles
std::vector<Vec3> triVerts;
std::vector<int> triColors;
int numTris = 0;
while (std::getline(inFile, line)) {
std::istringstream iss(line);
float x0, y0, z0, x1, y1, z1, x2, y2, z2;
int col;
if (iss >> x0 >> y0 >> z0 >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> col) {
triVerts.push_back(Vec3(x0,y0,z0));
triVerts.push_back(Vec3(x1,y1,z1));
triVerts.push_back(Vec3(x2,y2,z2));
triColors.push_back(col);
numTris += 1;
} else {
break;
}
}
// Read colored lines
std::vector<Vec3> lineVerts;
std::vector<int> lineColors;
int numLines = 0;
while (std::getline(inFile, line)) {
std::istringstream iss(line);
float x0, y0, z0, x1, y1, z1;
int col;
if (iss >> x0 >> y0 >> z0 >> x1 >> y1 >> z1 >> col) {
// std::vector<Vec3> wideLine = createWideLine(Vec3(x0,y0, z0)*1.01, Vec3(x1, y1, z1)*1.01, lineWidth);
// triVerts.insert(triVerts.end(), wideLine.begin(), wideLine.end());
// triColors.push_back(col);
// triColors.push_back(col);
// numTris += 2;
lineVerts.push_back(Vec3(x0,y0,z0)*1.01);
lineVerts.push_back(Vec3(x1,y1,z1)*1.01);
lineColors.push_back(col);
numLines += 1;
} else {
break;
}
}
inFile.close();
std::cout << "Loaded " << numTris << " triangles and " << numLines << " lines" << std::endl;
// Create the geometry from the vertices in spherical coords and the
// color palette
for (int i = 0; i < numTris; ++i) {
// float r = 1;
// float g = 0;
// float b = 1;
float r = palette[triColors[i]*3 + 0];
float g = palette[triColors[i]*3 + 1];
float b = palette[triColors[i]*3 + 2];
// Sanity checking
Vec3 v01 = triVerts[3*i + 1] - triVerts[3*i + 0];
Vec3 v12 = triVerts[3*i + 2] - triVerts[3*i + 1];
Vec3 v20 = triVerts[3*i + 0] - triVerts[3*i + 2];
Vec3 n0 = v20^v01;
Vec3 n1 = v01^v12;
Vec3 n2 = v12^v20;
if (triVerts[3*i + 0]*n0 < 0.0 ||
triVerts[3*i + 1]*n1 < 0.0 ||
triVerts[3*i + 2]*n2 < 0.0) {
std::swap(triVerts[3*i + 0], triVerts[3*i + 1]);
}
std::vector<Vec3> subTris = subdivide(triVerts[3*i + 0], triVerts[3*i + 1], triVerts[3*i + 2], subdivLevel);
for (size_t subTri = 0; subTri < subTris.size(); subTri += 3) {
for (int j = 0; j < 3; ++j) {
ball.vertIndices.push_back(ball.vertCoords.size()/3);
ball.vertCoords.push_back(subTris[subTri + j].x);
ball.vertCoords.push_back(subTris[subTri + j].y);
ball.vertCoords.push_back(subTris[subTri + j].z);
ball.vertColors.push_back(r);
ball.vertColors.push_back(g);
ball.vertColors.push_back(b);
}
}
}
for (int curLine = 0; curLine < numLines; curLine++) {
float r = palette[lineColors[curLine]*3 + 0];
float g = palette[lineColors[curLine]*3 + 1];
float b = palette[lineColors[curLine]*3 + 2];
std::vector<Vec3> subLines = subdivideLine(lineVerts[2*curLine + 0], lineVerts[2*curLine + 1], subdivLevel);
for (size_t subLine = 0; subLine < subLines.size(); subLine += 2) {
for (int j = 0; j < 2; ++j) {
ball.lineVertIndices.push_back(ball.lineVertCoords.size()/3);
ball.lineVertCoords.push_back(subLines[subLine + j].x);
ball.lineVertCoords.push_back(subLines[subLine + j].y);
ball.lineVertCoords.push_back(subLines[subLine + j].z);
ball.lineVertColors.push_back(r);
ball.lineVertColors.push_back(g);
ball.lineVertColors.push_back(b);
}
}
}
ball.lineWidth = lineWidth;
ball.setupRender();
return ball;
}
void YarnBall::draw()
{
if (interleavedVertices.empty()) return;
// interleaved array
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 36, &interleavedVertices[0]);
glNormalPointer(GL_FLOAT, 36, &interleavedVertices[3]);
glColorPointer(3, GL_FLOAT, 36, &interleavedVertices[6]);
glDrawElements(GL_TRIANGLES, (unsigned int)vertIndices.size(), GL_UNSIGNED_INT, vertIndices.data());
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisable(GL_LIGHTING);
glLineWidth(lineWidth);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 24, &interleavedLineVertices[0]);
glColorPointer(3, GL_FLOAT, 24, &interleavedLineVertices[3]);
glDrawElements(GL_LINES, (unsigned int)lineVertIndices.size(), GL_UNSIGNED_INT, lineVertIndices.data());
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
// glEnable(GL_LIGHTING);
}
| [
"pau.estalella@gmail.com"
] | pau.estalella@gmail.com |
6a4a540cbcd642d9e9d016cfcdca57c9c7f25ed8 | 73c02a45f06bf472dc8debad2b5ab56caeb7c38a | /Common/include/Vector3.h | 47ceecf2781b025c2dd7014362e030879ba765ba | [
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | mrkline/Core-Game-Engine | df814ba03091a1ca2d8ebf1a152a9426d3ee295d | 9c8fcb4c01f3f86a63fb6f3dbcbe6648d5fb11f1 | refs/heads/master | 2021-01-20T02:16:23.988882 | 2020-07-02T05:05:17 | 2020-07-02T05:05:51 | 2,075,337 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,606 | h | #pragma once
#include <string>
#include "CoreMath.h"
namespace Core
{
//! A three-dimensional vector using floats for each dimension
class Vector3
{
public:
float X;
float Y;
float Z;
//! Initializes vector to zero
Vector3() : X(0.0f), Y(0.0f), Z(0.0f) {}
//! Initializes vector to provided x, y, and z values
Vector3(float x, float y, float z) : X(x), Y(y), Z(z) {}
//! Initializes x, y, and z values to v
explicit Vector3(float v) : X(v), Y(v), Z(v) {}
//! Initializes vector with a provided vector's values
Vector3(const Vector3& o) : X(o.X), Y(o.Y), Z(o.Z) {}
//! Initializes vector with the first three values in the provided array
explicit Vector3(float* arr) : X(arr[0]), Y(arr[1]), Z(arr[2]) {}
Vector3 operator-() const { return Vector3(-X, -Y, -Z); }
Vector3& operator=(const Vector3& o) { X = o.X; Y = o.Y; Z = o.Z; return *this; }
Vector3 operator+(const Vector3& o) const { return Vector3(X + o.X, Y + o.Y, Z + o.Z); }
Vector3& operator +=(const Vector3& o) { X += o.X; Y += o.Y; Z += o.Z; return *this; }
Vector3 operator+(float v) const { return Vector3(X + v, Y + v, Z + v); }
Vector3& operator+=(float v) { X += v; Y += v; Z += v; return *this; }
Vector3 operator-(const Vector3& o) const { return Vector3(X - o.X, Y - o.Y, Z - o.Z); }
Vector3& operator -=(const Vector3& o) { X -= o.X; Y -= o.Y; Z -= o.Z; return *this; }
Vector3 operator-(float v) const { return Vector3(X - v, Y - v, Z - v); }
Vector3& operator-=(float v) { X -= v; Y -= v; Z -= v; return *this; }
//! Comparison operators can be used to sort vectors with respect to X, then Y, then Z
bool operator<=(const Vector3& o) const
{
return (X < o.X || Math::Equals(X, o.X)) ||
(Math::Equals(X, o.X) && (Y < o.Y || Math::Equals(Y, o.Y))) ||
(Math::Equals(X, o.X) && Math::Equals(Y, o.Y) && (Z < o.Z || Math::Equals(Z, o.Z)));
}
//! Comparison operators can be used to sort vectors with respect to X, then Y, then Z
bool operator>=(const Vector3& o) const
{
return (X > o.X || Math::Equals(X, o.X)) ||
(Math::Equals(X, o.X) && (Y > o.Y || Math::Equals(Y, o.Y))) ||
(Math::Equals(X, o.X) && Math::Equals(Y, o.Y) && (Z > o.Z || Math::Equals(Z, o.Z)));
}
//! Comparison operators can be used to sort vectors with respect to X, then Y, then Z
bool operator<(const Vector3& o) const
{
return (X < o.X && !Math::Equals(X, o.X)) ||
(Math::Equals(X, o.X) && Y < o.Y && !Math::Equals(Y, o.Y)) ||
(Math::Equals(X, o.X) && Math::Equals(Y, o.Y) && Z < o.Z && !Math::Equals(Z, o.Z));
}
//! Comparison operators can be used to sort vectors with respect to X, then Y, then Z
bool operator>(const Vector3& o) const
{
return (X > o.X && !Math::Equals(X, o.X)) ||
(Math::Equals(X, o.X) && Y > o.Y && !Math::Equals(Y, o.Y)) ||
(Math::Equals(X, o.X) && Math::Equals(Y, o.Y) && Z > o.Z && !Math::Equals(Z, o.Z));
}
/*!
\brief Checks equality using Math::kFloatRoundError as tolerance
\see Math::kFloatRoundError
*/
bool operator==(const Vector3& o) const { return IsWithinTolerance(o); }
/*!
\brief Checks inequality using Math::kFloatRoundError as tolerance
\see Math::kFloatRoundError
*/
bool operator!=(const Vector3& o) const { return !IsWithinTolerance(o); }
/*
\brief Checks if another vector is equal to this one within a provided tolerance
\param o The other vector
\param tolerance The tolerance allowed for each component of the
two vectors to be within and still be considered equal
\return True if this vector and o are equal within tolerance
\see Math::kFloatRoundError
*/
bool IsWithinTolerance(const Vector3& o, float tolerance = Math::kFloatRoundError) const
{
return Math::Equals(X, o.X, tolerance)
&& Math::Equals(Y, o.Y, tolerance)
&& Math::Equals(Z, o.Z, tolerance);
}
//! Gets the length of this vector
float GetLength() const { return std::sqrt(X*X + Y*Y + Z*Z); }
//! Gets the length squared of this vector, which is faster to calculate than the length
float GetLengthSq() const { return X*X + Y*Y + Z*Z; }
//! Gets the distance from this vector to another one, interpreting both vectors as points
float GetDistanceFrom(const Vector3& o) const
{
float dx, dy, dz;
dx = X - o.X;
dy = Y - o.Y;
dz = Z - o.Z;
return std::sqrt(dx*dx + dy*dy + dz*dz);
}
//! Gets the distance squared from this vector to another one, interpreting both vectors as points.
//! This is faster to calculate than the distance itself.
float GetDistanceSqFrom(const Vector3& o) const
{
float dx, dy, dz;
dx = X - o.X;
dy = Y - o.Y;
dz = Z - o.Z;
return dx*dx + dy*dy + dz*dz;
}
//! Returns true if this vector is a unit vector (with a length of 1)
bool IsNormalized() const { return Math::Equals(std::sqrt(X*X + Y*Y + Z*Z), 1.0f); }
//! Copies this vector into the first three values of the provided array
void GetAsArray(float* arr) const
{
arr[0] = X;
arr[1] = Y;
arr[3] = Z;
}
//! Sets this vector to the provided values
void Set(float x, float y, float z) { X = x; Y = y; Z = z; }
//! Sets this vector's values from the first three values of the provided array
void SetFromArray(float* asArray) { X = asArray[0]; Y = asArray[1]; Z = asArray[2]; }
//! Set's vector's components to their mulitplicative inverses
void SetToInverse() { X = 1.0f / X; Y = 1.0f / Y; Z = 1.0f / Z; }
//! Gets an array with components (1/x, 1/y, 1/z) of this vector
Vector3 GetInverse() const { Vector3 ret(*this); ret.SetToInverse(); return ret; }
//! Scales this vector by the components of the provided vector
void Scale(const Vector3& o) { X *= o.X; Y *= o.Y; Z *= o.Z; }
//! Returns a copy of this vector, scaled by the provided vector
Vector3 GetScaledBy(const Vector3& o) const { Vector3 ret(*this); ret.Scale(o); return ret; }
//! Scales this vector by a provided scalar
void Scale(float v) { X *= v; Y *= v; Z *= v; }
//! Returns a copy of this vector, scaled by the provided scalar
Vector3 GetScaledBy(float v) const { Vector3 ret(*this); ret.Scale(v); return ret; }
//! Sets the length of this vector to 1
void Normalize()
{
float len = std::sqrt(X*X + Y*Y + Z*Z);
// Normalized already if our length is zero.
// Also stops NaN errors
if(Math::IsZero(len))
return;
X /= len;
Y /= len;
Z /= len;
}
//! Returns a copy of this vector with a length of 1
Vector3 GetNormalized() const { Vector3 ret(*this); ret.Normalize(); return ret; }
//! Sets the length of this vector to a provided scalar
void SetLength(float len)
{
Normalize();
Scale(len);
}
//! Returns a copy of this vector with a length of the provided scalar
Vector3 SetLength(float len) const { Vector3 ret(*this); ret.SetLength(len); return ret; }
/*!
\brief Calculates the dot product of two vectors
\param a The first vector in the dot product
\param b The second vector in the dot product
\return a dot b
*/
static float DotProduct(const Vector3& a, const Vector3& b)
{
return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
}
/*!
\brief Calculates the cross product of two vectors
\param a The first vector in the cross product
\param b The second vector in the cross product
\return a x b
*/
static Vector3 CrossProduct(const Vector3& a, const Vector3& b)
{
return Vector3(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X);
}
//! Gets the left world vector (-1, 0, 0)
static const Vector3& GetLeft()
{
static Vector3 left(-1.0f, 0.0f, 0.0f);
return left;
}
//! Gets the right world vector, (1, 0, 0)
static const Vector3& GetRight()
{
static Vector3 right(1.0f, 0.0f, 0.0f);
return right;
}
//! Gets the forward world vector, (0, 0, 1)
static const Vector3& GetForward()
{
static Vector3 forward(0.0f, 0.0f, 1.0f);
return forward;
}
//! Gets the back world vector, (0, 0, -1)
static const Vector3& GetBack()
{
static Vector3 back(0.0f, 0.0f, -1.0f);
return back;
}
//! Gets the up world vector, (0, 1, 0)
static const Vector3& GetUp()
{
static Vector3 up(0.0f, 1.0f, 0.0f);
return up;
}
//! Gets the down world vector, (0, -1, 0)
static const Vector3& GetDown()
{
static Vector3 down(0.0f, -1.0f, 0.0f);
return down;
}
//! Gets (0, 0, 0)
static const Vector3& GetZero()
{
static Vector3 zero(0.0f);
return zero;
}
//! Gets (1, 1, 1)
static const Vector3& GetOne()
{
static Vector3 one(1.0f);
return one;
}
};
} // end namespace Core | [
"slavik262@gmail.com"
] | slavik262@gmail.com |
6ad6398023b56214a4c92aa5c4ed6381351ecbc5 | c92f0b0f950c59cd6f7e9b008f3d526934facd30 | /src/core/camera.cpp | 1c75d34835a999d3cffcc316d79513c582bddb6e | [] | no_license | polygoncz/raytracer | 39ed8119987aec7ecaa103d274986673dafb42d9 | c41b24f531d05c8258b8f23fe8e0d127b76b6424 | refs/heads/master | 2021-01-19T19:37:55.660515 | 2014-04-04T12:21:30 | 2014-04-04T12:21:30 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 507 | cpp | #include "camera.h"
Camera::Camera(void)
: exposure(0.f)
{
}
/**
* Provede výpočet ortonormální báze.
*/
Camera::Camera(const Point& eye, const Point& target, const Vector& up,
float exposure /* = 1.f */)
: eye(eye), target(target), up(up), exposure(exposure)
{
ComputeUVW();
}
Camera::~Camera()
{
//if (film) delete film;
}
void Camera::ComputeUVW()
{
w = eye - target;
w.Normalize();
u = Cross(up, w);
u.Normalize();
v = Cross(u, w);
v.Normalize();
}
| [
"polygoncz@gmail.com"
] | polygoncz@gmail.com |
90e6f4db02d170df33668572b0a215b2c63b5d9a | dc020629418694e2d018b3de052951cf975f954a | /GameStartScene.h | 3c1d787b0efafbb988f2ccf4ea856610babf7aea | [] | no_license | mingi332/TeamProjYeil_Kim | 4292027a953fa853eef80bc68ce763250a21ef9f | 2d7ca2e83cb234e2154b755c1dfc5189b81bcd06 | refs/heads/master | 2022-12-16T15:38:40.295656 | 2020-08-27T07:53:08 | 2020-08-27T07:53:08 | 289,877,236 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 306 | h | #pragma once
#include<cocos2d.h>
USING_NS_CC;
#include <ui/CocosGUI.h>
using namespace ui;
class GameStartScene :public Scene
{
public:
CREATE_FUNC(GameStartScene);
bool init();
void h2pClick(Ref* ref, Button::TouchEventType type);
void rdyClick(Ref* ref, Button::TouchEventType type);
}; | [
"noreply@github.com"
] | mingi332.noreply@github.com |
e4f7bd89a0ca812d42ed0472e45e9ad47be2e817 | 9dee323b659246c2dca86e165555a88f5f30f923 | /M7HW_Hewin/room.h | ed1b3cfba7405091730de3984d66227b05016002 | [] | no_license | jamesAustinHewin/CSC134 | 6342efc456278b5abaaa57bd571d26df3b0d2dc2 | 0d68eb8c8c902176ea0bc45585da70508a067b44 | refs/heads/master | 2020-04-16T20:50:28.551490 | 2019-05-15T03:49:35 | 2019-05-15T03:49:35 | 165,907,859 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 649 | h | #ifndef ROOM_H_INCLUDED
#define ROOM_H_INCLUDED
#include <string>
using namespace std;
/*
The Room class describes individual rooms in the game.
A room has a name, a description, a location ID,
and a series of exits which point to other rooms.
*/
class Room
{
public:
Room(); // default constructor
Room(string, string, int); // name and description and locationID
string printInfo();
void printInstructions();
string name;
string description;
int locationID;
// exits
Room* north;
Room* south;
Room* east;
Room* west;
};
#endif // ROOM_H_INCLUDED
| [
"noreply@github.com"
] | jamesAustinHewin.noreply@github.com |
fa4a24c59e76597963d4b79c99d7419a63f16cf1 | c82354cdbaa03ddc3779cf4fc4da78647067f35e | /AlgosGraph/include/FirstTask.h | 619a2bae8a8b425b5f99974e444b226a07450dda | [] | no_license | madxmarks/Graph_Algorithms | 5f817583bac290a1831fd8595692343baac06c97 | 64fc8f6a1d65738a1d5c073a08f48f0c395a5eee | refs/heads/master | 2020-12-29T08:26:44.241306 | 2020-02-05T19:45:24 | 2020-02-05T19:45:24 | 238,534,475 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,462 | h | #ifndef FIRSTTASK_H
#define FIRSTTASK_H
#include <vector>
#include <stack>
#include <iostream>
#include <list>
#include <queue>
using namespace std;
/// BFS
struct Node
{
int pt; // The cordinates of a cell
Node *prev;
};
class BFS
{
int n;
public:
BFS(int n)
{
this->n = n;
adj = new list<int>[n];
}
~BFS() {};
int no;
list<int> *adj;
int siz()
{
return n;
}
void addedge(int v, int w)
{
adj[v].push_back(w);
adj[w].push_back(v);
}
int calculate(int s =0, int finish =0 )
{
if((s!=finish) && finish<n && s<n)
{
vector<int> path;
vector<int> rightPath;
bool *visited = new bool[n];
int pred[n];
for(int i = 0; i < n; i++)
visited[i] = false;
list<int> queue;
visited[s] = true;
int start = s;
queue.push_back(s);
list<int>::iterator i;
int fir =0;
while(!queue.empty())
{
s = queue.front();
queue.pop_front();
path.push_back(s);
if (s==finish)
{
rightPath.push_back(s);
int joke=path.size()-1;
while(pred[path[joke]]!=start)
{
int korz =path[joke];
rightPath.push_back(pred[korz]);
for(int ze=0; ze<path.size(); ze++)
{
if(path[ze]==pred[path[joke]])
{
joke=ze;
}
}
}
cout << endl << endl<< endl << "The fastest way out is: " << endl;
rightPath.push_back(pred[path[joke]]);
for(int i=rightPath.size()-1; i>=0; i--)
{
cout << rightPath[i] << " \t ";
}
cout << endl << endl<< endl<< endl;
return rightPath.size();
}
for (i = adj[s].begin(); i != adj[s].end(); ++i)
{
if (!visited[*i])
{
pred[*i] = s;
visited[*i] = true;
queue.push_back(*i);
}
}
}
}
cout << "Sorry young magician you shell not pass";
return -1;
}
};
#endif // FIRSTTASK_H
| [
"60475881+madxmarks@users.noreply.github.com"
] | 60475881+madxmarks@users.noreply.github.com |
77414017a2c48ecc4c62697f9bcb37ea3a610380 | 503d2f8f5f5f547acb82f7299d86886691966ca5 | /atcoder/abc150_d_lcm.cpp | 827fe6b7e273b6798ba574db7e6d66abb7cf6ac6 | [] | no_license | Hironobu-Kawaguchi/atcoder | 3fcb649cb920dd837a1ced6713bbb939ecc090a9 | df4b55cc7d557bf61607ffde8bda8655cf129017 | refs/heads/master | 2023-08-21T14:13:13.856604 | 2023-08-12T14:53:03 | 2023-08-12T14:53:03 | 197,216,790 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,593 | cpp | // https://atcoder.jp/contests/abc150/tasks/abc150_d
#include<iostream>
// #include<algorithm>
// #include<string>
// #include<numeric>
// #include<vector>
// #include<map>
// #include<tuple>
// #include<set>
// #include<queue>
// #include<deque>
// #include<regex>
// #include<bitset>
// #include<iomanip>
// #include<complex>
// #include<stack>
// #include<functional>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int f(int x) {
int res = 0;
while (x%2 == 0) {
x /= 2;
res++;
}
return res;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n);
rep(i,n) cin >> a[i];
rep(i,n) {
if (a[i]%2 ==1) {
cout << 0 << endl;
return 0;
}
a[i] /= 2;
}
int t = f(a[0]);
rep(i,n) {
if (f(a[i]) != t) {
cout << 0 << endl;
return 0;
}
a[i] >>= t; // a[i] /= 2^t
}
m >>=t;
ll l = 1;
rep(i,n) {
l = lcm(l, a[i]);
if (l > m) {
cout << 0 << endl;
return 0;
}
}
m /= l;
int ans = (m+1)/2;
cout << ans << endl;
return 0;
}
| [
"hironobukawaguchi3@gmail.com"
] | hironobukawaguchi3@gmail.com |
61d327cb4a908133c92fe394cf5f21fcea3b6ac2 | ef94267c9e9f9be67a68e107e978c42c812965cb | /Source/FPSSimulator/GS_CTF.h | bab6bff4a34bb4e9c9d8457feb0328f9e27b4165 | [] | no_license | stevenlwk/LAGCOM | 3df1f0940584877033096c97b271bb4540549bc4 | f82e8183abafb1d512a1d28face7d986d67d05ec | refs/heads/master | 2021-01-20T02:33:59.495835 | 2017-08-24T22:04:38 | 2017-08-24T22:04:38 | 101,326,126 | 8 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,247 | h | #pragma once
#include "FPSSimulatorGameState.h"
#include "CTF_Flag.h"
#include "GS_CTF.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FFlagSpawnedDelegate, ACTF_Flag*, Flag);
UCLASS()
class FPSSIMULATOR_API AGS_CTF : public AFPSSimulatorGameState {
GENERATED_BODY()
public:
void BeginPlay() override;
UFUNCTION(NetMulticast, Reliable)
void CallOnFlagReturned(ACTF_Flag* Flag);
UFUNCTION(Client, Reliable)
void CallOnFlagSpawned(ACTF_Flag* Flag);
UPROPERTY(BlueprintReadOnly, Category = "Capture the Flag")
TArray<ACTF_Flag*> Flags;
UPROPERTY(BlueprintAssignable)
FFlagReturnedDelegate OnFlagReturnedDelegate;
UPROPERTY(BlueprintAssignable)
FFlagSpawnedDelegate OnFlagSpawnedDelegate;
/* Scores */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Score")
int32 PickupScore = 100;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Score")
int32 DeliverScore = 500;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Score")
int32 CarrierKillScore = 50;
protected:
UFUNCTION()
void SpawnFlag(int32 TeamID);
UFUNCTION()
void OnFlagReturned(ACTF_Flag* Flag);
FTimerHandle SpawnFlagTimer;
UPROPERTY(EditDefaultsOnly, Category = "Capture the Flag")
float FlagSpawningDelay = 10.f;
};
| [
"leewaikiu@gmail.com"
] | leewaikiu@gmail.com |
66ceec8afd2d9f27609fd1a23a9d3749182a7e5a | 5275c0920fa67ce3d5db5e0a08d80f61d3b28041 | /code/reverse_linked_list-2.cpp | 58f8a4ab0a2442f9e788e6b9d6885d131d31bb03 | [] | no_license | Yyaw/Leetcode | 7c4253bd3fa0a471fff7489b07602f010f252ea1 | 0eb52e521f26dd19a7e0b73dcb18a165309326b8 | refs/heads/master | 2021-03-16T08:48:14.275790 | 2019-01-13T17:54:27 | 2019-01-13T17:54:27 | 102,196,325 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 748 | cpp | #include <iostream>
#include "data.h"
using namespace std;
class Solution {
public:
ListNode *reverseBetween(ListNode*head, int m, int n)
{
ListNode *f = new ListNode(0);
f->next = head;
ListNode *first = f;
for (int i=1; i<m-1; i++)
first = first->next;
ListNode *pre = first == NULL ? NULL : first->next;
ListNode *post = pre == NULL ? NULL : pre->next;
if (post == NULL)
return head;
for (int i=m; i<n; i++)
{
pre->next = post->next;
post->next = first->next;
first->next = post;
post = pre->next;
}
return f->next;
}
};
int main(int argc, char **argv)
{
return 0;
} | [
"1947302673@qq.com"
] | 1947302673@qq.com |
5cec730a4edfd3cd8a4eb2e4eedd4eb15f0caa5a | a97c07f891ec71d81cc43d25234231680971a744 | /test/src/UriTests.cpp | be106494f11efee9e5010f3d2807eb0d0a48d364 | [
"MIT"
] | permissive | shaqsnake/uriparser | 99e7c3115378545f51aa3bca91d57b7ca0ea4fa8 | 76e74e5f2ceae67079e0dca76dd381be6a21978c | refs/heads/master | 2020-06-11T06:10:52.770764 | 2019-07-26T03:30:27 | 2019-07-26T03:30:27 | 193,872,044 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 30,069 | cpp | // Copyright (c) 2019 shaqsnake. All rights reserved.
/**
* @Author: shaqsnake
* @Email: shaqsnake@gmail.com
* @Date: 2019-06-27 09:17:12
* @LastEditTime: 2019-07-26 11:28:36
* @Description: Unittests of class uri::Uri.
*/
#include <gtest/gtest.h>
#include <uriparser/Uri.hpp>
TEST(UriTests, ParseFromCommonUri) {
uri::Uri uri;
ASSERT_TRUE(
uri.parseFromString("http://user:password@example.com:8080/some/path/"
"to/somewhere?search=regex&order=desc#fragment"));
ASSERT_EQ("http", uri.getScheme());
ASSERT_EQ("user:password@example.com:8080", uri.getAuthority());
ASSERT_EQ("example.com", uri.getHost());
ASSERT_EQ(8080, uri.getPort());
ASSERT_EQ("/some/path/to/somewhere", uri.getPath());
ASSERT_EQ("search=regex&order=desc", uri.getQuery());
ASSERT_EQ("fragment", uri.getFragment());
}
TEST(UriTests, ParseFromUrn) {
uri::Uri uri;
ASSERT_TRUE(uri.parseFromString(
"urn:oasis:names:specification:docbook:dtd:xml:4.1.2"));
ASSERT_EQ("urn", uri.getScheme());
ASSERT_EQ("", uri.getAuthority());
ASSERT_EQ("", uri.getHost());
ASSERT_EQ(-1, uri.getPort());
ASSERT_EQ("oasis:names:specification:docbook:dtd:xml:4.1.2", uri.getPath());
ASSERT_EQ("", uri.getQuery());
ASSERT_EQ("", uri.getFragment());
}
TEST(UriTests, ParseFromNestedUri) {
uri::Uri uri;
ASSERT_TRUE(
uri.parseFromString("mina:tcp://mainframeip:4444?textline=true"));
ASSERT_EQ("mina", uri.getScheme());
ASSERT_EQ("", uri.getAuthority());
ASSERT_EQ("", uri.getHost());
ASSERT_EQ(-1, uri.getPort());
ASSERT_EQ("tcp://mainframeip:4444", uri.getPath());
ASSERT_EQ("textline=true", uri.getQuery());
ASSERT_EQ("", uri.getFragment());
}
TEST(UriTests, ParseFromIPv6Addr) {
uri::Uri uri;
ASSERT_TRUE(
uri.parseFromString("ldap://[2001:db8::7]/c=GB?objectClass?one"));
ASSERT_EQ("ldap", uri.getScheme());
ASSERT_EQ("[2001:db8::7]", uri.getAuthority());
ASSERT_EQ("[2001:db8::7]", uri.getHost());
ASSERT_EQ(-1, uri.getPort());
ASSERT_EQ("/c=GB", uri.getPath());
ASSERT_EQ("objectClass?one", uri.getQuery());
ASSERT_EQ("", uri.getFragment());
}
TEST(UriTests, ParseFromGeneralUriStrings) {
struct TestCase {
std::string uriString;
std::string authority;
std::string path;
};
std::vector<TestCase> testCases{
{
"ftp://ftp.is.co.za/rfc/rfc1808.txt",
"ftp.is.co.za",
"/rfc/rfc1808.txt",
},
{
"http://www.ietf.org/rfc/rfc2396.txt",
"www.ietf.org",
"/rfc/rfc2396.txt",
},
{
"ldap://[2001:db8::7]/c=GB?objectClass?one",
"[2001:db8::7]",
"",
},
{
"mailto:John.Doe@example.com",
"",
"John.Doe@example.com",
},
{
"news:comp.infosystems.www.servers.unix",
"",
"comp.infosystems.www.servers.unix",
},
{
"tel:+1-816-555-1212",
"",
"+1-816-555-1212",
},
{
"telnet://192.0.2.16:80/",
"192.0.2.16:80",
"/",
},
{"urn:oasis:names:specification:docbook:dtd:xml:4.1.2", "",
"oasis:names:specification:docbook:dtd:xml:4.1.2"},
};
std::size_t idx = 0;
uri::Uri uri;
for (const auto &testCase : testCases) {
ASSERT_TRUE(uri.parseFromString(testCase.uriString)) << idx;
ASSERT_EQ(testCase.authority, uri.getAuthority()) << idx;
++idx;
}
}
TEST(UriTests, ParseFromUriWithInvalidScheme) {
std::vector<std::string> uriStrings{
"123://example.com", "0foo://example.com", "+foo://example.com",
"foo!://example.com", "foo$://example.com", "foo&://example.com",
"foo'://example.com", "foo(://example.com", "foo)://example.com",
"foo*://example.com", "foo,://example.com", "foo;://example.com",
"foo=://example.com", "foo[://example.com", "foo]://example.com",
"foo@://example.com", "foo_://example.com", "foo~://example.com",
// In this case , the scheme is "foo", so it's legal,
// but the authority, "://example.com", is ilegal.
// "foo:://example.com", "foo?://example.com", "foo#://example.com",
};
size_t idx = 0;
uri::Uri uri;
for (const auto &uriString : uriStrings) {
ASSERT_FALSE(uri.parseFromString(uriString)) << idx;
++idx;
}
}
TEST(UriTests, PaserFromUriWithBarelyValidScheme) {
struct TestCase {
std::string uriString;
std::string scheme;
};
std::vector<TestCase> testCases{
{"foo0://example.com", "foo0"}, {"foo+://example.com", "foo+"},
{"foo-://example.com", "foo-"}, {"foo.://example.com", "foo."},
{"f0o://example.com", "f0o"}, {"f+o://example.com", "f+o"},
{"f-o://example.com", "f-o"}, {"f.o://example.com", "f.o"},
};
size_t idx = 0;
uri::Uri uri;
for (const auto &testCase : testCases) {
ASSERT_TRUE(uri.parseFromString(testCase.uriString)) << idx;
ASSERT_EQ(testCase.scheme, uri.getScheme()) << idx;
++idx;
}
}
TEST(UriTests, ParseFromUriWithInvalidAuthority) {
std::vector<std::string> uriStrings{
// Testcase of userinfo
"foo://bar[@example.com",
"foo://bar]@example.com",
"foo://bar@@example.com",
// Tesecase of host
"foo://bar@example:com",
"foo://bar@example[com",
"foo://bar@example]com",
"foo://bar@example@com",
// Testcase of port
"foo://bar@example.com:-2",
"foo://bar@example.com:65536",
};
size_t idx = 0;
uri::Uri uri;
for (const auto &uriString : uriStrings) {
ASSERT_FALSE(uri.parseFromString(uriString))
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, PaserFromUriWithBarelyValidAuthority) {
struct TestCase {
std::string uriString;
std::string authority;
std::string userinfo;
std::string host;
int port;
};
std::vector<TestCase> testCases{
// Testcase of userinfo
{"foo://bar@example.com:80", "bar@example.com:80", "bar", "example.com",
80},
{"foo://bar:@example.com:80", "bar:@example.com:80",
"bar:", "example.com", 80},
{"foo://bar-@example.com:80", "bar-@example.com:80", "bar-",
"example.com", 80},
{"foo://bar.@example.com:80", "bar.@example.com:80", "bar.",
"example.com", 80},
{"foo://bar_@example.com:80", "bar_@example.com:80", "bar_",
"example.com", 80},
{"foo://bar~@example.com:80", "bar~@example.com:80", "bar~",
"example.com", 80},
{"foo://bar0@example.com:80", "bar0@example.com:80", "bar0",
"example.com", 80},
{"foo://bar!@example.com:80", "bar!@example.com:80", "bar!",
"example.com", 80},
{"foo://bar$@example.com:80", "bar$@example.com:80", "bar$",
"example.com", 80},
{"foo://bar&@example.com:80", "bar&@example.com:80", "bar&",
"example.com", 80},
{"foo://bar'@example.com:80", "bar'@example.com:80", "bar'",
"example.com", 80},
{"foo://bar(@example.com:80", "bar(@example.com:80", "bar(",
"example.com", 80},
{"foo://bar)@example.com:80", "bar)@example.com:80", "bar)",
"example.com", 80},
{"foo://bar*@example.com:80", "bar*@example.com:80", "bar*",
"example.com", 80},
{"foo://bar+@example.com:80", "bar+@example.com:80", "bar+",
"example.com", 80},
{"foo://bar,@example.com:80", "bar,@example.com:80", "bar,",
"example.com", 80},
{"foo://bar;@example.com:80", "bar;@example.com:80", "bar;",
"example.com", 80},
{"foo://bar=@example.com:80", "bar=@example.com:80",
"bar=", "example.com", 80},
// Tesecase of host
{"foo://bar@example-com:80", "bar@example-com:80", "bar", "example-com",
80},
{"foo://bar@example.com:80", "bar@example.com:80", "bar", "example.com",
80},
{"foo://bar@example_com:80", "bar@example_com:80", "bar", "example_com",
80},
{"foo://bar@example~com:80", "bar@example~com:80", "bar", "example~com",
80},
{"foo://bar@example0com:80", "bar@example0com:80", "bar", "example0com",
80},
{"foo://bar@example!com:80", "bar@example!com:80", "bar", "example!com",
80},
{"foo://bar@example$com:80", "bar@example$com:80", "bar", "example$com",
80},
{"foo://bar@example&com:80", "bar@example&com:80", "bar", "example&com",
80},
{"foo://bar@example'com:80", "bar@example'com:80", "bar", "example'com",
80},
{"foo://bar@example(com:80", "bar@example(com:80", "bar", "example(com",
80},
{"foo://bar@example)com:80", "bar@example)com:80", "bar", "example)com",
80},
{"foo://bar@example*com:80", "bar@example*com:80", "bar", "example*com",
80},
{"foo://bar@example+com:80", "bar@example+com:80", "bar", "example+com",
80},
{"foo://bar@example,com:80", "bar@example,com:80", "bar", "example,com",
80},
{"foo://bar@example;com:80", "bar@example;com:80", "bar", "example;com",
80},
{"foo://bar@example=com:80", "bar@example=com:80", "bar", "example=com",
80},
// Testcase of port
{"foo://bar@example.com:0", "bar@example.com:0", "bar", "example.com",
0},
{"foo://bar@example.com:65535", "bar@example.com:65535", "bar",
"example.com", 65535},
};
size_t idx = 0;
uri::Uri uri;
for (const auto &testCase : testCases) {
ASSERT_TRUE(uri.parseFromString(testCase.uriString))
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.authority, uri.getAuthority())
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.userinfo, uri.getUserinfo())
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.host, uri.getHost())
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.port, uri.getPort())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, ParseFromUriWithInvalidIPv6Addr) {
std::vector<std::string> uriStrings{
"http://[]",
"http://[:]",
"http://[I]",
"http://[::fFfF::1]",
"http://[::ffff:1.2.x.4]/",
"http://[::ffff:1.2.3.4.8]/",
"http://[::ffff:1.2.3]/",
"http://[::ffff:1.2.3.]/",
"http://[::ffff:1.2.3.256]/",
"http://[::fxff:1.2.3.4]/",
"http://[::ffff:1.2.3.-4]/",
"http://[::ffff:1.2.3. 4]/",
"http://[::ffff:1.2.3.4 ]/",
"http://[::ffff:1.2.3.4/",
"http://::ffff:1.2.3.4]/",
"http://::ffff:a.2.3.4]/",
"http://::ffff:1.a.3.4]/",
"http://[2001:db8:85a3:8d3:1319:8a2e:370:7348:0000]/",
"http://[2001:db8:85a3::8a2e:0:]/",
"http://[2001:db8:85a3::8a2e::]/",
};
size_t idx = 0;
uri::Uri uri;
for (const auto &uriString : uriStrings) {
ASSERT_FALSE(uri.parseFromString(uriString))
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, PaserFromUriWithBarelyValidIPv6Addr) {
struct TestCase {
std::string uriString;
std::string host;
};
std::vector<TestCase> testCases{
{"http://[::1]/", "[::1]"},
{"http://[::ffff:1.2.3.4]/", "[::ffff:1.2.3.4]"},
{"http://[2001:db8:85a3:8d3:1319:8a2e:370:7348]/",
"[2001:db8:85a3:8d3:1319:8a2e:370:7348]"},
{"http://[fFfF::1]", "[ffff::1]"},
{"http://[fFfF:1:2:3:4:5:6:a]", "[ffff:1:2:3:4:5:6:a]"},
};
size_t idx = 0;
uri::Uri uri;
for (const auto &testCase : testCases) {
ASSERT_TRUE(uri.parseFromString(testCase.uriString))
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.host, uri.getHost())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, ParseFromUriWithInvalidPath) {
std::vector<std::string> uriStrings{
"foo://example.com/[bar",
"foo://example.com/]bar",
};
size_t idx = 0;
uri::Uri uri;
for (const auto &uriString : uriStrings) {
ASSERT_FALSE(uri.parseFromString(uriString))
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, PaserFromUriWithBarelyValidPath) {
struct TestCase {
std::string uriString;
std::string path;
};
std::vector<TestCase> testCases{
{"foo://example.com/bar", "/bar"},
{"foo://example.com/0bar", "/0bar"},
{"foo://example.com/:bar", "/:bar"},
{"foo://example.com/@bar", "/@bar"},
{"foo://example.com/-bar", "/-bar"},
{"foo://example.com/.bar", "/.bar"},
{"foo://example.com/_bar", "/_bar"},
{"foo://example.com/~bar", "/~bar"},
{"foo://example.com/!bar", "/!bar"},
{"foo://example.com/$bar", "/$bar"},
{"foo://example.com/&bar", "/&bar"},
{"foo://example.com/'bar", "/'bar"},
{"foo://example.com/(bar", "/(bar"},
{"foo://example.com/)bar", "/)bar"},
{"foo://example.com/*bar", "/*bar"},
{"foo://example.com/+bar", "/+bar"},
{"foo://example.com/,bar", "/,bar"},
{"foo://example.com/;bar", "/;bar"},
{"foo://example.com/=bar", "/=bar"},
};
size_t idx = 0;
uri::Uri uri;
for (const auto &testCase : testCases) {
ASSERT_TRUE(uri.parseFromString(testCase.uriString))
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.path, uri.getPath())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, ParseFromUriWithInvalidQuery) {
std::vector<std::string> uriStrings{
"foo://example.com/bar?zoo]",
"foo://example.com/bar?zoo[",
};
size_t idx = 0;
uri::Uri uri;
for (const auto &uriString : uriStrings) {
ASSERT_FALSE(uri.parseFromString(uriString))
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, PaserFromUriWithBarelyValidQuery) {
struct TestCase {
std::string uriString;
std::string query;
};
std::vector<TestCase> testCases{{"foo://example.com/bar?", ""},
{"foo://example.com/bar?zoo", "zoo"},
{"foo://example.com/bar?0zoo", "0zoo"},
{"foo://example.com/bar?-zoo", "-zoo"},
{"foo://example.com/bar?.zoo", ".zoo"},
{"foo://example.com/bar?_zoo", "_zoo"},
{"foo://example.com/bar?~zoo", "~zoo"},
{"foo://example.com/bar?:zoo", ":zoo"},
{"foo://example.com/bar?@zoo", "@zoo"},
{"foo://example.com/bar?!zoo", "!zoo"},
{"foo://example.com/bar?$zoo", "$zoo"},
{"foo://example.com/bar?&zoo", "&zoo"},
{"foo://example.com/bar?'zoo", "'zoo"},
{"foo://example.com/bar?(zoo", "(zoo"},
{"foo://example.com/bar?)zoo", ")zoo"},
{"foo://example.com/bar?*zoo", "*zoo"},
{"foo://example.com/bar?+zoo", "+zoo"},
{"foo://example.com/bar?,zoo", ",zoo"},
{"foo://example.com/bar?;zoo", ";zoo"},
{"foo://example.com/bar?=zoo", "=zoo"},
{"foo://example.com/bar?/zoo", "/zoo"},
{"foo://example.com/bar??zoo", "?zoo"},
{"foo?://example.com", "://example.com"}};
size_t idx = 0;
uri::Uri uri;
for (auto const &testCase : testCases) {
ASSERT_TRUE(uri.parseFromString(testCase.uriString))
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.query, uri.getQuery())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, ParseFromUriWithInvalidFragment) {
std::vector<std::string> uriStrings{
"foo://example.com/bar#zoo]",
"foo://example.com/bar#zoo[",
};
size_t idx = 0;
uri::Uri uri;
for (const auto &uriString : uriStrings) {
ASSERT_FALSE(uri.parseFromString(uriString))
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, PaserFromUriWithBarelyValidFragment) {
struct TestCase {
std::string uriString;
std::string fragment;
};
std::vector<TestCase> testCases{
{"foo://example.com/bar#", ""},
{"foo://example.com/bar#zoo", "zoo"},
{"foo://example.com/bar#0zoo", "0zoo"},
{"foo://example.com/bar#-zoo", "-zoo"},
{"foo://example.com/bar#.zoo", ".zoo"},
{"foo://example.com/bar#_zoo", "_zoo"},
{"foo://example.com/bar#~zoo", "~zoo"},
{"foo://example.com/bar#:zoo", ":zoo"},
{"foo://example.com/bar#@zoo", "@zoo"},
{"foo://example.com/bar#!zoo", "!zoo"},
{"foo://example.com/bar#$zoo", "$zoo"},
{"foo://example.com/bar#&zoo", "&zoo"},
{"foo://example.com/bar#'zoo", "'zoo"},
{"foo://example.com/bar#(zoo", "(zoo"},
{"foo://example.com/bar#)zoo", ")zoo"},
{"foo://example.com/bar#*zoo", "*zoo"},
{"foo://example.com/bar#+zoo", "+zoo"},
{"foo://example.com/bar#,zoo", ",zoo"},
{"foo://example.com/bar#;zoo", ";zoo"},
{"foo://example.com/bar#=zoo", "=zoo"},
{"foo://example.com/bar#/zoo", "/zoo"},
{"foo://example.com/bar#?zoo", "?zoo"},
{"foo#://example.com", "://example.com"},
};
size_t idx = 0;
uri::Uri uri;
for (auto const &testCase : testCases) {
ASSERT_TRUE(uri.parseFromString(testCase.uriString))
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.fragment, uri.getFragment())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, PaserFromUriDecodingAuthority) {
struct TestCase {
std::string rawUriString;
std::string decodedUriString;
};
std::vector<TestCase> testCases{
{"foo://bar@example.com:80", "bar@example.com:80"},
{"foo://%41@example.com:80", "A@example.com:80"},
{"foo://bar@ex%61mple.com:80", "bar@example.com:80"},
{"foo://%41%42%43@example.com:80", "ABC@example.com:80"},
{"foo://bar@example%2Ecom:80", "bar@example.com:80"},
{"foo://bar@example%2ecom:80", "bar@example.com:80"},
{"foo://bar@%61%62%63:80", "bar@abc:80"},
{"foo://bar@%61%GG:80", "bar@a%GG:80"},
};
size_t idx = 0;
uri::Uri uri;
for (auto const &testCase : testCases) {
uri.parseFromString(testCase.rawUriString);
ASSERT_EQ(testCase.decodedUriString, uri.getAuthority())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, PaserFromUriDecodingPath) {
struct TestCase {
std::string rawUriString;
std::string decodedUriString;
};
std::vector<TestCase> testCases{
{"foo://example.com/bar", "/bar"},
{"foo://example.com/b%61r", "/bar"},
{"foo://example.com/bar/%2b", "/bar/+"},
{"foo://example.com/b%2dr", "/b-r"},
{"foo://example.com/b%2Dr", "/b-r"},
{"foo://@example.com/%41%42%43", "/ABC"},
{"foo://@example.com/%GG", "/%GG"},
};
size_t idx = 0;
uri::Uri uri;
for (auto const &testCase : testCases) {
uri.parseFromString(testCase.rawUriString);
ASSERT_EQ(testCase.decodedUriString, uri.getPath())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, PaserFromUriDecodingQuery) {
struct TestCase {
std::string rawUriString;
std::string decodedUriString;
};
std::vector<TestCase> testCases{
{"foo://example.com?bar", "bar"},
{"foo://example.com?b%61r", "bar"},
{"foo://example.com?bar/%2b", "bar/+"},
{"foo://example.com?b%2dr", "b-r"},
{"foo://example.com?b%2Dr", "b-r"},
{"foo://@example.com?%41%42%43", "ABC"},
{"foo://@example.com?%GG", "%GG"},
};
size_t idx = 0;
uri::Uri uri;
for (auto const &testCase : testCases) {
uri.parseFromString(testCase.rawUriString);
ASSERT_EQ(testCase.decodedUriString, uri.getQuery())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, PaserFromUriDecodingFragment) {
struct TestCase {
std::string rawUriString;
std::string decodedUriString;
};
std::vector<TestCase> testCases{
{"foo://example.com#bar", "bar"},
{"foo://example.com#b%61r", "bar"},
{"foo://example.com#bar/%2b", "bar/+"},
{"foo://example.com#b%2dr", "b-r"},
{"foo://example.com#b%2Dr", "b-r"},
{"foo://@example.com#%41%42%43", "ABC"},
{"foo://@example.com#%GG", "%GG"},
};
size_t idx = 0;
uri::Uri uri;
for (auto const &testCase : testCases) {
uri.parseFromString(testCase.rawUriString);
ASSERT_EQ(testCase.decodedUriString, uri.getFragment())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, ProduceToUriStrings) {
struct TestCase {
std::string inputUriString;
std::string targetUriString;
};
std::vector<TestCase> testCases{
{"http://user:password@example.com:8080/some/path/to"
"/somewhere?search=regex&order=desc#fragment",
"http%3A%2F%2Fuser%3Apassword%40example.com%3A8080%2Fsome%2Fpath%2Fto"
"%2Fsomewhere%3Fsearch%3Dregex%26order%3Ddesc%23fragment"},
{"foo://%41%42%43@example.com:80/b%2dr?GG",
"foo%3A%2F%2FABC%40example.com%3A80%2Fb-r%3FGG"},
{"example.com/", "example.com%2F"},
{"/foo/bar", "%2Ffoo%2Fbar"},
{"http://user:password@", "http%3A%2F%2Fuser%3Apassword%40"},
};
size_t idx = 0;
for (const auto &testCase : testCases) {
uri::Uri uri;
ASSERT_TRUE(uri.parseFromString(testCase.inputUriString))
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.targetUriString, uri.produceToString())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, ParseFromUriWithCaseSensitive) {
struct TestCase {
std::string uriString;
std::string scheme;
std::string host;
};
std::vector<TestCase> testCases{
{"HTTP://www.EXAMPLE.com/", "http", "www.example.com"},
{"htTp://www.example.com/", "http", "www.example.com"},
{"http://www.exAMple.com/", "http", "www.example.com"},
{"hTTp://www.ex%41%4dple.com/", "http", "www.example.com"},
};
size_t idx = 0;
uri::Uri uri;
for (const auto &testCase : testCases) {
ASSERT_TRUE(uri.parseFromString(testCase.uriString))
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.scheme, uri.getScheme())
<< ">>> Test is failed at " << idx << ". <<<";
ASSERT_EQ(testCase.host, uri.getHost())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, ParseFromUriWithNomalizePath) {
struct TestCase {
std::string uriString;
std::string path;
};
std::vector<TestCase> testCases{{"/a/b/c/./../../g", "/a/g"},
{"mid/content=5/../6", "mid/6"},
{"/a/b/c/../../../g", "/g"},
{"/a/b/c/../../../../g", "/g"},
{"foo://bar.com/", "/"},
{"foo://bar.com/../g", "/g"},
{"foo://bar.com/a/../b/", "/b/"},
{"./foo/bar", "foo/bar"},
{".", ""},
{"..", ""},
{"/", "/"},
{"foo/bar", "foo/bar"},
{"foo/bar/..", "foo/"},
{"foo/bar/.", "foo/bar/"},
{"foo/bar/./zoo", "foo/bar/zoo"},
{"foo/bar/./zoo/", "foo/bar/zoo/"},
{"./foo/bar/..", "foo/"},
{"/./foo/bar", "/foo/bar"},
{"/../foo/bar", "/foo/bar"},
{"../foo/bar/./../zoo/", "foo/zoo/"}};
size_t idx = 0;
uri::Uri uri;
for (const auto &testCase : testCases) {
ASSERT_TRUE(uri.parseFromString(testCase.uriString))
<< ">>> Test is failed at " << idx << ". <<<";
uri.normalizePath();
ASSERT_EQ(testCase.path, uri.getPath())
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, ResolveRelativeUriString) {
struct TestCase {
std::string baseUriString;
std::string relativeRefString;
std::string expectedUriString;
};
std::vector<TestCase> testCases{
// Normal examples
{"http://a/b/c/d;p?q", "g:h", "g:h"},
{"http://a/b/c/d;p?q", "g", "http://a/b/c/g"},
{"http://a/b/c/d;p?q", "./g", "http://a/b/c/g"},
{"http://a/b/c/d;p?q", "g/", "http://a/b/c/g/"},
{"http://a/b/c/d;p?q", "/g", "http://a/g"},
{"http://a/b/c/d;p?q", "//g", "http://g"},
{"http://a/b/c/d;p?q", "?y", "http://a/b/c/d;p?y"},
{"http://a/b/c/d;p?q", "g?y", "http://a/b/c/g?y"},
{"http://a/b/c/d;p?q", "#s", "http://a/b/c/d;p?q#s"},
{"http://a/b/c/d;p?q", "g#s", "http://a/b/c/g#s"},
{"http://a/b/c/d;p?q", "g?y#s", "http://a/b/c/g?y#s"},
{"http://a/b/c/d;p?q", ";x", "http://a/b/c/;x"},
{"http://a/b/c/d;p?q", "g;x", "http://a/b/c/g;x"},
{"http://a/b/c/d;p?q", "g;x?y#s", "http://a/b/c/g;x?y#s"},
{"http://a/b/c/d;p?q", "", "http://a/b/c/d;p?q"},
{"http://a/b/c/d;p?q", ".", "http://a/b/c/"},
{"http://a/b/c/d;p?q", "./", "http://a/b/c/"},
{"http://a/b/c/d;p?q", "..", "http://a/b/"},
{"http://a/b/c/d;p?q", "../", "http://a/b/"},
{"http://a/b/c/d;p?q", "../g", "http://a/b/g"},
{"http://a/b/c/d;p?q", "../..", "http://a/"},
{"http://a/b/c/d;p?q", "../../", "http://a/"},
{"http://a/b/c/d;p?q", "../../g", "http://a/g"},
// Abnormal examples
{"http://a/b/c/d;p?q", "../../../g", "http://a/g"},
{"http://a/b/c/d;p?q", "../../../../g", "http://a/g"},
{"http://a/b/c/d;p?q", "/./g", "http://a/g"},
{"http://a/b/c/d;p?q", "/../g", "http://a/g"},
{"http://a/b/c/d;p?q", "g.", "http://a/b/c/g."},
{"http://a/b/c/d;p?q", ".g", "http://a/b/c/.g"},
{"http://a/b/c/d;p?q", "g..", "http://a/b/c/g.."},
{"http://a/b/c/d;p?q", "..g", "http://a/b/c/..g"},
{"http://a/b/c/d;p?q", "./../g", "http://a/b/g"},
{"http://a/b/c/d;p?q", "./g/.", "http://a/b/c/g/"},
{"http://a/b/c/d;p?q", "g/./h", "http://a/b/c/g/h"},
{"http://a/b/c/d;p?q", "g/../h", "http://a/b/c/h"},
{"http://a/b/c/d;p?q", "g;x=1/./y", "http://a/b/c/g;x=1/y"},
{"http://a/b/c/d;p?q", "g;x=1/../y", "http://a/b/c/y"},
{"http://a/b/c/d;p?q", "g?y/./x", "http://a/b/c/g?y/./x"},
{"http://a/b/c/d;p?q", "g?y/../x", "http://a/b/c/g?y/../x"},
{"http://a/b/c/d;p?q", "g#s/./x", "http://a/b/c/g#s/./x"},
{"http://a/b/c/d;p?q", "g#s/../x", "http://a/b/c/g#s/../x"},
{"http://a/b/c/d;p?q", "http:g", "http:g"},
};
size_t idx = 0;
for (const auto &testCase : testCases) {
uri::Uri baseUri, relRefUri, targetUri;
ASSERT_TRUE(baseUri.parseFromString(testCase.baseUriString));
ASSERT_TRUE(relRefUri.parseFromString(testCase.relativeRefString));
targetUri = baseUri.resolve(relRefUri);
ASSERT_EQ(testCase.expectedUriString, targetUri.produceToString(false))
<< ">>> Test is failed at " << idx << ". <<<";
++idx;
}
}
TEST(UriTests, SetUriComponents) {
struct TestCase {
std::string scheme;
std::string authority;
std::string path;
std::string query;
std::string fragment;
std::string expectedUri;
};
std::vector<TestCase> testCases{
{"http", "example.com", "/foo", "bar", "spam",
"http://example.com/foo?bar#spam"},
{"", "example.com", "/foo", "bar", "spam",
"//example.com/foo?bar#spam"},
{"http", "", "/foo", "bar", "spam", "http:/foo?bar#spam"},
{"http", "example.com", "", "bar", "spam",
"http://example.com?bar#spam"},
{"http", "example.com", "/foo", "", "", "http://example.com/foo"},
};
for (auto const &testCase : testCases) {
uri::Uri uri;
uri.setScheme(testCase.scheme);
uri.setAuthority(testCase.authority);
uri.setPath(testCase.path);
uri.setQuery(testCase.query);
uri.setFragment(testCase.fragment);
ASSERT_EQ(testCase.expectedUri, uri.produceToString(false));
}
} | [
"shaqsnake@gmail.com"
] | shaqsnake@gmail.com |
62815ac035c5bfb8a234f622c1de6c74f059707d | a0f37fb7b728721a81020c87f8b1d1bd15cd61ee | /ShareLibACM/acmSuperDefs.cpp | 812aa0efd963dfe70409958cca71dc90e1a9a148 | [
"MIT"
] | permissive | chrishoen/Dev_ACM | d60fe5b3eff054a32d7bde7680193b8a5fd50758 | ddfd29c1abecb035872a916f553edd9461107364 | refs/heads/master | 2022-12-14T08:19:27.456446 | 2020-09-25T17:33:09 | 2020-09-25T17:33:09 | 285,373,169 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,135 | cpp | //******************************************************************************
//******************************************************************************
//******************************************************************************
#include "stdafx.h"
#include "acmSuperDefs.h"
//******************************************************************************
//******************************************************************************
//******************************************************************************
// Return a super state variable as a string.
const char* asString_Qx(int aOpMode)
{
switch (aOpMode)
{
case cQx_None: return "None";
case cQx_Request: return "Request";
case cQx_Pending1: return "Pending1";
case cQx_Pending2: return "Pending2";
case cQx_Ack: return "Ack";
case cQx_Nak: return "Nak";
}
return "UNKNOWN";
}
//******************************************************************************
//******************************************************************************
//******************************************************************************
| [
"chris123hoen@gmail.com"
] | chris123hoen@gmail.com |
ee6067fe75a993410c4e953e7d69450c6beca1fa | 6492844c7a51701ae6fe2a735e0ed307823ee81a | /video_source/video_source_event_handler.cpp | ba0d64aa43a4b4be221ba1f196097821133ed00e | [
"MIT"
] | permissive | KICKdesigns/agora_electron | 9ee87b214bae7a410ee494b15ee42dc37b90347e | 118e978aa9ca3404012618023393308bb054ec7f | refs/heads/master | 2020-03-19T03:43:05.408482 | 2018-06-01T19:26:02 | 2018-06-01T19:26:02 | 135,755,365 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,194 | cpp | /*
* Copyright (c) 2018 Agora.io
* All rights reserved.
* Proprietry and Confidential -- Agora.io
*/
/*
* Created by Wang Yongli, 2018
*/
#include "video_source_event_handler.h"
#include "node_log.h"
AgoraVideoSourceEventHandler::AgoraVideoSourceEventHandler(AgoraVideoSource& videoSource)
: m_videoSource(videoSource)
{
}
AgoraVideoSourceEventHandler::~AgoraVideoSourceEventHandler()
{}
void AgoraVideoSourceEventHandler::onJoinChannelSuccess(const char* channel, uid_t uid, int elapsed)
{
LOG_INFO("%s, channel :%s, uid : %d, elapsed :%d", __FUNCTION__, channel, uid, elapsed);
m_videoSource.notifyJoinedChannel(uid);
}
void AgoraVideoSourceEventHandler::onRejoinChannelSuccess(const char* channel, uid_t uid, int elapsed)
{
LOG_INFO("%s, channel :%s, uid: %d, elapsed :%d", __FUNCTION__, channel, uid, elapsed);
m_videoSource.notifyJoinedChannel(uid);
}
void AgoraVideoSourceEventHandler::onWarning(int warn, const char* msg)
{
LOG_INFO("%s, warn :%d, msg :%s", __FUNCTION__, warn, msg);
}
void AgoraVideoSourceEventHandler::onError(int err, const char* msg)
{
LOG_INFO("%s, err : %d, msg :%s", __FUNCTION__, err, msg);
}
void AgoraVideoSourceEventHandler::onLeaveChannel(const RtcStats& stats)
{
LOG_INFO("%s", __FUNCTION__);
m_videoSource.notifyLeaveChannel();
}
void AgoraVideoSourceEventHandler::onRtcStats(const RtcStats& stats)
{
LOG_INFO("%s", __FUNCTION__);
}
void AgoraVideoSourceEventHandler::onVideoDeviceStateChanged(const char* deviceId, int deviceType, int deviceState)
{
LOG_INFO("%s, deviceId :%s, deviceType :%d, deviceStatus :%d", __FUNCTION__, deviceId, deviceType, deviceState);
}
void AgoraVideoSourceEventHandler::onNetworkQuality(uid_t uid, int txQuality, int rxQuality)
{
//LOG_INFO("%s, uid :%d, txQuality :%d, rxQuality:%d", __FUNCTION__, uid, txQuality, rxQuality);
}
void AgoraVideoSourceEventHandler::onLastmileQuality(int quality)
{
LOG_INFO("%s, quality :%d", __FUNCTION__, quality);
}
void AgoraVideoSourceEventHandler::onFirstLocalVideoFrame(int width, int height, int elapsed)
{
LOG_INFO("%s, width :%d, height :%d, elapsed: %d", __FUNCTION__, width, height, elapsed);
}
void AgoraVideoSourceEventHandler::onVideoSizeChanged(uid_t uid, int width, int height, int rotation)
{
LOG_INFO("%s, uid :%d, width :%d, height:%d, rotation :%d", __FUNCTION__, uid, width, height, rotation);
}
void AgoraVideoSourceEventHandler::onApiCallExecuted(int err, const char* api, const char* result)
{
LOG_INFO("%s, err :%d, api :%s, result :%s", __FUNCTION__, err, api, result);
}
void AgoraVideoSourceEventHandler::onLocalVideoStats(const LocalVideoStats& stats)
{
LOG_INFO("%s", __FUNCTION__);
}
void AgoraVideoSourceEventHandler::onCameraReady()
{
LOG_INFO("%s", __FUNCTION__);
}
void AgoraVideoSourceEventHandler::onCameraFocusAreaChanged(int x, int y, int width, int height)
{
LOG_INFO("%s, x :%d, y:%d, width:%d, heigh:%d", __FUNCTION__, x, y, width, height);
}
void AgoraVideoSourceEventHandler::onVideoStopped()
{
LOG_INFO("%s", __FUNCTION__);
}
void AgoraVideoSourceEventHandler::onConnectionLost()
{
LOG_INFO("%s", __FUNCTION__);
}
void AgoraVideoSourceEventHandler::onConnectionInterrupted()
{
LOG_INFO("%s", __FUNCTION__);
}
void AgoraVideoSourceEventHandler::onConnectionBanned()
{
LOG_INFO("%s", __FUNCTION__);
}
void AgoraVideoSourceEventHandler::onRefreshRecordingServiceStatus(int status)
{
LOG_INFO("%s, status :%d", __FUNCTION__, status);
}
void AgoraVideoSourceEventHandler::onRequestToken()
{
LOG_INFO("%s", __FUNCTION__);
m_videoSource.notifyRequestNewToken();
}
void AgoraVideoSourceEventHandler::onStreamPublished(const char *url, int error)
{
LOG_INFO("%s, url :%s, error :%d", __FUNCTION__, url, error);
}
void AgoraVideoSourceEventHandler::onStreamUnpublished(const char* url)
{
LOG_INFO("%s, url :%s", __FUNCTION__, url);
}
void AgoraVideoSourceEventHandler::onTranscodingUpdated()
{
LOG_INFO("%s", __FUNCTION__);
}
void AgoraVideoSourceEventHandler::onStreamInjectedStatus(const char* url, uid_t uid, int status)
{
LOG_INFO("%s, url :%s, uid :%d, status :%d", __FUNCTION__, url, uid, status);
}
| [
"jwang@KICKdesigns.com"
] | jwang@KICKdesigns.com |
fee655b8b31297a336d5c447d0d982faf4370d3a | 950406578c21d7ebe5a4b28abba4de8733991bf2 | /doc/examples/CppApiExamples/HelloWorldExample.cpp | 66622b0d933f9193472b81358e498bdd1a24a9c0 | [] | no_license | LucasNatoli/eaglemode | b0014b1e3b59b72d628062d37772de8761a00e8e | c794886afe0c34b0f73d0ffc0cb89e81fad2d7ea | refs/heads/master | 2020-04-14T18:49:18.779639 | 2019-01-04T00:28:42 | 2019-01-04T00:28:42 | 164,034,142 | 1 | 0 | null | 2019-01-03T23:38:17 | 2019-01-03T23:38:17 | null | UTF-8 | C++ | false | false | 979 | cpp | #include <emCore/emGUIFramework.h>
#include <emCore/emPanel.h>
class MyPanel : public emPanel {
public:
MyPanel(ParentArg parent, const emString & name);
virtual emString GetTitle();
protected:
virtual void Paint(const emPainter & painter, emColor canvasColor);
};
MyPanel::MyPanel(ParentArg parent, const emString & name)
: emPanel(parent,name)
{
}
emString MyPanel::GetTitle()
{
return "Hello World Example";
}
void MyPanel::Paint(const emPainter & painter, emColor canvasColor)
{
painter.Clear(emColor::BLACK);
painter.PaintTextBoxed(0,0,1,GetHeight(),"Hello World!",.01,emColor::RED);
}
MAIN_OR_WINMAIN_HERE
static int wrapped_main(int argc, char * argv[])
{
emInitLocale();
emGUIFramework framework;
framework.EnableAutoTermination();
emWindow * window=new emWindow(framework.GetRootContext());
window->SetWindowFlags(emWindow::WF_AUTO_DELETE);
emPanel * panel=new MyPanel(window,"root");
panel->Layout(0.0,0.0,4.0,3.0);
return framework.Run();
}
| [
"a.c.kalker@gmail.com"
] | a.c.kalker@gmail.com |
e54cb6bcf8e0fe24be52c9b47c9ba39a17f09a3c | 142f6f29a6bba53b048bb4189387dc9c887672ea | /UnitTest/testRectangle.cpp | a36d06bdaeaba4256e7091717ffa2cadd09b9434 | [] | no_license | jckhoa/ShapeCalculator2013 | 2a3886c0e79e41a663f32dd6c63956be07b23113 | 6977a87dfd167aa2c5739877372a7eefc35f2341 | refs/heads/master | 2020-08-05T15:33:39.754298 | 2019-10-07T07:30:30 | 2019-10-07T07:30:30 | 212,596,839 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,741 | cpp | #include "stdafx.h"
#include "CppUnitTest.h"
#include "Rectangle.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTest
{
TEST_CLASS(UnitTestRectangle)
{
public:
//Test empty constructor
TEST_METHOD(TestRectangle_Constructor0)
{
Rectangle rec;
Assert::AreEqual(0., rec.getWidth());
Assert::AreEqual(0., rec.getHeight());
}
//Test constructor with 2 arguments
TEST_METHOD(TestRectangle_Constructor2)
{
Rectangle rec(2., 3.);
Assert::AreEqual(2., rec.getWidth());
Assert::AreEqual(3., rec.getHeight());
}
TEST_METHOD(TestRectangle_setDimension)
{
Rectangle rec;
rec.setDimension(2., 3.);
Assert::AreEqual(2., rec.getWidth());
Assert::AreEqual(3., rec.getHeight());
}
TEST_METHOD(TestRectangle_GetWidth)
{
Rectangle rec(2., 3.);
Assert::AreEqual(2., rec.getWidth());
}
TEST_METHOD(TestRectangle_GetHeight)
{
Rectangle rec(2., 3.);
Assert::AreEqual(3., rec.getHeight());
}
TEST_METHOD(TestRectangle_IsSquare)
{
// expect false when the width is not equal to height
Rectangle rec1(2., 3.);
Assert::IsFalse(rec1.isSquare());
// expect true when the width is equal to height
Rectangle rec2(2., 2.);
Assert::IsTrue(rec2.isSquare());
}
TEST_METHOD(TestRectangle_getClassShapeName)
{
Assert::IsTrue(Rectangle::getClassShapeName() == "Rectangle");
}
TEST_METHOD(TestRectangle_getSerializationSize)
{
Rectangle rec;
Assert::IsTrue(rec.getSerializationSize() == 2);
}
// Test setDimension(const std::vector<double>&)
TEST_METHOD(TestRectangle_setDimension_vector)
{
Rectangle rec;
std::vector<double> v1;
rec.setDimension(v1);
Assert::AreEqual(0., rec.getWidth());
Assert::AreEqual(0., rec.getHeight());
std::vector<double> v2 = { 2.5 };
rec.setDimension(v2);
Assert::AreEqual(2.5, rec.getWidth());
Assert::AreEqual(0., rec.getHeight());
std::vector<double> v3 = { 3., 6.8 };
rec.setDimension(v3);
Assert::AreEqual(3., rec.getWidth());
Assert::AreEqual(6.8, rec.getHeight());
std::vector<double> v4 = { 7.4, 3., 2.5 };
rec.setDimension(v4);
Assert::AreEqual(7.4, rec.getWidth());
Assert::AreEqual(3., rec.getHeight());
}
TEST_METHOD(TestRectangle_getShapeName)
{
Rectangle rec;
Assert::IsTrue(rec.getShapeName() == "Rectangle");
}
TEST_METHOD(TestRectangle_GetPerimeter)
{
// Expect the perimeter to be zero for zero width or zero height
Rectangle z0;
Assert::AreEqual(0., z0.getPerimeter());
Rectangle z1(0., 2.);
Assert::AreEqual(0., z1.getPerimeter());
Rectangle z2(2., 0.);
Assert::AreEqual(0., z2.getPerimeter());
// Expect the perimeter to be zero for negative width or negative height
Rectangle n1(-4.2, 3);
Assert::AreEqual(0., n1.getPerimeter());
Rectangle n2(4.2, -3);
Assert::AreEqual(0., n2.getPerimeter());
Rectangle n3(-4.2, -3);
Assert::AreEqual(0., n3.getPerimeter());
// Expect the perimeter to be 2 * (width + height) for positive width and height
Rectangle rec(2., 3.);
double expected = 10.;
Assert::AreEqual(expected, rec.getPerimeter());
}
TEST_METHOD(TestRectangle_GetArea)
{
// Expect the area to be zero for zero width or zero height
Rectangle z0;
Assert::AreEqual(0., z0.getArea());
Rectangle z1(0., 2.);
Assert::AreEqual(0., z1.getArea());
Rectangle z2(2., 0.);
Assert::AreEqual(0., z2.getArea());
// Expect the area to be zero for negative width or negative height
Rectangle n1(-4.2, 3);
Assert::AreEqual(0., n1.getArea());
Rectangle n2(4.2, -3);
Assert::AreEqual(0., n2.getArea());
Rectangle n3(-4.2, -3);
Assert::AreEqual(0., n3.getArea());
// Expect the area to be width * height for positive width and height
Rectangle rec(2., 3.);
double expected = 6.;
Assert::AreEqual(expected, rec.getArea());
}
TEST_METHOD(TestRectangle_IsValid)
{
// Expect false for zero width or zero height
Rectangle z0;
Assert::IsFalse(z0.isValid());
Rectangle z1(0., 2.);
Assert::IsFalse(z1.isValid());
Rectangle z2(2., 0.);
Assert::IsFalse(z2.isValid());
// Expect false for negative width or negative height
Rectangle n1(-4.2, 3);
Assert::IsFalse(n1.isValid());
Rectangle n2(4.2, -3);
Assert::IsFalse(n2.isValid());
Rectangle n3(-4.2, -3);
Assert::IsFalse(n3.isValid());
// Expect true for positive width and height
Rectangle rec(2., 3.);
Assert::IsTrue(rec.isValid());
}
TEST_METHOD(TestRectangle_getInfoString) {
double width = 5;
double height = 6;
Rectangle rec(width, height);
std::string expected("Rectangle(width=5,height=6)");
Assert::AreEqual(expected, rec.getInfoString());
}
};
} | [
"jckhoa@yahoo.com"
] | jckhoa@yahoo.com |
aa2a6b9ed6118edb0b8aeb1df84c3603422a9ad3 | c973e9cc070d77b3bc1ee36ab303be05b5828d45 | /Country.cpp | 70e18cadc85fd39de525551e1b664b164928e860 | [] | no_license | houssen-kassir/COMP-345 | f2f991ba5d325f6b48b6f4ed354b1bba9aa97287 | e37674200f1427ba8da9f028040ece9ab54b89bf | refs/heads/master | 2020-09-02T12:20:01.927643 | 2019-10-31T19:42:18 | 2019-10-31T19:42:18 | 219,219,843 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 3,226 | cpp | #include <iostream>
#include <string>
#include "Country.h"
#include "Player.h"
Country::Country(std::string name) {
country_name = name; // string representing country name
continent_name = "";
//Initialized to NULL as when the country is created, it does not have an owner.
owner = NULL; // pointer to the player that currently owns the country
containing_continent = NULL;
//Initialized to false as when the country is created, it does not have an owner.
is_owned = false; // boolean representing if country is currently owned
number_of_armies = 0; // representing number of armies situated in this country
//std::cout << get_country_name() + " Country object created." << std::endl;
}
Country::~Country() {
//std::cout << get_country_name() + " Country object destroyed." << std::endl;
}
Country::Country(const Country &anotherCountry) {
country_name = anotherCountry.country_name;
continent_name = anotherCountry.continent_name;
owner = anotherCountry.owner;
containing_continent = anotherCountry.containing_continent;
is_owned = anotherCountry.is_owned;
number_of_armies = anotherCountry.number_of_armies;
}
void Country::set_continent_name(std::string c_name) {
continent_name = c_name;
notifyObservers();
}
std::string Country::get_country_name() {
return country_name;
}
std::string Country::get_continent_name() {
return continent_name;
}
void Country::set_owned(bool value, Player& player) {
//If value is true, then we can assign the address of the player to the Player pointer, owner.
if(value == true) {
is_owned = value;
owner = &player;
notifyObservers();
}
//Else, set the Player pointer, owner back to NULL.
else {
is_owned = value;
owner = NULL;
}
}
Player* Country::get_owner() {
return owner;
}
std::string Country::get_owner_name() {
//If the Player pointer, owner is currently set to NULL, inform the system that the country has no owner.
if(owner == NULL) {
return "This country has no owner!";
}
//Else, through the Player pointer, owner, retrieve the string value of the player's name.
else {
return owner->get_player_name();
}
}
bool Country::owned() {
return is_owned;
}
void Country::increment_armies(int amt) {
number_of_armies += amt;
notifyObservers();
//owner->Notify();
}
void Country::decrement_armies(int amt) {
//If the decrement will reduce the number of armies situated in the country to below 0, inform the system.
if((number_of_armies - amt) < 0) {
std::cout << "Invalid decrement. Cannot decrease the number of armies below 0" << std::endl;
}
//Else, decrement the number of armies by amt.
else {
number_of_armies -= amt;
notifyObservers();
}
}
int Country::get_number_of_armies() {
return number_of_armies;
}
void Country::notifyObservers() {
for (unsigned int i = 0; i < observers.size(); i++) {
observers.at(i)->update(this);
}
}
void Country::printConnectedCountries() {
for (Country* c : connectedCountries) {
cout << c->get_country_name() << endl;
}
}
| [
"noreply@github.com"
] | houssen-kassir.noreply@github.com |
9709ded8e7cc433659b89f1e13ef87e126f4d780 | 84d99cf96e02161c25c6617af715b1789cd0fc65 | /Seance8/E8/Amphibie.cpp | 14072a5789018ef1e77dab57d3cb551cdcae25d2 | [] | no_license | HunterKruger/learnCPP | f6e03926f060e903346c1a508907c4bfe2d7a1dd | e34aa7873fdabf048be1e59b3cc7b6c9f08a215d | refs/heads/master | 2020-07-03T11:38:29.669362 | 2019-10-27T12:02:06 | 2019-10-27T12:02:06 | 201,893,425 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 334 | cpp | // Amphibie.cpp
#include <iostream>
#include "Terrestre.h"
#include "Marin.h"
#include "Amphibie.h"
using namespace std;
Amphibie::Amphibie (int vmaxTer, int vmaxMar, int nbr, int tir)
: Terrestre(vmaxTer, nbr), Marin(vmaxMar, tir)
{
}
void Amphibie::afficher () const
{
Terrestre::afficher();
Marin::afficher();
}
| [
"793264282@qq.com"
] | 793264282@qq.com |
9cb02bbe1617bd6d7fc73951d1dcb58655a2e999 | a75bea5ee718e00b7ea381bb32a7296a92f29bd8 | /AES_CMAC/AES_CMAC/crypto_test.cpp | e81dbf75a26a0a3a22b872141475d6e6acdb6e07 | [] | no_license | Ryan311/LeSecurity | bab42b1ce1e56becb7f73099f49f7414257752ba | 0db3397baefb651db2dde85d629fa8b8587ccd17 | refs/heads/master | 2021-01-10T15:27:40.315527 | 2016-03-28T08:29:28 | 2016-03-28T08:29:28 | 54,878,380 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,474 | cpp | #include "stdafx.h"
#include "aes_encrypt.h"
#include "aes_cmac.h"
#include "aes_encrypt.h"
#include "ble_smp_crypto.h"
void print_help(void)
{
printf("/*********************************************/\n");
printf("LE SMP crypto functions tester:\n");
printf(" BLECryptoFuncs.exe [test number]\n");
printf(" [test number]:\n");
printf(" 1 AES_128\n");
printf(" 2 SMP_ah\n");
printf(" 3 SMP_c1\n");
printf(" 4 SMP_s1\n");
printf(" 5 AES_CMAC\n");
printf(" 6 SMP_f4\n");
printf(" 7 SMP_f5\n");
printf(" 8 SMP_f6\n");
printf(" 9 SMP_g2\n");
printf(" a SMP_h6\n");
printf(" h Help\n");
printf(" q Quit\n");
printf("/*********************************************/\n");
}
int _tmain(int argc, _TCHAR* argv[])
{
printf("This is BLE smp test app");
print_help();
int op;
do{
printf("Enter the test number:");
op = getchar();
if (op == 'q') break;
switch (op)
{
case '1':
AES_128_Test();
break;
case '2':
Bt_SMP_ah_Test();
break;
case '3':
Bt_SMP_c1_Test();
break;
case '4':
Bt_SMP_s1_Test();
break;
case '5':
AES_CMAC_Test();
break;
case '6':
Bt_SMP_f4_Test();
break;
case '7':
Bt_SMP_f5_Test();
break;
case '8':
Bt_SMP_f6_Test();
break;
case '9':
Bt_SMP_g2_Test();
break;
case 'a':
Bt_SMP_h6_Test();
break;
case 'h':
print_help();
default:
print_help();
break;
}
getchar();
} while (true);
return 1;
} | [
"persnail311@gmail.com"
] | persnail311@gmail.com |
d6f10ef971433d10478f1a220a563198863b1dd2 | 4297ad692ad0388fd8a9f548764073e9747376d2 | /thirdparty/spirv-cross/spirv_glsl.cpp | c8bf7e0e764833f0d5a7d9e0967f521187017b2a | [
"Apache-2.0",
"MIT"
] | permissive | frank-lesser/abstract-gpu | b666e62a78b6c5b2e79baf30b123cd25ede0894e | a50fab26b398eff116a66f8eb37ebebc63c19824 | refs/heads/master | 2022-10-09T16:36:43.447174 | 2020-06-11T22:41:42 | 2020-06-11T22:41:42 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 355,606 | cpp | /*
* Copyright 2015-2019 Arm 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 "spirv_glsl.hpp"
#include "GLSL.std.450.h"
#include "spirv_common.hpp"
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <limits>
#include <locale.h>
#include <utility>
#ifndef _WIN32
#include <langinfo.h>
#endif
#include <locale.h>
using namespace spv;
using namespace SPIRV_CROSS_NAMESPACE;
using namespace std;
static bool is_unsigned_opcode(Op op)
{
// Don't have to be exhaustive, only relevant for legacy target checking ...
switch (op)
{
case OpShiftRightLogical:
case OpUGreaterThan:
case OpUGreaterThanEqual:
case OpULessThan:
case OpULessThanEqual:
case OpUConvert:
case OpUDiv:
case OpUMod:
case OpUMulExtended:
case OpConvertUToF:
case OpConvertFToU:
return true;
default:
return false;
}
}
static bool is_unsigned_glsl_opcode(GLSLstd450 op)
{
// Don't have to be exhaustive, only relevant for legacy target checking ...
switch (op)
{
case GLSLstd450UClamp:
case GLSLstd450UMin:
case GLSLstd450UMax:
case GLSLstd450FindUMsb:
return true;
default:
return false;
}
}
static bool packing_is_vec4_padded(BufferPackingStandard packing)
{
switch (packing)
{
case BufferPackingHLSLCbuffer:
case BufferPackingHLSLCbufferPackOffset:
case BufferPackingStd140:
case BufferPackingStd140EnhancedLayout:
return true;
default:
return false;
}
}
static bool packing_is_hlsl(BufferPackingStandard packing)
{
switch (packing)
{
case BufferPackingHLSLCbuffer:
case BufferPackingHLSLCbufferPackOffset:
return true;
default:
return false;
}
}
static bool packing_has_flexible_offset(BufferPackingStandard packing)
{
switch (packing)
{
case BufferPackingStd140:
case BufferPackingStd430:
case BufferPackingHLSLCbuffer:
return false;
default:
return true;
}
}
static BufferPackingStandard packing_to_substruct_packing(BufferPackingStandard packing)
{
switch (packing)
{
case BufferPackingStd140EnhancedLayout:
return BufferPackingStd140;
case BufferPackingStd430EnhancedLayout:
return BufferPackingStd430;
case BufferPackingHLSLCbufferPackOffset:
return BufferPackingHLSLCbuffer;
default:
return packing;
}
}
// Sanitizes underscores for GLSL where multiple underscores in a row are not allowed.
string CompilerGLSL::sanitize_underscores(const string &str)
{
string res;
res.reserve(str.size());
bool last_underscore = false;
for (auto c : str)
{
if (c == '_')
{
if (last_underscore)
continue;
res += c;
last_underscore = true;
}
else
{
res += c;
last_underscore = false;
}
}
return res;
}
void CompilerGLSL::init()
{
if (ir.source.known)
{
options.es = ir.source.es;
options.version = ir.source.version;
}
// Query the locale to see what the decimal point is.
// We'll rely on fixing it up ourselves in the rare case we have a comma-as-decimal locale
// rather than setting locales ourselves. Settings locales in a safe and isolated way is rather
// tricky.
#ifdef _WIN32
// On Windows, localeconv uses thread-local storage, so it should be fine.
const struct lconv *conv = localeconv();
if (conv && conv->decimal_point)
current_locale_radix_character = *conv->decimal_point;
#elif defined(__ANDROID__) && __ANDROID_API__ < 26
// nl_langinfo is not supported on this platform, fall back to the worse alternative.
const struct lconv *conv = localeconv();
if (conv && conv->decimal_point)
current_locale_radix_character = *conv->decimal_point;
#else
// localeconv, the portable function is not MT safe ...
const char *decimal_point = nl_langinfo(RADIXCHAR);
if (decimal_point && *decimal_point != '\0')
current_locale_radix_character = *decimal_point;
#endif
}
static const char *to_pls_layout(PlsFormat format)
{
switch (format)
{
case PlsR11FG11FB10F:
return "layout(r11f_g11f_b10f) ";
case PlsR32F:
return "layout(r32f) ";
case PlsRG16F:
return "layout(rg16f) ";
case PlsRGB10A2:
return "layout(rgb10_a2) ";
case PlsRGBA8:
return "layout(rgba8) ";
case PlsRG16:
return "layout(rg16) ";
case PlsRGBA8I:
return "layout(rgba8i)";
case PlsRG16I:
return "layout(rg16i) ";
case PlsRGB10A2UI:
return "layout(rgb10_a2ui) ";
case PlsRGBA8UI:
return "layout(rgba8ui) ";
case PlsRG16UI:
return "layout(rg16ui) ";
case PlsR32UI:
return "layout(r32ui) ";
default:
return "";
}
}
static SPIRType::BaseType pls_format_to_basetype(PlsFormat format)
{
switch (format)
{
default:
case PlsR11FG11FB10F:
case PlsR32F:
case PlsRG16F:
case PlsRGB10A2:
case PlsRGBA8:
case PlsRG16:
return SPIRType::Float;
case PlsRGBA8I:
case PlsRG16I:
return SPIRType::Int;
case PlsRGB10A2UI:
case PlsRGBA8UI:
case PlsRG16UI:
case PlsR32UI:
return SPIRType::UInt;
}
}
static uint32_t pls_format_to_components(PlsFormat format)
{
switch (format)
{
default:
case PlsR32F:
case PlsR32UI:
return 1;
case PlsRG16F:
case PlsRG16:
case PlsRG16UI:
case PlsRG16I:
return 2;
case PlsR11FG11FB10F:
return 3;
case PlsRGB10A2:
case PlsRGBA8:
case PlsRGBA8I:
case PlsRGB10A2UI:
case PlsRGBA8UI:
return 4;
}
}
static const char *vector_swizzle(int vecsize, int index)
{
static const char *swizzle[4][4] = {
{ ".x", ".y", ".z", ".w" }, { ".xy", ".yz", ".zw" }, { ".xyz", ".yzw" }, { "" }
};
assert(vecsize >= 1 && vecsize <= 4);
assert(index >= 0 && index < 4);
assert(swizzle[vecsize - 1][index]);
return swizzle[vecsize - 1][index];
}
void CompilerGLSL::reset()
{
// We do some speculative optimizations which should pretty much always work out,
// but just in case the SPIR-V is rather weird, recompile until it's happy.
// This typically only means one extra pass.
force_recompile = false;
// Clear invalid expression tracking.
invalid_expressions.clear();
current_function = nullptr;
// Clear temporary usage tracking.
expression_usage_counts.clear();
forwarded_temporaries.clear();
reset_name_caches();
ir.for_each_typed_id<SPIRFunction>([&](uint32_t, SPIRFunction &func) {
func.active = false;
func.flush_undeclared = true;
});
ir.for_each_typed_id<SPIRVariable>([&](uint32_t, SPIRVariable &var) { var.dependees.clear(); });
ir.reset_all_of_type<SPIRExpression>();
ir.reset_all_of_type<SPIRAccessChain>();
statement_count = 0;
indent = 0;
}
void CompilerGLSL::remap_pls_variables()
{
for (auto &input : pls_inputs)
{
auto &var = get<SPIRVariable>(input.id);
bool input_is_target = false;
if (var.storage == StorageClassUniformConstant)
{
auto &type = get<SPIRType>(var.basetype);
input_is_target = type.image.dim == DimSubpassData;
}
if (var.storage != StorageClassInput && !input_is_target)
SPIRV_CROSS_THROW("Can only use in and target variables for PLS inputs.");
var.remapped_variable = true;
}
for (auto &output : pls_outputs)
{
auto &var = get<SPIRVariable>(output.id);
if (var.storage != StorageClassOutput)
SPIRV_CROSS_THROW("Can only use out variables for PLS outputs.");
var.remapped_variable = true;
}
}
void CompilerGLSL::find_static_extensions()
{
ir.for_each_typed_id<SPIRType>([&](uint32_t, const SPIRType &type) {
if (type.basetype == SPIRType::Double)
{
if (options.es)
SPIRV_CROSS_THROW("FP64 not supported in ES profile.");
if (!options.es && options.version < 400)
require_extension_internal("GL_ARB_gpu_shader_fp64");
}
else if (type.basetype == SPIRType::Int64 || type.basetype == SPIRType::UInt64)
{
if (options.es)
SPIRV_CROSS_THROW("64-bit integers not supported in ES profile.");
if (!options.es)
require_extension_internal("GL_ARB_gpu_shader_int64");
}
else if (type.basetype == SPIRType::Half)
{
require_extension_internal("GL_EXT_shader_explicit_arithmetic_types_float16");
if (options.vulkan_semantics)
require_extension_internal("GL_EXT_shader_16bit_storage");
}
else if (type.basetype == SPIRType::SByte || type.basetype == SPIRType::UByte)
{
require_extension_internal("GL_EXT_shader_explicit_arithmetic_types_int8");
if (options.vulkan_semantics)
require_extension_internal("GL_EXT_shader_8bit_storage");
}
else if (type.basetype == SPIRType::Short || type.basetype == SPIRType::UShort)
{
require_extension_internal("GL_EXT_shader_explicit_arithmetic_types_int16");
if (options.vulkan_semantics)
require_extension_internal("GL_EXT_shader_16bit_storage");
}
});
auto &execution = get_entry_point();
switch (execution.model)
{
case ExecutionModelGLCompute:
if (!options.es && options.version < 430)
require_extension_internal("GL_ARB_compute_shader");
if (options.es && options.version < 310)
SPIRV_CROSS_THROW("At least ESSL 3.10 required for compute shaders.");
break;
case ExecutionModelGeometry:
if (options.es && options.version < 320)
require_extension_internal("GL_EXT_geometry_shader");
if (!options.es && options.version < 150)
require_extension_internal("GL_ARB_geometry_shader4");
if (execution.flags.get(ExecutionModeInvocations) && execution.invocations != 1)
{
// Instanced GS is part of 400 core or this extension.
if (!options.es && options.version < 400)
require_extension_internal("GL_ARB_gpu_shader5");
}
break;
case ExecutionModelTessellationEvaluation:
case ExecutionModelTessellationControl:
if (options.es && options.version < 320)
require_extension_internal("GL_EXT_tessellation_shader");
if (!options.es && options.version < 400)
require_extension_internal("GL_ARB_tessellation_shader");
break;
case ExecutionModelRayGenerationNV:
case ExecutionModelIntersectionNV:
case ExecutionModelAnyHitNV:
case ExecutionModelClosestHitNV:
case ExecutionModelMissNV:
case ExecutionModelCallableNV:
if (options.es || options.version < 460)
SPIRV_CROSS_THROW("Ray tracing shaders require non-es profile with version 460 or above.");
require_extension_internal("GL_NV_ray_tracing");
break;
default:
break;
}
if (!pls_inputs.empty() || !pls_outputs.empty())
require_extension_internal("GL_EXT_shader_pixel_local_storage");
if (options.separate_shader_objects && !options.es && options.version < 410)
require_extension_internal("GL_ARB_separate_shader_objects");
}
string CompilerGLSL::compile()
{
if (options.vulkan_semantics)
backend.allow_precision_qualifiers = true;
backend.force_gl_in_out_block = true;
backend.supports_extensions = true;
// Scan the SPIR-V to find trivial uses of extensions.
build_function_control_flow_graphs_and_analyze();
find_static_extensions();
fixup_image_load_store_access();
update_active_builtins();
analyze_image_and_sampler_usage();
uint32_t pass_count = 0;
do
{
if (pass_count >= 3)
SPIRV_CROSS_THROW("Over 3 compilation loops detected. Must be a bug!");
reset();
// Move constructor for this type is broken on GCC 4.9 ...
buffer = unique_ptr<ostringstream>(new ostringstream());
emit_header();
emit_resources();
emit_function(get<SPIRFunction>(ir.default_entry_point), Bitset());
pass_count++;
} while (force_recompile);
// Entry point in GLSL is always main().
get_entry_point().name = "main";
return buffer->str();
}
std::string CompilerGLSL::get_partial_source()
{
return buffer ? buffer->str() : "No compiled source available yet.";
}
void CompilerGLSL::build_workgroup_size(vector<string> &arguments, const SpecializationConstant &wg_x,
const SpecializationConstant &wg_y, const SpecializationConstant &wg_z)
{
auto &execution = get_entry_point();
if (wg_x.id)
{
if (options.vulkan_semantics)
arguments.push_back(join("local_size_x_id = ", wg_x.constant_id));
else
arguments.push_back(join("local_size_x = ", get<SPIRConstant>(wg_x.id).specialization_constant_macro_name));
}
else
arguments.push_back(join("local_size_x = ", execution.workgroup_size.x));
if (wg_y.id)
{
if (options.vulkan_semantics)
arguments.push_back(join("local_size_y_id = ", wg_y.constant_id));
else
arguments.push_back(join("local_size_y = ", get<SPIRConstant>(wg_y.id).specialization_constant_macro_name));
}
else
arguments.push_back(join("local_size_y = ", execution.workgroup_size.y));
if (wg_z.id)
{
if (options.vulkan_semantics)
arguments.push_back(join("local_size_z_id = ", wg_z.constant_id));
else
arguments.push_back(join("local_size_z = ", get<SPIRConstant>(wg_z.id).specialization_constant_macro_name));
}
else
arguments.push_back(join("local_size_z = ", execution.workgroup_size.z));
}
void CompilerGLSL::emit_header()
{
auto &execution = get_entry_point();
statement("#version ", options.version, options.es && options.version > 100 ? " es" : "");
if (!options.es && options.version < 420)
{
// Needed for binding = # on UBOs, etc.
if (options.enable_420pack_extension)
{
statement("#ifdef GL_ARB_shading_language_420pack");
statement("#extension GL_ARB_shading_language_420pack : require");
statement("#endif");
}
// Needed for: layout(early_fragment_tests) in;
if (execution.flags.get(ExecutionModeEarlyFragmentTests))
require_extension_internal("GL_ARB_shader_image_load_store");
}
for (auto &ext : forced_extensions)
{
if (ext == "GL_EXT_shader_explicit_arithmetic_types_float16")
{
// Special case, this extension has a potential fallback to another vendor extension in normal GLSL.
// GL_AMD_gpu_shader_half_float is a superset, so try that first.
statement("#if defined(GL_AMD_gpu_shader_half_float)");
statement("#extension GL_AMD_gpu_shader_half_float : require");
if (!options.vulkan_semantics)
{
statement("#elif defined(GL_NV_gpu_shader5)");
statement("#extension GL_NV_gpu_shader5 : require");
}
else
{
statement("#elif defined(GL_EXT_shader_explicit_arithmetic_types_float16)");
statement("#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require");
}
statement("#else");
statement("#error No extension available for FP16.");
statement("#endif");
}
else if (ext == "GL_EXT_shader_explicit_arithmetic_types_int16")
{
if (options.vulkan_semantics)
statement("#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require");
else
{
statement("#if defined(GL_AMD_gpu_shader_int16)");
statement("#extension GL_AMD_gpu_shader_int16 : require");
statement("#else");
statement("#error No extension available for Int16.");
statement("#endif");
}
}
else
statement("#extension ", ext, " : require");
}
for (auto &header : header_lines)
statement(header);
vector<string> inputs;
vector<string> outputs;
switch (execution.model)
{
case ExecutionModelGeometry:
outputs.push_back(join("max_vertices = ", execution.output_vertices));
if ((execution.flags.get(ExecutionModeInvocations)) && execution.invocations != 1)
inputs.push_back(join("invocations = ", execution.invocations));
if (execution.flags.get(ExecutionModeInputPoints))
inputs.push_back("points");
if (execution.flags.get(ExecutionModeInputLines))
inputs.push_back("lines");
if (execution.flags.get(ExecutionModeInputLinesAdjacency))
inputs.push_back("lines_adjacency");
if (execution.flags.get(ExecutionModeTriangles))
inputs.push_back("triangles");
if (execution.flags.get(ExecutionModeInputTrianglesAdjacency))
inputs.push_back("triangles_adjacency");
if (execution.flags.get(ExecutionModeOutputTriangleStrip))
outputs.push_back("triangle_strip");
if (execution.flags.get(ExecutionModeOutputPoints))
outputs.push_back("points");
if (execution.flags.get(ExecutionModeOutputLineStrip))
outputs.push_back("line_strip");
break;
case ExecutionModelTessellationControl:
if (execution.flags.get(ExecutionModeOutputVertices))
outputs.push_back(join("vertices = ", execution.output_vertices));
break;
case ExecutionModelTessellationEvaluation:
if (execution.flags.get(ExecutionModeQuads))
inputs.push_back("quads");
if (execution.flags.get(ExecutionModeTriangles))
inputs.push_back("triangles");
if (execution.flags.get(ExecutionModeIsolines))
inputs.push_back("isolines");
if (execution.flags.get(ExecutionModePointMode))
inputs.push_back("point_mode");
if (!execution.flags.get(ExecutionModeIsolines))
{
if (execution.flags.get(ExecutionModeVertexOrderCw))
inputs.push_back("cw");
if (execution.flags.get(ExecutionModeVertexOrderCcw))
inputs.push_back("ccw");
}
if (execution.flags.get(ExecutionModeSpacingFractionalEven))
inputs.push_back("fractional_even_spacing");
if (execution.flags.get(ExecutionModeSpacingFractionalOdd))
inputs.push_back("fractional_odd_spacing");
if (execution.flags.get(ExecutionModeSpacingEqual))
inputs.push_back("equal_spacing");
break;
case ExecutionModelGLCompute:
{
if (execution.workgroup_size.constant != 0)
{
SpecializationConstant wg_x, wg_y, wg_z;
get_work_group_size_specialization_constants(wg_x, wg_y, wg_z);
// If there are any spec constants on legacy GLSL, defer declaration, we need to set up macro
// declarations before we can emit the work group size.
if (options.vulkan_semantics || ((wg_x.id == 0) && (wg_y.id == 0) && (wg_z.id == 0)))
build_workgroup_size(inputs, wg_x, wg_y, wg_z);
}
else
{
inputs.push_back(join("local_size_x = ", execution.workgroup_size.x));
inputs.push_back(join("local_size_y = ", execution.workgroup_size.y));
inputs.push_back(join("local_size_z = ", execution.workgroup_size.z));
}
break;
}
case ExecutionModelFragment:
if (options.es)
{
switch (options.fragment.default_float_precision)
{
case Options::Lowp:
statement("precision lowp float;");
break;
case Options::Mediump:
statement("precision mediump float;");
break;
case Options::Highp:
statement("precision highp float;");
break;
default:
break;
}
switch (options.fragment.default_int_precision)
{
case Options::Lowp:
statement("precision lowp int;");
break;
case Options::Mediump:
statement("precision mediump int;");
break;
case Options::Highp:
statement("precision highp int;");
break;
default:
break;
}
}
if (execution.flags.get(ExecutionModeEarlyFragmentTests))
inputs.push_back("early_fragment_tests");
if (!options.es && execution.flags.get(ExecutionModeDepthGreater))
statement("layout(depth_greater) out float gl_FragDepth;");
else if (!options.es && execution.flags.get(ExecutionModeDepthLess))
statement("layout(depth_less) out float gl_FragDepth;");
break;
default:
break;
}
if (!inputs.empty())
statement("layout(", merge(inputs), ") in;");
if (!outputs.empty())
statement("layout(", merge(outputs), ") out;");
statement("");
}
bool CompilerGLSL::type_is_empty(const SPIRType &type)
{
return type.basetype == SPIRType::Struct && type.member_types.empty();
}
void CompilerGLSL::emit_struct(SPIRType &type)
{
// Struct types can be stamped out multiple times
// with just different offsets, matrix layouts, etc ...
// Type-punning with these types is legal, which complicates things
// when we are storing struct and array types in an SSBO for example.
// If the type master is packed however, we can no longer assume that the struct declaration will be redundant.
if (type.type_alias != 0 && !has_extended_decoration(type.type_alias, SPIRVCrossDecorationPacked))
return;
add_resource_name(type.self);
auto name = type_to_glsl(type);
statement(!backend.explicit_struct_type ? "struct " : "", name);
begin_scope();
type.member_name_cache.clear();
uint32_t i = 0;
bool emitted = false;
for (auto &member : type.member_types)
{
add_member_name(type, i);
emit_struct_member(type, member, i);
i++;
emitted = true;
}
// Don't declare empty structs in GLSL, this is not allowed.
if (type_is_empty(type) && !backend.supports_empty_struct)
{
statement("int empty_struct_member;");
emitted = true;
}
end_scope_decl();
if (emitted)
statement("");
}
string CompilerGLSL::to_interpolation_qualifiers(const Bitset &flags)
{
string res;
//if (flags & (1ull << DecorationSmooth))
// res += "smooth ";
if (flags.get(DecorationFlat))
res += "flat ";
if (flags.get(DecorationNoPerspective))
res += "noperspective ";
if (flags.get(DecorationCentroid))
res += "centroid ";
if (flags.get(DecorationPatch))
res += "patch ";
if (flags.get(DecorationSample))
res += "sample ";
if (flags.get(DecorationInvariant))
res += "invariant ";
if (flags.get(DecorationExplicitInterpAMD))
res += "__explicitInterpAMD ";
return res;
}
string CompilerGLSL::layout_for_member(const SPIRType &type, uint32_t index)
{
if (is_legacy())
return "";
bool is_block = ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock) ||
ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock);
if (!is_block)
return "";
auto &memb = ir.meta[type.self].members;
if (index >= memb.size())
return "";
auto &dec = memb[index];
vector<string> attr;
// We can only apply layouts on members in block interfaces.
// This is a bit problematic because in SPIR-V decorations are applied on the struct types directly.
// This is not supported on GLSL, so we have to make the assumption that if a struct within our buffer block struct
// has a decoration, it was originally caused by a top-level layout() qualifier in GLSL.
//
// We would like to go from (SPIR-V style):
//
// struct Foo { layout(row_major) mat4 matrix; };
// buffer UBO { Foo foo; };
//
// to
//
// struct Foo { mat4 matrix; }; // GLSL doesn't support any layout shenanigans in raw struct declarations.
// buffer UBO { layout(row_major) Foo foo; }; // Apply the layout on top-level.
auto flags = combined_decoration_for_member(type, index);
if (flags.get(DecorationRowMajor))
attr.push_back("row_major");
// We don't emit any global layouts, so column_major is default.
//if (flags & (1ull << DecorationColMajor))
// attr.push_back("column_major");
if (dec.decoration_flags.get(DecorationLocation) && can_use_io_location(type.storage, true))
attr.push_back(join("location = ", dec.location));
// Can only declare component if we can declare location.
if (dec.decoration_flags.get(DecorationComponent) && can_use_io_location(type.storage, true))
{
if (!options.es)
{
if (options.version < 440 && options.version >= 140)
require_extension_internal("GL_ARB_enhanced_layouts");
else if (options.version < 140)
SPIRV_CROSS_THROW("Component decoration is not supported in targets below GLSL 1.40.");
attr.push_back(join("component = ", dec.component));
}
else
SPIRV_CROSS_THROW("Component decoration is not supported in ES targets.");
}
// SPIRVCrossDecorationPacked is set by layout_for_variable earlier to mark that we need to emit offset qualifiers.
// This is only done selectively in GLSL as needed.
if (has_extended_decoration(type.self, SPIRVCrossDecorationPacked) && dec.decoration_flags.get(DecorationOffset))
attr.push_back(join("offset = ", dec.offset));
if (attr.empty())
return "";
string res = "layout(";
res += merge(attr);
res += ") ";
return res;
}
const char *CompilerGLSL::format_to_glsl(spv::ImageFormat format)
{
if (options.es && is_desktop_only_format(format))
SPIRV_CROSS_THROW("Attempting to use image format not supported in ES profile.");
switch (format)
{
case ImageFormatRgba32f:
return "rgba32f";
case ImageFormatRgba16f:
return "rgba16f";
case ImageFormatR32f:
return "r32f";
case ImageFormatRgba8:
return "rgba8";
case ImageFormatRgba8Snorm:
return "rgba8_snorm";
case ImageFormatRg32f:
return "rg32f";
case ImageFormatRg16f:
return "rg16f";
case ImageFormatRgba32i:
return "rgba32i";
case ImageFormatRgba16i:
return "rgba16i";
case ImageFormatR32i:
return "r32i";
case ImageFormatRgba8i:
return "rgba8i";
case ImageFormatRg32i:
return "rg32i";
case ImageFormatRg16i:
return "rg16i";
case ImageFormatRgba32ui:
return "rgba32ui";
case ImageFormatRgba16ui:
return "rgba16ui";
case ImageFormatR32ui:
return "r32ui";
case ImageFormatRgba8ui:
return "rgba8ui";
case ImageFormatRg32ui:
return "rg32ui";
case ImageFormatRg16ui:
return "rg16ui";
case ImageFormatR11fG11fB10f:
return "r11f_g11f_b10f";
case ImageFormatR16f:
return "r16f";
case ImageFormatRgb10A2:
return "rgb10_a2";
case ImageFormatR8:
return "r8";
case ImageFormatRg8:
return "rg8";
case ImageFormatR16:
return "r16";
case ImageFormatRg16:
return "rg16";
case ImageFormatRgba16:
return "rgba16";
case ImageFormatR16Snorm:
return "r16_snorm";
case ImageFormatRg16Snorm:
return "rg16_snorm";
case ImageFormatRgba16Snorm:
return "rgba16_snorm";
case ImageFormatR8Snorm:
return "r8_snorm";
case ImageFormatRg8Snorm:
return "rg8_snorm";
case ImageFormatR8ui:
return "r8ui";
case ImageFormatRg8ui:
return "rg8ui";
case ImageFormatR16ui:
return "r16ui";
case ImageFormatRgb10a2ui:
return "rgb10_a2ui";
case ImageFormatR8i:
return "r8i";
case ImageFormatRg8i:
return "rg8i";
case ImageFormatR16i:
return "r16i";
default:
case ImageFormatUnknown:
return nullptr;
}
}
uint32_t CompilerGLSL::type_to_packed_base_size(const SPIRType &type, BufferPackingStandard)
{
switch (type.basetype)
{
case SPIRType::Double:
case SPIRType::Int64:
case SPIRType::UInt64:
return 8;
case SPIRType::Float:
case SPIRType::Int:
case SPIRType::UInt:
return 4;
case SPIRType::Half:
case SPIRType::Short:
case SPIRType::UShort:
return 2;
case SPIRType::SByte:
case SPIRType::UByte:
return 1;
default:
SPIRV_CROSS_THROW("Unrecognized type in type_to_packed_base_size.");
}
}
uint32_t CompilerGLSL::type_to_packed_alignment(const SPIRType &type, const Bitset &flags,
BufferPackingStandard packing)
{
if (!type.array.empty())
{
uint32_t minimum_alignment = 1;
if (packing_is_vec4_padded(packing))
minimum_alignment = 16;
auto *tmp = &get<SPIRType>(type.parent_type);
while (!tmp->array.empty())
tmp = &get<SPIRType>(tmp->parent_type);
// Get the alignment of the base type, then maybe round up.
return max(minimum_alignment, type_to_packed_alignment(*tmp, flags, packing));
}
if (type.basetype == SPIRType::Struct)
{
// Rule 9. Structs alignments are maximum alignment of its members.
uint32_t alignment = 1;
for (uint32_t i = 0; i < type.member_types.size(); i++)
{
auto member_flags = ir.meta[type.self].members[i].decoration_flags;
alignment =
max(alignment, type_to_packed_alignment(get<SPIRType>(type.member_types[i]), member_flags, packing));
}
// In std140, struct alignment is rounded up to 16.
if (packing_is_vec4_padded(packing))
alignment = max(alignment, 16u);
return alignment;
}
else
{
const uint32_t base_alignment = type_to_packed_base_size(type, packing);
// Vectors are *not* aligned in HLSL, but there's an extra rule where vectors cannot straddle
// a vec4, this is handled outside since that part knows our current offset.
if (type.columns == 1 && packing_is_hlsl(packing))
return base_alignment;
// From 7.6.2.2 in GL 4.5 core spec.
// Rule 1
if (type.vecsize == 1 && type.columns == 1)
return base_alignment;
// Rule 2
if ((type.vecsize == 2 || type.vecsize == 4) && type.columns == 1)
return type.vecsize * base_alignment;
// Rule 3
if (type.vecsize == 3 && type.columns == 1)
return 4 * base_alignment;
// Rule 4 implied. Alignment does not change in std430.
// Rule 5. Column-major matrices are stored as arrays of
// vectors.
if (flags.get(DecorationColMajor) && type.columns > 1)
{
if (packing_is_vec4_padded(packing))
return 4 * base_alignment;
else if (type.vecsize == 3)
return 4 * base_alignment;
else
return type.vecsize * base_alignment;
}
// Rule 6 implied.
// Rule 7.
if (flags.get(DecorationRowMajor) && type.vecsize > 1)
{
if (packing_is_vec4_padded(packing))
return 4 * base_alignment;
else if (type.columns == 3)
return 4 * base_alignment;
else
return type.columns * base_alignment;
}
// Rule 8 implied.
}
SPIRV_CROSS_THROW("Did not find suitable rule for type. Bogus decorations?");
}
uint32_t CompilerGLSL::type_to_packed_array_stride(const SPIRType &type, const Bitset &flags,
BufferPackingStandard packing)
{
// Array stride is equal to aligned size of the underlying type.
uint32_t parent = type.parent_type;
assert(parent);
auto &tmp = get<SPIRType>(parent);
uint32_t size = type_to_packed_size(tmp, flags, packing);
if (tmp.array.empty())
{
uint32_t alignment = type_to_packed_alignment(type, flags, packing);
return (size + alignment - 1) & ~(alignment - 1);
}
else
{
// For multidimensional arrays, array stride always matches size of subtype.
// The alignment cannot change because multidimensional arrays are basically N * M array elements.
return size;
}
}
uint32_t CompilerGLSL::type_to_packed_size(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing)
{
if (!type.array.empty())
{
return to_array_size_literal(type) * type_to_packed_array_stride(type, flags, packing);
}
uint32_t size = 0;
if (type.basetype == SPIRType::Struct)
{
uint32_t pad_alignment = 1;
for (uint32_t i = 0; i < type.member_types.size(); i++)
{
auto member_flags = ir.meta[type.self].members[i].decoration_flags;
auto &member_type = get<SPIRType>(type.member_types[i]);
uint32_t packed_alignment = type_to_packed_alignment(member_type, member_flags, packing);
uint32_t alignment = max(packed_alignment, pad_alignment);
// The next member following a struct member is aligned to the base alignment of the struct that came before.
// GL 4.5 spec, 7.6.2.2.
if (member_type.basetype == SPIRType::Struct)
pad_alignment = packed_alignment;
else
pad_alignment = 1;
size = (size + alignment - 1) & ~(alignment - 1);
size += type_to_packed_size(member_type, member_flags, packing);
}
}
else
{
const uint32_t base_alignment = type_to_packed_base_size(type, packing);
if (type.columns == 1)
size = type.vecsize * base_alignment;
if (flags.get(DecorationColMajor) && type.columns > 1)
{
if (packing_is_vec4_padded(packing))
size = type.columns * 4 * base_alignment;
else if (type.vecsize == 3)
size = type.columns * 4 * base_alignment;
else
size = type.columns * type.vecsize * base_alignment;
}
if (flags.get(DecorationRowMajor) && type.vecsize > 1)
{
if (packing_is_vec4_padded(packing))
size = type.vecsize * 4 * base_alignment;
else if (type.columns == 3)
size = type.vecsize * 4 * base_alignment;
else
size = type.vecsize * type.columns * base_alignment;
}
}
return size;
}
bool CompilerGLSL::buffer_is_packing_standard(const SPIRType &type, BufferPackingStandard packing,
uint32_t start_offset, uint32_t end_offset)
{
// This is very tricky and error prone, but try to be exhaustive and correct here.
// SPIR-V doesn't directly say if we're using std430 or std140.
// SPIR-V communicates this using Offset and ArrayStride decorations (which is what really matters),
// so we have to try to infer whether or not the original GLSL source was std140 or std430 based on this information.
// We do not have to consider shared or packed since these layouts are not allowed in Vulkan SPIR-V (they are useless anyways, and custom offsets would do the same thing).
//
// It is almost certain that we're using std430, but it gets tricky with arrays in particular.
// We will assume std430, but infer std140 if we can prove the struct is not compliant with std430.
//
// The only two differences between std140 and std430 are related to padding alignment/array stride
// in arrays and structs. In std140 they take minimum vec4 alignment.
// std430 only removes the vec4 requirement.
uint32_t offset = 0;
uint32_t pad_alignment = 1;
bool is_top_level_block =
has_decoration(type.self, DecorationBlock) || has_decoration(type.self, DecorationBufferBlock);
for (uint32_t i = 0; i < type.member_types.size(); i++)
{
auto &memb_type = get<SPIRType>(type.member_types[i]);
auto member_flags = ir.meta[type.self].members[i].decoration_flags;
// Verify alignment rules.
uint32_t packed_alignment = type_to_packed_alignment(memb_type, member_flags, packing);
// This is a rather dirty workaround to deal with some cases of OpSpecConstantOp used as array size, e.g:
// layout(constant_id = 0) const int s = 10;
// const int S = s + 5; // SpecConstantOp
// buffer Foo { int data[S]; }; // <-- Very hard for us to deduce a fixed value here,
// we would need full implementation of compile-time constant folding. :(
// If we are the last member of a struct, there might be cases where the actual size of that member is irrelevant
// for our analysis (e.g. unsized arrays).
// This lets us simply ignore that there are spec constant op sized arrays in our buffers.
// Querying size of this member will fail, so just don't call it unless we have to.
//
// This is likely "best effort" we can support without going into unacceptably complicated workarounds.
bool member_can_be_unsized =
is_top_level_block && size_t(i + 1) == type.member_types.size() && !memb_type.array.empty();
uint32_t packed_size = 0;
if (!member_can_be_unsized)
packed_size = type_to_packed_size(memb_type, member_flags, packing);
// We only need to care about this if we have non-array types which can straddle the vec4 boundary.
if (packing_is_hlsl(packing))
{
// If a member straddles across a vec4 boundary, alignment is actually vec4.
uint32_t begin_word = offset / 16;
uint32_t end_word = (offset + packed_size - 1) / 16;
if (begin_word != end_word)
packed_alignment = max(packed_alignment, 16u);
}
uint32_t alignment = max(packed_alignment, pad_alignment);
offset = (offset + alignment - 1) & ~(alignment - 1);
// Field is not in the specified range anymore and we can ignore any further fields.
if (offset >= end_offset)
break;
// The next member following a struct member is aligned to the base alignment of the struct that came before.
// GL 4.5 spec, 7.6.2.2.
if (memb_type.basetype == SPIRType::Struct)
pad_alignment = packed_alignment;
else
pad_alignment = 1;
// Only care about packing if we are in the given range
if (offset >= start_offset)
{
// We only care about offsets in std140, std430, etc ...
// For EnhancedLayout variants, we have the flexibility to choose our own offsets.
if (!packing_has_flexible_offset(packing))
{
uint32_t actual_offset = type_struct_member_offset(type, i);
if (actual_offset != offset) // This cannot be the packing we're looking for.
return false;
}
// Verify array stride rules.
if (!memb_type.array.empty() && type_to_packed_array_stride(memb_type, member_flags, packing) !=
type_struct_member_array_stride(type, i))
return false;
// Verify that sub-structs also follow packing rules.
// We cannot use enhanced layouts on substructs, so they better be up to spec.
auto substruct_packing = packing_to_substruct_packing(packing);
if (!memb_type.member_types.empty() && !buffer_is_packing_standard(memb_type, substruct_packing))
return false;
}
// Bump size.
offset += packed_size;
}
return true;
}
bool CompilerGLSL::can_use_io_location(StorageClass storage, bool block)
{
// Location specifiers are must have in SPIR-V, but they aren't really supported in earlier versions of GLSL.
// Be very explicit here about how to solve the issue.
if ((get_execution_model() != ExecutionModelVertex && storage == StorageClassInput) ||
(get_execution_model() != ExecutionModelFragment && storage == StorageClassOutput))
{
uint32_t minimum_desktop_version = block ? 440 : 410;
// ARB_enhanced_layouts vs ARB_separate_shader_objects ...
if (!options.es && options.version < minimum_desktop_version && !options.separate_shader_objects)
return false;
else if (options.es && options.version < 310)
return false;
}
if ((get_execution_model() == ExecutionModelVertex && storage == StorageClassInput) ||
(get_execution_model() == ExecutionModelFragment && storage == StorageClassOutput))
{
if (options.es && options.version < 300)
return false;
else if (!options.es && options.version < 330)
return false;
}
if (storage == StorageClassUniform || storage == StorageClassUniformConstant || storage == StorageClassPushConstant)
{
if (options.es && options.version < 310)
return false;
else if (!options.es && options.version < 430)
return false;
}
return true;
}
string CompilerGLSL::layout_for_variable(const SPIRVariable &var)
{
// FIXME: Come up with a better solution for when to disable layouts.
// Having layouts depend on extensions as well as which types
// of layouts are used. For now, the simple solution is to just disable
// layouts for legacy versions.
if (is_legacy())
return "";
vector<string> attr;
auto &dec = ir.meta[var.self].decoration;
auto &type = get<SPIRType>(var.basetype);
auto &flags = dec.decoration_flags;
auto typeflags = ir.meta[type.self].decoration.decoration_flags;
if (options.vulkan_semantics && var.storage == StorageClassPushConstant)
attr.push_back("push_constant");
if (flags.get(DecorationRowMajor))
attr.push_back("row_major");
if (flags.get(DecorationColMajor))
attr.push_back("column_major");
if (options.vulkan_semantics)
{
if (flags.get(DecorationInputAttachmentIndex))
attr.push_back(join("input_attachment_index = ", dec.input_attachment));
}
bool is_block = has_decoration(type.self, DecorationBlock);
if (flags.get(DecorationLocation) && can_use_io_location(var.storage, is_block))
{
Bitset combined_decoration;
for (uint32_t i = 0; i < ir.meta[type.self].members.size(); i++)
combined_decoration.merge_or(combined_decoration_for_member(type, i));
// If our members have location decorations, we don't need to
// emit location decorations at the top as well (looks weird).
if (!combined_decoration.get(DecorationLocation))
attr.push_back(join("location = ", dec.location));
}
// Can only declare Component if we can declare location.
if (flags.get(DecorationComponent) && can_use_io_location(var.storage, is_block))
{
if (!options.es)
{
if (options.version < 440 && options.version >= 140)
require_extension_internal("GL_ARB_enhanced_layouts");
else if (options.version < 140)
SPIRV_CROSS_THROW("Component decoration is not supported in targets below GLSL 1.40.");
attr.push_back(join("component = ", dec.component));
}
else
SPIRV_CROSS_THROW("Component decoration is not supported in ES targets.");
}
if (flags.get(DecorationIndex))
attr.push_back(join("index = ", dec.index));
// Do not emit set = decoration in regular GLSL output, but
// we need to preserve it in Vulkan GLSL mode.
if (var.storage != StorageClassPushConstant)
{
if (flags.get(DecorationDescriptorSet) && options.vulkan_semantics)
attr.push_back(join("set = ", dec.set));
}
// GL 3.0/GLSL 1.30 is not considered legacy, but it doesn't have UBOs ...
bool can_use_buffer_blocks = (options.es && options.version >= 300) || (!options.es && options.version >= 140);
bool can_use_binding;
if (options.es)
can_use_binding = options.version >= 310;
else
can_use_binding = options.enable_420pack_extension || (options.version >= 420);
// Make sure we don't emit binding layout for a classic uniform on GLSL 1.30.
if (!can_use_buffer_blocks && var.storage == StorageClassUniform)
can_use_binding = false;
if (can_use_binding && flags.get(DecorationBinding))
attr.push_back(join("binding = ", dec.binding));
if (flags.get(DecorationOffset))
attr.push_back(join("offset = ", dec.offset));
bool push_constant_block = options.vulkan_semantics && var.storage == StorageClassPushConstant;
bool ssbo_block = var.storage == StorageClassStorageBuffer ||
(var.storage == StorageClassUniform && typeflags.get(DecorationBufferBlock));
bool emulated_ubo = var.storage == StorageClassPushConstant && options.emit_push_constant_as_uniform_buffer;
bool ubo_block = var.storage == StorageClassUniform && typeflags.get(DecorationBlock);
// Instead of adding explicit offsets for every element here, just assume we're using std140 or std430.
// If SPIR-V does not comply with either layout, we cannot really work around it.
if (can_use_buffer_blocks && (ubo_block || emulated_ubo))
{
if (buffer_is_packing_standard(type, BufferPackingStd140))
attr.push_back("std140");
else if (buffer_is_packing_standard(type, BufferPackingStd140EnhancedLayout))
{
attr.push_back("std140");
// Fallback time. We might be able to use the ARB_enhanced_layouts to deal with this difference,
// however, we can only use layout(offset) on the block itself, not any substructs, so the substructs better be the appropriate layout.
// Enhanced layouts seem to always work in Vulkan GLSL, so no need for extensions there.
if (options.es && !options.vulkan_semantics)
SPIRV_CROSS_THROW("Uniform buffer block cannot be expressed as std140. ES-targets do "
"not support GL_ARB_enhanced_layouts.");
if (!options.es && !options.vulkan_semantics && options.version < 440)
require_extension_internal("GL_ARB_enhanced_layouts");
// This is a very last minute to check for this, but use this unused decoration to mark that we should emit
// explicit offsets for this block type.
// layout_for_variable() will be called before the actual buffer emit.
// The alternative is a full pass before codegen where we deduce this decoration,
// but then we are just doing the exact same work twice, and more complexity.
set_extended_decoration(type.self, SPIRVCrossDecorationPacked);
}
else
{
SPIRV_CROSS_THROW("Uniform buffer cannot be expressed as std140, even with enhanced layouts. You can try "
"flattening this block to "
"support a more flexible layout.");
}
}
else if (can_use_buffer_blocks && (push_constant_block || ssbo_block))
{
if (buffer_is_packing_standard(type, BufferPackingStd430))
attr.push_back("std430");
else if (buffer_is_packing_standard(type, BufferPackingStd140))
attr.push_back("std140");
else if (buffer_is_packing_standard(type, BufferPackingStd140EnhancedLayout))
{
attr.push_back("std140");
// Fallback time. We might be able to use the ARB_enhanced_layouts to deal with this difference,
// however, we can only use layout(offset) on the block itself, not any substructs, so the substructs better be the appropriate layout.
// Enhanced layouts seem to always work in Vulkan GLSL, so no need for extensions there.
if (options.es && !options.vulkan_semantics)
SPIRV_CROSS_THROW("Push constant block cannot be expressed as neither std430 nor std140. ES-targets do "
"not support GL_ARB_enhanced_layouts.");
if (!options.es && !options.vulkan_semantics && options.version < 440)
require_extension_internal("GL_ARB_enhanced_layouts");
set_extended_decoration(type.self, SPIRVCrossDecorationPacked);
}
else if (buffer_is_packing_standard(type, BufferPackingStd430EnhancedLayout))
{
attr.push_back("std430");
if (options.es && !options.vulkan_semantics)
SPIRV_CROSS_THROW("Push constant block cannot be expressed as neither std430 nor std140. ES-targets do "
"not support GL_ARB_enhanced_layouts.");
if (!options.es && !options.vulkan_semantics && options.version < 440)
require_extension_internal("GL_ARB_enhanced_layouts");
set_extended_decoration(type.self, SPIRVCrossDecorationPacked);
}
else
{
SPIRV_CROSS_THROW("Buffer block cannot be expressed as neither std430 nor std140, even with enhanced "
"layouts. You can try flattening this block to support a more flexible layout.");
}
}
// For images, the type itself adds a layout qualifer.
// Only emit the format for storage images.
if (type.basetype == SPIRType::Image && type.image.sampled == 2)
{
const char *fmt = format_to_glsl(type.image.format);
if (fmt)
attr.push_back(fmt);
}
if (attr.empty())
return "";
string res = "layout(";
res += merge(attr);
res += ") ";
return res;
}
void CompilerGLSL::emit_push_constant_block(const SPIRVariable &var)
{
if (flattened_buffer_blocks.count(var.self))
emit_buffer_block_flattened(var);
else if (options.vulkan_semantics)
emit_push_constant_block_vulkan(var);
else if (options.emit_push_constant_as_uniform_buffer)
emit_buffer_block_native(var);
else
emit_push_constant_block_glsl(var);
}
void CompilerGLSL::emit_push_constant_block_vulkan(const SPIRVariable &var)
{
emit_buffer_block(var);
}
void CompilerGLSL::emit_push_constant_block_glsl(const SPIRVariable &var)
{
// OpenGL has no concept of push constant blocks, implement it as a uniform struct.
auto &type = get<SPIRType>(var.basetype);
auto &flags = ir.meta[var.self].decoration.decoration_flags;
flags.clear(DecorationBinding);
flags.clear(DecorationDescriptorSet);
#if 0
if (flags & ((1ull << DecorationBinding) | (1ull << DecorationDescriptorSet)))
SPIRV_CROSS_THROW("Push constant blocks cannot be compiled to GLSL with Binding or Set syntax. "
"Remap to location with reflection API first or disable these decorations.");
#endif
// We're emitting the push constant block as a regular struct, so disable the block qualifier temporarily.
// Otherwise, we will end up emitting layout() qualifiers on naked structs which is not allowed.
auto &block_flags = ir.meta[type.self].decoration.decoration_flags;
bool block_flag = block_flags.get(DecorationBlock);
block_flags.clear(DecorationBlock);
emit_struct(type);
if (block_flag)
block_flags.set(DecorationBlock);
emit_uniform(var);
statement("");
}
void CompilerGLSL::emit_buffer_block(const SPIRVariable &var)
{
if (flattened_buffer_blocks.count(var.self))
emit_buffer_block_flattened(var);
else if (is_legacy() || (!options.es && options.version == 130))
emit_buffer_block_legacy(var);
else
emit_buffer_block_native(var);
}
void CompilerGLSL::emit_buffer_block_legacy(const SPIRVariable &var)
{
auto &type = get<SPIRType>(var.basetype);
bool ssbo = var.storage == StorageClassStorageBuffer ||
ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock);
if (ssbo)
SPIRV_CROSS_THROW("SSBOs not supported in legacy targets.");
// We're emitting the push constant block as a regular struct, so disable the block qualifier temporarily.
// Otherwise, we will end up emitting layout() qualifiers on naked structs which is not allowed.
auto &block_flags = ir.meta[type.self].decoration.decoration_flags;
bool block_flag = block_flags.get(DecorationBlock);
block_flags.clear(DecorationBlock);
emit_struct(type);
if (block_flag)
block_flags.set(DecorationBlock);
emit_uniform(var);
statement("");
}
void CompilerGLSL::emit_buffer_block_native(const SPIRVariable &var)
{
auto &type = get<SPIRType>(var.basetype);
Bitset flags = ir.get_buffer_block_flags(var);
bool ssbo = var.storage == StorageClassStorageBuffer ||
ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock);
bool is_restrict = ssbo && flags.get(DecorationRestrict);
bool is_writeonly = ssbo && flags.get(DecorationNonReadable);
bool is_readonly = ssbo && flags.get(DecorationNonWritable);
bool is_coherent = ssbo && flags.get(DecorationCoherent);
// Block names should never alias, but from HLSL input they kind of can because block types are reused for UAVs ...
auto buffer_name = to_name(type.self, false);
auto &block_namespace = ssbo ? block_ssbo_names : block_ubo_names;
// Shaders never use the block by interface name, so we don't
// have to track this other than updating name caches.
// If we have a collision for any reason, just fallback immediately.
if (ir.meta[type.self].decoration.alias.empty() || block_namespace.find(buffer_name) != end(block_namespace) ||
resource_names.find(buffer_name) != end(resource_names))
{
buffer_name = get_block_fallback_name(var.self);
}
// Make sure we get something unique for both global name scope and block name scope.
// See GLSL 4.5 spec: section 4.3.9 for details.
add_variable(block_namespace, resource_names, buffer_name);
// If for some reason buffer_name is an illegal name, make a final fallback to a workaround name.
// This cannot conflict with anything else, so we're safe now.
// We cannot reuse this fallback name in neither global scope (blocked by block_names) nor block name scope.
if (buffer_name.empty())
buffer_name = join("_", get<SPIRType>(var.basetype).self, "_", var.self);
block_names.insert(buffer_name);
block_namespace.insert(buffer_name);
// Save for post-reflection later.
declared_block_names[var.self] = buffer_name;
statement(layout_for_variable(var), is_coherent ? "coherent " : "", is_restrict ? "restrict " : "",
is_writeonly ? "writeonly " : "", is_readonly ? "readonly " : "", ssbo ? "buffer " : "uniform ",
buffer_name);
begin_scope();
type.member_name_cache.clear();
uint32_t i = 0;
for (auto &member : type.member_types)
{
add_member_name(type, i);
emit_struct_member(type, member, i);
i++;
}
// var.self can be used as a backup name for the block name,
// so we need to make sure we don't disturb the name here on a recompile.
// It will need to be reset if we have to recompile.
preserve_alias_on_reset(var.self);
add_resource_name(var.self);
end_scope_decl(to_name(var.self) + type_to_array_glsl(type));
statement("");
}
void CompilerGLSL::emit_buffer_block_flattened(const SPIRVariable &var)
{
auto &type = get<SPIRType>(var.basetype);
// Block names should never alias.
auto buffer_name = to_name(type.self, false);
size_t buffer_size = (get_declared_struct_size(type) + 15) / 16;
SPIRType::BaseType basic_type;
if (get_common_basic_type(type, basic_type))
{
SPIRType tmp;
tmp.basetype = basic_type;
tmp.vecsize = 4;
if (basic_type != SPIRType::Float && basic_type != SPIRType::Int && basic_type != SPIRType::UInt)
SPIRV_CROSS_THROW("Basic types in a flattened UBO must be float, int or uint.");
auto flags = ir.get_buffer_block_flags(var);
statement("uniform ", flags_to_precision_qualifiers_glsl(tmp, flags), type_to_glsl(tmp), " ", buffer_name, "[",
buffer_size, "];");
}
else
SPIRV_CROSS_THROW("All basic types in a flattened block must be the same.");
}
const char *CompilerGLSL::to_storage_qualifiers_glsl(const SPIRVariable &var)
{
auto &execution = get_entry_point();
if (var.storage == StorageClassInput || var.storage == StorageClassOutput)
{
if (is_legacy() && execution.model == ExecutionModelVertex)
return var.storage == StorageClassInput ? "attribute " : "varying ";
else if (is_legacy() && execution.model == ExecutionModelFragment)
return "varying "; // Fragment outputs are renamed so they never hit this case.
else
return var.storage == StorageClassInput ? "in " : "out ";
}
else if (var.storage == StorageClassUniformConstant || var.storage == StorageClassUniform ||
var.storage == StorageClassPushConstant)
{
return "uniform ";
}
else if (var.storage == StorageClassRayPayloadNV)
{
return "rayPayloadNV ";
}
else if (var.storage == StorageClassIncomingRayPayloadNV)
{
return "rayPayloadInNV ";
}
else if (var.storage == StorageClassHitAttributeNV)
{
return "hitAttributeNV ";
}
return "";
}
void CompilerGLSL::emit_flattened_io_block(const SPIRVariable &var, const char *qual)
{
auto &type = get<SPIRType>(var.basetype);
if (!type.array.empty())
SPIRV_CROSS_THROW("Array of varying structs cannot be flattened to legacy-compatible varyings.");
auto old_flags = ir.meta[type.self].decoration.decoration_flags;
// Emit the members as if they are part of a block to get all qualifiers.
ir.meta[type.self].decoration.decoration_flags.set(DecorationBlock);
type.member_name_cache.clear();
uint32_t i = 0;
for (auto &member : type.member_types)
{
add_member_name(type, i);
auto &membertype = get<SPIRType>(member);
if (membertype.basetype == SPIRType::Struct)
SPIRV_CROSS_THROW("Cannot flatten struct inside structs in I/O variables.");
// Pass in the varying qualifier here so it will appear in the correct declaration order.
// Replace member name while emitting it so it encodes both struct name and member name.
// Sanitize underscores because joining the two identifiers might create more than 1 underscore in a row,
// which is not allowed.
auto backup_name = get_member_name(type.self, i);
auto member_name = to_member_name(type, i);
set_member_name(type.self, i, sanitize_underscores(join(to_name(var.self), "_", member_name)));
emit_struct_member(type, member, i, qual);
// Restore member name.
set_member_name(type.self, i, member_name);
i++;
}
ir.meta[type.self].decoration.decoration_flags = old_flags;
// Treat this variable as flattened from now on.
flattened_structs.insert(var.self);
}
void CompilerGLSL::emit_interface_block(const SPIRVariable &var)
{
auto &type = get<SPIRType>(var.basetype);
// Either make it plain in/out or in/out blocks depending on what shader is doing ...
bool block = ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock);
const char *qual = to_storage_qualifiers_glsl(var);
if (block)
{
// ESSL earlier than 310 and GLSL earlier than 150 did not support
// I/O variables which are struct types.
// To support this, flatten the struct into separate varyings instead.
if ((options.es && options.version < 310) || (!options.es && options.version < 150))
{
// I/O blocks on ES require version 310 with Android Extension Pack extensions, or core version 320.
// On desktop, I/O blocks were introduced with geometry shaders in GL 3.2 (GLSL 150).
emit_flattened_io_block(var, qual);
}
else
{
if (options.es && options.version < 320)
{
// Geometry and tessellation extensions imply this extension.
if (!has_extension("GL_EXT_geometry_shader") && !has_extension("GL_EXT_tessellation_shader"))
require_extension_internal("GL_EXT_shader_io_blocks");
}
// Block names should never alias.
auto block_name = to_name(type.self, false);
// The namespace for I/O blocks is separate from other variables in GLSL.
auto &block_namespace = type.storage == StorageClassInput ? block_input_names : block_output_names;
// Shaders never use the block by interface name, so we don't
// have to track this other than updating name caches.
if (block_name.empty() || block_namespace.find(block_name) != end(block_namespace))
block_name = get_fallback_name(type.self);
else
block_namespace.insert(block_name);
// If for some reason buffer_name is an illegal name, make a final fallback to a workaround name.
// This cannot conflict with anything else, so we're safe now.
if (block_name.empty())
block_name = join("_", get<SPIRType>(var.basetype).self, "_", var.self);
// Instance names cannot alias block names.
resource_names.insert(block_name);
statement(layout_for_variable(var), qual, block_name);
begin_scope();
type.member_name_cache.clear();
uint32_t i = 0;
for (auto &member : type.member_types)
{
add_member_name(type, i);
emit_struct_member(type, member, i);
i++;
}
add_resource_name(var.self);
end_scope_decl(join(to_name(var.self), type_to_array_glsl(type)));
statement("");
}
}
else
{
// ESSL earlier than 310 and GLSL earlier than 150 did not support
// I/O variables which are struct types.
// To support this, flatten the struct into separate varyings instead.
if (type.basetype == SPIRType::Struct &&
((options.es && options.version < 310) || (!options.es && options.version < 150)))
{
emit_flattened_io_block(var, qual);
}
else
{
add_resource_name(var.self);
statement(layout_for_variable(var), to_qualifiers_glsl(var.self),
variable_decl(type, to_name(var.self), var.self), ";");
// If a StorageClassOutput variable has an initializer, we need to initialize it in main().
if (var.storage == StorageClassOutput && var.initializer)
{
auto &entry_func = this->get<SPIRFunction>(ir.default_entry_point);
entry_func.fixup_hooks_in.push_back(
[&]() { statement(to_name(var.self), " = ", to_expression(var.initializer), ";"); });
}
}
}
}
void CompilerGLSL::emit_uniform(const SPIRVariable &var)
{
auto &type = get<SPIRType>(var.basetype);
if (type.basetype == SPIRType::Image && type.image.sampled == 2)
{
if (!options.es && options.version < 420)
require_extension_internal("GL_ARB_shader_image_load_store");
else if (options.es && options.version < 310)
SPIRV_CROSS_THROW("At least ESSL 3.10 required for shader image load store.");
}
add_resource_name(var.self);
statement(layout_for_variable(var), variable_decl(var), ";");
}
string CompilerGLSL::constant_value_macro_name(uint32_t id)
{
return join("SPIRV_CROSS_CONSTANT_ID_", id);
}
void CompilerGLSL::emit_specialization_constant_op(const SPIRConstantOp &constant)
{
auto &type = get<SPIRType>(constant.basetype);
auto name = to_name(constant.self);
statement("const ", variable_decl(type, name), " = ", constant_op_expression(constant), ";");
}
void CompilerGLSL::emit_constant(const SPIRConstant &constant)
{
auto &type = get<SPIRType>(constant.constant_type);
auto name = to_name(constant.self);
SpecializationConstant wg_x, wg_y, wg_z;
uint32_t workgroup_size_id = get_work_group_size_specialization_constants(wg_x, wg_y, wg_z);
// This specialization constant is implicitly declared by emitting layout() in;
if (constant.self == workgroup_size_id)
return;
// These specialization constants are implicitly declared by emitting layout() in;
// In legacy GLSL, we will still need to emit macros for these, so a layout() in; declaration
// later can use macro overrides for work group size.
bool is_workgroup_size_constant = constant.self == wg_x.id || constant.self == wg_y.id || constant.self == wg_z.id;
if (options.vulkan_semantics && is_workgroup_size_constant)
{
// Vulkan GLSL does not need to declare workgroup spec constants explicitly, it is handled in layout().
return;
}
else if (!options.vulkan_semantics && is_workgroup_size_constant &&
!has_decoration(constant.self, DecorationSpecId))
{
// Only bother declaring a workgroup size if it is actually a specialization constant, because we need macros.
return;
}
// Only scalars have constant IDs.
if (has_decoration(constant.self, DecorationSpecId))
{
if (options.vulkan_semantics)
{
statement("layout(constant_id = ", get_decoration(constant.self, DecorationSpecId), ") const ",
variable_decl(type, name), " = ", constant_expression(constant), ";");
}
else
{
const string ¯o_name = constant.specialization_constant_macro_name;
statement("#ifndef ", macro_name);
statement("#define ", macro_name, " ", constant_expression(constant));
statement("#endif");
// For workgroup size constants, only emit the macros.
if (!is_workgroup_size_constant)
statement("const ", variable_decl(type, name), " = ", macro_name, ";");
}
}
else
{
statement("const ", variable_decl(type, name), " = ", constant_expression(constant), ";");
}
}
void CompilerGLSL::emit_entry_point_declarations()
{
}
void CompilerGLSL::replace_illegal_names()
{
// clang-format off
static const unordered_set<string> keywords = {
"abs", "acos", "acosh", "all", "any", "asin", "asinh", "atan", "atanh",
"atomicAdd", "atomicCompSwap", "atomicCounter", "atomicCounterDecrement", "atomicCounterIncrement",
"atomicExchange", "atomicMax", "atomicMin", "atomicOr", "atomicXor",
"bitCount", "bitfieldExtract", "bitfieldInsert", "bitfieldReverse",
"ceil", "cos", "cosh", "cross", "degrees",
"dFdx", "dFdxCoarse", "dFdxFine",
"dFdy", "dFdyCoarse", "dFdyFine",
"distance", "dot", "EmitStreamVertex", "EmitVertex", "EndPrimitive", "EndStreamPrimitive", "equal", "exp", "exp2",
"faceforward", "findLSB", "findMSB", "float16BitsToInt16", "float16BitsToUint16", "floatBitsToInt", "floatBitsToUint", "floor", "fma", "fract",
"frexp", "fwidth", "fwidthCoarse", "fwidthFine",
"greaterThan", "greaterThanEqual", "groupMemoryBarrier",
"imageAtomicAdd", "imageAtomicAnd", "imageAtomicCompSwap", "imageAtomicExchange", "imageAtomicMax", "imageAtomicMin", "imageAtomicOr", "imageAtomicXor",
"imageLoad", "imageSamples", "imageSize", "imageStore", "imulExtended", "int16BitsToFloat16", "intBitsToFloat", "interpolateAtOffset", "interpolateAtCentroid", "interpolateAtSample",
"inverse", "inversesqrt", "isinf", "isnan", "ldexp", "length", "lessThan", "lessThanEqual", "log", "log2",
"matrixCompMult", "max", "memoryBarrier", "memoryBarrierAtomicCounter", "memoryBarrierBuffer", "memoryBarrierImage", "memoryBarrierShared",
"min", "mix", "mod", "modf", "noise", "noise1", "noise2", "noise3", "noise4", "normalize", "not", "notEqual",
"outerProduct", "packDouble2x32", "packHalf2x16", "packInt2x16", "packInt4x16", "packSnorm2x16", "packSnorm4x8",
"packUint2x16", "packUint4x16", "packUnorm2x16", "packUnorm4x8", "pow",
"radians", "reflect", "refract", "round", "roundEven", "sign", "sin", "sinh", "smoothstep", "sqrt", "step",
"tan", "tanh", "texelFetch", "texelFetchOffset", "texture", "textureGather", "textureGatherOffset", "textureGatherOffsets",
"textureGrad", "textureGradOffset", "textureLod", "textureLodOffset", "textureOffset", "textureProj", "textureProjGrad",
"textureProjGradOffset", "textureProjLod", "textureProjLodOffset", "textureProjOffset", "textureQueryLevels", "textureQueryLod", "textureSamples", "textureSize",
"transpose", "trunc", "uaddCarry", "uint16BitsToFloat16", "uintBitsToFloat", "umulExtended", "unpackDouble2x32", "unpackHalf2x16", "unpackInt2x16", "unpackInt4x16",
"unpackSnorm2x16", "unpackSnorm4x8", "unpackUint2x16", "unpackUint4x16", "unpackUnorm2x16", "unpackUnorm4x8", "usubBorrow",
"active", "asm", "atomic_uint", "attribute", "bool", "break", "buffer",
"bvec2", "bvec3", "bvec4", "case", "cast", "centroid", "class", "coherent", "common", "const", "continue", "default", "discard",
"dmat2", "dmat2x2", "dmat2x3", "dmat2x4", "dmat3", "dmat3x2", "dmat3x3", "dmat3x4", "dmat4", "dmat4x2", "dmat4x3", "dmat4x4",
"do", "double", "dvec2", "dvec3", "dvec4", "else", "enum", "extern", "external", "false", "filter", "fixed", "flat", "float",
"for", "fvec2", "fvec3", "fvec4", "goto", "half", "highp", "hvec2", "hvec3", "hvec4", "if", "iimage1D", "iimage1DArray",
"iimage2D", "iimage2DArray", "iimage2DMS", "iimage2DMSArray", "iimage2DRect", "iimage3D", "iimageBuffer", "iimageCube",
"iimageCubeArray", "image1D", "image1DArray", "image2D", "image2DArray", "image2DMS", "image2DMSArray", "image2DRect",
"image3D", "imageBuffer", "imageCube", "imageCubeArray", "in", "inline", "inout", "input", "int", "interface", "invariant",
"isampler1D", "isampler1DArray", "isampler2D", "isampler2DArray", "isampler2DMS", "isampler2DMSArray", "isampler2DRect",
"isampler3D", "isamplerBuffer", "isamplerCube", "isamplerCubeArray", "ivec2", "ivec3", "ivec4", "layout", "long", "lowp",
"mat2", "mat2x2", "mat2x3", "mat2x4", "mat3", "mat3x2", "mat3x3", "mat3x4", "mat4", "mat4x2", "mat4x3", "mat4x4", "mediump",
"namespace", "noinline", "noperspective", "out", "output", "packed", "partition", "patch", "precise", "precision", "public", "readonly",
"resource", "restrict", "return", "sample", "sampler1D", "sampler1DArray", "sampler1DArrayShadow",
"sampler1DShadow", "sampler2D", "sampler2DArray", "sampler2DArrayShadow", "sampler2DMS", "sampler2DMSArray",
"sampler2DRect", "sampler2DRectShadow", "sampler2DShadow", "sampler3D", "sampler3DRect", "samplerBuffer",
"samplerCube", "samplerCubeArray", "samplerCubeArrayShadow", "samplerCubeShadow", "shared", "short", "sizeof", "smooth", "static",
"struct", "subroutine", "superp", "switch", "template", "this", "true", "typedef", "uimage1D", "uimage1DArray", "uimage2D",
"uimage2DArray", "uimage2DMS", "uimage2DMSArray", "uimage2DRect", "uimage3D", "uimageBuffer", "uimageCube",
"uimageCubeArray", "uint", "uniform", "union", "unsigned", "usampler1D", "usampler1DArray", "usampler2D", "usampler2DArray",
"usampler2DMS", "usampler2DMSArray", "usampler2DRect", "usampler3D", "usamplerBuffer", "usamplerCube",
"usamplerCubeArray", "using", "uvec2", "uvec3", "uvec4", "varying", "vec2", "vec3", "vec4", "void", "volatile",
"while", "writeonly",
};
// clang-format on
ir.for_each_typed_id<SPIRVariable>([&](uint32_t, const SPIRVariable &var) {
if (!is_hidden_variable(var))
{
auto &m = ir.meta[var.self].decoration;
if (m.alias.compare(0, 3, "gl_") == 0 || keywords.find(m.alias) != end(keywords))
m.alias = join("_", m.alias);
}
});
}
void CompilerGLSL::replace_fragment_output(SPIRVariable &var)
{
auto &m = ir.meta[var.self].decoration;
uint32_t location = 0;
if (m.decoration_flags.get(DecorationLocation))
location = m.location;
// If our variable is arrayed, we must not emit the array part of this as the SPIR-V will
// do the access chain part of this for us.
auto &type = get<SPIRType>(var.basetype);
if (type.array.empty())
{
// Redirect the write to a specific render target in legacy GLSL.
m.alias = join("gl_FragData[", location, "]");
if (is_legacy_es() && location != 0)
require_extension_internal("GL_EXT_draw_buffers");
}
else if (type.array.size() == 1)
{
// If location is non-zero, we probably have to add an offset.
// This gets really tricky since we'd have to inject an offset in the access chain.
// FIXME: This seems like an extremely odd-ball case, so it's probably fine to leave it like this for now.
m.alias = "gl_FragData";
if (location != 0)
SPIRV_CROSS_THROW("Arrayed output variable used, but location is not 0. "
"This is unimplemented in SPIRV-Cross.");
if (is_legacy_es())
require_extension_internal("GL_EXT_draw_buffers");
}
else
SPIRV_CROSS_THROW("Array-of-array output variable used. This cannot be implemented in legacy GLSL.");
var.compat_builtin = true; // We don't want to declare this variable, but use the name as-is.
}
void CompilerGLSL::replace_fragment_outputs()
{
ir.for_each_typed_id<SPIRVariable>([&](uint32_t, SPIRVariable &var) {
auto &type = this->get<SPIRType>(var.basetype);
if (!is_builtin_variable(var) && !var.remapped_variable && type.pointer && var.storage == StorageClassOutput)
replace_fragment_output(var);
});
}
string CompilerGLSL::remap_swizzle(const SPIRType &out_type, uint32_t input_components, const string &expr)
{
if (out_type.vecsize == input_components)
return expr;
else if (input_components == 1 && !backend.can_swizzle_scalar)
return join(type_to_glsl(out_type), "(", expr, ")");
else
{
// FIXME: This will not work with packed expressions.
auto e = enclose_expression(expr) + ".";
// Just clamp the swizzle index if we have more outputs than inputs.
for (uint32_t c = 0; c < out_type.vecsize; c++)
e += index_to_swizzle(min(c, input_components - 1));
if (backend.swizzle_is_function && out_type.vecsize > 1)
e += "()";
remove_duplicate_swizzle(e);
return e;
}
}
void CompilerGLSL::emit_pls()
{
auto &execution = get_entry_point();
if (execution.model != ExecutionModelFragment)
SPIRV_CROSS_THROW("Pixel local storage only supported in fragment shaders.");
if (!options.es)
SPIRV_CROSS_THROW("Pixel local storage only supported in OpenGL ES.");
if (options.version < 300)
SPIRV_CROSS_THROW("Pixel local storage only supported in ESSL 3.0 and above.");
if (!pls_inputs.empty())
{
statement("__pixel_local_inEXT _PLSIn");
begin_scope();
for (auto &input : pls_inputs)
statement(pls_decl(input), ";");
end_scope_decl();
statement("");
}
if (!pls_outputs.empty())
{
statement("__pixel_local_outEXT _PLSOut");
begin_scope();
for (auto &output : pls_outputs)
statement(pls_decl(output), ";");
end_scope_decl();
statement("");
}
}
void CompilerGLSL::fixup_image_load_store_access()
{
ir.for_each_typed_id<SPIRVariable>([&](uint32_t var, const SPIRVariable &) {
auto &vartype = expression_type(var);
if (vartype.basetype == SPIRType::Image)
{
// Older glslangValidator does not emit required qualifiers here.
// Solve this by making the image access as restricted as possible and loosen up if we need to.
// If any no-read/no-write flags are actually set, assume that the compiler knows what it's doing.
auto &flags = ir.meta[var].decoration.decoration_flags;
if (!flags.get(DecorationNonWritable) && !flags.get(DecorationNonReadable))
{
flags.set(DecorationNonWritable);
flags.set(DecorationNonReadable);
}
}
});
}
void CompilerGLSL::emit_declared_builtin_block(StorageClass storage, ExecutionModel model)
{
Bitset emitted_builtins;
Bitset global_builtins;
const SPIRVariable *block_var = nullptr;
bool emitted_block = false;
bool builtin_array = false;
// Need to use declared size in the type.
// These variables might have been declared, but not statically used, so we haven't deduced their size yet.
uint32_t cull_distance_size = 0;
uint32_t clip_distance_size = 0;
ir.for_each_typed_id<SPIRVariable>([&](uint32_t, SPIRVariable &var) {
auto &type = this->get<SPIRType>(var.basetype);
bool block = has_decoration(type.self, DecorationBlock);
Bitset builtins;
if (var.storage == storage && block && is_builtin_variable(var))
{
uint32_t index = 0;
for (auto &m : ir.meta[type.self].members)
{
if (m.builtin)
{
builtins.set(m.builtin_type);
if (m.builtin_type == BuiltInCullDistance)
cull_distance_size = this->get<SPIRType>(type.member_types[index]).array.front();
else if (m.builtin_type == BuiltInClipDistance)
clip_distance_size = this->get<SPIRType>(type.member_types[index]).array.front();
}
index++;
}
}
else if (var.storage == storage && !block && is_builtin_variable(var))
{
// While we're at it, collect all declared global builtins (HLSL mostly ...).
auto &m = ir.meta[var.self].decoration;
if (m.builtin)
{
global_builtins.set(m.builtin_type);
if (m.builtin_type == BuiltInCullDistance)
cull_distance_size = type.array.front();
else if (m.builtin_type == BuiltInClipDistance)
clip_distance_size = type.array.front();
}
}
if (builtins.empty())
return;
if (emitted_block)
SPIRV_CROSS_THROW("Cannot use more than one builtin I/O block.");
emitted_builtins = builtins;
emitted_block = true;
builtin_array = !type.array.empty();
block_var = &var;
});
global_builtins =
Bitset(global_builtins.get_lower() & ((1ull << BuiltInPosition) | (1ull << BuiltInPointSize) |
(1ull << BuiltInClipDistance) | (1ull << BuiltInCullDistance)));
// Try to collect all other declared builtins.
if (!emitted_block)
emitted_builtins = global_builtins;
// Can't declare an empty interface block.
if (emitted_builtins.empty())
return;
if (storage == StorageClassOutput)
statement("out gl_PerVertex");
else
statement("in gl_PerVertex");
begin_scope();
if (emitted_builtins.get(BuiltInPosition))
statement("vec4 gl_Position;");
if (emitted_builtins.get(BuiltInPointSize))
statement("float gl_PointSize;");
if (emitted_builtins.get(BuiltInClipDistance))
statement("float gl_ClipDistance[", clip_distance_size, "];");
if (emitted_builtins.get(BuiltInCullDistance))
statement("float gl_CullDistance[", cull_distance_size, "];");
bool tessellation = model == ExecutionModelTessellationEvaluation || model == ExecutionModelTessellationControl;
if (builtin_array)
{
// Make sure the array has a supported name in the code.
if (storage == StorageClassOutput)
set_name(block_var->self, "gl_out");
else if (storage == StorageClassInput)
set_name(block_var->self, "gl_in");
if (model == ExecutionModelTessellationControl && storage == StorageClassOutput)
end_scope_decl(join(to_name(block_var->self), "[", get_entry_point().output_vertices, "]"));
else
end_scope_decl(join(to_name(block_var->self), tessellation ? "[gl_MaxPatchVertices]" : "[]"));
}
else
end_scope_decl();
statement("");
}
void CompilerGLSL::declare_undefined_values()
{
bool emitted = false;
ir.for_each_typed_id<SPIRUndef>([&](uint32_t, const SPIRUndef &undef) {
statement(variable_decl(this->get<SPIRType>(undef.basetype), to_name(undef.self), undef.self), ";");
emitted = true;
});
if (emitted)
statement("");
}
bool CompilerGLSL::variable_is_lut(const SPIRVariable &var) const
{
bool statically_assigned = var.statically_assigned && var.static_expression != 0 && var.remapped_variable;
if (statically_assigned)
{
auto *constant = maybe_get<SPIRConstant>(var.static_expression);
if (constant && constant->is_used_as_lut)
return true;
}
return false;
}
void CompilerGLSL::emit_resources()
{
auto &execution = get_entry_point();
replace_illegal_names();
// Legacy GL uses gl_FragData[], redeclare all fragment outputs
// with builtins.
if (execution.model == ExecutionModelFragment && is_legacy())
replace_fragment_outputs();
// Emit PLS blocks if we have such variables.
if (!pls_inputs.empty() || !pls_outputs.empty())
emit_pls();
// Emit custom gl_PerVertex for SSO compatibility.
if (options.separate_shader_objects && !options.es && execution.model != ExecutionModelFragment)
{
switch (execution.model)
{
case ExecutionModelGeometry:
case ExecutionModelTessellationControl:
case ExecutionModelTessellationEvaluation:
emit_declared_builtin_block(StorageClassInput, execution.model);
emit_declared_builtin_block(StorageClassOutput, execution.model);
break;
case ExecutionModelVertex:
emit_declared_builtin_block(StorageClassOutput, execution.model);
break;
default:
break;
}
}
else
{
// Need to redeclare clip/cull distance with explicit size to use them.
// SPIR-V mandates these builtins have a size declared.
const char *storage = execution.model == ExecutionModelFragment ? "in" : "out";
if (clip_distance_count != 0)
statement(storage, " float gl_ClipDistance[", clip_distance_count, "];");
if (cull_distance_count != 0)
statement(storage, " float gl_CullDistance[", cull_distance_count, "];");
if (clip_distance_count != 0 || cull_distance_count != 0)
statement("");
}
if (position_invariant)
{
statement("invariant gl_Position;");
statement("");
}
bool emitted = false;
// If emitted Vulkan GLSL,
// emit specialization constants as actual floats,
// spec op expressions will redirect to the constant name.
//
for (auto &id_ : ir.ids_for_constant_or_type)
{
auto &id = ir.ids[id_];
if (id.get_type() == TypeConstant)
{
auto &c = id.get<SPIRConstant>();
bool needs_declaration = c.specialization || c.is_used_as_lut;
if (needs_declaration)
{
if (!options.vulkan_semantics && c.specialization)
{
c.specialization_constant_macro_name =
constant_value_macro_name(get_decoration(c.self, DecorationSpecId));
}
emit_constant(c);
emitted = true;
}
}
else if (id.get_type() == TypeConstantOp)
{
emit_specialization_constant_op(id.get<SPIRConstantOp>());
emitted = true;
}
else if (id.get_type() == TypeType)
{
auto &type = id.get<SPIRType>();
if (type.basetype == SPIRType::Struct && type.array.empty() && !type.pointer &&
(!ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock) &&
!ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock)))
{
if (emitted)
statement("");
emitted = false;
emit_struct(type);
}
}
}
if (emitted)
statement("");
// If we needed to declare work group size late, check here.
// If the work group size depends on a specialization constant, we need to declare the layout() block
// after constants (and their macros) have been declared.
if (execution.model == ExecutionModelGLCompute && !options.vulkan_semantics &&
execution.workgroup_size.constant != 0)
{
SpecializationConstant wg_x, wg_y, wg_z;
get_work_group_size_specialization_constants(wg_x, wg_y, wg_z);
if ((wg_x.id != 0) || (wg_y.id != 0) || (wg_z.id != 0))
{
vector<string> inputs;
build_workgroup_size(inputs, wg_x, wg_y, wg_z);
statement("layout(", merge(inputs), ") in;");
statement("");
}
}
emitted = false;
// Output UBOs and SSBOs
ir.for_each_typed_id<SPIRVariable>([&](uint32_t, SPIRVariable &var) {
auto &type = this->get<SPIRType>(var.basetype);
bool is_block_storage = type.storage == StorageClassStorageBuffer || type.storage == StorageClassUniform;
bool has_block_flags = ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock) ||
ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock);
if (var.storage != StorageClassFunction && type.pointer && is_block_storage && !is_hidden_variable(var) &&
has_block_flags)
{
emit_buffer_block(var);
}
});
// Output push constant blocks
ir.for_each_typed_id<SPIRVariable>([&](uint32_t, SPIRVariable &var) {
auto &type = this->get<SPIRType>(var.basetype);
if (var.storage != StorageClassFunction && type.pointer && type.storage == StorageClassPushConstant &&
!is_hidden_variable(var))
{
emit_push_constant_block(var);
}
});
bool skip_separate_image_sampler = !combined_image_samplers.empty() || !options.vulkan_semantics;
// Output Uniform Constants (values, samplers, images, etc).
ir.for_each_typed_id<SPIRVariable>([&](uint32_t, SPIRVariable &var) {
auto &type = this->get<SPIRType>(var.basetype);
// If we're remapping separate samplers and images, only emit the combined samplers.
if (skip_separate_image_sampler)
{
// Sampler buffers are always used without a sampler, and they will also work in regular GL.
bool sampler_buffer = type.basetype == SPIRType::Image && type.image.dim == DimBuffer;
bool separate_image = type.basetype == SPIRType::Image && type.image.sampled == 1;
bool separate_sampler = type.basetype == SPIRType::Sampler;
if (!sampler_buffer && (separate_image || separate_sampler))
return;
}
if (var.storage != StorageClassFunction && type.pointer &&
(type.storage == StorageClassUniformConstant || type.storage == StorageClassAtomicCounter ||
type.storage == StorageClassRayPayloadNV || type.storage == StorageClassHitAttributeNV ||
type.storage == StorageClassIncomingRayPayloadNV) &&
!is_hidden_variable(var))
{
emit_uniform(var);
emitted = true;
}
});
if (emitted)
statement("");
emitted = false;
// Output in/out interfaces.
ir.for_each_typed_id<SPIRVariable>([&](uint32_t, SPIRVariable &var) {
auto &type = this->get<SPIRType>(var.basetype);
if (var.storage != StorageClassFunction && type.pointer &&
(var.storage == StorageClassInput || var.storage == StorageClassOutput) &&
interface_variable_exists_in_entry_point(var.self) && !is_hidden_variable(var))
{
emit_interface_block(var);
emitted = true;
}
else if (is_builtin_variable(var))
{
// For gl_InstanceIndex emulation on GLES, the API user needs to
// supply this uniform.
if (options.vertex.support_nonzero_base_instance &&
ir.meta[var.self].decoration.builtin_type == BuiltInInstanceIndex && !options.vulkan_semantics)
{
statement("uniform int SPIRV_Cross_BaseInstance;");
emitted = true;
}
}
});
// Global variables.
for (auto global : global_variables)
{
auto &var = get<SPIRVariable>(global);
if (var.storage != StorageClassOutput)
{
if (!variable_is_lut(var))
{
add_resource_name(var.self);
statement(variable_decl(var), ";");
emitted = true;
}
}
}
if (emitted)
statement("");
declare_undefined_values();
}
// Returns a string representation of the ID, usable as a function arg.
// Default is to simply return the expression representation fo the arg ID.
// Subclasses may override to modify the return value.
string CompilerGLSL::to_func_call_arg(uint32_t id)
{
// Make sure that we use the name of the original variable, and not the parameter alias.
uint32_t name_id = id;
auto *var = maybe_get<SPIRVariable>(id);
if (var && var->basevariable)
name_id = var->basevariable;
return to_expression(name_id);
}
void CompilerGLSL::handle_invalid_expression(uint32_t id)
{
// We tried to read an invalidated expression.
// This means we need another pass at compilation, but next time, force temporary variables so that they cannot be invalidated.
forced_temporaries.insert(id);
force_recompile = true;
}
// Converts the format of the current expression from packed to unpacked,
// by wrapping the expression in a constructor of the appropriate type.
// GLSL does not support packed formats, so simply return the expression.
// Subclasses that do will override
string CompilerGLSL::unpack_expression_type(string expr_str, const SPIRType &, uint32_t)
{
return expr_str;
}
// Sometimes we proactively enclosed an expression where it turns out we might have not needed it after all.
void CompilerGLSL::strip_enclosed_expression(string &expr)
{
if (expr.size() < 2 || expr.front() != '(' || expr.back() != ')')
return;
// Have to make sure that our first and last parens actually enclose everything inside it.
uint32_t paren_count = 0;
for (auto &c : expr)
{
if (c == '(')
paren_count++;
else if (c == ')')
{
paren_count--;
// If we hit 0 and this is not the final char, our first and final parens actually don't
// enclose the expression, and we cannot strip, e.g.: (a + b) * (c + d).
if (paren_count == 0 && &c != &expr.back())
return;
}
}
expr.erase(expr.size() - 1, 1);
expr.erase(begin(expr));
}
string CompilerGLSL::enclose_expression(const string &expr)
{
bool need_parens = false;
// If the expression starts with a unary we need to enclose to deal with cases where we have back-to-back
// unary expressions.
if (!expr.empty())
{
auto c = expr.front();
if (c == '-' || c == '+' || c == '!' || c == '~' || c == '&' || c == '*')
need_parens = true;
}
if (!need_parens)
{
uint32_t paren_count = 0;
for (auto c : expr)
{
if (c == '(' || c == '[')
paren_count++;
else if (c == ')' || c == ']')
{
assert(paren_count);
paren_count--;
}
else if (c == ' ' && paren_count == 0)
{
need_parens = true;
break;
}
}
assert(paren_count == 0);
}
// If this expression contains any spaces which are not enclosed by parentheses,
// we need to enclose it so we can treat the whole string as an expression.
// This happens when two expressions have been part of a binary op earlier.
if (need_parens)
return join('(', expr, ')');
else
return expr;
}
string CompilerGLSL::dereference_expression(const std::string &expr)
{
// If this expression starts with an address-of operator ('&'), then
// just return the part after the operator.
// TODO: Strip parens if unnecessary?
if (expr.front() == '&')
return expr.substr(1);
else
return join('*', expr);
}
string CompilerGLSL::address_of_expression(const std::string &expr)
{
// If this expression starts with a dereference operator ('*'), then
// just return the part after the operator.
// TODO: Strip parens if unnecessary?
if (expr.front() == '*')
return expr.substr(1);
else
return join('&', expr);
}
// Just like to_expression except that we enclose the expression inside parentheses if needed.
string CompilerGLSL::to_enclosed_expression(uint32_t id, bool register_expression_read)
{
return enclose_expression(to_expression(id, register_expression_read));
}
string CompilerGLSL::to_unpacked_expression(uint32_t id, bool register_expression_read)
{
// If we need to transpose, it will also take care of unpacking rules.
auto *e = maybe_get<SPIRExpression>(id);
bool need_transpose = e && e->need_transpose;
if (!need_transpose && has_extended_decoration(id, SPIRVCrossDecorationPacked))
return unpack_expression_type(to_expression(id, register_expression_read), expression_type(id),
get_extended_decoration(id, SPIRVCrossDecorationPackedType));
else
return to_expression(id, register_expression_read);
}
string CompilerGLSL::to_enclosed_unpacked_expression(uint32_t id, bool register_expression_read)
{
// If we need to transpose, it will also take care of unpacking rules.
auto *e = maybe_get<SPIRExpression>(id);
bool need_transpose = e && e->need_transpose;
if (!need_transpose && has_extended_decoration(id, SPIRVCrossDecorationPacked))
return unpack_expression_type(to_expression(id, register_expression_read), expression_type(id),
get_extended_decoration(id, SPIRVCrossDecorationPackedType));
else
return to_enclosed_expression(id, register_expression_read);
}
string CompilerGLSL::to_dereferenced_expression(uint32_t id, bool register_expression_read)
{
auto &type = expression_type(id);
if (type.pointer && should_dereference(id))
return dereference_expression(to_enclosed_expression(id, register_expression_read));
else
return to_expression(id, register_expression_read);
}
string CompilerGLSL::to_pointer_expression(uint32_t id, bool register_expression_read)
{
auto &type = expression_type(id);
if (type.pointer && expression_is_lvalue(id) && !should_dereference(id))
return address_of_expression(to_enclosed_expression(id, register_expression_read));
else
return to_unpacked_expression(id, register_expression_read);
}
string CompilerGLSL::to_enclosed_pointer_expression(uint32_t id, bool register_expression_read)
{
auto &type = expression_type(id);
if (type.pointer && expression_is_lvalue(id) && !should_dereference(id))
return address_of_expression(to_enclosed_expression(id, register_expression_read));
else
return to_enclosed_unpacked_expression(id, register_expression_read);
}
string CompilerGLSL::to_extract_component_expression(uint32_t id, uint32_t index)
{
auto expr = to_enclosed_expression(id);
if (has_extended_decoration(id, SPIRVCrossDecorationPacked))
return join(expr, "[", index, "]");
else
return join(expr, ".", index_to_swizzle(index));
}
string CompilerGLSL::to_expression(uint32_t id, bool register_expression_read)
{
auto itr = invalid_expressions.find(id);
if (itr != end(invalid_expressions))
handle_invalid_expression(id);
if (ir.ids[id].get_type() == TypeExpression)
{
// We might have a more complex chain of dependencies.
// A possible scenario is that we
//
// %1 = OpLoad
// %2 = OpDoSomething %1 %1. here %2 will have a dependency on %1.
// %3 = OpDoSomethingAgain %2 %2. Here %3 will lose the link to %1 since we don't propagate the dependencies like that.
// OpStore %1 %foo // Here we can invalidate %1, and hence all expressions which depend on %1. Only %2 will know since it's part of invalid_expressions.
// %4 = OpDoSomethingAnotherTime %3 %3 // If we forward all expressions we will see %1 expression after store, not before.
//
// However, we can propagate up a list of depended expressions when we used %2, so we can check if %2 is invalid when reading %3 after the store,
// and see that we should not forward reads of the original variable.
auto &expr = get<SPIRExpression>(id);
for (uint32_t dep : expr.expression_dependencies)
if (invalid_expressions.find(dep) != end(invalid_expressions))
handle_invalid_expression(dep);
}
if (register_expression_read)
track_expression_read(id);
switch (ir.ids[id].get_type())
{
case TypeExpression:
{
auto &e = get<SPIRExpression>(id);
if (e.base_expression)
return to_enclosed_expression(e.base_expression) + e.expression;
else if (e.need_transpose)
{
bool is_packed = has_extended_decoration(id, SPIRVCrossDecorationPacked);
return convert_row_major_matrix(e.expression, get<SPIRType>(e.expression_type), is_packed);
}
else
{
if (force_recompile)
{
// During first compilation phase, certain expression patterns can trigger exponential growth of memory.
// Avoid this by returning dummy expressions during this phase.
// Do not use empty expressions here, because those are sentinels for other cases.
return "_";
}
else
return e.expression;
}
}
case TypeConstant:
{
auto &c = get<SPIRConstant>(id);
auto &type = get<SPIRType>(c.constant_type);
// WorkGroupSize may be a constant.
auto &dec = ir.meta[c.self].decoration;
if (dec.builtin)
return builtin_to_glsl(dec.builtin_type, StorageClassGeneric);
else if (c.specialization)
return to_name(id);
else if (c.is_used_as_lut)
return to_name(id);
else if (type.basetype == SPIRType::Struct && !backend.can_declare_struct_inline)
return to_name(id);
else if (!type.array.empty() && !backend.can_declare_arrays_inline)
return to_name(id);
else
return constant_expression(c);
}
case TypeConstantOp:
return to_name(id);
case TypeVariable:
{
auto &var = get<SPIRVariable>(id);
// If we try to use a loop variable before the loop header, we have to redirect it to the static expression,
// the variable has not been declared yet.
if (var.statically_assigned || (var.loop_variable && !var.loop_variable_enable))
return to_expression(var.static_expression);
else if (var.deferred_declaration)
{
var.deferred_declaration = false;
return variable_decl(var);
}
else if (flattened_structs.count(id))
{
return load_flattened_struct(var);
}
else
{
auto &dec = ir.meta[var.self].decoration;
if (dec.builtin)
return builtin_to_glsl(dec.builtin_type, var.storage);
else
return to_name(id);
}
}
case TypeCombinedImageSampler:
// This type should never be taken the expression of directly.
// The intention is that texture sampling functions will extract the image and samplers
// separately and take their expressions as needed.
// GLSL does not use this type because OpSampledImage immediately creates a combined image sampler
// expression ala sampler2D(texture, sampler).
SPIRV_CROSS_THROW("Combined image samplers have no default expression representation.");
case TypeAccessChain:
// We cannot express this type. They only have meaning in other OpAccessChains, OpStore or OpLoad.
SPIRV_CROSS_THROW("Access chains have no default expression representation.");
default:
return to_name(id);
}
}
string CompilerGLSL::constant_op_expression(const SPIRConstantOp &cop)
{
auto &type = get<SPIRType>(cop.basetype);
bool binary = false;
bool unary = false;
string op;
if (is_legacy() && is_unsigned_opcode(cop.opcode))
SPIRV_CROSS_THROW("Unsigned integers are not supported on legacy targets.");
// TODO: Find a clean way to reuse emit_instruction.
switch (cop.opcode)
{
case OpSConvert:
case OpUConvert:
case OpFConvert:
op = type_to_glsl_constructor(type);
break;
#define GLSL_BOP(opname, x) \
case Op##opname: \
binary = true; \
op = x; \
break
#define GLSL_UOP(opname, x) \
case Op##opname: \
unary = true; \
op = x; \
break
GLSL_UOP(SNegate, "-");
GLSL_UOP(Not, "~");
GLSL_BOP(IAdd, "+");
GLSL_BOP(ISub, "-");
GLSL_BOP(IMul, "*");
GLSL_BOP(SDiv, "/");
GLSL_BOP(UDiv, "/");
GLSL_BOP(UMod, "%");
GLSL_BOP(SMod, "%");
GLSL_BOP(ShiftRightLogical, ">>");
GLSL_BOP(ShiftRightArithmetic, ">>");
GLSL_BOP(ShiftLeftLogical, "<<");
GLSL_BOP(BitwiseOr, "|");
GLSL_BOP(BitwiseXor, "^");
GLSL_BOP(BitwiseAnd, "&");
GLSL_BOP(LogicalOr, "||");
GLSL_BOP(LogicalAnd, "&&");
GLSL_UOP(LogicalNot, "!");
GLSL_BOP(LogicalEqual, "==");
GLSL_BOP(LogicalNotEqual, "!=");
GLSL_BOP(IEqual, "==");
GLSL_BOP(INotEqual, "!=");
GLSL_BOP(ULessThan, "<");
GLSL_BOP(SLessThan, "<");
GLSL_BOP(ULessThanEqual, "<=");
GLSL_BOP(SLessThanEqual, "<=");
GLSL_BOP(UGreaterThan, ">");
GLSL_BOP(SGreaterThan, ">");
GLSL_BOP(UGreaterThanEqual, ">=");
GLSL_BOP(SGreaterThanEqual, ">=");
case OpSelect:
{
if (cop.arguments.size() < 3)
SPIRV_CROSS_THROW("Not enough arguments to OpSpecConstantOp.");
// This one is pretty annoying. It's triggered from
// uint(bool), int(bool) from spec constants.
// In order to preserve its compile-time constness in Vulkan GLSL,
// we need to reduce the OpSelect expression back to this simplified model.
// If we cannot, fail.
if (to_trivial_mix_op(type, op, cop.arguments[2], cop.arguments[1], cop.arguments[0]))
{
// Implement as a simple cast down below.
}
else
{
// Implement a ternary and pray the compiler understands it :)
return to_ternary_expression(type, cop.arguments[0], cop.arguments[1], cop.arguments[2]);
}
break;
}
case OpVectorShuffle:
{
string expr = type_to_glsl_constructor(type);
expr += "(";
uint32_t left_components = expression_type(cop.arguments[0]).vecsize;
string left_arg = to_enclosed_expression(cop.arguments[0]);
string right_arg = to_enclosed_expression(cop.arguments[1]);
for (uint32_t i = 2; i < uint32_t(cop.arguments.size()); i++)
{
uint32_t index = cop.arguments[i];
if (index >= left_components)
expr += right_arg + "." + "xyzw"[index - left_components];
else
expr += left_arg + "." + "xyzw"[index];
if (i + 1 < uint32_t(cop.arguments.size()))
expr += ", ";
}
expr += ")";
return expr;
}
case OpCompositeExtract:
{
auto expr = access_chain_internal(cop.arguments[0], &cop.arguments[1], uint32_t(cop.arguments.size() - 1),
ACCESS_CHAIN_INDEX_IS_LITERAL_BIT, nullptr);
return expr;
}
case OpCompositeInsert:
SPIRV_CROSS_THROW("OpCompositeInsert spec constant op is not supported.");
default:
// Some opcodes are unimplemented here, these are currently not possible to test from glslang.
SPIRV_CROSS_THROW("Unimplemented spec constant op.");
}
uint32_t bit_width = 0;
if (unary || binary)
bit_width = expression_type(cop.arguments[0]).width;
SPIRType::BaseType input_type;
bool skip_cast_if_equal_type = opcode_is_sign_invariant(cop.opcode);
switch (cop.opcode)
{
case OpIEqual:
case OpINotEqual:
input_type = to_signed_basetype(bit_width);
break;
case OpSLessThan:
case OpSLessThanEqual:
case OpSGreaterThan:
case OpSGreaterThanEqual:
case OpSMod:
case OpSDiv:
case OpShiftRightArithmetic:
input_type = to_signed_basetype(bit_width);
break;
case OpULessThan:
case OpULessThanEqual:
case OpUGreaterThan:
case OpUGreaterThanEqual:
case OpUMod:
case OpUDiv:
case OpShiftRightLogical:
input_type = to_unsigned_basetype(bit_width);
break;
default:
input_type = type.basetype;
break;
}
#undef GLSL_BOP
#undef GLSL_UOP
if (binary)
{
if (cop.arguments.size() < 2)
SPIRV_CROSS_THROW("Not enough arguments to OpSpecConstantOp.");
string cast_op0;
string cast_op1;
auto expected_type = binary_op_bitcast_helper(cast_op0, cast_op1, input_type, cop.arguments[0],
cop.arguments[1], skip_cast_if_equal_type);
if (type.basetype != input_type && type.basetype != SPIRType::Boolean)
{
expected_type.basetype = input_type;
auto expr = bitcast_glsl_op(type, expected_type);
expr += '(';
expr += join(cast_op0, " ", op, " ", cast_op1);
expr += ')';
return expr;
}
else
return join("(", cast_op0, " ", op, " ", cast_op1, ")");
}
else if (unary)
{
if (cop.arguments.size() < 1)
SPIRV_CROSS_THROW("Not enough arguments to OpSpecConstantOp.");
// Auto-bitcast to result type as needed.
// Works around various casting scenarios in glslang as there is no OpBitcast for specialization constants.
return join("(", op, bitcast_glsl(type, cop.arguments[0]), ")");
}
else
{
if (cop.arguments.size() < 1)
SPIRV_CROSS_THROW("Not enough arguments to OpSpecConstantOp.");
return join(op, "(", to_expression(cop.arguments[0]), ")");
}
}
string CompilerGLSL::constant_expression(const SPIRConstant &c)
{
auto &type = get<SPIRType>(c.constant_type);
if (type.pointer)
{
return backend.null_pointer_literal;
}
else if (!c.subconstants.empty())
{
// Handles Arrays and structures.
string res;
if (backend.use_initializer_list && backend.use_typed_initializer_list && type.basetype == SPIRType::Struct &&
type.array.empty())
{
res = type_to_glsl_constructor(type) + "{ ";
}
else if (backend.use_initializer_list)
{
res = "{ ";
}
else
{
res = type_to_glsl_constructor(type) + "(";
}
for (auto &elem : c.subconstants)
{
auto &subc = get<SPIRConstant>(elem);
if (subc.specialization)
res += to_name(elem);
else
res += constant_expression(subc);
if (&elem != &c.subconstants.back())
res += ", ";
}
res += backend.use_initializer_list ? " }" : ")";
return res;
}
else if (c.columns() == 1)
{
return constant_expression_vector(c, 0);
}
else
{
string res = type_to_glsl(get<SPIRType>(c.constant_type)) + "(";
for (uint32_t col = 0; col < c.columns(); col++)
{
if (c.specialization_constant_id(col) != 0)
res += to_name(c.specialization_constant_id(col));
else
res += constant_expression_vector(c, col);
if (col + 1 < c.columns())
res += ", ";
}
res += ")";
return res;
}
}
#ifdef _MSC_VER
// sprintf warning.
// We cannot rely on snprintf existing because, ..., MSVC.
#pragma warning(push)
#pragma warning(disable : 4996)
#endif
string CompilerGLSL::convert_half_to_string(const SPIRConstant &c, uint32_t col, uint32_t row)
{
string res;
float float_value = c.scalar_f16(col, row);
// There is no literal "hf" in GL_NV_gpu_shader5, so to avoid lots
// of complicated workarounds, just value-cast to the half type always.
if (std::isnan(float_value) || std::isinf(float_value))
{
SPIRType type;
type.basetype = SPIRType::Half;
type.vecsize = 1;
type.columns = 1;
if (float_value == numeric_limits<float>::infinity())
res = join(type_to_glsl(type), "(1.0 / 0.0)");
else if (float_value == -numeric_limits<float>::infinity())
res = join(type_to_glsl(type), "(-1.0 / 0.0)");
else if (std::isnan(float_value))
res = join(type_to_glsl(type), "(0.0 / 0.0)");
else
SPIRV_CROSS_THROW("Cannot represent non-finite floating point constant.");
}
else
{
SPIRType type;
type.basetype = SPIRType::Half;
type.vecsize = 1;
type.columns = 1;
res = join(type_to_glsl(type), "(", convert_to_string(float_value, current_locale_radix_character), ")");
}
return res;
}
string CompilerGLSL::convert_float_to_string(const SPIRConstant &c, uint32_t col, uint32_t row)
{
string res;
float float_value = c.scalar_f32(col, row);
if (std::isnan(float_value) || std::isinf(float_value))
{
// Use special representation.
if (!is_legacy())
{
SPIRType out_type;
SPIRType in_type;
out_type.basetype = SPIRType::Float;
in_type.basetype = SPIRType::UInt;
out_type.vecsize = 1;
in_type.vecsize = 1;
out_type.width = 32;
in_type.width = 32;
char print_buffer[32];
sprintf(print_buffer, "0x%xu", c.scalar(col, row));
res = join(bitcast_glsl_op(out_type, in_type), "(", print_buffer, ")");
}
else
{
if (float_value == numeric_limits<float>::infinity())
{
if (backend.float_literal_suffix)
res = "(1.0f / 0.0f)";
else
res = "(1.0 / 0.0)";
}
else if (float_value == -numeric_limits<float>::infinity())
{
if (backend.float_literal_suffix)
res = "(-1.0f / 0.0f)";
else
res = "(-1.0 / 0.0)";
}
else if (std::isnan(float_value))
{
if (backend.float_literal_suffix)
res = "(0.0f / 0.0f)";
else
res = "(0.0 / 0.0)";
}
else
SPIRV_CROSS_THROW("Cannot represent non-finite floating point constant.");
}
}
else
{
res = convert_to_string(float_value, current_locale_radix_character);
if (backend.float_literal_suffix)
res += "f";
}
return res;
}
std::string CompilerGLSL::convert_double_to_string(const SPIRConstant &c, uint32_t col, uint32_t row)
{
string res;
double double_value = c.scalar_f64(col, row);
if (std::isnan(double_value) || std::isinf(double_value))
{
// Use special representation.
if (!is_legacy())
{
SPIRType out_type;
SPIRType in_type;
out_type.basetype = SPIRType::Double;
in_type.basetype = SPIRType::UInt64;
out_type.vecsize = 1;
in_type.vecsize = 1;
out_type.width = 64;
in_type.width = 64;
uint64_t u64_value = c.scalar_u64(col, row);
if (options.es)
SPIRV_CROSS_THROW("64-bit integers/float not supported in ES profile.");
require_extension_internal("GL_ARB_gpu_shader_int64");
char print_buffer[64];
sprintf(print_buffer, "0x%llx%s", static_cast<unsigned long long>(u64_value),
backend.long_long_literal_suffix ? "ull" : "ul");
res = join(bitcast_glsl_op(out_type, in_type), "(", print_buffer, ")");
}
else
{
if (options.es)
SPIRV_CROSS_THROW("FP64 not supported in ES profile.");
if (options.version < 400)
require_extension_internal("GL_ARB_gpu_shader_fp64");
if (double_value == numeric_limits<double>::infinity())
{
if (backend.double_literal_suffix)
res = "(1.0lf / 0.0lf)";
else
res = "(1.0 / 0.0)";
}
else if (double_value == -numeric_limits<double>::infinity())
{
if (backend.double_literal_suffix)
res = "(-1.0lf / 0.0lf)";
else
res = "(-1.0 / 0.0)";
}
else if (std::isnan(double_value))
{
if (backend.double_literal_suffix)
res = "(0.0lf / 0.0lf)";
else
res = "(0.0 / 0.0)";
}
else
SPIRV_CROSS_THROW("Cannot represent non-finite floating point constant.");
}
}
else
{
res = convert_to_string(double_value, current_locale_radix_character);
if (backend.double_literal_suffix)
res += "lf";
}
return res;
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
string CompilerGLSL::constant_expression_vector(const SPIRConstant &c, uint32_t vector)
{
auto type = get<SPIRType>(c.constant_type);
type.columns = 1;
auto scalar_type = type;
scalar_type.vecsize = 1;
string res;
bool splat = backend.use_constructor_splatting && c.vector_size() > 1;
bool swizzle_splat = backend.can_swizzle_scalar && c.vector_size() > 1;
if (!type_is_floating_point(type))
{
// Cannot swizzle literal integers as a special case.
swizzle_splat = false;
}
if (splat || swizzle_splat)
{
// Cannot use constant splatting if we have specialization constants somewhere in the vector.
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.specialization_constant_id(vector, i) != 0)
{
splat = false;
swizzle_splat = false;
break;
}
}
}
if (splat || swizzle_splat)
{
if (type.width == 64)
{
uint64_t ident = c.scalar_u64(vector, 0);
for (uint32_t i = 1; i < c.vector_size(); i++)
{
if (ident != c.scalar_u64(vector, i))
{
splat = false;
swizzle_splat = false;
break;
}
}
}
else
{
uint32_t ident = c.scalar(vector, 0);
for (uint32_t i = 1; i < c.vector_size(); i++)
{
if (ident != c.scalar(vector, i))
{
splat = false;
swizzle_splat = false;
}
}
}
}
if (c.vector_size() > 1 && !swizzle_splat)
res += type_to_glsl(type) + "(";
switch (type.basetype)
{
case SPIRType::Half:
if (splat || swizzle_splat)
{
res += convert_half_to_string(c, vector, 0);
if (swizzle_splat)
res = remap_swizzle(get<SPIRType>(c.constant_type), 1, res);
}
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
res += convert_half_to_string(c, vector, i);
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::Float:
if (splat || swizzle_splat)
{
res += convert_float_to_string(c, vector, 0);
if (swizzle_splat)
res = remap_swizzle(get<SPIRType>(c.constant_type), 1, res);
}
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
res += convert_float_to_string(c, vector, i);
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::Double:
if (splat || swizzle_splat)
{
res += convert_double_to_string(c, vector, 0);
if (swizzle_splat)
res = remap_swizzle(get<SPIRType>(c.constant_type), 1, res);
}
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
res += convert_double_to_string(c, vector, i);
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::Int64:
if (splat)
{
res += convert_to_string(c.scalar_i64(vector, 0));
if (backend.long_long_literal_suffix)
res += "ll";
else
res += "l";
}
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
{
res += convert_to_string(c.scalar_i64(vector, i));
if (backend.long_long_literal_suffix)
res += "ll";
else
res += "l";
}
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::UInt64:
if (splat)
{
res += convert_to_string(c.scalar_u64(vector, 0));
if (backend.long_long_literal_suffix)
res += "ull";
else
res += "ul";
}
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
{
res += convert_to_string(c.scalar_u64(vector, i));
if (backend.long_long_literal_suffix)
res += "ull";
else
res += "ul";
}
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::UInt:
if (splat)
{
res += convert_to_string(c.scalar(vector, 0));
if (is_legacy())
{
// Fake unsigned constant literals with signed ones if possible.
// Things like array sizes, etc, tend to be unsigned even though they could just as easily be signed.
if (c.scalar_i32(vector, 0) < 0)
SPIRV_CROSS_THROW("Tried to convert uint literal into int, but this made the literal negative.");
}
else if (backend.uint32_t_literal_suffix)
res += "u";
}
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
{
res += convert_to_string(c.scalar(vector, i));
if (is_legacy())
{
// Fake unsigned constant literals with signed ones if possible.
// Things like array sizes, etc, tend to be unsigned even though they could just as easily be signed.
if (c.scalar_i32(vector, i) < 0)
SPIRV_CROSS_THROW(
"Tried to convert uint literal into int, but this made the literal negative.");
}
else if (backend.uint32_t_literal_suffix)
res += "u";
}
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::Int:
if (splat)
res += convert_to_string(c.scalar_i32(vector, 0));
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
res += convert_to_string(c.scalar_i32(vector, i));
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::UShort:
if (splat)
{
res += convert_to_string(c.scalar(vector, 0));
if (is_legacy())
{
// Fake unsigned constant literals with signed ones if possible.
// Things like array sizes, etc, tend to be unsigned even though they could just as easily be signed.
if (c.scalar_i16(vector, 0) < 0)
SPIRV_CROSS_THROW("Tried to convert uint literal into int, but this made the literal negative.");
}
else
res += backend.uint16_t_literal_suffix;
}
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
{
res += convert_to_string(c.scalar(vector, i));
if (is_legacy())
{
// Fake unsigned constant literals with signed ones if possible.
// Things like array sizes, etc, tend to be unsigned even though they could just as easily be signed.
if (c.scalar_i16(vector, i) < 0)
SPIRV_CROSS_THROW(
"Tried to convert uint literal into int, but this made the literal negative.");
}
else
res += backend.uint16_t_literal_suffix;
}
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::Short:
if (splat)
{
res += convert_to_string(c.scalar_i16(vector, 0));
res += backend.int16_t_literal_suffix;
}
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
{
res += convert_to_string(c.scalar_i16(vector, i));
res += backend.int16_t_literal_suffix;
}
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::UByte:
if (splat)
{
res += convert_to_string(c.scalar_u8(vector, 0));
}
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
{
res += type_to_glsl(scalar_type);
res += "(";
res += convert_to_string(c.scalar_u8(vector, i));
res += ")";
}
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::SByte:
if (splat)
{
res += convert_to_string(c.scalar_i8(vector, 0));
}
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
{
res += type_to_glsl(scalar_type);
res += "(";
res += convert_to_string(c.scalar_i8(vector, i));
res += ")";
}
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
case SPIRType::Boolean:
if (splat)
res += c.scalar(vector, 0) ? "true" : "false";
else
{
for (uint32_t i = 0; i < c.vector_size(); i++)
{
if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0)
res += to_name(c.specialization_constant_id(vector, i));
else
res += c.scalar(vector, i) ? "true" : "false";
if (i + 1 < c.vector_size())
res += ", ";
}
}
break;
default:
SPIRV_CROSS_THROW("Invalid constant expression basetype.");
}
if (c.vector_size() > 1 && !swizzle_splat)
res += ")";
return res;
}
string CompilerGLSL::declare_temporary(uint32_t result_type, uint32_t result_id)
{
auto &type = get<SPIRType>(result_type);
auto &flags = ir.meta[result_id].decoration.decoration_flags;
// If we're declaring temporaries inside continue blocks,
// we must declare the temporary in the loop header so that the continue block can avoid declaring new variables.
if (current_continue_block && !hoisted_temporaries.count(result_id))
{
auto &header = get<SPIRBlock>(current_continue_block->loop_dominator);
if (find_if(begin(header.declare_temporary), end(header.declare_temporary),
[result_type, result_id](const pair<uint32_t, uint32_t> &tmp) {
return tmp.first == result_type && tmp.second == result_id;
}) == end(header.declare_temporary))
{
header.declare_temporary.emplace_back(result_type, result_id);
hoisted_temporaries.insert(result_id);
force_recompile = true;
}
return join(to_name(result_id), " = ");
}
else if (hoisted_temporaries.count(result_id))
{
// The temporary has already been declared earlier, so just "declare" the temporary by writing to it.
return join(to_name(result_id), " = ");
}
else
{
// The result_id has not been made into an expression yet, so use flags interface.
add_local_variable_name(result_id);
return join(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, to_name(result_id)), " = ");
}
}
bool CompilerGLSL::expression_is_forwarded(uint32_t id)
{
return forwarded_temporaries.find(id) != end(forwarded_temporaries);
}
SPIRExpression &CompilerGLSL::emit_op(uint32_t result_type, uint32_t result_id, const string &rhs, bool forwarding,
bool suppress_usage_tracking)
{
if (forwarding && (forced_temporaries.find(result_id) == end(forced_temporaries)))
{
// Just forward it without temporary.
// If the forward is trivial, we do not force flushing to temporary for this expression.
if (!suppress_usage_tracking)
forwarded_temporaries.insert(result_id);
return set<SPIRExpression>(result_id, rhs, result_type, true);
}
else
{
// If expression isn't immutable, bind it to a temporary and make the new temporary immutable (they always are).
statement(declare_temporary(result_type, result_id), rhs, ";");
return set<SPIRExpression>(result_id, to_name(result_id), result_type, true);
}
}
void CompilerGLSL::emit_unary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op)
{
bool forward = should_forward(op0);
emit_op(result_type, result_id, join(op, to_enclosed_unpacked_expression(op0)), forward);
inherit_expression_dependencies(result_id, op0);
}
void CompilerGLSL::emit_binary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op)
{
bool forward = should_forward(op0) && should_forward(op1);
emit_op(result_type, result_id,
join(to_enclosed_unpacked_expression(op0), " ", op, " ", to_enclosed_unpacked_expression(op1)), forward);
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
}
void CompilerGLSL::emit_unrolled_unary_op(uint32_t result_type, uint32_t result_id, uint32_t operand, const char *op)
{
auto &type = get<SPIRType>(result_type);
auto expr = type_to_glsl_constructor(type);
expr += '(';
for (uint32_t i = 0; i < type.vecsize; i++)
{
// Make sure to call to_expression multiple times to ensure
// that these expressions are properly flushed to temporaries if needed.
expr += op;
expr += to_extract_component_expression(operand, i);
if (i + 1 < type.vecsize)
expr += ", ";
}
expr += ')';
emit_op(result_type, result_id, expr, should_forward(operand));
inherit_expression_dependencies(result_id, operand);
}
void CompilerGLSL::emit_unrolled_binary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
const char *op)
{
auto &type = get<SPIRType>(result_type);
auto expr = type_to_glsl_constructor(type);
expr += '(';
for (uint32_t i = 0; i < type.vecsize; i++)
{
// Make sure to call to_expression multiple times to ensure
// that these expressions are properly flushed to temporaries if needed.
expr += to_extract_component_expression(op0, i);
expr += ' ';
expr += op;
expr += ' ';
expr += to_extract_component_expression(op1, i);
if (i + 1 < type.vecsize)
expr += ", ";
}
expr += ')';
emit_op(result_type, result_id, expr, should_forward(op0) && should_forward(op1));
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
}
SPIRType CompilerGLSL::binary_op_bitcast_helper(string &cast_op0, string &cast_op1, SPIRType::BaseType &input_type,
uint32_t op0, uint32_t op1, bool skip_cast_if_equal_type)
{
auto &type0 = expression_type(op0);
auto &type1 = expression_type(op1);
// We have to bitcast if our inputs are of different type, or if our types are not equal to expected inputs.
// For some functions like OpIEqual and INotEqual, we don't care if inputs are of different types than expected
// since equality test is exactly the same.
bool cast = (type0.basetype != type1.basetype) || (!skip_cast_if_equal_type && type0.basetype != input_type);
// Create a fake type so we can bitcast to it.
// We only deal with regular arithmetic types here like int, uints and so on.
SPIRType expected_type;
expected_type.basetype = input_type;
expected_type.vecsize = type0.vecsize;
expected_type.columns = type0.columns;
expected_type.width = type0.width;
if (cast)
{
cast_op0 = bitcast_glsl(expected_type, op0);
cast_op1 = bitcast_glsl(expected_type, op1);
}
else
{
// If we don't cast, our actual input type is that of the first (or second) argument.
cast_op0 = to_enclosed_unpacked_expression(op0);
cast_op1 = to_enclosed_unpacked_expression(op1);
input_type = type0.basetype;
}
return expected_type;
}
void CompilerGLSL::emit_binary_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
const char *op, SPIRType::BaseType input_type, bool skip_cast_if_equal_type)
{
string cast_op0, cast_op1;
auto expected_type = binary_op_bitcast_helper(cast_op0, cast_op1, input_type, op0, op1, skip_cast_if_equal_type);
auto &out_type = get<SPIRType>(result_type);
// We might have casted away from the result type, so bitcast again.
// For example, arithmetic right shift with uint inputs.
// Special case boolean outputs since relational opcodes output booleans instead of int/uint.
string expr;
if (out_type.basetype != input_type && out_type.basetype != SPIRType::Boolean)
{
expected_type.basetype = input_type;
expr = bitcast_glsl_op(out_type, expected_type);
expr += '(';
expr += join(cast_op0, " ", op, " ", cast_op1);
expr += ')';
}
else
expr += join(cast_op0, " ", op, " ", cast_op1);
emit_op(result_type, result_id, expr, should_forward(op0) && should_forward(op1));
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
}
void CompilerGLSL::emit_unary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op)
{
bool forward = should_forward(op0);
emit_op(result_type, result_id, join(op, "(", to_unpacked_expression(op0), ")"), forward);
inherit_expression_dependencies(result_id, op0);
}
void CompilerGLSL::emit_binary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
const char *op)
{
bool forward = should_forward(op0) && should_forward(op1);
emit_op(result_type, result_id, join(op, "(", to_unpacked_expression(op0), ", ", to_unpacked_expression(op1), ")"),
forward);
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
}
void CompilerGLSL::emit_unary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op,
SPIRType::BaseType input_type, SPIRType::BaseType expected_result_type)
{
auto &out_type = get<SPIRType>(result_type);
auto expected_type = out_type;
expected_type.basetype = input_type;
string cast_op = expression_type(op0).basetype != input_type ? bitcast_glsl(expected_type, op0) : to_expression(op0);
string expr;
if (out_type.basetype != expected_result_type)
{
expected_type.basetype = expected_result_type;
expr = bitcast_glsl_op(out_type, expected_type);
expr += '(';
expr += join(op, "(", cast_op, ")");
expr += ')';
}
else
{
expr += join(op, "(", cast_op, ")");
}
emit_op(result_type, result_id, expr, should_forward(op0));
inherit_expression_dependencies(result_id, op0);
}
void CompilerGLSL::emit_trinary_func_op_cast(uint32_t result_type, uint32_t result_id,
uint32_t op0, uint32_t op1, uint32_t op2,
const char *op,
SPIRType::BaseType input_type)
{
auto &out_type = get<SPIRType>(result_type);
auto expected_type = out_type;
expected_type.basetype = input_type;
string cast_op0 = expression_type(op0).basetype != input_type ? bitcast_glsl(expected_type, op0) : to_expression(op0);
string cast_op1 = expression_type(op1).basetype != input_type ? bitcast_glsl(expected_type, op1) : to_expression(op1);
string cast_op2 = expression_type(op2).basetype != input_type ? bitcast_glsl(expected_type, op2) : to_expression(op2);
string expr;
if (out_type.basetype != input_type)
{
expr = bitcast_glsl_op(out_type, expected_type);
expr += '(';
expr += join(op, "(", cast_op0, ", ", cast_op1, ", ", cast_op2, ")");
expr += ')';
}
else
{
expr += join(op, "(", cast_op0, ", ", cast_op1, ", ", cast_op2, ")");
}
emit_op(result_type, result_id, expr, should_forward(op0) && should_forward(op1) && should_forward(op2));
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
inherit_expression_dependencies(result_id, op2);
}
void CompilerGLSL::emit_binary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
const char *op, SPIRType::BaseType input_type, bool skip_cast_if_equal_type)
{
string cast_op0, cast_op1;
auto expected_type = binary_op_bitcast_helper(cast_op0, cast_op1, input_type, op0, op1, skip_cast_if_equal_type);
auto &out_type = get<SPIRType>(result_type);
// Special case boolean outputs since relational opcodes output booleans instead of int/uint.
string expr;
if (out_type.basetype != input_type && out_type.basetype != SPIRType::Boolean)
{
expected_type.basetype = input_type;
expr = bitcast_glsl_op(out_type, expected_type);
expr += '(';
expr += join(op, "(", cast_op0, ", ", cast_op1, ")");
expr += ')';
}
else
{
expr += join(op, "(", cast_op0, ", ", cast_op1, ")");
}
emit_op(result_type, result_id, expr, should_forward(op0) && should_forward(op1));
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
}
void CompilerGLSL::emit_trinary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
uint32_t op2, const char *op)
{
bool forward = should_forward(op0) && should_forward(op1) && should_forward(op2);
emit_op(result_type, result_id,
join(op, "(", to_unpacked_expression(op0), ", ", to_unpacked_expression(op1), ", ",
to_unpacked_expression(op2), ")"),
forward);
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
inherit_expression_dependencies(result_id, op2);
}
void CompilerGLSL::emit_quaternary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
uint32_t op2, uint32_t op3, const char *op)
{
bool forward = should_forward(op0) && should_forward(op1) && should_forward(op2) && should_forward(op3);
emit_op(result_type, result_id,
join(op, "(", to_unpacked_expression(op0), ", ", to_unpacked_expression(op1), ", ",
to_unpacked_expression(op2), ", ", to_unpacked_expression(op3), ")"),
forward);
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
inherit_expression_dependencies(result_id, op2);
inherit_expression_dependencies(result_id, op3);
}
// EXT_shader_texture_lod only concerns fragment shaders so lod tex functions
// are not allowed in ES 2 vertex shaders. But SPIR-V only supports lod tex
// functions in vertex shaders so we revert those back to plain calls when
// the lod is a constant value of zero.
bool CompilerGLSL::check_explicit_lod_allowed(uint32_t lod)
{
auto &execution = get_entry_point();
bool allowed = !is_legacy_es() || execution.model == ExecutionModelFragment;
if (!allowed && lod != 0)
{
auto *lod_constant = maybe_get<SPIRConstant>(lod);
if (!lod_constant || lod_constant->scalar_f32() != 0.0f)
{
SPIRV_CROSS_THROW("Explicit lod not allowed in legacy ES non-fragment shaders.");
}
}
return allowed;
}
string CompilerGLSL::legacy_tex_op(const std::string &op, const SPIRType &imgtype, uint32_t lod, uint32_t tex)
{
const char *type;
switch (imgtype.image.dim)
{
case spv::Dim1D:
type = (imgtype.image.arrayed && !options.es) ? "1DArray" : "1D";
break;
case spv::Dim2D:
type = (imgtype.image.arrayed && !options.es) ? "2DArray" : "2D";
break;
case spv::Dim3D:
type = "3D";
break;
case spv::DimCube:
type = "Cube";
break;
case spv::DimRect:
type = "2DRect";
break;
case spv::DimBuffer:
type = "Buffer";
break;
case spv::DimSubpassData:
type = "2D";
break;
default:
type = "";
break;
}
bool use_explicit_lod = check_explicit_lod_allowed(lod);
if (op == "textureLod" || op == "textureProjLod" || op == "textureGrad" || op == "textureProjGrad")
{
if (is_legacy_es())
{
if (use_explicit_lod)
require_extension_internal("GL_EXT_shader_texture_lod");
}
else if (is_legacy())
require_extension_internal("GL_ARB_shader_texture_lod");
}
if (op == "textureLodOffset" || op == "textureProjLodOffset")
{
if (is_legacy_es())
SPIRV_CROSS_THROW(join(op, " not allowed in legacy ES"));
require_extension_internal("GL_EXT_gpu_shader4");
}
// GLES has very limited support for shadow samplers.
// Basically shadow2D and shadow2DProj work through EXT_shadow_samplers,
// everything else can just throw
if (image_is_comparison(imgtype, tex) && is_legacy_es())
{
if (op == "texture" || op == "textureProj")
require_extension_internal("GL_EXT_shadow_samplers");
else
SPIRV_CROSS_THROW(join(op, " not allowed on depth samplers in legacy ES"));
}
bool is_es_and_depth = is_legacy_es() && image_is_comparison(imgtype, tex);
std::string type_prefix = image_is_comparison(imgtype, tex) ? "shadow" : "texture";
if (op == "texture")
return is_es_and_depth ? join(type_prefix, type, "EXT") : join(type_prefix, type);
else if (op == "textureLod")
{
if (use_explicit_lod)
return join(type_prefix, type, is_legacy_es() ? "LodEXT" : "Lod");
else
return join(type_prefix, type);
}
else if (op == "textureProj")
return join(type_prefix, type, is_es_and_depth ? "ProjEXT" : "Proj");
else if (op == "textureGrad")
return join(type_prefix, type, is_legacy_es() ? "GradEXT" : is_legacy_desktop() ? "GradARB" : "Grad");
else if (op == "textureProjLod")
{
if (use_explicit_lod)
return join(type_prefix, type, is_legacy_es() ? "ProjLodEXT" : "ProjLod");
else
return join(type_prefix, type, "Proj");
}
else if (op == "textureLodOffset")
{
if (use_explicit_lod)
return join(type_prefix, type, "LodOffset");
else
return join(type_prefix, type);
}
else if (op == "textureProjGrad")
return join(type_prefix, type,
is_legacy_es() ? "ProjGradEXT" : is_legacy_desktop() ? "ProjGradARB" : "ProjGrad");
else if (op == "textureProjLodOffset")
{
if (use_explicit_lod)
return join(type_prefix, type, "ProjLodOffset");
else
return join(type_prefix, type, "ProjOffset");
}
else
{
SPIRV_CROSS_THROW(join("Unsupported legacy texture op: ", op));
}
}
bool CompilerGLSL::to_trivial_mix_op(const SPIRType &type, string &op, uint32_t left, uint32_t right, uint32_t lerp)
{
auto *cleft = maybe_get<SPIRConstant>(left);
auto *cright = maybe_get<SPIRConstant>(right);
auto &lerptype = expression_type(lerp);
// If our targets aren't constants, we cannot use construction.
if (!cleft || !cright)
return false;
// If our targets are spec constants, we cannot use construction.
if (cleft->specialization || cright->specialization)
return false;
// We can only use trivial construction if we have a scalar
// (should be possible to do it for vectors as well, but that is overkill for now).
if (lerptype.basetype != SPIRType::Boolean || lerptype.vecsize > 1)
return false;
// If our bool selects between 0 and 1, we can cast from bool instead, making our trivial constructor.
bool ret = false;
switch (type.basetype)
{
case SPIRType::Short:
case SPIRType::UShort:
ret = cleft->scalar_u16() == 0 && cright->scalar_u16() == 1;
break;
case SPIRType::Int:
case SPIRType::UInt:
ret = cleft->scalar() == 0 && cright->scalar() == 1;
break;
case SPIRType::Half:
ret = cleft->scalar_f16() == 0.0f && cright->scalar_f16() == 1.0f;
break;
case SPIRType::Float:
ret = cleft->scalar_f32() == 0.0f && cright->scalar_f32() == 1.0f;
break;
case SPIRType::Double:
ret = cleft->scalar_f64() == 0.0 && cright->scalar_f64() == 1.0;
break;
case SPIRType::Int64:
case SPIRType::UInt64:
ret = cleft->scalar_u64() == 0 && cright->scalar_u64() == 1;
break;
default:
break;
}
if (ret)
op = type_to_glsl_constructor(type);
return ret;
}
string CompilerGLSL::to_ternary_expression(const SPIRType &restype, uint32_t select, uint32_t true_value,
uint32_t false_value)
{
string expr;
auto &lerptype = expression_type(select);
if (lerptype.vecsize == 1)
expr = join(to_enclosed_expression(select), " ? ", to_enclosed_pointer_expression(true_value), " : ",
to_enclosed_pointer_expression(false_value));
else
{
auto swiz = [this](uint32_t expression, uint32_t i) { return to_extract_component_expression(expression, i); };
expr = type_to_glsl_constructor(restype);
expr += "(";
for (uint32_t i = 0; i < restype.vecsize; i++)
{
expr += swiz(select, i);
expr += " ? ";
expr += swiz(true_value, i);
expr += " : ";
expr += swiz(false_value, i);
if (i + 1 < restype.vecsize)
expr += ", ";
}
expr += ")";
}
return expr;
}
void CompilerGLSL::emit_mix_op(uint32_t result_type, uint32_t id, uint32_t left, uint32_t right, uint32_t lerp)
{
auto &lerptype = expression_type(lerp);
auto &restype = get<SPIRType>(result_type);
// If this results in a variable pointer, assume it may be written through.
if (restype.pointer)
{
register_write(left);
register_write(right);
}
string mix_op;
bool has_boolean_mix = backend.boolean_mix_support &&
((options.es && options.version >= 310) || (!options.es && options.version >= 450));
bool trivial_mix = to_trivial_mix_op(restype, mix_op, left, right, lerp);
// Cannot use boolean mix when the lerp argument is just one boolean,
// fall back to regular trinary statements.
if (lerptype.vecsize == 1)
has_boolean_mix = false;
// If we can reduce the mix to a simple cast, do so.
// This helps for cases like int(bool), uint(bool) which is implemented with
// OpSelect bool 1 0.
if (trivial_mix)
{
emit_unary_func_op(result_type, id, lerp, mix_op.c_str());
}
else if (!has_boolean_mix && lerptype.basetype == SPIRType::Boolean)
{
// Boolean mix not supported on desktop without extension.
// Was added in OpenGL 4.5 with ES 3.1 compat.
//
// Could use GL_EXT_shader_integer_mix on desktop at least,
// but Apple doesn't support it. :(
// Just implement it as ternary expressions.
auto expr = to_ternary_expression(get<SPIRType>(result_type), lerp, right, left);
emit_op(result_type, id, expr, should_forward(left) && should_forward(right) && should_forward(lerp));
inherit_expression_dependencies(id, left);
inherit_expression_dependencies(id, right);
inherit_expression_dependencies(id, lerp);
}
else
emit_trinary_func_op(result_type, id, left, right, lerp, "mix");
}
string CompilerGLSL::to_combined_image_sampler(uint32_t image_id, uint32_t samp_id)
{
// Keep track of the array indices we have used to load the image.
// We'll need to use the same array index into the combined image sampler array.
auto image_expr = to_expression(image_id);
string array_expr;
auto array_index = image_expr.find_first_of('[');
if (array_index != string::npos)
array_expr = image_expr.substr(array_index, string::npos);
auto &args = current_function->arguments;
// For GLSL and ESSL targets, we must enumerate all possible combinations for sampler2D(texture2D, sampler) and redirect
// all possible combinations into new sampler2D uniforms.
auto *image = maybe_get_backing_variable(image_id);
auto *samp = maybe_get_backing_variable(samp_id);
if (image)
image_id = image->self;
if (samp)
samp_id = samp->self;
auto image_itr = find_if(begin(args), end(args),
[image_id](const SPIRFunction::Parameter ¶m) { return param.id == image_id; });
auto sampler_itr = find_if(begin(args), end(args),
[samp_id](const SPIRFunction::Parameter ¶m) { return param.id == samp_id; });
if (image_itr != end(args) || sampler_itr != end(args))
{
// If any parameter originates from a parameter, we will find it in our argument list.
bool global_image = image_itr == end(args);
bool global_sampler = sampler_itr == end(args);
uint32_t iid = global_image ? image_id : uint32_t(image_itr - begin(args));
uint32_t sid = global_sampler ? samp_id : uint32_t(sampler_itr - begin(args));
auto &combined = current_function->combined_parameters;
auto itr = find_if(begin(combined), end(combined), [=](const SPIRFunction::CombinedImageSamplerParameter &p) {
return p.global_image == global_image && p.global_sampler == global_sampler && p.image_id == iid &&
p.sampler_id == sid;
});
if (itr != end(combined))
return to_expression(itr->id) + array_expr;
else
{
SPIRV_CROSS_THROW(
"Cannot find mapping for combined sampler parameter, was build_combined_image_samplers() used "
"before compile() was called?");
}
}
else
{
// For global sampler2D, look directly at the global remapping table.
auto &mapping = combined_image_samplers;
auto itr = find_if(begin(mapping), end(mapping), [image_id, samp_id](const CombinedImageSampler &combined) {
return combined.image_id == image_id && combined.sampler_id == samp_id;
});
if (itr != end(combined_image_samplers))
return to_expression(itr->combined_id) + array_expr;
else
{
SPIRV_CROSS_THROW("Cannot find mapping for combined sampler, was build_combined_image_samplers() used "
"before compile() was called?");
}
}
}
void CompilerGLSL::emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id)
{
if (options.vulkan_semantics && combined_image_samplers.empty())
{
emit_binary_func_op(result_type, result_id, image_id, samp_id,
type_to_glsl(get<SPIRType>(result_type), result_id).c_str());
// Make sure to suppress usage tracking. It is illegal to create temporaries of opaque types.
forwarded_temporaries.erase(result_id);
}
else
{
// Make sure to suppress usage tracking. It is illegal to create temporaries of opaque types.
emit_op(result_type, result_id, to_combined_image_sampler(image_id, samp_id), true, true);
}
}
static inline bool image_opcode_is_sample_no_dref(Op op)
{
switch (op)
{
case OpImageSampleExplicitLod:
case OpImageSampleImplicitLod:
case OpImageSampleProjExplicitLod:
case OpImageSampleProjImplicitLod:
case OpImageFetch:
case OpImageRead:
case OpImageSparseSampleExplicitLod:
case OpImageSparseSampleImplicitLod:
case OpImageSparseSampleProjExplicitLod:
case OpImageSparseSampleProjImplicitLod:
case OpImageSparseFetch:
case OpImageSparseRead:
return true;
default:
return false;
}
}
void CompilerGLSL::emit_texture_op(const Instruction &i)
{
auto *ops = stream(i);
auto op = static_cast<Op>(i.op);
uint32_t length = i.length;
vector<uint32_t> inherited_expressions;
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t img = ops[2];
uint32_t coord = ops[3];
uint32_t dref = 0;
uint32_t comp = 0;
bool gather = false;
bool proj = false;
bool fetch = false;
const uint32_t *opt = nullptr;
inherited_expressions.push_back(coord);
switch (op)
{
case OpImageSampleDrefImplicitLod:
case OpImageSampleDrefExplicitLod:
dref = ops[4];
opt = &ops[5];
length -= 5;
break;
case OpImageSampleProjDrefImplicitLod:
case OpImageSampleProjDrefExplicitLod:
dref = ops[4];
opt = &ops[5];
length -= 5;
proj = true;
break;
case OpImageDrefGather:
dref = ops[4];
opt = &ops[5];
length -= 5;
gather = true;
break;
case OpImageGather:
comp = ops[4];
opt = &ops[5];
length -= 5;
gather = true;
break;
case OpImageFetch:
case OpImageRead: // Reads == fetches in Metal (other langs will not get here)
opt = &ops[4];
length -= 4;
fetch = true;
break;
case OpImageSampleProjImplicitLod:
case OpImageSampleProjExplicitLod:
opt = &ops[4];
length -= 4;
proj = true;
break;
default:
opt = &ops[4];
length -= 4;
break;
}
// Bypass pointers because we need the real image struct
auto &type = expression_type(img);
auto &imgtype = get<SPIRType>(type.self);
uint32_t coord_components = 0;
switch (imgtype.image.dim)
{
case spv::Dim1D:
coord_components = 1;
break;
case spv::Dim2D:
coord_components = 2;
break;
case spv::Dim3D:
coord_components = 3;
break;
case spv::DimCube:
coord_components = 3;
break;
case spv::DimBuffer:
coord_components = 1;
break;
default:
coord_components = 2;
break;
}
if (dref)
inherited_expressions.push_back(dref);
if (proj)
coord_components++;
if (imgtype.image.arrayed)
coord_components++;
uint32_t bias = 0;
uint32_t lod = 0;
uint32_t grad_x = 0;
uint32_t grad_y = 0;
uint32_t coffset = 0;
uint32_t offset = 0;
uint32_t coffsets = 0;
uint32_t sample = 0;
uint32_t flags = 0;
if (length)
{
flags = *opt++;
length--;
}
auto test = [&](uint32_t &v, uint32_t flag) {
if (length && (flags & flag))
{
v = *opt++;
inherited_expressions.push_back(v);
length--;
}
};
test(bias, ImageOperandsBiasMask);
test(lod, ImageOperandsLodMask);
test(grad_x, ImageOperandsGradMask);
test(grad_y, ImageOperandsGradMask);
test(coffset, ImageOperandsConstOffsetMask);
test(offset, ImageOperandsOffsetMask);
test(coffsets, ImageOperandsConstOffsetsMask);
test(sample, ImageOperandsSampleMask);
string expr;
bool forward = false;
expr += to_function_name(img, imgtype, !!fetch, !!gather, !!proj, !!coffsets, (!!coffset || !!offset),
(!!grad_x || !!grad_y), !!dref, lod);
expr += "(";
expr += to_function_args(img, imgtype, fetch, gather, proj, coord, coord_components, dref, grad_x, grad_y, lod,
coffset, offset, bias, comp, sample, &forward);
expr += ")";
// texture(samplerXShadow) returns float. shadowX() returns vec4. Swizzle here.
if (is_legacy() && image_is_comparison(imgtype, img))
expr += ".r";
// Sampling from a texture which was deduced to be a depth image, might actually return 1 component here.
// Remap back to 4 components as sampling opcodes expect.
bool image_is_depth;
const auto *combined = maybe_get<SPIRCombinedImageSampler>(img);
if (combined)
image_is_depth = image_is_comparison(imgtype, combined->image);
else
image_is_depth = image_is_comparison(imgtype, img);
if (image_is_depth && backend.comparison_image_samples_scalar && image_opcode_is_sample_no_dref(op))
{
expr = remap_swizzle(get<SPIRType>(result_type), 1, expr);
}
// Deals with reads from MSL. We might need to downconvert to fewer components.
if (op == OpImageRead)
expr = remap_swizzle(get<SPIRType>(result_type), 4, expr);
emit_op(result_type, id, expr, forward);
for (auto &inherit : inherited_expressions)
inherit_expression_dependencies(id, inherit);
switch (op)
{
case OpImageSampleDrefImplicitLod:
case OpImageSampleImplicitLod:
case OpImageSampleProjImplicitLod:
case OpImageSampleProjDrefImplicitLod:
register_control_dependent_expression(id);
break;
default:
break;
}
}
bool CompilerGLSL::expression_is_constant_null(uint32_t id) const
{
auto *c = maybe_get<SPIRConstant>(id);
if (!c)
return false;
return c->constant_is_null();
}
// Returns the function name for a texture sampling function for the specified image and sampling characteristics.
// For some subclasses, the function is a method on the specified image.
string CompilerGLSL::to_function_name(uint32_t tex, const SPIRType &imgtype, bool is_fetch, bool is_gather,
bool is_proj, bool has_array_offsets, bool has_offset, bool has_grad, bool,
uint32_t lod)
{
string fname;
// textureLod on sampler2DArrayShadow and samplerCubeShadow does not exist in GLSL for some reason.
// To emulate this, we will have to use textureGrad with a constant gradient of 0.
// The workaround will assert that the LOD is in fact constant 0, or we cannot emit correct code.
// This happens for HLSL SampleCmpLevelZero on Texture2DArray and TextureCube.
bool workaround_lod_array_shadow_as_grad = false;
if (((imgtype.image.arrayed && imgtype.image.dim == Dim2D) || imgtype.image.dim == DimCube) &&
image_is_comparison(imgtype, tex) && lod)
{
if (!expression_is_constant_null(lod))
{
SPIRV_CROSS_THROW(
"textureLod on sampler2DArrayShadow is not constant 0.0. This cannot be expressed in GLSL.");
}
workaround_lod_array_shadow_as_grad = true;
}
if (is_fetch)
fname += "texelFetch";
else
{
fname += "texture";
if (is_gather)
fname += "Gather";
if (has_array_offsets)
fname += "Offsets";
if (is_proj)
fname += "Proj";
if (has_grad || workaround_lod_array_shadow_as_grad)
fname += "Grad";
if (!!lod && !workaround_lod_array_shadow_as_grad)
fname += "Lod";
}
if (has_offset)
fname += "Offset";
return is_legacy() ? legacy_tex_op(fname, imgtype, lod, tex) : fname;
}
std::string CompilerGLSL::convert_separate_image_to_expression(uint32_t id)
{
auto *var = maybe_get_backing_variable(id);
// If we are fetching from a plain OpTypeImage, we must combine with a dummy sampler in GLSL.
// In Vulkan GLSL, we can make use of the newer GL_EXT_samplerless_texture_functions.
if (var)
{
auto &type = get<SPIRType>(var->basetype);
if (type.basetype == SPIRType::Image && type.image.sampled == 1 && type.image.dim != DimBuffer)
{
if (options.vulkan_semantics)
{
// Newer glslang supports this extension to deal with texture2D as argument to texture functions.
if (dummy_sampler_id)
SPIRV_CROSS_THROW("Vulkan GLSL should not have a dummy sampler for combining.");
require_extension_internal("GL_EXT_samplerless_texture_functions");
}
else
{
if (!dummy_sampler_id)
SPIRV_CROSS_THROW(
"Cannot find dummy sampler ID. Was build_dummy_sampler_for_combined_images() called?");
return to_combined_image_sampler(id, dummy_sampler_id);
}
}
}
return to_expression(id);
}
// Returns the function args for a texture sampling function for the specified image and sampling characteristics.
string CompilerGLSL::to_function_args(uint32_t img, const SPIRType &imgtype, bool is_fetch, bool is_gather,
bool is_proj, uint32_t coord, uint32_t coord_components, uint32_t dref,
uint32_t grad_x, uint32_t grad_y, uint32_t lod, uint32_t coffset, uint32_t offset,
uint32_t bias, uint32_t comp, uint32_t sample, bool *p_forward)
{
string farg_str;
if (is_fetch)
farg_str = convert_separate_image_to_expression(img);
else
farg_str = to_expression(img);
bool swizz_func = backend.swizzle_is_function;
auto swizzle = [swizz_func](uint32_t comps, uint32_t in_comps) -> const char * {
if (comps == in_comps)
return "";
switch (comps)
{
case 1:
return ".x";
case 2:
return swizz_func ? ".xy()" : ".xy";
case 3:
return swizz_func ? ".xyz()" : ".xyz";
default:
return "";
}
};
bool forward = should_forward(coord);
// The IR can give us more components than we need, so chop them off as needed.
auto swizzle_expr = swizzle(coord_components, expression_type(coord).vecsize);
// Only enclose the UV expression if needed.
auto coord_expr = (*swizzle_expr == '\0') ? to_expression(coord) : (to_enclosed_expression(coord) + swizzle_expr);
// texelFetch only takes int, not uint.
auto &coord_type = expression_type(coord);
if (coord_type.basetype == SPIRType::UInt)
{
auto expected_type = coord_type;
expected_type.basetype = SPIRType::Int;
coord_expr = bitcast_expression(expected_type, coord_type.basetype, coord_expr);
}
// textureLod on sampler2DArrayShadow and samplerCubeShadow does not exist in GLSL for some reason.
// To emulate this, we will have to use textureGrad with a constant gradient of 0.
// The workaround will assert that the LOD is in fact constant 0, or we cannot emit correct code.
// This happens for HLSL SampleCmpLevelZero on Texture2DArray and TextureCube.
bool workaround_lod_array_shadow_as_grad =
((imgtype.image.arrayed && imgtype.image.dim == Dim2D) || imgtype.image.dim == DimCube) &&
image_is_comparison(imgtype, img) && lod;
if (dref)
{
forward = forward && should_forward(dref);
// SPIR-V splits dref and coordinate.
if (is_gather || coord_components == 4) // GLSL also splits the arguments in two. Same for textureGather.
{
farg_str += ", ";
farg_str += to_expression(coord);
farg_str += ", ";
farg_str += to_expression(dref);
}
else if (is_proj)
{
// Have to reshuffle so we get vec4(coord, dref, proj), special case.
// Other shading languages splits up the arguments for coord and compare value like SPIR-V.
// The coordinate type for textureProj shadow is always vec4 even for sampler1DShadow.
farg_str += ", vec4(";
if (imgtype.image.dim == Dim1D)
{
// Could reuse coord_expr, but we will mess up the temporary usage checking.
farg_str += to_enclosed_expression(coord) + ".x";
farg_str += ", ";
farg_str += "0.0, ";
farg_str += to_expression(dref);
farg_str += ", ";
farg_str += to_enclosed_expression(coord) + ".y)";
}
else if (imgtype.image.dim == Dim2D)
{
// Could reuse coord_expr, but we will mess up the temporary usage checking.
farg_str += to_enclosed_expression(coord) + (swizz_func ? ".xy()" : ".xy");
farg_str += ", ";
farg_str += to_expression(dref);
farg_str += ", ";
farg_str += to_enclosed_expression(coord) + ".z)";
}
else
SPIRV_CROSS_THROW("Invalid type for textureProj with shadow.");
}
else
{
// Create a composite which merges coord/dref into a single vector.
auto type = expression_type(coord);
type.vecsize = coord_components + 1;
farg_str += ", ";
farg_str += type_to_glsl_constructor(type);
farg_str += "(";
farg_str += coord_expr;
farg_str += ", ";
farg_str += to_expression(dref);
farg_str += ")";
}
}
else
{
farg_str += ", ";
farg_str += coord_expr;
}
if (grad_x || grad_y)
{
forward = forward && should_forward(grad_x);
forward = forward && should_forward(grad_y);
farg_str += ", ";
farg_str += to_expression(grad_x);
farg_str += ", ";
farg_str += to_expression(grad_y);
}
if (lod)
{
if (workaround_lod_array_shadow_as_grad)
{
// Implement textureGrad() instead. LOD == 0.0 is implemented as gradient of 0.0.
// Implementing this as plain texture() is not safe on some implementations.
if (imgtype.image.dim == Dim2D)
farg_str += ", vec2(0.0), vec2(0.0)";
else if (imgtype.image.dim == DimCube)
farg_str += ", vec3(0.0), vec3(0.0)";
}
else
{
if (check_explicit_lod_allowed(lod))
{
forward = forward && should_forward(lod);
farg_str += ", ";
farg_str += to_expression(lod);
}
}
}
else if (is_fetch && imgtype.image.dim != DimBuffer && !imgtype.image.ms)
{
// Lod argument is optional in OpImageFetch, but we require a LOD value, pick 0 as the default.
farg_str += ", 0";
}
if (coffset)
{
forward = forward && should_forward(coffset);
farg_str += ", ";
farg_str += to_expression(coffset);
}
else if (offset)
{
forward = forward && should_forward(offset);
farg_str += ", ";
farg_str += to_expression(offset);
}
if (bias)
{
forward = forward && should_forward(bias);
farg_str += ", ";
farg_str += to_expression(bias);
}
if (comp)
{
forward = forward && should_forward(comp);
farg_str += ", ";
farg_str += to_expression(comp);
}
if (sample)
{
farg_str += ", ";
farg_str += to_expression(sample);
}
*p_forward = forward;
return farg_str;
}
void CompilerGLSL::emit_glsl_op(uint32_t result_type, uint32_t id, uint32_t eop, const uint32_t *args, uint32_t length)
{
auto op = static_cast<GLSLstd450>(eop);
if (is_legacy() && is_unsigned_glsl_opcode(op))
SPIRV_CROSS_THROW("Unsigned integers are not supported on legacy GLSL targets.");
// If we need to do implicit bitcasts, make sure we do it with the correct type.
uint32_t integer_width = get_integer_width_for_glsl_instruction(op, args, length);
auto int_type = to_signed_basetype(integer_width);
auto uint_type = to_unsigned_basetype(integer_width);
switch (op)
{
// FP fiddling
case GLSLstd450Round:
emit_unary_func_op(result_type, id, args[0], "round");
break;
case GLSLstd450RoundEven:
if ((options.es && options.version >= 300) || (!options.es && options.version >= 130))
emit_unary_func_op(result_type, id, args[0], "roundEven");
else
SPIRV_CROSS_THROW("roundEven supported only in ESSL 300 and GLSL 130 and up.");
break;
case GLSLstd450Trunc:
emit_unary_func_op(result_type, id, args[0], "trunc");
break;
case GLSLstd450SAbs:
emit_unary_func_op_cast(result_type, id, args[0], "abs", int_type, int_type);
break;
case GLSLstd450FAbs:
emit_unary_func_op(result_type, id, args[0], "abs");
break;
case GLSLstd450SSign:
emit_unary_func_op_cast(result_type, id, args[0], "sign", int_type, int_type);
break;
case GLSLstd450FSign:
emit_unary_func_op(result_type, id, args[0], "sign");
break;
case GLSLstd450Floor:
emit_unary_func_op(result_type, id, args[0], "floor");
break;
case GLSLstd450Ceil:
emit_unary_func_op(result_type, id, args[0], "ceil");
break;
case GLSLstd450Fract:
emit_unary_func_op(result_type, id, args[0], "fract");
break;
case GLSLstd450Radians:
emit_unary_func_op(result_type, id, args[0], "radians");
break;
case GLSLstd450Degrees:
emit_unary_func_op(result_type, id, args[0], "degrees");
break;
case GLSLstd450Fma:
emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "fma");
break;
case GLSLstd450Modf:
register_call_out_argument(args[1]);
forced_temporaries.insert(id);
emit_binary_func_op(result_type, id, args[0], args[1], "modf");
break;
case GLSLstd450ModfStruct:
{
forced_temporaries.insert(id);
auto &type = get<SPIRType>(result_type);
auto &flags = ir.meta[id].decoration.decoration_flags;
statement(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, to_name(id)), ";");
set<SPIRExpression>(id, to_name(id), result_type, true);
statement(to_expression(id), ".", to_member_name(type, 0), " = ", "modf(", to_expression(args[0]), ", ",
to_expression(id), ".", to_member_name(type, 1), ");");
break;
}
// Minmax
case GLSLstd450UMin:
emit_binary_func_op_cast(result_type, id, args[0], args[1], "min", uint_type, false);
break;
case GLSLstd450SMin:
emit_binary_func_op_cast(result_type, id, args[0], args[1], "min", int_type, false);
break;
case GLSLstd450FMin:
emit_binary_func_op(result_type, id, args[0], args[1], "min");
break;
case GLSLstd450FMax:
emit_binary_func_op(result_type, id, args[0], args[1], "max");
break;
case GLSLstd450UMax:
emit_binary_func_op_cast(result_type, id, args[0], args[1], "max", uint_type, false);
break;
case GLSLstd450SMax:
emit_binary_func_op_cast(result_type, id, args[0], args[1], "max", int_type, false);
break;
case GLSLstd450FClamp:
emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "clamp");
break;
case GLSLstd450UClamp:
emit_trinary_func_op_cast(result_type, id, args[0], args[1], args[2], "clamp", uint_type);
break;
case GLSLstd450SClamp:
emit_trinary_func_op_cast(result_type, id, args[0], args[1], args[2], "clamp", int_type);
break;
// Trig
case GLSLstd450Sin:
emit_unary_func_op(result_type, id, args[0], "sin");
break;
case GLSLstd450Cos:
emit_unary_func_op(result_type, id, args[0], "cos");
break;
case GLSLstd450Tan:
emit_unary_func_op(result_type, id, args[0], "tan");
break;
case GLSLstd450Asin:
emit_unary_func_op(result_type, id, args[0], "asin");
break;
case GLSLstd450Acos:
emit_unary_func_op(result_type, id, args[0], "acos");
break;
case GLSLstd450Atan:
emit_unary_func_op(result_type, id, args[0], "atan");
break;
case GLSLstd450Sinh:
emit_unary_func_op(result_type, id, args[0], "sinh");
break;
case GLSLstd450Cosh:
emit_unary_func_op(result_type, id, args[0], "cosh");
break;
case GLSLstd450Tanh:
emit_unary_func_op(result_type, id, args[0], "tanh");
break;
case GLSLstd450Asinh:
emit_unary_func_op(result_type, id, args[0], "asinh");
break;
case GLSLstd450Acosh:
emit_unary_func_op(result_type, id, args[0], "acosh");
break;
case GLSLstd450Atanh:
emit_unary_func_op(result_type, id, args[0], "atanh");
break;
case GLSLstd450Atan2:
emit_binary_func_op(result_type, id, args[0], args[1], "atan");
break;
// Exponentials
case GLSLstd450Pow:
emit_binary_func_op(result_type, id, args[0], args[1], "pow");
break;
case GLSLstd450Exp:
emit_unary_func_op(result_type, id, args[0], "exp");
break;
case GLSLstd450Log:
emit_unary_func_op(result_type, id, args[0], "log");
break;
case GLSLstd450Exp2:
emit_unary_func_op(result_type, id, args[0], "exp2");
break;
case GLSLstd450Log2:
emit_unary_func_op(result_type, id, args[0], "log2");
break;
case GLSLstd450Sqrt:
emit_unary_func_op(result_type, id, args[0], "sqrt");
break;
case GLSLstd450InverseSqrt:
emit_unary_func_op(result_type, id, args[0], "inversesqrt");
break;
// Matrix math
case GLSLstd450Determinant:
emit_unary_func_op(result_type, id, args[0], "determinant");
break;
case GLSLstd450MatrixInverse:
emit_unary_func_op(result_type, id, args[0], "inverse");
break;
// Lerping
case GLSLstd450FMix:
case GLSLstd450IMix:
{
emit_mix_op(result_type, id, args[0], args[1], args[2]);
break;
}
case GLSLstd450Step:
emit_binary_func_op(result_type, id, args[0], args[1], "step");
break;
case GLSLstd450SmoothStep:
emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "smoothstep");
break;
// Packing
case GLSLstd450Frexp:
register_call_out_argument(args[1]);
forced_temporaries.insert(id);
emit_binary_func_op(result_type, id, args[0], args[1], "frexp");
break;
case GLSLstd450FrexpStruct:
{
forced_temporaries.insert(id);
auto &type = get<SPIRType>(result_type);
auto &flags = ir.meta[id].decoration.decoration_flags;
statement(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, to_name(id)), ";");
set<SPIRExpression>(id, to_name(id), result_type, true);
statement(to_expression(id), ".", to_member_name(type, 0), " = ", "frexp(", to_expression(args[0]), ", ",
to_expression(id), ".", to_member_name(type, 1), ");");
break;
}
case GLSLstd450Ldexp:
emit_binary_func_op(result_type, id, args[0], args[1], "ldexp");
break;
case GLSLstd450PackSnorm4x8:
emit_unary_func_op(result_type, id, args[0], "packSnorm4x8");
break;
case GLSLstd450PackUnorm4x8:
emit_unary_func_op(result_type, id, args[0], "packUnorm4x8");
break;
case GLSLstd450PackSnorm2x16:
emit_unary_func_op(result_type, id, args[0], "packSnorm2x16");
break;
case GLSLstd450PackUnorm2x16:
emit_unary_func_op(result_type, id, args[0], "packUnorm2x16");
break;
case GLSLstd450PackHalf2x16:
emit_unary_func_op(result_type, id, args[0], "packHalf2x16");
break;
case GLSLstd450UnpackSnorm4x8:
emit_unary_func_op(result_type, id, args[0], "unpackSnorm4x8");
break;
case GLSLstd450UnpackUnorm4x8:
emit_unary_func_op(result_type, id, args[0], "unpackUnorm4x8");
break;
case GLSLstd450UnpackSnorm2x16:
emit_unary_func_op(result_type, id, args[0], "unpackSnorm2x16");
break;
case GLSLstd450UnpackUnorm2x16:
emit_unary_func_op(result_type, id, args[0], "unpackUnorm2x16");
break;
case GLSLstd450UnpackHalf2x16:
emit_unary_func_op(result_type, id, args[0], "unpackHalf2x16");
break;
case GLSLstd450PackDouble2x32:
emit_unary_func_op(result_type, id, args[0], "packDouble2x32");
break;
case GLSLstd450UnpackDouble2x32:
emit_unary_func_op(result_type, id, args[0], "unpackDouble2x32");
break;
// Vector math
case GLSLstd450Length:
emit_unary_func_op(result_type, id, args[0], "length");
break;
case GLSLstd450Distance:
emit_binary_func_op(result_type, id, args[0], args[1], "distance");
break;
case GLSLstd450Cross:
emit_binary_func_op(result_type, id, args[0], args[1], "cross");
break;
case GLSLstd450Normalize:
emit_unary_func_op(result_type, id, args[0], "normalize");
break;
case GLSLstd450FaceForward:
emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "faceforward");
break;
case GLSLstd450Reflect:
emit_binary_func_op(result_type, id, args[0], args[1], "reflect");
break;
case GLSLstd450Refract:
emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "refract");
break;
// Bit-fiddling
case GLSLstd450FindILsb:
emit_unary_func_op(result_type, id, args[0], "findLSB");
break;
case GLSLstd450FindSMsb:
emit_unary_func_op_cast(result_type, id, args[0], "findMSB", int_type, int_type);
break;
case GLSLstd450FindUMsb:
emit_unary_func_op_cast(result_type, id, args[0], "findMSB", uint_type, int_type); // findMSB always returns int.
break;
// Multisampled varying
case GLSLstd450InterpolateAtCentroid:
emit_unary_func_op(result_type, id, args[0], "interpolateAtCentroid");
break;
case GLSLstd450InterpolateAtSample:
emit_binary_func_op(result_type, id, args[0], args[1], "interpolateAtSample");
break;
case GLSLstd450InterpolateAtOffset:
emit_binary_func_op(result_type, id, args[0], args[1], "interpolateAtOffset");
break;
case GLSLstd450NMin:
case GLSLstd450NMax:
{
emit_nminmax_op(result_type, id, args[0], args[1], op);
break;
}
case GLSLstd450NClamp:
{
// Make sure we have a unique ID here to avoid aliasing the extra sub-expressions between clamp and NMin sub-op.
// IDs cannot exceed 24 bits, so we can make use of the higher bits for some unique flags.
uint32_t &max_id = extra_sub_expressions[id | 0x80000000u];
if (!max_id)
max_id = ir.increase_bound_by(1);
// Inherit precision qualifiers.
ir.meta[max_id] = ir.meta[id];
emit_nminmax_op(result_type, max_id, args[0], args[1], GLSLstd450NMax);
emit_nminmax_op(result_type, id, max_id, args[2], GLSLstd450NMin);
break;
}
default:
statement("// unimplemented GLSL op ", eop);
break;
}
}
void CompilerGLSL::emit_nminmax_op(uint32_t result_type, uint32_t id, uint32_t op0, uint32_t op1, GLSLstd450 op)
{
// Need to emulate this call.
uint32_t &ids = extra_sub_expressions[id];
if (!ids)
{
ids = ir.increase_bound_by(5);
auto btype = get<SPIRType>(result_type);
btype.basetype = SPIRType::Boolean;
set<SPIRType>(ids, btype);
}
uint32_t btype_id = ids + 0;
uint32_t left_nan_id = ids + 1;
uint32_t right_nan_id = ids + 2;
uint32_t tmp_id = ids + 3;
uint32_t mixed_first_id = ids + 4;
// Inherit precision qualifiers.
ir.meta[tmp_id] = ir.meta[id];
ir.meta[mixed_first_id] = ir.meta[id];
emit_unary_func_op(btype_id, left_nan_id, op0, "isnan");
emit_unary_func_op(btype_id, right_nan_id, op1, "isnan");
emit_binary_func_op(result_type, tmp_id, op0, op1, op == GLSLstd450NMin ? "min" : "max");
emit_mix_op(result_type, mixed_first_id, tmp_id, op1, left_nan_id);
emit_mix_op(result_type, id, mixed_first_id, op0, right_nan_id);
}
void CompilerGLSL::emit_spv_amd_shader_ballot_op(uint32_t result_type, uint32_t id, uint32_t eop, const uint32_t *args,
uint32_t)
{
require_extension_internal("GL_AMD_shader_ballot");
enum AMDShaderBallot
{
SwizzleInvocationsAMD = 1,
SwizzleInvocationsMaskedAMD = 2,
WriteInvocationAMD = 3,
MbcntAMD = 4
};
auto op = static_cast<AMDShaderBallot>(eop);
switch (op)
{
case SwizzleInvocationsAMD:
emit_binary_func_op(result_type, id, args[0], args[1], "swizzleInvocationsAMD");
register_control_dependent_expression(id);
break;
case SwizzleInvocationsMaskedAMD:
emit_binary_func_op(result_type, id, args[0], args[1], "swizzleInvocationsMaskedAMD");
register_control_dependent_expression(id);
break;
case WriteInvocationAMD:
emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "writeInvocationAMD");
register_control_dependent_expression(id);
break;
case MbcntAMD:
emit_unary_func_op(result_type, id, args[0], "mbcntAMD");
register_control_dependent_expression(id);
break;
default:
statement("// unimplemented SPV AMD shader ballot op ", eop);
break;
}
}
void CompilerGLSL::emit_spv_amd_shader_explicit_vertex_parameter_op(uint32_t result_type, uint32_t id, uint32_t eop,
const uint32_t *args, uint32_t)
{
require_extension_internal("GL_AMD_shader_explicit_vertex_parameter");
enum AMDShaderExplicitVertexParameter
{
InterpolateAtVertexAMD = 1
};
auto op = static_cast<AMDShaderExplicitVertexParameter>(eop);
switch (op)
{
case InterpolateAtVertexAMD:
emit_binary_func_op(result_type, id, args[0], args[1], "interpolateAtVertexAMD");
break;
default:
statement("// unimplemented SPV AMD shader explicit vertex parameter op ", eop);
break;
}
}
void CompilerGLSL::emit_spv_amd_shader_trinary_minmax_op(uint32_t result_type, uint32_t id, uint32_t eop,
const uint32_t *args, uint32_t)
{
require_extension_internal("GL_AMD_shader_trinary_minmax");
enum AMDShaderTrinaryMinMax
{
FMin3AMD = 1,
UMin3AMD = 2,
SMin3AMD = 3,
FMax3AMD = 4,
UMax3AMD = 5,
SMax3AMD = 6,
FMid3AMD = 7,
UMid3AMD = 8,
SMid3AMD = 9
};
auto op = static_cast<AMDShaderTrinaryMinMax>(eop);
switch (op)
{
case FMin3AMD:
case UMin3AMD:
case SMin3AMD:
emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "min3");
break;
case FMax3AMD:
case UMax3AMD:
case SMax3AMD:
emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "max3");
break;
case FMid3AMD:
case UMid3AMD:
case SMid3AMD:
emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "mid3");
break;
default:
statement("// unimplemented SPV AMD shader trinary minmax op ", eop);
break;
}
}
void CompilerGLSL::emit_spv_amd_gcn_shader_op(uint32_t result_type, uint32_t id, uint32_t eop, const uint32_t *args,
uint32_t)
{
require_extension_internal("GL_AMD_gcn_shader");
enum AMDGCNShader
{
CubeFaceIndexAMD = 1,
CubeFaceCoordAMD = 2,
TimeAMD = 3
};
auto op = static_cast<AMDGCNShader>(eop);
switch (op)
{
case CubeFaceIndexAMD:
emit_unary_func_op(result_type, id, args[0], "cubeFaceIndexAMD");
break;
case CubeFaceCoordAMD:
emit_unary_func_op(result_type, id, args[0], "cubeFaceCoordAMD");
break;
case TimeAMD:
{
string expr = "timeAMD()";
emit_op(result_type, id, expr, true);
register_control_dependent_expression(id);
break;
}
default:
statement("// unimplemented SPV AMD gcn shader op ", eop);
break;
}
}
void CompilerGLSL::emit_subgroup_op(const Instruction &i)
{
const uint32_t *ops = stream(i);
auto op = static_cast<Op>(i.op);
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Can only use subgroup operations in Vulkan semantics.");
switch (op)
{
case OpGroupNonUniformElect:
require_extension_internal("GL_KHR_shader_subgroup_basic");
break;
case OpGroupNonUniformBroadcast:
case OpGroupNonUniformBroadcastFirst:
case OpGroupNonUniformBallot:
case OpGroupNonUniformInverseBallot:
case OpGroupNonUniformBallotBitExtract:
case OpGroupNonUniformBallotBitCount:
case OpGroupNonUniformBallotFindLSB:
case OpGroupNonUniformBallotFindMSB:
require_extension_internal("GL_KHR_shader_subgroup_ballot");
break;
case OpGroupNonUniformShuffle:
case OpGroupNonUniformShuffleXor:
require_extension_internal("GL_KHR_shader_subgroup_shuffle");
break;
case OpGroupNonUniformShuffleUp:
case OpGroupNonUniformShuffleDown:
require_extension_internal("GL_KHR_shader_subgroup_shuffle_relative");
break;
case OpGroupNonUniformAll:
case OpGroupNonUniformAny:
case OpGroupNonUniformAllEqual:
require_extension_internal("GL_KHR_shader_subgroup_vote");
break;
case OpGroupNonUniformFAdd:
case OpGroupNonUniformFMul:
case OpGroupNonUniformFMin:
case OpGroupNonUniformFMax:
case OpGroupNonUniformIAdd:
case OpGroupNonUniformIMul:
case OpGroupNonUniformSMin:
case OpGroupNonUniformSMax:
case OpGroupNonUniformUMin:
case OpGroupNonUniformUMax:
case OpGroupNonUniformBitwiseAnd:
case OpGroupNonUniformBitwiseOr:
case OpGroupNonUniformBitwiseXor:
{
auto operation = static_cast<GroupOperation>(ops[3]);
if (operation == GroupOperationClusteredReduce)
{
require_extension_internal("GL_KHR_shader_subgroup_clustered");
}
else if (operation == GroupOperationExclusiveScan || operation == GroupOperationInclusiveScan ||
operation == GroupOperationReduce)
{
require_extension_internal("GL_KHR_shader_subgroup_arithmetic");
}
else
SPIRV_CROSS_THROW("Invalid group operation.");
break;
}
case OpGroupNonUniformQuadSwap:
case OpGroupNonUniformQuadBroadcast:
require_extension_internal("GL_KHR_shader_subgroup_quad");
break;
default:
SPIRV_CROSS_THROW("Invalid opcode for subgroup.");
}
uint32_t result_type = ops[0];
uint32_t id = ops[1];
auto scope = static_cast<Scope>(get<SPIRConstant>(ops[2]).scalar());
if (scope != ScopeSubgroup)
SPIRV_CROSS_THROW("Only subgroup scope is supported.");
switch (op)
{
case OpGroupNonUniformElect:
emit_op(result_type, id, "subgroupElect()", true);
break;
case OpGroupNonUniformBroadcast:
emit_binary_func_op(result_type, id, ops[3], ops[4], "subgroupBroadcast");
break;
case OpGroupNonUniformBroadcastFirst:
emit_unary_func_op(result_type, id, ops[3], "subgroupBroadcastFirst");
break;
case OpGroupNonUniformBallot:
emit_unary_func_op(result_type, id, ops[3], "subgroupBallot");
break;
case OpGroupNonUniformInverseBallot:
emit_unary_func_op(result_type, id, ops[3], "subgroupInverseBallot");
break;
case OpGroupNonUniformBallotBitExtract:
emit_binary_func_op(result_type, id, ops[3], ops[4], "subgroupBallotBitExtract");
break;
case OpGroupNonUniformBallotFindLSB:
emit_unary_func_op(result_type, id, ops[3], "subgroupBallotFindLSB");
break;
case OpGroupNonUniformBallotFindMSB:
emit_unary_func_op(result_type, id, ops[3], "subgroupBallotFindMSB");
break;
case OpGroupNonUniformBallotBitCount:
{
auto operation = static_cast<GroupOperation>(ops[3]);
if (operation == GroupOperationReduce)
emit_unary_func_op(result_type, id, ops[4], "subgroupBallotBitCount");
else if (operation == GroupOperationInclusiveScan)
emit_unary_func_op(result_type, id, ops[4], "subgroupBallotInclusiveBitCount");
else if (operation == GroupOperationExclusiveScan)
emit_unary_func_op(result_type, id, ops[4], "subgroupBallotExclusiveBitCount");
else
SPIRV_CROSS_THROW("Invalid BitCount operation.");
break;
}
case OpGroupNonUniformShuffle:
emit_binary_func_op(result_type, id, ops[3], ops[4], "subgroupShuffle");
break;
case OpGroupNonUniformShuffleXor:
emit_binary_func_op(result_type, id, ops[3], ops[4], "subgroupShuffleXor");
break;
case OpGroupNonUniformShuffleUp:
emit_binary_func_op(result_type, id, ops[3], ops[4], "subgroupShuffleUp");
break;
case OpGroupNonUniformShuffleDown:
emit_binary_func_op(result_type, id, ops[3], ops[4], "subgroupShuffleDown");
break;
case OpGroupNonUniformAll:
emit_unary_func_op(result_type, id, ops[3], "subgroupAll");
break;
case OpGroupNonUniformAny:
emit_unary_func_op(result_type, id, ops[3], "subgroupAny");
break;
case OpGroupNonUniformAllEqual:
emit_unary_func_op(result_type, id, ops[3], "subgroupAllEqual");
break;
// clang-format off
#define GLSL_GROUP_OP(op, glsl_op) \
case OpGroupNonUniform##op: \
{ \
auto operation = static_cast<GroupOperation>(ops[3]); \
if (operation == GroupOperationReduce) \
emit_unary_func_op(result_type, id, ops[4], "subgroup" #glsl_op); \
else if (operation == GroupOperationInclusiveScan) \
emit_unary_func_op(result_type, id, ops[4], "subgroupInclusive" #glsl_op); \
else if (operation == GroupOperationExclusiveScan) \
emit_unary_func_op(result_type, id, ops[4], "subgroupExclusive" #glsl_op); \
else if (operation == GroupOperationClusteredReduce) \
emit_binary_func_op(result_type, id, ops[4], ops[5], "subgroupClustered" #glsl_op); \
else \
SPIRV_CROSS_THROW("Invalid group operation."); \
break; \
}
GLSL_GROUP_OP(FAdd, Add)
GLSL_GROUP_OP(FMul, Mul)
GLSL_GROUP_OP(FMin, Min)
GLSL_GROUP_OP(FMax, Max)
GLSL_GROUP_OP(IAdd, Add)
GLSL_GROUP_OP(IMul, Mul)
GLSL_GROUP_OP(SMin, Min)
GLSL_GROUP_OP(SMax, Max)
GLSL_GROUP_OP(UMin, Min)
GLSL_GROUP_OP(UMax, Max)
GLSL_GROUP_OP(BitwiseAnd, And)
GLSL_GROUP_OP(BitwiseOr, Or)
GLSL_GROUP_OP(BitwiseXor, Xor)
#undef GLSL_GROUP_OP
// clang-format on
case OpGroupNonUniformQuadSwap:
{
uint32_t direction = get<SPIRConstant>(ops[4]).scalar();
if (direction == 0)
emit_unary_func_op(result_type, id, ops[3], "subgroupQuadSwapHorizontal");
else if (direction == 1)
emit_unary_func_op(result_type, id, ops[3], "subgroupQuadSwapVertical");
else if (direction == 2)
emit_unary_func_op(result_type, id, ops[3], "subgroupQuadSwapDiagonal");
else
SPIRV_CROSS_THROW("Invalid quad swap direction.");
break;
}
case OpGroupNonUniformQuadBroadcast:
{
emit_binary_func_op(result_type, id, ops[3], ops[4], "subgroupQuadBroadcast");
break;
}
default:
SPIRV_CROSS_THROW("Invalid opcode for subgroup.");
}
register_control_dependent_expression(id);
}
string CompilerGLSL::bitcast_glsl_op(const SPIRType &out_type, const SPIRType &in_type)
{
if (out_type.basetype == in_type.basetype)
return "";
assert(out_type.basetype != SPIRType::Boolean);
assert(in_type.basetype != SPIRType::Boolean);
bool integral_cast = type_is_integral(out_type) && type_is_integral(in_type);
bool same_size_cast = out_type.width == in_type.width;
// Trivial bitcast case, casts between integers.
if (integral_cast && same_size_cast)
return type_to_glsl(out_type);
// Catch-all 8-bit arithmetic casts (GL_EXT_shader_explicit_arithmetic_types).
if (out_type.width == 8 && in_type.width >= 16 && integral_cast && in_type.vecsize == 1)
return "unpack8";
else if (in_type.width == 8 && out_type.width == 16 && integral_cast && out_type.vecsize == 1)
return "pack16";
else if (in_type.width == 8 && out_type.width == 32 && integral_cast && out_type.vecsize == 1)
return "pack32";
// Floating <-> Integer special casts. Just have to enumerate all cases. :(
// 16-bit, 32-bit and 64-bit floats.
if (out_type.basetype == SPIRType::UInt && in_type.basetype == SPIRType::Float)
return "floatBitsToUint";
else if (out_type.basetype == SPIRType::Int && in_type.basetype == SPIRType::Float)
return "floatBitsToInt";
else if (out_type.basetype == SPIRType::Float && in_type.basetype == SPIRType::UInt)
return "uintBitsToFloat";
else if (out_type.basetype == SPIRType::Float && in_type.basetype == SPIRType::Int)
return "intBitsToFloat";
else if (out_type.basetype == SPIRType::Int64 && in_type.basetype == SPIRType::Double)
return "doubleBitsToInt64";
else if (out_type.basetype == SPIRType::UInt64 && in_type.basetype == SPIRType::Double)
return "doubleBitsToUint64";
else if (out_type.basetype == SPIRType::Double && in_type.basetype == SPIRType::Int64)
return "int64BitsToDouble";
else if (out_type.basetype == SPIRType::Double && in_type.basetype == SPIRType::UInt64)
return "uint64BitsToDouble";
else if (out_type.basetype == SPIRType::Short && in_type.basetype == SPIRType::Half)
return "float16BitsToInt16";
else if (out_type.basetype == SPIRType::UShort && in_type.basetype == SPIRType::Half)
return "float16BitsToUint16";
else if (out_type.basetype == SPIRType::Half && in_type.basetype == SPIRType::Short)
return "int16BitsToFloat16";
else if (out_type.basetype == SPIRType::Half && in_type.basetype == SPIRType::UShort)
return "uint16BitsToFloat16";
// And finally, some even more special purpose casts.
if (out_type.basetype == SPIRType::UInt64 && in_type.basetype == SPIRType::UInt && in_type.vecsize == 2)
return "packUint2x32";
else if (out_type.basetype == SPIRType::Half && in_type.basetype == SPIRType::UInt && in_type.vecsize == 1)
return "unpackFloat2x16";
else if (out_type.basetype == SPIRType::UInt && in_type.basetype == SPIRType::Half && in_type.vecsize == 2)
return "packFloat2x16";
else if (out_type.basetype == SPIRType::Int && in_type.basetype == SPIRType::Short && in_type.vecsize == 2)
return "packInt2x16";
else if (out_type.basetype == SPIRType::Short && in_type.basetype == SPIRType::Int && in_type.vecsize == 1)
return "unpackInt2x16";
else if (out_type.basetype == SPIRType::UInt && in_type.basetype == SPIRType::UShort && in_type.vecsize == 2)
return "packUint2x16";
else if (out_type.basetype == SPIRType::UShort && in_type.basetype == SPIRType::UInt && in_type.vecsize == 1)
return "unpackUint2x16";
else if (out_type.basetype == SPIRType::Int64 && in_type.basetype == SPIRType::Short && in_type.vecsize == 4)
return "packInt4x16";
else if (out_type.basetype == SPIRType::Short && in_type.basetype == SPIRType::Int64 && in_type.vecsize == 1)
return "unpackInt4x16";
else if (out_type.basetype == SPIRType::UInt64 && in_type.basetype == SPIRType::UShort && in_type.vecsize == 4)
return "packUint4x16";
else if (out_type.basetype == SPIRType::UShort && in_type.basetype == SPIRType::UInt64 && in_type.vecsize == 1)
return "unpackUint4x16";
return "";
}
string CompilerGLSL::bitcast_glsl(const SPIRType &result_type, uint32_t argument)
{
auto op = bitcast_glsl_op(result_type, expression_type(argument));
if (op.empty())
return to_enclosed_expression(argument);
else
return join(op, "(", to_expression(argument), ")");
}
std::string CompilerGLSL::bitcast_expression(SPIRType::BaseType target_type, uint32_t arg)
{
auto expr = to_expression(arg);
auto &src_type = expression_type(arg);
if (src_type.basetype != target_type)
{
auto target = src_type;
target.basetype = target_type;
expr = join(bitcast_glsl_op(target, src_type), "(", expr, ")");
}
return expr;
}
std::string CompilerGLSL::bitcast_expression(const SPIRType &target_type, SPIRType::BaseType expr_type,
const std::string &expr)
{
if (target_type.basetype == expr_type)
return expr;
auto src_type = target_type;
src_type.basetype = expr_type;
return join(bitcast_glsl_op(target_type, src_type), "(", expr, ")");
}
string CompilerGLSL::builtin_to_glsl(BuiltIn builtin, StorageClass storage)
{
switch (builtin)
{
case BuiltInPosition:
return "gl_Position";
case BuiltInPointSize:
return "gl_PointSize";
case BuiltInClipDistance:
return "gl_ClipDistance";
case BuiltInCullDistance:
return "gl_CullDistance";
case BuiltInVertexId:
if (options.vulkan_semantics)
SPIRV_CROSS_THROW(
"Cannot implement gl_VertexID in Vulkan GLSL. This shader was created with GL semantics.");
return "gl_VertexID";
case BuiltInInstanceId:
if (options.vulkan_semantics)
SPIRV_CROSS_THROW(
"Cannot implement gl_InstanceID in Vulkan GLSL. This shader was created with GL semantics.");
return "gl_InstanceID";
case BuiltInVertexIndex:
if (options.vulkan_semantics)
return "gl_VertexIndex";
else
return "gl_VertexID"; // gl_VertexID already has the base offset applied.
case BuiltInInstanceIndex:
if (options.vulkan_semantics)
return "gl_InstanceIndex";
else if (options.vertex.support_nonzero_base_instance)
return "(gl_InstanceID + SPIRV_Cross_BaseInstance)"; // ... but not gl_InstanceID.
else
return "gl_InstanceID";
case BuiltInPrimitiveId:
if (storage == StorageClassInput && get_entry_point().model == ExecutionModelGeometry)
return "gl_PrimitiveIDIn";
else
return "gl_PrimitiveID";
case BuiltInInvocationId:
return "gl_InvocationID";
case BuiltInLayer:
return "gl_Layer";
case BuiltInViewportIndex:
return "gl_ViewportIndex";
case BuiltInTessLevelOuter:
return "gl_TessLevelOuter";
case BuiltInTessLevelInner:
return "gl_TessLevelInner";
case BuiltInTessCoord:
return "gl_TessCoord";
case BuiltInFragCoord:
return "gl_FragCoord";
case BuiltInPointCoord:
return "gl_PointCoord";
case BuiltInFrontFacing:
return "gl_FrontFacing";
case BuiltInFragDepth:
return "gl_FragDepth";
case BuiltInNumWorkgroups:
return "gl_NumWorkGroups";
case BuiltInWorkgroupSize:
return "gl_WorkGroupSize";
case BuiltInWorkgroupId:
return "gl_WorkGroupID";
case BuiltInLocalInvocationId:
return "gl_LocalInvocationID";
case BuiltInGlobalInvocationId:
return "gl_GlobalInvocationID";
case BuiltInLocalInvocationIndex:
return "gl_LocalInvocationIndex";
case BuiltInHelperInvocation:
return "gl_HelperInvocation";
case BuiltInBaseVertex:
if (options.es)
SPIRV_CROSS_THROW("BaseVertex not supported in ES profile.");
if (options.version < 460)
{
require_extension_internal("GL_ARB_shader_draw_parameters");
return "gl_BaseVertexARB";
}
return "gl_BaseVertex";
case BuiltInBaseInstance:
if (options.es)
SPIRV_CROSS_THROW("BaseInstance not supported in ES profile.");
if (options.version < 460)
{
require_extension_internal("GL_ARB_shader_draw_parameters");
return "gl_BaseInstanceARB";
}
return "gl_BaseInstance";
case BuiltInDrawIndex:
if (options.es)
SPIRV_CROSS_THROW("DrawIndex not supported in ES profile.");
if (options.version < 460)
{
require_extension_internal("GL_ARB_shader_draw_parameters");
return "gl_DrawIDARB";
}
return "gl_DrawID";
case BuiltInSampleId:
if (options.es && options.version < 320)
require_extension_internal("GL_OES_sample_variables");
if (!options.es && options.version < 400)
SPIRV_CROSS_THROW("gl_SampleID not supported before GLSL 400.");
return "gl_SampleID";
case BuiltInSampleMask:
if (options.es && options.version < 320)
require_extension_internal("GL_OES_sample_variables");
if (!options.es && options.version < 400)
SPIRV_CROSS_THROW("gl_SampleMask/gl_SampleMaskIn not supported before GLSL 400.");
if (storage == StorageClassInput)
return "gl_SampleMaskIn";
else
return "gl_SampleMask";
case BuiltInSamplePosition:
if (options.es && options.version < 320)
require_extension_internal("GL_OES_sample_variables");
if (!options.es && options.version < 400)
SPIRV_CROSS_THROW("gl_SamplePosition not supported before GLSL 400.");
return "gl_SamplePosition";
case BuiltInViewIndex:
if (options.vulkan_semantics)
{
require_extension_internal("GL_EXT_multiview");
return "gl_ViewIndex";
}
else
{
require_extension_internal("GL_OVR_multiview2");
return "gl_ViewID_OVR";
}
case BuiltInNumSubgroups:
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Need Vulkan semantics for subgroup.");
require_extension_internal("GL_KHR_shader_subgroup_basic");
return "gl_NumSubgroups";
case BuiltInSubgroupId:
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Need Vulkan semantics for subgroup.");
require_extension_internal("GL_KHR_shader_subgroup_basic");
return "gl_SubgroupID";
case BuiltInSubgroupSize:
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Need Vulkan semantics for subgroup.");
require_extension_internal("GL_KHR_shader_subgroup_basic");
return "gl_SubgroupSize";
case BuiltInSubgroupLocalInvocationId:
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Need Vulkan semantics for subgroup.");
require_extension_internal("GL_KHR_shader_subgroup_basic");
return "gl_SubgroupInvocationID";
case BuiltInSubgroupEqMask:
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Need Vulkan semantics for subgroup.");
require_extension_internal("GL_KHR_shader_subgroup_ballot");
return "gl_SubgroupEqMask";
case BuiltInSubgroupGeMask:
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Need Vulkan semantics for subgroup.");
require_extension_internal("GL_KHR_shader_subgroup_ballot");
return "gl_SubgroupGeMask";
case BuiltInSubgroupGtMask:
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Need Vulkan semantics for subgroup.");
require_extension_internal("GL_KHR_shader_subgroup_ballot");
return "gl_SubgroupGtMask";
case BuiltInSubgroupLeMask:
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Need Vulkan semantics for subgroup.");
require_extension_internal("GL_KHR_shader_subgroup_ballot");
return "gl_SubgroupLeMask";
case BuiltInSubgroupLtMask:
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Need Vulkan semantics for subgroup.");
require_extension_internal("GL_KHR_shader_subgroup_ballot");
return "gl_SubgroupLtMask";
case BuiltInLaunchIdNV:
return "gl_LaunchIDNV";
case BuiltInLaunchSizeNV:
return "gl_LaunchSizeNV";
case BuiltInWorldRayOriginNV:
return "gl_WorldRayOriginNV";
case BuiltInWorldRayDirectionNV:
return "gl_WorldRayDirectionNV";
case BuiltInObjectRayOriginNV:
return "gl_ObjectRayOriginNV";
case BuiltInObjectRayDirectionNV:
return "gl_ObjectRayDirectionNV";
case BuiltInRayTminNV:
return "gl_RayTminNV";
case BuiltInRayTmaxNV:
return "gl_RayTmaxNV";
case BuiltInInstanceCustomIndexNV:
return "gl_InstanceCustomIndexNV";
case BuiltInObjectToWorldNV:
return "gl_ObjectToWorldNV";
case BuiltInWorldToObjectNV:
return "gl_WorldToObjectNV";
case BuiltInHitTNV:
return "gl_HitTNV";
case BuiltInHitKindNV:
return "gl_HitKindNV";
case BuiltInIncomingRayFlagsNV:
return "gl_IncomingRayFlagsNV";
default:
return join("gl_BuiltIn_", convert_to_string(builtin));
}
}
const char *CompilerGLSL::index_to_swizzle(uint32_t index)
{
switch (index)
{
case 0:
return "x";
case 1:
return "y";
case 2:
return "z";
case 3:
return "w";
default:
SPIRV_CROSS_THROW("Swizzle index out of range");
}
}
string CompilerGLSL::access_chain_internal(uint32_t base, const uint32_t *indices, uint32_t count,
AccessChainFlags flags, AccessChainMeta *meta)
{
string expr;
bool index_is_literal = (flags & ACCESS_CHAIN_INDEX_IS_LITERAL_BIT) != 0;
bool chain_only = (flags & ACCESS_CHAIN_CHAIN_ONLY_BIT) != 0;
bool ptr_chain = (flags & ACCESS_CHAIN_PTR_CHAIN_BIT) != 0;
bool register_expression_read = (flags & ACCESS_CHAIN_SKIP_REGISTER_EXPRESSION_READ_BIT) == 0;
if (!chain_only)
expr = to_enclosed_expression(base, register_expression_read);
// Start traversing type hierarchy at the proper non-pointer types,
// but keep type_id referencing the original pointer for use below.
uint32_t type_id = expression_type_id(base);
const auto *type = &get_pointee_type(type_id);
bool access_chain_is_arrayed = expr.find_first_of('[') != string::npos;
bool row_major_matrix_needs_conversion = is_non_native_row_major_matrix(base);
bool is_packed = has_extended_decoration(base, SPIRVCrossDecorationPacked);
uint32_t packed_type = get_extended_decoration(base, SPIRVCrossDecorationPackedType);
bool is_invariant = has_decoration(base, DecorationInvariant);
bool pending_array_enclose = false;
bool dimension_flatten = false;
for (uint32_t i = 0; i < count; i++)
{
uint32_t index = indices[i];
const auto append_index = [&]() {
expr += "[";
if (index_is_literal)
expr += convert_to_string(index);
else
expr += to_expression(index, register_expression_read);
expr += "]";
};
// Pointer chains
if (ptr_chain && i == 0)
{
// If we are flattening multidimensional arrays, only create opening bracket on first
// array index.
if (options.flatten_multidimensional_arrays)
{
dimension_flatten = type->array.size() >= 1;
pending_array_enclose = dimension_flatten;
if (pending_array_enclose)
expr += "[";
}
if (options.flatten_multidimensional_arrays && dimension_flatten)
{
// If we are flattening multidimensional arrays, do manual stride computation.
if (index_is_literal)
expr += convert_to_string(index);
else
expr += to_enclosed_expression(index, register_expression_read);
for (auto j = uint32_t(type->array.size()); j; j--)
{
expr += " * ";
expr += enclose_expression(to_array_size(*type, j - 1));
}
if (type->array.empty())
pending_array_enclose = false;
else
expr += " + ";
if (!pending_array_enclose)
expr += "]";
}
else
{
append_index();
}
if (type->basetype == SPIRType::ControlPointArray)
{
type_id = type->parent_type;
type = &get<SPIRType>(type_id);
}
access_chain_is_arrayed = true;
}
// Arrays
else if (!type->array.empty())
{
// If we are flattening multidimensional arrays, only create opening bracket on first
// array index.
if (options.flatten_multidimensional_arrays && !pending_array_enclose)
{
dimension_flatten = type->array.size() > 1;
pending_array_enclose = dimension_flatten;
if (pending_array_enclose)
expr += "[";
}
assert(type->parent_type);
auto *var = maybe_get<SPIRVariable>(base);
if (backend.force_gl_in_out_block && i == 0 && var && is_builtin_variable(*var) &&
!has_decoration(type->self, DecorationBlock))
{
// This deals with scenarios for tesc/geom where arrays of gl_Position[] are declared.
// Normally, these variables live in blocks when compiled from GLSL,
// but HLSL seems to just emit straight arrays here.
// We must pretend this access goes through gl_in/gl_out arrays
// to be able to access certain builtins as arrays.
auto builtin = ir.meta[base].decoration.builtin_type;
switch (builtin)
{
// case BuiltInCullDistance: // These are already arrays, need to figure out rules for these in tess/geom.
// case BuiltInClipDistance:
case BuiltInPosition:
case BuiltInPointSize:
if (var->storage == StorageClassInput)
expr = join("gl_in[", to_expression(index, register_expression_read), "].", expr);
else if (var->storage == StorageClassOutput)
expr = join("gl_out[", to_expression(index, register_expression_read), "].", expr);
else
append_index();
break;
default:
append_index();
break;
}
}
else if (options.flatten_multidimensional_arrays && dimension_flatten)
{
// If we are flattening multidimensional arrays, do manual stride computation.
auto &parent_type = get<SPIRType>(type->parent_type);
if (index_is_literal)
expr += convert_to_string(index);
else
expr += to_enclosed_expression(index, register_expression_read);
for (auto j = uint32_t(parent_type.array.size()); j; j--)
{
expr += " * ";
expr += enclose_expression(to_array_size(parent_type, j - 1));
}
if (parent_type.array.empty())
pending_array_enclose = false;
else
expr += " + ";
if (!pending_array_enclose)
expr += "]";
}
else
{
append_index();
}
type_id = type->parent_type;
type = &get<SPIRType>(type_id);
access_chain_is_arrayed = true;
}
// For structs, the index refers to a constant, which indexes into the members.
// We also check if this member is a builtin, since we then replace the entire expression with the builtin one.
else if (type->basetype == SPIRType::Struct)
{
if (!index_is_literal)
index = get<SPIRConstant>(index).scalar();
if (index >= type->member_types.size())
SPIRV_CROSS_THROW("Member index is out of bounds!");
BuiltIn builtin;
if (is_member_builtin(*type, index, &builtin))
{
// FIXME: We rely here on OpName on gl_in/gl_out to make this work properly.
// To make this properly work by omitting all OpName opcodes,
// we need to infer gl_in or gl_out based on the builtin, and stage.
if (access_chain_is_arrayed)
{
expr += ".";
expr += builtin_to_glsl(builtin, type->storage);
}
else
expr = builtin_to_glsl(builtin, type->storage);
}
else
{
// If the member has a qualified name, use it as the entire chain
string qual_mbr_name = get_member_qualified_name(type_id, index);
if (!qual_mbr_name.empty())
expr = qual_mbr_name;
else
expr += to_member_reference(base, *type, index, ptr_chain);
}
if (has_member_decoration(type->self, index, DecorationInvariant))
is_invariant = true;
is_packed = member_is_packed_type(*type, index);
if (is_packed)
packed_type = get_extended_member_decoration(type->self, index, SPIRVCrossDecorationPackedType);
else
packed_type = 0;
row_major_matrix_needs_conversion = member_is_non_native_row_major_matrix(*type, index);
type = &get<SPIRType>(type->member_types[index]);
}
// Matrix -> Vector
else if (type->columns > 1)
{
if (row_major_matrix_needs_conversion)
{
expr = convert_row_major_matrix(expr, *type, is_packed);
row_major_matrix_needs_conversion = false;
is_packed = false;
packed_type = 0;
}
expr += "[";
if (index_is_literal)
expr += convert_to_string(index);
else
expr += to_expression(index, register_expression_read);
expr += "]";
type_id = type->parent_type;
type = &get<SPIRType>(type_id);
}
// Vector -> Scalar
else if (type->vecsize > 1)
{
if (index_is_literal && !is_packed)
{
expr += ".";
expr += index_to_swizzle(index);
}
else if (ir.ids[index].get_type() == TypeConstant && !is_packed)
{
auto &c = get<SPIRConstant>(index);
expr += ".";
expr += index_to_swizzle(c.scalar());
}
else if (index_is_literal)
{
// For packed vectors, we can only access them as an array, not by swizzle.
expr += join("[", index, "]");
}
else
{
expr += "[";
expr += to_expression(index, register_expression_read);
expr += "]";
}
is_packed = false;
packed_type = 0;
type_id = type->parent_type;
type = &get<SPIRType>(type_id);
}
else if (!backend.allow_truncated_access_chain)
SPIRV_CROSS_THROW("Cannot subdivide a scalar value!");
}
if (pending_array_enclose)
{
SPIRV_CROSS_THROW("Flattening of multidimensional arrays were enabled, "
"but the access chain was terminated in the middle of a multidimensional array. "
"This is not supported.");
}
if (meta)
{
meta->need_transpose = row_major_matrix_needs_conversion;
meta->storage_is_packed = is_packed;
meta->storage_is_invariant = is_invariant;
meta->storage_packed_type = packed_type;
}
return expr;
}
string CompilerGLSL::to_flattened_struct_member(const SPIRVariable &var, uint32_t index)
{
auto &type = get<SPIRType>(var.basetype);
return sanitize_underscores(join(to_name(var.self), "_", to_member_name(type, index)));
}
string CompilerGLSL::access_chain(uint32_t base, const uint32_t *indices, uint32_t count, const SPIRType &target_type,
AccessChainMeta *meta, bool ptr_chain)
{
if (flattened_buffer_blocks.count(base))
{
uint32_t matrix_stride = 0;
bool need_transpose = false;
flattened_access_chain_offset(expression_type(base), indices, count, 0, 16, &need_transpose, &matrix_stride,
ptr_chain);
if (meta)
{
meta->need_transpose = target_type.columns > 1 && need_transpose;
meta->storage_is_packed = false;
}
return flattened_access_chain(base, indices, count, target_type, 0, matrix_stride, need_transpose);
}
else if (flattened_structs.count(base) && count > 0)
{
AccessChainFlags flags = ACCESS_CHAIN_CHAIN_ONLY_BIT | ACCESS_CHAIN_SKIP_REGISTER_EXPRESSION_READ_BIT;
if (ptr_chain)
flags |= ACCESS_CHAIN_PTR_CHAIN_BIT;
auto chain = access_chain_internal(base, indices, count, flags, nullptr).substr(1);
if (meta)
{
meta->need_transpose = false;
meta->storage_is_packed = false;
}
return sanitize_underscores(join(to_name(base), "_", chain));
}
else
{
AccessChainFlags flags = ACCESS_CHAIN_SKIP_REGISTER_EXPRESSION_READ_BIT;
if (ptr_chain)
flags |= ACCESS_CHAIN_PTR_CHAIN_BIT;
return access_chain_internal(base, indices, count, flags, meta);
}
}
string CompilerGLSL::load_flattened_struct(SPIRVariable &var)
{
auto expr = type_to_glsl_constructor(get<SPIRType>(var.basetype));
expr += '(';
auto &type = get<SPIRType>(var.basetype);
for (uint32_t i = 0; i < uint32_t(type.member_types.size()); i++)
{
if (i)
expr += ", ";
// Flatten the varyings.
// Apply name transformation for flattened I/O blocks.
expr += to_flattened_struct_member(var, i);
}
expr += ')';
return expr;
}
void CompilerGLSL::store_flattened_struct(SPIRVariable &var, uint32_t value)
{
// We're trying to store a structure which has been flattened.
// Need to copy members one by one.
auto rhs = to_expression(value);
// Store result locally.
// Since we're declaring a variable potentially multiple times here,
// store the variable in an isolated scope.
begin_scope();
statement(variable_decl_function_local(var), " = ", rhs, ";");
auto &type = get<SPIRType>(var.basetype);
for (uint32_t i = 0; i < uint32_t(type.member_types.size()); i++)
{
// Flatten the varyings.
// Apply name transformation for flattened I/O blocks.
auto lhs = sanitize_underscores(join(to_name(var.self), "_", to_member_name(type, i)));
rhs = join(to_name(var.self), ".", to_member_name(type, i));
statement(lhs, " = ", rhs, ";");
}
end_scope();
}
std::string CompilerGLSL::flattened_access_chain(uint32_t base, const uint32_t *indices, uint32_t count,
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
bool need_transpose)
{
if (!target_type.array.empty())
SPIRV_CROSS_THROW("Access chains that result in an array can not be flattened");
else if (target_type.basetype == SPIRType::Struct)
return flattened_access_chain_struct(base, indices, count, target_type, offset);
else if (target_type.columns > 1)
return flattened_access_chain_matrix(base, indices, count, target_type, offset, matrix_stride, need_transpose);
else
return flattened_access_chain_vector(base, indices, count, target_type, offset, matrix_stride, need_transpose);
}
std::string CompilerGLSL::flattened_access_chain_struct(uint32_t base, const uint32_t *indices, uint32_t count,
const SPIRType &target_type, uint32_t offset)
{
std::string expr;
expr += type_to_glsl_constructor(target_type);
expr += "(";
for (uint32_t i = 0; i < uint32_t(target_type.member_types.size()); ++i)
{
if (i != 0)
expr += ", ";
const SPIRType &member_type = get<SPIRType>(target_type.member_types[i]);
uint32_t member_offset = type_struct_member_offset(target_type, i);
// The access chain terminates at the struct, so we need to find matrix strides and row-major information
// ahead of time.
bool need_transpose = false;
uint32_t matrix_stride = 0;
if (member_type.columns > 1)
{
need_transpose = combined_decoration_for_member(target_type, i).get(DecorationRowMajor);
matrix_stride = type_struct_member_matrix_stride(target_type, i);
}
auto tmp = flattened_access_chain(base, indices, count, member_type, offset + member_offset, matrix_stride,
need_transpose);
// Cannot forward transpositions, so resolve them here.
if (need_transpose)
expr += convert_row_major_matrix(tmp, member_type, false);
else
expr += tmp;
}
expr += ")";
return expr;
}
std::string CompilerGLSL::flattened_access_chain_matrix(uint32_t base, const uint32_t *indices, uint32_t count,
const SPIRType &target_type, uint32_t offset,
uint32_t matrix_stride, bool need_transpose)
{
assert(matrix_stride);
SPIRType tmp_type = target_type;
if (need_transpose)
swap(tmp_type.vecsize, tmp_type.columns);
std::string expr;
expr += type_to_glsl_constructor(tmp_type);
expr += "(";
for (uint32_t i = 0; i < tmp_type.columns; i++)
{
if (i != 0)
expr += ", ";
expr += flattened_access_chain_vector(base, indices, count, tmp_type, offset + i * matrix_stride, matrix_stride,
/* need_transpose= */ false);
}
expr += ")";
return expr;
}
std::string CompilerGLSL::flattened_access_chain_vector(uint32_t base, const uint32_t *indices, uint32_t count,
const SPIRType &target_type, uint32_t offset,
uint32_t matrix_stride, bool need_transpose)
{
auto result = flattened_access_chain_offset(expression_type(base), indices, count, offset, 16);
auto buffer_name = to_name(expression_type(base).self);
if (need_transpose)
{
std::string expr;
if (target_type.vecsize > 1)
{
expr += type_to_glsl_constructor(target_type);
expr += "(";
}
for (uint32_t i = 0; i < target_type.vecsize; ++i)
{
if (i != 0)
expr += ", ";
uint32_t component_offset = result.second + i * matrix_stride;
assert(component_offset % (target_type.width / 8) == 0);
uint32_t index = component_offset / (target_type.width / 8);
expr += buffer_name;
expr += "[";
expr += result.first; // this is a series of N1 * k1 + N2 * k2 + ... that is either empty or ends with a +
expr += convert_to_string(index / 4);
expr += "]";
expr += vector_swizzle(1, index % 4);
}
if (target_type.vecsize > 1)
{
expr += ")";
}
return expr;
}
else
{
assert(result.second % (target_type.width / 8) == 0);
uint32_t index = result.second / (target_type.width / 8);
std::string expr;
expr += buffer_name;
expr += "[";
expr += result.first; // this is a series of N1 * k1 + N2 * k2 + ... that is either empty or ends with a +
expr += convert_to_string(index / 4);
expr += "]";
expr += vector_swizzle(target_type.vecsize, index % 4);
return expr;
}
}
std::pair<std::string, uint32_t> CompilerGLSL::flattened_access_chain_offset(
const SPIRType &basetype, const uint32_t *indices, uint32_t count, uint32_t offset, uint32_t word_stride,
bool *need_transpose, uint32_t *out_matrix_stride, bool ptr_chain)
{
// Start traversing type hierarchy at the proper non-pointer types.
const auto *type = &get_pointee_type(basetype);
// This holds the type of the current pointer which we are traversing through.
// We always start out from a struct type which is the block.
// This is primarily used to reflect the array strides and matrix strides later.
// For the first access chain index, type_id won't be needed, so just keep it as 0, it will be set
// accordingly as members of structs are accessed.
assert(type->basetype == SPIRType::Struct);
uint32_t type_id = 0;
std::string expr;
// Inherit matrix information in case we are access chaining a vector which might have come from a row major layout.
bool row_major_matrix_needs_conversion = need_transpose ? *need_transpose : false;
uint32_t matrix_stride = out_matrix_stride ? *out_matrix_stride : 0;
for (uint32_t i = 0; i < count; i++)
{
uint32_t index = indices[i];
// Pointers
if (ptr_chain && i == 0)
{
// Here, the pointer type will be decorated with an array stride.
uint32_t array_stride = get_decoration(basetype.self, DecorationArrayStride);
if (!array_stride)
SPIRV_CROSS_THROW("SPIR-V does not define ArrayStride for buffer block.");
auto *constant = maybe_get<SPIRConstant>(index);
if (constant)
{
// Constant array access.
offset += constant->scalar() * array_stride;
}
else
{
// Dynamic array access.
if (array_stride % word_stride)
{
SPIRV_CROSS_THROW(
"Array stride for dynamic indexing must be divisible by the size of a 4-component vector. "
"Likely culprit here is a float or vec2 array inside a push constant block which is std430. "
"This cannot be flattened. Try using std140 layout instead.");
}
expr += to_enclosed_expression(index);
expr += " * ";
expr += convert_to_string(array_stride / word_stride);
expr += " + ";
}
// Type ID is unchanged.
}
// Arrays
else if (!type->array.empty())
{
// Here, the type_id will be a type ID for the array type itself.
uint32_t array_stride = get_decoration(type_id, DecorationArrayStride);
if (!array_stride)
SPIRV_CROSS_THROW("SPIR-V does not define ArrayStride for buffer block.");
auto *constant = maybe_get<SPIRConstant>(index);
if (constant)
{
// Constant array access.
offset += constant->scalar() * array_stride;
}
else
{
// Dynamic array access.
if (array_stride % word_stride)
{
SPIRV_CROSS_THROW(
"Array stride for dynamic indexing must be divisible by the size of a 4-component vector. "
"Likely culprit here is a float or vec2 array inside a push constant block which is std430. "
"This cannot be flattened. Try using std140 layout instead.");
}
expr += to_enclosed_expression(index, false);
expr += " * ";
expr += convert_to_string(array_stride / word_stride);
expr += " + ";
}
uint32_t parent_type = type->parent_type;
type = &get<SPIRType>(parent_type);
type_id = parent_type;
// Type ID now refers to the array type with one less dimension.
}
// For structs, the index refers to a constant, which indexes into the members.
// We also check if this member is a builtin, since we then replace the entire expression with the builtin one.
else if (type->basetype == SPIRType::Struct)
{
index = get<SPIRConstant>(index).scalar();
if (index >= type->member_types.size())
SPIRV_CROSS_THROW("Member index is out of bounds!");
offset += type_struct_member_offset(*type, index);
type_id = type->member_types[index];
auto &struct_type = *type;
type = &get<SPIRType>(type->member_types[index]);
if (type->columns > 1)
{
matrix_stride = type_struct_member_matrix_stride(struct_type, index);
row_major_matrix_needs_conversion =
combined_decoration_for_member(struct_type, index).get(DecorationRowMajor);
}
else
row_major_matrix_needs_conversion = false;
}
// Matrix -> Vector
else if (type->columns > 1)
{
auto *constant = maybe_get<SPIRConstant>(index);
if (constant)
{
index = get<SPIRConstant>(index).scalar();
offset += index * (row_major_matrix_needs_conversion ? (type->width / 8) : matrix_stride);
}
else
{
uint32_t indexing_stride = row_major_matrix_needs_conversion ? (type->width / 8) : matrix_stride;
// Dynamic array access.
if (indexing_stride % word_stride)
{
SPIRV_CROSS_THROW(
"Matrix stride for dynamic indexing must be divisible by the size of a 4-component vector. "
"Likely culprit here is a row-major matrix being accessed dynamically. "
"This cannot be flattened. Try using std140 layout instead.");
}
expr += to_enclosed_expression(index, false);
expr += " * ";
expr += convert_to_string(indexing_stride / word_stride);
expr += " + ";
}
uint32_t parent_type = type->parent_type;
type = &get<SPIRType>(type->parent_type);
type_id = parent_type;
}
// Vector -> Scalar
else if (type->vecsize > 1)
{
auto *constant = maybe_get<SPIRConstant>(index);
if (constant)
{
index = get<SPIRConstant>(index).scalar();
offset += index * (row_major_matrix_needs_conversion ? matrix_stride : (type->width / 8));
}
else
{
uint32_t indexing_stride = row_major_matrix_needs_conversion ? matrix_stride : (type->width / 8);
// Dynamic array access.
if (indexing_stride % word_stride)
{
SPIRV_CROSS_THROW(
"Stride for dynamic vector indexing must be divisible by the size of a 4-component vector. "
"This cannot be flattened in legacy targets.");
}
expr += to_enclosed_expression(index, false);
expr += " * ";
expr += convert_to_string(indexing_stride / word_stride);
expr += " + ";
}
uint32_t parent_type = type->parent_type;
type = &get<SPIRType>(type->parent_type);
type_id = parent_type;
}
else
SPIRV_CROSS_THROW("Cannot subdivide a scalar value!");
}
if (need_transpose)
*need_transpose = row_major_matrix_needs_conversion;
if (out_matrix_stride)
*out_matrix_stride = matrix_stride;
return std::make_pair(expr, offset);
}
bool CompilerGLSL::should_dereference(uint32_t id)
{
const auto &type = expression_type(id);
// Non-pointer expressions don't need to be dereferenced.
if (!type.pointer)
return false;
// Handles shouldn't be dereferenced either.
if (!expression_is_lvalue(id))
return false;
// If id is a variable but not a phi variable, we should not dereference it.
if (auto *var = maybe_get<SPIRVariable>(id))
return var->phi_variable;
// If id is an access chain, we should not dereference it.
if (auto *expr = maybe_get<SPIRExpression>(id))
return !expr->access_chain;
// Otherwise, we should dereference this pointer expression.
return true;
}
bool CompilerGLSL::should_forward(uint32_t id)
{
// If id is a variable we will try to forward it regardless of force_temporary check below
// This is important because otherwise we'll get local sampler copies (highp sampler2D foo = bar) that are invalid in OpenGL GLSL
auto *var = maybe_get<SPIRVariable>(id);
if (var && var->forwardable)
return true;
// For debugging emit temporary variables for all expressions
if (options.force_temporary)
return false;
// Immutable expression can always be forwarded.
if (is_immutable(id))
return true;
return false;
}
void CompilerGLSL::track_expression_read(uint32_t id)
{
switch (ir.ids[id].get_type())
{
case TypeExpression:
{
auto &e = get<SPIRExpression>(id);
for (auto implied_read : e.implied_read_expressions)
track_expression_read(implied_read);
break;
}
case TypeAccessChain:
{
auto &e = get<SPIRAccessChain>(id);
for (auto implied_read : e.implied_read_expressions)
track_expression_read(implied_read);
break;
}
default:
break;
}
// If we try to read a forwarded temporary more than once we will stamp out possibly complex code twice.
// In this case, it's better to just bind the complex expression to the temporary and read that temporary twice.
if (expression_is_forwarded(id))
{
auto &v = expression_usage_counts[id];
v++;
if (v >= 2)
{
//if (v == 2)
// fprintf(stderr, "ID %u was forced to temporary due to more than 1 expression use!\n", id);
forced_temporaries.insert(id);
// Force a recompile after this pass to avoid forwarding this variable.
force_recompile = true;
}
}
}
bool CompilerGLSL::args_will_forward(uint32_t id, const uint32_t *args, uint32_t num_args, bool pure)
{
if (forced_temporaries.find(id) != end(forced_temporaries))
return false;
for (uint32_t i = 0; i < num_args; i++)
if (!should_forward(args[i]))
return false;
// We need to forward globals as well.
if (!pure)
{
for (auto global : global_variables)
if (!should_forward(global))
return false;
for (auto aliased : aliased_variables)
if (!should_forward(aliased))
return false;
}
return true;
}
void CompilerGLSL::register_impure_function_call()
{
// Impure functions can modify globals and aliased variables, so invalidate them as well.
for (auto global : global_variables)
flush_dependees(get<SPIRVariable>(global));
for (auto aliased : aliased_variables)
flush_dependees(get<SPIRVariable>(aliased));
}
void CompilerGLSL::register_call_out_argument(uint32_t id)
{
register_write(id);
auto *var = maybe_get<SPIRVariable>(id);
if (var)
flush_variable_declaration(var->self);
}
string CompilerGLSL::variable_decl_function_local(SPIRVariable &var)
{
// These variables are always function local,
// so make sure we emit the variable without storage qualifiers.
// Some backends will inject custom variables locally in a function
// with a storage qualifier which is not function-local.
auto old_storage = var.storage;
var.storage = StorageClassFunction;
auto expr = variable_decl(var);
var.storage = old_storage;
return expr;
}
void CompilerGLSL::flush_variable_declaration(uint32_t id)
{
auto *var = maybe_get<SPIRVariable>(id);
if (var && var->deferred_declaration)
{
statement(variable_decl_function_local(*var), ";");
if (var->allocate_temporary_copy)
{
auto &type = get<SPIRType>(var->basetype);
auto &flags = ir.meta[id].decoration.decoration_flags;
statement(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, join("_", id, "_copy")),
";");
}
var->deferred_declaration = false;
}
}
bool CompilerGLSL::remove_duplicate_swizzle(string &op)
{
auto pos = op.find_last_of('.');
if (pos == string::npos || pos == 0)
return false;
string final_swiz = op.substr(pos + 1, string::npos);
if (backend.swizzle_is_function)
{
if (final_swiz.size() < 2)
return false;
if (final_swiz.substr(final_swiz.size() - 2, string::npos) == "()")
final_swiz.erase(final_swiz.size() - 2, string::npos);
else
return false;
}
// Check if final swizzle is of form .x, .xy, .xyz, .xyzw or similar.
// If so, and previous swizzle is of same length,
// we can drop the final swizzle altogether.
for (uint32_t i = 0; i < final_swiz.size(); i++)
{
static const char expected[] = { 'x', 'y', 'z', 'w' };
if (i >= 4 || final_swiz[i] != expected[i])
return false;
}
auto prevpos = op.find_last_of('.', pos - 1);
if (prevpos == string::npos)
return false;
prevpos++;
// Make sure there are only swizzles here ...
for (auto i = prevpos; i < pos; i++)
{
if (op[i] < 'w' || op[i] > 'z')
{
// If swizzles are foo.xyz() like in C++ backend for example, check for that.
if (backend.swizzle_is_function && i + 2 == pos && op[i] == '(' && op[i + 1] == ')')
break;
return false;
}
}
// If original swizzle is large enough, just carve out the components we need.
// E.g. foobar.wyx.xy will turn into foobar.wy.
if (pos - prevpos >= final_swiz.size())
{
op.erase(prevpos + final_swiz.size(), string::npos);
// Add back the function call ...
if (backend.swizzle_is_function)
op += "()";
}
return true;
}
// Optimizes away vector swizzles where we have something like
// vec3 foo;
// foo.xyz <-- swizzle expression does nothing.
// This is a very common pattern after OpCompositeCombine.
bool CompilerGLSL::remove_unity_swizzle(uint32_t base, string &op)
{
auto pos = op.find_last_of('.');
if (pos == string::npos || pos == 0)
return false;
string final_swiz = op.substr(pos + 1, string::npos);
if (backend.swizzle_is_function)
{
if (final_swiz.size() < 2)
return false;
if (final_swiz.substr(final_swiz.size() - 2, string::npos) == "()")
final_swiz.erase(final_swiz.size() - 2, string::npos);
else
return false;
}
// Check if final swizzle is of form .x, .xy, .xyz, .xyzw or similar.
// If so, and previous swizzle is of same length,
// we can drop the final swizzle altogether.
for (uint32_t i = 0; i < final_swiz.size(); i++)
{
static const char expected[] = { 'x', 'y', 'z', 'w' };
if (i >= 4 || final_swiz[i] != expected[i])
return false;
}
auto &type = expression_type(base);
// Sanity checking ...
assert(type.columns == 1 && type.array.empty());
if (type.vecsize == final_swiz.size())
op.erase(pos, string::npos);
return true;
}
string CompilerGLSL::build_composite_combiner(uint32_t return_type, const uint32_t *elems, uint32_t length)
{
uint32_t base = 0;
string op;
string subop;
// Can only merge swizzles for vectors.
auto &type = get<SPIRType>(return_type);
bool can_apply_swizzle_opt = type.basetype != SPIRType::Struct && type.array.empty() && type.columns == 1;
bool swizzle_optimization = false;
for (uint32_t i = 0; i < length; i++)
{
auto *e = maybe_get<SPIRExpression>(elems[i]);
// If we're merging another scalar which belongs to the same base
// object, just merge the swizzles to avoid triggering more than 1 expression read as much as possible!
if (can_apply_swizzle_opt && e && e->base_expression && e->base_expression == base)
{
// Only supposed to be used for vector swizzle -> scalar.
assert(!e->expression.empty() && e->expression.front() == '.');
subop += e->expression.substr(1, string::npos);
swizzle_optimization = true;
}
else
{
// We'll likely end up with duplicated swizzles, e.g.
// foobar.xyz.xyz from patterns like
// OpVectorShuffle
// OpCompositeExtract x 3
// OpCompositeConstruct 3x + other scalar.
// Just modify op in-place.
if (swizzle_optimization)
{
if (backend.swizzle_is_function)
subop += "()";
// Don't attempt to remove unity swizzling if we managed to remove duplicate swizzles.
// The base "foo" might be vec4, while foo.xyz is vec3 (OpVectorShuffle) and looks like a vec3 due to the .xyz tacked on.
// We only want to remove the swizzles if we're certain that the resulting base will be the same vecsize.
// Essentially, we can only remove one set of swizzles, since that's what we have control over ...
// Case 1:
// foo.yxz.xyz: Duplicate swizzle kicks in, giving foo.yxz, we are done.
// foo.yxz was the result of OpVectorShuffle and we don't know the type of foo.
// Case 2:
// foo.xyz: Duplicate swizzle won't kick in.
// If foo is vec3, we can remove xyz, giving just foo.
if (!remove_duplicate_swizzle(subop))
remove_unity_swizzle(base, subop);
// Strips away redundant parens if we created them during component extraction.
strip_enclosed_expression(subop);
swizzle_optimization = false;
op += subop;
}
else
op += subop;
if (i)
op += ", ";
subop = to_expression(elems[i]);
}
base = e ? e->base_expression : 0;
}
if (swizzle_optimization)
{
if (backend.swizzle_is_function)
subop += "()";
if (!remove_duplicate_swizzle(subop))
remove_unity_swizzle(base, subop);
// Strips away redundant parens if we created them during component extraction.
strip_enclosed_expression(subop);
}
op += subop;
return op;
}
bool CompilerGLSL::skip_argument(uint32_t id) const
{
if (!combined_image_samplers.empty() || !options.vulkan_semantics)
{
auto &type = expression_type(id);
if (type.basetype == SPIRType::Sampler || (type.basetype == SPIRType::Image && type.image.sampled == 1))
return true;
}
return false;
}
bool CompilerGLSL::optimize_read_modify_write(const SPIRType &type, const string &lhs, const string &rhs)
{
// Do this with strings because we have a very clear pattern we can check for and it avoids
// adding lots of special cases to the code emission.
if (rhs.size() < lhs.size() + 3)
return false;
// Do not optimize matrices. They are a bit awkward to reason about in general
// (in which order does operation happen?), and it does not work on MSL anyways.
if (type.vecsize > 1 && type.columns > 1)
return false;
auto index = rhs.find(lhs);
if (index != 0)
return false;
// TODO: Shift operators, but it's not important for now.
auto op = rhs.find_first_of("+-/*%|&^", lhs.size() + 1);
if (op != lhs.size() + 1)
return false;
// Check that the op is followed by space. This excludes && and ||.
if (rhs[op + 1] != ' ')
return false;
char bop = rhs[op];
auto expr = rhs.substr(lhs.size() + 3);
// Try to find increments and decrements. Makes it look neater as += 1, -= 1 is fairly rare to see in real code.
// Find some common patterns which are equivalent.
if ((bop == '+' || bop == '-') && (expr == "1" || expr == "uint(1)" || expr == "1u" || expr == "int(1u)"))
statement(lhs, bop, bop, ";");
else
statement(lhs, " ", bop, "= ", expr, ";");
return true;
}
void CompilerGLSL::register_control_dependent_expression(uint32_t expr)
{
if (forwarded_temporaries.find(expr) == end(forwarded_temporaries))
return;
assert(current_emitting_block);
current_emitting_block->invalidate_expressions.push_back(expr);
}
void CompilerGLSL::emit_block_instructions(SPIRBlock &block)
{
current_emitting_block = █
for (auto &op : block.ops)
emit_instruction(op);
current_emitting_block = nullptr;
}
void CompilerGLSL::disallow_forwarding_in_expression_chain(const SPIRExpression &expr)
{
if (forwarded_temporaries.count(expr.self))
{
forced_temporaries.insert(expr.self);
force_recompile = true;
}
for (auto &dependent : expr.expression_dependencies)
disallow_forwarding_in_expression_chain(get<SPIRExpression>(dependent));
}
void CompilerGLSL::handle_store_to_invariant_variable(uint32_t store_id, uint32_t value_id)
{
// Variables or access chains marked invariant are complicated. We will need to make sure the code-gen leading up to
// this variable is consistent. The failure case for SPIRV-Cross is when an expression is forced to a temporary
// in one translation unit, but not another, e.g. due to multiple use of an expression.
// This causes variance despite the output variable being marked invariant, so the solution here is to force all dependent
// expressions to be temporaries.
// It is uncertain if this is enough to support invariant in all possible cases, but it should be good enough
// for all reasonable uses of invariant.
if (!has_decoration(store_id, DecorationInvariant))
return;
auto *expr = maybe_get<SPIRExpression>(value_id);
if (!expr)
return;
disallow_forwarding_in_expression_chain(*expr);
}
void CompilerGLSL::emit_store_statement(uint32_t lhs_expression, uint32_t rhs_expression)
{
auto rhs = to_pointer_expression(rhs_expression);
// Statements to OpStore may be empty if it is a struct with zero members. Just forward the store to /dev/null.
if (!rhs.empty())
{
handle_store_to_invariant_variable(lhs_expression, rhs_expression);
auto lhs = to_dereferenced_expression(lhs_expression);
// We might need to bitcast in order to store to a builtin.
bitcast_to_builtin_store(lhs_expression, rhs, expression_type(rhs_expression));
// Tries to optimize assignments like "<lhs> = <lhs> op expr".
// While this is purely cosmetic, this is important for legacy ESSL where loop
// variable increments must be in either i++ or i += const-expr.
// Without this, we end up with i = i + 1, which is correct GLSL, but not correct GLES 2.0.
if (!optimize_read_modify_write(expression_type(rhs_expression), lhs, rhs))
statement(lhs, " = ", rhs, ";");
register_write(lhs_expression);
}
}
uint32_t CompilerGLSL::get_integer_width_for_instruction(const Instruction &instr) const
{
if (instr.length < 3)
return 32;
auto *ops = stream(instr);
switch (instr.op)
{
case OpIEqual:
case OpINotEqual:
case OpSLessThan:
case OpSLessThanEqual:
case OpSGreaterThan:
case OpSGreaterThanEqual:
return expression_type(ops[2]).width;
default:
{
// We can look at result type which is more robust.
auto *type = maybe_get<SPIRType>(ops[0]);
if (type && type_is_integral(*type))
return type->width;
else
return 32;
}
}
}
uint32_t CompilerGLSL::get_integer_width_for_glsl_instruction(GLSLstd450 op, const uint32_t *ops, uint32_t length) const
{
if (length < 1)
return 32;
switch (op)
{
case GLSLstd450SAbs:
case GLSLstd450SSign:
case GLSLstd450UMin:
case GLSLstd450SMin:
case GLSLstd450UMax:
case GLSLstd450SMax:
case GLSLstd450UClamp:
case GLSLstd450SClamp:
case GLSLstd450FindSMsb:
case GLSLstd450FindUMsb:
return expression_type(ops[0]).width;
default:
{
// We don't need to care about other opcodes, just return 32.
return 32;
}
}
}
void CompilerGLSL::emit_instruction(const Instruction &instruction)
{
auto ops = stream(instruction);
auto opcode = static_cast<Op>(instruction.op);
uint32_t length = instruction.length;
#define GLSL_BOP(op) emit_binary_op(ops[0], ops[1], ops[2], ops[3], #op)
#define GLSL_BOP_CAST(op, type) \
emit_binary_op_cast(ops[0], ops[1], ops[2], ops[3], #op, type, opcode_is_sign_invariant(opcode))
#define GLSL_UOP(op) emit_unary_op(ops[0], ops[1], ops[2], #op)
#define GLSL_QFOP(op) emit_quaternary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], ops[5], #op)
#define GLSL_TFOP(op) emit_trinary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], #op)
#define GLSL_BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define GLSL_BFOP_CAST(op, type) \
emit_binary_func_op_cast(ops[0], ops[1], ops[2], ops[3], #op, type, opcode_is_sign_invariant(opcode))
#define GLSL_BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define GLSL_UFOP(op) emit_unary_func_op(ops[0], ops[1], ops[2], #op)
// If we need to do implicit bitcasts, make sure we do it with the correct type.
uint32_t integer_width = get_integer_width_for_instruction(instruction);
auto int_type = to_signed_basetype(integer_width);
auto uint_type = to_unsigned_basetype(integer_width);
switch (opcode)
{
// Dealing with memory
case OpLoad:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t ptr = ops[2];
flush_variable_declaration(ptr);
// If we're loading from memory that cannot be changed by the shader,
// just forward the expression directly to avoid needless temporaries.
// If an expression is mutable and forwardable, we speculate that it is immutable.
bool forward = should_forward(ptr) && forced_temporaries.find(id) == end(forced_temporaries);
// If loading a non-native row-major matrix, mark the expression as need_transpose.
bool need_transpose = false;
bool old_need_transpose = false;
auto *ptr_expression = maybe_get<SPIRExpression>(ptr);
if (ptr_expression && ptr_expression->need_transpose)
{
old_need_transpose = true;
ptr_expression->need_transpose = false;
need_transpose = true;
}
else if (is_non_native_row_major_matrix(ptr))
need_transpose = true;
// If we are forwarding this load,
// don't register the read to access chain here, defer that to when we actually use the expression,
// using the add_implied_read_expression mechanism.
auto expr = to_dereferenced_expression(ptr, !forward);
// We might need to bitcast in order to load from a builtin.
bitcast_from_builtin_load(ptr, expr, get<SPIRType>(result_type));
// We might be trying to load a gl_Position[N], where we should be
// doing float4[](gl_in[i].gl_Position, ...) instead.
// Similar workarounds are required for input arrays in tessellation.
unroll_array_from_complex_load(id, ptr, expr);
if (ptr_expression)
ptr_expression->need_transpose = old_need_transpose;
// By default, suppress usage tracking since using same expression multiple times does not imply any extra work.
// However, if we try to load a complex, composite object from a flattened buffer,
// we should avoid emitting the same code over and over and lower the result to a temporary.
auto &type = get<SPIRType>(result_type);
bool usage_tracking = ptr_expression && flattened_buffer_blocks.count(ptr_expression->loaded_from) != 0 &&
(type.basetype == SPIRType::Struct || (type.columns > 1));
auto &e = emit_op(result_type, id, expr, forward, !usage_tracking);
e.need_transpose = need_transpose;
register_read(id, ptr, forward);
// Pass through whether the result is of a packed type.
if (has_extended_decoration(ptr, SPIRVCrossDecorationPacked))
{
set_extended_decoration(id, SPIRVCrossDecorationPacked);
set_extended_decoration(id, SPIRVCrossDecorationPackedType,
get_extended_decoration(ptr, SPIRVCrossDecorationPackedType));
}
inherit_expression_dependencies(id, ptr);
if (forward)
add_implied_read_expression(e, ptr);
break;
}
case OpInBoundsAccessChain:
case OpAccessChain:
case OpPtrAccessChain:
{
auto *var = maybe_get<SPIRVariable>(ops[2]);
if (var)
flush_variable_declaration(var->self);
// If the base is immutable, the access chain pointer must also be.
// If an expression is mutable and forwardable, we speculate that it is immutable.
AccessChainMeta meta;
bool ptr_chain = opcode == OpPtrAccessChain;
auto e = access_chain(ops[2], &ops[3], length - 3, get<SPIRType>(ops[0]), &meta, ptr_chain);
auto &expr = set<SPIRExpression>(ops[1], move(e), ops[0], should_forward(ops[2]));
auto *backing_variable = maybe_get_backing_variable(ops[2]);
expr.loaded_from = backing_variable ? backing_variable->self : ops[2];
expr.need_transpose = meta.need_transpose;
expr.access_chain = true;
// Mark the result as being packed. Some platforms handled packed vectors differently than non-packed.
if (meta.storage_is_packed)
set_extended_decoration(ops[1], SPIRVCrossDecorationPacked);
if (meta.storage_packed_type != 0)
set_extended_decoration(ops[1], SPIRVCrossDecorationPackedType, meta.storage_packed_type);
if (meta.storage_is_invariant)
set_decoration(ops[1], DecorationInvariant);
for (uint32_t i = 2; i < length; i++)
{
inherit_expression_dependencies(ops[1], ops[i]);
add_implied_read_expression(expr, ops[i]);
}
break;
}
case OpStore:
{
auto *var = maybe_get<SPIRVariable>(ops[0]);
if (var && var->statically_assigned)
var->static_expression = ops[1];
else if (var && var->loop_variable && !var->loop_variable_enable)
var->static_expression = ops[1];
else if (var && var->remapped_variable)
{
// Skip the write.
}
else if (var && flattened_structs.count(ops[0]))
{
store_flattened_struct(*var, ops[1]);
register_write(ops[0]);
}
else
{
emit_store_statement(ops[0], ops[1]);
}
// Storing a pointer results in a variable pointer, so we must conservatively assume
// we can write through it.
if (expression_type(ops[1]).pointer)
register_write(ops[1]);
break;
}
case OpArrayLength:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
auto e = access_chain_internal(ops[2], &ops[3], length - 3, ACCESS_CHAIN_INDEX_IS_LITERAL_BIT, nullptr);
set<SPIRExpression>(id, e + ".length()", result_type, true);
break;
}
// Function calls
case OpFunctionCall:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t func = ops[2];
const auto *arg = &ops[3];
length -= 3;
auto &callee = get<SPIRFunction>(func);
auto &return_type = get<SPIRType>(callee.return_type);
bool pure = function_is_pure(callee);
bool callee_has_out_variables = false;
bool emit_return_value_as_argument = false;
// Invalidate out variables passed to functions since they can be OpStore'd to.
for (uint32_t i = 0; i < length; i++)
{
if (callee.arguments[i].write_count)
{
register_call_out_argument(arg[i]);
callee_has_out_variables = true;
}
flush_variable_declaration(arg[i]);
}
if (!return_type.array.empty() && !backend.can_return_array)
{
callee_has_out_variables = true;
emit_return_value_as_argument = true;
}
if (!pure)
register_impure_function_call();
string funexpr;
vector<string> arglist;
funexpr += to_name(func) + "(";
if (emit_return_value_as_argument)
{
statement(type_to_glsl(return_type), " ", to_name(id), type_to_array_glsl(return_type), ";");
arglist.push_back(to_name(id));
}
for (uint32_t i = 0; i < length; i++)
{
// Do not pass in separate images or samplers if we're remapping
// to combined image samplers.
if (skip_argument(arg[i]))
continue;
arglist.push_back(to_func_call_arg(arg[i]));
}
for (auto &combined : callee.combined_parameters)
{
uint32_t image_id = combined.global_image ? combined.image_id : arg[combined.image_id];
uint32_t sampler_id = combined.global_sampler ? combined.sampler_id : arg[combined.sampler_id];
arglist.push_back(to_combined_image_sampler(image_id, sampler_id));
}
append_global_func_args(callee, length, arglist);
funexpr += merge(arglist);
funexpr += ")";
// Check for function call constraints.
check_function_call_constraints(arg, length);
if (return_type.basetype != SPIRType::Void)
{
// If the function actually writes to an out variable,
// take the conservative route and do not forward.
// The problem is that we might not read the function
// result (and emit the function) before an out variable
// is read (common case when return value is ignored!
// In order to avoid start tracking invalid variables,
// just avoid the forwarding problem altogether.
bool forward = args_will_forward(id, arg, length, pure) && !callee_has_out_variables && pure &&
(forced_temporaries.find(id) == end(forced_temporaries));
if (emit_return_value_as_argument)
{
statement(funexpr, ";");
set<SPIRExpression>(id, to_name(id), result_type, true);
}
else
emit_op(result_type, id, funexpr, forward);
// Function calls are implicit loads from all variables in question.
// Set dependencies for them.
for (uint32_t i = 0; i < length; i++)
register_read(id, arg[i], forward);
// If we're going to forward the temporary result,
// put dependencies on every variable that must not change.
if (forward)
register_global_read_dependencies(callee, id);
}
else
statement(funexpr, ";");
break;
}
// Composite munging
case OpCompositeConstruct:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
const auto *const elems = &ops[2];
length -= 2;
bool forward = true;
for (uint32_t i = 0; i < length; i++)
forward = forward && should_forward(elems[i]);
auto &out_type = get<SPIRType>(result_type);
auto *in_type = length > 0 ? &expression_type(elems[0]) : nullptr;
// Only splat if we have vector constructors.
// Arrays and structs must be initialized properly in full.
bool composite = !out_type.array.empty() || out_type.basetype == SPIRType::Struct;
bool splat = false;
bool swizzle_splat = false;
if (in_type)
{
splat = in_type->vecsize == 1 && in_type->columns == 1 && !composite && backend.use_constructor_splatting;
swizzle_splat = in_type->vecsize == 1 && in_type->columns == 1 && backend.can_swizzle_scalar;
if (ir.ids[elems[0]].get_type() == TypeConstant && !type_is_floating_point(*in_type))
{
// Cannot swizzle literal integers as a special case.
swizzle_splat = false;
}
}
if (splat || swizzle_splat)
{
uint32_t input = elems[0];
for (uint32_t i = 0; i < length; i++)
{
if (input != elems[i])
{
splat = false;
swizzle_splat = false;
}
}
}
if (out_type.basetype == SPIRType::Struct && !backend.can_declare_struct_inline)
forward = false;
if (!out_type.array.empty() && !backend.can_declare_arrays_inline)
forward = false;
if (type_is_empty(out_type) && !backend.supports_empty_struct)
forward = false;
string constructor_op;
if (!backend.array_is_value_type && out_type.array.size() > 1)
{
// We cannot construct array of arrays because we cannot treat the inputs
// as value types. Need to declare the array-of-arrays, and copy in elements one by one.
forced_temporaries.insert(id);
auto &flags = ir.meta[id].decoration.decoration_flags;
statement(flags_to_precision_qualifiers_glsl(out_type, flags), variable_decl(out_type, to_name(id)), ";");
set<SPIRExpression>(id, to_name(id), result_type, true);
for (uint32_t i = 0; i < length; i++)
emit_array_copy(join(to_expression(id), "[", i, "]"), elems[i]);
}
else if (backend.use_initializer_list && composite)
{
// Only use this path if we are building composites.
// This path cannot be used for arithmetic.
if (backend.use_typed_initializer_list && out_type.basetype == SPIRType::Struct && out_type.array.empty())
constructor_op += type_to_glsl_constructor(get<SPIRType>(result_type));
constructor_op += "{ ";
if (type_is_empty(out_type) && !backend.supports_empty_struct)
constructor_op += "0";
else if (splat)
constructor_op += to_expression(elems[0]);
else
constructor_op += build_composite_combiner(result_type, elems, length);
constructor_op += " }";
}
else if (swizzle_splat && !composite)
{
constructor_op = remap_swizzle(get<SPIRType>(result_type), 1, to_expression(elems[0]));
}
else
{
constructor_op = type_to_glsl_constructor(get<SPIRType>(result_type)) + "(";
if (type_is_empty(out_type) && !backend.supports_empty_struct)
constructor_op += "0";
else if (splat)
constructor_op += to_expression(elems[0]);
else
constructor_op += build_composite_combiner(result_type, elems, length);
constructor_op += ")";
}
if (!constructor_op.empty())
{
emit_op(result_type, id, constructor_op, forward);
for (uint32_t i = 0; i < length; i++)
inherit_expression_dependencies(id, elems[i]);
}
break;
}
case OpVectorInsertDynamic:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t vec = ops[2];
uint32_t comp = ops[3];
uint32_t index = ops[4];
flush_variable_declaration(vec);
// Make a copy, then use access chain to store the variable.
statement(declare_temporary(result_type, id), to_expression(vec), ";");
set<SPIRExpression>(id, to_name(id), result_type, true);
auto chain = access_chain_internal(id, &index, 1, 0, nullptr);
statement(chain, " = ", to_expression(comp), ";");
break;
}
case OpVectorExtractDynamic:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
auto expr = access_chain_internal(ops[2], &ops[3], 1, 0, nullptr);
emit_op(result_type, id, expr, should_forward(ops[2]));
inherit_expression_dependencies(id, ops[2]);
inherit_expression_dependencies(id, ops[3]);
break;
}
case OpCompositeExtract:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
length -= 3;
auto &type = get<SPIRType>(result_type);
// We can only split the expression here if our expression is forwarded as a temporary.
bool allow_base_expression = forced_temporaries.find(id) == end(forced_temporaries);
// Do not allow base expression for struct members. We risk doing "swizzle" optimizations in this case.
auto &composite_type = expression_type(ops[2]);
if (composite_type.basetype == SPIRType::Struct || !composite_type.array.empty())
allow_base_expression = false;
// Packed expressions cannot be split up.
if (has_extended_decoration(ops[2], SPIRVCrossDecorationPacked))
allow_base_expression = false;
AccessChainMeta meta;
SPIRExpression *e = nullptr;
// Only apply this optimization if result is scalar.
if (allow_base_expression && should_forward(ops[2]) && type.vecsize == 1 && type.columns == 1 && length == 1)
{
// We want to split the access chain from the base.
// This is so we can later combine different CompositeExtract results
// with CompositeConstruct without emitting code like
//
// vec3 temp = texture(...).xyz
// vec4(temp.x, temp.y, temp.z, 1.0).
//
// when we actually wanted to emit this
// vec4(texture(...).xyz, 1.0).
//
// Including the base will prevent this and would trigger multiple reads
// from expression causing it to be forced to an actual temporary in GLSL.
auto expr = access_chain_internal(ops[2], &ops[3], length,
ACCESS_CHAIN_INDEX_IS_LITERAL_BIT | ACCESS_CHAIN_CHAIN_ONLY_BIT, &meta);
e = &emit_op(result_type, id, expr, true, !expression_is_forwarded(ops[2]));
inherit_expression_dependencies(id, ops[2]);
e->base_expression = ops[2];
}
else
{
auto expr = access_chain_internal(ops[2], &ops[3], length, ACCESS_CHAIN_INDEX_IS_LITERAL_BIT, &meta);
e = &emit_op(result_type, id, expr, should_forward(ops[2]), !expression_is_forwarded(ops[2]));
inherit_expression_dependencies(id, ops[2]);
}
// Pass through some meta information to the loaded expression.
// We can still end up loading a buffer type to a variable, then CompositeExtract from it
// instead of loading everything through an access chain.
e->need_transpose = meta.need_transpose;
if (meta.storage_is_packed)
set_extended_decoration(id, SPIRVCrossDecorationPacked);
if (meta.storage_packed_type != 0)
set_extended_decoration(id, SPIRVCrossDecorationPackedType, meta.storage_packed_type);
if (meta.storage_is_invariant)
set_decoration(id, DecorationInvariant);
break;
}
case OpCompositeInsert:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t obj = ops[2];
uint32_t composite = ops[3];
const auto *elems = &ops[4];
length -= 4;
flush_variable_declaration(composite);
// Make a copy, then use access chain to store the variable.
statement(declare_temporary(result_type, id), to_expression(composite), ";");
set<SPIRExpression>(id, to_name(id), result_type, true);
auto chain = access_chain_internal(id, elems, length, ACCESS_CHAIN_INDEX_IS_LITERAL_BIT, nullptr);
statement(chain, " = ", to_expression(obj), ";");
break;
}
case OpCopyMemory:
{
uint32_t lhs = ops[0];
uint32_t rhs = ops[1];
if (lhs != rhs)
{
flush_variable_declaration(lhs);
flush_variable_declaration(rhs);
statement(to_expression(lhs), " = ", to_expression(rhs), ";");
register_write(lhs);
}
break;
}
case OpCopyObject:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t rhs = ops[2];
bool pointer = get<SPIRType>(result_type).pointer;
if (expression_is_lvalue(rhs) && !pointer)
{
// Need a copy.
// For pointer types, we copy the pointer itself.
statement(declare_temporary(result_type, id), to_expression(rhs), ";");
set<SPIRExpression>(id, to_name(id), result_type, true);
inherit_expression_dependencies(id, rhs);
}
else
{
// RHS expression is immutable, so just forward it.
// Copying these things really make no sense, but
// seems to be allowed anyways.
auto &e = set<SPIRExpression>(id, to_expression(rhs), result_type, true);
if (pointer)
{
auto *var = maybe_get_backing_variable(rhs);
e.loaded_from = var ? var->self : 0;
}
}
break;
}
case OpVectorShuffle:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t vec0 = ops[2];
uint32_t vec1 = ops[3];
const auto *elems = &ops[4];
length -= 4;
auto &type0 = expression_type(vec0);
// If we have the undefined swizzle index -1, we need to swizzle in undefined data,
// or in our case, T(0).
bool shuffle = false;
for (uint32_t i = 0; i < length; i++)
if (elems[i] >= type0.vecsize || elems[i] == 0xffffffffu)
shuffle = true;
// Cannot use swizzles with packed expressions, force shuffle path.
if (!shuffle && has_extended_decoration(vec0, SPIRVCrossDecorationPacked))
shuffle = true;
string expr;
bool should_fwd, trivial_forward;
if (shuffle)
{
should_fwd = should_forward(vec0) && should_forward(vec1);
trivial_forward = !expression_is_forwarded(vec0) && !expression_is_forwarded(vec1);
// Constructor style and shuffling from two different vectors.
vector<string> args;
for (uint32_t i = 0; i < length; i++)
{
if (elems[i] == 0xffffffffu)
{
// Use a constant 0 here.
// We could use the first component or similar, but then we risk propagating
// a value we might not need, and bog down codegen.
SPIRConstant c;
c.constant_type = type0.parent_type;
assert(type0.parent_type != 0);
args.push_back(constant_expression(c));
}
else if (elems[i] >= type0.vecsize)
args.push_back(to_extract_component_expression(vec1, elems[i] - type0.vecsize));
else
args.push_back(to_extract_component_expression(vec0, elems[i]));
}
expr += join(type_to_glsl_constructor(get<SPIRType>(result_type)), "(", merge(args), ")");
}
else
{
should_fwd = should_forward(vec0);
trivial_forward = !expression_is_forwarded(vec0);
// We only source from first vector, so can use swizzle.
// If the vector is packed, unpack it before applying a swizzle (needed for MSL)
expr += to_enclosed_unpacked_expression(vec0);
expr += ".";
for (uint32_t i = 0; i < length; i++)
{
assert(elems[i] != 0xffffffffu);
expr += index_to_swizzle(elems[i]);
}
if (backend.swizzle_is_function && length > 1)
expr += "()";
}
// A shuffle is trivial in that it doesn't actually *do* anything.
// We inherit the forwardedness from our arguments to avoid flushing out to temporaries when it's not really needed.
emit_op(result_type, id, expr, should_fwd, trivial_forward);
inherit_expression_dependencies(id, vec0);
inherit_expression_dependencies(id, vec1);
break;
}
// ALU
case OpIsNan:
GLSL_UFOP(isnan);
break;
case OpIsInf:
GLSL_UFOP(isinf);
break;
case OpSNegate:
case OpFNegate:
GLSL_UOP(-);
break;
case OpIAdd:
{
// For simple arith ops, prefer the output type if there's a mismatch to avoid extra bitcasts.
auto type = get<SPIRType>(ops[0]).basetype;
GLSL_BOP_CAST(+, type);
break;
}
case OpFAdd:
GLSL_BOP(+);
break;
case OpISub:
{
auto type = get<SPIRType>(ops[0]).basetype;
GLSL_BOP_CAST(-, type);
break;
}
case OpFSub:
GLSL_BOP(-);
break;
case OpIMul:
{
auto type = get<SPIRType>(ops[0]).basetype;
GLSL_BOP_CAST(*, type);
break;
}
case OpVectorTimesMatrix:
case OpMatrixTimesVector:
{
// If the matrix needs transpose, just flip the multiply order.
auto *e = maybe_get<SPIRExpression>(ops[opcode == OpMatrixTimesVector ? 2 : 3]);
if (e && e->need_transpose)
{
e->need_transpose = false;
emit_binary_op(ops[0], ops[1], ops[3], ops[2], "*");
e->need_transpose = true;
}
else
GLSL_BOP(*);
break;
}
case OpFMul:
case OpMatrixTimesScalar:
case OpVectorTimesScalar:
case OpMatrixTimesMatrix:
GLSL_BOP(*);
break;
case OpOuterProduct:
GLSL_BFOP(outerProduct);
break;
case OpDot:
GLSL_BFOP(dot);
break;
case OpTranspose:
GLSL_UFOP(transpose);
break;
case OpSRem:
{
uint32_t result_type = ops[0];
uint32_t result_id = ops[1];
uint32_t op0 = ops[2];
uint32_t op1 = ops[3];
// Needs special handling.
bool forward = should_forward(op0) && should_forward(op1);
auto expr = join(to_enclosed_expression(op0), " - ", to_enclosed_expression(op1), " * ", "(",
to_enclosed_expression(op0), " / ", to_enclosed_expression(op1), ")");
emit_op(result_type, result_id, expr, forward);
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
break;
}
case OpSDiv:
GLSL_BOP_CAST(/, int_type);
break;
case OpUDiv:
GLSL_BOP_CAST(/, uint_type);
break;
case OpIAddCarry:
case OpISubBorrow:
{
if (options.es && options.version < 310)
SPIRV_CROSS_THROW("Extended arithmetic is only available from ESSL 310.");
else if (!options.es && options.version < 400)
SPIRV_CROSS_THROW("Extended arithmetic is only available from GLSL 400.");
uint32_t result_type = ops[0];
uint32_t result_id = ops[1];
uint32_t op0 = ops[2];
uint32_t op1 = ops[3];
forced_temporaries.insert(result_id);
auto &type = get<SPIRType>(result_type);
auto &flags = ir.meta[result_id].decoration.decoration_flags;
statement(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, to_name(result_id)), ";");
set<SPIRExpression>(result_id, to_name(result_id), result_type, true);
const char *op = opcode == OpIAddCarry ? "uaddCarry" : "usubBorrow";
statement(to_expression(result_id), ".", to_member_name(type, 0), " = ", op, "(", to_expression(op0), ", ",
to_expression(op1), ", ", to_expression(result_id), ".", to_member_name(type, 1), ");");
break;
}
case OpUMulExtended:
case OpSMulExtended:
{
if (options.es && options.version < 310)
SPIRV_CROSS_THROW("Extended arithmetic is only available from ESSL 310.");
else if (!options.es && options.version < 400)
SPIRV_CROSS_THROW("Extended arithmetic is only available from GLSL 4000.");
uint32_t result_type = ops[0];
uint32_t result_id = ops[1];
uint32_t op0 = ops[2];
uint32_t op1 = ops[3];
forced_temporaries.insert(result_id);
auto &type = get<SPIRType>(result_type);
auto &flags = ir.meta[result_id].decoration.decoration_flags;
statement(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, to_name(result_id)), ";");
set<SPIRExpression>(result_id, to_name(result_id), result_type, true);
const char *op = opcode == OpUMulExtended ? "umulExtended" : "imulExtended";
statement(op, "(", to_expression(op0), ", ", to_expression(op1), ", ", to_expression(result_id), ".",
to_member_name(type, 1), ", ", to_expression(result_id), ".", to_member_name(type, 0), ");");
break;
}
case OpFDiv:
GLSL_BOP(/);
break;
case OpShiftRightLogical:
GLSL_BOP_CAST(>>, uint_type);
break;
case OpShiftRightArithmetic:
GLSL_BOP_CAST(>>, int_type);
break;
case OpShiftLeftLogical:
{
auto type = get<SPIRType>(ops[0]).basetype;
GLSL_BOP_CAST(<<, type);
break;
}
case OpBitwiseOr:
{
auto type = get<SPIRType>(ops[0]).basetype;
GLSL_BOP_CAST(|, type);
break;
}
case OpBitwiseXor:
{
auto type = get<SPIRType>(ops[0]).basetype;
GLSL_BOP_CAST(^, type);
break;
}
case OpBitwiseAnd:
{
auto type = get<SPIRType>(ops[0]).basetype;
GLSL_BOP_CAST(&, type);
break;
}
case OpNot:
GLSL_UOP(~);
break;
case OpUMod:
GLSL_BOP_CAST(%, uint_type);
break;
case OpSMod:
GLSL_BOP_CAST(%, int_type);
break;
case OpFMod:
GLSL_BFOP(mod);
break;
case OpFRem:
{
if (is_legacy())
SPIRV_CROSS_THROW("OpFRem requires trunc() and is only supported on non-legacy targets. A workaround is "
"needed for legacy.");
uint32_t result_type = ops[0];
uint32_t result_id = ops[1];
uint32_t op0 = ops[2];
uint32_t op1 = ops[3];
// Needs special handling.
bool forward = should_forward(op0) && should_forward(op1);
auto expr = join(to_enclosed_expression(op0), " - ", to_enclosed_expression(op1), " * ", "trunc(",
to_enclosed_expression(op0), " / ", to_enclosed_expression(op1), ")");
emit_op(result_type, result_id, expr, forward);
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
break;
}
// Relational
case OpAny:
GLSL_UFOP(any);
break;
case OpAll:
GLSL_UFOP(all);
break;
case OpSelect:
emit_mix_op(ops[0], ops[1], ops[4], ops[3], ops[2]);
break;
case OpLogicalOr:
{
// No vector variant in GLSL for logical OR.
auto result_type = ops[0];
auto id = ops[1];
auto &type = get<SPIRType>(result_type);
if (type.vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "||");
else
GLSL_BOP(||);
break;
}
case OpLogicalAnd:
{
// No vector variant in GLSL for logical AND.
auto result_type = ops[0];
auto id = ops[1];
auto &type = get<SPIRType>(result_type);
if (type.vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "&&");
else
GLSL_BOP(&&);
break;
}
case OpLogicalNot:
{
auto &type = get<SPIRType>(ops[0]);
if (type.vecsize > 1)
GLSL_UFOP(not);
else
GLSL_UOP(!);
break;
}
case OpIEqual:
{
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP_CAST(equal, int_type);
else
GLSL_BOP_CAST(==, int_type);
break;
}
case OpLogicalEqual:
case OpFOrdEqual:
{
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP(equal);
else
GLSL_BOP(==);
break;
}
case OpINotEqual:
{
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP_CAST(notEqual, int_type);
else
GLSL_BOP_CAST(!=, int_type);
break;
}
case OpLogicalNotEqual:
case OpFOrdNotEqual:
{
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP(notEqual);
else
GLSL_BOP(!=);
break;
}
case OpUGreaterThan:
case OpSGreaterThan:
{
auto type = opcode == OpUGreaterThan ? SPIRType::UInt : SPIRType::Int;
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP_CAST(greaterThan, type);
else
GLSL_BOP_CAST(>, type);
break;
}
case OpFOrdGreaterThan:
{
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP(greaterThan);
else
GLSL_BOP(>);
break;
}
case OpUGreaterThanEqual:
case OpSGreaterThanEqual:
{
auto type = opcode == OpUGreaterThanEqual ? SPIRType::UInt : SPIRType::Int;
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP_CAST(greaterThanEqual, type);
else
GLSL_BOP_CAST(>=, type);
break;
}
case OpFOrdGreaterThanEqual:
{
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP(greaterThanEqual);
else
GLSL_BOP(>=);
break;
}
case OpULessThan:
case OpSLessThan:
{
auto type = opcode == OpULessThan ? SPIRType::UInt : SPIRType::Int;
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP_CAST(lessThan, type);
else
GLSL_BOP_CAST(<, type);
break;
}
case OpFOrdLessThan:
{
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP(lessThan);
else
GLSL_BOP(<);
break;
}
case OpULessThanEqual:
case OpSLessThanEqual:
{
auto type = opcode == OpULessThanEqual ? SPIRType::UInt : SPIRType::Int;
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP_CAST(lessThanEqual, type);
else
GLSL_BOP_CAST(<=, type);
break;
}
case OpFOrdLessThanEqual:
{
if (expression_type(ops[2]).vecsize > 1)
GLSL_BFOP(lessThanEqual);
else
GLSL_BOP(<=);
break;
}
// Conversion
case OpConvertFToU:
case OpConvertFToS:
case OpConvertSToF:
case OpConvertUToF:
case OpUConvert:
case OpSConvert:
case OpFConvert:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
auto func = type_to_glsl_constructor(get<SPIRType>(result_type));
emit_unary_func_op(result_type, id, ops[2], func.c_str());
break;
}
case OpBitcast:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t arg = ops[2];
auto op = bitcast_glsl_op(get<SPIRType>(result_type), expression_type(arg));
emit_unary_func_op(result_type, id, arg, op.c_str());
break;
}
case OpQuantizeToF16:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t arg = ops[2];
string op;
auto &type = get<SPIRType>(result_type);
switch (type.vecsize)
{
case 1:
op = join("unpackHalf2x16(packHalf2x16(vec2(", to_expression(arg), "))).x");
break;
case 2:
op = join("unpackHalf2x16(packHalf2x16(", to_expression(arg), "))");
break;
case 3:
{
auto op0 = join("unpackHalf2x16(packHalf2x16(", to_expression(arg), ".xy))");
auto op1 = join("unpackHalf2x16(packHalf2x16(", to_expression(arg), ".zz)).x");
op = join("vec3(", op0, ", ", op1, ")");
break;
}
case 4:
{
auto op0 = join("unpackHalf2x16(packHalf2x16(", to_expression(arg), ".xy))");
auto op1 = join("unpackHalf2x16(packHalf2x16(", to_expression(arg), ".zw))");
op = join("vec4(", op0, ", ", op1, ")");
break;
}
default:
SPIRV_CROSS_THROW("Illegal argument to OpQuantizeToF16.");
}
emit_op(result_type, id, op, should_forward(arg));
inherit_expression_dependencies(id, arg);
break;
}
// Derivatives
case OpDPdx:
GLSL_UFOP(dFdx);
if (is_legacy_es())
require_extension_internal("GL_OES_standard_derivatives");
register_control_dependent_expression(ops[1]);
break;
case OpDPdy:
GLSL_UFOP(dFdy);
if (is_legacy_es())
require_extension_internal("GL_OES_standard_derivatives");
register_control_dependent_expression(ops[1]);
break;
case OpDPdxFine:
GLSL_UFOP(dFdxFine);
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
}
if (options.version < 450)
require_extension_internal("GL_ARB_derivative_control");
register_control_dependent_expression(ops[1]);
break;
case OpDPdyFine:
GLSL_UFOP(dFdyFine);
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
}
if (options.version < 450)
require_extension_internal("GL_ARB_derivative_control");
register_control_dependent_expression(ops[1]);
break;
case OpDPdxCoarse:
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
}
GLSL_UFOP(dFdxCoarse);
if (options.version < 450)
require_extension_internal("GL_ARB_derivative_control");
register_control_dependent_expression(ops[1]);
break;
case OpDPdyCoarse:
GLSL_UFOP(dFdyCoarse);
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
}
if (options.version < 450)
require_extension_internal("GL_ARB_derivative_control");
register_control_dependent_expression(ops[1]);
break;
case OpFwidth:
GLSL_UFOP(fwidth);
if (is_legacy_es())
require_extension_internal("GL_OES_standard_derivatives");
register_control_dependent_expression(ops[1]);
break;
case OpFwidthCoarse:
GLSL_UFOP(fwidthCoarse);
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
}
if (options.version < 450)
require_extension_internal("GL_ARB_derivative_control");
register_control_dependent_expression(ops[1]);
break;
case OpFwidthFine:
GLSL_UFOP(fwidthFine);
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
}
if (options.version < 450)
require_extension_internal("GL_ARB_derivative_control");
register_control_dependent_expression(ops[1]);
break;
// Bitfield
case OpBitFieldInsert:
// TODO: The signedness of inputs is strict in GLSL, but not in SPIR-V, bitcast if necessary.
GLSL_QFOP(bitfieldInsert);
break;
case OpBitFieldSExtract:
case OpBitFieldUExtract:
// TODO: The signedness of inputs is strict in GLSL, but not in SPIR-V, bitcast if necessary.
GLSL_TFOP(bitfieldExtract);
break;
case OpBitReverse:
GLSL_UFOP(bitfieldReverse);
break;
case OpBitCount:
GLSL_UFOP(bitCount);
break;
// Atomics
case OpAtomicExchange:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t ptr = ops[2];
// Ignore semantics for now, probably only relevant to CL.
uint32_t val = ops[5];
const char *op = check_atomic_image(ptr) ? "imageAtomicExchange" : "atomicExchange";
forced_temporaries.insert(id);
emit_binary_func_op(result_type, id, ptr, val, op);
flush_all_atomic_capable_variables();
break;
}
case OpAtomicCompareExchange:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t ptr = ops[2];
uint32_t val = ops[6];
uint32_t comp = ops[7];
const char *op = check_atomic_image(ptr) ? "imageAtomicCompSwap" : "atomicCompSwap";
forced_temporaries.insert(id);
emit_trinary_func_op(result_type, id, ptr, comp, val, op);
flush_all_atomic_capable_variables();
break;
}
case OpAtomicLoad:
flush_all_atomic_capable_variables();
// FIXME: Image?
// OpAtomicLoad seems to only be relevant for atomic counters.
GLSL_UFOP(atomicCounter);
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
case OpAtomicStore:
SPIRV_CROSS_THROW("Unsupported opcode OpAtomicStore.");
case OpAtomicIIncrement:
case OpAtomicIDecrement:
{
forced_temporaries.insert(ops[1]);
auto &type = expression_type(ops[2]);
if (type.storage == StorageClassAtomicCounter)
{
// Legacy GLSL stuff, not sure if this is relevant to support.
if (opcode == OpAtomicIIncrement)
GLSL_UFOP(atomicCounterIncrement);
else
GLSL_UFOP(atomicCounterDecrement);
}
else
{
bool atomic_image = check_atomic_image(ops[2]);
bool unsigned_type = (type.basetype == SPIRType::UInt) ||
(atomic_image && get<SPIRType>(type.image.type).basetype == SPIRType::UInt);
const char *op = atomic_image ? "imageAtomicAdd" : "atomicAdd";
const char *increment = nullptr;
if (opcode == OpAtomicIIncrement && unsigned_type)
increment = "1u";
else if (opcode == OpAtomicIIncrement)
increment = "1";
else if (unsigned_type)
increment = "uint(-1)";
else
increment = "-1";
emit_op(ops[0], ops[1], join(op, "(", to_expression(ops[2]), ", ", increment, ")"), false);
}
flush_all_atomic_capable_variables();
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
}
case OpAtomicIAdd:
{
const char *op = check_atomic_image(ops[2]) ? "imageAtomicAdd" : "atomicAdd";
forced_temporaries.insert(ops[1]);
emit_binary_func_op(ops[0], ops[1], ops[2], ops[5], op);
flush_all_atomic_capable_variables();
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
}
case OpAtomicISub:
{
const char *op = check_atomic_image(ops[2]) ? "imageAtomicAdd" : "atomicAdd";
forced_temporaries.insert(ops[1]);
auto expr = join(op, "(", to_expression(ops[2]), ", -", to_enclosed_expression(ops[5]), ")");
emit_op(ops[0], ops[1], expr, should_forward(ops[2]) && should_forward(ops[5]));
flush_all_atomic_capable_variables();
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
}
case OpAtomicSMin:
case OpAtomicUMin:
{
const char *op = check_atomic_image(ops[2]) ? "imageAtomicMin" : "atomicMin";
forced_temporaries.insert(ops[1]);
emit_binary_func_op(ops[0], ops[1], ops[2], ops[5], op);
flush_all_atomic_capable_variables();
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
}
case OpAtomicSMax:
case OpAtomicUMax:
{
const char *op = check_atomic_image(ops[2]) ? "imageAtomicMax" : "atomicMax";
forced_temporaries.insert(ops[1]);
emit_binary_func_op(ops[0], ops[1], ops[2], ops[5], op);
flush_all_atomic_capable_variables();
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
}
case OpAtomicAnd:
{
const char *op = check_atomic_image(ops[2]) ? "imageAtomicAnd" : "atomicAnd";
forced_temporaries.insert(ops[1]);
emit_binary_func_op(ops[0], ops[1], ops[2], ops[5], op);
flush_all_atomic_capable_variables();
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
}
case OpAtomicOr:
{
const char *op = check_atomic_image(ops[2]) ? "imageAtomicOr" : "atomicOr";
forced_temporaries.insert(ops[1]);
emit_binary_func_op(ops[0], ops[1], ops[2], ops[5], op);
flush_all_atomic_capable_variables();
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
}
case OpAtomicXor:
{
const char *op = check_atomic_image(ops[2]) ? "imageAtomicXor" : "atomicXor";
forced_temporaries.insert(ops[1]);
emit_binary_func_op(ops[0], ops[1], ops[2], ops[5], op);
flush_all_atomic_capable_variables();
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
}
// Geometry shaders
case OpEmitVertex:
statement("EmitVertex();");
break;
case OpEndPrimitive:
statement("EndPrimitive();");
break;
case OpEmitStreamVertex:
statement("EmitStreamVertex();");
break;
case OpEndStreamPrimitive:
statement("EndStreamPrimitive();");
break;
// Textures
case OpImageSampleExplicitLod:
case OpImageSampleProjExplicitLod:
case OpImageSampleDrefExplicitLod:
case OpImageSampleProjDrefExplicitLod:
case OpImageSampleImplicitLod:
case OpImageSampleProjImplicitLod:
case OpImageSampleDrefImplicitLod:
case OpImageSampleProjDrefImplicitLod:
case OpImageFetch:
case OpImageGather:
case OpImageDrefGather:
// Gets a bit hairy, so move this to a separate instruction.
emit_texture_op(instruction);
break;
case OpImage:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
// Suppress usage tracking.
auto &e = emit_op(result_type, id, to_expression(ops[2]), true, true);
// When using the image, we need to know which variable it is actually loaded from.
auto *var = maybe_get_backing_variable(ops[2]);
e.loaded_from = var ? var->self : 0;
break;
}
case OpImageQueryLod:
{
if (!options.es && options.version < 400)
{
require_extension_internal("GL_ARB_texture_query_lod");
// For some reason, the ARB spec is all-caps.
GLSL_BFOP(textureQueryLOD);
}
else if (options.es)
SPIRV_CROSS_THROW("textureQueryLod not supported in ES profile.");
else
GLSL_BFOP(textureQueryLod);
register_control_dependent_expression(ops[1]);
break;
}
case OpImageQueryLevels:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
if (!options.es && options.version < 430)
require_extension_internal("GL_ARB_texture_query_levels");
if (options.es)
SPIRV_CROSS_THROW("textureQueryLevels not supported in ES profile.");
auto expr = join("textureQueryLevels(", convert_separate_image_to_expression(ops[2]), ")");
auto &restype = get<SPIRType>(ops[0]);
expr = bitcast_expression(restype, SPIRType::Int, expr);
emit_op(result_type, id, expr, true);
break;
}
case OpImageQuerySamples:
{
auto &type = expression_type(ops[2]);
uint32_t result_type = ops[0];
uint32_t id = ops[1];
string expr;
if (type.image.sampled == 2)
expr = join("imageSamples(", to_expression(ops[2]), ")");
else
expr = join("textureSamples(", convert_separate_image_to_expression(ops[2]), ")");
auto &restype = get<SPIRType>(ops[0]);
expr = bitcast_expression(restype, SPIRType::Int, expr);
emit_op(result_type, id, expr, true);
break;
}
case OpSampledImage:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
emit_sampled_image_op(result_type, id, ops[2], ops[3]);
break;
}
case OpImageQuerySizeLod:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
auto expr = join("textureSize(", convert_separate_image_to_expression(ops[2]), ", ",
bitcast_expression(SPIRType::Int, ops[3]), ")");
auto &restype = get<SPIRType>(ops[0]);
expr = bitcast_expression(restype, SPIRType::Int, expr);
emit_op(result_type, id, expr, true);
break;
}
// Image load/store
case OpImageRead:
{
// We added Nonreadable speculatively to the OpImage variable due to glslangValidator
// not adding the proper qualifiers.
// If it turns out we need to read the image after all, remove the qualifier and recompile.
auto *var = maybe_get_backing_variable(ops[2]);
if (var)
{
auto &flags = ir.meta[var->self].decoration.decoration_flags;
if (flags.get(DecorationNonReadable))
{
flags.clear(DecorationNonReadable);
force_recompile = true;
}
}
uint32_t result_type = ops[0];
uint32_t id = ops[1];
bool pure;
string imgexpr;
auto &type = expression_type(ops[2]);
if (var && var->remapped_variable) // Remapped input, just read as-is without any op-code
{
if (type.image.ms)
SPIRV_CROSS_THROW("Trying to remap multisampled image to variable, this is not possible.");
auto itr =
find_if(begin(pls_inputs), end(pls_inputs), [var](const PlsRemap &pls) { return pls.id == var->self; });
if (itr == end(pls_inputs))
{
// For non-PLS inputs, we rely on subpass type remapping information to get it right
// since ImageRead always returns 4-component vectors and the backing type is opaque.
if (!var->remapped_components)
SPIRV_CROSS_THROW("subpassInput was remapped, but remap_components is not set correctly.");
imgexpr = remap_swizzle(get<SPIRType>(result_type), var->remapped_components, to_expression(ops[2]));
}
else
{
// PLS input could have different number of components than what the SPIR expects, swizzle to
// the appropriate vector size.
uint32_t components = pls_format_to_components(itr->format);
imgexpr = remap_swizzle(get<SPIRType>(result_type), components, to_expression(ops[2]));
}
pure = true;
}
else if (type.image.dim == DimSubpassData)
{
if (options.vulkan_semantics)
{
// With Vulkan semantics, use the proper Vulkan GLSL construct.
if (type.image.ms)
{
uint32_t operands = ops[4];
if (operands != ImageOperandsSampleMask || length != 6)
SPIRV_CROSS_THROW(
"Multisampled image used in OpImageRead, but unexpected operand mask was used.");
uint32_t samples = ops[5];
imgexpr = join("subpassLoad(", to_expression(ops[2]), ", ", to_expression(samples), ")");
}
else
imgexpr = join("subpassLoad(", to_expression(ops[2]), ")");
}
else
{
if (type.image.ms)
{
uint32_t operands = ops[4];
if (operands != ImageOperandsSampleMask || length != 6)
SPIRV_CROSS_THROW(
"Multisampled image used in OpImageRead, but unexpected operand mask was used.");
uint32_t samples = ops[5];
imgexpr = join("texelFetch(", to_expression(ops[2]), ", ivec2(gl_FragCoord.xy), ",
to_expression(samples), ")");
}
else
{
// Implement subpass loads via texture barrier style sampling.
imgexpr = join("texelFetch(", to_expression(ops[2]), ", ivec2(gl_FragCoord.xy), 0)");
}
}
imgexpr = remap_swizzle(get<SPIRType>(result_type), 4, imgexpr);
pure = true;
}
else
{
// imageLoad only accepts int coords, not uint.
auto coord_expr = to_expression(ops[3]);
auto target_coord_type = expression_type(ops[3]);
target_coord_type.basetype = SPIRType::Int;
coord_expr = bitcast_expression(target_coord_type, expression_type(ops[3]).basetype, coord_expr);
// Plain image load/store.
if (type.image.ms)
{
uint32_t operands = ops[4];
if (operands != ImageOperandsSampleMask || length != 6)
SPIRV_CROSS_THROW("Multisampled image used in OpImageRead, but unexpected operand mask was used.");
uint32_t samples = ops[5];
imgexpr =
join("imageLoad(", to_expression(ops[2]), ", ", coord_expr, ", ", to_expression(samples), ")");
}
else
imgexpr = join("imageLoad(", to_expression(ops[2]), ", ", coord_expr, ")");
imgexpr = remap_swizzle(get<SPIRType>(result_type), 4, imgexpr);
pure = false;
}
if (var && var->forwardable)
{
bool forward = forced_temporaries.find(id) == end(forced_temporaries);
auto &e = emit_op(result_type, id, imgexpr, forward);
// We only need to track dependencies if we're reading from image load/store.
if (!pure)
{
e.loaded_from = var->self;
if (forward)
var->dependees.push_back(id);
}
}
else
emit_op(result_type, id, imgexpr, false);
inherit_expression_dependencies(id, ops[2]);
if (type.image.ms)
inherit_expression_dependencies(id, ops[5]);
break;
}
case OpImageTexelPointer:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
auto &e = set<SPIRExpression>(id, join(to_expression(ops[2]), ", ", to_expression(ops[3])), result_type, true);
// When using the pointer, we need to know which variable it is actually loaded from.
auto *var = maybe_get_backing_variable(ops[2]);
e.loaded_from = var ? var->self : 0;
break;
}
case OpImageWrite:
{
// We added Nonwritable speculatively to the OpImage variable due to glslangValidator
// not adding the proper qualifiers.
// If it turns out we need to write to the image after all, remove the qualifier and recompile.
auto *var = maybe_get_backing_variable(ops[0]);
if (var)
{
auto &flags = ir.meta[var->self].decoration.decoration_flags;
if (flags.get(DecorationNonWritable))
{
flags.clear(DecorationNonWritable);
force_recompile = true;
}
}
auto &type = expression_type(ops[0]);
auto &value_type = expression_type(ops[2]);
auto store_type = value_type;
store_type.vecsize = 4;
// imageStore only accepts int coords, not uint.
auto coord_expr = to_expression(ops[1]);
auto target_coord_type = expression_type(ops[1]);
target_coord_type.basetype = SPIRType::Int;
coord_expr = bitcast_expression(target_coord_type, expression_type(ops[1]).basetype, coord_expr);
if (type.image.ms)
{
uint32_t operands = ops[3];
if (operands != ImageOperandsSampleMask || length != 5)
SPIRV_CROSS_THROW("Multisampled image used in OpImageWrite, but unexpected operand mask was used.");
uint32_t samples = ops[4];
statement("imageStore(", to_expression(ops[0]), ", ", coord_expr, ", ", to_expression(samples), ", ",
remap_swizzle(store_type, value_type.vecsize, to_expression(ops[2])), ");");
}
else
statement("imageStore(", to_expression(ops[0]), ", ", coord_expr, ", ",
remap_swizzle(store_type, value_type.vecsize, to_expression(ops[2])), ");");
if (var && variable_storage_is_aliased(*var))
flush_all_aliased_variables();
break;
}
case OpImageQuerySize:
{
auto &type = expression_type(ops[2]);
uint32_t result_type = ops[0];
uint32_t id = ops[1];
if (type.basetype == SPIRType::Image)
{
string expr;
if (type.image.sampled == 2)
{
// The size of an image is always constant.
expr = join("imageSize(", to_expression(ops[2]), ")");
}
else
{
// This path is hit for samplerBuffers and multisampled images which do not have LOD.
expr = join("textureSize(", convert_separate_image_to_expression(ops[2]), ")");
}
auto &restype = get<SPIRType>(ops[0]);
expr = bitcast_expression(restype, SPIRType::Int, expr);
emit_op(result_type, id, expr, true);
}
else
SPIRV_CROSS_THROW("Invalid type for OpImageQuerySize.");
break;
}
// Compute
case OpControlBarrier:
case OpMemoryBarrier:
{
uint32_t execution_scope = 0;
uint32_t memory;
uint32_t semantics;
if (opcode == OpMemoryBarrier)
{
memory = get<SPIRConstant>(ops[0]).scalar();
semantics = get<SPIRConstant>(ops[1]).scalar();
}
else
{
execution_scope = get<SPIRConstant>(ops[0]).scalar();
memory = get<SPIRConstant>(ops[1]).scalar();
semantics = get<SPIRConstant>(ops[2]).scalar();
}
if (execution_scope == ScopeSubgroup || memory == ScopeSubgroup)
{
if (!options.vulkan_semantics)
SPIRV_CROSS_THROW("Can only use subgroup operations in Vulkan semantics.");
require_extension_internal("GL_KHR_shader_subgroup_basic");
}
if (execution_scope != ScopeSubgroup && get_entry_point().model == ExecutionModelTessellationControl)
{
// Control shaders only have barriers, and it implies memory barriers.
if (opcode == OpControlBarrier)
statement("barrier();");
break;
}
// We only care about these flags, acquire/release and friends are not relevant to GLSL.
semantics = mask_relevant_memory_semantics(semantics);
if (opcode == OpMemoryBarrier)
{
// If we are a memory barrier, and the next instruction is a control barrier, check if that memory barrier
// does what we need, so we avoid redundant barriers.
const Instruction *next = get_next_instruction_in_block(instruction);
if (next && next->op == OpControlBarrier)
{
auto *next_ops = stream(*next);
uint32_t next_memory = get<SPIRConstant>(next_ops[1]).scalar();
uint32_t next_semantics = get<SPIRConstant>(next_ops[2]).scalar();
next_semantics = mask_relevant_memory_semantics(next_semantics);
bool memory_scope_covered = false;
if (next_memory == memory)
memory_scope_covered = true;
else if (next_semantics == MemorySemanticsWorkgroupMemoryMask)
{
// If we only care about workgroup memory, either Device or Workgroup scope is fine,
// scope does not have to match.
if ((next_memory == ScopeDevice || next_memory == ScopeWorkgroup) &&
(memory == ScopeDevice || memory == ScopeWorkgroup))
{
memory_scope_covered = true;
}
}
else if (memory == ScopeWorkgroup && next_memory == ScopeDevice)
{
// The control barrier has device scope, but the memory barrier just has workgroup scope.
memory_scope_covered = true;
}
// If we have the same memory scope, and all memory types are covered, we're good.
if (memory_scope_covered && (semantics & next_semantics) == semantics)
break;
}
}
// We are synchronizing some memory or syncing execution,
// so we cannot forward any loads beyond the memory barrier.
if (semantics || opcode == OpControlBarrier)
{
assert(current_emitting_block);
flush_control_dependent_expressions(current_emitting_block->self);
flush_all_active_variables();
}
if (memory == ScopeWorkgroup) // Only need to consider memory within a group
{
if (semantics == MemorySemanticsWorkgroupMemoryMask)
statement("memoryBarrierShared();");
else if (semantics != 0)
statement("groupMemoryBarrier();");
}
else if (memory == ScopeSubgroup)
{
const uint32_t all_barriers =
MemorySemanticsWorkgroupMemoryMask | MemorySemanticsUniformMemoryMask | MemorySemanticsImageMemoryMask;
if (semantics & (MemorySemanticsCrossWorkgroupMemoryMask | MemorySemanticsSubgroupMemoryMask))
{
// These are not relevant for GLSL, but assume it means memoryBarrier().
// memoryBarrier() does everything, so no need to test anything else.
statement("subgroupMemoryBarrier();");
}
else if ((semantics & all_barriers) == all_barriers)
{
// Short-hand instead of emitting 3 barriers.
statement("subgroupMemoryBarrier();");
}
else
{
// Pick out individual barriers.
if (semantics & MemorySemanticsWorkgroupMemoryMask)
statement("subgroupMemoryBarrierShared();");
if (semantics & MemorySemanticsUniformMemoryMask)
statement("subgroupMemoryBarrierBuffer();");
if (semantics & MemorySemanticsImageMemoryMask)
statement("subgroupMemoryBarrierImage();");
}
}
else
{
const uint32_t all_barriers = MemorySemanticsWorkgroupMemoryMask | MemorySemanticsUniformMemoryMask |
MemorySemanticsImageMemoryMask | MemorySemanticsAtomicCounterMemoryMask;
if (semantics & (MemorySemanticsCrossWorkgroupMemoryMask | MemorySemanticsSubgroupMemoryMask))
{
// These are not relevant for GLSL, but assume it means memoryBarrier().
// memoryBarrier() does everything, so no need to test anything else.
statement("memoryBarrier();");
}
else if ((semantics & all_barriers) == all_barriers)
{
// Short-hand instead of emitting 4 barriers.
statement("memoryBarrier();");
}
else
{
// Pick out individual barriers.
if (semantics & MemorySemanticsWorkgroupMemoryMask)
statement("memoryBarrierShared();");
if (semantics & MemorySemanticsUniformMemoryMask)
statement("memoryBarrierBuffer();");
if (semantics & MemorySemanticsImageMemoryMask)
statement("memoryBarrierImage();");
if (semantics & MemorySemanticsAtomicCounterMemoryMask)
statement("memoryBarrierAtomicCounter();");
}
}
if (opcode == OpControlBarrier)
{
if (execution_scope == ScopeSubgroup)
statement("subgroupBarrier();");
else
statement("barrier();");
}
break;
}
case OpExtInst:
{
uint32_t extension_set = ops[2];
if (get<SPIRExtension>(extension_set).ext == SPIRExtension::GLSL)
{
emit_glsl_op(ops[0], ops[1], ops[3], &ops[4], length - 4);
}
else if (get<SPIRExtension>(extension_set).ext == SPIRExtension::SPV_AMD_shader_ballot)
{
emit_spv_amd_shader_ballot_op(ops[0], ops[1], ops[3], &ops[4], length - 4);
}
else if (get<SPIRExtension>(extension_set).ext == SPIRExtension::SPV_AMD_shader_explicit_vertex_parameter)
{
emit_spv_amd_shader_explicit_vertex_parameter_op(ops[0], ops[1], ops[3], &ops[4], length - 4);
}
else if (get<SPIRExtension>(extension_set).ext == SPIRExtension::SPV_AMD_shader_trinary_minmax)
{
emit_spv_amd_shader_trinary_minmax_op(ops[0], ops[1], ops[3], &ops[4], length - 4);
}
else if (get<SPIRExtension>(extension_set).ext == SPIRExtension::SPV_AMD_gcn_shader)
{
emit_spv_amd_gcn_shader_op(ops[0], ops[1], ops[3], &ops[4], length - 4);
}
else
{
statement("// unimplemented ext op ", instruction.op);
break;
}
break;
}
// Legacy sub-group stuff ...
case OpSubgroupBallotKHR:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
string expr;
expr = join("uvec4(unpackUint2x32(ballotARB(" + to_expression(ops[2]) + ")), 0u, 0u)");
emit_op(result_type, id, expr, should_forward(ops[2]));
require_extension_internal("GL_ARB_shader_ballot");
inherit_expression_dependencies(id, ops[2]);
register_control_dependent_expression(ops[1]);
break;
}
case OpSubgroupFirstInvocationKHR:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
emit_unary_func_op(result_type, id, ops[2], "readFirstInvocationARB");
require_extension_internal("GL_ARB_shader_ballot");
register_control_dependent_expression(ops[1]);
break;
}
case OpSubgroupReadInvocationKHR:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
emit_binary_func_op(result_type, id, ops[2], ops[3], "readInvocationARB");
require_extension_internal("GL_ARB_shader_ballot");
register_control_dependent_expression(ops[1]);
break;
}
case OpSubgroupAllKHR:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
emit_unary_func_op(result_type, id, ops[2], "allInvocationsARB");
require_extension_internal("GL_ARB_shader_group_vote");
register_control_dependent_expression(ops[1]);
break;
}
case OpSubgroupAnyKHR:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
emit_unary_func_op(result_type, id, ops[2], "anyInvocationARB");
require_extension_internal("GL_ARB_shader_group_vote");
register_control_dependent_expression(ops[1]);
break;
}
case OpSubgroupAllEqualKHR:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
emit_unary_func_op(result_type, id, ops[2], "allInvocationsEqualARB");
require_extension_internal("GL_ARB_shader_group_vote");
register_control_dependent_expression(ops[1]);
break;
}
case OpGroupIAddNonUniformAMD:
case OpGroupFAddNonUniformAMD:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
emit_unary_func_op(result_type, id, ops[4], "addInvocationsNonUniformAMD");
require_extension_internal("GL_AMD_shader_ballot");
register_control_dependent_expression(ops[1]);
break;
}
case OpGroupFMinNonUniformAMD:
case OpGroupUMinNonUniformAMD:
case OpGroupSMinNonUniformAMD:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
emit_unary_func_op(result_type, id, ops[4], "minInvocationsNonUniformAMD");
require_extension_internal("GL_AMD_shader_ballot");
register_control_dependent_expression(ops[1]);
break;
}
case OpGroupFMaxNonUniformAMD:
case OpGroupUMaxNonUniformAMD:
case OpGroupSMaxNonUniformAMD:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
emit_unary_func_op(result_type, id, ops[4], "maxInvocationsNonUniformAMD");
require_extension_internal("GL_AMD_shader_ballot");
register_control_dependent_expression(ops[1]);
break;
}
case OpFragmentMaskFetchAMD:
{
auto &type = expression_type(ops[2]);
uint32_t result_type = ops[0];
uint32_t id = ops[1];
if (type.image.dim == spv::DimSubpassData)
{
emit_unary_func_op(result_type, id, ops[2], "fragmentMaskFetchAMD");
}
else
{
emit_binary_func_op(result_type, id, ops[2], ops[3], "fragmentMaskFetchAMD");
}
require_extension_internal("GL_AMD_shader_fragment_mask");
break;
}
case OpFragmentFetchAMD:
{
auto &type = expression_type(ops[2]);
uint32_t result_type = ops[0];
uint32_t id = ops[1];
if (type.image.dim == spv::DimSubpassData)
{
emit_binary_func_op(result_type, id, ops[2], ops[4], "fragmentFetchAMD");
}
else
{
emit_trinary_func_op(result_type, id, ops[2], ops[3], ops[4], "fragmentFetchAMD");
}
require_extension_internal("GL_AMD_shader_fragment_mask");
break;
}
// Vulkan 1.1 sub-group stuff ...
case OpGroupNonUniformElect:
case OpGroupNonUniformBroadcast:
case OpGroupNonUniformBroadcastFirst:
case OpGroupNonUniformBallot:
case OpGroupNonUniformInverseBallot:
case OpGroupNonUniformBallotBitExtract:
case OpGroupNonUniformBallotBitCount:
case OpGroupNonUniformBallotFindLSB:
case OpGroupNonUniformBallotFindMSB:
case OpGroupNonUniformShuffle:
case OpGroupNonUniformShuffleXor:
case OpGroupNonUniformShuffleUp:
case OpGroupNonUniformShuffleDown:
case OpGroupNonUniformAll:
case OpGroupNonUniformAny:
case OpGroupNonUniformAllEqual:
case OpGroupNonUniformFAdd:
case OpGroupNonUniformIAdd:
case OpGroupNonUniformFMul:
case OpGroupNonUniformIMul:
case OpGroupNonUniformFMin:
case OpGroupNonUniformFMax:
case OpGroupNonUniformSMin:
case OpGroupNonUniformSMax:
case OpGroupNonUniformUMin:
case OpGroupNonUniformUMax:
case OpGroupNonUniformBitwiseAnd:
case OpGroupNonUniformBitwiseOr:
case OpGroupNonUniformBitwiseXor:
case OpGroupNonUniformQuadSwap:
case OpGroupNonUniformQuadBroadcast:
emit_subgroup_op(instruction);
break;
case OpFUnordEqual:
GLSL_BFOP(unsupported_FUnordEqual);
break;
case OpFUnordNotEqual:
GLSL_BFOP(unsupported_FUnordNotEqual);
break;
case OpFUnordLessThan:
GLSL_BFOP(unsupported_FUnordLessThan);
break;
case OpFUnordGreaterThan:
GLSL_BFOP(unsupported_FUnordGreaterThan);
break;
case OpFUnordLessThanEqual:
GLSL_BFOP(unsupported_FUnordLessThanEqual);
break;
case OpFUnordGreaterThanEqual:
GLSL_BFOP(unsupported_FUnordGreaterThanEqual);
break;
case OpReportIntersectionNV:
statement("reportIntersectionNV(", to_expression(ops[0]), ", ", to_expression(ops[1]), ");");
break;
case OpIgnoreIntersectionNV:
statement("ignoreIntersectionNV();");
break;
case OpTerminateRayNV:
statement("terminateRayNV();");
break;
case OpTraceNV:
statement("traceNV(", to_expression(ops[0]), ", ", to_expression(ops[1]), ", ", to_expression(ops[2]), ", ",
to_expression(ops[3]), ", ", to_expression(ops[4]), ", ", to_expression(ops[5]), ", ",
to_expression(ops[6]), ", ", to_expression(ops[7]), ", ", to_expression(ops[8]), ", ",
to_expression(ops[9]), ", ", to_expression(ops[10]), ");");
break;
case OpExecuteCallableNV:
statement("executeCallableNV(", to_expression(ops[0]), ", ", to_expression(ops[1]), ");");
break;
default:
statement("// unimplemented op ", instruction.op);
break;
}
}
// Appends function arguments, mapped from global variables, beyond the specified arg index.
// This is used when a function call uses fewer arguments than the function defines.
// This situation may occur if the function signature has been dynamically modified to
// extract global variables referenced from within the function, and convert them to
// function arguments. This is necessary for shader languages that do not support global
// access to shader input content from within a function (eg. Metal). Each additional
// function args uses the name of the global variable. Function nesting will modify the
// functions and function calls all the way up the nesting chain.
void CompilerGLSL::append_global_func_args(const SPIRFunction &func, uint32_t index, vector<string> &arglist)
{
auto &args = func.arguments;
uint32_t arg_cnt = uint32_t(args.size());
for (uint32_t arg_idx = index; arg_idx < arg_cnt; arg_idx++)
{
auto &arg = args[arg_idx];
assert(arg.alias_global_variable);
// If the underlying variable needs to be declared
// (ie. a local variable with deferred declaration), do so now.
uint32_t var_id = get<SPIRVariable>(arg.id).basevariable;
if (var_id)
flush_variable_declaration(var_id);
arglist.push_back(to_func_call_arg(arg.id));
}
}
string CompilerGLSL::to_member_name(const SPIRType &type, uint32_t index)
{
auto &memb = ir.meta[type.self].members;
if (index < memb.size() && !memb[index].alias.empty())
return memb[index].alias;
else
return join("_m", index);
}
string CompilerGLSL::to_member_reference(uint32_t, const SPIRType &type, uint32_t index, bool)
{
return join(".", to_member_name(type, index));
}
void CompilerGLSL::add_member_name(SPIRType &type, uint32_t index)
{
auto &memb = ir.meta[type.self].members;
if (index < memb.size() && !memb[index].alias.empty())
{
auto &name = memb[index].alias;
if (name.empty())
return;
// Reserved for temporaries.
if (name[0] == '_' && name.size() >= 2 && isdigit(name[1]))
{
name.clear();
return;
}
update_name_cache(type.member_name_cache, name);
}
}
// Checks whether the ID is a row_major matrix that requires conversion before use
bool CompilerGLSL::is_non_native_row_major_matrix(uint32_t id)
{
// Natively supported row-major matrices do not need to be converted.
// Legacy targets do not support row major.
if (backend.native_row_major_matrix && !is_legacy())
return false;
// Non-matrix or column-major matrix types do not need to be converted.
if (!has_decoration(id, DecorationRowMajor))
return false;
// Only square row-major matrices can be converted at this time.
// Converting non-square matrices will require defining custom GLSL function that
// swaps matrix elements while retaining the original dimensional form of the matrix.
const auto type = expression_type(id);
if (type.columns != type.vecsize)
SPIRV_CROSS_THROW("Row-major matrices must be square on this platform.");
return true;
}
// Checks whether the member is a row_major matrix that requires conversion before use
bool CompilerGLSL::member_is_non_native_row_major_matrix(const SPIRType &type, uint32_t index)
{
// Natively supported row-major matrices do not need to be converted.
if (backend.native_row_major_matrix && !is_legacy())
return false;
// Non-matrix or column-major matrix types do not need to be converted.
if (!has_member_decoration(type.self, index, DecorationRowMajor))
return false;
// Only square row-major matrices can be converted at this time.
// Converting non-square matrices will require defining custom GLSL function that
// swaps matrix elements while retaining the original dimensional form of the matrix.
const auto mbr_type = get<SPIRType>(type.member_types[index]);
if (mbr_type.columns != mbr_type.vecsize)
SPIRV_CROSS_THROW("Row-major matrices must be square on this platform.");
return true;
}
// Checks whether the member is in packed data type, that might need to be unpacked.
// GLSL does not define packed data types, but certain subclasses do.
bool CompilerGLSL::member_is_packed_type(const SPIRType &type, uint32_t index) const
{
return has_extended_member_decoration(type.self, index, SPIRVCrossDecorationPacked);
}
// Wraps the expression string in a function call that converts the
// row_major matrix result of the expression to a column_major matrix.
// Base implementation uses the standard library transpose() function.
// Subclasses may override to use a different function.
string CompilerGLSL::convert_row_major_matrix(string exp_str, const SPIRType & /*exp_type*/, bool /*is_packed*/)
{
strip_enclosed_expression(exp_str);
return join("transpose(", exp_str, ")");
}
string CompilerGLSL::variable_decl(const SPIRType &type, const string &name, uint32_t id)
{
string type_name = type_to_glsl(type, id);
remap_variable_type_name(type, name, type_name);
return join(type_name, " ", name, type_to_array_glsl(type));
}
// Emit a structure member. Subclasses may override to modify output,
// or to dynamically add a padding member if needed.
void CompilerGLSL::emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index,
const string &qualifier, uint32_t)
{
auto &membertype = get<SPIRType>(member_type_id);
Bitset memberflags;
auto &memb = ir.meta[type.self].members;
if (index < memb.size())
memberflags = memb[index].decoration_flags;
string qualifiers;
bool is_block = ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock) ||
ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock);
if (is_block)
qualifiers = to_interpolation_qualifiers(memberflags);
statement(layout_for_member(type, index), qualifiers, qualifier,
flags_to_precision_qualifiers_glsl(membertype, memberflags),
variable_decl(membertype, to_member_name(type, index)), ";");
}
const char *CompilerGLSL::flags_to_precision_qualifiers_glsl(const SPIRType &type, const Bitset &flags)
{
// Structs do not have precision qualifiers, neither do doubles (desktop only anyways, so no mediump/highp).
if (type.basetype != SPIRType::Float && type.basetype != SPIRType::Int && type.basetype != SPIRType::UInt &&
type.basetype != SPIRType::Image && type.basetype != SPIRType::SampledImage &&
type.basetype != SPIRType::Sampler)
return "";
if (options.es)
{
auto &execution = get_entry_point();
if (flags.get(DecorationRelaxedPrecision))
{
bool implied_fmediump = type.basetype == SPIRType::Float &&
options.fragment.default_float_precision == Options::Mediump &&
execution.model == ExecutionModelFragment;
bool implied_imediump = (type.basetype == SPIRType::Int || type.basetype == SPIRType::UInt) &&
options.fragment.default_int_precision == Options::Mediump &&
execution.model == ExecutionModelFragment;
return implied_fmediump || implied_imediump ? "" : "mediump ";
}
else
{
bool implied_fhighp =
type.basetype == SPIRType::Float && ((options.fragment.default_float_precision == Options::Highp &&
execution.model == ExecutionModelFragment) ||
(execution.model != ExecutionModelFragment));
bool implied_ihighp = (type.basetype == SPIRType::Int || type.basetype == SPIRType::UInt) &&
((options.fragment.default_int_precision == Options::Highp &&
execution.model == ExecutionModelFragment) ||
(execution.model != ExecutionModelFragment));
return implied_fhighp || implied_ihighp ? "" : "highp ";
}
}
else if (backend.allow_precision_qualifiers)
{
// Vulkan GLSL supports precision qualifiers, even in desktop profiles, which is convenient.
// The default is highp however, so only emit mediump in the rare case that a shader has these.
if (flags.get(DecorationRelaxedPrecision))
return "mediump ";
else
return "";
}
else
return "";
}
const char *CompilerGLSL::to_precision_qualifiers_glsl(uint32_t id)
{
return flags_to_precision_qualifiers_glsl(expression_type(id), ir.meta[id].decoration.decoration_flags);
}
string CompilerGLSL::to_qualifiers_glsl(uint32_t id)
{
auto &flags = ir.meta[id].decoration.decoration_flags;
string res;
auto *var = maybe_get<SPIRVariable>(id);
if (var && var->storage == StorageClassWorkgroup && !backend.shared_is_implied)
res += "shared ";
res += to_interpolation_qualifiers(flags);
if (var)
res += to_storage_qualifiers_glsl(*var);
auto &type = expression_type(id);
if (type.image.dim != DimSubpassData && type.image.sampled == 2)
{
if (flags.get(DecorationCoherent))
res += "coherent ";
if (flags.get(DecorationRestrict))
res += "restrict ";
if (flags.get(DecorationNonWritable))
res += "readonly ";
if (flags.get(DecorationNonReadable))
res += "writeonly ";
}
res += to_precision_qualifiers_glsl(id);
return res;
}
string CompilerGLSL::argument_decl(const SPIRFunction::Parameter &arg)
{
// glslangValidator seems to make all arguments pointer no matter what which is rather bizarre ...
auto &type = expression_type(arg.id);
const char *direction = "";
if (type.pointer)
{
if (arg.write_count && arg.read_count)
direction = "inout ";
else if (arg.write_count)
direction = "out ";
}
return join(direction, to_qualifiers_glsl(arg.id), variable_decl(type, to_name(arg.id), arg.id));
}
string CompilerGLSL::to_initializer_expression(const SPIRVariable &var)
{
return to_expression(var.initializer);
}
string CompilerGLSL::variable_decl(const SPIRVariable &variable)
{
// Ignore the pointer type since GLSL doesn't have pointers.
auto &type = get_variable_data_type(variable);
if (type.pointer_depth > 1)
SPIRV_CROSS_THROW("Cannot declare pointer-to-pointer types.");
auto res = join(to_qualifiers_glsl(variable.self), variable_decl(type, to_name(variable.self), variable.self));
if (variable.loop_variable && variable.static_expression)
{
uint32_t expr = variable.static_expression;
if (ir.ids[expr].get_type() != TypeUndef)
res += join(" = ", to_expression(variable.static_expression));
}
else if (variable.initializer)
{
uint32_t expr = variable.initializer;
if (ir.ids[expr].get_type() != TypeUndef)
res += join(" = ", to_initializer_expression(variable));
}
return res;
}
const char *CompilerGLSL::to_pls_qualifiers_glsl(const SPIRVariable &variable)
{
auto &flags = ir.meta[variable.self].decoration.decoration_flags;
if (flags.get(DecorationRelaxedPrecision))
return "mediump ";
else
return "highp ";
}
string CompilerGLSL::pls_decl(const PlsRemap &var)
{
auto &variable = get<SPIRVariable>(var.id);
SPIRType type;
type.vecsize = pls_format_to_components(var.format);
type.basetype = pls_format_to_basetype(var.format);
return join(to_pls_layout(var.format), to_pls_qualifiers_glsl(variable), type_to_glsl(type), " ",
to_name(variable.self));
}
uint32_t CompilerGLSL::to_array_size_literal(const SPIRType &type) const
{
return to_array_size_literal(type, uint32_t(type.array.size() - 1));
}
uint32_t CompilerGLSL::to_array_size_literal(const SPIRType &type, uint32_t index) const
{
assert(type.array.size() == type.array_size_literal.size());
if (type.array_size_literal[index])
{
return type.array[index];
}
else
{
// Use the default spec constant value.
// This is the best we can do.
uint32_t array_size_id = type.array[index];
// Explicitly check for this case. The error message you would get (bad cast) makes no sense otherwise.
if (ir.ids[array_size_id].get_type() == TypeConstantOp)
SPIRV_CROSS_THROW("An array size was found to be an OpSpecConstantOp. This is not supported since "
"SPIRV-Cross cannot deduce the actual size here.");
uint32_t array_size = get<SPIRConstant>(array_size_id).scalar();
return array_size;
}
}
string CompilerGLSL::to_array_size(const SPIRType &type, uint32_t index)
{
assert(type.array.size() == type.array_size_literal.size());
// Tessellation control and evaluation shaders must have either gl_MaxPatchVertices or unsized arrays for input arrays.
// Opt for unsized as it's the more "correct" variant to use.
if (type.storage == StorageClassInput && (get_entry_point().model == ExecutionModelTessellationControl ||
get_entry_point().model == ExecutionModelTessellationEvaluation))
return "";
auto &size = type.array[index];
if (!type.array_size_literal[index])
return to_expression(size);
else if (size)
return convert_to_string(size);
else if (!backend.flexible_member_array_supported)
{
// For runtime-sized arrays, we can work around
// lack of standard support for this by simply having
// a single element array.
//
// Runtime length arrays must always be the last element
// in an interface block.
return "1";
}
else
return "";
}
string CompilerGLSL::type_to_array_glsl(const SPIRType &type)
{
if (type.array.empty())
return "";
if (options.flatten_multidimensional_arrays)
{
string res;
res += "[";
for (auto i = uint32_t(type.array.size()); i; i--)
{
res += enclose_expression(to_array_size(type, i - 1));
if (i > 1)
res += " * ";
}
res += "]";
return res;
}
else
{
if (type.array.size() > 1)
{
if (!options.es && options.version < 430)
require_extension_internal("GL_ARB_arrays_of_arrays");
else if (options.es && options.version < 310)
SPIRV_CROSS_THROW("Arrays of arrays not supported before ESSL version 310. "
"Try using --flatten-multidimensional-arrays or set "
"options.flatten_multidimensional_arrays to true.");
}
string res;
for (auto i = uint32_t(type.array.size()); i; i--)
{
res += "[";
res += to_array_size(type, i - 1);
res += "]";
}
return res;
}
}
string CompilerGLSL::image_type_glsl(const SPIRType &type, uint32_t id)
{
auto &imagetype = get<SPIRType>(type.image.type);
string res;
switch (imagetype.basetype)
{
case SPIRType::Int:
res = "i";
break;
case SPIRType::UInt:
res = "u";
break;
default:
break;
}
if (type.basetype == SPIRType::Image && type.image.dim == DimSubpassData && options.vulkan_semantics)
return res + "subpassInput" + (type.image.ms ? "MS" : "");
// If we're emulating subpassInput with samplers, force sampler2D
// so we don't have to specify format.
if (type.basetype == SPIRType::Image && type.image.dim != DimSubpassData)
{
// Sampler buffers are always declared as samplerBuffer even though they might be separate images in the SPIR-V.
if (type.image.dim == DimBuffer && type.image.sampled == 1)
res += "sampler";
else
res += type.image.sampled == 2 ? "image" : "texture";
}
else
res += "sampler";
switch (type.image.dim)
{
case Dim1D:
res += "1D";
break;
case Dim2D:
res += "2D";
break;
case Dim3D:
res += "3D";
break;
case DimCube:
res += "Cube";
break;
case DimRect:
if (options.es)
SPIRV_CROSS_THROW("Rectangle textures are not supported on OpenGL ES.");
if (is_legacy_desktop())
require_extension_internal("GL_ARB_texture_rectangle");
res += "2DRect";
break;
case DimBuffer:
if (options.es && options.version < 320)
require_extension_internal("GL_OES_texture_buffer");
else if (!options.es && options.version < 300)
require_extension_internal("GL_EXT_texture_buffer_object");
res += "Buffer";
break;
case DimSubpassData:
res += "2D";
break;
default:
SPIRV_CROSS_THROW("Only 1D, 2D, 2DRect, 3D, Buffer, InputTarget and Cube textures supported.");
}
if (type.image.ms)
res += "MS";
if (type.image.arrayed)
{
if (is_legacy_desktop())
require_extension_internal("GL_EXT_texture_array");
res += "Array";
}
// "Shadow" state in GLSL only exists for samplers and combined image samplers.
if (((type.basetype == SPIRType::SampledImage) || (type.basetype == SPIRType::Sampler)) &&
image_is_comparison(type, id))
{
res += "Shadow";
}
return res;
}
string CompilerGLSL::type_to_glsl_constructor(const SPIRType &type)
{
if (type.array.size() > 1)
{
if (options.flatten_multidimensional_arrays)
SPIRV_CROSS_THROW("Cannot flatten constructors of multidimensional array constructors, e.g. float[][]().");
else if (!options.es && options.version < 430)
require_extension_internal("GL_ARB_arrays_of_arrays");
else if (options.es && options.version < 310)
SPIRV_CROSS_THROW("Arrays of arrays not supported before ESSL version 310.");
}
auto e = type_to_glsl(type);
for (uint32_t i = 0; i < type.array.size(); i++)
e += "[]";
return e;
}
// The optional id parameter indicates the object whose type we are trying
// to find the description for. It is optional. Most type descriptions do not
// depend on a specific object's use of that type.
string CompilerGLSL::type_to_glsl(const SPIRType &type, uint32_t id)
{
// Ignore the pointer type since GLSL doesn't have pointers.
switch (type.basetype)
{
case SPIRType::Struct:
// Need OpName lookup here to get a "sensible" name for a struct.
if (backend.explicit_struct_type)
return join("struct ", to_name(type.self));
else
return to_name(type.self);
case SPIRType::Image:
case SPIRType::SampledImage:
return image_type_glsl(type, id);
case SPIRType::Sampler:
// The depth field is set by calling code based on the variable ID of the sampler, effectively reintroducing
// this distinction into the type system.
return comparison_ids.count(id) ? "samplerShadow" : "sampler";
case SPIRType::AccelerationStructureNV:
return "accelerationStructureNV";
case SPIRType::Void:
return "void";
default:
break;
}
if (type.basetype == SPIRType::UInt && is_legacy())
SPIRV_CROSS_THROW("Unsigned integers are not supported on legacy targets.");
if (type.vecsize == 1 && type.columns == 1) // Scalar builtin
{
switch (type.basetype)
{
case SPIRType::Boolean:
return "bool";
case SPIRType::SByte:
return backend.basic_int8_type;
case SPIRType::UByte:
return backend.basic_uint8_type;
case SPIRType::Short:
return backend.basic_int16_type;
case SPIRType::UShort:
return backend.basic_uint16_type;
case SPIRType::Int:
return backend.basic_int_type;
case SPIRType::UInt:
return backend.basic_uint_type;
case SPIRType::AtomicCounter:
return "atomic_uint";
case SPIRType::Half:
return "float16_t";
case SPIRType::Float:
return "float";
case SPIRType::Double:
return "double";
case SPIRType::Int64:
return "int64_t";
case SPIRType::UInt64:
return "uint64_t";
default:
return "???";
}
}
else if (type.vecsize > 1 && type.columns == 1) // Vector builtin
{
switch (type.basetype)
{
case SPIRType::Boolean:
return join("bvec", type.vecsize);
case SPIRType::SByte:
return join("i8vec", type.vecsize);
case SPIRType::UByte:
return join("u8vec", type.vecsize);
case SPIRType::Short:
return join("i16vec", type.vecsize);
case SPIRType::UShort:
return join("u16vec", type.vecsize);
case SPIRType::Int:
return join("ivec", type.vecsize);
case SPIRType::UInt:
return join("uvec", type.vecsize);
case SPIRType::Half:
return join("f16vec", type.vecsize);
case SPIRType::Float:
return join("vec", type.vecsize);
case SPIRType::Double:
return join("dvec", type.vecsize);
case SPIRType::Int64:
return join("i64vec", type.vecsize);
case SPIRType::UInt64:
return join("u64vec", type.vecsize);
default:
return "???";
}
}
else if (type.vecsize == type.columns) // Simple Matrix builtin
{
switch (type.basetype)
{
case SPIRType::Boolean:
return join("bmat", type.vecsize);
case SPIRType::Int:
return join("imat", type.vecsize);
case SPIRType::UInt:
return join("umat", type.vecsize);
case SPIRType::Half:
return join("f16mat", type.vecsize);
case SPIRType::Float:
return join("mat", type.vecsize);
case SPIRType::Double:
return join("dmat", type.vecsize);
// Matrix types not supported for int64/uint64.
default:
return "???";
}
}
else
{
switch (type.basetype)
{
case SPIRType::Boolean:
return join("bmat", type.columns, "x", type.vecsize);
case SPIRType::Int:
return join("imat", type.columns, "x", type.vecsize);
case SPIRType::UInt:
return join("umat", type.columns, "x", type.vecsize);
case SPIRType::Half:
return join("f16mat", type.columns, "x", type.vecsize);
case SPIRType::Float:
return join("mat", type.columns, "x", type.vecsize);
case SPIRType::Double:
return join("dmat", type.columns, "x", type.vecsize);
// Matrix types not supported for int64/uint64.
default:
return "???";
}
}
}
void CompilerGLSL::add_variable(unordered_set<string> &variables_primary,
const unordered_set<string> &variables_secondary, string &name)
{
if (name.empty())
return;
// Reserved for temporaries.
if (name[0] == '_' && name.size() >= 2 && isdigit(name[1]))
{
name.clear();
return;
}
// Avoid double underscores.
name = sanitize_underscores(name);
update_name_cache(variables_primary, variables_secondary, name);
}
void CompilerGLSL::add_local_variable_name(uint32_t id)
{
add_variable(local_variable_names, block_names, ir.meta[id].decoration.alias);
}
void CompilerGLSL::add_resource_name(uint32_t id)
{
add_variable(resource_names, block_names, ir.meta[id].decoration.alias);
}
void CompilerGLSL::add_header_line(const std::string &line)
{
header_lines.push_back(line);
}
bool CompilerGLSL::has_extension(const std::string &ext) const
{
auto itr = find(begin(forced_extensions), end(forced_extensions), ext);
return itr != end(forced_extensions);
}
void CompilerGLSL::require_extension(const std::string &ext)
{
if (!has_extension(ext))
forced_extensions.push_back(ext);
}
void CompilerGLSL::require_extension_internal(const string &ext)
{
if (backend.supports_extensions && !has_extension(ext))
{
forced_extensions.push_back(ext);
force_recompile = true;
}
}
void CompilerGLSL::flatten_buffer_block(uint32_t id)
{
auto &var = get<SPIRVariable>(id);
auto &type = get<SPIRType>(var.basetype);
auto name = to_name(type.self, false);
auto &flags = ir.meta[type.self].decoration.decoration_flags;
if (!type.array.empty())
SPIRV_CROSS_THROW(name + " is an array of UBOs.");
if (type.basetype != SPIRType::Struct)
SPIRV_CROSS_THROW(name + " is not a struct.");
if (!flags.get(DecorationBlock))
SPIRV_CROSS_THROW(name + " is not a block.");
if (type.member_types.empty())
SPIRV_CROSS_THROW(name + " is an empty struct.");
flattened_buffer_blocks.insert(id);
}
bool CompilerGLSL::check_atomic_image(uint32_t id)
{
auto &type = expression_type(id);
if (type.storage == StorageClassImage)
{
if (options.es && options.version < 320)
require_extension_internal("GL_OES_shader_image_atomic");
auto *var = maybe_get_backing_variable(id);
if (var)
{
auto &flags = ir.meta[var->self].decoration.decoration_flags;
if (flags.get(DecorationNonWritable) || flags.get(DecorationNonReadable))
{
flags.clear(DecorationNonWritable);
flags.clear(DecorationNonReadable);
force_recompile = true;
}
}
return true;
}
else
return false;
}
void CompilerGLSL::add_function_overload(const SPIRFunction &func)
{
Hasher hasher;
for (auto &arg : func.arguments)
{
// Parameters can vary with pointer type or not,
// but that will not change the signature in GLSL/HLSL,
// so strip the pointer type before hashing.
uint32_t type_id = get_pointee_type_id(arg.type);
auto &type = get<SPIRType>(type_id);
if (!combined_image_samplers.empty())
{
// If we have combined image samplers, we cannot really trust the image and sampler arguments
// we pass down to callees, because they may be shuffled around.
// Ignore these arguments, to make sure that functions need to differ in some other way
// to be considered different overloads.
if (type.basetype == SPIRType::SampledImage ||
(type.basetype == SPIRType::Image && type.image.sampled == 1) || type.basetype == SPIRType::Sampler)
{
continue;
}
}
hasher.u32(type_id);
}
uint64_t types_hash = hasher.get();
auto function_name = to_name(func.self);
auto itr = function_overloads.find(function_name);
if (itr != end(function_overloads))
{
// There exists a function with this name already.
auto &overloads = itr->second;
if (overloads.count(types_hash) != 0)
{
// Overload conflict, assign a new name.
add_resource_name(func.self);
function_overloads[to_name(func.self)].insert(types_hash);
}
else
{
// Can reuse the name.
overloads.insert(types_hash);
}
}
else
{
// First time we see this function name.
add_resource_name(func.self);
function_overloads[to_name(func.self)].insert(types_hash);
}
}
void CompilerGLSL::emit_function_prototype(SPIRFunction &func, const Bitset &return_flags)
{
if (func.self != ir.default_entry_point)
add_function_overload(func);
// Avoid shadow declarations.
local_variable_names = resource_names;
string decl;
auto &type = get<SPIRType>(func.return_type);
decl += flags_to_precision_qualifiers_glsl(type, return_flags);
decl += type_to_glsl(type);
decl += type_to_array_glsl(type);
decl += " ";
if (func.self == ir.default_entry_point)
{
decl += "main";
processing_entry_point = true;
}
else
decl += to_name(func.self);
decl += "(";
vector<string> arglist;
for (auto &arg : func.arguments)
{
// Do not pass in separate images or samplers if we're remapping
// to combined image samplers.
if (skip_argument(arg.id))
continue;
// Might change the variable name if it already exists in this function.
// SPIRV OpName doesn't have any semantic effect, so it's valid for an implementation
// to use same name for variables.
// Since we want to make the GLSL debuggable and somewhat sane, use fallback names for variables which are duplicates.
add_local_variable_name(arg.id);
arglist.push_back(argument_decl(arg));
// Hold a pointer to the parameter so we can invalidate the readonly field if needed.
auto *var = maybe_get<SPIRVariable>(arg.id);
if (var)
var->parameter = &arg;
}
for (auto &arg : func.shadow_arguments)
{
// Might change the variable name if it already exists in this function.
// SPIRV OpName doesn't have any semantic effect, so it's valid for an implementation
// to use same name for variables.
// Since we want to make the GLSL debuggable and somewhat sane, use fallback names for variables which are duplicates.
add_local_variable_name(arg.id);
arglist.push_back(argument_decl(arg));
// Hold a pointer to the parameter so we can invalidate the readonly field if needed.
auto *var = maybe_get<SPIRVariable>(arg.id);
if (var)
var->parameter = &arg;
}
decl += merge(arglist);
decl += ")";
statement(decl);
}
void CompilerGLSL::emit_function(SPIRFunction &func, const Bitset &return_flags)
{
// Avoid potential cycles.
if (func.active)
return;
func.active = true;
// If we depend on a function, emit that function before we emit our own function.
for (auto block : func.blocks)
{
auto &b = get<SPIRBlock>(block);
for (auto &i : b.ops)
{
auto ops = stream(i);
auto op = static_cast<Op>(i.op);
if (op == OpFunctionCall)
{
// Recursively emit functions which are called.
uint32_t id = ops[2];
emit_function(get<SPIRFunction>(id), ir.meta[ops[1]].decoration.decoration_flags);
}
}
}
emit_function_prototype(func, return_flags);
begin_scope();
if (func.self == ir.default_entry_point)
emit_entry_point_declarations();
current_function = &func;
auto &entry_block = get<SPIRBlock>(func.entry_block);
sort(begin(func.constant_arrays_needed_on_stack), end(func.constant_arrays_needed_on_stack));
for (auto &array : func.constant_arrays_needed_on_stack)
{
auto &c = get<SPIRConstant>(array);
auto &type = get<SPIRType>(c.constant_type);
statement(variable_decl(type, join("_", array, "_array_copy")), " = ", constant_expression(c), ";");
}
for (auto &v : func.local_variables)
{
auto &var = get<SPIRVariable>(v);
if (var.storage == StorageClassWorkgroup)
{
// Special variable type which cannot have initializer,
// need to be declared as standalone variables.
// Comes from MSL which can push global variables as local variables in main function.
add_local_variable_name(var.self);
statement(variable_decl(var), ";");
var.deferred_declaration = false;
}
else if (var.storage == StorageClassPrivate)
{
// These variables will not have had their CFG usage analyzed, so move it to the entry block.
// Comes from MSL which can push global variables as local variables in main function.
// We could just declare them right now, but we would miss out on an important initialization case which is
// LUT declaration in MSL.
// If we don't declare the variable when it is assigned we're forced to go through a helper function
// which copies elements one by one.
add_local_variable_name(var.self);
auto &dominated = entry_block.dominated_variables;
if (find(begin(dominated), end(dominated), var.self) == end(dominated))
entry_block.dominated_variables.push_back(var.self);
var.deferred_declaration = true;
}
else if (var.storage == StorageClassFunction && var.remapped_variable && var.static_expression)
{
// No need to declare this variable, it has a static expression.
var.deferred_declaration = false;
}
else if (expression_is_lvalue(v))
{
add_local_variable_name(var.self);
if (var.initializer)
statement(variable_decl_function_local(var), ";");
else
{
// Don't declare variable until first use to declutter the GLSL output quite a lot.
// If we don't touch the variable before first branch,
// declare it then since we need variable declaration to be in top scope.
var.deferred_declaration = true;
}
}
else
{
// HACK: SPIR-V in older glslang output likes to use samplers and images as local variables, but GLSL does not allow this.
// For these types (non-lvalue), we enforce forwarding through a shadowed variable.
// This means that when we OpStore to these variables, we just write in the expression ID directly.
// This breaks any kind of branching, since the variable must be statically assigned.
// Branching on samplers and images would be pretty much impossible to fake in GLSL.
var.statically_assigned = true;
}
var.loop_variable_enable = false;
// Loop variables are never declared outside their for-loop, so block any implicit declaration.
if (var.loop_variable)
var.deferred_declaration = false;
}
for (auto &line : current_function->fixup_hooks_in)
line();
entry_block.loop_dominator = SPIRBlock::NoDominator;
emit_block_chain(entry_block);
end_scope();
processing_entry_point = false;
statement("");
}
void CompilerGLSL::emit_fixup()
{
auto &execution = get_entry_point();
if (execution.model == ExecutionModelVertex)
{
if (options.vertex.fixup_clipspace)
{
const char *suffix = backend.float_literal_suffix ? "f" : "";
statement("gl_Position.z = 2.0", suffix, " * gl_Position.z - gl_Position.w;");
}
if (options.vertex.flip_vert_y)
statement("gl_Position.y = -gl_Position.y;");
}
}
bool CompilerGLSL::flush_phi_required(uint32_t from, uint32_t to)
{
auto &child = get<SPIRBlock>(to);
for (auto &phi : child.phi_variables)
if (phi.parent == from)
return true;
return false;
}
void CompilerGLSL::flush_phi(uint32_t from, uint32_t to)
{
auto &child = get<SPIRBlock>(to);
unordered_set<uint32_t> temporary_phi_variables;
for (auto itr = begin(child.phi_variables); itr != end(child.phi_variables); ++itr)
{
auto &phi = *itr;
if (phi.parent == from)
{
auto &var = get<SPIRVariable>(phi.function_variable);
// A Phi variable might be a loop variable, so flush to static expression.
if (var.loop_variable && !var.loop_variable_enable)
var.static_expression = phi.local_variable;
else
{
flush_variable_declaration(phi.function_variable);
// Check if we are going to write to a Phi variable that another statement will read from
// as part of another Phi node in our target block.
// For this case, we will need to copy phi.function_variable to a temporary, and use that for future reads.
// This is judged to be extremely rare, so deal with it here using a simple, but suboptimal algorithm.
bool need_saved_temporary =
find_if(itr + 1, end(child.phi_variables), [&](const SPIRBlock::Phi &future_phi) -> bool {
return future_phi.local_variable == phi.function_variable && future_phi.parent == from;
}) != end(child.phi_variables);
if (need_saved_temporary)
{
// Need to make sure we declare the phi variable with a copy at the right scope.
// We cannot safely declare a temporary here since we might be inside a continue block.
if (!var.allocate_temporary_copy)
{
var.allocate_temporary_copy = true;
force_recompile = true;
}
statement("_", phi.function_variable, "_copy", " = ", to_name(phi.function_variable), ";");
temporary_phi_variables.insert(phi.function_variable);
}
// This might be called in continue block, so make sure we
// use this to emit ESSL 1.0 compliant increments/decrements.
auto lhs = to_expression(phi.function_variable);
string rhs;
if (temporary_phi_variables.count(phi.local_variable))
rhs = join("_", phi.local_variable, "_copy");
else
rhs = to_pointer_expression(phi.local_variable);
if (!optimize_read_modify_write(get<SPIRType>(var.basetype), lhs, rhs))
statement(lhs, " = ", rhs, ";");
}
register_write(phi.function_variable);
}
}
}
void CompilerGLSL::branch_to_continue(uint32_t from, uint32_t to)
{
auto &to_block = get<SPIRBlock>(to);
if (from == to)
return;
assert(is_continue(to));
if (to_block.complex_continue)
{
// Just emit the whole block chain as is.
auto usage_counts = expression_usage_counts;
auto invalid = invalid_expressions;
emit_block_chain(to_block);
// Expression usage counts and invalid expressions
// are moot after returning from the continue block.
// Since we emit the same block multiple times,
// we don't want to invalidate ourselves.
expression_usage_counts = usage_counts;
invalid_expressions = invalid;
}
else
{
auto &from_block = get<SPIRBlock>(from);
bool outside_control_flow = false;
uint32_t loop_dominator = 0;
// FIXME: Refactor this to not use the old loop_dominator tracking.
if (from_block.merge_block)
{
// If we are a loop header, we don't set the loop dominator,
// so just use "self" here.
loop_dominator = from;
}
else if (from_block.loop_dominator != SPIRBlock::NoDominator)
{
loop_dominator = from_block.loop_dominator;
}
if (loop_dominator != 0)
{
auto &dominator = get<SPIRBlock>(loop_dominator);
// For non-complex continue blocks, we implicitly branch to the continue block
// by having the continue block be part of the loop header in for (; ; continue-block).
outside_control_flow = block_is_outside_flow_control_from_block(dominator, from_block);
}
// Some simplification for for-loops. We always end up with a useless continue;
// statement since we branch to a loop block.
// Walk the CFG, if we uncoditionally execute the block calling continue assuming we're in the loop block,
// we can avoid writing out an explicit continue statement.
// Similar optimization to return statements if we know we're outside flow control.
if (!outside_control_flow)
statement("continue;");
}
}
void CompilerGLSL::branch(uint32_t from, uint32_t to)
{
flush_phi(from, to);
flush_control_dependent_expressions(from);
flush_all_active_variables();
// This is only a continue if we branch to our loop dominator.
if ((ir.block_meta[to] & ParsedIR::BLOCK_META_LOOP_HEADER_BIT) != 0 && get<SPIRBlock>(from).loop_dominator == to)
{
// This can happen if we had a complex continue block which was emitted.
// Once the continue block tries to branch to the loop header, just emit continue;
// and end the chain here.
statement("continue;");
}
else if (is_break(to))
{
// Very dirty workaround.
// Switch constructs are able to break, but they cannot break out of a loop at the same time.
// Only sensible solution is to make a ladder variable, which we declare at the top of the switch block,
// write to the ladder here, and defer the break.
// The loop we're breaking out of must dominate the switch block, or there is no ladder breaking case.
if (current_emitting_switch && is_loop_break(to) && current_emitting_switch->loop_dominator != ~0u &&
get<SPIRBlock>(current_emitting_switch->loop_dominator).merge_block == to)
{
if (!current_emitting_switch->need_ladder_break)
{
force_recompile = true;
current_emitting_switch->need_ladder_break = true;
}
statement("_", current_emitting_switch->self, "_ladder_break = true;");
}
statement("break;");
}
else if (is_continue(to) || (from == to))
{
// For from == to case can happen for a do-while loop which branches into itself.
// We don't mark these cases as continue blocks, but the only possible way to branch into
// ourselves is through means of continue blocks.
branch_to_continue(from, to);
}
else if (!is_conditional(to))
emit_block_chain(get<SPIRBlock>(to));
// It is important that we check for break before continue.
// A block might serve two purposes, a break block for the inner scope, and
// a continue block in the outer scope.
// Inner scope always takes precedence.
}
void CompilerGLSL::branch(uint32_t from, uint32_t cond, uint32_t true_block, uint32_t false_block)
{
// If we branch directly to a selection merge target, we don't really need a code path.
bool true_sub = !is_conditional(true_block);
bool false_sub = !is_conditional(false_block);
if (true_sub)
{
emit_block_hints(get<SPIRBlock>(from));
statement("if (", to_expression(cond), ")");
begin_scope();
branch(from, true_block);
end_scope();
if (false_sub || is_continue(false_block) || is_break(false_block))
{
statement("else");
begin_scope();
branch(from, false_block);
end_scope();
}
else if (flush_phi_required(from, false_block))
{
statement("else");
begin_scope();
flush_phi(from, false_block);
end_scope();
}
}
else if (false_sub && !true_sub)
{
// Only need false path, use negative conditional.
emit_block_hints(get<SPIRBlock>(from));
statement("if (!", to_enclosed_expression(cond), ")");
begin_scope();
branch(from, false_block);
end_scope();
if (is_continue(true_block) || is_break(true_block))
{
statement("else");
begin_scope();
branch(from, true_block);
end_scope();
}
else if (flush_phi_required(from, true_block))
{
statement("else");
begin_scope();
flush_phi(from, true_block);
end_scope();
}
}
}
void CompilerGLSL::propagate_loop_dominators(const SPIRBlock &block)
{
// Propagate down the loop dominator block, so that dominated blocks can back trace.
if (block.merge == SPIRBlock::MergeLoop || block.loop_dominator)
{
uint32_t dominator = block.merge == SPIRBlock::MergeLoop ? block.self : block.loop_dominator;
auto set_dominator = [this](uint32_t self, uint32_t new_dominator) {
auto &dominated_block = this->get<SPIRBlock>(self);
// If we already have a loop dominator, we're trying to break out to merge targets
// which should not update the loop dominator.
if (!dominated_block.loop_dominator)
dominated_block.loop_dominator = new_dominator;
};
// After merging a loop, we inherit the loop dominator always.
if (block.merge_block)
set_dominator(block.merge_block, block.loop_dominator);
if (block.true_block)
set_dominator(block.true_block, dominator);
if (block.false_block)
set_dominator(block.false_block, dominator);
if (block.next_block)
set_dominator(block.next_block, dominator);
if (block.default_block)
set_dominator(block.default_block, dominator);
for (auto &c : block.cases)
set_dominator(c.block, dominator);
// In older glslang output continue_block can be == loop header.
if (block.continue_block && block.continue_block != block.self)
set_dominator(block.continue_block, dominator);
}
}
// FIXME: This currently cannot handle complex continue blocks
// as in do-while.
// This should be seen as a "trivial" continue block.
string CompilerGLSL::emit_continue_block(uint32_t continue_block, bool follow_true_block, bool follow_false_block)
{
auto *block = &get<SPIRBlock>(continue_block);
// While emitting the continue block, declare_temporary will check this
// if we have to emit temporaries.
current_continue_block = block;
vector<string> statements;
// Capture all statements into our list.
auto *old = redirect_statement;
redirect_statement = &statements;
// Stamp out all blocks one after each other.
while ((ir.block_meta[block->self] & ParsedIR::BLOCK_META_LOOP_HEADER_BIT) == 0)
{
propagate_loop_dominators(*block);
// Write out all instructions we have in this block.
emit_block_instructions(*block);
// For plain branchless for/while continue blocks.
if (block->next_block)
{
flush_phi(continue_block, block->next_block);
block = &get<SPIRBlock>(block->next_block);
}
// For do while blocks. The last block will be a select block.
else if (block->true_block && follow_true_block)
{
flush_phi(continue_block, block->true_block);
block = &get<SPIRBlock>(block->true_block);
}
else if (block->false_block && follow_false_block)
{
flush_phi(continue_block, block->false_block);
block = &get<SPIRBlock>(block->false_block);
}
else
{
SPIRV_CROSS_THROW("Invalid continue block detected!");
}
}
// Restore old pointer.
redirect_statement = old;
// Somewhat ugly, strip off the last ';' since we use ',' instead.
// Ideally, we should select this behavior in statement().
for (auto &s : statements)
{
if (!s.empty() && s.back() == ';')
s.erase(s.size() - 1, 1);
}
current_continue_block = nullptr;
return merge(statements);
}
void CompilerGLSL::emit_while_loop_initializers(const SPIRBlock &block)
{
// While loops do not take initializers, so declare all of them outside.
for (auto &loop_var : block.loop_variables)
{
auto &var = get<SPIRVariable>(loop_var);
statement(variable_decl(var), ";");
}
}
string CompilerGLSL::emit_for_loop_initializers(const SPIRBlock &block)
{
if (block.loop_variables.empty())
return "";
bool same_types = for_loop_initializers_are_same_type(block);
// We can only declare for loop initializers if all variables are of same type.
// If we cannot do this, declare individual variables before the loop header.
// We might have a loop variable candidate which was not assigned to for some reason.
uint32_t missing_initializers = 0;
for (auto &variable : block.loop_variables)
{
uint32_t expr = get<SPIRVariable>(variable).static_expression;
// Sometimes loop variables are initialized with OpUndef, but we can just declare
// a plain variable without initializer in this case.
if (expr == 0 || ir.ids[expr].get_type() == TypeUndef)
missing_initializers++;
}
if (block.loop_variables.size() == 1 && missing_initializers == 0)
{
return variable_decl(get<SPIRVariable>(block.loop_variables.front()));
}
else if (!same_types || missing_initializers == uint32_t(block.loop_variables.size()))
{
for (auto &loop_var : block.loop_variables)
statement(variable_decl(get<SPIRVariable>(loop_var)), ";");
return "";
}
else
{
// We have a mix of loop variables, either ones with a clear initializer, or ones without.
// Separate the two streams.
string expr;
for (auto &loop_var : block.loop_variables)
{
uint32_t static_expr = get<SPIRVariable>(loop_var).static_expression;
if (static_expr == 0 || ir.ids[static_expr].get_type() == TypeUndef)
{
statement(variable_decl(get<SPIRVariable>(loop_var)), ";");
}
else
{
auto &var = get<SPIRVariable>(loop_var);
auto &type = get_variable_data_type(var);
if (expr.empty())
{
// For loop initializers are of the form <type id = value, id = value, id = value, etc ...
expr = join(to_qualifiers_glsl(var.self), type_to_glsl(type), " ");
}
else
{
expr += ", ";
// In MSL, being based on C++, the asterisk marking a pointer
// binds to the identifier, not the type.
if (type.pointer)
expr += "* ";
}
expr += join(to_name(loop_var), " = ", to_pointer_expression(var.static_expression));
}
}
return expr;
}
}
bool CompilerGLSL::for_loop_initializers_are_same_type(const SPIRBlock &block)
{
if (block.loop_variables.size() <= 1)
return true;
uint32_t expected = 0;
Bitset expected_flags;
for (auto &var : block.loop_variables)
{
// Don't care about uninitialized variables as they will not be part of the initializers.
uint32_t expr = get<SPIRVariable>(var).static_expression;
if (expr == 0 || ir.ids[expr].get_type() == TypeUndef)
continue;
if (expected == 0)
{
expected = get<SPIRVariable>(var).basetype;
expected_flags = get_decoration_bitset(var);
}
else if (expected != get<SPIRVariable>(var).basetype)
return false;
// Precision flags and things like that must also match.
if (expected_flags != get_decoration_bitset(var))
return false;
}
return true;
}
bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method method)
{
SPIRBlock::ContinueBlockType continue_type = continue_block_type(get<SPIRBlock>(block.continue_block));
if (method == SPIRBlock::MergeToSelectForLoop || method == SPIRBlock::MergeToSelectContinueForLoop)
{
uint32_t current_count = statement_count;
// If we're trying to create a true for loop,
// we need to make sure that all opcodes before branch statement do not actually emit any code.
// We can then take the condition expression and create a for (; cond ; ) { body; } structure instead.
emit_block_instructions(block);
bool condition_is_temporary = forced_temporaries.find(block.condition) == end(forced_temporaries);
// This can work! We only did trivial things which could be forwarded in block body!
if (current_count == statement_count && condition_is_temporary)
{
switch (continue_type)
{
case SPIRBlock::ForLoop:
{
// This block may be a dominating block, so make sure we flush undeclared variables before building the for loop header.
flush_undeclared_variables(block);
// Important that we do this in this order because
// emitting the continue block can invalidate the condition expression.
auto initializer = emit_for_loop_initializers(block);
auto condition = to_expression(block.condition);
// Condition might have to be inverted.
if (execution_is_noop(get<SPIRBlock>(block.true_block), get<SPIRBlock>(block.merge_block)))
condition = join("!", enclose_expression(condition));
emit_block_hints(block);
if (method != SPIRBlock::MergeToSelectContinueForLoop)
{
auto continue_block = emit_continue_block(block.continue_block, false, false);
statement("for (", initializer, "; ", condition, "; ", continue_block, ")");
}
else
statement("for (", initializer, "; ", condition, "; )");
break;
}
case SPIRBlock::WhileLoop:
{
// This block may be a dominating block, so make sure we flush undeclared variables before building the while loop header.
flush_undeclared_variables(block);
emit_while_loop_initializers(block);
emit_block_hints(block);
auto condition = to_expression(block.condition);
// Condition might have to be inverted.
if (execution_is_noop(get<SPIRBlock>(block.true_block), get<SPIRBlock>(block.merge_block)))
condition = join("!", enclose_expression(condition));
statement("while (", condition, ")");
break;
}
default:
SPIRV_CROSS_THROW("For/while loop detected, but need while/for loop semantics.");
}
begin_scope();
return true;
}
else
{
block.disable_block_optimization = true;
force_recompile = true;
begin_scope(); // We'll see an end_scope() later.
return false;
}
}
else if (method == SPIRBlock::MergeToDirectForLoop)
{
auto &child = get<SPIRBlock>(block.next_block);
// This block may be a dominating block, so make sure we flush undeclared variables before building the for loop header.
flush_undeclared_variables(child);
uint32_t current_count = statement_count;
// If we're trying to create a true for loop,
// we need to make sure that all opcodes before branch statement do not actually emit any code.
// We can then take the condition expression and create a for (; cond ; ) { body; } structure instead.
emit_block_instructions(child);
bool condition_is_temporary = forced_temporaries.find(child.condition) == end(forced_temporaries);
if (current_count == statement_count && condition_is_temporary)
{
propagate_loop_dominators(child);
uint32_t target_block = child.true_block;
switch (continue_type)
{
case SPIRBlock::ForLoop:
{
// Important that we do this in this order because
// emitting the continue block can invalidate the condition expression.
auto initializer = emit_for_loop_initializers(block);
auto condition = to_expression(child.condition);
// Condition might have to be inverted.
if (execution_is_noop(get<SPIRBlock>(child.true_block), get<SPIRBlock>(block.merge_block)))
{
condition = join("!", enclose_expression(condition));
target_block = child.false_block;
}
auto continue_block = emit_continue_block(block.continue_block, false, false);
emit_block_hints(block);
statement("for (", initializer, "; ", condition, "; ", continue_block, ")");
break;
}
case SPIRBlock::WhileLoop:
{
emit_while_loop_initializers(block);
emit_block_hints(block);
auto condition = to_expression(child.condition);
// Condition might have to be inverted.
if (execution_is_noop(get<SPIRBlock>(child.true_block), get<SPIRBlock>(block.merge_block)))
{
condition = join("!", enclose_expression(condition));
target_block = child.false_block;
}
statement("while (", condition, ")");
break;
}
default:
SPIRV_CROSS_THROW("For/while loop detected, but need while/for loop semantics.");
}
begin_scope();
branch(child.self, target_block);
return true;
}
else
{
block.disable_block_optimization = true;
force_recompile = true;
begin_scope(); // We'll see an end_scope() later.
return false;
}
}
else
return false;
}
void CompilerGLSL::flush_undeclared_variables(SPIRBlock &block)
{
// Enforce declaration order for regression testing purposes.
sort(begin(block.dominated_variables), end(block.dominated_variables));
for (auto &v : block.dominated_variables)
flush_variable_declaration(v);
}
void CompilerGLSL::emit_hoisted_temporaries(vector<pair<uint32_t, uint32_t>> &temporaries)
{
// If we need to force temporaries for certain IDs due to continue blocks, do it before starting loop header.
// Need to sort these to ensure that reference output is stable.
sort(begin(temporaries), end(temporaries),
[](const pair<uint32_t, uint32_t> &a, const pair<uint32_t, uint32_t> &b) { return a.second < b.second; });
for (auto &tmp : temporaries)
{
add_local_variable_name(tmp.second);
auto &flags = ir.meta[tmp.second].decoration.decoration_flags;
auto &type = get<SPIRType>(tmp.first);
statement(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, to_name(tmp.second)), ";");
hoisted_temporaries.insert(tmp.second);
forced_temporaries.insert(tmp.second);
// The temporary might be read from before it's assigned, set up the expression now.
set<SPIRExpression>(tmp.second, to_name(tmp.second), tmp.first, true);
}
}
void CompilerGLSL::emit_block_chain(SPIRBlock &block)
{
propagate_loop_dominators(block);
bool select_branch_to_true_block = false;
bool select_branch_to_false_block = false;
bool skip_direct_branch = false;
bool emitted_loop_header_variables = false;
bool force_complex_continue_block = false;
emit_hoisted_temporaries(block.declare_temporary);
SPIRBlock::ContinueBlockType continue_type = SPIRBlock::ContinueNone;
if (block.continue_block)
continue_type = continue_block_type(get<SPIRBlock>(block.continue_block));
// If we have loop variables, stop masking out access to the variable now.
for (auto var : block.loop_variables)
get<SPIRVariable>(var).loop_variable_enable = true;
// This is the method often used by spirv-opt to implement loops.
// The loop header goes straight into the continue block.
// However, don't attempt this on ESSL 1.0, because if a loop variable is used in a continue block,
// it *MUST* be used in the continue block. This loop method will not work.
if (!is_legacy_es() && block_is_loop_candidate(block, SPIRBlock::MergeToSelectContinueForLoop))
{
flush_undeclared_variables(block);
if (attempt_emit_loop_header(block, SPIRBlock::MergeToSelectContinueForLoop))
{
if (execution_is_noop(get<SPIRBlock>(block.true_block), get<SPIRBlock>(block.merge_block)))
select_branch_to_false_block = true;
else
select_branch_to_true_block = true;
emitted_loop_header_variables = true;
force_complex_continue_block = true;
}
}
// This is the older loop behavior in glslang which branches to loop body directly from the loop header.
else if (block_is_loop_candidate(block, SPIRBlock::MergeToSelectForLoop))
{
flush_undeclared_variables(block);
if (attempt_emit_loop_header(block, SPIRBlock::MergeToSelectForLoop))
{
// The body of while, is actually just the true (or false) block, so always branch there unconditionally.
if (execution_is_noop(get<SPIRBlock>(block.true_block), get<SPIRBlock>(block.merge_block)))
select_branch_to_false_block = true;
else
select_branch_to_true_block = true;
emitted_loop_header_variables = true;
}
}
// This is the newer loop behavior in glslang which branches from Loop header directly to
// a new block, which in turn has a OpBranchSelection without a selection merge.
else if (block_is_loop_candidate(block, SPIRBlock::MergeToDirectForLoop))
{
flush_undeclared_variables(block);
if (attempt_emit_loop_header(block, SPIRBlock::MergeToDirectForLoop))
{
skip_direct_branch = true;
emitted_loop_header_variables = true;
}
}
else if (continue_type == SPIRBlock::DoWhileLoop)
{
flush_undeclared_variables(block);
emit_while_loop_initializers(block);
emitted_loop_header_variables = true;
// We have some temporaries where the loop header is the dominator.
// We risk a case where we have code like:
// for (;;) { create-temporary; break; } consume-temporary;
// so force-declare temporaries here.
emit_hoisted_temporaries(block.potential_declare_temporary);
statement("do");
begin_scope();
emit_block_instructions(block);
}
else if (block.merge == SPIRBlock::MergeLoop)
{
flush_undeclared_variables(block);
emit_while_loop_initializers(block);
emitted_loop_header_variables = true;
// We have a generic loop without any distinguishable pattern like for, while or do while.
get<SPIRBlock>(block.continue_block).complex_continue = true;
continue_type = SPIRBlock::ComplexLoop;
// We have some temporaries where the loop header is the dominator.
// We risk a case where we have code like:
// for (;;) { create-temporary; break; } consume-temporary;
// so force-declare temporaries here.
emit_hoisted_temporaries(block.potential_declare_temporary);
statement("for (;;)");
begin_scope();
emit_block_instructions(block);
}
else
{
emit_block_instructions(block);
}
// If we didn't successfully emit a loop header and we had loop variable candidates, we have a problem
// as writes to said loop variables might have been masked out, we need a recompile.
if (!emitted_loop_header_variables && !block.loop_variables.empty())
{
force_recompile = true;
for (auto var : block.loop_variables)
get<SPIRVariable>(var).loop_variable = false;
block.loop_variables.clear();
}
flush_undeclared_variables(block);
bool emit_next_block = true;
// Handle end of block.
switch (block.terminator)
{
case SPIRBlock::Direct:
// True when emitting complex continue block.
if (block.loop_dominator == block.next_block)
{
branch(block.self, block.next_block);
emit_next_block = false;
}
// True if MergeToDirectForLoop succeeded.
else if (skip_direct_branch)
emit_next_block = false;
else if (is_continue(block.next_block) || is_break(block.next_block) || is_conditional(block.next_block))
{
branch(block.self, block.next_block);
emit_next_block = false;
}
break;
case SPIRBlock::Select:
// True if MergeToSelectForLoop or MergeToSelectContinueForLoop succeeded.
if (select_branch_to_true_block)
{
if (force_complex_continue_block)
{
assert(block.true_block == block.continue_block);
// We're going to emit a continue block directly here, so make sure it's marked as complex.
auto &complex_continue = get<SPIRBlock>(block.continue_block).complex_continue;
bool old_complex = complex_continue;
complex_continue = true;
branch(block.self, block.true_block);
complex_continue = old_complex;
}
else
branch(block.self, block.true_block);
}
else if (select_branch_to_false_block)
{
if (force_complex_continue_block)
{
assert(block.false_block == block.continue_block);
// We're going to emit a continue block directly here, so make sure it's marked as complex.
auto &complex_continue = get<SPIRBlock>(block.continue_block).complex_continue;
bool old_complex = complex_continue;
complex_continue = true;
branch(block.self, block.false_block);
complex_continue = old_complex;
}
else
branch(block.self, block.false_block);
}
else
branch(block.self, block.condition, block.true_block, block.false_block);
break;
case SPIRBlock::MultiSelect:
{
auto &type = expression_type(block.condition);
bool unsigned_case = type.basetype == SPIRType::UInt || type.basetype == SPIRType::UShort;
if (block.merge == SPIRBlock::MergeNone)
SPIRV_CROSS_THROW("Switch statement is not structured");
if (type.basetype == SPIRType::UInt64 || type.basetype == SPIRType::Int64)
{
// SPIR-V spec suggests this is allowed, but we cannot support it in higher level languages.
SPIRV_CROSS_THROW("Cannot use 64-bit switch selectors.");
}
const char *label_suffix = "";
if (type.basetype == SPIRType::UInt && backend.uint32_t_literal_suffix)
label_suffix = "u";
else if (type.basetype == SPIRType::UShort)
label_suffix = backend.uint16_t_literal_suffix;
else if (type.basetype == SPIRType::Short)
label_suffix = backend.int16_t_literal_suffix;
SPIRBlock *old_emitting_switch = current_emitting_switch;
current_emitting_switch = █
if (block.need_ladder_break)
statement("bool _", block.self, "_ladder_break = false;");
emit_block_hints(block);
statement("switch (", to_expression(block.condition), ")");
begin_scope();
// Multiple case labels can branch to same block, so find all unique blocks.
bool emitted_default = false;
unordered_set<uint32_t> emitted_blocks;
for (auto &c : block.cases)
{
if (emitted_blocks.count(c.block) != 0)
continue;
// Emit all case labels which branch to our target.
// FIXME: O(n^2), revisit if we hit shaders with 100++ case labels ...
for (auto &other_case : block.cases)
{
if (other_case.block == c.block)
{
// The case label value must be sign-extended properly in SPIR-V, so we can assume 32-bit values here.
auto case_value = unsigned_case ? convert_to_string(uint32_t(other_case.value)) :
convert_to_string(int32_t(other_case.value));
statement("case ", case_value, label_suffix, ":");
}
}
// Maybe we share with default block?
if (block.default_block == c.block)
{
statement("default:");
emitted_default = true;
}
// Complete the target.
emitted_blocks.insert(c.block);
begin_scope();
branch(block.self, c.block);
end_scope();
}
if (!emitted_default)
{
if (block.default_block != block.next_block)
{
statement("default:");
begin_scope();
if (is_break(block.default_block))
SPIRV_CROSS_THROW("Cannot break; out of a switch statement and out of a loop at the same time ...");
branch(block.self, block.default_block);
end_scope();
}
else if (flush_phi_required(block.self, block.next_block))
{
statement("default:");
begin_scope();
flush_phi(block.self, block.next_block);
statement("break;");
end_scope();
}
}
end_scope();
if (block.need_ladder_break)
{
statement("if (_", block.self, "_ladder_break)");
begin_scope();
statement("break;");
end_scope();
}
current_emitting_switch = old_emitting_switch;
break;
}
case SPIRBlock::Return:
for (auto &line : current_function->fixup_hooks_out)
line();
if (processing_entry_point)
emit_fixup();
if (block.return_value)
{
auto &type = expression_type(block.return_value);
if (!type.array.empty() && !backend.can_return_array)
{
// If we cannot return arrays, we will have a special out argument we can write to instead.
// The backend is responsible for setting this up, and redirection the return values as appropriate.
if (ir.ids[block.return_value].get_type() != TypeUndef)
emit_array_copy("SPIRV_Cross_return_value", block.return_value);
if (!block_is_outside_flow_control_from_block(get<SPIRBlock>(current_function->entry_block), block) ||
block.loop_dominator != SPIRBlock::NoDominator)
{
statement("return;");
}
}
else
{
// OpReturnValue can return Undef, so don't emit anything for this case.
if (ir.ids[block.return_value].get_type() != TypeUndef)
statement("return ", to_expression(block.return_value), ";");
}
}
// If this block is the very final block and not called from control flow,
// we do not need an explicit return which looks out of place. Just end the function here.
// In the very weird case of for(;;) { return; } executing return is unconditional,
// but we actually need a return here ...
else if (!block_is_outside_flow_control_from_block(get<SPIRBlock>(current_function->entry_block), block) ||
block.loop_dominator != SPIRBlock::NoDominator)
{
statement("return;");
}
break;
case SPIRBlock::Kill:
statement(backend.discard_literal, ";");
break;
case SPIRBlock::Unreachable:
emit_next_block = false;
break;
default:
SPIRV_CROSS_THROW("Unimplemented block terminator.");
}
if (block.next_block && emit_next_block)
{
// If we hit this case, we're dealing with an unconditional branch, which means we will output
// that block after this. If we had selection merge, we already flushed phi variables.
if (block.merge != SPIRBlock::MergeSelection)
flush_phi(block.self, block.next_block);
// For merge selects we might have ignored the fact that a merge target
// could have been a break; or continue;
// We will need to deal with it here.
if (is_loop_break(block.next_block))
{
// Cannot check for just break, because switch statements will also use break.
assert(block.merge == SPIRBlock::MergeSelection);
statement("break;");
}
else if (is_continue(block.next_block))
{
assert(block.merge == SPIRBlock::MergeSelection);
branch_to_continue(block.self, block.next_block);
}
else
emit_block_chain(get<SPIRBlock>(block.next_block));
}
if (block.merge == SPIRBlock::MergeLoop)
{
if (continue_type == SPIRBlock::DoWhileLoop)
{
// Make sure that we run the continue block to get the expressions set, but this
// should become an empty string.
// We have no fallbacks if we cannot forward everything to temporaries ...
const auto &continue_block = get<SPIRBlock>(block.continue_block);
bool positive_test = execution_is_noop(get<SPIRBlock>(continue_block.true_block),
get<SPIRBlock>(continue_block.loop_dominator));
auto statements = emit_continue_block(block.continue_block, positive_test, !positive_test);
if (!statements.empty())
{
// The DoWhile block has side effects, force ComplexLoop pattern next pass.
get<SPIRBlock>(block.continue_block).complex_continue = true;
force_recompile = true;
}
// Might have to invert the do-while test here.
auto condition = to_expression(continue_block.condition);
if (!positive_test)
condition = join("!", enclose_expression(condition));
end_scope_decl(join("while (", condition, ")"));
}
else
end_scope();
// We cannot break out of two loops at once, so don't check for break; here.
// Using block.self as the "from" block isn't quite right, but it has the same scope
// and dominance structure, so it's fine.
if (is_continue(block.merge_block))
branch_to_continue(block.self, block.merge_block);
else
emit_block_chain(get<SPIRBlock>(block.merge_block));
}
// Forget about control dependent expressions now.
block.invalidate_expressions.clear();
}
void CompilerGLSL::begin_scope()
{
statement("{");
indent++;
}
void CompilerGLSL::end_scope()
{
if (!indent)
SPIRV_CROSS_THROW("Popping empty indent stack.");
indent--;
statement("}");
}
void CompilerGLSL::end_scope_decl()
{
if (!indent)
SPIRV_CROSS_THROW("Popping empty indent stack.");
indent--;
statement("};");
}
void CompilerGLSL::end_scope_decl(const string &decl)
{
if (!indent)
SPIRV_CROSS_THROW("Popping empty indent stack.");
indent--;
statement("} ", decl, ";");
}
void CompilerGLSL::check_function_call_constraints(const uint32_t *args, uint32_t length)
{
// If our variable is remapped, and we rely on type-remapping information as
// well, then we cannot pass the variable as a function parameter.
// Fixing this is non-trivial without stamping out variants of the same function,
// so for now warn about this and suggest workarounds instead.
for (uint32_t i = 0; i < length; i++)
{
auto *var = maybe_get<SPIRVariable>(args[i]);
if (!var || !var->remapped_variable)
continue;
auto &type = get<SPIRType>(var->basetype);
if (type.basetype == SPIRType::Image && type.image.dim == DimSubpassData)
{
SPIRV_CROSS_THROW("Tried passing a remapped subpassInput variable to a function. "
"This will not work correctly because type-remapping information is lost. "
"To workaround, please consider not passing the subpass input as a function parameter, "
"or use in/out variables instead which do not need type remapping information.");
}
}
}
const Instruction *CompilerGLSL::get_next_instruction_in_block(const Instruction &instr)
{
// FIXME: This is kind of hacky. There should be a cleaner way.
auto offset = uint32_t(&instr - current_emitting_block->ops.data());
if ((offset + 1) < current_emitting_block->ops.size())
return ¤t_emitting_block->ops[offset + 1];
else
return nullptr;
}
uint32_t CompilerGLSL::mask_relevant_memory_semantics(uint32_t semantics)
{
return semantics & (MemorySemanticsAtomicCounterMemoryMask | MemorySemanticsImageMemoryMask |
MemorySemanticsWorkgroupMemoryMask | MemorySemanticsUniformMemoryMask |
MemorySemanticsCrossWorkgroupMemoryMask | MemorySemanticsSubgroupMemoryMask);
}
void CompilerGLSL::emit_array_copy(const string &lhs, uint32_t rhs_id)
{
statement(lhs, " = ", to_expression(rhs_id), ";");
}
void CompilerGLSL::unroll_array_from_complex_load(uint32_t target_id, uint32_t source_id, std::string &expr)
{
if (!backend.force_gl_in_out_block)
return;
// This path is only relevant for GL backends.
auto *var = maybe_get<SPIRVariable>(source_id);
if (!var)
return;
if (var->storage != StorageClassInput)
return;
auto &type = get_variable_data_type(*var);
if (type.array.empty())
return;
auto builtin = BuiltIn(get_decoration(var->self, DecorationBuiltIn));
bool is_builtin = is_builtin_variable(*var) && (builtin == BuiltInPointSize || builtin == BuiltInPosition);
bool is_tess = is_tessellation_shader();
// Tessellation input arrays are special in that they are unsized, so we cannot directly copy from it.
// We must unroll the array load.
// For builtins, we couldn't catch this case normally,
// because this is resolved in the OpAccessChain in most cases.
// If we load the entire array, we have no choice but to unroll here.
if (is_builtin || is_tess)
{
auto new_expr = join("_", target_id, "_unrolled");
statement(variable_decl(type, new_expr, target_id), ";");
string array_expr;
if (type.array_size_literal.front())
{
array_expr = convert_to_string(type.array.front());
if (type.array.front() == 0)
SPIRV_CROSS_THROW("Cannot unroll an array copy from unsized array.");
}
else
array_expr = to_expression(type.array.front());
// The array size might be a specialization constant, so use a for-loop instead.
statement("for (int i = 0; i < int(", array_expr, "); i++)");
begin_scope();
if (is_builtin)
statement(new_expr, "[i] = gl_in[i].", expr, ";");
else
statement(new_expr, "[i] = ", expr, "[i];");
end_scope();
expr = move(new_expr);
}
}
void CompilerGLSL::bitcast_from_builtin_load(uint32_t source_id, std::string &expr,
const SPIRType &expr_type)
{
auto *var = maybe_get_backing_variable(source_id);
if (var)
source_id = var->self;
// Only interested in standalone builtin variables.
if (!has_decoration(source_id, DecorationBuiltIn))
return;
auto builtin = static_cast<BuiltIn>(get_decoration(source_id, DecorationBuiltIn));
auto expected_type = expr_type.basetype;
// TODO: Fill in for more builtins.
switch (builtin)
{
case BuiltInLayer:
case BuiltInPrimitiveId:
case BuiltInViewportIndex:
case BuiltInInstanceId:
case BuiltInInstanceIndex:
case BuiltInVertexId:
case BuiltInVertexIndex:
case BuiltInSampleId:
case BuiltInBaseVertex:
case BuiltInBaseInstance:
case BuiltInDrawIndex:
expected_type = SPIRType::Int;
break;
case BuiltInGlobalInvocationId:
case BuiltInLocalInvocationId:
case BuiltInWorkgroupId:
case BuiltInLocalInvocationIndex:
case BuiltInWorkgroupSize:
case BuiltInNumWorkgroups:
expected_type = SPIRType::UInt;
break;
default:
break;
}
if (expected_type != expr_type.basetype)
expr = bitcast_expression(expr_type, expected_type, expr);
}
void CompilerGLSL::bitcast_to_builtin_store(uint32_t target_id, std::string &expr,
const SPIRType &expr_type)
{
// Only interested in standalone builtin variables.
if (!has_decoration(target_id, DecorationBuiltIn))
return;
auto builtin = static_cast<BuiltIn>(get_decoration(target_id, DecorationBuiltIn));
auto expected_type = expr_type.basetype;
// TODO: Fill in for more builtins.
switch (builtin)
{
case BuiltInLayer:
case BuiltInPrimitiveId:
case BuiltInViewportIndex:
expected_type = SPIRType::Int;
break;
default:
break;
}
if (expected_type != expr_type.basetype)
{
auto type = expr_type;
type.basetype = expected_type;
expr = bitcast_expression(type, expr_type.basetype, expr);
}
}
void CompilerGLSL::emit_block_hints(const SPIRBlock &)
{
}
void CompilerGLSL::preserve_alias_on_reset(uint32_t id)
{
preserved_aliases[id] = get_name(id);
}
void CompilerGLSL::reset_name_caches()
{
for (auto &preserved : preserved_aliases)
set_name(preserved.first, preserved.second);
preserved_aliases.clear();
resource_names.clear();
block_input_names.clear();
block_output_names.clear();
block_ubo_names.clear();
block_ssbo_names.clear();
block_names.clear();
function_overloads.clear();
}
| [
"roniesalg@gmail.com"
] | roniesalg@gmail.com |
0479a939d9b04818b70ed93492104c4c9072e91d | 3525be850c8065e292a1770f19a89730a7095d0d | /ra_cpp/src/raysphere.cpp | 4a6cec0e95ced969590ae05d989c6d2dd14bc5d0 | [] | no_license | pokjnb/ra | a0e323fa0165e27eb2d36641a40d6cf19343582a | 345be1496d2c3f59f0aaa3594977f495c80f50e3 | refs/heads/master | 2022-04-21T08:09:24.325333 | 2020-04-17T19:04:32 | 2020-04-17T19:04:32 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 968 | cpp | #include "raysphere.h"
double raysphere(Eigen::Ref<Eigen::RowVector3f> ray_origin,
Eigen::Ref<Eigen::RowVector3f> v_dir,
Eigen::Ref<Eigen::RowVector3f> rec_coord,
double rec_radius,
double c0,
double dist_travel){
// Initialize timecross
double time_cross = 0.0;
// Calculate the roots for ray-sphere intersection
Eigen::RowVector3f ray_rec_vec = ray_origin - rec_coord;
double b = ray_rec_vec.dot(v_dir);
double dist_origin2rec = ray_rec_vec.norm();
double c = pow(dist_origin2rec, 2.0) - pow(rec_radius, 2.0);
double delta = pow(b, 2.0) - c;
// test of ray intersection
if (delta >= 0.0 && b <= 0.0){
// distance from center of receiver to mid crossing point
double d = (ray_rec_vec - b * v_dir).norm();
// distance from wall to receiver
double dL = sqrt(pow(dist_origin2rec, 2.0) + pow(d, 2.0));
time_cross = (dist_travel + dL) / c0;
}
return time_cross;
} | [
"ericbacustica@gmail.com"
] | ericbacustica@gmail.com |
a8da28872efc2858230ab89a84abd056692ac413 | 0aa925ab0109f9b5bf0b47a93ca0b196c634dc75 | /base-case/airfoil-test/constant/polyMesh/owner | dc44ce9d37c7392262bb949b5b57cde6d3b90644 | [] | no_license | david-moravec/airfoil-tests | cca7fd7fa7fb99eb606f2f36b5df77ac3c54a8f9 | 845efa5f9eb88321f321cddc7c3cd68521f126cc | refs/heads/main | 2023-04-15T02:22:53.219871 | 2021-04-14T10:51:40 | 2021-04-14T10:51:40 | 302,572,741 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 301,766 | /*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class labelList;
note "nPoints:29250 nCells:14336 nFaces:57632 nInternalFaces:28384";
location "constant/polyMesh";
object owner;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57632
(
0
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
48
49
49
50
50
51
51
52
52
53
53
54
54
55
55
56
56
57
57
58
58
59
59
60
60
61
61
62
62
63
64
64
65
65
66
66
67
67
68
68
69
69
70
70
71
71
72
72
73
73
74
74
75
75
76
76
77
77
78
78
79
79
80
80
81
81
82
82
83
83
84
84
85
85
86
86
87
87
88
88
89
89
90
90
91
91
92
92
93
93
94
94
95
95
96
96
97
97
98
98
99
99
100
100
101
101
102
102
103
103
104
104
105
105
106
106
107
107
108
108
109
109
110
110
111
111
112
112
113
113
114
114
115
115
116
116
117
117
118
118
119
119
120
120
121
121
122
122
123
123
124
124
125
125
126
126
127
128
128
129
129
130
130
131
131
132
132
133
133
134
134
135
135
136
136
137
137
138
138
139
139
140
140
141
141
142
142
143
143
144
144
145
145
146
146
147
147
148
148
149
149
150
150
151
151
152
152
153
153
154
154
155
155
156
156
157
157
158
158
159
159
160
160
161
161
162
162
163
163
164
164
165
165
166
166
167
167
168
168
169
169
170
170
171
171
172
172
173
173
174
174
175
175
176
176
177
177
178
178
179
179
180
180
181
181
182
182
183
183
184
184
185
185
186
186
187
187
188
188
189
189
190
190
191
192
192
193
193
194
194
195
195
196
196
197
197
198
198
199
199
200
200
201
201
202
202
203
203
204
204
205
205
206
206
207
207
208
208
209
209
210
210
211
211
212
212
213
213
214
214
215
215
216
216
217
217
218
218
219
219
220
220
221
221
222
222
223
223
224
224
225
225
226
226
227
227
228
228
229
229
230
230
231
231
232
232
233
233
234
234
235
235
236
236
237
237
238
238
239
239
240
240
241
241
242
242
243
243
244
244
245
245
246
246
247
247
248
248
249
249
250
250
251
251
252
252
253
253
254
254
255
256
256
257
257
258
258
259
259
260
260
261
261
262
262
263
263
264
264
265
265
266
266
267
267
268
268
269
269
270
270
271
271
272
272
273
273
274
274
275
275
276
276
277
277
278
278
279
279
280
280
281
281
282
282
283
283
284
284
285
285
286
286
287
287
288
288
289
289
290
290
291
291
292
292
293
293
294
294
295
295
296
296
297
297
298
298
299
299
300
300
301
301
302
302
303
303
304
304
305
305
306
306
307
307
308
308
309
309
310
310
311
311
312
312
313
313
314
314
315
315
316
316
317
317
318
318
319
320
320
321
321
322
322
323
323
324
324
325
325
326
326
327
327
328
328
329
329
330
330
331
331
332
332
333
333
334
334
335
335
336
336
337
337
338
338
339
339
340
340
341
341
342
342
343
343
344
344
345
345
346
346
347
347
348
348
349
349
350
350
351
351
352
352
353
353
354
354
355
355
356
356
357
357
358
358
359
359
360
360
361
361
362
362
363
363
364
364
365
365
366
366
367
367
368
368
369
369
370
370
371
371
372
372
373
373
374
374
375
375
376
376
377
377
378
378
379
379
380
380
381
381
382
382
383
384
384
385
385
386
386
387
387
388
388
389
389
390
390
391
391
392
392
393
393
394
394
395
395
396
396
397
397
398
398
399
399
400
400
401
401
402
402
403
403
404
404
405
405
406
406
407
407
408
408
409
409
410
410
411
411
412
412
413
413
414
414
415
415
416
416
417
417
418
418
419
419
420
420
421
421
422
422
423
423
424
424
425
425
426
426
427
427
428
428
429
429
430
430
431
431
432
432
433
433
434
434
435
435
436
436
437
437
438
438
439
439
440
440
441
441
442
442
443
443
444
444
445
445
446
446
447
448
448
449
449
450
450
451
451
452
452
453
453
454
454
455
455
456
456
457
457
458
458
459
459
460
460
461
461
462
462
463
463
464
464
465
465
466
466
467
467
468
468
469
469
470
470
471
471
472
472
473
473
474
474
475
475
476
476
477
477
478
478
479
479
480
480
481
481
482
482
483
483
484
484
485
485
486
486
487
487
488
488
489
489
490
490
491
491
492
492
493
493
494
494
495
495
496
496
497
497
498
498
499
499
500
500
501
501
502
502
503
503
504
504
505
505
506
506
507
507
508
508
509
509
510
510
511
512
512
513
513
514
514
515
515
516
516
517
517
518
518
519
519
520
520
521
521
522
522
523
523
524
524
525
525
526
526
527
527
528
528
529
529
530
530
531
531
532
532
533
533
534
534
535
535
536
536
537
537
538
538
539
539
540
540
541
541
542
542
543
543
544
544
545
545
546
546
547
547
548
548
549
549
550
550
551
551
552
552
553
553
554
554
555
555
556
556
557
557
558
558
559
559
560
560
561
561
562
562
563
563
564
564
565
565
566
566
567
567
568
568
569
569
570
570
571
571
572
572
573
573
574
574
575
576
576
577
577
578
578
579
579
580
580
581
581
582
582
583
583
584
584
585
585
586
586
587
587
588
588
589
589
590
590
591
591
592
592
593
593
594
594
595
595
596
596
597
597
598
598
599
599
600
600
601
601
602
602
603
603
604
604
605
605
606
606
607
607
608
608
609
609
610
610
611
611
612
612
613
613
614
614
615
615
616
616
617
617
618
618
619
619
620
620
621
621
622
622
623
623
624
624
625
625
626
626
627
627
628
628
629
629
630
630
631
631
632
632
633
633
634
634
635
635
636
636
637
637
638
638
639
640
640
641
641
642
642
643
643
644
644
645
645
646
646
647
647
648
648
649
649
650
650
651
651
652
652
653
653
654
654
655
655
656
656
657
657
658
658
659
659
660
660
661
661
662
662
663
663
664
664
665
665
666
666
667
667
668
668
669
669
670
670
671
671
672
672
673
673
674
674
675
675
676
676
677
677
678
678
679
679
680
680
681
681
682
682
683
683
684
684
685
685
686
686
687
687
688
688
689
689
690
690
691
691
692
692
693
693
694
694
695
695
696
696
697
697
698
698
699
699
700
700
701
701
702
702
703
704
704
705
705
706
706
707
707
708
708
709
709
710
710
711
711
712
712
713
713
714
714
715
715
716
716
717
717
718
718
719
719
720
720
721
721
722
722
723
723
724
724
725
725
726
726
727
727
728
728
729
729
730
730
731
731
732
732
733
733
734
734
735
735
736
736
737
737
738
738
739
739
740
740
741
741
742
742
743
743
744
744
745
745
746
746
747
747
748
748
749
749
750
750
751
751
752
752
753
753
754
754
755
755
756
756
757
757
758
758
759
759
760
760
761
761
762
762
763
763
764
764
765
765
766
766
767
768
768
769
769
770
770
771
771
772
772
773
773
774
774
775
775
776
776
777
777
778
778
779
779
780
780
781
781
782
782
783
783
784
784
785
785
786
786
787
787
788
788
789
789
790
790
791
791
792
792
793
793
794
794
795
795
796
796
797
797
798
798
799
799
800
800
801
801
802
802
803
803
804
804
805
805
806
806
807
807
808
808
809
809
810
810
811
811
812
812
813
813
814
814
815
815
816
816
817
817
818
818
819
819
820
820
821
821
822
822
823
823
824
824
825
825
826
826
827
827
828
828
829
829
830
830
831
832
832
833
833
834
834
835
835
836
836
837
837
838
838
839
839
840
840
841
841
842
842
843
843
844
844
845
845
846
846
847
847
848
848
849
849
850
850
851
851
852
852
853
853
854
854
855
855
856
856
857
857
858
858
859
859
860
860
861
861
862
862
863
863
864
864
865
865
866
866
867
867
868
868
869
869
870
870
871
871
872
872
873
873
874
874
875
875
876
876
877
877
878
878
879
879
880
880
881
881
882
882
883
883
884
884
885
885
886
886
887
887
888
888
889
889
890
890
891
891
892
892
893
893
894
894
895
896
896
897
897
898
898
899
899
900
900
901
901
902
902
903
903
904
904
905
905
906
906
907
907
908
908
909
909
910
910
911
911
912
912
913
913
914
914
915
915
916
916
917
917
918
918
919
919
920
920
921
921
922
922
923
923
924
924
925
925
926
926
927
927
928
928
929
929
930
930
931
931
932
932
933
933
934
934
935
935
936
936
937
937
938
938
939
939
940
940
941
941
942
942
943
943
944
944
945
945
946
946
947
947
948
948
949
949
950
950
951
951
952
952
953
953
954
954
955
955
956
956
957
957
958
958
959
960
960
961
961
962
962
963
963
964
964
965
965
966
966
967
967
968
968
969
969
970
970
971
971
972
972
973
973
974
974
975
975
976
976
977
977
978
978
979
979
980
980
981
981
982
982
983
983
984
984
985
985
986
986
987
987
988
988
989
989
990
990
991
991
992
992
993
993
994
994
995
995
996
996
997
997
998
998
999
999
1000
1000
1001
1001
1002
1002
1003
1003
1004
1004
1005
1005
1006
1006
1007
1007
1008
1008
1009
1009
1010
1010
1011
1011
1012
1012
1013
1013
1014
1014
1015
1015
1016
1016
1017
1017
1018
1018
1019
1019
1020
1020
1021
1021
1022
1022
1023
1024
1024
1025
1025
1026
1026
1027
1027
1028
1028
1029
1029
1030
1030
1031
1031
1032
1032
1033
1033
1034
1034
1035
1035
1036
1036
1037
1037
1038
1038
1039
1039
1040
1040
1041
1041
1042
1042
1043
1043
1044
1044
1045
1045
1046
1046
1047
1047
1048
1048
1049
1049
1050
1050
1051
1051
1052
1052
1053
1053
1054
1054
1055
1055
1056
1056
1057
1057
1058
1058
1059
1059
1060
1060
1061
1061
1062
1062
1063
1063
1064
1064
1065
1065
1066
1066
1067
1067
1068
1068
1069
1069
1070
1070
1071
1071
1072
1072
1073
1073
1074
1074
1075
1075
1076
1076
1077
1077
1078
1078
1079
1079
1080
1080
1081
1081
1082
1082
1083
1083
1084
1084
1085
1085
1086
1086
1087
1088
1088
1089
1089
1090
1090
1091
1091
1092
1092
1093
1093
1094
1094
1095
1095
1096
1096
1097
1097
1098
1098
1099
1099
1100
1100
1101
1101
1102
1102
1103
1103
1104
1104
1105
1105
1106
1106
1107
1107
1108
1108
1109
1109
1110
1110
1111
1111
1112
1112
1113
1113
1114
1114
1115
1115
1116
1116
1117
1117
1118
1118
1119
1119
1120
1120
1121
1121
1122
1122
1123
1123
1124
1124
1125
1125
1126
1126
1127
1127
1128
1128
1129
1129
1130
1130
1131
1131
1132
1132
1133
1133
1134
1134
1135
1135
1136
1136
1137
1137
1138
1138
1139
1139
1140
1140
1141
1141
1142
1142
1143
1143
1144
1144
1145
1145
1146
1146
1147
1147
1148
1148
1149
1149
1150
1150
1151
1152
1152
1153
1153
1154
1154
1155
1155
1156
1156
1157
1157
1158
1158
1159
1159
1160
1160
1161
1161
1162
1162
1163
1163
1164
1164
1165
1165
1166
1166
1167
1167
1168
1168
1169
1169
1170
1170
1171
1171
1172
1172
1173
1173
1174
1174
1175
1175
1176
1176
1177
1177
1178
1178
1179
1179
1180
1180
1181
1181
1182
1182
1183
1183
1184
1184
1185
1185
1186
1186
1187
1187
1188
1188
1189
1189
1190
1190
1191
1191
1192
1192
1193
1193
1194
1194
1195
1195
1196
1196
1197
1197
1198
1198
1199
1199
1200
1200
1201
1201
1202
1202
1203
1203
1204
1204
1205
1205
1206
1206
1207
1207
1208
1208
1209
1209
1210
1210
1211
1211
1212
1212
1213
1213
1214
1214
1215
1216
1216
1217
1217
1218
1218
1219
1219
1220
1220
1221
1221
1222
1222
1223
1223
1224
1224
1225
1225
1226
1226
1227
1227
1228
1228
1229
1229
1230
1230
1231
1231
1232
1232
1233
1233
1234
1234
1235
1235
1236
1236
1237
1237
1238
1238
1239
1239
1240
1240
1241
1241
1242
1242
1243
1243
1244
1244
1245
1245
1246
1246
1247
1247
1248
1248
1249
1249
1250
1250
1251
1251
1252
1252
1253
1253
1254
1254
1255
1255
1256
1256
1257
1257
1258
1258
1259
1259
1260
1260
1261
1261
1262
1262
1263
1263
1264
1264
1265
1265
1266
1266
1267
1267
1268
1268
1269
1269
1270
1270
1271
1271
1272
1272
1273
1273
1274
1274
1275
1275
1276
1276
1277
1277
1278
1278
1279
1280
1280
1281
1281
1282
1282
1283
1283
1284
1284
1285
1285
1286
1286
1287
1287
1288
1288
1289
1289
1290
1290
1291
1291
1292
1292
1293
1293
1294
1294
1295
1295
1296
1296
1297
1297
1298
1298
1299
1299
1300
1300
1301
1301
1302
1302
1303
1303
1304
1304
1305
1305
1306
1306
1307
1307
1308
1308
1309
1309
1310
1310
1311
1311
1312
1312
1313
1313
1314
1314
1315
1315
1316
1316
1317
1317
1318
1318
1319
1319
1320
1320
1321
1321
1322
1322
1323
1323
1324
1324
1325
1325
1326
1326
1327
1327
1328
1328
1329
1329
1330
1330
1331
1331
1332
1332
1333
1333
1334
1334
1335
1335
1336
1336
1337
1337
1338
1338
1339
1339
1340
1340
1341
1341
1342
1342
1343
1344
1344
1345
1345
1346
1346
1347
1347
1348
1348
1349
1349
1350
1350
1351
1351
1352
1352
1353
1353
1354
1354
1355
1355
1356
1356
1357
1357
1358
1358
1359
1359
1360
1360
1361
1361
1362
1362
1363
1363
1364
1364
1365
1365
1366
1366
1367
1367
1368
1368
1369
1369
1370
1370
1371
1371
1372
1372
1373
1373
1374
1374
1375
1375
1376
1376
1377
1377
1378
1378
1379
1379
1380
1380
1381
1381
1382
1382
1383
1383
1384
1384
1385
1385
1386
1386
1387
1387
1388
1388
1389
1389
1390
1390
1391
1391
1392
1392
1393
1393
1394
1394
1395
1395
1396
1396
1397
1397
1398
1398
1399
1399
1400
1400
1401
1401
1402
1402
1403
1403
1404
1404
1405
1405
1406
1406
1407
1408
1408
1409
1409
1410
1410
1411
1411
1412
1412
1413
1413
1414
1414
1415
1415
1416
1416
1417
1417
1418
1418
1419
1419
1420
1420
1421
1421
1422
1422
1423
1423
1424
1424
1425
1425
1426
1426
1427
1427
1428
1428
1429
1429
1430
1430
1431
1431
1432
1432
1433
1433
1434
1434
1435
1435
1436
1436
1437
1437
1438
1438
1439
1439
1440
1440
1441
1441
1442
1442
1443
1443
1444
1444
1445
1445
1446
1446
1447
1447
1448
1448
1449
1449
1450
1450
1451
1451
1452
1452
1453
1453
1454
1454
1455
1455
1456
1456
1457
1457
1458
1458
1459
1459
1460
1460
1461
1461
1462
1462
1463
1463
1464
1464
1465
1465
1466
1466
1467
1467
1468
1468
1469
1469
1470
1470
1471
1472
1472
1473
1473
1474
1474
1475
1475
1476
1476
1477
1477
1478
1478
1479
1479
1480
1480
1481
1481
1482
1482
1483
1483
1484
1484
1485
1485
1486
1486
1487
1487
1488
1488
1489
1489
1490
1490
1491
1491
1492
1492
1493
1493
1494
1494
1495
1495
1496
1496
1497
1497
1498
1498
1499
1499
1500
1500
1501
1501
1502
1502
1503
1503
1504
1504
1505
1505
1506
1506
1507
1507
1508
1508
1509
1509
1510
1510
1511
1511
1512
1512
1513
1513
1514
1514
1515
1515
1516
1516
1517
1517
1518
1518
1519
1519
1520
1520
1521
1521
1522
1522
1523
1523
1524
1524
1525
1525
1526
1526
1527
1527
1528
1528
1529
1529
1530
1530
1531
1531
1532
1532
1533
1533
1534
1534
1535
1536
1536
1537
1537
1538
1538
1539
1539
1540
1540
1541
1541
1542
1542
1543
1543
1544
1544
1545
1545
1546
1546
1547
1547
1548
1548
1549
1549
1550
1550
1551
1551
1552
1552
1553
1553
1554
1554
1555
1555
1556
1556
1557
1557
1558
1558
1559
1559
1560
1560
1561
1561
1562
1562
1563
1563
1564
1564
1565
1565
1566
1566
1567
1567
1568
1568
1569
1569
1570
1570
1571
1571
1572
1572
1573
1573
1574
1574
1575
1575
1576
1576
1577
1577
1578
1578
1579
1579
1580
1580
1581
1581
1582
1582
1583
1583
1584
1584
1585
1585
1586
1586
1587
1587
1588
1588
1589
1589
1590
1590
1591
1591
1592
1592
1593
1593
1594
1594
1595
1595
1596
1596
1597
1597
1598
1598
1599
1600
1600
1601
1601
1602
1602
1603
1603
1604
1604
1605
1605
1606
1606
1607
1607
1608
1608
1609
1609
1610
1610
1611
1611
1612
1612
1613
1613
1614
1614
1615
1615
1616
1616
1617
1617
1618
1618
1619
1619
1620
1620
1621
1621
1622
1622
1623
1623
1624
1624
1625
1625
1626
1626
1627
1627
1628
1628
1629
1629
1630
1630
1631
1631
1632
1632
1633
1633
1634
1634
1635
1635
1636
1636
1637
1637
1638
1638
1639
1639
1640
1640
1641
1641
1642
1642
1643
1643
1644
1644
1645
1645
1646
1646
1647
1647
1648
1648
1649
1649
1650
1650
1651
1651
1652
1652
1653
1653
1654
1654
1655
1655
1656
1656
1657
1657
1658
1658
1659
1659
1660
1660
1661
1661
1662
1662
1663
1664
1664
1665
1665
1666
1666
1667
1667
1668
1668
1669
1669
1670
1670
1671
1671
1672
1672
1673
1673
1674
1674
1675
1675
1676
1676
1677
1677
1678
1678
1679
1679
1680
1680
1681
1681
1682
1682
1683
1683
1684
1684
1685
1685
1686
1686
1687
1687
1688
1688
1689
1689
1690
1690
1691
1691
1692
1692
1693
1693
1694
1694
1695
1695
1696
1696
1697
1697
1698
1698
1699
1699
1700
1700
1701
1701
1702
1702
1703
1703
1704
1704
1705
1705
1706
1706
1707
1707
1708
1708
1709
1709
1710
1710
1711
1711
1712
1712
1713
1713
1714
1714
1715
1715
1716
1716
1717
1717
1718
1718
1719
1719
1720
1720
1721
1721
1722
1722
1723
1723
1724
1724
1725
1725
1726
1726
1727
1728
1728
1729
1729
1730
1730
1731
1731
1732
1732
1733
1733
1734
1734
1735
1735
1736
1736
1737
1737
1738
1738
1739
1739
1740
1740
1741
1741
1742
1742
1743
1743
1744
1744
1745
1745
1746
1746
1747
1747
1748
1748
1749
1749
1750
1750
1751
1751
1752
1752
1753
1753
1754
1754
1755
1755
1756
1756
1757
1757
1758
1758
1759
1759
1760
1760
1761
1761
1762
1762
1763
1763
1764
1764
1765
1765
1766
1766
1767
1767
1768
1768
1769
1769
1770
1770
1771
1771
1772
1772
1773
1773
1774
1774
1775
1775
1776
1776
1777
1777
1778
1778
1779
1779
1780
1780
1781
1781
1782
1782
1783
1783
1784
1784
1785
1785
1786
1786
1787
1787
1788
1788
1789
1789
1790
1790
1791
1792
1792
1793
1793
1794
1794
1795
1795
1796
1796
1797
1797
1798
1798
1799
1799
1800
1800
1801
1801
1802
1802
1803
1803
1804
1804
1805
1805
1806
1806
1807
1807
1808
1808
1809
1809
1810
1810
1811
1811
1812
1812
1813
1813
1814
1814
1815
1815
1816
1816
1817
1817
1818
1818
1819
1819
1820
1820
1821
1821
1822
1822
1823
1823
1824
1824
1825
1825
1826
1826
1827
1827
1828
1828
1829
1829
1830
1830
1831
1831
1832
1832
1833
1833
1834
1834
1835
1835
1836
1836
1837
1837
1838
1838
1839
1839
1840
1840
1841
1841
1842
1842
1843
1843
1844
1844
1845
1845
1846
1846
1847
1847
1848
1848
1849
1849
1850
1850
1851
1851
1852
1852
1853
1853
1854
1854
1855
1856
1856
1857
1857
1858
1858
1859
1859
1860
1860
1861
1861
1862
1862
1863
1863
1864
1864
1865
1865
1866
1866
1867
1867
1868
1868
1869
1869
1870
1870
1871
1871
1872
1872
1873
1873
1874
1874
1875
1875
1876
1876
1877
1877
1878
1878
1879
1879
1880
1880
1881
1881
1882
1882
1883
1883
1884
1884
1885
1885
1886
1886
1887
1887
1888
1888
1889
1889
1890
1890
1891
1891
1892
1892
1893
1893
1894
1894
1895
1895
1896
1896
1897
1897
1898
1898
1899
1899
1900
1900
1901
1901
1902
1902
1903
1903
1904
1904
1905
1905
1906
1906
1907
1907
1908
1908
1909
1909
1910
1910
1911
1911
1912
1912
1913
1913
1914
1914
1915
1915
1916
1916
1917
1917
1918
1918
1919
1920
1920
1921
1921
1922
1922
1923
1923
1924
1924
1925
1925
1926
1926
1927
1927
1928
1928
1929
1929
1930
1930
1931
1931
1932
1932
1933
1933
1934
1934
1935
1935
1936
1936
1937
1937
1938
1938
1939
1939
1940
1940
1941
1941
1942
1942
1943
1943
1944
1944
1945
1945
1946
1946
1947
1947
1948
1948
1949
1949
1950
1950
1951
1951
1952
1952
1953
1953
1954
1954
1955
1955
1956
1956
1957
1957
1958
1958
1959
1959
1960
1960
1961
1961
1962
1962
1963
1963
1964
1964
1965
1965
1966
1966
1967
1967
1968
1968
1969
1969
1970
1970
1971
1971
1972
1972
1973
1973
1974
1974
1975
1975
1976
1976
1977
1977
1978
1978
1979
1979
1980
1980
1981
1981
1982
1982
1983
1984
1984
1985
1985
1986
1986
1987
1987
1988
1988
1989
1989
1990
1990
1991
1991
1992
1992
1993
1993
1994
1994
1995
1995
1996
1996
1997
1997
1998
1998
1999
1999
2000
2000
2001
2001
2002
2002
2003
2003
2004
2004
2005
2005
2006
2006
2007
2007
2008
2008
2009
2009
2010
2010
2011
2011
2012
2012
2013
2013
2014
2014
2015
2015
2016
2016
2017
2017
2018
2018
2019
2019
2020
2020
2021
2021
2022
2022
2023
2023
2024
2024
2025
2025
2026
2026
2027
2027
2028
2028
2029
2029
2030
2030
2031
2031
2032
2032
2033
2033
2034
2034
2035
2035
2036
2036
2037
2037
2038
2038
2039
2039
2040
2040
2041
2041
2042
2042
2043
2043
2044
2044
2045
2045
2046
2046
2047
2048
2048
2049
2049
2050
2050
2051
2051
2052
2052
2053
2053
2054
2054
2055
2055
2056
2056
2057
2057
2058
2058
2059
2059
2060
2060
2061
2061
2062
2062
2063
2063
2064
2064
2065
2065
2066
2066
2067
2067
2068
2068
2069
2069
2070
2070
2071
2071
2072
2072
2073
2073
2074
2074
2075
2075
2076
2076
2077
2077
2078
2078
2079
2079
2080
2080
2081
2081
2082
2082
2083
2083
2084
2084
2085
2085
2086
2086
2087
2087
2088
2088
2089
2089
2090
2090
2091
2091
2092
2092
2093
2093
2094
2094
2095
2095
2096
2096
2097
2097
2098
2098
2099
2099
2100
2100
2101
2101
2102
2102
2103
2103
2104
2104
2105
2105
2106
2106
2107
2107
2108
2108
2109
2109
2110
2110
2111
2112
2112
2113
2113
2114
2114
2115
2115
2116
2116
2117
2117
2118
2118
2119
2119
2120
2120
2121
2121
2122
2122
2123
2123
2124
2124
2125
2125
2126
2126
2127
2127
2128
2128
2129
2129
2130
2130
2131
2131
2132
2132
2133
2133
2134
2134
2135
2135
2136
2136
2137
2137
2138
2138
2139
2139
2140
2140
2141
2141
2142
2142
2143
2143
2144
2144
2145
2145
2146
2146
2147
2147
2148
2148
2149
2149
2150
2150
2151
2151
2152
2152
2153
2153
2154
2154
2155
2155
2156
2156
2157
2157
2158
2158
2159
2159
2160
2160
2161
2161
2162
2162
2163
2163
2164
2164
2165
2165
2166
2166
2167
2167
2168
2168
2169
2169
2170
2170
2171
2171
2172
2172
2173
2173
2174
2174
2175
2176
2176
2177
2177
2178
2178
2179
2179
2180
2180
2181
2181
2182
2182
2183
2183
2184
2184
2185
2185
2186
2186
2187
2187
2188
2188
2189
2189
2190
2190
2191
2191
2192
2192
2193
2193
2194
2194
2195
2195
2196
2196
2197
2197
2198
2198
2199
2199
2200
2200
2201
2201
2202
2202
2203
2203
2204
2204
2205
2205
2206
2206
2207
2207
2208
2208
2209
2209
2210
2210
2211
2211
2212
2212
2213
2213
2214
2214
2215
2215
2216
2216
2217
2217
2218
2218
2219
2219
2220
2220
2221
2221
2222
2222
2223
2223
2224
2224
2225
2225
2226
2226
2227
2227
2228
2228
2229
2229
2230
2230
2231
2231
2232
2232
2233
2233
2234
2234
2235
2235
2236
2236
2237
2237
2238
2238
2239
2240
2240
2241
2241
2242
2242
2243
2243
2244
2244
2245
2245
2246
2246
2247
2247
2248
2248
2249
2249
2250
2250
2251
2251
2252
2252
2253
2253
2254
2254
2255
2255
2256
2256
2257
2257
2258
2258
2259
2259
2260
2260
2261
2261
2262
2262
2263
2263
2264
2264
2265
2265
2266
2266
2267
2267
2268
2268
2269
2269
2270
2270
2271
2271
2272
2272
2273
2273
2274
2274
2275
2275
2276
2276
2277
2277
2278
2278
2279
2279
2280
2280
2281
2281
2282
2282
2283
2283
2284
2284
2285
2285
2286
2286
2287
2287
2288
2288
2289
2289
2290
2290
2291
2291
2292
2292
2293
2293
2294
2294
2295
2295
2296
2296
2297
2297
2298
2298
2299
2299
2300
2300
2301
2301
2302
2302
2303
2304
2304
2305
2305
2306
2306
2307
2307
2308
2308
2309
2309
2310
2310
2311
2311
2312
2312
2313
2313
2314
2314
2315
2315
2316
2316
2317
2317
2318
2318
2319
2319
2320
2320
2321
2321
2322
2322
2323
2323
2324
2324
2325
2325
2326
2326
2327
2327
2328
2328
2329
2329
2330
2330
2331
2331
2332
2332
2333
2333
2334
2334
2335
2335
2336
2336
2337
2337
2338
2338
2339
2339
2340
2340
2341
2341
2342
2342
2343
2343
2344
2344
2345
2345
2346
2346
2347
2347
2348
2348
2349
2349
2350
2350
2351
2351
2352
2352
2353
2353
2354
2354
2355
2355
2356
2356
2357
2357
2358
2358
2359
2359
2360
2360
2361
2361
2362
2362
2363
2363
2364
2364
2365
2365
2366
2366
2367
2368
2368
2369
2369
2370
2370
2371
2371
2372
2372
2373
2373
2374
2374
2375
2375
2376
2376
2377
2377
2378
2378
2379
2379
2380
2380
2381
2381
2382
2382
2383
2383
2384
2384
2385
2385
2386
2386
2387
2387
2388
2388
2389
2389
2390
2390
2391
2391
2392
2392
2393
2393
2394
2394
2395
2395
2396
2396
2397
2397
2398
2398
2399
2399
2400
2400
2401
2401
2402
2402
2403
2403
2404
2404
2405
2405
2406
2406
2407
2407
2408
2408
2409
2409
2410
2410
2411
2411
2412
2412
2413
2413
2414
2414
2415
2415
2416
2416
2417
2417
2418
2418
2419
2419
2420
2420
2421
2421
2422
2422
2423
2423
2424
2424
2425
2425
2426
2426
2427
2427
2428
2428
2429
2429
2430
2430
2431
2432
2432
2433
2433
2434
2434
2435
2435
2436
2436
2437
2437
2438
2438
2439
2439
2440
2440
2441
2441
2442
2442
2443
2443
2444
2444
2445
2445
2446
2446
2447
2447
2448
2448
2449
2449
2450
2450
2451
2451
2452
2452
2453
2453
2454
2454
2455
2455
2456
2456
2457
2457
2458
2458
2459
2459
2460
2460
2461
2461
2462
2462
2463
2463
2464
2464
2465
2465
2466
2466
2467
2467
2468
2468
2469
2469
2470
2470
2471
2471
2472
2472
2473
2473
2474
2474
2475
2475
2476
2476
2477
2477
2478
2478
2479
2479
2480
2480
2481
2481
2482
2482
2483
2483
2484
2484
2485
2485
2486
2486
2487
2487
2488
2488
2489
2489
2490
2490
2491
2491
2492
2492
2493
2493
2494
2494
2495
2496
2496
2497
2497
2498
2498
2499
2499
2500
2500
2501
2501
2502
2502
2503
2503
2504
2504
2505
2505
2506
2506
2507
2507
2508
2508
2509
2509
2510
2510
2511
2511
2512
2512
2513
2513
2514
2514
2515
2515
2516
2516
2517
2517
2518
2518
2519
2519
2520
2520
2521
2521
2522
2522
2523
2523
2524
2524
2525
2525
2526
2526
2527
2527
2528
2528
2529
2529
2530
2530
2531
2531
2532
2532
2533
2533
2534
2534
2535
2535
2536
2536
2537
2537
2538
2538
2539
2539
2540
2540
2541
2541
2542
2542
2543
2543
2544
2544
2545
2545
2546
2546
2547
2547
2548
2548
2549
2549
2550
2550
2551
2551
2552
2552
2553
2553
2554
2554
2555
2555
2556
2556
2557
2557
2558
2558
2559
2560
2560
2561
2561
2562
2562
2563
2563
2564
2564
2565
2565
2566
2566
2567
2567
2568
2568
2569
2569
2570
2570
2571
2571
2572
2572
2573
2573
2574
2574
2575
2575
2576
2576
2577
2577
2578
2578
2579
2579
2580
2580
2581
2581
2582
2582
2583
2583
2584
2584
2585
2585
2586
2586
2587
2587
2588
2588
2589
2589
2590
2590
2591
2591
2592
2592
2593
2593
2594
2594
2595
2595
2596
2596
2597
2597
2598
2598
2599
2599
2600
2600
2601
2601
2602
2602
2603
2603
2604
2604
2605
2605
2606
2606
2607
2607
2608
2608
2609
2609
2610
2610
2611
2611
2612
2612
2613
2613
2614
2614
2615
2615
2616
2616
2617
2617
2618
2618
2619
2619
2620
2620
2621
2621
2622
2622
2623
2624
2624
2625
2625
2626
2626
2627
2627
2628
2628
2629
2629
2630
2630
2631
2631
2632
2632
2633
2633
2634
2634
2635
2635
2636
2636
2637
2637
2638
2638
2639
2639
2640
2640
2641
2641
2642
2642
2643
2643
2644
2644
2645
2645
2646
2646
2647
2647
2648
2648
2649
2649
2650
2650
2651
2651
2652
2652
2653
2653
2654
2654
2655
2655
2656
2656
2657
2657
2658
2658
2659
2659
2660
2660
2661
2661
2662
2662
2663
2663
2664
2664
2665
2665
2666
2666
2667
2667
2668
2668
2669
2669
2670
2670
2671
2671
2672
2672
2673
2673
2674
2674
2675
2675
2676
2676
2677
2677
2678
2678
2679
2679
2680
2680
2681
2681
2682
2682
2683
2683
2684
2684
2685
2685
2686
2686
2687
2688
2688
2689
2689
2690
2690
2691
2691
2692
2692
2693
2693
2694
2694
2695
2695
2696
2696
2697
2697
2698
2698
2699
2699
2700
2700
2701
2701
2702
2702
2703
2703
2704
2704
2705
2705
2706
2706
2707
2707
2708
2708
2709
2709
2710
2710
2711
2711
2712
2712
2713
2713
2714
2714
2715
2715
2716
2716
2717
2717
2718
2718
2719
2719
2720
2720
2721
2721
2722
2722
2723
2723
2724
2724
2725
2725
2726
2726
2727
2727
2728
2728
2729
2729
2730
2730
2731
2731
2732
2732
2733
2733
2734
2734
2735
2735
2736
2736
2737
2737
2738
2738
2739
2739
2740
2740
2741
2741
2742
2742
2743
2743
2744
2744
2745
2745
2746
2746
2747
2747
2748
2748
2749
2749
2750
2750
2751
2752
2752
2753
2753
2754
2754
2755
2755
2756
2756
2757
2757
2758
2758
2759
2759
2760
2760
2761
2761
2762
2762
2763
2763
2764
2764
2765
2765
2766
2766
2767
2767
2768
2768
2769
2769
2770
2770
2771
2771
2772
2772
2773
2773
2774
2774
2775
2775
2776
2776
2777
2777
2778
2778
2779
2779
2780
2780
2781
2781
2782
2782
2783
2783
2784
2784
2785
2785
2786
2786
2787
2787
2788
2788
2789
2789
2790
2790
2791
2791
2792
2792
2793
2793
2794
2794
2795
2795
2796
2796
2797
2797
2798
2798
2799
2799
2800
2800
2801
2801
2802
2802
2803
2803
2804
2804
2805
2805
2806
2806
2807
2807
2808
2808
2809
2809
2810
2810
2811
2811
2812
2812
2813
2813
2814
2814
2815
2816
2816
2817
2817
2818
2818
2819
2819
2820
2820
2821
2821
2822
2822
2823
2823
2824
2824
2825
2825
2826
2826
2827
2827
2828
2828
2829
2829
2830
2830
2831
2831
2832
2832
2833
2833
2834
2834
2835
2835
2836
2836
2837
2837
2838
2838
2839
2839
2840
2840
2841
2841
2842
2842
2843
2843
2844
2844
2845
2845
2846
2846
2847
2847
2848
2848
2849
2849
2850
2850
2851
2851
2852
2852
2853
2853
2854
2854
2855
2855
2856
2856
2857
2857
2858
2858
2859
2859
2860
2860
2861
2861
2862
2862
2863
2863
2864
2864
2865
2865
2866
2866
2867
2867
2868
2868
2869
2869
2870
2870
2871
2871
2872
2872
2873
2873
2874
2874
2875
2875
2876
2876
2877
2877
2878
2878
2879
2880
2880
2881
2881
2882
2882
2883
2883
2884
2884
2885
2885
2886
2886
2887
2887
2888
2888
2889
2889
2890
2890
2891
2891
2892
2892
2893
2893
2894
2894
2895
2895
2896
2896
2897
2897
2898
2898
2899
2899
2900
2900
2901
2901
2902
2902
2903
2903
2904
2904
2905
2905
2906
2906
2907
2907
2908
2908
2909
2909
2910
2910
2911
2911
2912
2912
2913
2913
2914
2914
2915
2915
2916
2916
2917
2917
2918
2918
2919
2919
2920
2920
2921
2921
2922
2922
2923
2923
2924
2924
2925
2925
2926
2926
2927
2927
2928
2928
2929
2929
2930
2930
2931
2931
2932
2932
2933
2933
2934
2934
2935
2935
2936
2936
2937
2937
2938
2938
2939
2939
2940
2940
2941
2941
2942
2942
2943
2944
2944
2945
2945
2946
2946
2947
2947
2948
2948
2949
2949
2950
2950
2951
2951
2952
2952
2953
2953
2954
2954
2955
2955
2956
2956
2957
2957
2958
2958
2959
2959
2960
2960
2961
2961
2962
2962
2963
2963
2964
2964
2965
2965
2966
2966
2967
2967
2968
2968
2969
2969
2970
2970
2971
2971
2972
2972
2973
2973
2974
2974
2975
2975
2976
2976
2977
2977
2978
2978
2979
2979
2980
2980
2981
2981
2982
2982
2983
2983
2984
2984
2985
2985
2986
2986
2987
2987
2988
2988
2989
2989
2990
2990
2991
2991
2992
2992
2993
2993
2994
2994
2995
2995
2996
2996
2997
2997
2998
2998
2999
2999
3000
3000
3001
3001
3002
3002
3003
3003
3004
3004
3005
3005
3006
3006
3007
3008
3008
3009
3009
3010
3010
3011
3011
3012
3012
3013
3013
3014
3014
3015
3015
3016
3016
3017
3017
3018
3018
3019
3019
3020
3020
3021
3021
3022
3022
3023
3023
3024
3024
3025
3025
3026
3026
3027
3027
3028
3028
3029
3029
3030
3030
3031
3031
3032
3032
3033
3033
3034
3034
3035
3035
3036
3036
3037
3037
3038
3038
3039
3039
3040
3040
3041
3041
3042
3042
3043
3043
3044
3044
3045
3045
3046
3046
3047
3047
3048
3048
3049
3049
3050
3050
3051
3051
3052
3052
3053
3053
3054
3054
3055
3055
3056
3056
3057
3057
3058
3058
3059
3059
3060
3060
3061
3061
3062
3062
3063
3063
3064
3064
3065
3065
3066
3066
3067
3067
3068
3068
3069
3069
3070
3070
3071
3072
3072
3073
3073
3074
3074
3075
3075
3076
3076
3077
3077
3078
3078
3079
3079
3080
3080
3081
3081
3082
3082
3083
3083
3084
3084
3085
3085
3086
3086
3087
3087
3088
3088
3089
3089
3090
3090
3091
3091
3092
3092
3093
3093
3094
3094
3095
3095
3096
3096
3097
3097
3098
3098
3099
3099
3100
3100
3101
3101
3102
3102
3103
3103
3104
3104
3105
3105
3106
3106
3107
3107
3108
3108
3109
3109
3110
3110
3111
3111
3112
3112
3113
3113
3114
3114
3115
3115
3116
3116
3117
3117
3118
3118
3119
3119
3120
3120
3121
3121
3122
3122
3123
3123
3124
3124
3125
3125
3126
3126
3127
3127
3128
3128
3129
3129
3130
3130
3131
3131
3132
3132
3133
3133
3134
3134
3135
3136
3136
3137
3137
3138
3138
3139
3139
3140
3140
3141
3141
3142
3142
3143
3143
3144
3144
3145
3145
3146
3146
3147
3147
3148
3148
3149
3149
3150
3150
3151
3151
3152
3152
3153
3153
3154
3154
3155
3155
3156
3156
3157
3157
3158
3158
3159
3159
3160
3160
3161
3161
3162
3162
3163
3163
3164
3164
3165
3165
3166
3166
3167
3167
3168
3168
3169
3169
3170
3170
3171
3171
3172
3172
3173
3173
3174
3174
3175
3175
3176
3176
3177
3177
3178
3178
3179
3179
3180
3180
3181
3181
3182
3182
3183
3183
3184
3184
3185
3185
3186
3186
3187
3187
3188
3188
3189
3189
3190
3190
3191
3191
3192
3192
3193
3193
3194
3194
3195
3195
3196
3196
3197
3197
3198
3198
3199
3200
3200
3201
3201
3202
3202
3203
3203
3204
3204
3205
3205
3206
3206
3207
3207
3208
3208
3209
3209
3210
3210
3211
3211
3212
3212
3213
3213
3214
3214
3215
3215
3216
3216
3217
3217
3218
3218
3219
3219
3220
3220
3221
3221
3222
3222
3223
3223
3224
3224
3225
3225
3226
3226
3227
3227
3228
3228
3229
3229
3230
3230
3231
3231
3232
3232
3233
3233
3234
3234
3235
3235
3236
3236
3237
3237
3238
3238
3239
3239
3240
3240
3241
3241
3242
3242
3243
3243
3244
3244
3245
3245
3246
3246
3247
3247
3248
3248
3249
3249
3250
3250
3251
3251
3252
3252
3253
3253
3254
3254
3255
3255
3256
3256
3257
3257
3258
3258
3259
3259
3260
3260
3261
3261
3262
3262
3263
3264
3264
3265
3265
3266
3266
3267
3267
3268
3268
3269
3269
3270
3270
3271
3271
3272
3272
3273
3273
3274
3274
3275
3275
3276
3276
3277
3277
3278
3278
3279
3279
3280
3280
3281
3281
3282
3282
3283
3283
3284
3284
3285
3285
3286
3286
3287
3287
3288
3288
3289
3289
3290
3290
3291
3291
3292
3292
3293
3293
3294
3294
3295
3295
3296
3296
3297
3297
3298
3298
3299
3299
3300
3300
3301
3301
3302
3302
3303
3303
3304
3304
3305
3305
3306
3306
3307
3307
3308
3308
3309
3309
3310
3310
3311
3311
3312
3312
3313
3313
3314
3314
3315
3315
3316
3316
3317
3317
3318
3318
3319
3319
3320
3320
3321
3321
3322
3322
3323
3323
3324
3324
3325
3325
3326
3326
3327
3328
3328
3329
3329
3330
3330
3331
3331
3332
3332
3333
3333
3334
3334
3335
3335
3336
3336
3337
3337
3338
3338
3339
3339
3340
3340
3341
3341
3342
3342
3343
3343
3344
3344
3345
3345
3346
3346
3347
3347
3348
3348
3349
3349
3350
3350
3351
3351
3352
3352
3353
3353
3354
3354
3355
3355
3356
3356
3357
3357
3358
3358
3359
3359
3360
3360
3361
3361
3362
3362
3363
3363
3364
3364
3365
3365
3366
3366
3367
3367
3368
3368
3369
3369
3370
3370
3371
3371
3372
3372
3373
3373
3374
3374
3375
3375
3376
3376
3377
3377
3378
3378
3379
3379
3380
3380
3381
3381
3382
3382
3383
3383
3384
3384
3385
3385
3386
3386
3387
3387
3388
3388
3389
3389
3390
3390
3391
3392
3392
3393
3393
3394
3394
3395
3395
3396
3396
3397
3397
3398
3398
3399
3399
3400
3400
3401
3401
3402
3402
3403
3403
3404
3404
3405
3405
3406
3406
3407
3407
3408
3408
3409
3409
3410
3410
3411
3411
3412
3412
3413
3413
3414
3414
3415
3415
3416
3416
3417
3417
3418
3418
3419
3419
3420
3420
3421
3421
3422
3422
3423
3423
3424
3424
3425
3425
3426
3426
3427
3427
3428
3428
3429
3429
3430
3430
3431
3431
3432
3432
3433
3433
3434
3434
3435
3435
3436
3436
3437
3437
3438
3438
3439
3439
3440
3440
3441
3441
3442
3442
3443
3443
3444
3444
3445
3445
3446
3446
3447
3447
3448
3448
3449
3449
3450
3450
3451
3451
3452
3452
3453
3453
3454
3454
3455
3456
3456
3457
3457
3458
3458
3459
3459
3460
3460
3461
3461
3462
3462
3463
3463
3464
3464
3465
3465
3466
3466
3467
3467
3468
3468
3469
3469
3470
3470
3471
3471
3472
3472
3473
3473
3474
3474
3475
3475
3476
3476
3477
3477
3478
3478
3479
3479
3480
3480
3481
3481
3482
3482
3483
3483
3484
3484
3485
3485
3486
3486
3487
3487
3488
3488
3489
3489
3490
3490
3491
3491
3492
3492
3493
3493
3494
3494
3495
3495
3496
3496
3497
3497
3498
3498
3499
3499
3500
3500
3501
3501
3502
3502
3503
3503
3504
3504
3505
3505
3506
3506
3507
3507
3508
3508
3509
3509
3510
3510
3511
3511
3512
3512
3513
3513
3514
3514
3515
3515
3516
3516
3517
3517
3518
3518
3519
3520
3520
3521
3521
3522
3522
3523
3523
3524
3524
3525
3525
3526
3526
3527
3527
3528
3528
3529
3529
3530
3530
3531
3531
3532
3532
3533
3533
3534
3534
3535
3535
3536
3536
3537
3537
3538
3538
3539
3539
3540
3540
3541
3541
3542
3542
3543
3543
3544
3544
3545
3545
3546
3546
3547
3547
3548
3548
3549
3549
3550
3550
3551
3551
3552
3552
3553
3553
3554
3554
3555
3555
3556
3556
3557
3557
3558
3558
3559
3559
3560
3560
3561
3561
3562
3562
3563
3563
3564
3564
3565
3565
3566
3566
3567
3567
3568
3568
3569
3569
3570
3570
3571
3571
3572
3572
3573
3573
3574
3574
3575
3575
3576
3576
3577
3577
3578
3578
3579
3579
3580
3580
3581
3581
3582
3582
3583
3584
3584
3585
3585
3586
3586
3587
3587
3588
3588
3589
3589
3590
3590
3591
3591
3592
3592
3593
3593
3594
3594
3595
3595
3596
3596
3597
3597
3598
3598
3599
3599
3600
3600
3601
3601
3602
3602
3603
3603
3604
3604
3605
3605
3606
3606
3607
3607
3608
3608
3609
3609
3610
3610
3611
3611
3612
3612
3613
3613
3614
3614
3615
3615
3616
3616
3617
3617
3618
3618
3619
3619
3620
3620
3621
3621
3622
3622
3623
3623
3624
3624
3625
3625
3626
3626
3627
3627
3628
3628
3629
3629
3630
3630
3631
3631
3632
3632
3633
3633
3634
3634
3635
3635
3636
3636
3637
3637
3638
3638
3639
3639
3640
3640
3641
3641
3642
3642
3643
3643
3644
3644
3645
3645
3646
3646
3647
3648
3648
3649
3649
3650
3650
3651
3651
3652
3652
3653
3653
3654
3654
3655
3655
3656
3656
3657
3657
3658
3658
3659
3659
3660
3660
3661
3661
3662
3662
3663
3663
3664
3664
3665
3665
3666
3666
3667
3667
3668
3668
3669
3669
3670
3670
3671
3671
3672
3672
3673
3673
3674
3674
3675
3675
3676
3676
3677
3677
3678
3678
3679
3679
3680
3680
3681
3681
3682
3682
3683
3683
3684
3684
3685
3685
3686
3686
3687
3687
3688
3688
3689
3689
3690
3690
3691
3691
3692
3692
3693
3693
3694
3694
3695
3695
3696
3696
3697
3697
3698
3698
3699
3699
3700
3700
3701
3701
3702
3702
3703
3703
3704
3704
3705
3705
3706
3706
3707
3707
3708
3708
3709
3709
3710
3710
3711
3712
3712
3713
3713
3714
3714
3715
3715
3716
3716
3717
3717
3718
3718
3719
3719
3720
3720
3721
3721
3722
3722
3723
3723
3724
3724
3725
3725
3726
3726
3727
3727
3728
3728
3729
3729
3730
3730
3731
3731
3732
3732
3733
3733
3734
3734
3735
3735
3736
3736
3737
3737
3738
3738
3739
3739
3740
3740
3741
3741
3742
3742
3743
3743
3744
3744
3745
3745
3746
3746
3747
3747
3748
3748
3749
3749
3750
3750
3751
3751
3752
3752
3753
3753
3754
3754
3755
3755
3756
3756
3757
3757
3758
3758
3759
3759
3760
3760
3761
3761
3762
3762
3763
3763
3764
3764
3765
3765
3766
3766
3767
3767
3768
3768
3769
3769
3770
3770
3771
3771
3772
3772
3773
3773
3774
3774
3775
3776
3776
3777
3777
3778
3778
3779
3779
3780
3780
3781
3781
3782
3782
3783
3783
3784
3784
3785
3785
3786
3786
3787
3787
3788
3788
3789
3789
3790
3790
3791
3791
3792
3792
3793
3793
3794
3794
3795
3795
3796
3796
3797
3797
3798
3798
3799
3799
3800
3800
3801
3801
3802
3802
3803
3803
3804
3804
3805
3805
3806
3806
3807
3807
3808
3808
3809
3809
3810
3810
3811
3811
3812
3812
3813
3813
3814
3814
3815
3815
3816
3816
3817
3817
3818
3818
3819
3819
3820
3820
3821
3821
3822
3822
3823
3823
3824
3824
3825
3825
3826
3826
3827
3827
3828
3828
3829
3829
3830
3830
3831
3831
3832
3832
3833
3833
3834
3834
3835
3835
3836
3836
3837
3837
3838
3838
3839
3840
3840
3841
3841
3842
3842
3843
3843
3844
3844
3845
3845
3846
3846
3847
3847
3848
3848
3849
3849
3850
3850
3851
3851
3852
3852
3853
3853
3854
3854
3855
3855
3856
3856
3857
3857
3858
3858
3859
3859
3860
3860
3861
3861
3862
3862
3863
3863
3864
3864
3865
3865
3866
3866
3867
3867
3868
3868
3869
3869
3870
3870
3871
3871
3872
3872
3873
3873
3874
3874
3875
3875
3876
3876
3877
3877
3878
3878
3879
3879
3880
3880
3881
3881
3882
3882
3883
3883
3884
3884
3885
3885
3886
3886
3887
3887
3888
3888
3889
3889
3890
3890
3891
3891
3892
3892
3893
3893
3894
3894
3895
3895
3896
3896
3897
3897
3898
3898
3899
3899
3900
3900
3901
3901
3902
3902
3903
3904
3904
3905
3905
3906
3906
3907
3907
3908
3908
3909
3909
3910
3910
3911
3911
3912
3912
3913
3913
3914
3914
3915
3915
3916
3916
3917
3917
3918
3918
3919
3919
3920
3920
3921
3921
3922
3922
3923
3923
3924
3924
3925
3925
3926
3926
3927
3927
3928
3928
3929
3929
3930
3930
3931
3931
3932
3932
3933
3933
3934
3934
3935
3935
3936
3936
3937
3937
3938
3938
3939
3939
3940
3940
3941
3941
3942
3942
3943
3943
3944
3944
3945
3945
3946
3946
3947
3947
3948
3948
3949
3949
3950
3950
3951
3951
3952
3952
3953
3953
3954
3954
3955
3955
3956
3956
3957
3957
3958
3958
3959
3959
3960
3960
3961
3961
3962
3962
3963
3963
3964
3964
3965
3965
3966
3966
3967
3968
3968
3969
3969
3970
3970
3971
3971
3972
3972
3973
3973
3974
3974
3975
3975
3976
3976
3977
3977
3978
3978
3979
3979
3980
3980
3981
3981
3982
3982
3983
3983
3984
3984
3985
3985
3986
3986
3987
3987
3988
3988
3989
3989
3990
3990
3991
3991
3992
3992
3993
3993
3994
3994
3995
3995
3996
3996
3997
3997
3998
3998
3999
3999
4000
4000
4001
4001
4002
4002
4003
4003
4004
4004
4005
4005
4006
4006
4007
4007
4008
4008
4009
4009
4010
4010
4011
4011
4012
4012
4013
4013
4014
4014
4015
4015
4016
4016
4017
4017
4018
4018
4019
4019
4020
4020
4021
4021
4022
4022
4023
4023
4024
4024
4025
4025
4026
4026
4027
4027
4028
4028
4029
4029
4030
4030
4031
4032
4032
4033
4033
4034
4034
4035
4035
4036
4036
4037
4037
4038
4038
4039
4039
4040
4040
4041
4041
4042
4042
4043
4043
4044
4044
4045
4045
4046
4046
4047
4047
4048
4048
4049
4049
4050
4050
4051
4051
4052
4052
4053
4053
4054
4054
4055
4055
4056
4056
4057
4057
4058
4058
4059
4059
4060
4060
4061
4061
4062
4062
4063
4063
4064
4064
4065
4065
4066
4066
4067
4067
4068
4068
4069
4069
4070
4070
4071
4071
4072
4072
4073
4073
4074
4074
4075
4075
4076
4076
4077
4077
4078
4078
4079
4079
4080
4080
4081
4081
4082
4082
4083
4083
4084
4084
4085
4085
4086
4086
4087
4087
4088
4088
4089
4089
4090
4090
4091
4091
4092
4092
4093
4093
4094
4094
4095
4096
4096
4097
4097
4098
4098
4099
4099
4100
4100
4101
4101
4102
4102
4103
4103
4104
4104
4105
4105
4106
4106
4107
4107
4108
4108
4109
4109
4110
4110
4111
4111
4112
4112
4113
4113
4114
4114
4115
4115
4116
4116
4117
4117
4118
4118
4119
4119
4120
4120
4121
4121
4122
4122
4123
4123
4124
4124
4125
4125
4126
4126
4127
4127
4128
4128
4129
4129
4130
4130
4131
4131
4132
4132
4133
4133
4134
4134
4135
4135
4136
4136
4137
4137
4138
4138
4139
4139
4140
4140
4141
4141
4142
4142
4143
4143
4144
4144
4145
4145
4146
4146
4147
4147
4148
4148
4149
4149
4150
4150
4151
4151
4152
4152
4153
4153
4154
4154
4155
4155
4156
4156
4157
4157
4158
4158
4159
4160
4160
4161
4161
4162
4162
4163
4163
4164
4164
4165
4165
4166
4166
4167
4167
4168
4168
4169
4169
4170
4170
4171
4171
4172
4172
4173
4173
4174
4174
4175
4175
4176
4176
4177
4177
4178
4178
4179
4179
4180
4180
4181
4181
4182
4182
4183
4183
4184
4184
4185
4185
4186
4186
4187
4187
4188
4188
4189
4189
4190
4190
4191
4191
4192
4192
4193
4193
4194
4194
4195
4195
4196
4196
4197
4197
4198
4198
4199
4199
4200
4200
4201
4201
4202
4202
4203
4203
4204
4204
4205
4205
4206
4206
4207
4207
4208
4208
4209
4209
4210
4210
4211
4211
4212
4212
4213
4213
4214
4214
4215
4215
4216
4216
4217
4217
4218
4218
4219
4219
4220
4220
4221
4221
4222
4222
4223
4224
4224
4225
4225
4226
4226
4227
4227
4228
4228
4229
4229
4230
4230
4231
4231
4232
4232
4233
4233
4234
4234
4235
4235
4236
4236
4237
4237
4238
4238
4239
4239
4240
4240
4241
4241
4242
4242
4243
4243
4244
4244
4245
4245
4246
4246
4247
4247
4248
4248
4249
4249
4250
4250
4251
4251
4252
4252
4253
4253
4254
4254
4255
4255
4256
4256
4257
4257
4258
4258
4259
4259
4260
4260
4261
4261
4262
4262
4263
4263
4264
4264
4265
4265
4266
4266
4267
4267
4268
4268
4269
4269
4270
4270
4271
4271
4272
4272
4273
4273
4274
4274
4275
4275
4276
4276
4277
4277
4278
4278
4279
4279
4280
4280
4281
4281
4282
4282
4283
4283
4284
4284
4285
4285
4286
4286
4287
4288
4288
4289
4289
4290
4290
4291
4291
4292
4292
4293
4293
4294
4294
4295
4295
4296
4296
4297
4297
4298
4298
4299
4299
4300
4300
4301
4301
4302
4302
4303
4303
4304
4304
4305
4305
4306
4306
4307
4307
4308
4308
4309
4309
4310
4310
4311
4311
4312
4312
4313
4313
4314
4314
4315
4315
4316
4316
4317
4317
4318
4318
4319
4319
4320
4320
4321
4321
4322
4322
4323
4323
4324
4324
4325
4325
4326
4326
4327
4327
4328
4328
4329
4329
4330
4330
4331
4331
4332
4332
4333
4333
4334
4334
4335
4335
4336
4336
4337
4337
4338
4338
4339
4339
4340
4340
4341
4341
4342
4342
4343
4343
4344
4344
4345
4345
4346
4346
4347
4347
4348
4348
4349
4349
4350
4350
4351
4352
4352
4353
4353
4354
4354
4355
4355
4356
4356
4357
4357
4358
4358
4359
4359
4360
4360
4361
4361
4362
4362
4363
4363
4364
4364
4365
4365
4366
4366
4367
4367
4368
4368
4369
4369
4370
4370
4371
4371
4372
4372
4373
4373
4374
4374
4375
4375
4376
4376
4377
4377
4378
4378
4379
4379
4380
4380
4381
4381
4382
4382
4383
4383
4384
4384
4385
4385
4386
4386
4387
4387
4388
4388
4389
4389
4390
4390
4391
4391
4392
4392
4393
4393
4394
4394
4395
4395
4396
4396
4397
4397
4398
4398
4399
4399
4400
4400
4401
4401
4402
4402
4403
4403
4404
4404
4405
4405
4406
4406
4407
4407
4408
4408
4409
4409
4410
4410
4411
4411
4412
4412
4413
4413
4414
4414
4415
4416
4416
4417
4417
4418
4418
4419
4419
4420
4420
4421
4421
4422
4422
4423
4423
4424
4424
4425
4425
4426
4426
4427
4427
4428
4428
4429
4429
4430
4430
4431
4431
4432
4432
4433
4433
4434
4434
4435
4435
4436
4436
4437
4437
4438
4438
4439
4439
4440
4440
4441
4441
4442
4442
4443
4443
4444
4444
4445
4445
4446
4446
4447
4447
4448
4448
4449
4449
4450
4450
4451
4451
4452
4452
4453
4453
4454
4454
4455
4455
4456
4456
4457
4457
4458
4458
4459
4459
4460
4460
4461
4461
4462
4462
4463
4463
4464
4464
4465
4465
4466
4466
4467
4467
4468
4468
4469
4469
4470
4470
4471
4471
4472
4472
4473
4473
4474
4474
4475
4475
4476
4476
4477
4477
4478
4478
4479
4480
4480
4481
4481
4482
4482
4483
4483
4484
4484
4485
4485
4486
4486
4487
4487
4488
4488
4489
4489
4490
4490
4491
4491
4492
4492
4493
4493
4494
4494
4495
4495
4496
4496
4497
4497
4498
4498
4499
4499
4500
4500
4501
4501
4502
4502
4503
4503
4504
4504
4505
4505
4506
4506
4507
4507
4508
4508
4509
4509
4510
4510
4511
4511
4512
4512
4513
4513
4514
4514
4515
4515
4516
4516
4517
4517
4518
4518
4519
4519
4520
4520
4521
4521
4522
4522
4523
4523
4524
4524
4525
4525
4526
4526
4527
4527
4528
4528
4529
4529
4530
4530
4531
4531
4532
4532
4533
4533
4534
4534
4535
4535
4536
4536
4537
4537
4538
4538
4539
4539
4540
4540
4541
4541
4542
4542
4543
4544
4544
4545
4545
4546
4546
4547
4547
4548
4548
4549
4549
4550
4550
4551
4551
4552
4552
4553
4553
4554
4554
4555
4555
4556
4556
4557
4557
4558
4558
4559
4559
4560
4560
4561
4561
4562
4562
4563
4563
4564
4564
4565
4565
4566
4566
4567
4567
4568
4568
4569
4569
4570
4570
4571
4571
4572
4572
4573
4573
4574
4574
4575
4575
4576
4576
4577
4577
4578
4578
4579
4579
4580
4580
4581
4581
4582
4582
4583
4583
4584
4584
4585
4585
4586
4586
4587
4587
4588
4588
4589
4589
4590
4590
4591
4591
4592
4592
4593
4593
4594
4594
4595
4595
4596
4596
4597
4597
4598
4598
4599
4599
4600
4600
4601
4601
4602
4602
4603
4603
4604
4604
4605
4605
4606
4606
4607
4608
4608
4609
4609
4610
4610
4611
4611
4612
4612
4613
4613
4614
4614
4615
4615
4616
4616
4617
4617
4618
4618
4619
4619
4620
4620
4621
4621
4622
4622
4623
4623
4624
4624
4625
4625
4626
4626
4627
4627
4628
4628
4629
4629
4630
4630
4631
4631
4632
4632
4633
4633
4634
4634
4635
4635
4636
4636
4637
4637
4638
4638
4639
4639
4640
4640
4641
4641
4642
4642
4643
4643
4644
4644
4645
4645
4646
4646
4647
4647
4648
4648
4649
4649
4650
4650
4651
4651
4652
4652
4653
4653
4654
4654
4655
4655
4656
4656
4657
4657
4658
4658
4659
4659
4660
4660
4661
4661
4662
4662
4663
4663
4664
4664
4665
4665
4666
4666
4667
4667
4668
4668
4669
4669
4670
4670
4671
4672
4672
4673
4673
4674
4674
4675
4675
4676
4676
4677
4677
4678
4678
4679
4679
4680
4680
4681
4681
4682
4682
4683
4683
4684
4684
4685
4685
4686
4686
4687
4687
4688
4688
4689
4689
4690
4690
4691
4691
4692
4692
4693
4693
4694
4694
4695
4695
4696
4696
4697
4697
4698
4698
4699
4699
4700
4700
4701
4701
4702
4702
4703
4703
4704
4704
4705
4705
4706
4706
4707
4707
4708
4708
4709
4709
4710
4710
4711
4711
4712
4712
4713
4713
4714
4714
4715
4715
4716
4716
4717
4717
4718
4718
4719
4719
4720
4720
4721
4721
4722
4722
4723
4723
4724
4724
4725
4725
4726
4726
4727
4727
4728
4728
4729
4729
4730
4730
4731
4731
4732
4732
4733
4733
4734
4734
4735
4736
4736
4737
4737
4738
4738
4739
4739
4740
4740
4741
4741
4742
4742
4743
4743
4744
4744
4745
4745
4746
4746
4747
4747
4748
4748
4749
4749
4750
4750
4751
4751
4752
4752
4753
4753
4754
4754
4755
4755
4756
4756
4757
4757
4758
4758
4759
4759
4760
4760
4761
4761
4762
4762
4763
4763
4764
4764
4765
4765
4766
4766
4767
4767
4768
4768
4769
4769
4770
4770
4771
4771
4772
4772
4773
4773
4774
4774
4775
4775
4776
4776
4777
4777
4778
4778
4779
4779
4780
4780
4781
4781
4782
4782
4783
4783
4784
4784
4785
4785
4786
4786
4787
4787
4788
4788
4789
4789
4790
4790
4791
4791
4792
4792
4793
4793
4794
4794
4795
4795
4796
4796
4797
4797
4798
4798
4799
4800
4800
4801
4801
4802
4802
4803
4803
4804
4804
4805
4805
4806
4806
4807
4807
4808
4808
4809
4809
4810
4810
4811
4811
4812
4812
4813
4813
4814
4814
4815
4815
4816
4816
4817
4817
4818
4818
4819
4819
4820
4820
4821
4821
4822
4822
4823
4823
4824
4824
4825
4825
4826
4826
4827
4827
4828
4828
4829
4829
4830
4830
4831
4831
4832
4832
4833
4833
4834
4834
4835
4835
4836
4836
4837
4837
4838
4838
4839
4839
4840
4840
4841
4841
4842
4842
4843
4843
4844
4844
4845
4845
4846
4846
4847
4847
4848
4848
4849
4849
4850
4850
4851
4851
4852
4852
4853
4853
4854
4854
4855
4855
4856
4856
4857
4857
4858
4858
4859
4859
4860
4860
4861
4861
4862
4862
4863
4864
4864
4865
4865
4866
4866
4867
4867
4868
4868
4869
4869
4870
4870
4871
4871
4872
4872
4873
4873
4874
4874
4875
4875
4876
4876
4877
4877
4878
4878
4879
4879
4880
4880
4881
4881
4882
4882
4883
4883
4884
4884
4885
4885
4886
4886
4887
4887
4888
4888
4889
4889
4890
4890
4891
4891
4892
4892
4893
4893
4894
4894
4895
4895
4896
4896
4897
4897
4898
4898
4899
4899
4900
4900
4901
4901
4902
4902
4903
4903
4904
4904
4905
4905
4906
4906
4907
4907
4908
4908
4909
4909
4910
4910
4911
4911
4912
4912
4913
4913
4914
4914
4915
4915
4916
4916
4917
4917
4918
4918
4919
4919
4920
4920
4921
4921
4922
4922
4923
4923
4924
4924
4925
4925
4926
4926
4927
4928
4928
4929
4929
4930
4930
4931
4931
4932
4932
4933
4933
4934
4934
4935
4935
4936
4936
4937
4937
4938
4938
4939
4939
4940
4940
4941
4941
4942
4942
4943
4943
4944
4944
4945
4945
4946
4946
4947
4947
4948
4948
4949
4949
4950
4950
4951
4951
4952
4952
4953
4953
4954
4954
4955
4955
4956
4956
4957
4957
4958
4958
4959
4959
4960
4960
4961
4961
4962
4962
4963
4963
4964
4964
4965
4965
4966
4966
4967
4967
4968
4968
4969
4969
4970
4970
4971
4971
4972
4972
4973
4973
4974
4974
4975
4975
4976
4976
4977
4977
4978
4978
4979
4979
4980
4980
4981
4981
4982
4982
4983
4983
4984
4984
4985
4985
4986
4986
4987
4987
4988
4988
4989
4989
4990
4990
4991
4992
4992
4993
4993
4994
4994
4995
4995
4996
4996
4997
4997
4998
4998
4999
4999
5000
5000
5001
5001
5002
5002
5003
5003
5004
5004
5005
5005
5006
5006
5007
5007
5008
5008
5009
5009
5010
5010
5011
5011
5012
5012
5013
5013
5014
5014
5015
5015
5016
5016
5017
5017
5018
5018
5019
5019
5020
5020
5021
5021
5022
5022
5023
5023
5024
5024
5025
5025
5026
5026
5027
5027
5028
5028
5029
5029
5030
5030
5031
5031
5032
5032
5033
5033
5034
5034
5035
5035
5036
5036
5037
5037
5038
5038
5039
5039
5040
5040
5041
5041
5042
5042
5043
5043
5044
5044
5045
5045
5046
5046
5047
5047
5048
5048
5049
5049
5050
5050
5051
5051
5052
5052
5053
5053
5054
5054
5055
5056
5056
5057
5057
5058
5058
5059
5059
5060
5060
5061
5061
5062
5062
5063
5063
5064
5064
5065
5065
5066
5066
5067
5067
5068
5068
5069
5069
5070
5070
5071
5071
5072
5072
5073
5073
5074
5074
5075
5075
5076
5076
5077
5077
5078
5078
5079
5079
5080
5080
5081
5081
5082
5082
5083
5083
5084
5084
5085
5085
5086
5086
5087
5087
5088
5088
5089
5089
5090
5090
5091
5091
5092
5092
5093
5093
5094
5094
5095
5095
5096
5096
5097
5097
5098
5098
5099
5099
5100
5100
5101
5101
5102
5102
5103
5103
5104
5104
5105
5105
5106
5106
5107
5107
5108
5108
5109
5109
5110
5110
5111
5111
5112
5112
5113
5113
5114
5114
5115
5115
5116
5116
5117
5117
5118
5118
5119
5120
5120
5121
5121
5122
5122
5123
5123
5124
5124
5125
5125
5126
5126
5127
5127
5128
5128
5129
5129
5130
5130
5131
5131
5132
5132
5133
5133
5134
5134
5135
5135
5136
5136
5137
5137
5138
5138
5139
5139
5140
5140
5141
5141
5142
5142
5143
5143
5144
5144
5145
5145
5146
5146
5147
5147
5148
5148
5149
5149
5150
5150
5151
5151
5152
5152
5153
5153
5154
5154
5155
5155
5156
5156
5157
5157
5158
5158
5159
5159
5160
5160
5161
5161
5162
5162
5163
5163
5164
5164
5165
5165
5166
5166
5167
5167
5168
5168
5169
5169
5170
5170
5171
5171
5172
5172
5173
5173
5174
5174
5175
5175
5176
5176
5177
5177
5178
5178
5179
5179
5180
5180
5181
5181
5182
5182
5183
5184
5184
5185
5185
5186
5186
5187
5187
5188
5188
5189
5189
5190
5190
5191
5191
5192
5192
5193
5193
5194
5194
5195
5195
5196
5196
5197
5197
5198
5198
5199
5199
5200
5200
5201
5201
5202
5202
5203
5203
5204
5204
5205
5205
5206
5206
5207
5207
5208
5208
5209
5209
5210
5210
5211
5211
5212
5212
5213
5213
5214
5214
5215
5215
5216
5216
5217
5217
5218
5218
5219
5219
5220
5220
5221
5221
5222
5222
5223
5223
5224
5224
5225
5225
5226
5226
5227
5227
5228
5228
5229
5229
5230
5230
5231
5231
5232
5232
5233
5233
5234
5234
5235
5235
5236
5236
5237
5237
5238
5238
5239
5239
5240
5240
5241
5241
5242
5242
5243
5243
5244
5244
5245
5245
5246
5246
5247
5248
5248
5249
5249
5250
5250
5251
5251
5252
5252
5253
5253
5254
5254
5255
5255
5256
5256
5257
5257
5258
5258
5259
5259
5260
5260
5261
5261
5262
5262
5263
5263
5264
5264
5265
5265
5266
5266
5267
5267
5268
5268
5269
5269
5270
5270
5271
5271
5272
5272
5273
5273
5274
5274
5275
5275
5276
5276
5277
5277
5278
5278
5279
5279
5280
5280
5281
5281
5282
5282
5283
5283
5284
5284
5285
5285
5286
5286
5287
5287
5288
5288
5289
5289
5290
5290
5291
5291
5292
5292
5293
5293
5294
5294
5295
5295
5296
5296
5297
5297
5298
5298
5299
5299
5300
5300
5301
5301
5302
5302
5303
5303
5304
5304
5305
5305
5306
5306
5307
5307
5308
5308
5309
5309
5310
5310
5311
5312
5312
5313
5313
5314
5314
5315
5315
5316
5316
5317
5317
5318
5318
5319
5319
5320
5320
5321
5321
5322
5322
5323
5323
5324
5324
5325
5325
5326
5326
5327
5327
5328
5328
5329
5329
5330
5330
5331
5331
5332
5332
5333
5333
5334
5334
5335
5335
5336
5336
5337
5337
5338
5338
5339
5339
5340
5340
5341
5341
5342
5342
5343
5343
5344
5344
5345
5345
5346
5346
5347
5347
5348
5348
5349
5349
5350
5350
5351
5351
5352
5352
5353
5353
5354
5354
5355
5355
5356
5356
5357
5357
5358
5358
5359
5359
5360
5360
5361
5361
5362
5362
5363
5363
5364
5364
5365
5365
5366
5366
5367
5367
5368
5368
5369
5369
5370
5370
5371
5371
5372
5372
5373
5373
5374
5374
5375
5376
5376
5377
5377
5378
5378
5379
5379
5380
5380
5381
5381
5382
5382
5383
5383
5384
5384
5385
5385
5386
5386
5387
5387
5388
5388
5389
5389
5390
5390
5391
5391
5392
5392
5393
5393
5394
5394
5395
5395
5396
5396
5397
5397
5398
5398
5399
5399
5400
5400
5401
5401
5402
5402
5403
5403
5404
5404
5405
5405
5406
5406
5407
5407
5408
5408
5409
5409
5410
5410
5411
5411
5412
5412
5413
5413
5414
5414
5415
5415
5416
5416
5417
5417
5418
5418
5419
5419
5420
5420
5421
5421
5422
5422
5423
5423
5424
5424
5425
5425
5426
5426
5427
5427
5428
5428
5429
5429
5430
5430
5431
5431
5432
5432
5433
5433
5434
5434
5435
5435
5436
5436
5437
5437
5438
5438
5439
5440
5440
5441
5441
5442
5442
5443
5443
5444
5444
5445
5445
5446
5446
5447
5447
5448
5448
5449
5449
5450
5450
5451
5451
5452
5452
5453
5453
5454
5454
5455
5455
5456
5456
5457
5457
5458
5458
5459
5459
5460
5460
5461
5461
5462
5462
5463
5463
5464
5464
5465
5465
5466
5466
5467
5467
5468
5468
5469
5469
5470
5470
5471
5471
5472
5472
5473
5473
5474
5474
5475
5475
5476
5476
5477
5477
5478
5478
5479
5479
5480
5480
5481
5481
5482
5482
5483
5483
5484
5484
5485
5485
5486
5486
5487
5487
5488
5488
5489
5489
5490
5490
5491
5491
5492
5492
5493
5493
5494
5494
5495
5495
5496
5496
5497
5497
5498
5498
5499
5499
5500
5500
5501
5501
5502
5502
5503
5504
5504
5505
5505
5506
5506
5507
5507
5508
5508
5509
5509
5510
5510
5511
5511
5512
5512
5513
5513
5514
5514
5515
5515
5516
5516
5517
5517
5518
5518
5519
5519
5520
5520
5521
5521
5522
5522
5523
5523
5524
5524
5525
5525
5526
5526
5527
5527
5528
5528
5529
5529
5530
5530
5531
5531
5532
5532
5533
5533
5534
5534
5535
5535
5536
5536
5537
5537
5538
5538
5539
5539
5540
5540
5541
5541
5542
5542
5543
5543
5544
5544
5545
5545
5546
5546
5547
5547
5548
5548
5549
5549
5550
5550
5551
5551
5552
5552
5553
5553
5554
5554
5555
5555
5556
5556
5557
5557
5558
5558
5559
5559
5560
5560
5561
5561
5562
5562
5563
5563
5564
5564
5565
5565
5566
5566
5567
5568
5568
5569
5569
5570
5570
5571
5571
5572
5572
5573
5573
5574
5574
5575
5575
5576
5576
5577
5577
5578
5578
5579
5579
5580
5580
5581
5581
5582
5582
5583
5583
5584
5584
5585
5585
5586
5586
5587
5587
5588
5588
5589
5589
5590
5590
5591
5591
5592
5592
5593
5593
5594
5594
5595
5595
5596
5596
5597
5597
5598
5598
5599
5599
5600
5600
5601
5601
5602
5602
5603
5603
5604
5604
5605
5605
5606
5606
5607
5607
5608
5608
5609
5609
5610
5610
5611
5611
5612
5612
5613
5613
5614
5614
5615
5615
5616
5616
5617
5617
5618
5618
5619
5619
5620
5620
5621
5621
5622
5622
5623
5623
5624
5624
5625
5625
5626
5626
5627
5627
5628
5628
5629
5629
5630
5630
5631
5632
5632
5633
5633
5634
5634
5635
5635
5636
5636
5637
5637
5638
5638
5639
5639
5640
5640
5641
5641
5642
5642
5643
5643
5644
5644
5645
5645
5646
5646
5647
5647
5648
5648
5649
5649
5650
5650
5651
5651
5652
5652
5653
5653
5654
5654
5655
5655
5656
5656
5657
5657
5658
5658
5659
5659
5660
5660
5661
5661
5662
5662
5663
5663
5664
5664
5665
5665
5666
5666
5667
5667
5668
5668
5669
5669
5670
5670
5671
5671
5672
5672
5673
5673
5674
5674
5675
5675
5676
5676
5677
5677
5678
5678
5679
5679
5680
5680
5681
5681
5682
5682
5683
5683
5684
5684
5685
5685
5686
5686
5687
5687
5688
5688
5689
5689
5690
5690
5691
5691
5692
5692
5693
5693
5694
5694
5695
5696
5696
5697
5697
5698
5698
5699
5699
5700
5700
5701
5701
5702
5702
5703
5703
5704
5704
5705
5705
5706
5706
5707
5707
5708
5708
5709
5709
5710
5710
5711
5711
5712
5712
5713
5713
5714
5714
5715
5715
5716
5716
5717
5717
5718
5718
5719
5719
5720
5720
5721
5721
5722
5722
5723
5723
5724
5724
5725
5725
5726
5726
5727
5727
5728
5728
5729
5729
5730
5730
5731
5731
5732
5732
5733
5733
5734
5734
5735
5735
5736
5736
5737
5737
5738
5738
5739
5739
5740
5740
5741
5741
5742
5742
5743
5743
5744
5744
5745
5745
5746
5746
5747
5747
5748
5748
5749
5749
5750
5750
5751
5751
5752
5752
5753
5753
5754
5754
5755
5755
5756
5756
5757
5757
5758
5758
5759
5760
5760
5761
5761
5762
5762
5763
5763
5764
5764
5765
5765
5766
5766
5767
5767
5768
5768
5769
5769
5770
5770
5771
5771
5772
5772
5773
5773
5774
5774
5775
5775
5776
5776
5777
5777
5778
5778
5779
5779
5780
5780
5781
5781
5782
5782
5783
5783
5784
5784
5785
5785
5786
5786
5787
5787
5788
5788
5789
5789
5790
5790
5791
5791
5792
5792
5793
5793
5794
5794
5795
5795
5796
5796
5797
5797
5798
5798
5799
5799
5800
5800
5801
5801
5802
5802
5803
5803
5804
5804
5805
5805
5806
5806
5807
5807
5808
5808
5809
5809
5810
5810
5811
5811
5812
5812
5813
5813
5814
5814
5815
5815
5816
5816
5817
5817
5818
5818
5819
5819
5820
5820
5821
5821
5822
5822
5823
5824
5824
5825
5825
5826
5826
5827
5827
5828
5828
5829
5829
5830
5830
5831
5831
5832
5832
5833
5833
5834
5834
5835
5835
5836
5836
5837
5837
5838
5838
5839
5839
5840
5840
5841
5841
5842
5842
5843
5843
5844
5844
5845
5845
5846
5846
5847
5847
5848
5848
5849
5849
5850
5850
5851
5851
5852
5852
5853
5853
5854
5854
5855
5855
5856
5856
5857
5857
5858
5858
5859
5859
5860
5860
5861
5861
5862
5862
5863
5863
5864
5864
5865
5865
5866
5866
5867
5867
5868
5868
5869
5869
5870
5870
5871
5871
5872
5872
5873
5873
5874
5874
5875
5875
5876
5876
5877
5877
5878
5878
5879
5879
5880
5880
5881
5881
5882
5882
5883
5883
5884
5884
5885
5885
5886
5886
5887
5888
5888
5889
5889
5890
5890
5891
5891
5892
5892
5893
5893
5894
5894
5895
5895
5896
5896
5897
5897
5898
5898
5899
5899
5900
5900
5901
5901
5902
5902
5903
5903
5904
5904
5905
5905
5906
5906
5907
5907
5908
5908
5909
5909
5910
5910
5911
5911
5912
5912
5913
5913
5914
5914
5915
5915
5916
5916
5917
5917
5918
5918
5919
5919
5920
5920
5921
5921
5922
5922
5923
5923
5924
5924
5925
5925
5926
5926
5927
5927
5928
5928
5929
5929
5930
5930
5931
5931
5932
5932
5933
5933
5934
5934
5935
5935
5936
5936
5937
5937
5938
5938
5939
5939
5940
5940
5941
5941
5942
5942
5943
5943
5944
5944
5945
5945
5946
5946
5947
5947
5948
5948
5949
5949
5950
5950
5951
5952
5952
5953
5953
5954
5954
5955
5955
5956
5956
5957
5957
5958
5958
5959
5959
5960
5960
5961
5961
5962
5962
5963
5963
5964
5964
5965
5965
5966
5966
5967
5967
5968
5968
5969
5969
5970
5970
5971
5971
5972
5972
5973
5973
5974
5974
5975
5975
5976
5976
5977
5977
5978
5978
5979
5979
5980
5980
5981
5981
5982
5982
5983
5983
5984
5984
5985
5985
5986
5986
5987
5987
5988
5988
5989
5989
5990
5990
5991
5991
5992
5992
5993
5993
5994
5994
5995
5995
5996
5996
5997
5997
5998
5998
5999
5999
6000
6000
6001
6001
6002
6002
6003
6003
6004
6004
6005
6005
6006
6006
6007
6007
6008
6008
6009
6009
6010
6010
6011
6011
6012
6012
6013
6013
6014
6014
6015
6016
6016
6017
6017
6018
6018
6019
6019
6020
6020
6021
6021
6022
6022
6023
6023
6024
6024
6025
6025
6026
6026
6027
6027
6028
6028
6029
6029
6030
6030
6031
6031
6032
6032
6033
6033
6034
6034
6035
6035
6036
6036
6037
6037
6038
6038
6039
6039
6040
6040
6041
6041
6042
6042
6043
6043
6044
6044
6045
6045
6046
6046
6047
6047
6048
6048
6049
6049
6050
6050
6051
6051
6052
6052
6053
6053
6054
6054
6055
6055
6056
6056
6057
6057
6058
6058
6059
6059
6060
6060
6061
6061
6062
6062
6063
6063
6064
6064
6065
6065
6066
6066
6067
6067
6068
6068
6069
6069
6070
6070
6071
6071
6072
6072
6073
6073
6074
6074
6075
6075
6076
6076
6077
6077
6078
6078
6079
6080
6080
6081
6081
6082
6082
6083
6083
6084
6084
6085
6085
6086
6086
6087
6087
6088
6088
6089
6089
6090
6090
6091
6091
6092
6092
6093
6093
6094
6094
6095
6095
6096
6096
6097
6097
6098
6098
6099
6099
6100
6100
6101
6101
6102
6102
6103
6103
6104
6104
6105
6105
6106
6106
6107
6107
6108
6108
6109
6109
6110
6110
6111
6111
6112
6112
6113
6113
6114
6114
6115
6115
6116
6116
6117
6117
6118
6118
6119
6119
6120
6120
6121
6121
6122
6122
6123
6123
6124
6124
6125
6125
6126
6126
6127
6127
6128
6128
6129
6129
6130
6130
6131
6131
6132
6132
6133
6133
6134
6134
6135
6135
6136
6136
6137
6137
6138
6138
6139
6139
6140
6140
6141
6141
6142
6142
6143
6144
6144
6145
6145
6146
6146
6147
6147
6148
6148
6149
6149
6150
6150
6151
6151
6152
6152
6153
6153
6154
6154
6155
6155
6156
6156
6157
6157
6158
6158
6159
6159
6160
6160
6161
6161
6162
6162
6163
6163
6164
6164
6165
6165
6166
6166
6167
6167
6168
6168
6169
6169
6170
6170
6171
6171
6172
6172
6173
6173
6174
6174
6175
6175
6176
6176
6177
6177
6178
6178
6179
6179
6180
6180
6181
6181
6182
6182
6183
6183
6184
6184
6185
6185
6186
6186
6187
6187
6188
6188
6189
6189
6190
6190
6191
6191
6192
6192
6193
6193
6194
6194
6195
6195
6196
6196
6197
6197
6198
6198
6199
6199
6200
6200
6201
6201
6202
6202
6203
6203
6204
6204
6205
6205
6206
6206
6207
6208
6208
6209
6209
6210
6210
6211
6211
6212
6212
6213
6213
6214
6214
6215
6215
6216
6216
6217
6217
6218
6218
6219
6219
6220
6220
6221
6221
6222
6222
6223
6223
6224
6224
6225
6225
6226
6226
6227
6227
6228
6228
6229
6229
6230
6230
6231
6231
6232
6232
6233
6233
6234
6234
6235
6235
6236
6236
6237
6237
6238
6238
6239
6239
6240
6240
6241
6241
6242
6242
6243
6243
6244
6244
6245
6245
6246
6246
6247
6247
6248
6248
6249
6249
6250
6250
6251
6251
6252
6252
6253
6253
6254
6254
6255
6255
6256
6256
6257
6257
6258
6258
6259
6259
6260
6260
6261
6261
6262
6262
6263
6263
6264
6264
6265
6265
6266
6266
6267
6267
6268
6268
6269
6269
6270
6270
6271
6272
6272
6273
6273
6274
6274
6275
6275
6276
6276
6277
6277
6278
6278
6279
6279
6280
6280
6281
6281
6282
6282
6283
6283
6284
6284
6285
6285
6286
6286
6287
6287
6288
6288
6289
6289
6290
6290
6291
6291
6292
6292
6293
6293
6294
6294
6295
6295
6296
6296
6297
6297
6298
6298
6299
6299
6300
6300
6301
6301
6302
6302
6303
6303
6304
6304
6305
6305
6306
6306
6307
6307
6308
6308
6309
6309
6310
6310
6311
6311
6312
6312
6313
6313
6314
6314
6315
6315
6316
6316
6317
6317
6318
6318
6319
6319
6320
6320
6321
6321
6322
6322
6323
6323
6324
6324
6325
6325
6326
6326
6327
6327
6328
6328
6329
6329
6330
6330
6331
6331
6332
6332
6333
6333
6334
6334
6335
6336
6336
6337
6337
6338
6338
6339
6339
6340
6340
6341
6341
6342
6342
6343
6343
6344
6344
6345
6345
6346
6346
6347
6347
6348
6348
6349
6349
6350
6350
6351
6351
6352
6352
6353
6353
6354
6354
6355
6355
6356
6356
6357
6357
6358
6358
6359
6359
6360
6360
6361
6361
6362
6362
6363
6363
6364
6364
6365
6365
6366
6366
6367
6367
6368
6368
6369
6369
6370
6370
6371
6371
6372
6372
6373
6373
6374
6374
6375
6375
6376
6376
6377
6377
6378
6378
6379
6379
6380
6380
6381
6381
6382
6382
6383
6383
6384
6384
6385
6385
6386
6386
6387
6387
6388
6388
6389
6389
6390
6390
6391
6391
6392
6392
6393
6393
6394
6394
6395
6395
6396
6396
6397
6397
6398
6398
6399
6400
6400
6401
6401
6402
6402
6403
6403
6404
6404
6405
6405
6406
6406
6407
6407
6408
6408
6409
6409
6410
6410
6411
6411
6412
6412
6413
6413
6414
6414
6415
6415
6416
6416
6417
6417
6418
6418
6419
6419
6420
6420
6421
6421
6422
6422
6423
6423
6424
6424
6425
6425
6426
6426
6427
6427
6428
6428
6429
6429
6430
6430
6431
6431
6432
6432
6433
6433
6434
6434
6435
6435
6436
6436
6437
6437
6438
6438
6439
6439
6440
6440
6441
6441
6442
6442
6443
6443
6444
6444
6445
6445
6446
6446
6447
6447
6448
6448
6449
6449
6450
6450
6451
6451
6452
6452
6453
6453
6454
6454
6455
6455
6456
6456
6457
6457
6458
6458
6459
6459
6460
6460
6461
6461
6462
6462
6463
6464
6464
6465
6465
6466
6466
6467
6467
6468
6468
6469
6469
6470
6470
6471
6471
6472
6472
6473
6473
6474
6474
6475
6475
6476
6476
6477
6477
6478
6478
6479
6479
6480
6480
6481
6481
6482
6482
6483
6483
6484
6484
6485
6485
6486
6486
6487
6487
6488
6488
6489
6489
6490
6490
6491
6491
6492
6492
6493
6493
6494
6494
6495
6495
6496
6496
6497
6497
6498
6498
6499
6499
6500
6500
6501
6501
6502
6502
6503
6503
6504
6504
6505
6505
6506
6506
6507
6507
6508
6508
6509
6509
6510
6510
6511
6511
6512
6512
6513
6513
6514
6514
6515
6515
6516
6516
6517
6517
6518
6518
6519
6519
6520
6520
6521
6521
6522
6522
6523
6523
6524
6524
6525
6525
6526
6526
6527
6528
6528
6529
6529
6530
6530
6531
6531
6532
6532
6533
6533
6534
6534
6535
6535
6536
6536
6537
6537
6538
6538
6539
6539
6540
6540
6541
6541
6542
6542
6543
6543
6544
6544
6545
6545
6546
6546
6547
6547
6548
6548
6549
6549
6550
6550
6551
6551
6552
6552
6553
6553
6554
6554
6555
6555
6556
6556
6557
6557
6558
6558
6559
6559
6560
6560
6561
6561
6562
6562
6563
6563
6564
6564
6565
6565
6566
6566
6567
6567
6568
6568
6569
6569
6570
6570
6571
6571
6572
6572
6573
6573
6574
6574
6575
6575
6576
6576
6577
6577
6578
6578
6579
6579
6580
6580
6581
6581
6582
6582
6583
6583
6584
6584
6585
6585
6586
6586
6587
6587
6588
6588
6589
6589
6590
6590
6591
6592
6592
6593
6593
6594
6594
6595
6595
6596
6596
6597
6597
6598
6598
6599
6599
6600
6600
6601
6601
6602
6602
6603
6603
6604
6604
6605
6605
6606
6606
6607
6607
6608
6608
6609
6609
6610
6610
6611
6611
6612
6612
6613
6613
6614
6614
6615
6615
6616
6616
6617
6617
6618
6618
6619
6619
6620
6620
6621
6621
6622
6622
6623
6623
6624
6624
6625
6625
6626
6626
6627
6627
6628
6628
6629
6629
6630
6630
6631
6631
6632
6632
6633
6633
6634
6634
6635
6635
6636
6636
6637
6637
6638
6638
6639
6639
6640
6640
6641
6641
6642
6642
6643
6643
6644
6644
6645
6645
6646
6646
6647
6647
6648
6648
6649
6649
6650
6650
6651
6651
6652
6652
6653
6653
6654
6654
6655
6656
6656
6657
6657
6658
6658
6659
6659
6660
6660
6661
6661
6662
6662
6663
6663
6664
6664
6665
6665
6666
6666
6667
6667
6668
6668
6669
6669
6670
6670
6671
6671
6672
6672
6673
6673
6674
6674
6675
6675
6676
6676
6677
6677
6678
6678
6679
6679
6680
6680
6681
6681
6682
6682
6683
6683
6684
6684
6685
6685
6686
6686
6687
6687
6688
6688
6689
6689
6690
6690
6691
6691
6692
6692
6693
6693
6694
6694
6695
6695
6696
6696
6697
6697
6698
6698
6699
6699
6700
6700
6701
6701
6702
6702
6703
6703
6704
6704
6705
6705
6706
6706
6707
6707
6708
6708
6709
6709
6710
6710
6711
6711
6712
6712
6713
6713
6714
6714
6715
6715
6716
6716
6717
6717
6718
6718
6719
6720
6720
6721
6721
6722
6722
6723
6723
6724
6724
6725
6725
6726
6726
6727
6727
6728
6728
6729
6729
6730
6730
6731
6731
6732
6732
6733
6733
6734
6734
6735
6735
6736
6736
6737
6737
6738
6738
6739
6739
6740
6740
6741
6741
6742
6742
6743
6743
6744
6744
6745
6745
6746
6746
6747
6747
6748
6748
6749
6749
6750
6750
6751
6751
6752
6752
6753
6753
6754
6754
6755
6755
6756
6756
6757
6757
6758
6758
6759
6759
6760
6760
6761
6761
6762
6762
6763
6763
6764
6764
6765
6765
6766
6766
6767
6767
6768
6768
6769
6769
6770
6770
6771
6771
6772
6772
6773
6773
6774
6774
6775
6775
6776
6776
6777
6777
6778
6778
6779
6779
6780
6780
6781
6781
6782
6782
6783
6784
6784
6785
6785
6786
6786
6787
6787
6788
6788
6789
6789
6790
6790
6791
6791
6792
6792
6793
6793
6794
6794
6795
6795
6796
6796
6797
6797
6798
6798
6799
6799
6800
6800
6801
6801
6802
6802
6803
6803
6804
6804
6805
6805
6806
6806
6807
6807
6808
6808
6809
6809
6810
6810
6811
6811
6812
6812
6813
6813
6814
6814
6815
6815
6816
6816
6817
6817
6818
6818
6819
6819
6820
6820
6821
6821
6822
6822
6823
6823
6824
6824
6825
6825
6826
6826
6827
6827
6828
6828
6829
6829
6830
6830
6831
6831
6832
6832
6833
6833
6834
6834
6835
6835
6836
6836
6837
6837
6838
6838
6839
6839
6840
6840
6841
6841
6842
6842
6843
6843
6844
6844
6845
6845
6846
6846
6847
6848
6848
6849
6849
6850
6850
6851
6851
6852
6852
6853
6853
6854
6854
6855
6855
6856
6856
6857
6857
6858
6858
6859
6859
6860
6860
6861
6861
6862
6862
6863
6863
6864
6864
6865
6865
6866
6866
6867
6867
6868
6868
6869
6869
6870
6870
6871
6871
6872
6872
6873
6873
6874
6874
6875
6875
6876
6876
6877
6877
6878
6878
6879
6879
6880
6880
6881
6881
6882
6882
6883
6883
6884
6884
6885
6885
6886
6886
6887
6887
6888
6888
6889
6889
6890
6890
6891
6891
6892
6892
6893
6893
6894
6894
6895
6895
6896
6896
6897
6897
6898
6898
6899
6899
6900
6900
6901
6901
6902
6902
6903
6903
6904
6904
6905
6905
6906
6906
6907
6907
6908
6908
6909
6909
6910
6910
6911
6912
6912
6913
6913
6914
6914
6915
6915
6916
6916
6917
6917
6918
6918
6919
6919
6920
6920
6921
6921
6922
6922
6923
6923
6924
6924
6925
6925
6926
6926
6927
6927
6928
6928
6929
6929
6930
6930
6931
6931
6932
6932
6933
6933
6934
6934
6935
6935
6936
6936
6937
6937
6938
6938
6939
6939
6940
6940
6941
6941
6942
6942
6943
6943
6944
6944
6945
6945
6946
6946
6947
6947
6948
6948
6949
6949
6950
6950
6951
6951
6952
6952
6953
6953
6954
6954
6955
6955
6956
6956
6957
6957
6958
6958
6959
6959
6960
6960
6961
6961
6962
6962
6963
6963
6964
6964
6965
6965
6966
6966
6967
6967
6968
6968
6969
6969
6970
6970
6971
6971
6972
6972
6973
6973
6974
6974
6975
6976
6976
6977
6977
6978
6978
6979
6979
6980
6980
6981
6981
6982
6982
6983
6983
6984
6984
6985
6985
6986
6986
6987
6987
6988
6988
6989
6989
6990
6990
6991
6991
6992
6992
6993
6993
6994
6994
6995
6995
6996
6996
6997
6997
6998
6998
6999
6999
7000
7000
7001
7001
7002
7002
7003
7003
7004
7004
7005
7005
7006
7006
7007
7007
7008
7008
7009
7009
7010
7010
7011
7011
7012
7012
7013
7013
7014
7014
7015
7015
7016
7016
7017
7017
7018
7018
7019
7019
7020
7020
7021
7021
7022
7022
7023
7023
7024
7024
7025
7025
7026
7026
7027
7027
7028
7028
7029
7029
7030
7030
7031
7031
7032
7032
7033
7033
7034
7034
7035
7035
7036
7036
7037
7037
7038
7038
7039
7040
7040
7041
7041
7042
7042
7043
7043
7044
7044
7045
7045
7046
7046
7047
7047
7048
7048
7049
7049
7050
7050
7051
7051
7052
7052
7053
7053
7054
7054
7055
7055
7056
7056
7057
7057
7058
7058
7059
7059
7060
7060
7061
7061
7062
7062
7063
7063
7064
7064
7065
7065
7066
7066
7067
7067
7068
7068
7069
7069
7070
7070
7071
7071
7072
7072
7073
7073
7074
7074
7075
7075
7076
7076
7077
7077
7078
7078
7079
7079
7080
7080
7081
7081
7082
7082
7083
7083
7084
7084
7085
7085
7086
7086
7087
7087
7088
7088
7089
7089
7090
7090
7091
7091
7092
7092
7093
7093
7094
7094
7095
7095
7096
7096
7097
7097
7098
7098
7099
7099
7100
7100
7101
7101
7102
7102
7103
7104
7104
7105
7105
7106
7106
7107
7107
7108
7108
7109
7109
7110
7110
7111
7111
7112
7112
7113
7113
7114
7114
7115
7115
7116
7116
7117
7117
7118
7118
7119
7119
7120
7120
7121
7121
7122
7122
7123
7123
7124
7124
7125
7125
7126
7126
7127
7127
7128
7128
7129
7129
7130
7130
7131
7131
7132
7132
7133
7133
7134
7134
7135
7135
7136
7136
7137
7137
7138
7138
7139
7139
7140
7140
7141
7141
7142
7142
7143
7143
7144
7144
7145
7145
7146
7146
7147
7147
7148
7148
7149
7149
7150
7150
7151
7151
7152
7152
7153
7153
7154
7154
7155
7155
7156
7156
7157
7157
7158
7158
7159
7159
7160
7160
7161
7161
7162
7162
7163
7163
7164
7164
7165
7165
7166
7166
7167
7168
7168
7169
7169
7170
7170
7171
7171
7172
7172
7173
7173
7174
7174
7175
7175
7176
7176
7177
7177
7178
7178
7179
7179
7180
7180
7181
7181
7182
7182
7183
7183
7184
7184
7185
7185
7186
7186
7187
7187
7188
7188
7189
7189
7190
7190
7191
7191
7192
7192
7193
7193
7194
7194
7195
7195
7196
7196
7197
7197
7198
7198
7199
7199
7200
7200
7201
7201
7202
7202
7203
7203
7204
7204
7205
7205
7206
7206
7207
7207
7208
7208
7209
7209
7210
7210
7211
7211
7212
7212
7213
7213
7214
7214
7215
7215
7216
7216
7217
7217
7218
7218
7219
7219
7220
7220
7221
7221
7222
7222
7223
7223
7224
7224
7225
7225
7226
7226
7227
7227
7228
7228
7229
7229
7230
7230
7231
7232
7232
7233
7233
7234
7234
7235
7235
7236
7236
7237
7237
7238
7238
7239
7239
7240
7240
7241
7241
7242
7242
7243
7243
7244
7244
7245
7245
7246
7246
7247
7247
7248
7248
7249
7249
7250
7250
7251
7251
7252
7252
7253
7253
7254
7254
7255
7255
7256
7256
7257
7257
7258
7258
7259
7259
7260
7260
7261
7261
7262
7262
7263
7263
7264
7264
7265
7265
7266
7266
7267
7267
7268
7268
7269
7269
7270
7270
7271
7271
7272
7272
7273
7273
7274
7274
7275
7275
7276
7276
7277
7277
7278
7278
7279
7279
7280
7280
7281
7281
7282
7282
7283
7283
7284
7284
7285
7285
7286
7286
7287
7287
7288
7288
7289
7289
7290
7290
7291
7291
7292
7292
7293
7293
7294
7294
7295
7296
7296
7297
7297
7298
7298
7299
7299
7300
7300
7301
7301
7302
7302
7303
7303
7304
7304
7305
7305
7306
7306
7307
7307
7308
7308
7309
7309
7310
7310
7311
7311
7312
7312
7313
7313
7314
7314
7315
7315
7316
7316
7317
7317
7318
7318
7319
7319
7320
7320
7321
7321
7322
7322
7323
7323
7324
7324
7325
7325
7326
7326
7327
7327
7328
7328
7329
7329
7330
7330
7331
7331
7332
7332
7333
7333
7334
7334
7335
7335
7336
7336
7337
7337
7338
7338
7339
7339
7340
7340
7341
7341
7342
7342
7343
7343
7344
7344
7345
7345
7346
7346
7347
7347
7348
7348
7349
7349
7350
7350
7351
7351
7352
7352
7353
7353
7354
7354
7355
7355
7356
7356
7357
7357
7358
7358
7359
7360
7360
7361
7361
7362
7362
7363
7363
7364
7364
7365
7365
7366
7366
7367
7367
7368
7368
7369
7369
7370
7370
7371
7371
7372
7372
7373
7373
7374
7374
7375
7375
7376
7376
7377
7377
7378
7378
7379
7379
7380
7380
7381
7381
7382
7382
7383
7383
7384
7384
7385
7385
7386
7386
7387
7387
7388
7388
7389
7389
7390
7390
7391
7391
7392
7392
7393
7393
7394
7394
7395
7395
7396
7396
7397
7397
7398
7398
7399
7399
7400
7400
7401
7401
7402
7402
7403
7403
7404
7404
7405
7405
7406
7406
7407
7407
7408
7408
7409
7409
7410
7410
7411
7411
7412
7412
7413
7413
7414
7414
7415
7415
7416
7416
7417
7417
7418
7418
7419
7419
7420
7420
7421
7421
7422
7422
7423
7424
7424
7425
7425
7426
7426
7427
7427
7428
7428
7429
7429
7430
7430
7431
7431
7432
7432
7433
7433
7434
7434
7435
7435
7436
7436
7437
7437
7438
7438
7439
7439
7440
7440
7441
7441
7442
7442
7443
7443
7444
7444
7445
7445
7446
7446
7447
7447
7448
7448
7449
7449
7450
7450
7451
7451
7452
7452
7453
7453
7454
7454
7455
7455
7456
7456
7457
7457
7458
7458
7459
7459
7460
7460
7461
7461
7462
7462
7463
7463
7464
7464
7465
7465
7466
7466
7467
7467
7468
7468
7469
7469
7470
7470
7471
7471
7472
7472
7473
7473
7474
7474
7475
7475
7476
7476
7477
7477
7478
7478
7479
7479
7480
7480
7481
7481
7482
7482
7483
7483
7484
7484
7485
7485
7486
7486
7487
7488
7488
7489
7489
7490
7490
7491
7491
7492
7492
7493
7493
7494
7494
7495
7495
7496
7496
7497
7497
7498
7498
7499
7499
7500
7500
7501
7501
7502
7502
7503
7503
7504
7504
7505
7505
7506
7506
7507
7507
7508
7508
7509
7509
7510
7510
7511
7511
7512
7512
7513
7513
7514
7514
7515
7515
7516
7516
7517
7517
7518
7518
7519
7519
7520
7520
7521
7521
7522
7522
7523
7523
7524
7524
7525
7525
7526
7526
7527
7527
7528
7528
7529
7529
7530
7530
7531
7531
7532
7532
7533
7533
7534
7534
7535
7535
7536
7536
7537
7537
7538
7538
7539
7539
7540
7540
7541
7541
7542
7542
7543
7543
7544
7544
7545
7545
7546
7546
7547
7547
7548
7548
7549
7549
7550
7550
7551
7552
7552
7553
7553
7554
7554
7555
7555
7556
7556
7557
7557
7558
7558
7559
7559
7560
7560
7561
7561
7562
7562
7563
7563
7564
7564
7565
7565
7566
7566
7567
7567
7568
7568
7569
7569
7570
7570
7571
7571
7572
7572
7573
7573
7574
7574
7575
7575
7576
7576
7577
7577
7578
7578
7579
7579
7580
7580
7581
7581
7582
7582
7583
7583
7584
7584
7585
7585
7586
7586
7587
7587
7588
7588
7589
7589
7590
7590
7591
7591
7592
7592
7593
7593
7594
7594
7595
7595
7596
7596
7597
7597
7598
7598
7599
7599
7600
7600
7601
7601
7602
7602
7603
7603
7604
7604
7605
7605
7606
7606
7607
7607
7608
7608
7609
7609
7610
7610
7611
7611
7612
7612
7613
7613
7614
7614
7615
7616
7616
7617
7617
7618
7618
7619
7619
7620
7620
7621
7621
7622
7622
7623
7623
7624
7624
7625
7625
7626
7626
7627
7627
7628
7628
7629
7629
7630
7630
7631
7631
7632
7632
7633
7633
7634
7634
7635
7635
7636
7636
7637
7637
7638
7638
7639
7639
7640
7640
7641
7641
7642
7642
7643
7643
7644
7644
7645
7645
7646
7646
7647
7647
7648
7648
7649
7649
7650
7650
7651
7651
7652
7652
7653
7653
7654
7654
7655
7655
7656
7656
7657
7657
7658
7658
7659
7659
7660
7660
7661
7661
7662
7662
7663
7663
7664
7664
7665
7665
7666
7666
7667
7667
7668
7668
7669
7669
7670
7670
7671
7671
7672
7672
7673
7673
7674
7674
7675
7675
7676
7676
7677
7677
7678
7678
7679
7680
7680
7681
7681
7682
7682
7683
7683
7684
7684
7685
7685
7686
7686
7687
7687
7688
7688
7689
7689
7690
7690
7691
7691
7692
7692
7693
7693
7694
7694
7695
7695
7696
7696
7697
7697
7698
7698
7699
7699
7700
7700
7701
7701
7702
7702
7703
7703
7704
7704
7705
7705
7706
7706
7707
7707
7708
7708
7709
7709
7710
7710
7711
7711
7712
7712
7713
7713
7714
7714
7715
7715
7716
7716
7717
7717
7718
7718
7719
7719
7720
7720
7721
7721
7722
7722
7723
7723
7724
7724
7725
7725
7726
7726
7727
7727
7728
7728
7729
7729
7730
7730
7731
7731
7732
7732
7733
7733
7734
7734
7735
7735
7736
7736
7737
7737
7738
7738
7739
7739
7740
7740
7741
7741
7742
7742
7743
7744
7744
7745
7745
7746
7746
7747
7747
7748
7748
7749
7749
7750
7750
7751
7751
7752
7752
7753
7753
7754
7754
7755
7755
7756
7756
7757
7757
7758
7758
7759
7759
7760
7760
7761
7761
7762
7762
7763
7763
7764
7764
7765
7765
7766
7766
7767
7767
7768
7768
7769
7769
7770
7770
7771
7771
7772
7772
7773
7773
7774
7774
7775
7775
7776
7776
7777
7777
7778
7778
7779
7779
7780
7780
7781
7781
7782
7782
7783
7783
7784
7784
7785
7785
7786
7786
7787
7787
7788
7788
7789
7789
7790
7790
7791
7791
7792
7792
7793
7793
7794
7794
7795
7795
7796
7796
7797
7797
7798
7798
7799
7799
7800
7800
7801
7801
7802
7802
7803
7803
7804
7804
7805
7805
7806
7806
7807
7808
7808
7809
7809
7810
7810
7811
7811
7812
7812
7813
7813
7814
7814
7815
7815
7816
7816
7817
7817
7818
7818
7819
7819
7820
7820
7821
7821
7822
7822
7823
7823
7824
7824
7825
7825
7826
7826
7827
7827
7828
7828
7829
7829
7830
7830
7831
7831
7832
7832
7833
7833
7834
7834
7835
7835
7836
7836
7837
7837
7838
7838
7839
7839
7840
7840
7841
7841
7842
7842
7843
7843
7844
7844
7845
7845
7846
7846
7847
7847
7848
7848
7849
7849
7850
7850
7851
7851
7852
7852
7853
7853
7854
7854
7855
7855
7856
7856
7857
7857
7858
7858
7859
7859
7860
7860
7861
7861
7862
7862
7863
7863
7864
7864
7865
7865
7866
7866
7867
7867
7868
7868
7869
7869
7870
7870
7871
7872
7872
7873
7873
7874
7874
7875
7875
7876
7876
7877
7877
7878
7878
7879
7879
7880
7880
7881
7881
7882
7882
7883
7883
7884
7884
7885
7885
7886
7886
7887
7887
7888
7888
7889
7889
7890
7890
7891
7891
7892
7892
7893
7893
7894
7894
7895
7895
7896
7896
7897
7897
7898
7898
7899
7899
7900
7900
7901
7901
7902
7902
7903
7903
7904
7904
7905
7905
7906
7906
7907
7907
7908
7908
7909
7909
7910
7910
7911
7911
7912
7912
7913
7913
7914
7914
7915
7915
7916
7916
7917
7917
7918
7918
7919
7919
7920
7920
7921
7921
7922
7922
7923
7923
7924
7924
7925
7925
7926
7926
7927
7927
7928
7928
7929
7929
7930
7930
7931
7931
7932
7932
7933
7933
7934
7934
7935
7936
7936
7937
7937
7938
7938
7939
7939
7940
7940
7941
7941
7942
7942
7943
7943
7944
7944
7945
7945
7946
7946
7947
7947
7948
7948
7949
7949
7950
7950
7951
7951
7952
7952
7953
7953
7954
7954
7955
7955
7956
7956
7957
7957
7958
7958
7959
7959
7960
7960
7961
7961
7962
7962
7963
7963
7964
7964
7965
7965
7966
7966
7967
7967
7968
7968
7969
7969
7970
7970
7971
7971
7972
7972
7973
7973
7974
7974
7975
7975
7976
7976
7977
7977
7978
7978
7979
7979
7980
7980
7981
7981
7982
7982
7983
7983
7984
7984
7985
7985
7986
7986
7987
7987
7988
7988
7989
7989
7990
7990
7991
7991
7992
7992
7993
7993
7994
7994
7995
7995
7996
7996
7997
7997
7998
7998
7999
8000
8000
8001
8001
8002
8002
8003
8003
8004
8004
8005
8005
8006
8006
8007
8007
8008
8008
8009
8009
8010
8010
8011
8011
8012
8012
8013
8013
8014
8014
8015
8015
8016
8016
8017
8017
8018
8018
8019
8019
8020
8020
8021
8021
8022
8022
8023
8023
8024
8024
8025
8025
8026
8026
8027
8027
8028
8028
8029
8029
8030
8030
8031
8031
8032
8032
8033
8033
8034
8034
8035
8035
8036
8036
8037
8037
8038
8038
8039
8039
8040
8040
8041
8041
8042
8042
8043
8043
8044
8044
8045
8045
8046
8046
8047
8047
8048
8048
8049
8049
8050
8050
8051
8051
8052
8052
8053
8053
8054
8054
8055
8055
8056
8056
8057
8057
8058
8058
8059
8059
8060
8060
8061
8061
8062
8062
8063
8064
8064
8065
8065
8066
8066
8067
8067
8068
8068
8069
8069
8070
8070
8071
8071
8072
8072
8073
8073
8074
8074
8075
8075
8076
8076
8077
8077
8078
8078
8079
8079
8080
8080
8081
8081
8082
8082
8083
8083
8084
8084
8085
8085
8086
8086
8087
8087
8088
8088
8089
8089
8090
8090
8091
8091
8092
8092
8093
8093
8094
8094
8095
8095
8096
8096
8097
8097
8098
8098
8099
8099
8100
8100
8101
8101
8102
8102
8103
8103
8104
8104
8105
8105
8106
8106
8107
8107
8108
8108
8109
8109
8110
8110
8111
8111
8112
8112
8113
8113
8114
8114
8115
8115
8116
8116
8117
8117
8118
8118
8119
8119
8120
8120
8121
8121
8122
8122
8123
8123
8124
8124
8125
8125
8126
8126
8127
8128
8128
8129
8129
8130
8130
8131
8131
8132
8132
8133
8133
8134
8134
8135
8135
8136
8136
8137
8137
8138
8138
8139
8139
8140
8140
8141
8141
8142
8142
8143
8143
8144
8144
8145
8145
8146
8146
8147
8147
8148
8148
8149
8149
8150
8150
8151
8151
8152
8152
8153
8153
8154
8154
8155
8155
8156
8156
8157
8157
8158
8158
8159
8159
8160
8160
8161
8161
8162
8162
8163
8163
8164
8164
8165
8165
8166
8166
8167
8167
8168
8168
8169
8169
8170
8170
8171
8171
8172
8172
8173
8173
8174
8174
8175
8175
8176
8176
8177
8177
8178
8178
8179
8179
8180
8180
8181
8181
8182
8182
8183
8183
8184
8184
8185
8185
8186
8186
8187
8187
8188
8188
8189
8189
8190
8190
8191
8192
8192
8193
8193
8194
8194
8195
8195
8196
8196
8197
8197
8198
8198
8199
8199
8200
8200
8201
8201
8202
8202
8203
8203
8204
8204
8205
8205
8206
8206
8207
8207
8208
8208
8209
8209
8210
8210
8211
8211
8212
8212
8213
8213
8214
8214
8215
8215
8216
8216
8217
8217
8218
8218
8219
8219
8220
8220
8221
8221
8222
8222
8223
8223
8224
8224
8225
8225
8226
8226
8227
8227
8228
8228
8229
8229
8230
8230
8231
8231
8232
8232
8233
8233
8234
8234
8235
8235
8236
8236
8237
8237
8238
8238
8239
8239
8240
8240
8241
8241
8242
8242
8243
8243
8244
8244
8245
8245
8246
8246
8247
8247
8248
8248
8249
8249
8250
8250
8251
8251
8252
8252
8253
8253
8254
8254
8255
8256
8256
8257
8257
8258
8258
8259
8259
8260
8260
8261
8261
8262
8262
8263
8263
8264
8264
8265
8265
8266
8266
8267
8267
8268
8268
8269
8269
8270
8270
8271
8271
8272
8272
8273
8273
8274
8274
8275
8275
8276
8276
8277
8277
8278
8278
8279
8279
8280
8280
8281
8281
8282
8282
8283
8283
8284
8284
8285
8285
8286
8286
8287
8287
8288
8288
8289
8289
8290
8290
8291
8291
8292
8292
8293
8293
8294
8294
8295
8295
8296
8296
8297
8297
8298
8298
8299
8299
8300
8300
8301
8301
8302
8302
8303
8303
8304
8304
8305
8305
8306
8306
8307
8307
8308
8308
8309
8309
8310
8310
8311
8311
8312
8312
8313
8313
8314
8314
8315
8315
8316
8316
8317
8317
8318
8318
8319
8320
8320
8321
8321
8322
8322
8323
8323
8324
8324
8325
8325
8326
8326
8327
8327
8328
8328
8329
8329
8330
8330
8331
8331
8332
8332
8333
8333
8334
8334
8335
8335
8336
8336
8337
8337
8338
8338
8339
8339
8340
8340
8341
8341
8342
8342
8343
8343
8344
8344
8345
8345
8346
8346
8347
8347
8348
8348
8349
8349
8350
8350
8351
8351
8352
8352
8353
8353
8354
8354
8355
8355
8356
8356
8357
8357
8358
8358
8359
8359
8360
8360
8361
8361
8362
8362
8363
8363
8364
8364
8365
8365
8366
8366
8367
8367
8368
8368
8369
8369
8370
8370
8371
8371
8372
8372
8373
8373
8374
8374
8375
8375
8376
8376
8377
8377
8378
8378
8379
8379
8380
8380
8381
8381
8382
8382
8383
8384
8384
8385
8385
8386
8386
8387
8387
8388
8388
8389
8389
8390
8390
8391
8391
8392
8392
8393
8393
8394
8394
8395
8395
8396
8396
8397
8397
8398
8398
8399
8399
8400
8400
8401
8401
8402
8402
8403
8403
8404
8404
8405
8405
8406
8406
8407
8407
8408
8408
8409
8409
8410
8410
8411
8411
8412
8412
8413
8413
8414
8414
8415
8415
8416
8416
8417
8417
8418
8418
8419
8419
8420
8420
8421
8421
8422
8422
8423
8423
8424
8424
8425
8425
8426
8426
8427
8427
8428
8428
8429
8429
8430
8430
8431
8431
8432
8432
8433
8433
8434
8434
8435
8435
8436
8436
8437
8437
8438
8438
8439
8439
8440
8440
8441
8441
8442
8442
8443
8443
8444
8444
8445
8445
8446
8446
8447
8448
8448
8449
8449
8450
8450
8451
8451
8452
8452
8453
8453
8454
8454
8455
8455
8456
8456
8457
8457
8458
8458
8459
8459
8460
8460
8461
8461
8462
8462
8463
8463
8464
8464
8465
8465
8466
8466
8467
8467
8468
8468
8469
8469
8470
8470
8471
8471
8472
8472
8473
8473
8474
8474
8475
8475
8476
8476
8477
8477
8478
8478
8479
8479
8480
8480
8481
8481
8482
8482
8483
8483
8484
8484
8485
8485
8486
8486
8487
8487
8488
8488
8489
8489
8490
8490
8491
8491
8492
8492
8493
8493
8494
8494
8495
8495
8496
8496
8497
8497
8498
8498
8499
8499
8500
8500
8501
8501
8502
8502
8503
8503
8504
8504
8505
8505
8506
8506
8507
8507
8508
8508
8509
8509
8510
8510
8511
8512
8512
8513
8513
8514
8514
8515
8515
8516
8516
8517
8517
8518
8518
8519
8519
8520
8520
8521
8521
8522
8522
8523
8523
8524
8524
8525
8525
8526
8526
8527
8527
8528
8528
8529
8529
8530
8530
8531
8531
8532
8532
8533
8533
8534
8534
8535
8535
8536
8536
8537
8537
8538
8538
8539
8539
8540
8540
8541
8541
8542
8542
8543
8543
8544
8544
8545
8545
8546
8546
8547
8547
8548
8548
8549
8549
8550
8550
8551
8551
8552
8552
8553
8553
8554
8554
8555
8555
8556
8556
8557
8557
8558
8558
8559
8559
8560
8560
8561
8561
8562
8562
8563
8563
8564
8564
8565
8565
8566
8566
8567
8567
8568
8568
8569
8569
8570
8570
8571
8571
8572
8572
8573
8573
8574
8574
8575
8576
8576
8577
8577
8578
8578
8579
8579
8580
8580
8581
8581
8582
8582
8583
8583
8584
8584
8585
8585
8586
8586
8587
8587
8588
8588
8589
8589
8590
8590
8591
8591
8592
8592
8593
8593
8594
8594
8595
8595
8596
8596
8597
8597
8598
8598
8599
8599
8600
8600
8601
8601
8602
8602
8603
8603
8604
8604
8605
8605
8606
8606
8607
8607
8608
8608
8609
8609
8610
8610
8611
8611
8612
8612
8613
8613
8614
8614
8615
8615
8616
8616
8617
8617
8618
8618
8619
8619
8620
8620
8621
8621
8622
8622
8623
8623
8624
8624
8625
8625
8626
8626
8627
8627
8628
8628
8629
8629
8630
8630
8631
8631
8632
8632
8633
8633
8634
8634
8635
8635
8636
8636
8637
8637
8638
8638
8639
8640
8640
8641
8641
8642
8642
8643
8643
8644
8644
8645
8645
8646
8646
8647
8647
8648
8648
8649
8649
8650
8650
8651
8651
8652
8652
8653
8653
8654
8654
8655
8655
8656
8656
8657
8657
8658
8658
8659
8659
8660
8660
8661
8661
8662
8662
8663
8663
8664
8664
8665
8665
8666
8666
8667
8667
8668
8668
8669
8669
8670
8670
8671
8671
8672
8672
8673
8673
8674
8674
8675
8675
8676
8676
8677
8677
8678
8678
8679
8679
8680
8680
8681
8681
8682
8682
8683
8683
8684
8684
8685
8685
8686
8686
8687
8687
8688
8688
8689
8689
8690
8690
8691
8691
8692
8692
8693
8693
8694
8694
8695
8695
8696
8696
8697
8697
8698
8698
8699
8699
8700
8700
8701
8701
8702
8702
8703
8704
8704
8705
8705
8706
8706
8707
8707
8708
8708
8709
8709
8710
8710
8711
8711
8712
8712
8713
8713
8714
8714
8715
8715
8716
8716
8717
8717
8718
8718
8719
8719
8720
8720
8721
8721
8722
8722
8723
8723
8724
8724
8725
8725
8726
8726
8727
8727
8728
8728
8729
8729
8730
8730
8731
8731
8732
8732
8733
8733
8734
8734
8735
8735
8736
8736
8737
8737
8738
8738
8739
8739
8740
8740
8741
8741
8742
8742
8743
8743
8744
8744
8745
8745
8746
8746
8747
8747
8748
8748
8749
8749
8750
8750
8751
8751
8752
8752
8753
8753
8754
8754
8755
8755
8756
8756
8757
8757
8758
8758
8759
8759
8760
8760
8761
8761
8762
8762
8763
8763
8764
8764
8765
8765
8766
8766
8767
8768
8768
8769
8769
8770
8770
8771
8771
8772
8772
8773
8773
8774
8774
8775
8775
8776
8776
8777
8777
8778
8778
8779
8779
8780
8780
8781
8781
8782
8782
8783
8783
8784
8784
8785
8785
8786
8786
8787
8787
8788
8788
8789
8789
8790
8790
8791
8791
8792
8792
8793
8793
8794
8794
8795
8795
8796
8796
8797
8797
8798
8798
8799
8799
8800
8800
8801
8801
8802
8802
8803
8803
8804
8804
8805
8805
8806
8806
8807
8807
8808
8808
8809
8809
8810
8810
8811
8811
8812
8812
8813
8813
8814
8814
8815
8815
8816
8816
8817
8817
8818
8818
8819
8819
8820
8820
8821
8821
8822
8822
8823
8823
8824
8824
8825
8825
8826
8826
8827
8827
8828
8828
8829
8829
8830
8830
8831
8832
8832
8833
8833
8834
8834
8835
8835
8836
8836
8837
8837
8838
8838
8839
8839
8840
8840
8841
8841
8842
8842
8843
8843
8844
8844
8845
8845
8846
8846
8847
8847
8848
8848
8849
8849
8850
8850
8851
8851
8852
8852
8853
8853
8854
8854
8855
8855
8856
8856
8857
8857
8858
8858
8859
8859
8860
8860
8861
8861
8862
8862
8863
8863
8864
8864
8865
8865
8866
8866
8867
8867
8868
8868
8869
8869
8870
8870
8871
8871
8872
8872
8873
8873
8874
8874
8875
8875
8876
8876
8877
8877
8878
8878
8879
8879
8880
8880
8881
8881
8882
8882
8883
8883
8884
8884
8885
8885
8886
8886
8887
8887
8888
8888
8889
8889
8890
8890
8891
8891
8892
8892
8893
8893
8894
8894
8895
8896
8896
8897
8897
8898
8898
8899
8899
8900
8900
8901
8901
8902
8902
8903
8903
8904
8904
8905
8905
8906
8906
8907
8907
8908
8908
8909
8909
8910
8910
8911
8911
8912
8912
8913
8913
8914
8914
8915
8915
8916
8916
8917
8917
8918
8918
8919
8919
8920
8920
8921
8921
8922
8922
8923
8923
8924
8924
8925
8925
8926
8926
8927
8927
8928
8928
8929
8929
8930
8930
8931
8931
8932
8932
8933
8933
8934
8934
8935
8935
8936
8936
8937
8937
8938
8938
8939
8939
8940
8940
8941
8941
8942
8942
8943
8943
8944
8944
8945
8945
8946
8946
8947
8947
8948
8948
8949
8949
8950
8950
8951
8951
8952
8952
8953
8953
8954
8954
8955
8955
8956
8956
8957
8957
8958
8958
8959
8960
8960
8961
8961
8962
8962
8963
8963
8964
8964
8965
8965
8966
8966
8967
8967
8968
8968
8969
8969
8970
8970
8971
8971
8972
8972
8973
8973
8974
8974
8975
8975
8976
8976
8977
8977
8978
8978
8979
8979
8980
8980
8981
8981
8982
8982
8983
8983
8984
8984
8985
8985
8986
8986
8987
8987
8988
8988
8989
8989
8990
8990
8991
8991
8992
8992
8993
8993
8994
8994
8995
8995
8996
8996
8997
8997
8998
8998
8999
8999
9000
9000
9001
9001
9002
9002
9003
9003
9004
9004
9005
9005
9006
9006
9007
9007
9008
9008
9009
9009
9010
9010
9011
9011
9012
9012
9013
9013
9014
9014
9015
9015
9016
9016
9017
9017
9018
9018
9019
9019
9020
9020
9021
9021
9022
9022
9023
9024
9024
9025
9025
9026
9026
9027
9027
9028
9028
9029
9029
9030
9030
9031
9031
9032
9032
9033
9033
9034
9034
9035
9035
9036
9036
9037
9037
9038
9038
9039
9039
9040
9040
9041
9041
9042
9042
9043
9043
9044
9044
9045
9045
9046
9046
9047
9047
9048
9048
9049
9049
9050
9050
9051
9051
9052
9052
9053
9053
9054
9054
9055
9055
9056
9056
9057
9057
9058
9058
9059
9059
9060
9060
9061
9061
9062
9062
9063
9063
9064
9064
9065
9065
9066
9066
9067
9067
9068
9068
9069
9069
9070
9070
9071
9071
9072
9072
9073
9073
9074
9074
9075
9075
9076
9076
9077
9077
9078
9078
9079
9079
9080
9080
9081
9081
9082
9082
9083
9083
9084
9084
9085
9085
9086
9086
9087
9088
9088
9089
9089
9090
9090
9091
9091
9092
9092
9093
9093
9094
9094
9095
9095
9096
9096
9097
9097
9098
9098
9099
9099
9100
9100
9101
9101
9102
9102
9103
9103
9104
9104
9105
9105
9106
9106
9107
9107
9108
9108
9109
9109
9110
9110
9111
9111
9112
9112
9113
9113
9114
9114
9115
9115
9116
9116
9117
9117
9118
9118
9119
9119
9120
9120
9121
9121
9122
9122
9123
9123
9124
9124
9125
9125
9126
9126
9127
9127
9128
9128
9129
9129
9130
9130
9131
9131
9132
9132
9133
9133
9134
9134
9135
9135
9136
9136
9137
9137
9138
9138
9139
9139
9140
9140
9141
9141
9142
9142
9143
9143
9144
9144
9145
9145
9146
9146
9147
9147
9148
9148
9149
9149
9150
9150
9151
9152
9152
9153
9153
9154
9154
9155
9155
9156
9156
9157
9157
9158
9158
9159
9159
9160
9160
9161
9161
9162
9162
9163
9163
9164
9164
9165
9165
9166
9166
9167
9167
9168
9168
9169
9169
9170
9170
9171
9171
9172
9172
9173
9173
9174
9174
9175
9175
9176
9176
9177
9177
9178
9178
9179
9179
9180
9180
9181
9181
9182
9182
9183
9183
9184
9184
9185
9185
9186
9186
9187
9187
9188
9188
9189
9189
9190
9190
9191
9191
9192
9192
9193
9193
9194
9194
9195
9195
9196
9196
9197
9197
9198
9198
9199
9199
9200
9200
9201
9201
9202
9202
9203
9203
9204
9204
9205
9205
9206
9206
9207
9207
9208
9208
9209
9209
9210
9210
9211
9211
9212
9212
9213
9213
9214
9214
9215
9216
9216
9217
9217
9218
9218
9219
9219
9220
9220
9221
9221
9222
9222
9223
9223
9224
9224
9225
9225
9226
9226
9227
9227
9228
9228
9229
9229
9230
9230
9231
9231
9232
9232
9233
9233
9234
9234
9235
9235
9236
9236
9237
9237
9238
9238
9239
9239
9240
9240
9241
9241
9242
9242
9243
9243
9244
9244
9245
9245
9246
9246
9247
9247
9248
9248
9249
9249
9250
9250
9251
9251
9252
9252
9253
9253
9254
9254
9255
9255
9256
9256
9257
9257
9258
9258
9259
9259
9260
9260
9261
9261
9262
9262
9263
9263
9264
9264
9265
9265
9266
9266
9267
9267
9268
9268
9269
9269
9270
9270
9271
9271
9272
9272
9273
9273
9274
9274
9275
9275
9276
9276
9277
9277
9278
9278
9279
9280
9280
9281
9281
9282
9282
9283
9283
9284
9284
9285
9285
9286
9286
9287
9287
9288
9288
9289
9289
9290
9290
9291
9291
9292
9292
9293
9293
9294
9294
9295
9295
9296
9296
9297
9297
9298
9298
9299
9299
9300
9300
9301
9301
9302
9302
9303
9303
9304
9304
9305
9305
9306
9306
9307
9307
9308
9308
9309
9309
9310
9310
9311
9311
9312
9312
9313
9313
9314
9314
9315
9315
9316
9316
9317
9317
9318
9318
9319
9319
9320
9320
9321
9321
9322
9322
9323
9323
9324
9324
9325
9325
9326
9326
9327
9327
9328
9328
9329
9329
9330
9330
9331
9331
9332
9332
9333
9333
9334
9334
9335
9335
9336
9336
9337
9337
9338
9338
9339
9339
9340
9340
9341
9341
9342
9342
9343
9344
9344
9345
9345
9346
9346
9347
9347
9348
9348
9349
9349
9350
9350
9351
9351
9352
9352
9353
9353
9354
9354
9355
9355
9356
9356
9357
9357
9358
9358
9359
9359
9360
9360
9361
9361
9362
9362
9363
9363
9364
9364
9365
9365
9366
9366
9367
9367
9368
9368
9369
9369
9370
9370
9371
9371
9372
9372
9373
9373
9374
9374
9375
9375
9376
9376
9377
9377
9378
9378
9379
9379
9380
9380
9381
9381
9382
9382
9383
9383
9384
9384
9385
9385
9386
9386
9387
9387
9388
9388
9389
9389
9390
9390
9391
9391
9392
9392
9393
9393
9394
9394
9395
9395
9396
9396
9397
9397
9398
9398
9399
9399
9400
9400
9401
9401
9402
9402
9403
9403
9404
9404
9405
9405
9406
9406
9407
9408
9408
9409
9409
9410
9410
9411
9411
9412
9412
9413
9413
9414
9414
9415
9415
9416
9416
9417
9417
9418
9418
9419
9419
9420
9420
9421
9421
9422
9422
9423
9423
9424
9424
9425
9425
9426
9426
9427
9427
9428
9428
9429
9429
9430
9430
9431
9431
9432
9432
9433
9433
9434
9434
9435
9435
9436
9436
9437
9437
9438
9438
9439
9439
9440
9440
9441
9441
9442
9442
9443
9443
9444
9444
9445
9445
9446
9446
9447
9447
9448
9448
9449
9449
9450
9450
9451
9451
9452
9452
9453
9453
9454
9454
9455
9455
9456
9456
9457
9457
9458
9458
9459
9459
9460
9460
9461
9461
9462
9462
9463
9463
9464
9464
9465
9465
9466
9466
9467
9467
9468
9468
9469
9469
9470
9470
9471
9472
9472
9473
9473
9474
9474
9475
9475
9476
9476
9477
9477
9478
9478
9479
9479
9480
9480
9481
9481
9482
9482
9483
9483
9484
9484
9485
9485
9486
9486
9487
9487
9488
9488
9489
9489
9490
9490
9491
9491
9492
9492
9493
9493
9494
9494
9495
9495
9496
9496
9497
9497
9498
9498
9499
9499
9500
9500
9501
9501
9502
9502
9503
9503
9504
9504
9505
9505
9506
9506
9507
9507
9508
9508
9509
9509
9510
9510
9511
9511
9512
9512
9513
9513
9514
9514
9515
9515
9516
9516
9517
9517
9518
9518
9519
9519
9520
9520
9521
9521
9522
9522
9523
9523
9524
9524
9525
9525
9526
9526
9527
9527
9528
9528
9529
9529
9530
9530
9531
9531
9532
9532
9533
9533
9534
9534
9535
9536
9536
9537
9537
9538
9538
9539
9539
9540
9540
9541
9541
9542
9542
9543
9543
9544
9544
9545
9545
9546
9546
9547
9547
9548
9548
9549
9549
9550
9550
9551
9551
9552
9552
9553
9553
9554
9554
9555
9555
9556
9556
9557
9557
9558
9558
9559
9559
9560
9560
9561
9561
9562
9562
9563
9563
9564
9564
9565
9565
9566
9566
9567
9567
9568
9568
9569
9569
9570
9570
9571
9571
9572
9572
9573
9573
9574
9574
9575
9575
9576
9576
9577
9577
9578
9578
9579
9579
9580
9580
9581
9581
9582
9582
9583
9583
9584
9584
9585
9585
9586
9586
9587
9587
9588
9588
9589
9589
9590
9590
9591
9591
9592
9592
9593
9593
9594
9594
9595
9595
9596
9596
9597
9597
9598
9598
9599
9600
9600
9601
9601
9602
9602
9603
9603
9604
9604
9605
9605
9606
9606
9607
9607
9608
9608
9609
9609
9610
9610
9611
9611
9612
9612
9613
9613
9614
9614
9615
9615
9616
9616
9617
9617
9618
9618
9619
9619
9620
9620
9621
9621
9622
9622
9623
9623
9624
9624
9625
9625
9626
9626
9627
9627
9628
9628
9629
9629
9630
9630
9631
9631
9632
9632
9633
9633
9634
9634
9635
9635
9636
9636
9637
9637
9638
9638
9639
9639
9640
9640
9641
9641
9642
9642
9643
9643
9644
9644
9645
9645
9646
9646
9647
9647
9648
9648
9649
9649
9650
9650
9651
9651
9652
9652
9653
9653
9654
9654
9655
9655
9656
9656
9657
9657
9658
9658
9659
9659
9660
9660
9661
9661
9662
9662
9663
9664
9664
9665
9665
9666
9666
9667
9667
9668
9668
9669
9669
9670
9670
9671
9671
9672
9672
9673
9673
9674
9674
9675
9675
9676
9676
9677
9677
9678
9678
9679
9679
9680
9680
9681
9681
9682
9682
9683
9683
9684
9684
9685
9685
9686
9686
9687
9687
9688
9688
9689
9689
9690
9690
9691
9691
9692
9692
9693
9693
9694
9694
9695
9695
9696
9696
9697
9697
9698
9698
9699
9699
9700
9700
9701
9701
9702
9702
9703
9703
9704
9704
9705
9705
9706
9706
9707
9707
9708
9708
9709
9709
9710
9710
9711
9711
9712
9712
9713
9713
9714
9714
9715
9715
9716
9716
9717
9717
9718
9718
9719
9719
9720
9720
9721
9721
9722
9722
9723
9723
9724
9724
9725
9725
9726
9726
9727
9728
9728
9729
9729
9730
9730
9731
9731
9732
9732
9733
9733
9734
9734
9735
9735
9736
9736
9737
9737
9738
9738
9739
9739
9740
9740
9741
9741
9742
9742
9743
9743
9744
9744
9745
9745
9746
9746
9747
9747
9748
9748
9749
9749
9750
9750
9751
9751
9752
9752
9753
9753
9754
9754
9755
9755
9756
9756
9757
9757
9758
9758
9759
9759
9760
9760
9761
9761
9762
9762
9763
9763
9764
9764
9765
9765
9766
9766
9767
9767
9768
9768
9769
9769
9770
9770
9771
9771
9772
9772
9773
9773
9774
9774
9775
9775
9776
9776
9777
9777
9778
9778
9779
9779
9780
9780
9781
9781
9782
9782
9783
9783
9784
9784
9785
9785
9786
9786
9787
9787
9788
9788
9789
9789
9790
9790
9791
9792
9792
9793
9793
9794
9794
9795
9795
9796
9796
9797
9797
9798
9798
9799
9799
9800
9800
9801
9801
9802
9802
9803
9803
9804
9804
9805
9805
9806
9806
9807
9807
9808
9808
9809
9809
9810
9810
9811
9811
9812
9812
9813
9813
9814
9814
9815
9815
9816
9816
9817
9817
9818
9818
9819
9819
9820
9820
9821
9821
9822
9822
9823
9823
9824
9824
9825
9825
9826
9826
9827
9827
9828
9828
9829
9829
9830
9830
9831
9831
9832
9832
9833
9833
9834
9834
9835
9835
9836
9836
9837
9837
9838
9838
9839
9839
9840
9840
9841
9841
9842
9842
9843
9843
9844
9844
9845
9845
9846
9846
9847
9847
9848
9848
9849
9849
9850
9850
9851
9851
9852
9852
9853
9853
9854
9854
9855
9856
9856
9857
9857
9858
9858
9859
9859
9860
9860
9861
9861
9862
9862
9863
9863
9864
9864
9865
9865
9866
9866
9867
9867
9868
9868
9869
9869
9870
9870
9871
9871
9872
9872
9873
9873
9874
9874
9875
9875
9876
9876
9877
9877
9878
9878
9879
9879
9880
9880
9881
9881
9882
9882
9883
9883
9884
9884
9885
9885
9886
9886
9887
9887
9888
9888
9889
9889
9890
9890
9891
9891
9892
9892
9893
9893
9894
9894
9895
9895
9896
9896
9897
9897
9898
9898
9899
9899
9900
9900
9901
9901
9902
9902
9903
9903
9904
9904
9905
9905
9906
9906
9907
9907
9908
9908
9909
9909
9910
9910
9911
9911
9912
9912
9913
9913
9914
9914
9915
9915
9916
9916
9917
9917
9918
9918
9919
9920
9920
9921
9921
9922
9922
9923
9923
9924
9924
9925
9925
9926
9926
9927
9927
9928
9928
9929
9929
9930
9930
9931
9931
9932
9932
9933
9933
9934
9934
9935
9935
9936
9936
9937
9937
9938
9938
9939
9939
9940
9940
9941
9941
9942
9942
9943
9943
9944
9944
9945
9945
9946
9946
9947
9947
9948
9948
9949
9949
9950
9950
9951
9951
9952
9952
9953
9953
9954
9954
9955
9955
9956
9956
9957
9957
9958
9958
9959
9959
9960
9960
9961
9961
9962
9962
9963
9963
9964
9964
9965
9965
9966
9966
9967
9967
9968
9968
9969
9969
9970
9970
9971
9971
9972
9972
9973
9973
9974
9974
9975
9975
9976
9976
9977
9977
9978
9978
9979
9979
9980
9980
9981
9981
9982
9982
9983
9984
9984
9985
9985
9986
9986
9987
9987
9988
9988
9989
9989
9990
9990
9991
9991
9992
9992
9993
9993
9994
9994
9995
9995
9996
9996
9997
9997
9998
9998
9999
9999
10000
10000
10001
10001
10002
10002
10003
10003
10004
10004
10005
10005
10006
10006
10007
10007
10008
10008
10009
10009
10010
10010
10011
10011
10012
10012
10013
10013
10014
10014
10015
10015
10016
10016
10017
10017
10018
10018
10019
10019
10020
10020
10021
10021
10022
10022
10023
10023
10024
10024
10025
10025
10026
10026
10027
10027
10028
10028
10029
10029
10030
10030
10031
10031
10032
10032
10033
10033
10034
10034
10035
10035
10036
10036
10037
10037
10038
10038
10039
10039
10040
10040
10041
10041
10042
10042
10043
10043
10044
10044
10045
10045
10046
10046
10047
10048
10048
10049
10049
10050
10050
10051
10051
10052
10052
10053
10053
10054
10054
10055
10055
10056
10056
10057
10057
10058
10058
10059
10059
10060
10060
10061
10061
10062
10062
10063
10063
10064
10064
10065
10065
10066
10066
10067
10067
10068
10068
10069
10069
10070
10070
10071
10071
10072
10072
10073
10073
10074
10074
10075
10075
10076
10076
10077
10077
10078
10078
10079
10079
10080
10080
10081
10081
10082
10082
10083
10083
10084
10084
10085
10085
10086
10086
10087
10087
10088
10088
10089
10089
10090
10090
10091
10091
10092
10092
10093
10093
10094
10094
10095
10095
10096
10096
10097
10097
10098
10098
10099
10099
10100
10100
10101
10101
10102
10102
10103
10103
10104
10104
10105
10105
10106
10106
10107
10107
10108
10108
10109
10109
10110
10110
10111
10112
10112
10113
10113
10114
10114
10115
10115
10116
10116
10117
10117
10118
10118
10119
10119
10120
10120
10121
10121
10122
10122
10123
10123
10124
10124
10125
10125
10126
10126
10127
10127
10128
10128
10129
10129
10130
10130
10131
10131
10132
10132
10133
10133
10134
10134
10135
10135
10136
10136
10137
10137
10138
10138
10139
10139
10140
10140
10141
10141
10142
10142
10143
10143
10144
10144
10145
10145
10146
10146
10147
10147
10148
10148
10149
10149
10150
10150
10151
10151
10152
10152
10153
10153
10154
10154
10155
10155
10156
10156
10157
10157
10158
10158
10159
10159
10160
10160
10161
10161
10162
10162
10163
10163
10164
10164
10165
10165
10166
10166
10167
10167
10168
10168
10169
10169
10170
10170
10171
10171
10172
10172
10173
10173
10174
10174
10175
10176
10176
10177
10177
10178
10178
10179
10179
10180
10180
10181
10181
10182
10182
10183
10183
10184
10184
10185
10185
10186
10186
10187
10187
10188
10188
10189
10189
10190
10190
10191
10191
10192
10192
10193
10193
10194
10194
10195
10195
10196
10196
10197
10197
10198
10198
10199
10199
10200
10200
10201
10201
10202
10202
10203
10203
10204
10204
10205
10205
10206
10206
10207
10207
10208
10208
10209
10209
10210
10210
10211
10211
10212
10212
10213
10213
10214
10214
10215
10215
10216
10216
10217
10217
10218
10218
10219
10219
10220
10220
10221
10221
10222
10222
10223
10223
10224
10224
10225
10225
10226
10226
10227
10227
10228
10228
10229
10229
10230
10230
10231
10231
10232
10232
10233
10233
10234
10234
10235
10235
10236
10236
10237
10237
10238
10238
10239
10240
10240
10241
10241
10242
10242
10243
10243
10244
10244
10245
10245
10246
10246
10247
10247
10248
10248
10249
10249
10250
10250
10251
10251
10252
10252
10253
10253
10254
10254
10255
10255
10256
10256
10257
10257
10258
10258
10259
10259
10260
10260
10261
10261
10262
10262
10263
10263
10264
10264
10265
10265
10266
10266
10267
10267
10268
10268
10269
10269
10270
10270
10271
10271
10272
10272
10273
10273
10274
10274
10275
10275
10276
10276
10277
10277
10278
10278
10279
10279
10280
10280
10281
10281
10282
10282
10283
10283
10284
10284
10285
10285
10286
10286
10287
10287
10288
10288
10289
10289
10290
10290
10291
10291
10292
10292
10293
10293
10294
10294
10295
10295
10296
10296
10297
10297
10298
10298
10299
10299
10300
10300
10301
10301
10302
10302
10303
10304
10304
10305
10305
10306
10306
10307
10307
10308
10308
10309
10309
10310
10310
10311
10311
10312
10312
10313
10313
10314
10314
10315
10315
10316
10316
10317
10317
10318
10318
10319
10319
10320
10320
10321
10321
10322
10322
10323
10323
10324
10324
10325
10325
10326
10326
10327
10327
10328
10328
10329
10329
10330
10330
10331
10331
10332
10332
10333
10333
10334
10334
10335
10335
10336
10336
10337
10337
10338
10338
10339
10339
10340
10340
10341
10341
10342
10342
10343
10343
10344
10344
10345
10345
10346
10346
10347
10347
10348
10348
10349
10349
10350
10350
10351
10351
10352
10352
10353
10353
10354
10354
10355
10355
10356
10356
10357
10357
10358
10358
10359
10359
10360
10360
10361
10361
10362
10362
10363
10363
10364
10364
10365
10365
10366
10366
10367
10368
10368
10369
10369
10370
10370
10371
10371
10372
10372
10373
10373
10374
10374
10375
10375
10376
10376
10377
10377
10378
10378
10379
10379
10380
10380
10381
10381
10382
10382
10383
10383
10384
10384
10385
10385
10386
10386
10387
10387
10388
10388
10389
10389
10390
10390
10391
10391
10392
10392
10393
10393
10394
10394
10395
10395
10396
10396
10397
10397
10398
10398
10399
10399
10400
10400
10401
10401
10402
10402
10403
10403
10404
10404
10405
10405
10406
10406
10407
10407
10408
10408
10409
10409
10410
10410
10411
10411
10412
10412
10413
10413
10414
10414
10415
10415
10416
10416
10417
10417
10418
10418
10419
10419
10420
10420
10421
10421
10422
10422
10423
10423
10424
10424
10425
10425
10426
10426
10427
10427
10428
10428
10429
10429
10430
10430
10431
10432
10432
10433
10433
10434
10434
10435
10435
10436
10436
10437
10437
10438
10438
10439
10439
10440
10440
10441
10441
10442
10442
10443
10443
10444
10444
10445
10445
10446
10446
10447
10447
10448
10448
10449
10449
10450
10450
10451
10451
10452
10452
10453
10453
10454
10454
10455
10455
10456
10456
10457
10457
10458
10458
10459
10459
10460
10460
10461
10461
10462
10462
10463
10463
10464
10464
10465
10465
10466
10466
10467
10467
10468
10468
10469
10469
10470
10470
10471
10471
10472
10472
10473
10473
10474
10474
10475
10475
10476
10476
10477
10477
10478
10478
10479
10479
10480
10480
10481
10481
10482
10482
10483
10483
10484
10484
10485
10485
10486
10486
10487
10487
10488
10488
10489
10489
10490
10490
10491
10491
10492
10492
10493
10493
10494
10494
10495
10496
10496
10497
10497
10498
10498
10499
10499
10500
10500
10501
10501
10502
10502
10503
10503
10504
10504
10505
10505
10506
10506
10507
10507
10508
10508
10509
10509
10510
10510
10511
10511
10512
10512
10513
10513
10514
10514
10515
10515
10516
10516
10517
10517
10518
10518
10519
10519
10520
10520
10521
10521
10522
10522
10523
10523
10524
10524
10525
10525
10526
10526
10527
10527
10528
10528
10529
10529
10530
10530
10531
10531
10532
10532
10533
10533
10534
10534
10535
10535
10536
10536
10537
10537
10538
10538
10539
10539
10540
10540
10541
10541
10542
10542
10543
10543
10544
10544
10545
10545
10546
10546
10547
10547
10548
10548
10549
10549
10550
10550
10551
10551
10552
10552
10553
10553
10554
10554
10555
10555
10556
10556
10557
10557
10558
10558
10559
10560
10560
10561
10561
10562
10562
10563
10563
10564
10564
10565
10565
10566
10566
10567
10567
10568
10568
10569
10569
10570
10570
10571
10571
10572
10572
10573
10573
10574
10574
10575
10575
10576
10576
10577
10577
10578
10578
10579
10579
10580
10580
10581
10581
10582
10582
10583
10583
10584
10584
10585
10585
10586
10586
10587
10587
10588
10588
10589
10589
10590
10590
10591
10591
10592
10592
10593
10593
10594
10594
10595
10595
10596
10596
10597
10597
10598
10598
10599
10599
10600
10600
10601
10601
10602
10602
10603
10603
10604
10604
10605
10605
10606
10606
10607
10607
10608
10608
10609
10609
10610
10610
10611
10611
10612
10612
10613
10613
10614
10614
10615
10615
10616
10616
10617
10617
10618
10618
10619
10619
10620
10620
10621
10621
10622
10622
10623
10624
10624
10625
10625
10626
10626
10627
10627
10628
10628
10629
10629
10630
10630
10631
10631
10632
10632
10633
10633
10634
10634
10635
10635
10636
10636
10637
10637
10638
10638
10639
10639
10640
10640
10641
10641
10642
10642
10643
10643
10644
10644
10645
10645
10646
10646
10647
10647
10648
10648
10649
10649
10650
10650
10651
10651
10652
10652
10653
10653
10654
10654
10655
10655
10656
10656
10657
10657
10658
10658
10659
10659
10660
10660
10661
10661
10662
10662
10663
10663
10664
10664
10665
10665
10666
10666
10667
10667
10668
10668
10669
10669
10670
10670
10671
10671
10672
10672
10673
10673
10674
10674
10675
10675
10676
10676
10677
10677
10678
10678
10679
10679
10680
10680
10681
10681
10682
10682
10683
10683
10684
10684
10685
10685
10686
10686
10687
10688
10688
10689
10689
10690
10690
10691
10691
10692
10692
10693
10693
10694
10694
10695
10695
10696
10696
10697
10697
10698
10698
10699
10699
10700
10700
10701
10701
10702
10702
10703
10703
10704
10704
10705
10705
10706
10706
10707
10707
10708
10708
10709
10709
10710
10710
10711
10711
10712
10712
10713
10713
10714
10714
10715
10715
10716
10716
10717
10717
10718
10718
10719
10719
10720
10720
10721
10721
10722
10722
10723
10723
10724
10724
10725
10725
10726
10726
10727
10727
10728
10728
10729
10729
10730
10730
10731
10731
10732
10732
10733
10733
10734
10734
10735
10735
10736
10736
10737
10737
10738
10738
10739
10739
10740
10740
10741
10741
10742
10742
10743
10743
10744
10744
10745
10745
10746
10746
10747
10747
10748
10748
10749
10749
10750
10750
10751
10752
10752
10753
10753
10754
10754
10755
10755
10756
10756
10757
10757
10758
10758
10759
10759
10760
10760
10761
10761
10762
10762
10763
10763
10764
10764
10765
10765
10766
10766
10767
10767
10768
10768
10769
10769
10770
10770
10771
10771
10772
10772
10773
10773
10774
10774
10775
10775
10776
10776
10777
10777
10778
10778
10779
10779
10780
10780
10781
10781
10782
10782
10783
10783
10784
10784
10785
10785
10786
10786
10787
10787
10788
10788
10789
10789
10790
10790
10791
10791
10792
10792
10793
10793
10794
10794
10795
10795
10796
10796
10797
10797
10798
10798
10799
10799
10800
10800
10801
10801
10802
10802
10803
10803
10804
10804
10805
10805
10806
10806
10807
10807
10808
10808
10809
10809
10810
10810
10811
10811
10812
10812
10813
10813
10814
10814
10815
10816
10816
10817
10817
10818
10818
10819
10819
10820
10820
10821
10821
10822
10822
10823
10823
10824
10824
10825
10825
10826
10826
10827
10827
10828
10828
10829
10829
10830
10830
10831
10831
10832
10832
10833
10833
10834
10834
10835
10835
10836
10836
10837
10837
10838
10838
10839
10839
10840
10840
10841
10841
10842
10842
10843
10843
10844
10844
10845
10845
10846
10846
10847
10847
10848
10848
10849
10849
10850
10850
10851
10851
10852
10852
10853
10853
10854
10854
10855
10855
10856
10856
10857
10857
10858
10858
10859
10859
10860
10860
10861
10861
10862
10862
10863
10863
10864
10864
10865
10865
10866
10866
10867
10867
10868
10868
10869
10869
10870
10870
10871
10871
10872
10872
10873
10873
10874
10874
10875
10875
10876
10876
10877
10877
10878
10878
10879
10880
10880
10881
10881
10882
10882
10883
10883
10884
10884
10885
10885
10886
10886
10887
10887
10888
10888
10889
10889
10890
10890
10891
10891
10892
10892
10893
10893
10894
10894
10895
10895
10896
10896
10897
10897
10898
10898
10899
10899
10900
10900
10901
10901
10902
10902
10903
10903
10904
10904
10905
10905
10906
10906
10907
10907
10908
10908
10909
10909
10910
10910
10911
10911
10912
10912
10913
10913
10914
10914
10915
10915
10916
10916
10917
10917
10918
10918
10919
10919
10920
10920
10921
10921
10922
10922
10923
10923
10924
10924
10925
10925
10926
10926
10927
10927
10928
10928
10929
10929
10930
10930
10931
10931
10932
10932
10933
10933
10934
10934
10935
10935
10936
10936
10937
10937
10938
10938
10939
10939
10940
10940
10941
10941
10942
10942
10943
10944
10944
10945
10945
10946
10946
10947
10947
10948
10948
10949
10949
10950
10950
10951
10951
10952
10952
10953
10953
10954
10954
10955
10955
10956
10956
10957
10957
10958
10958
10959
10959
10960
10960
10961
10961
10962
10962
10963
10963
10964
10964
10965
10965
10966
10966
10967
10967
10968
10968
10969
10969
10970
10970
10971
10971
10972
10972
10973
10973
10974
10974
10975
10975
10976
10976
10977
10977
10978
10978
10979
10979
10980
10980
10981
10981
10982
10982
10983
10983
10984
10984
10985
10985
10986
10986
10987
10987
10988
10988
10989
10989
10990
10990
10991
10991
10992
10992
10993
10993
10994
10994
10995
10995
10996
10996
10997
10997
10998
10998
10999
10999
11000
11000
11001
11001
11002
11002
11003
11003
11004
11004
11005
11005
11006
11006
11007
11008
11008
11009
11009
11010
11010
11011
11011
11012
11012
11013
11013
11014
11014
11015
11015
11016
11016
11017
11017
11018
11018
11019
11019
11020
11020
11021
11021
11022
11022
11023
11023
11024
11024
11025
11025
11026
11026
11027
11027
11028
11028
11029
11029
11030
11030
11031
11031
11032
11032
11033
11033
11034
11034
11035
11035
11036
11036
11037
11037
11038
11038
11039
11039
11040
11040
11041
11041
11042
11042
11043
11043
11044
11044
11045
11045
11046
11046
11047
11047
11048
11048
11049
11049
11050
11050
11051
11051
11052
11052
11053
11053
11054
11054
11055
11055
11056
11056
11057
11057
11058
11058
11059
11059
11060
11060
11061
11061
11062
11062
11063
11063
11064
11064
11065
11065
11066
11066
11067
11067
11068
11068
11069
11069
11070
11070
11071
11072
11072
11073
11073
11074
11074
11075
11075
11076
11076
11077
11077
11078
11078
11079
11079
11080
11080
11081
11081
11082
11082
11083
11083
11084
11084
11085
11085
11086
11086
11087
11087
11088
11088
11089
11089
11090
11090
11091
11091
11092
11092
11093
11093
11094
11094
11095
11095
11096
11096
11097
11097
11098
11098
11099
11099
11100
11100
11101
11101
11102
11102
11103
11103
11104
11104
11105
11105
11106
11106
11107
11107
11108
11108
11109
11109
11110
11110
11111
11111
11112
11112
11113
11113
11114
11114
11115
11115
11116
11116
11117
11117
11118
11118
11119
11119
11120
11120
11121
11121
11122
11122
11123
11123
11124
11124
11125
11125
11126
11126
11127
11127
11128
11128
11129
11129
11130
11130
11131
11131
11132
11132
11133
11133
11134
11134
11135
11136
11136
11137
11137
11138
11138
11139
11139
11140
11140
11141
11141
11142
11142
11143
11143
11144
11144
11145
11145
11146
11146
11147
11147
11148
11148
11149
11149
11150
11150
11151
11151
11152
11152
11153
11153
11154
11154
11155
11155
11156
11156
11157
11157
11158
11158
11159
11159
11160
11160
11161
11161
11162
11162
11163
11163
11164
11164
11165
11165
11166
11166
11167
11167
11168
11168
11169
11169
11170
11170
11171
11171
11172
11172
11173
11173
11174
11174
11175
11175
11176
11176
11177
11177
11178
11178
11179
11179
11180
11180
11181
11181
11182
11182
11183
11183
11184
11184
11185
11185
11186
11186
11187
11187
11188
11188
11189
11189
11190
11190
11191
11191
11192
11192
11193
11193
11194
11194
11195
11195
11196
11196
11197
11197
11198
11198
11199
11200
11200
11201
11201
11202
11202
11203
11203
11204
11204
11205
11205
11206
11206
11207
11207
11208
11208
11209
11209
11210
11210
11211
11211
11212
11212
11213
11213
11214
11214
11215
11215
11216
11216
11217
11217
11218
11218
11219
11219
11220
11220
11221
11221
11222
11222
11223
11223
11224
11224
11225
11225
11226
11226
11227
11227
11228
11228
11229
11229
11230
11230
11231
11231
11232
11232
11233
11233
11234
11234
11235
11235
11236
11236
11237
11237
11238
11238
11239
11239
11240
11240
11241
11241
11242
11242
11243
11243
11244
11244
11245
11245
11246
11246
11247
11247
11248
11248
11249
11249
11250
11250
11251
11251
11252
11252
11253
11253
11254
11254
11255
11255
11256
11256
11257
11257
11258
11258
11259
11259
11260
11260
11261
11261
11262
11262
11263
11264
11264
11265
11265
11266
11266
11267
11267
11268
11268
11269
11269
11270
11270
11271
11271
11272
11272
11273
11273
11274
11274
11275
11275
11276
11276
11277
11277
11278
11278
11279
11279
11280
11280
11281
11281
11282
11282
11283
11283
11284
11284
11285
11285
11286
11286
11287
11287
11288
11288
11289
11289
11290
11290
11291
11291
11292
11292
11293
11293
11294
11294
11295
11295
11296
11296
11297
11297
11298
11298
11299
11299
11300
11300
11301
11301
11302
11302
11303
11303
11304
11304
11305
11305
11306
11306
11307
11307
11308
11308
11309
11309
11310
11310
11311
11311
11312
11312
11313
11313
11314
11314
11315
11315
11316
11316
11317
11317
11318
11318
11319
11319
11320
11320
11321
11321
11322
11322
11323
11323
11324
11324
11325
11325
11326
11326
11327
11328
11328
11329
11329
11330
11330
11331
11331
11332
11332
11333
11333
11334
11334
11335
11335
11336
11336
11337
11337
11338
11338
11339
11339
11340
11340
11341
11341
11342
11342
11343
11343
11344
11344
11345
11345
11346
11346
11347
11347
11348
11348
11349
11349
11350
11350
11351
11351
11352
11352
11353
11353
11354
11354
11355
11355
11356
11356
11357
11357
11358
11358
11359
11359
11360
11360
11361
11361
11362
11362
11363
11363
11364
11364
11365
11365
11366
11366
11367
11367
11368
11368
11369
11369
11370
11370
11371
11371
11372
11372
11373
11373
11374
11374
11375
11375
11376
11376
11377
11377
11378
11378
11379
11379
11380
11380
11381
11381
11382
11382
11383
11383
11384
11384
11385
11385
11386
11386
11387
11387
11388
11388
11389
11389
11390
11390
11391
11392
11392
11393
11393
11394
11394
11395
11395
11396
11396
11397
11397
11398
11398
11399
11399
11400
11400
11401
11401
11402
11402
11403
11403
11404
11404
11405
11405
11406
11406
11407
11407
11408
11408
11409
11409
11410
11410
11411
11411
11412
11412
11413
11413
11414
11414
11415
11415
11416
11416
11417
11417
11418
11418
11419
11419
11420
11420
11421
11421
11422
11422
11423
11423
11424
11424
11425
11425
11426
11426
11427
11427
11428
11428
11429
11429
11430
11430
11431
11431
11432
11432
11433
11433
11434
11434
11435
11435
11436
11436
11437
11437
11438
11438
11439
11439
11440
11440
11441
11441
11442
11442
11443
11443
11444
11444
11445
11445
11446
11446
11447
11447
11448
11448
11449
11449
11450
11450
11451
11451
11452
11452
11453
11453
11454
11454
11455
11456
11456
11457
11457
11458
11458
11459
11459
11460
11460
11461
11461
11462
11462
11463
11463
11464
11464
11465
11465
11466
11466
11467
11467
11468
11468
11469
11469
11470
11470
11471
11471
11472
11472
11473
11473
11474
11474
11475
11475
11476
11476
11477
11477
11478
11478
11479
11479
11480
11480
11481
11481
11482
11482
11483
11483
11484
11484
11485
11485
11486
11486
11487
11487
11488
11488
11489
11489
11490
11490
11491
11491
11492
11492
11493
11493
11494
11494
11495
11495
11496
11496
11497
11497
11498
11498
11499
11499
11500
11500
11501
11501
11502
11502
11503
11503
11504
11504
11505
11505
11506
11506
11507
11507
11508
11508
11509
11509
11510
11510
11511
11511
11512
11512
11513
11513
11514
11514
11515
11515
11516
11516
11517
11517
11518
11518
11519
11520
11520
11521
11521
11522
11522
11523
11523
11524
11524
11525
11525
11526
11526
11527
11527
11528
11528
11529
11529
11530
11530
11531
11531
11532
11532
11533
11533
11534
11534
11535
11535
11536
11536
11537
11537
11538
11538
11539
11539
11540
11540
11541
11541
11542
11542
11543
11543
11544
11544
11545
11545
11546
11546
11547
11547
11548
11548
11549
11549
11550
11550
11551
11551
11552
11552
11553
11553
11554
11554
11555
11555
11556
11556
11557
11557
11558
11558
11559
11559
11560
11560
11561
11561
11562
11562
11563
11563
11564
11564
11565
11565
11566
11566
11567
11567
11568
11568
11569
11569
11570
11570
11571
11571
11572
11572
11573
11573
11574
11574
11575
11575
11576
11576
11577
11577
11578
11578
11579
11579
11580
11580
11581
11581
11582
11582
11583
11584
11584
11585
11585
11586
11586
11587
11587
11588
11588
11589
11589
11590
11590
11591
11591
11592
11592
11593
11593
11594
11594
11595
11595
11596
11596
11597
11597
11598
11598
11599
11599
11600
11600
11601
11601
11602
11602
11603
11603
11604
11604
11605
11605
11606
11606
11607
11607
11608
11608
11609
11609
11610
11610
11611
11611
11612
11612
11613
11613
11614
11614
11615
11615
11616
11616
11617
11617
11618
11618
11619
11619
11620
11620
11621
11621
11622
11622
11623
11623
11624
11624
11625
11625
11626
11626
11627
11627
11628
11628
11629
11629
11630
11630
11631
11631
11632
11632
11633
11633
11634
11634
11635
11635
11636
11636
11637
11637
11638
11638
11639
11639
11640
11640
11641
11641
11642
11642
11643
11643
11644
11644
11645
11645
11646
11646
11647
11648
11648
11649
11649
11650
11650
11651
11651
11652
11652
11653
11653
11654
11654
11655
11655
11656
11656
11657
11657
11658
11658
11659
11659
11660
11660
11661
11661
11662
11662
11663
11663
11664
11664
11665
11665
11666
11666
11667
11667
11668
11668
11669
11669
11670
11670
11671
11671
11672
11672
11673
11673
11674
11674
11675
11675
11676
11676
11677
11677
11678
11678
11679
11679
11680
11680
11681
11681
11682
11682
11683
11683
11684
11684
11685
11685
11686
11686
11687
11687
11688
11688
11689
11689
11690
11690
11691
11691
11692
11692
11693
11693
11694
11694
11695
11695
11696
11696
11697
11697
11698
11698
11699
11699
11700
11700
11701
11701
11702
11702
11703
11703
11704
11704
11705
11705
11706
11706
11707
11707
11708
11708
11709
11709
11710
11710
11711
11712
11712
11713
11713
11714
11714
11715
11715
11716
11716
11717
11717
11718
11718
11719
11719
11720
11720
11721
11721
11722
11722
11723
11723
11724
11724
11725
11725
11726
11726
11727
11727
11728
11728
11729
11729
11730
11730
11731
11731
11732
11732
11733
11733
11734
11734
11735
11735
11736
11736
11737
11737
11738
11738
11739
11739
11740
11740
11741
11741
11742
11742
11743
11743
11744
11744
11745
11745
11746
11746
11747
11747
11748
11748
11749
11749
11750
11750
11751
11751
11752
11752
11753
11753
11754
11754
11755
11755
11756
11756
11757
11757
11758
11758
11759
11759
11760
11760
11761
11761
11762
11762
11763
11763
11764
11764
11765
11765
11766
11766
11767
11767
11768
11768
11769
11769
11770
11770
11771
11771
11772
11772
11773
11773
11774
11774
11775
11776
11776
11777
11777
11778
11778
11779
11779
11780
11780
11781
11781
11782
11782
11783
11783
11784
11784
11785
11785
11786
11786
11787
11787
11788
11788
11789
11789
11790
11790
11791
11791
11792
11792
11793
11793
11794
11794
11795
11795
11796
11796
11797
11797
11798
11798
11799
11799
11800
11800
11801
11801
11802
11802
11803
11803
11804
11804
11805
11805
11806
11806
11807
11807
11808
11808
11809
11809
11810
11810
11811
11811
11812
11812
11813
11813
11814
11814
11815
11815
11816
11816
11817
11817
11818
11818
11819
11819
11820
11820
11821
11821
11822
11822
11823
11823
11824
11824
11825
11825
11826
11826
11827
11827
11828
11828
11829
11829
11830
11830
11831
11831
11832
11832
11833
11833
11834
11834
11835
11835
11836
11836
11837
11837
11838
11838
11839
11840
11840
11841
11841
11842
11842
11843
11843
11844
11844
11845
11845
11846
11846
11847
11847
11848
11848
11849
11849
11850
11850
11851
11851
11852
11852
11853
11853
11854
11854
11855
11855
11856
11856
11857
11857
11858
11858
11859
11859
11860
11860
11861
11861
11862
11862
11863
11863
11864
11864
11865
11865
11866
11866
11867
11867
11868
11868
11869
11869
11870
11870
11871
11871
11872
11872
11873
11873
11874
11874
11875
11875
11876
11876
11877
11877
11878
11878
11879
11879
11880
11880
11881
11881
11882
11882
11883
11883
11884
11884
11885
11885
11886
11886
11887
11887
11888
11888
11889
11889
11890
11890
11891
11891
11892
11892
11893
11893
11894
11894
11895
11895
11896
11896
11897
11897
11898
11898
11899
11899
11900
11900
11901
11901
11902
11902
11903
11904
11904
11905
11905
11906
11906
11907
11907
11908
11908
11909
11909
11910
11910
11911
11911
11912
11912
11913
11913
11914
11914
11915
11915
11916
11916
11917
11917
11918
11918
11919
11919
11920
11920
11921
11921
11922
11922
11923
11923
11924
11924
11925
11925
11926
11926
11927
11927
11928
11928
11929
11929
11930
11930
11931
11931
11932
11932
11933
11933
11934
11934
11935
11935
11936
11936
11937
11937
11938
11938
11939
11939
11940
11940
11941
11941
11942
11942
11943
11943
11944
11944
11945
11945
11946
11946
11947
11947
11948
11948
11949
11949
11950
11950
11951
11951
11952
11952
11953
11953
11954
11954
11955
11955
11956
11956
11957
11957
11958
11958
11959
11959
11960
11960
11961
11961
11962
11962
11963
11963
11964
11964
11965
11965
11966
11966
11967
11968
11968
11969
11969
11970
11970
11971
11971
11972
11972
11973
11973
11974
11974
11975
11975
11976
11976
11977
11977
11978
11978
11979
11979
11980
11980
11981
11981
11982
11982
11983
11983
11984
11984
11985
11985
11986
11986
11987
11987
11988
11988
11989
11989
11990
11990
11991
11991
11992
11992
11993
11993
11994
11994
11995
11995
11996
11996
11997
11997
11998
11998
11999
11999
12000
12000
12001
12001
12002
12002
12003
12003
12004
12004
12005
12005
12006
12006
12007
12007
12008
12008
12009
12009
12010
12010
12011
12011
12012
12012
12013
12013
12014
12014
12015
12015
12016
12016
12017
12017
12018
12018
12019
12019
12020
12020
12021
12021
12022
12022
12023
12023
12024
12024
12025
12025
12026
12026
12027
12027
12028
12028
12029
12029
12030
12030
12031
12032
12032
12033
12033
12034
12034
12035
12035
12036
12036
12037
12037
12038
12038
12039
12039
12040
12040
12041
12041
12042
12042
12043
12043
12044
12044
12045
12045
12046
12046
12047
12047
12048
12048
12049
12049
12050
12050
12051
12051
12052
12052
12053
12053
12054
12054
12055
12055
12056
12056
12057
12057
12058
12058
12059
12059
12060
12060
12061
12061
12062
12062
12063
12063
12064
12064
12065
12065
12066
12066
12067
12067
12068
12068
12069
12069
12070
12070
12071
12071
12072
12072
12073
12073
12074
12074
12075
12075
12076
12076
12077
12077
12078
12078
12079
12079
12080
12080
12081
12081
12082
12082
12083
12083
12084
12084
12085
12085
12086
12086
12087
12087
12088
12088
12089
12089
12090
12090
12091
12091
12092
12092
12093
12093
12094
12094
12095
12096
12096
12097
12097
12098
12098
12099
12099
12100
12100
12101
12101
12102
12102
12103
12103
12104
12104
12105
12105
12106
12106
12107
12107
12108
12108
12109
12109
12110
12110
12111
12111
12112
12112
12113
12113
12114
12114
12115
12115
12116
12116
12117
12117
12118
12118
12119
12119
12120
12120
12121
12121
12122
12122
12123
12123
12124
12124
12125
12125
12126
12126
12127
12127
12128
12128
12129
12129
12130
12130
12131
12131
12132
12132
12133
12133
12134
12134
12135
12135
12136
12136
12137
12137
12138
12138
12139
12139
12140
12140
12141
12141
12142
12142
12143
12143
12144
12144
12145
12145
12146
12146
12147
12147
12148
12148
12149
12149
12150
12150
12151
12151
12152
12152
12153
12153
12154
12154
12155
12155
12156
12156
12157
12157
12158
12158
12159
12160
12160
12161
12161
12162
12162
12163
12163
12164
12164
12165
12165
12166
12166
12167
12167
12168
12168
12169
12169
12170
12170
12171
12171
12172
12172
12173
12173
12174
12174
12175
12175
12176
12176
12177
12177
12178
12178
12179
12179
12180
12180
12181
12181
12182
12182
12183
12183
12184
12184
12185
12185
12186
12186
12187
12187
12188
12188
12189
12189
12190
12190
12191
12191
12192
12192
12193
12193
12194
12194
12195
12195
12196
12196
12197
12197
12198
12198
12199
12199
12200
12200
12201
12201
12202
12202
12203
12203
12204
12204
12205
12205
12206
12206
12207
12207
12208
12208
12209
12209
12210
12210
12211
12211
12212
12212
12213
12213
12214
12214
12215
12215
12216
12216
12217
12217
12218
12218
12219
12219
12220
12220
12221
12221
12222
12222
12223
12224
12224
12225
12225
12226
12226
12227
12227
12228
12228
12229
12229
12230
12230
12231
12231
12232
12232
12233
12233
12234
12234
12235
12235
12236
12236
12237
12237
12238
12238
12239
12239
12240
12240
12241
12241
12242
12242
12243
12243
12244
12244
12245
12245
12246
12246
12247
12247
12248
12248
12249
12249
12250
12250
12251
12251
12252
12252
12253
12253
12254
12254
12255
12255
12256
12256
12257
12257
12258
12258
12259
12259
12260
12260
12261
12261
12262
12262
12263
12263
12264
12264
12265
12265
12266
12266
12267
12267
12268
12268
12269
12269
12270
12270
12271
12271
12272
12272
12273
12273
12274
12274
12275
12275
12276
12276
12277
12277
12278
12278
12279
12279
12280
12280
12281
12281
12282
12282
12283
12283
12284
12284
12285
12285
12286
12286
12287
12288
12288
12289
12289
12290
12290
12291
12291
12292
12292
12293
12293
12294
12294
12295
12295
12296
12296
12297
12297
12298
12298
12299
12299
12300
12300
12301
12301
12302
12302
12303
12303
12304
12304
12305
12305
12306
12306
12307
12307
12308
12308
12309
12309
12310
12310
12311
12311
12312
12312
12313
12313
12314
12314
12315
12315
12316
12316
12317
12317
12318
12318
12319
12319
12320
12320
12321
12321
12322
12322
12323
12323
12324
12324
12325
12325
12326
12326
12327
12327
12328
12328
12329
12329
12330
12330
12331
12331
12332
12332
12333
12333
12334
12334
12335
12335
12336
12336
12337
12337
12338
12338
12339
12339
12340
12340
12341
12341
12342
12342
12343
12343
12344
12344
12345
12345
12346
12346
12347
12347
12348
12348
12349
12349
12350
12350
12351
12352
12352
12353
12353
12354
12354
12355
12355
12356
12356
12357
12357
12358
12358
12359
12359
12360
12360
12361
12361
12362
12362
12363
12363
12364
12364
12365
12365
12366
12366
12367
12367
12368
12368
12369
12369
12370
12370
12371
12371
12372
12372
12373
12373
12374
12374
12375
12375
12376
12376
12377
12377
12378
12378
12379
12379
12380
12380
12381
12381
12382
12382
12383
12383
12384
12384
12385
12385
12386
12386
12387
12387
12388
12388
12389
12389
12390
12390
12391
12391
12392
12392
12393
12393
12394
12394
12395
12395
12396
12396
12397
12397
12398
12398
12399
12399
12400
12400
12401
12401
12402
12402
12403
12403
12404
12404
12405
12405
12406
12406
12407
12407
12408
12408
12409
12409
12410
12410
12411
12411
12412
12412
12413
12413
12414
12414
12415
12416
12416
12417
12417
12418
12418
12419
12419
12420
12420
12421
12421
12422
12422
12423
12423
12424
12424
12425
12425
12426
12426
12427
12427
12428
12428
12429
12429
12430
12430
12431
12431
12432
12432
12433
12433
12434
12434
12435
12435
12436
12436
12437
12437
12438
12438
12439
12439
12440
12440
12441
12441
12442
12442
12443
12443
12444
12444
12445
12445
12446
12446
12447
12447
12448
12448
12449
12449
12450
12450
12451
12451
12452
12452
12453
12453
12454
12454
12455
12455
12456
12456
12457
12457
12458
12458
12459
12459
12460
12460
12461
12461
12462
12462
12463
12463
12464
12464
12465
12465
12466
12466
12467
12467
12468
12468
12469
12469
12470
12470
12471
12471
12472
12472
12473
12473
12474
12474
12475
12475
12476
12476
12477
12477
12478
12478
12479
12480
12480
12481
12481
12482
12482
12483
12483
12484
12484
12485
12485
12486
12486
12487
12487
12488
12488
12489
12489
12490
12490
12491
12491
12492
12492
12493
12493
12494
12494
12495
12495
12496
12496
12497
12497
12498
12498
12499
12499
12500
12500
12501
12501
12502
12502
12503
12503
12504
12504
12505
12505
12506
12506
12507
12507
12508
12508
12509
12509
12510
12510
12511
12511
12512
12512
12513
12513
12514
12514
12515
12515
12516
12516
12517
12517
12518
12518
12519
12519
12520
12520
12521
12521
12522
12522
12523
12523
12524
12524
12525
12525
12526
12526
12527
12527
12528
12528
12529
12529
12530
12530
12531
12531
12532
12532
12533
12533
12534
12534
12535
12535
12536
12536
12537
12537
12538
12538
12539
12539
12540
12540
12541
12541
12542
12542
12543
12544
12544
12545
12545
12546
12546
12547
12547
12548
12548
12549
12549
12550
12550
12551
12551
12552
12552
12553
12553
12554
12554
12555
12555
12556
12556
12557
12557
12558
12558
12559
12559
12560
12560
12561
12561
12562
12562
12563
12563
12564
12564
12565
12565
12566
12566
12567
12567
12568
12568
12569
12569
12570
12570
12571
12571
12572
12572
12573
12573
12574
12574
12575
12575
12576
12576
12577
12577
12578
12578
12579
12579
12580
12580
12581
12581
12582
12582
12583
12583
12584
12584
12585
12585
12586
12586
12587
12587
12588
12588
12589
12589
12590
12590
12591
12591
12592
12592
12593
12593
12594
12594
12595
12595
12596
12596
12597
12597
12598
12598
12599
12599
12600
12600
12601
12601
12602
12602
12603
12603
12604
12604
12605
12605
12606
12606
12607
12608
12608
12609
12609
12610
12610
12611
12611
12612
12612
12613
12613
12614
12614
12615
12615
12616
12616
12617
12617
12618
12618
12619
12619
12620
12620
12621
12621
12622
12622
12623
12623
12624
12624
12625
12625
12626
12626
12627
12627
12628
12628
12629
12629
12630
12630
12631
12631
12632
12632
12633
12633
12634
12634
12635
12635
12636
12636
12637
12637
12638
12638
12639
12639
12640
12640
12641
12641
12642
12642
12643
12643
12644
12644
12645
12645
12646
12646
12647
12647
12648
12648
12649
12649
12650
12650
12651
12651
12652
12652
12653
12653
12654
12654
12655
12655
12656
12656
12657
12657
12658
12658
12659
12659
12660
12660
12661
12661
12662
12662
12663
12663
12664
12664
12665
12665
12666
12666
12667
12667
12668
12668
12669
12669
12670
12670
12671
12672
12672
12673
12673
12674
12674
12675
12675
12676
12676
12677
12677
12678
12678
12679
12679
12680
12680
12681
12681
12682
12682
12683
12683
12684
12684
12685
12685
12686
12686
12687
12687
12688
12688
12689
12689
12690
12690
12691
12691
12692
12692
12693
12693
12694
12694
12695
12695
12696
12696
12697
12697
12698
12698
12699
12699
12700
12700
12701
12701
12702
12702
12703
12703
12704
12704
12705
12705
12706
12706
12707
12707
12708
12708
12709
12709
12710
12710
12711
12711
12712
12712
12713
12713
12714
12714
12715
12715
12716
12716
12717
12717
12718
12718
12719
12719
12720
12720
12721
12721
12722
12722
12723
12723
12724
12724
12725
12725
12726
12726
12727
12727
12728
12728
12729
12729
12730
12730
12731
12731
12732
12732
12733
12733
12734
12734
12735
12736
12736
12737
12737
12738
12738
12739
12739
12740
12740
12741
12741
12742
12742
12743
12743
12744
12744
12745
12745
12746
12746
12747
12747
12748
12748
12749
12749
12750
12750
12751
12751
12752
12752
12753
12753
12754
12754
12755
12755
12756
12756
12757
12757
12758
12758
12759
12759
12760
12760
12761
12761
12762
12762
12763
12763
12764
12764
12765
12765
12766
12766
12767
12767
12768
12768
12769
12769
12770
12770
12771
12771
12772
12772
12773
12773
12774
12774
12775
12775
12776
12776
12777
12777
12778
12778
12779
12779
12780
12780
12781
12781
12782
12782
12783
12783
12784
12784
12785
12785
12786
12786
12787
12787
12788
12788
12789
12789
12790
12790
12791
12791
12792
12792
12793
12793
12794
12794
12795
12795
12796
12796
12797
12797
12798
12798
12799
12800
12800
12801
12801
12802
12802
12803
12803
12804
12804
12805
12805
12806
12806
12807
12807
12808
12808
12809
12809
12810
12810
12811
12811
12812
12812
12813
12813
12814
12814
12815
12815
12816
12816
12817
12817
12818
12818
12819
12819
12820
12820
12821
12821
12822
12822
12823
12823
12824
12824
12825
12825
12826
12826
12827
12827
12828
12828
12829
12829
12830
12830
12831
12831
12832
12832
12833
12833
12834
12834
12835
12835
12836
12836
12837
12837
12838
12838
12839
12839
12840
12840
12841
12841
12842
12842
12843
12843
12844
12844
12845
12845
12846
12846
12847
12847
12848
12848
12849
12849
12850
12850
12851
12851
12852
12852
12853
12853
12854
12854
12855
12855
12856
12856
12857
12857
12858
12858
12859
12859
12860
12860
12861
12861
12862
12862
12863
12864
12864
12865
12865
12866
12866
12867
12867
12868
12868
12869
12869
12870
12870
12871
12871
12872
12872
12873
12873
12874
12874
12875
12875
12876
12876
12877
12877
12878
12878
12879
12879
12880
12880
12881
12881
12882
12882
12883
12883
12884
12884
12885
12885
12886
12886
12887
12887
12888
12888
12889
12889
12890
12890
12891
12891
12892
12892
12893
12893
12894
12894
12895
12895
12896
12896
12897
12897
12898
12898
12899
12899
12900
12900
12901
12901
12902
12902
12903
12903
12904
12904
12905
12905
12906
12906
12907
12907
12908
12908
12909
12909
12910
12910
12911
12911
12912
12912
12913
12913
12914
12914
12915
12915
12916
12916
12917
12917
12918
12918
12919
12919
12920
12920
12921
12921
12922
12922
12923
12923
12924
12924
12925
12925
12926
12926
12927
12928
12928
12929
12929
12930
12930
12931
12931
12932
12932
12933
12933
12934
12934
12935
12935
12936
12936
12937
12937
12938
12938
12939
12939
12940
12940
12941
12941
12942
12942
12943
12943
12944
12944
12945
12945
12946
12946
12947
12947
12948
12948
12949
12949
12950
12950
12951
12951
12952
12952
12953
12953
12954
12954
12955
12955
12956
12956
12957
12957
12958
12958
12959
12959
12960
12960
12961
12961
12962
12962
12963
12963
12964
12964
12965
12965
12966
12966
12967
12967
12968
12968
12969
12969
12970
12970
12971
12971
12972
12972
12973
12973
12974
12974
12975
12975
12976
12976
12977
12977
12978
12978
12979
12979
12980
12980
12981
12981
12982
12982
12983
12983
12984
12984
12985
12985
12986
12986
12987
12987
12988
12988
12989
12989
12990
12990
12991
12992
12992
12993
12993
12994
12994
12995
12995
12996
12996
12997
12997
12998
12998
12999
12999
13000
13000
13001
13001
13002
13002
13003
13003
13004
13004
13005
13005
13006
13006
13007
13007
13008
13008
13009
13009
13010
13010
13011
13011
13012
13012
13013
13013
13014
13014
13015
13015
13016
13016
13017
13017
13018
13018
13019
13019
13020
13020
13021
13021
13022
13022
13023
13023
13024
13024
13025
13025
13026
13026
13027
13027
13028
13028
13029
13029
13030
13030
13031
13031
13032
13032
13033
13033
13034
13034
13035
13035
13036
13036
13037
13037
13038
13038
13039
13039
13040
13040
13041
13041
13042
13042
13043
13043
13044
13044
13045
13045
13046
13046
13047
13047
13048
13048
13049
13049
13050
13050
13051
13051
13052
13052
13053
13053
13054
13054
13055
13056
13056
13057
13057
13058
13058
13059
13059
13060
13060
13061
13061
13062
13062
13063
13063
13064
13064
13065
13065
13066
13066
13067
13067
13068
13068
13069
13069
13070
13070
13071
13071
13072
13072
13073
13073
13074
13074
13075
13075
13076
13076
13077
13077
13078
13078
13079
13079
13080
13080
13081
13081
13082
13082
13083
13083
13084
13084
13085
13085
13086
13086
13087
13087
13088
13088
13089
13089
13090
13090
13091
13091
13092
13092
13093
13093
13094
13094
13095
13095
13096
13096
13097
13097
13098
13098
13099
13099
13100
13100
13101
13101
13102
13102
13103
13103
13104
13104
13105
13105
13106
13106
13107
13107
13108
13108
13109
13109
13110
13110
13111
13111
13112
13112
13113
13113
13114
13114
13115
13115
13116
13116
13117
13117
13118
13118
13119
13120
13120
13121
13121
13122
13122
13123
13123
13124
13124
13125
13125
13126
13126
13127
13127
13128
13128
13129
13129
13130
13130
13131
13131
13132
13132
13133
13133
13134
13134
13135
13135
13136
13136
13137
13137
13138
13138
13139
13139
13140
13140
13141
13141
13142
13142
13143
13143
13144
13144
13145
13145
13146
13146
13147
13147
13148
13148
13149
13149
13150
13150
13151
13151
13152
13152
13153
13153
13154
13154
13155
13155
13156
13156
13157
13157
13158
13158
13159
13159
13160
13160
13161
13161
13162
13162
13163
13163
13164
13164
13165
13165
13166
13166
13167
13167
13168
13168
13169
13169
13170
13170
13171
13171
13172
13172
13173
13173
13174
13174
13175
13175
13176
13176
13177
13177
13178
13178
13179
13179
13180
13180
13181
13181
13182
13182
13183
13184
13184
13185
13185
13186
13186
13187
13187
13188
13188
13189
13189
13190
13190
13191
13191
13192
13192
13193
13193
13194
13194
13195
13195
13196
13196
13197
13197
13198
13198
13199
13199
13200
13200
13201
13201
13202
13202
13203
13203
13204
13204
13205
13205
13206
13206
13207
13207
13208
13208
13209
13209
13210
13210
13211
13211
13212
13212
13213
13213
13214
13214
13215
13215
13216
13216
13217
13217
13218
13218
13219
13219
13220
13220
13221
13221
13222
13222
13223
13223
13224
13224
13225
13225
13226
13226
13227
13227
13228
13228
13229
13229
13230
13230
13231
13231
13232
13232
13233
13233
13234
13234
13235
13235
13236
13236
13237
13237
13238
13238
13239
13239
13240
13240
13241
13241
13242
13242
13243
13243
13244
13244
13245
13245
13246
13246
13247
13248
13248
13249
13249
13250
13250
13251
13251
13252
13252
13253
13253
13254
13254
13255
13255
13256
13256
13257
13257
13258
13258
13259
13259
13260
13260
13261
13261
13262
13262
13263
13263
13264
13264
13265
13265
13266
13266
13267
13267
13268
13268
13269
13269
13270
13270
13271
13271
13272
13272
13273
13273
13274
13274
13275
13275
13276
13276
13277
13277
13278
13278
13279
13279
13280
13280
13281
13281
13282
13282
13283
13283
13284
13284
13285
13285
13286
13286
13287
13287
13288
13288
13289
13289
13290
13290
13291
13291
13292
13292
13293
13293
13294
13294
13295
13295
13296
13296
13297
13297
13298
13298
13299
13299
13300
13300
13301
13301
13302
13302
13303
13303
13304
13304
13305
13305
13306
13306
13307
13307
13308
13308
13309
13309
13310
13310
13311
13312
13312
13313
13313
13314
13314
13315
13315
13316
13316
13317
13317
13318
13318
13319
13319
13320
13320
13321
13321
13322
13322
13323
13323
13324
13324
13325
13325
13326
13326
13327
13327
13328
13328
13329
13329
13330
13330
13331
13331
13332
13332
13333
13333
13334
13334
13335
13335
13336
13336
13337
13337
13338
13338
13339
13339
13340
13340
13341
13341
13342
13342
13343
13343
13344
13344
13345
13345
13346
13346
13347
13347
13348
13348
13349
13349
13350
13350
13351
13351
13352
13352
13353
13353
13354
13354
13355
13355
13356
13356
13357
13357
13358
13358
13359
13359
13360
13360
13361
13361
13362
13362
13363
13363
13364
13364
13365
13365
13366
13366
13367
13367
13368
13368
13369
13369
13370
13370
13371
13371
13372
13372
13373
13373
13374
13374
13375
13376
13376
13377
13377
13378
13378
13379
13379
13380
13380
13381
13381
13382
13382
13383
13383
13384
13384
13385
13385
13386
13386
13387
13387
13388
13388
13389
13389
13390
13390
13391
13391
13392
13392
13393
13393
13394
13394
13395
13395
13396
13396
13397
13397
13398
13398
13399
13399
13400
13400
13401
13401
13402
13402
13403
13403
13404
13404
13405
13405
13406
13406
13407
13407
13408
13408
13409
13409
13410
13410
13411
13411
13412
13412
13413
13413
13414
13414
13415
13415
13416
13416
13417
13417
13418
13418
13419
13419
13420
13420
13421
13421
13422
13422
13423
13423
13424
13424
13425
13425
13426
13426
13427
13427
13428
13428
13429
13429
13430
13430
13431
13431
13432
13432
13433
13433
13434
13434
13435
13435
13436
13436
13437
13437
13438
13438
13439
13440
13440
13441
13441
13442
13442
13443
13443
13444
13444
13445
13445
13446
13446
13447
13447
13448
13448
13449
13449
13450
13450
13451
13451
13452
13452
13453
13453
13454
13454
13455
13455
13456
13456
13457
13457
13458
13458
13459
13459
13460
13460
13461
13461
13462
13462
13463
13463
13464
13464
13465
13465
13466
13466
13467
13467
13468
13468
13469
13469
13470
13470
13471
13471
13472
13472
13473
13473
13474
13474
13475
13475
13476
13476
13477
13477
13478
13478
13479
13479
13480
13480
13481
13481
13482
13482
13483
13483
13484
13484
13485
13485
13486
13486
13487
13487
13488
13488
13489
13489
13490
13490
13491
13491
13492
13492
13493
13493
13494
13494
13495
13495
13496
13496
13497
13497
13498
13498
13499
13499
13500
13500
13501
13501
13502
13502
13503
13504
13504
13505
13505
13506
13506
13507
13507
13508
13508
13509
13509
13510
13510
13511
13511
13512
13512
13513
13513
13514
13514
13515
13515
13516
13516
13517
13517
13518
13518
13519
13519
13520
13520
13521
13521
13522
13522
13523
13523
13524
13524
13525
13525
13526
13526
13527
13527
13528
13528
13529
13529
13530
13530
13531
13531
13532
13532
13533
13533
13534
13534
13535
13535
13536
13536
13537
13537
13538
13538
13539
13539
13540
13540
13541
13541
13542
13542
13543
13543
13544
13544
13545
13545
13546
13546
13547
13547
13548
13548
13549
13549
13550
13550
13551
13551
13552
13552
13553
13553
13554
13554
13555
13555
13556
13556
13557
13557
13558
13558
13559
13559
13560
13560
13561
13561
13562
13562
13563
13563
13564
13564
13565
13565
13566
13566
13567
13568
13568
13569
13569
13570
13570
13571
13571
13572
13572
13573
13573
13574
13574
13575
13575
13576
13576
13577
13577
13578
13578
13579
13579
13580
13580
13581
13581
13582
13582
13583
13583
13584
13584
13585
13585
13586
13586
13587
13587
13588
13588
13589
13589
13590
13590
13591
13591
13592
13592
13593
13593
13594
13594
13595
13595
13596
13596
13597
13597
13598
13598
13599
13599
13600
13600
13601
13601
13602
13602
13603
13603
13604
13604
13605
13605
13606
13606
13607
13607
13608
13608
13609
13609
13610
13610
13611
13611
13612
13612
13613
13613
13614
13614
13615
13615
13616
13616
13617
13617
13618
13618
13619
13619
13620
13620
13621
13621
13622
13622
13623
13623
13624
13624
13625
13625
13626
13626
13627
13627
13628
13628
13629
13629
13630
13630
13631
13632
13632
13633
13633
13634
13634
13635
13635
13636
13636
13637
13637
13638
13638
13639
13639
13640
13640
13641
13641
13642
13642
13643
13643
13644
13644
13645
13645
13646
13646
13647
13647
13648
13648
13649
13649
13650
13650
13651
13651
13652
13652
13653
13653
13654
13654
13655
13655
13656
13656
13657
13657
13658
13658
13659
13659
13660
13660
13661
13661
13662
13662
13663
13663
13664
13664
13665
13665
13666
13666
13667
13667
13668
13668
13669
13669
13670
13670
13671
13671
13672
13672
13673
13673
13674
13674
13675
13675
13676
13676
13677
13677
13678
13678
13679
13679
13680
13680
13681
13681
13682
13682
13683
13683
13684
13684
13685
13685
13686
13686
13687
13687
13688
13688
13689
13689
13690
13690
13691
13691
13692
13692
13693
13693
13694
13694
13695
13696
13696
13697
13697
13698
13698
13699
13699
13700
13700
13701
13701
13702
13702
13703
13703
13704
13704
13705
13705
13706
13706
13707
13707
13708
13708
13709
13709
13710
13710
13711
13711
13712
13712
13713
13713
13714
13714
13715
13715
13716
13716
13717
13717
13718
13718
13719
13719
13720
13720
13721
13721
13722
13722
13723
13723
13724
13724
13725
13725
13726
13726
13727
13727
13728
13728
13729
13729
13730
13730
13731
13731
13732
13732
13733
13733
13734
13734
13735
13735
13736
13736
13737
13737
13738
13738
13739
13739
13740
13740
13741
13741
13742
13742
13743
13743
13744
13744
13745
13745
13746
13746
13747
13747
13748
13748
13749
13749
13750
13750
13751
13751
13752
13752
13753
13753
13754
13754
13755
13755
13756
13756
13757
13757
13758
13758
13759
13760
13760
13761
13761
13762
13762
13763
13763
13764
13764
13765
13765
13766
13766
13767
13767
13768
13768
13769
13769
13770
13770
13771
13771
13772
13772
13773
13773
13774
13774
13775
13775
13776
13776
13777
13777
13778
13778
13779
13779
13780
13780
13781
13781
13782
13782
13783
13783
13784
13784
13785
13785
13786
13786
13787
13787
13788
13788
13789
13789
13790
13790
13791
13791
13792
13792
13793
13793
13794
13794
13795
13795
13796
13796
13797
13797
13798
13798
13799
13799
13800
13800
13801
13801
13802
13802
13803
13803
13804
13804
13805
13805
13806
13806
13807
13807
13808
13808
13809
13809
13810
13810
13811
13811
13812
13812
13813
13813
13814
13814
13815
13815
13816
13816
13817
13817
13818
13818
13819
13819
13820
13820
13821
13821
13822
13822
13823
13824
13824
13825
13825
13826
13826
13827
13827
13828
13828
13829
13829
13830
13830
13831
13831
13832
13832
13833
13833
13834
13834
13835
13835
13836
13836
13837
13837
13838
13838
13839
13839
13840
13840
13841
13841
13842
13842
13843
13843
13844
13844
13845
13845
13846
13846
13847
13847
13848
13848
13849
13849
13850
13850
13851
13851
13852
13852
13853
13853
13854
13854
13855
13855
13856
13856
13857
13857
13858
13858
13859
13859
13860
13860
13861
13861
13862
13862
13863
13863
13864
13864
13865
13865
13866
13866
13867
13867
13868
13868
13869
13869
13870
13870
13871
13871
13872
13872
13873
13873
13874
13874
13875
13875
13876
13876
13877
13877
13878
13878
13879
13879
13880
13880
13881
13881
13882
13882
13883
13883
13884
13884
13885
13885
13886
13886
13887
13888
13888
13889
13889
13890
13890
13891
13891
13892
13892
13893
13893
13894
13894
13895
13895
13896
13896
13897
13897
13898
13898
13899
13899
13900
13900
13901
13901
13902
13902
13903
13903
13904
13904
13905
13905
13906
13906
13907
13907
13908
13908
13909
13909
13910
13910
13911
13911
13912
13912
13913
13913
13914
13914
13915
13915
13916
13916
13917
13917
13918
13918
13919
13919
13920
13920
13921
13921
13922
13922
13923
13923
13924
13924
13925
13925
13926
13926
13927
13927
13928
13928
13929
13929
13930
13930
13931
13931
13932
13932
13933
13933
13934
13934
13935
13935
13936
13936
13937
13937
13938
13938
13939
13939
13940
13940
13941
13941
13942
13942
13943
13943
13944
13944
13945
13945
13946
13946
13947
13947
13948
13948
13949
13949
13950
13950
13951
13952
13952
13953
13953
13954
13954
13955
13955
13956
13956
13957
13957
13958
13958
13959
13959
13960
13960
13961
13961
13962
13962
13963
13963
13964
13964
13965
13965
13966
13966
13967
13967
13968
13968
13969
13969
13970
13970
13971
13971
13972
13972
13973
13973
13974
13974
13975
13975
13976
13976
13977
13977
13978
13978
13979
13979
13980
13980
13981
13981
13982
13982
13983
13983
13984
13984
13985
13985
13986
13986
13987
13987
13988
13988
13989
13989
13990
13990
13991
13991
13992
13992
13993
13993
13994
13994
13995
13995
13996
13996
13997
13997
13998
13998
13999
13999
14000
14000
14001
14001
14002
14002
14003
14003
14004
14004
14005
14005
14006
14006
14007
14007
14008
14008
14009
14009
14010
14010
14011
14011
14012
14012
14013
14013
14014
14014
14015
14016
14016
14017
14017
14018
14018
14019
14019
14020
14020
14021
14021
14022
14022
14023
14023
14024
14024
14025
14025
14026
14026
14027
14027
14028
14028
14029
14029
14030
14030
14031
14031
14032
14032
14033
14033
14034
14034
14035
14035
14036
14036
14037
14037
14038
14038
14039
14039
14040
14040
14041
14041
14042
14042
14043
14043
14044
14044
14045
14045
14046
14046
14047
14047
14048
14048
14049
14049
14050
14050
14051
14051
14052
14052
14053
14053
14054
14054
14055
14055
14056
14056
14057
14057
14058
14058
14059
14059
14060
14060
14061
14061
14062
14062
14063
14063
14064
14064
14065
14065
14066
14066
14067
14067
14068
14068
14069
14069
14070
14070
14071
14071
14072
14072
14073
14073
14074
14074
14075
14075
14076
14076
14077
14077
14078
14078
14079
14080
14080
14081
14081
14082
14082
14083
14083
14084
14084
14085
14085
14086
14086
14087
14087
14088
14088
14089
14089
14090
14090
14091
14091
14092
14092
14093
14093
14094
14094
14095
14095
14096
14096
14097
14097
14098
14098
14099
14099
14100
14100
14101
14101
14102
14102
14103
14103
14104
14104
14105
14105
14106
14106
14107
14107
14108
14108
14109
14109
14110
14110
14111
14111
14112
14112
14113
14113
14114
14114
14115
14115
14116
14116
14117
14117
14118
14118
14119
14119
14120
14120
14121
14121
14122
14122
14123
14123
14124
14124
14125
14125
14126
14126
14127
14127
14128
14128
14129
14129
14130
14130
14131
14131
14132
14132
14133
14133
14134
14134
14135
14135
14136
14136
14137
14137
14138
14138
14139
14139
14140
14140
14141
14141
14142
14142
14143
14144
14144
14145
14145
14146
14146
14147
14147
14148
14148
14149
14149
14150
14150
14151
14151
14152
14152
14153
14153
14154
14154
14155
14155
14156
14156
14157
14157
14158
14158
14159
14159
14160
14160
14161
14161
14162
14162
14163
14163
14164
14164
14165
14165
14166
14166
14167
14167
14168
14168
14169
14169
14170
14170
14171
14171
14172
14172
14173
14173
14174
14174
14175
14175
14176
14176
14177
14177
14178
14178
14179
14179
14180
14180
14181
14181
14182
14182
14183
14183
14184
14184
14185
14185
14186
14186
14187
14187
14188
14188
14189
14189
14190
14190
14191
14191
14192
14192
14193
14193
14194
14194
14195
14195
14196
14196
14197
14197
14198
14198
14199
14199
14200
14200
14201
14201
14202
14202
14203
14203
14204
14204
14205
14205
14206
14206
14207
14208
14208
14209
14209
14210
14210
14211
14211
14212
14212
14213
14213
14214
14214
14215
14215
14216
14216
14217
14217
14218
14218
14219
14219
14220
14220
14221
14221
14222
14222
14223
14223
14224
14224
14225
14225
14226
14226
14227
14227
14228
14228
14229
14229
14230
14230
14231
14231
14232
14232
14233
14233
14234
14234
14235
14235
14236
14236
14237
14237
14238
14238
14239
14239
14240
14240
14241
14241
14242
14242
14243
14243
14244
14244
14245
14245
14246
14246
14247
14247
14248
14248
14249
14249
14250
14250
14251
14251
14252
14252
14253
14253
14254
14254
14255
14255
14256
14256
14257
14257
14258
14258
14259
14259
14260
14260
14261
14261
14262
14262
14263
14263
14264
14264
14265
14265
14266
14266
14267
14267
14268
14268
14269
14269
14270
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
3072
3136
3200
3264
3328
3392
3456
3520
3584
3648
3712
3776
3840
3904
3968
4032
4096
4160
4224
4288
4352
4416
4480
4544
4608
4672
4736
4800
4864
4928
4992
5056
5120
5184
5248
5312
5376
5440
5504
5568
5632
5696
5760
5824
5888
5952
6016
6080
6144
6208
6272
6336
6400
6464
6528
6592
6656
6720
6784
6848
6912
6976
7040
7104
7168
7232
7296
7360
7424
7488
7552
7616
7680
7744
7808
7872
7936
8000
8064
8128
8192
8256
8320
8384
8448
8512
8576
8640
8704
8768
8832
8896
8960
9024
9088
9152
9216
9280
9344
9408
9472
9536
9600
9664
9728
9792
9856
9920
9984
10048
10112
10176
10240
10304
10368
10432
10496
10560
10624
10688
10752
10816
10880
10944
11008
11072
11136
11200
63
127
191
255
319
383
447
511
575
639
703
767
831
895
959
1023
1087
1151
1215
1279
1343
1407
1471
1535
1599
1663
1727
1791
1855
1919
1983
2047
2111
2175
2239
2303
2367
2431
2495
2559
2623
2687
2751
2815
2879
2943
3007
3071
3135
3199
3263
3327
3391
3455
3519
3583
3647
3711
3775
3839
3903
3967
4031
4095
4159
4223
4287
4351
4415
4479
4543
4607
4671
4735
4799
4863
4927
4991
5055
5119
5183
5247
5311
5375
5439
5503
5567
5631
5695
5759
5823
5887
5951
6015
6079
6143
6207
6271
6335
6399
6463
6527
6591
6655
6719
6783
6847
6911
6975
7039
7103
7167
7231
7295
7359
7423
7487
7551
7615
7679
7743
7807
7871
7935
7999
8063
8127
8191
8255
8319
8383
8447
8511
8575
8639
8703
8767
8831
8895
8959
9023
9087
9151
9215
9279
9343
9407
9471
9535
9599
9663
9727
9791
9855
9919
9983
10047
10111
10175
10239
10303
10367
10431
10495
10559
10623
10687
10751
10815
10879
10943
11007
11071
11135
11199
11263
11327
11391
11455
11519
11583
11647
11711
11775
11839
11903
11967
12031
12095
12159
12223
12287
12351
12415
12479
12543
12607
12671
12735
12799
12863
12927
12991
13055
13119
13183
13247
13311
13375
13439
13503
13567
13631
13695
13759
13823
13887
13951
14015
14079
14143
14207
14271
14335
0
64
128
192
256
320
384
448
512
576
640
704
768
832
896
960
1024
1088
1152
1216
1280
1344
1408
1472
1536
1600
1664
1728
1792
1856
1920
1984
2048
2112
2176
2240
2304
2368
2432
2496
2560
2624
2688
2752
2816
2880
2944
3008
11264
11328
11392
11456
11520
11584
11648
11712
11776
11840
11904
11968
12032
12096
12160
12224
12288
12352
12416
12480
12544
12608
12672
12736
12800
12864
12928
12992
13056
13120
13184
13248
13312
13376
13440
13504
13568
13632
13696
13760
13824
13888
13952
14016
14080
14144
14208
14272
)
// ************************************************************************* //
| [
"david.moravec@cfdsupport.com"
] | david.moravec@cfdsupport.com | |
268b53674eafa9f7f8df9979d2d40b1e66b30436 | 14818097e81239f6326fdeaa72a839cb7c77dd36 | /src/Core/Algorithms/Legacy/Inverse/SolveInverseProblemWithTikhonovTSVD_impl.h | 18fe4133be88257013d6bb6b4b857229bba1056b | [
"MIT"
] | permissive | lmccane/SCIRun | 33a626a7919d800acf3b8ac0105e0fbabad885b0 | 8d19fb86f8ea3922bdcee9b8556abe19b9239a6c | refs/heads/master | 2021-04-28T03:21:41.961509 | 2018-02-15T23:59:22 | 2018-02-15T23:59:22 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,651 | h | /*
For more information, please see: http://software.sci.utah.edu
The MIT License
Copyright (c) 2015 Scientific Computing and Imaging Institute,
University of Utah.
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.
*/
// File : SolveInverseProblemWithTSVD.h
// Author : Jaume Coll-Font, Yesim Serinagaoglu & Alireza Ghodrati
// Date : September 06th, 2017 (last update)
#ifndef BioPSE_SolveInverseProblemWithTikhonovTSVDimpl_H__
#define BioPSE_SolveInverseProblemWithTikhonovTSVDimpl_H__
#include <vector>
#include <boost/utility.hpp>
#include <boost/function.hpp>
#include <Core/Datatypes/MatrixFwd.h>
#include <Core/Datatypes/DenseMatrix.h>
#include <Core/Datatypes/DenseColumnMatrix.h>
#include <Core/Logging/LoggerFwd.h>
#include <Core/Algorithms/Legacy/Inverse/TikhonovImpl.h>
#include <Core/Algorithms/Legacy/Inverse/share.h>
namespace SCIRun {
namespace Core {
namespace Algorithms {
namespace Inverse {
class SCISHARE SolveInverseProblemWithTikhonovTSVD_impl : public TikhonovImpl
{
public:
SolveInverseProblemWithTikhonovTSVD_impl(const SCIRun::Core::Datatypes::DenseMatrix& forwardMatrix_, const SCIRun::Core::Datatypes::DenseMatrix& measuredData_ , const SCIRun::Core::Datatypes::DenseMatrix& sourceWeighting_, const SCIRun::Core::Datatypes::DenseMatrix& sensorWeighting_, const SCIRun::Core::Datatypes::DenseMatrix& matrixU_, const SCIRun::Core::Datatypes::DenseMatrix& singularValues_, const SCIRun::Core::Datatypes::DenseMatrix& matrixV_)
{
preAlocateInverseMatrices( forwardMatrix_, measuredData_ , sourceWeighting_, sensorWeighting_, matrixU_, singularValues_, matrixV_ );
};
SolveInverseProblemWithTikhonovTSVD_impl(const SCIRun::Core::Datatypes::DenseMatrix& forwardMatrix_, const SCIRun::Core::Datatypes::DenseMatrix& measuredData_ , const SCIRun::Core::Datatypes::DenseMatrix& sourceWeighting_, const SCIRun::Core::Datatypes::DenseMatrix& sensorWeighting_)
{
preAlocateInverseMatrices( forwardMatrix_, measuredData_ , sourceWeighting_, sensorWeighting_);
};
private:
// Data Members
int rank;
SCIRun::Core::Datatypes::DenseMatrix svd_MatrixU;
SCIRun::Core::Datatypes::DenseColumnMatrix svd_SingularValues;
SCIRun::Core::Datatypes::DenseMatrix svd_MatrixV;
SCIRun::Core::Datatypes::DenseMatrix Uy;
// Methods
void preAlocateInverseMatrices(const SCIRun::Core::Datatypes::DenseMatrix& forwardMatrix_, const SCIRun::Core::Datatypes::DenseMatrix& measuredData_ , const SCIRun::Core::Datatypes::DenseMatrix& sourceWeighting_, const SCIRun::Core::Datatypes::DenseMatrix& sensorWeighting_, const SCIRun::Core::Datatypes::DenseMatrix& matrixU_, const SCIRun::Core::Datatypes::DenseMatrix& singularValues_, const SCIRun::Core::Datatypes::DenseMatrix& matrixV_);
void preAlocateInverseMatrices(const SCIRun::Core::Datatypes::DenseMatrix& forwardMatrix_, const SCIRun::Core::Datatypes::DenseMatrix& measuredData_ , const SCIRun::Core::Datatypes::DenseMatrix& sourceWeighting_, const SCIRun::Core::Datatypes::DenseMatrix& sensorWeighting_);
virtual SCIRun::Core::Datatypes::DenseMatrix computeInverseSolution( double truncationPoint, bool inverseCalculation) const;
std::vector<double> computeLambdaArray( double lambdaMin, double lambdaMax, int nLambda ) const;
// bool checkInputMatrixSizes(); // DEFINED IN PARENT, MIGHT WANT TO OVERRIDE SOME OTHER TIME
};
}}}}
#endif
| [
"jcollfont@gmail.com"
] | jcollfont@gmail.com |
55635138247157103d9cb8c4d020fbc8b02d260b | dcdd5fe5fa3db4c2455359b34e494df53de88dc3 | /Difficulty1000/1245A.cpp | 1c0be2ab7e9bf84232d3598650d21120619a0b29 | [] | no_license | tetat/Codeforces-Problems-Sol | 8a0dbf68f2d8b4a5ce56db2fa7a2b3ff14b5ecb1 | a66d40d84a2842fc6bab83e9c5aa6875b096f767 | refs/heads/main | 2023-06-06T05:19:54.311565 | 2021-06-25T03:05:32 | 2021-06-25T03:05:32 | 369,604,595 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 813 | cpp | /// Problem Name: Good ol' Numbers Coloring
/// Problem Link: https://codeforces.com/problemset/problem/1245/A
/**
* winners never quit
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define II int, int
#define IS int, string
#define SI string, int
#define SS string, string
#define ull unsigned long long
#define all(X) X.begin(), X.end()
#define set_point(pnt) cout<<fixed<<setprecision(pnt);
const double pi = acos(-1.0);
const int N = 500;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int tc, ca = 0;
cin >> tc;
while (tc--){
int a, b;
cin >> a >> b;
if (__gcd(a, b) == 1)cout << "finite" << '\n';
else cout << "infinite" << '\n';
}
return 0;
}
| [
"noreply@github.com"
] | tetat.noreply@github.com |
a644175da0d470481361bfc52abf64e1efe272db | 1653acd0b8a476b55128b9af60c74366cc730568 | /2018-1/msgs/p4tags.cc | e40ea03df8bcd3768a563adcdc50c78f986b29dd | [
"LicenseRef-scancode-unknown-license-reference",
"BSD-2-Clause"
] | permissive | sgtest/p4test | 5c6ab62098e99413af8ee12b5911ad9cf7fc081e | 0b065a1f4aad902f5860d03fa44d14e00ee980a4 | refs/heads/master | 2020-04-27T16:46:05.018649 | 2019-02-07T10:04:05 | 2019-02-07T10:04:05 | 174,492,667 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 23,403 | cc | /*
* Copyright 1995, 2000 Perforce Software. All rights reserved.
*
* This file is part of Perforce - the FAST SCM System.
*/
/*
* P4Tags.cc - definition of rpc variable names
*/
# include <p4tags.h>
const char P4Tag::c_Ack[] = "client-Ack";
const char P4Tag::c_AckMatch[] = "client-AckMatch";
const char P4Tag::c_ActionResolve[] = "client-ActionResolve";
const char P4Tag::c_CheckFile[] = "client-CheckFile";
const char P4Tag::c_ReconcileEdit[] = "client-ReconcileEdit";
const char P4Tag::c_ChmodFile[] = "client-ChmodFile";
const char P4Tag::c_CloseDiff[] = "client-CloseDiff";
const char P4Tag::c_CloseFile[] = "client-CloseFile";
const char P4Tag::c_CloseMatch[] = "client-CloseMatch";
const char P4Tag::c_CloseMerge[] = "client-CloseMerge";
const char P4Tag::c_ConvertFile[] = "client-ConvertFile";
const char P4Tag::c_Crypto[] = "client-Crypto";
const char P4Tag::c_DeleteFile[] = "client-DeleteFile";
const char P4Tag::c_EditData[] = "client-EditData";
const char P4Tag::c_ErrorPause[] = "client-ErrorPause";
const char P4Tag::c_FstatInfo[] = "client-FstatInfo";
const char P4Tag::c_FstatPartial[] = "client-FstatPartial";
const char P4Tag::c_HandleError[] = "client-HandleError";
const char P4Tag::c_InputData[] = "client-InputData";
const char P4Tag::c_Message[] = "client-Message";
const char P4Tag::c_OpenDiff[] = "client-OpenDiff";
const char P4Tag::c_OpenFile[] = "client-OpenFile";
const char P4Tag::c_OpenMatch[] = "client-OpenMatch";
const char P4Tag::c_OpenMerge2[] = "client-OpenMerge2";
const char P4Tag::c_OpenMerge3[] = "client-OpenMerge3";
const char P4Tag::c_OutputBinary[] = "client-OutputBinary";
const char P4Tag::c_OutputData[] = "client-OutputData";
const char P4Tag::c_OutputError[] = "client-OutputError";
const char P4Tag::c_OutputInfo[] = "client-OutputInfo";
const char P4Tag::c_OutputText[] = "client-OutputText";
const char P4Tag::c_Ping[] = "client-Ping";
const char P4Tag::c_Progress[] = "client-Progress";
const char P4Tag::c_Prompt[] = "client-Prompt";
const char P4Tag::c_MoveFile[] = "client-MoveFile";
const char P4Tag::c_ReconcileAdd[] = "client-ReconcileAdd";
const char P4Tag::c_ReconcileFlush[] = "client-ReconcileFlush";
const char P4Tag::c_ReceiveFiles[] = "client-ReceiveFiles";
const char P4Tag::c_ExactMatch[] = "client-ExactMatch";
const char P4Tag::c_ScanDir[] = "client-ScanDir";
const char P4Tag::c_SendFile[] = "client-SendFile";
const char P4Tag::c_SetPassword[] = "client-SetPassword";
const char P4Tag::c_SSO[] = "client-SSO";
const char P4Tag::c_WriteDiff[] = "client-WriteDiff";
const char P4Tag::c_WriteFile[] = "client-WriteFile";
const char P4Tag::c_WriteMatch[] = "client-WriteMatch";
const char P4Tag::c_WriteMerge[] = "client-WriteMerge";
const char P4Tag::p_compress1[] = "compress1";
const char P4Tag::p_compress2[] = "compress2";
const char P4Tag::p_echo[] = "echo";
const char P4Tag::p_errorHandler[] = "errorHandler";
const char P4Tag::p_flush1[] = "flush1";
const char P4Tag::p_flush2[] = "flush2";
const char P4Tag::p_funcHandler[] = "funcHandler";
const char P4Tag::p_protocol[] = "protocol";
const char P4Tag::p_release[] = "release";
const char P4Tag::p_release2[] = "release2";
// These should be client known variables
const char P4Tag::v_actionOwner[] = "actionOwner";
const char P4Tag::v_action[] = "action";
const char P4Tag::v_api[] = "api";
const char P4Tag::v_app[] = "app";
const char P4Tag::v_appliedJnl[] = "appliedJnl";
const char P4Tag::v_appliedPos[] = "appliedPos";
const char P4Tag::v_andmap[] = "andmap";
const char P4Tag::v_attack[] = "attack";
const char P4Tag::v_attr[] = "attr";
const char P4Tag::v_authServer[] = "authServer";
const char P4Tag::v_autoLogin[] = "autoLogin";
const char P4Tag::v_autoTune[] = "autoTune";
const char P4Tag::v_baseName[] = "baseName";
const char P4Tag::v_bits[] = "bits";
const char P4Tag::v_blob[] = "blob";
const char P4Tag::v_blockCount[] = "blockCount";
const char P4Tag::v_branch[] = "branch";
const char P4Tag::v_broker[] = "broker";
const char P4Tag::v_archiveFile[] = "archiveFile";
const char P4Tag::v_caddr[] = "caddr";
const char P4Tag::v_caseHandling[] = "caseHandling";
const char P4Tag::v_change[] = "change";
const char P4Tag::v_changeIdentity[] = "changeIdentity";
const char P4Tag::v_changeImportedBy[] = "changeImportedBy";
const char P4Tag::v_changeServer[] = "changeServer";
const char P4Tag::v_changeType[] = "changeType";
const char P4Tag::v_charset[] = "charset";
const char P4Tag::v_checkpoint[] = "checkpoint";
const char P4Tag::v_checkLinks[] = "checkLinks";
const char P4Tag::v_checkLinksN[] = "checkLinksN";
const char P4Tag::v_clientAddress[] = "clientAddress";
const char P4Tag::v_clientCase[] = "clientCase";
const char P4Tag::v_clientCwd[] = "clientCwd";
const char P4Tag::v_clientFile[] = "clientFile";
const char P4Tag::v_clientHost[] = "clientHost";
const char P4Tag::v_clientName[] = "clientName";
const char P4Tag::v_clientRoot[] = "clientRoot";
const char P4Tag::v_clientStream[] = "clientStream";
const char P4Tag::v_client[] = "client";
const char P4Tag::v_cmpfile[] = "cmpfile";
const char P4Tag::v_code[] = "code";
const char P4Tag::v_commit[] = "commit";
const char P4Tag::v_commitAuthor[] = "author";
const char P4Tag::v_commitAuthorEmail[] = "authorEmail";
const char P4Tag::v_commits[] = "commits";
const char P4Tag::v_committer[] = "committer";
const char P4Tag::v_committerEmail[] = "committerEmail";
const char P4Tag::v_committerDate[] = "committerDate";
const char P4Tag::v_compare[] = "compare";
const char P4Tag::v_confirm[] = "confirm";
const char P4Tag::v_counter[] = "counter";
const char P4Tag::v_current[] = "current";
const char P4Tag::v_cwd[] = "cwd";
const char P4Tag::v_daddr[] = "daddr";
const char P4Tag::v_data[] = "data";
const char P4Tag::v_data2[] = "data2";
const char P4Tag::v_date[] = "date";
const char P4Tag::v_dbstat[] = "dbstat";
const char P4Tag::v_decline[] = "decline";
const char P4Tag::v_depotTime[] = "depotTime";
const char P4Tag::v_desc[] = "desc";
const char P4Tag::v_descKey[] = "oldChange";
const char P4Tag::v_dhash[] = "dhash";
const char P4Tag::v_diffFlags[] = "diffFlags";
const char P4Tag::v_digest[] = "digest";
const char P4Tag::v_digestType[] = "digestType";
const char P4Tag::v_digestTypeMD5[] = "md5";
const char P4Tag::v_digestTypeGitText[] = "GitText";
const char P4Tag::v_digestTypeGitBinary[] = "GitBinary";
const char P4Tag::v_digestTypeSHA256[] = "sha256";
const char P4Tag::v_dir[] = "dir";
const char P4Tag::v_enableGraph[] = "enableGraph";
const char P4Tag::v_enableStreams[] = "enableStreams";
const char P4Tag::v_endFromRev[] = "endFromRev";
const char P4Tag::v_endToRev[] = "endToRev";
const char P4Tag::v_erev[] = "erev";
const char P4Tag::v_expandAndmaps[] = "expandAndmaps";
const char P4Tag::v_externalAuth[] = "externalAuth";
const char P4Tag::v_extraTag[] = "extraTag";
const char P4Tag::v_extraTagType[] = "extraTagType";
const char P4Tag::v_fatal[] = "fatal";
const char P4Tag::v_fileCount[] = "fileCount";
const char P4Tag::v_fileNum[] = "fileNum";
const char P4Tag::v_fileSize[] = "fileSize";
const char P4Tag::v_file[] = "file";
const char P4Tag::v_filter[] = "filter";
const char P4Tag::v_fmt[] = "fmt";
const char P4Tag::v_forceType[] = "forceType";
const char P4Tag::v_fromFile[] = "fromFile";
const char P4Tag::v_fromRev[] = "fromRev";
const char P4Tag::v_fseq[] = "fseq";
const char P4Tag::v_func[] = "func";
const char P4Tag::v_func2[] = "func2";
const char P4Tag::v_handle[] = "handle";
const char P4Tag::v_haveRev[] = "haveRev";
const char P4Tag::v_headAction[] = "headAction";
const char P4Tag::v_headChange[] = "headChange";
const char P4Tag::v_headCharset[] = "headCharset";
const char P4Tag::v_headContent[] = "headContent";
const char P4Tag::v_headModTime[] = "headModTime";
const char P4Tag::v_headRev[] = "headRev";
const char P4Tag::v_headTime[] = "headTime";
const char P4Tag::v_headType[] = "headType";
const char P4Tag::v_himark[] = "himark";
const char P4Tag::v_host[] = "host";
const char P4Tag::v_how[] = "how";
const char P4Tag::v_ignore[] = "ignore";
const char P4Tag::v_initroot[] = "initroot";
const char P4Tag::v_isgroup[] = "isgroup";
const char P4Tag::v_journalcopyFlags[] = "journalcopyFlags";
const char P4Tag::v_job[] = "job";
const char P4Tag::v_jobstat[] = "jobstat";
const char P4Tag::v_jnlBatchSize[] = "jnlBatchSize";
const char P4Tag::v_journal[] = "journal";
const char P4Tag::v_key[] = "key";
const char P4Tag::v_language[] = "language";
const char P4Tag::v_lbrFile[] = "lbrFile";
const char P4Tag::v_lbrRev[] = "lbrRev";
const char P4Tag::v_lbrType[] = "lbrType";
const char P4Tag::v_lbrReplication[] = "lbr.replication";
const char P4Tag::v_leof_num[] = "leofNum";
const char P4Tag::v_leof_sequence[] = "leofSequence";
const char P4Tag::v_ldap[] = "ldap";
const char P4Tag::v_ldapAuth[] = "ldapAuth";
const char P4Tag::v_level[] = "level";
const char P4Tag::v_lfmt[] = "lfmt";
const char P4Tag::v_line[] = "line";
const char P4Tag::v_lower[] = "lower";
const char P4Tag::v_mangle[] = "mangle";
const char P4Tag::v_matchedLine[] = "matchedLine";
const char P4Tag::v_matchBegin[] = "matchBegin";
const char P4Tag::v_matchEnd[] = "matchEnd";
const char P4Tag::v_maxLockTime[] = "maxLockTime";
const char P4Tag::v_maxOpenFiles[] = "maxOpenFiles";
const char P4Tag::v_maxResults[] = "maxResults";
const char P4Tag::v_maxScanRows[] = "maxScanRows";
const char P4Tag::v_mergeAuto[] = "mergeAuto";
const char P4Tag::v_mergeConfirm[] = "mergeConfirm";
const char P4Tag::v_mergeDecline[] = "mergeDecline";
const char P4Tag::v_mergeHow[] = "mergeHow";
const char P4Tag::v_mergePerms[] = "mergePerms";
const char P4Tag::v_minClient[] = "minClient";
const char P4Tag::v_mode[] = "mode";
const char P4Tag::v_monitor[] = "monitor";
const char P4Tag::v_name[] = "name";
const char P4Tag::v_newServerId[] = "newServerId";
const char P4Tag::v_noBase[] = "noBase";
const char P4Tag::v_nocase[] = "nocase";
const char P4Tag::v_noclobber[] = "noclobber";
const char P4Tag::v_noecho[] = "noecho";
const char P4Tag::v_noprompt[] = "noprompt";
const char P4Tag::v_offset[] = "offset";
const char P4Tag::v_oid[] = "oid";
const char P4Tag::v_op[] = "op";
const char P4Tag::v_open[] = "open";
const char P4Tag::v_os[] = "os";
const char P4Tag::v_otherAction[] = "otherAction";
const char P4Tag::v_otherChange[] = "otherChange";
const char P4Tag::v_otherLock[] = "otherLock";
const char P4Tag::v_otherOpen[] = "otherOpen";
const char P4Tag::v_ourLock[] = "ourLock";
const char P4Tag::v_packName[] = "packName";
const char P4Tag::v_parent[] = "parent";
const char P4Tag::v_password[] = "password";
const char P4Tag::v_path[] = "path";
const char P4Tag::v_path2[] = "path2";
const char P4Tag::v_peeking[] = "peeking";
const char P4Tag::v_perm[] = "perm";
const char P4Tag::v_permmax[] = "permMax";
const char P4Tag::v_perms[] = "perms";
const char P4Tag::v_port[] = "port";
const char P4Tag::v_preview[] = "preview";
const char P4Tag::v_prog[] = "prog";
const char P4Tag::v_progress[] = "progress";
const char P4Tag::v_proxy[] = "proxy";
const char P4Tag::v_proxyAddress[] = "proxyAddress";
const char P4Tag::v_proxyEncryption[] = "proxyEncryption";
const char P4Tag::v_proxyCertExpires[] = "proxyCertExpires";
const char P4Tag::v_proxyRoot[] = "proxyRoot";
const char P4Tag::v_proxyVersion[] = "proxyVersion";
const char P4Tag::v_purge[] = "purge";
const char P4Tag::v_pusher[] = "pusher";
const char P4Tag::v_rActionType[] = "rActionType";
const char P4Tag::v_rActionMerge[] = "rActionMerge";
const char P4Tag::v_rActionTheirs[] = "rActionTheirs";
const char P4Tag::v_rActionYours[] = "rActionYours";
const char P4Tag::v_rAutoResult[] = "rAutoResult";
const char P4Tag::v_rOptAuto[] = "rOptAuto";
const char P4Tag::v_rOptHelp[] = "rOptHelp";
const char P4Tag::v_rOptMerge[] = "rOptMerge";
const char P4Tag::v_rOptSkip[] = "rOptSkip";
const char P4Tag::v_rOptTheirs[] = "rOptTheirs";
const char P4Tag::v_rOptYours[] = "rOptYours";
const char P4Tag::v_rPromptMerge[] = "rPromptMerge";
const char P4Tag::v_rPromptTheirs[] = "rPromptTheirs";
const char P4Tag::v_rPromptType[] = "rPromptType";
const char P4Tag::v_rPromptYours[] = "rPromptYours";
const char P4Tag::v_rUserError[] = "rUserError";
const char P4Tag::v_rUserHelp[] = "rUserHelp";
const char P4Tag::v_rUserPrompt[] = "rUserPrompt";
const char P4Tag::v_rUserResult[] = "rUserResult";
const char P4Tag::v_rcvbuf[] = "rcvbuf";
const char P4Tag::v_reason[] = "reason";
const char P4Tag::v_ref[] = "ref";
const char P4Tag::v_remap[] = "remap";
const char P4Tag::v_remoteFunc[] = "remoteFunc";
const char P4Tag::v_remoteMap[] = "remoteMap";
const char P4Tag::v_remoteRange[] = "remoteRange";
const char P4Tag::v_repo[] = "repo";
const char P4Tag::v_repoName[] = "repoName";
const char P4Tag::v_reresolvable[] = "reresolvable";
const char P4Tag::v_resolved[] = "resolved";
const char P4Tag::v_resolveFlag[] = "resolveFlag";
const char P4Tag::v_resolveType[] = "resolveType";
const char P4Tag::v_rev[] = "rev";
const char P4Tag::v_rev2[] = "rev2";
const char P4Tag::v_rmdir[] = "rmdir";
const char P4Tag::v_rseq[] = "rseq";
const char P4Tag::v_scanSize[] = "scanSize";
const char P4Tag::v_scope[] = "scope";
const char P4Tag::v_secondFactor[] = "secondFactor";
const char P4Tag::v_security[] = "security";
const char P4Tag::v_sendspec[] = "sendspec";
const char P4Tag::v_sndbuf[] = "sndbuf";
const char P4Tag::v_sequence[] = "sequence";
const char P4Tag::v_server2[] = "server2";
const char P4Tag::v_server[] = "server";
const char P4Tag::v_serverID[] = "serverID";
const char P4Tag::v_serverAddress[] = "serverAddress";
const char P4Tag::v_serverCluster[] = "serverCluster";
const char P4Tag::v_serverDescription[] = "serverDescription";
const char P4Tag::v_serverDate[] = "serverDate";
const char P4Tag::v_serverEncryption[] = "serverEncryption";
const char P4Tag::v_serverCertExpires[] = "serverCertExpires";
const char P4Tag::v_serverName[] = "serverName";
const char P4Tag::v_serverRoot[] = "serverRoot";
const char P4Tag::v_serverType[] = "serverType";
const char P4Tag::v_serverUptime[] = "serverUptime";
const char P4Tag::v_serverLicense[] = "serverLicense";
const char P4Tag::v_serverLicenseIp[] = "serverLicense-ip";
const char P4Tag::v_serverVersion[] = "serverVersion";
const char P4Tag::v_sha[] = "sha";
const char P4Tag::v_showAll[] = "showAll";
const char P4Tag::v_size[] = "size";
const char P4Tag::v_specdef[] = "specdef"; // 97.3
const char P4Tag::v_specstring[] = "specstring";
const char P4Tag::v_specFormatted[] = "specFormatted";
const char P4Tag::v_srev[] = "srev";
const char P4Tag::v_sso[] = "sso";
const char P4Tag::v_startFromRev[] = "startFromRev";
const char P4Tag::v_startToRev[] = "startToRev";
const char P4Tag::v_stat[] = "stat";
const char P4Tag::v_status[] = "status";
const char P4Tag::v_svrname[] = "svrname";
const char P4Tag::v_symref[] = "symref";
const char P4Tag::v_tableexcludelist[] = "tableexcludelist";
const char P4Tag::v_tag[] = "tag";
const char P4Tag::v_tagJnl[] = "tagjnl";
const char P4Tag::v_targetSha[] = "targetSha";
const char P4Tag::v_targetType[] = "targetType";
const char P4Tag::v_theirName[] = "theirName";
const char P4Tag::v_theirTime[] = "theirTime";
const char P4Tag::v_time[] = "time";
const char P4Tag::v_toFile[] = "toFile";
const char P4Tag::v_token[] = "token";
const char P4Tag::v_token2[] = "token2";
const char P4Tag::v_total[] = "total";
const char P4Tag::v_totalFileCount[] = "totalFileCount";
const char P4Tag::v_totalFileSize[] = "totalFileSize";
const char P4Tag::v_track[] = "track"; // 2005.2
const char P4Tag::v_trans[] = "trans"; // 2001.2
const char P4Tag::v_tree[] = "tree";
const char P4Tag::v_truncate[] = "truncate";
const char P4Tag::v_type[] = "type";
const char P4Tag::v_type2[] = "type2";
const char P4Tag::v_type3[] = "type3";
const char P4Tag::v_type4[] = "type4";
const char P4Tag::v_unicode[] = "unicode";
const char P4Tag::v_unmap[] = "unmap";
const char P4Tag::v_unresolved[] = "unresolved";
const char P4Tag::v_upper[] = "upper";
const char P4Tag::v_user[] = "user";
const char P4Tag::v_userChanged[] = "userChanged";
const char P4Tag::v_userName[] = "userName";
const char P4Tag::v_version[] = "version";
const char P4Tag::v_warning[] = "warning";
const char P4Tag::v_wingui[] = "wingui";
const char P4Tag::v_workRev[] = "workRev";
const char P4Tag::v_write[] = "write";
const char P4Tag::v_xfiles[] = "xfiles";
const char P4Tag::v_yourName[] = "yourName";
// These should be the server-to-server or server-to-proxy variables
const char P4Tag::v_allTamperCheck[] = "allTamperCheck";
const char P4Tag::v_altArg[] = "altArg";
const char P4Tag::v_altArg2[] = "altArg2";
const char P4Tag::v_altArg3[] = "altArg3";
const char P4Tag::v_arg[] = "arg";
const char P4Tag::v_asBinary[] = "asBinary";
const char P4Tag::v_attrib[] = "attrib";
const char P4Tag::v_author[] = "Author";
const char P4Tag::v_bkupInterval[] ="bkupInterval";
const char P4Tag::v_baseDepotRec[] = "baseDepotRec";
const char P4Tag::v_changeNo[] = "changeNo";
const char P4Tag::v_checkSum[] = "checkSum";
const char P4Tag::v_clientEntity[] = "clientEntity";
const char P4Tag::v_confirm2[] = "confirm2";
const char P4Tag::v_dataHandle[] = "dataHandle";
const char P4Tag::v_delete[] = "delete";
const char P4Tag::v_depotFile[] = "depotFile";
const char P4Tag::v_depotFile2[] = "depotFile2";
const char P4Tag::v_depotName[] = "depotName";
const char P4Tag::v_depotRec[] = "depotRec";
const char P4Tag::v_do[] = "do";
const char P4Tag::v_doForce[] = "doForce";
const char P4Tag::v_doPromote[] = "doPromote";
const char P4Tag::v_fixStatus[] = "fixStatus";
const char P4Tag::v_force[] = "force";
const char P4Tag::v_getFlag[] = "getFlag";
const char P4Tag::v_haveRec[] = "haveRec";
const char P4Tag::v_haveGRec[] = "haveGRec";
const char P4Tag::v_ignoreIsEdit[] = "ignoreIsEdit";
const char P4Tag::v_index[] = "index";
const char P4Tag::v_integRec[] = "integRec";
const char P4Tag::v_integRec2[] = "integRec2";
const char P4Tag::v_ipaddr[] = "ipaddr";
const char P4Tag::v_keyVal[] = "keyVal";
const char P4Tag::v_labelEntity[] = "labelEntity";
const char P4Tag::v_leaveUnchanged[] = "leaveUnchanged";
const char P4Tag::v_lockAll[] = "lockAll";
const char P4Tag::v_message[] = "message";
const char P4Tag::v_message2[] = "message2";
const char P4Tag::v_movedFile[] = "movedFile";
const char P4Tag::v_movedRev[] = "movedRev";
const char P4Tag::v_noretry[] = "noretry";
const char P4Tag::v_peer[] = "peer";
const char P4Tag::v_peerAddress[] = "peerAddress";
const char P4Tag::v_propigate[] = "propigate";
const char P4Tag::v_replace[] = "replace";
const char P4Tag::v_reopen[] = "reopen";
const char P4Tag::v_revertUnchanged[] = "revertUnchanged";
const char P4Tag::v_revRec[] = "revRec";
const char P4Tag::v_revGRec[] = "revGRec";
const char P4Tag::v_revtime[] = "revtime";
const char P4Tag::v_revver[] = "revver";
const char P4Tag::v_revgver[] = "revgver";
const char P4Tag::v_role[] = "role";
const char P4Tag::v_save[] = "save";
const char P4Tag::v_setViews[] = "setViews"; // set client views even if empty
const char P4Tag::v_shelved[] = "shelved";
const char P4Tag::v_shelveFile[] = "shelveFile";
const char P4Tag::v_state[] = "state";
const char P4Tag::v_table[] = "table";
const char P4Tag::v_traitCount[] = "traitCount";
const char P4Tag::v_tzoffset[] = "tzoffset";
const char P4Tag::v_output[] = "output";
const char P4Tag::v_unloadInterval[] = "unloadInterval";
const char P4Tag::v_value[] = "value";
const char P4Tag::v_workRec[] = "workRec";
const char P4Tag::v_workRec2[] = "workRec2";
const char P4Tag::v_workGRec[] = "workGRec";
const char P4Tag::v_yourDepotRec[] = "yourDepotRec";
const char P4Tag::v_zksEntity[] = "zksEntity";
const char P4Tag::u_add[] = "add";
const char P4Tag::u_admin[] = "admin";
const char P4Tag::u_branch[] = "branch";
const char P4Tag::u_branches[] = "branches";
const char P4Tag::u_change[] = "change";
const char P4Tag::u_changes[] = "changes";
const char P4Tag::u_client[] = "client";
const char P4Tag::u_clients[] = "clients";
const char P4Tag::u_counter[] = "counter";
const char P4Tag::u_counters[] = "counters";
const char P4Tag::u_delete[] = "delete";
const char P4Tag::u_depot[] = "depot";
const char P4Tag::u_depots[] = "depots";
const char P4Tag::u_describe[] = "describe";
const char P4Tag::u_diff[] = "diff" ;
const char P4Tag::u_diff2[] = "diff2";
const char P4Tag::u_dirs[] = "dirs" ;
const char P4Tag::u_edit[] = "edit" ;
const char P4Tag::u_fetch[] = "fetch";
const char P4Tag::u_filelog[] = "filelog";
const char P4Tag::u_files[] = "files";
const char P4Tag::u_fix[] = "fix";
const char P4Tag::u_fixes[] = "fixes";
const char P4Tag::u_flush[] = "flush";
const char P4Tag::u_fstat[] = "fstat";
const char P4Tag::u_group[] = "group";
const char P4Tag::u_groups[] = "groups";
const char P4Tag::u_have[] = "have";
const char P4Tag::u_help[] = "help";
const char P4Tag::u_info[] = "info";
const char P4Tag::u_integrate[] = "integrate";
const char P4Tag::u_integrated[] = "integrated";
const char P4Tag::u_job[] = "job";
const char P4Tag::u_jobs[] = "jobs";
const char P4Tag::u_jobspec[] = "jobspec";
const char P4Tag::u_label[] = "label";
const char P4Tag::u_labels[] = "labels";
const char P4Tag::u_labelsync[] = "labelsync";
const char P4Tag::u_lock[] = "lock";
const char P4Tag::u_obliterate[] = "obliterate";
const char P4Tag::u_opened[] = "opened";
const char P4Tag::u_passwd[] = "passwd";
const char P4Tag::u_print[] = "print";
const char P4Tag::u_protect[] = "protect";
const char P4Tag::u_push[] = "push";
const char P4Tag::u_reconcile[] = "reconcile";
const char P4Tag::u_remote[] = "remote";
const char P4Tag::u_remotes[] = "remotes";
const char P4Tag::u_rename[] = "rename";
const char P4Tag::u_reopen[] = "reopen";
const char P4Tag::u_resolve[] = "resolve";
const char P4Tag::u_resolved[] = "resolved";
const char P4Tag::u_resubmit[] = "resubmit";
const char P4Tag::u_revert[] = "revert";
const char P4Tag::u_review[] = "review";
const char P4Tag::u_reviews[] = "reviews";
const char P4Tag::u_set[] = "set";
const char P4Tag::u_stream[] = "stream";
const char P4Tag::u_streams[] = "streams";
const char P4Tag::u_submit[] = "submit";
const char P4Tag::u_switch[] = "switch";
const char P4Tag::u_sync[] = "sync";
const char P4Tag::u_triggers[] = "triggers";
const char P4Tag::u_typemap[] = "typemap";
const char P4Tag::u_undo[] = "undo";
const char P4Tag::u_unlock[] = "unlock";
const char P4Tag::u_unsubmit[] = "unsubmit";
const char P4Tag::u_unzip[] = "unzip";
const char P4Tag::u_user[] = "user";
const char P4Tag::u_users[] = "users";
const char P4Tag::u_verify[] = "verify";
const char P4Tag::u_where[] = "where";
const char P4Tag::u_zip[] = "zip";
// server-p4zk message fields
const char P4Tag::z_clusterid[] = "clusterid";
const char P4Tag::z_clusterrole[] = "clusterrole";
const char P4Tag::z_genNum[] = "generationNum";
const char P4Tag::z_jnlnum[] = "journalnumber";
const char P4Tag::z_jnloffst[] = "journaloffset";
const char P4Tag::z_p4port[] = "p4port";
const char P4Tag::z_p4target[] = "p4target";
const char P4Tag::z_pid[] = "pid";
const char P4Tag::z_serverid[] = "serverid";
const char P4Tag::z_zkhostport[] = "zkhostport";
const char P4Tag::z_zkconnecttime[] = "zkconnecttime";
const char P4Tag::z_brokercfg[] = "brokercfg";
| [
"nickpoole@black-sphere.co.uk"
] | nickpoole@black-sphere.co.uk |
075fdf44adb51335a225c1fa3475743aea37d29e | 61b3f1b5512e4f09cda4e2a9aa85bc90cbea2f34 | /1-getting-started/lessons/4-connect-internet/code-telemetry/wio-terminal/nightlight/src/main.cpp | 5bf64b3ed76fbeafebf261d6f1620c0dcb11c193 | [
"MIT"
] | permissive | erickarugu/IoT-For-Beginners | 027f91eaf3b21dea36740f13ea63cfc4a9234470 | ba7100d0a0a88a54bb9b54ba4ae22b348fdc737a | refs/heads/main | 2023-06-20T14:27:53.073058 | 2021-07-22T15:13:39 | 2021-07-22T15:13:39 | 388,538,972 | 1 | 0 | MIT | 2021-07-22T17:54:57 | 2021-07-22T17:05:56 | null | UTF-8 | C++ | false | false | 1,567 | cpp | #include <Arduino.h>
#include <ArduinoJSON.h>
#include <PubSubClient.h>
#include <rpcWiFi.h>
#include <SPI.h>
#include "config.h"
void connectWiFi()
{
while (WiFi.status() != WL_CONNECTED)
{
Serial.println("Connecting to WiFi..");
WiFi.begin(SSID, PASSWORD);
delay(500);
}
Serial.println("Connected!");
}
WiFiClient wioClient;
PubSubClient client(wioClient);
void reconnectMQTTClient()
{
while (!client.connected())
{
Serial.print("Attempting MQTT connection...");
if (client.connect(CLIENT_NAME.c_str()))
{
Serial.println("connected");
}
else
{
Serial.print("Retying in 5 seconds - failed, rc=");
Serial.println(client.state());
delay(5000);
}
}
}
void createMQTTClient()
{
client.setServer(BROKER.c_str(), 1883);
reconnectMQTTClient();
}
void setup()
{
Serial.begin(9600);
while (!Serial)
; // Wait for Serial to be ready
delay(1000);
pinMode(WIO_LIGHT, INPUT);
pinMode(D0, OUTPUT);
connectWiFi();
createMQTTClient();
}
void loop()
{
reconnectMQTTClient();
client.loop();
int light = analogRead(WIO_LIGHT);
DynamicJsonDocument doc(1024);
doc["light"] = light;
string telemetry;
JsonObject obj = doc.as<JsonObject>();
serializeJson(obj, telemetry);
Serial.print("Sending telemetry ");
Serial.println(telemetry.c_str());
client.publish(CLIENT_TELEMETRY_TOPIC.c_str(), telemetry.c_str());
delay(2000);
} | [
"noreply@github.com"
] | erickarugu.noreply@github.com |
6e66ef8515f89235541de463c6a6d858f7879caa | e7f19f64d1523e701dd4fa9f09d09b018d93a8dd | /TouchGFX/gui/include/gui/climate_screen_screen/Climate_screenPresenter.hpp | de770ad226bcc41514d549083ae618882213daae | [] | no_license | EmbeddedSystemClass/STM32F7_Meteo_TouchGFX | 45c19700fb05730f7ba0dd03f1c51e850d8ce3f9 | 597919b0fa9ff15e8cd43d32f58ac638c5230e4c | refs/heads/master | 2022-04-05T21:45:48.828978 | 2020-03-04T05:45:29 | 2020-03-04T05:45:29 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,192 | hpp | #ifndef CLIMATE_SCREENPRESENTER_HPP
#define CLIMATE_SCREENPRESENTER_HPP
#include <gui/model/ModelListener.hpp>
#include <mvp/Presenter.hpp>
using namespace touchgfx;
class Climate_screenView;
class Climate_screenPresenter : public touchgfx::Presenter, public ModelListener
{
public:
Climate_screenPresenter(Climate_screenView& v);
/**
* The activate function is called automatically when this screen is "switched in"
* (ie. made active). Initialization logic can be placed here.
*/
virtual void activate();
/**
* The deactivate function is called automatically when this screen is "switched out"
* (ie. made inactive). Teardown functionality can be placed here.
*/
virtual void deactivate();
virtual ~Climate_screenPresenter() {};
uint16_t getTempMantissa (void){
return model->getTempMantissa();
}
uint16_t getTempFraction (void){
return model->getTempFraction();
}
uint8_t getHumidity()
{
return model->getHumidity();
}
private:
Climate_screenPresenter();
Climate_screenView& view;
};
#endif // CLIMATE_SCREENPRESENTER_HPP
| [
"ALSCode@home"
] | ALSCode@home |
71f6575934e7acc7799113690fc623d4b9d17527 | 8b7abc4a71a4bfa488aa0f78b181f05bf0e2ca39 | /DS/Lab4/SELECTIO.CPP | 7ff24bfc045e0e344a98b2d5293b14ff2b720a96 | [] | no_license | itsnavneetk/sem3 | d9a7f37d0466bcd5037f0e81947fe4c53d6270ac | fdef1c43a487660172c3b684e7123c2fe328c3e4 | refs/heads/master | 2021-01-25T07:44:18.047946 | 2017-08-03T05:18:08 | 2017-08-03T05:18:08 | 93,657,894 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 380 | cpp | #include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,j,a[10],small,temp=0,pos=0;
cout<<"Enter n "<<endl;
cin>>n;
for(i=0;i<n;i++){
cin>>a[i];
}
for(i=0;i<n;i++){
small = a[i];
pos =i;
for(j=i+1;j<n;j++){
if(small>a[j]){
pos = j;
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(i=0;i<n;i++){
cout<<a[i]<<" ";
}
getch();
} | [
"itsnavneetk@gmail.com"
] | itsnavneetk@gmail.com |
06d1dd62cf8dad880f14887f3b2191468bacceb3 | f1b64a5f59155bc291f8cf0f53fb741b069f3234 | /final_pkg/src/bumper.cpp | aa4d01089270eefff12e4778463b7a148bbb69e6 | [] | no_license | Matchr19/p1_repository | c9731372db3f44db7b68fd670daf368c435a826d | b7c8d6396d24597cbb3cc754935c3359c4401a7a | refs/heads/master | 2020-08-10T18:10:32.996148 | 2019-12-10T08:25:30 | 2019-12-10T08:25:30 | 214,392,800 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,966 | cpp | #include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <kobuki_msgs/BumperEvent.h>
#include <kobuki_msgs/Led.h>
#include <iostream>
#include <string>
kobuki_msgs::Led LEDmsg;
kobuki_msgs::BumperEvent bumpMsg;
ros::Publisher cmd_vel_pub;
ros::Publisher LED1_pub;
ros::Publisher LED2_pub;
ros::Subscriber bumperSub;
void bump(const kobuki_msgs::BumperEvent &bumpMsg)
{
if (bumpMsg.state == 1)
{
LEDmsg.value = 3;
LED1_pub.publish(LEDmsg);
LED2_pub.publish(LEDmsg);
std::cout << "Robot er kørt ind i noget" << std::endl;
geometry_msgs::Twist twistMsg;
double angularspeed = 0.5;
for (size_t i = 0; i < 13; i++)
{
twistMsg.linear.x = 0.0;
twistMsg.angular.z = angularspeed;
cmd_vel_pub.publish(twistMsg);
}
for (int i = 0; i < 5; i++)
{
twistMsg.linear.x = 0.1;
twistMsg.angular.z = 0.0;
cmd_vel_pub.publish(twistMsg);
ros::Duration(0.5).sleep();
}
for (size_t i = 0; i < 13; i++)
{
twistMsg.linear.x = 0.0;
twistMsg.angular.z = angularspeed;
cmd_vel_pub.publish(twistMsg);
}
ros::Duration(0.5).sleep();
LEDmsg.value = 1;
LED1_pub.publish(LEDmsg);
LED2_pub.publish(LEDmsg);
}
}
int main(int argc, char *argv[])
{
ros::init(argc, argv, "pubsub");
srand(time(NULL));
ros::NodeHandle n;
ros::NodeHandle m;
cmd_vel_pub = n.advertise<geometry_msgs::Twist>
("/cmd_vel_mux/input/teleop", 1);
LED1_pub = n.advertise<kobuki_msgs::Led>
("/mobile_base/commands/led1", 1);
LED2_pub = n.advertise<kobuki_msgs::Led>
("/mobile_base/commands/led2", 1);
bumperSub = n.subscribe
("/mobile_base/events/bumper", 1, bump);
while (ros::ok())
{
ros::Duration(0.5).sleep();
ros::spinOnce();
}
return 0;
} | [
"kgrant19@student.aau.dk"
] | kgrant19@student.aau.dk |
84cab0c68ba7b7d4674dc70f379e948938873eae | acb29e5ca1a28f1a0510d6ea7e299fe684ba9ea9 | /SampleGame/Disgaea2/Code/battlemap.h | 229dfe01a62bc383b6acf4a56deb9e53925c27ee | [] | no_license | ZTZEROS/Portfolio | 579aced98885803e1f7d158ecde6db64c4115cff | c65d4d375cdfa7a746d83a81dfa27006e8240ea0 | refs/heads/main | 2023-03-28T11:39:55.575872 | 2021-04-02T00:00:03 | 2021-04-02T00:00:03 | 347,345,688 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,216 | h | #pragma once
#include "gameNode.h"
#include "tileNode.h"
class battlemap : public gameNode
{
private:
tagTile _tiles[TILENUMX][TILENUMY];
tagTile _temp[TILENUMX][TILENUMY];
tagTile tempTile;
POINT _currentTile;
POINT _start;
image* _tileGraass;
image* _tileRock;
image* _tileStones;
image* _tileGraassTop;
image* _tileRockTop;
image* _tileStonesTop;
image* _tileWater;
image* _active;
image* _tileDeepTile;
image* _tileLightTile;
image* _tileGraveTile;
image* _startTile;
image* _obj;
int _cameraX, _cameraY;
int _magicCicleAlpha;
bool _alphaSwitch;
bool _cameraTurn;
bool addObj;
bool addObj2;
bool re;
vector<POINT> OpenableTileV;
vector<POINT>::iterator OpenableTileVI;
vector<tagTile> _vOpenList;
vector<tagTile>::iterator _viOpenList;
vector<POINT> _vPathList;
vector<POINT>::iterator _viPathList;
int OpenableTileVSize;
int PreviousOpenableTileVSize;
public:
HRESULT init(void);
void release(void);
void update();
void render(int i,int j);
bool getCameraTurn() { return _cameraTurn; }
void setCameraTurn(bool turn) { _cameraTurn = turn; }
void cameraTurnRight(int i, int j);
void cameraTurnLeft(int i, int j);
void load(void);
vector<POINT> GetPathsV() { return _vPathList; }
vector<POINT>::iterator GetPathsVI() { return _viPathList; }
vector<POINT>* GetPathsVAddress() { return &_vPathList; }
vector<POINT>::iterator* GetPathsVIAddres() { return &_viPathList; }
vector<POINT> addOpenableTileV(POINT currentTile, int movableDistance, bool loop);
void SearchMovableTile(tagTile tile, POINT currentTile, bool enemy);
void ClearMoveableTile(void);
void SearchAttackableTile(POINT currentTile);
float costAdd(POINT currentTile, POINT endTile);
vector<POINT> pathFinder(POINT currentTile, POINT endTile, int movableDistance);
void onTheTileReset(void);
void clearAllList(void);
battlemap();
~battlemap();
tagTile* getTiles(int x, int y) { return &_tiles[x][y]; }
//tagTile GetTile(int indexX, int indexY) { return _tiles[indexX][indexY]; }
//tagTile* GetTileAddress(int indexX, int indexY) { return &_tiles[indexX][indexY]; }
//
//tagTile GetTiles() { return **_tiles; }
//tagTile* GetTilesAddressA() { return &**_tiles; }
}; | [
"zt00000@naver.com"
] | zt00000@naver.com |
92c0325d2b6c3e5db31bc2a82e208fe44257fac8 | 8d8fa72f7a43266add4446cb86116e62ba23f839 | /test/fixtures/observers.hpp | f17ffb164e51fbf804e348d77848c429fb3fbd8c | [] | no_license | asmr-hex/grid | f82fd8d0584d6f4cdb0a1936507160b4d5644285 | eeb0dbfcab203000c08da11ba9c7fb36b05652df | refs/heads/master | 2023-06-30T05:41:03.009915 | 2021-07-14T21:14:06 | 2021-07-14T21:14:06 | 217,150,100 | 0 | 0 | null | 2021-07-14T21:14:07 | 2019-10-23T20:43:52 | C++ | UTF-8 | C++ | false | false | 1,152 | hpp | #ifndef TEST_FIXTURES_OBSERVERS_H
#define TEST_FIXTURES_OBSERVERS_H
#include <string>
#include <vector>
#include "anemone/io/observer.hpp"
#include "anemone/io/grid/event.hpp"
#include "anemone/io/grid/device/events.hpp"
#include "anemone/rx/observer.hpp"
#include "fixtures/state/composite_state.hpp"
class TestStringObserver : public Observer<std::string> {
public:
virtual void handle(const std::string& event) override {
events.push_back(event);
}
std::vector<std::string> events;
};
class TestGridDeviceEventObserver : public Observer<grid_device_event_t> {
public:
virtual void handle(const grid_device_event_t& event) override {
events.push_back(event);
}
std::vector<grid_device_event_t> events;
};
class TestGridEventObserver : public Observer<grid_event_t> {
public:
virtual void handle(const grid_event_t& event) override {
events.push_back(event);
}
std::vector<grid_event_t> events;
};
namespace fixture {
namespace observer {
namespace rx {
class Simple : public ::rx::Observer {
public:
int count = 0;
bool on = false;
};
}
}
}
#endif
| [
"c@polygon.pizza"
] | c@polygon.pizza |
8293bcaf4320d007f268be4874c27c8299365757 | ddf551357f2f718fbb07ef8843facd38eccde027 | /Lab_5.1/Source.cpp | f4d9d55afdab395399ed22eebdd76a7230621a34 | [] | no_license | Perkhun/Lab_5.0 | 620c5fe8e7be46d527822b0292ca9bdeaa0030c3 | f8af7f11a970dd2f06ea3f2a38b4d15df2b9d063 | refs/heads/master | 2023-08-24T15:15:52.429192 | 2021-10-19T17:52:39 | 2021-10-19T17:52:39 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 426 | cpp | #include <iostream>
#include <cmath>
using namespace std;
double h(const double x, const double y, const double z);
int main()
{
double a, b;
cout << "a= "; cin >> a;
cout << "b= "; cin >> b;
double c = (h (a, b, 1) + h (1, a, b)) / 1 + h (a * a + b * b, 1, 0);
cout << "c = " << c << endl;
return 0;
}
double h(const double x, const double y, const double z)
{
return (x + y + z) / (x * x + y * y + z * z);
}
| [
"Iryna.Perkhun.IT.2021@lpnu.ua"
] | Iryna.Perkhun.IT.2021@lpnu.ua |
85868c34fcb97161f1c90b14883aed6c617338b0 | 44289ecb892b6f3df043bab40142cf8530ac2ba4 | /Sources/Elastos/Frameworks/Droid/Base/Packages/SystemUI/src/elastos/droid/systemui/statusbar/policy/AccessibilityController.cpp | 88d388d9070a32df949bf30b294b92d5d595194c | [
"Apache-2.0"
] | permissive | warrenween/Elastos | a6ef68d8fb699fd67234f376b171c1b57235ed02 | 5618eede26d464bdf739f9244344e3e87118d7fe | refs/heads/master | 2021-01-01T04:07:12.833674 | 2017-06-17T15:34:33 | 2017-06-17T15:34:33 | 97,120,576 | 2 | 1 | null | 2017-07-13T12:33:20 | 2017-07-13T12:33:20 | null | UTF-8 | C++ | false | false | 4,268 | cpp | //=========================================================================
// Copyright (C) 2012 The Elastos Open Source Project
//
// 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 "elastos/droid/systemui/statusbar/policy/AccessibilityController.h"
#include "Elastos.Droid.Content.h"
#include "Elastos.CoreLibrary.IO.h"
#include "Elastos.CoreLibrary.Utility.h"
using Elastos::Droid::View::Accessibility::IAccessibilityManager;
using Elastos::Droid::View::Accessibility::EIID_IAccessibilityManagerAccessibilityStateChangeListener;
using Elastos::Droid::View::Accessibility::EIID_IAccessibilityManagerTouchExplorationStateChangeListener;
using Elastos::Utility::CArrayList;
namespace Elastos {
namespace Droid {
namespace SystemUI {
namespace StatusBar {
namespace Policy {
CAR_INTERFACE_IMPL_3(AccessibilityController, Object, IAccessibilityController \
, IAccessibilityManagerAccessibilityStateChangeListener
, IAccessibilityManagerTouchExplorationStateChangeListener);
AccessibilityController::AccessibilityController(
/* [in] */ IContext* context)
: mAccessibilityEnabled(FALSE)
, mTouchExplorationEnabled(FALSE)
{
CArrayList::New((IArrayList**)&mChangeCallbacks);
AutoPtr<IInterface> obj;
context->GetSystemService(IContext::ACCESSIBILITY_SERVICE, (IInterface**)&obj);
AutoPtr<IAccessibilityManager> am = IAccessibilityManager::Probe(obj);
Boolean tmp = FALSE;
am->AddTouchExplorationStateChangeListener(this, &tmp);
am->AddAccessibilityStateChangeListener(this, &tmp);
am->IsEnabled(&mAccessibilityEnabled);
am->IsTouchExplorationEnabled(&mTouchExplorationEnabled);
}
ECode AccessibilityController::IsAccessibilityEnabled(
/* [out] */ Boolean* enabled)
{
VALIDATE_NOT_NULL(enabled);
*enabled = mAccessibilityEnabled;
return NOERROR;
}
ECode AccessibilityController::IsTouchExplorationEnabled(
/* [out] */ Boolean* enabled)
{
VALIDATE_NOT_NULL(enabled);
*enabled = mTouchExplorationEnabled;
return NOERROR;
}
ECode AccessibilityController::Dump(
/* [in] */ IFileDescriptor* fd,
/* [in] */ IPrintWriter* pw,
/* [in] */ ArrayOf<String>* args)
{
pw->Println(String("AccessibilityController state:"));
pw->Print(String(" mAccessibilityEnabled="));
pw->Println(mAccessibilityEnabled);
pw->Print(String(" mTouchExplorationEnabled="));
pw->Println(mTouchExplorationEnabled);
return NOERROR;
}
ECode AccessibilityController::AddStateChangedCallback(
/* [in] */ IAccessibilityStateChangedCallback* cb)
{
mChangeCallbacks->Add(cb);
cb->OnStateChanged(mAccessibilityEnabled, mTouchExplorationEnabled);
return NOERROR;
}
ECode AccessibilityController::RemoveStateChangedCallback(
/* [in] */ IAccessibilityStateChangedCallback* cb)
{
mChangeCallbacks->Remove(cb);
return NOERROR;
}
void AccessibilityController::FireChanged()
{
Int32 N = 0;
mChangeCallbacks->GetSize(&N);
for (Int32 i = 0; i < N; i++) {
AutoPtr<IInterface> obj;
mChangeCallbacks->Get(i, (IInterface**)&obj);
IAccessibilityStateChangedCallback::Probe(obj)->OnStateChanged(mAccessibilityEnabled
, mTouchExplorationEnabled);
}
}
ECode AccessibilityController::OnAccessibilityStateChanged(
/* [in] */ Boolean enabled)
{
mAccessibilityEnabled = enabled;
FireChanged();
return NOERROR;
}
ECode AccessibilityController::OnTouchExplorationStateChanged(
/* [in] */ Boolean enabled)
{
mTouchExplorationEnabled = enabled;
FireChanged();
return NOERROR;
}
} // namespace Policy
} // namespace StatusBar
} // namespace SystemUI
} // namespace Droid
} // namespace Elastos
| [
"cao.jing@kortide.com"
] | cao.jing@kortide.com |
4c93e7c683ede3aedcc8ffae75d41259935f64be | 89c3868b6228cb9c3d9ccb31721f9b879641a545 | /entities/functions.h | 64cba5e93032fe64c1fe35fe7a3e42852815afd0 | [] | no_license | dronperminov/ModelLang | b118209ff5b0d28a5b2d8fe18bd43ec756c3266a | 256b614f0dc79806ea4dc41932d4e6c3ca3b4218 | refs/heads/master | 2021-09-12T23:10:21.623513 | 2018-04-22T10:53:59 | 2018-04-22T10:53:59 | 109,563,692 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 413 | h | #ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <iostream>
#include <ostream>
#include <string>
#include "../colors.h"
int realLength(std::string s);
void printCenter(std::string msg, int count, const std::string& color = "");
void printCenter(std::ostream &stream, std::string msg, int count, const std::string& color = "");
void printCenterCell(std::string msg, int count, const char* color = "");
#endif | [
"dronperminov@gmail.com"
] | dronperminov@gmail.com |
974fe277f151749e330fbd40c067a35f43dedbff | fd081a9a4621f0964099883b234e32d5ee36c4ff | /Record.h | ca82225dc97d98bb2ba4ef8c73165078cdebdd8e | [] | no_license | srobbins511/Database | f3d968b9a560d936189900efe66b406d89407cf3 | 8843a635ee003495145fce5af3f04f57126877e2 | refs/heads/master | 2020-09-09T00:05:37.111982 | 2019-11-28T06:45:55 | 2019-11-28T06:45:55 | 221,283,765 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 340 | h | #ifndef RECORD_H
#define RECORD_H
#include <iostream>
using namespace std;
class Record
{
public:
bool originStudent;
bool opInsert;
int ID;
std::string info;
Record();
Record(bool student, bool op, int id, std::string information);
~Record();
};
#endif | [
"srobbins@chapman.edu"
] | srobbins@chapman.edu |
3fd6ceddd1ff3aef6f6d2d4ced89ffa1204fb50a | 04251e142abab46720229970dab4f7060456d361 | /lib/rosetta/source/src/basic/TracerImpl.cc | afda5e73092442f23a0f873d5f0286455bd94084 | [] | no_license | sailfish009/binding_affinity_calculator | 216257449a627d196709f9743ca58d8764043f12 | 7af9ce221519e373aa823dadc2005de7a377670d | refs/heads/master | 2022-12-29T11:15:45.164881 | 2020-10-22T09:35:32 | 2020-10-22T09:35:32 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 22,836 | cc | // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
// vi: set ts=2 noet:
//
// (c) Copyright Rosetta Commons Member Institutions.
// (c) This file is part of the Rosetta software suite and is made available under license.
// (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
// (c) For more information, see http://www.rosettacommons.org. Questions about this can be
// (c) addressed to University of Washington CoMotion, email: license@uw.edu.
/// @file src/basic/unti/tracer.cc
/// @brief Tracer IO system
/// @author Sergey Lyskov
/// @author Rocco Moretti (rmorettiase@gmail.com)
#ifdef USEMPI
#include <mpi.h>
#endif
#include <basic/TracerImpl.hh>
#include <ObjexxFCL/string.functions.hh> // for lowercased
#include <algorithm> // for find
#include <cassert> // for assert
#include <cstddef> // for size_t
#include <iosfwd> // for string, ostream
#include <iostream> // for cout, cerr
#include <ostream> // for operator<<, basic_ostream
#include <platform/types.hh> // for Size
#include <string> // for allocator, operator==, basi...
#include <utility>
#include <utility/CSI_Sequence.hh> // for CSI_Sequence, CSI_Black
#include <utility/sys_util.hh> // for timestamp
#include <utility/string_util.hh> // for split, string2int, string_s...
#include <utility/tools/make_vector.hh> // for make_vector
#include <utility/vector1.hh> // for vector1
#include <utility/vectorL.hh> // for vectorL
#include <vector> // for vector, vector<>::iterator
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#ifdef MULTI_THREADED
#include <mutex>
#include <basic/thread_manager/RosettaThreadManager.hh>
#endif
namespace basic {
bool
TracerOptions::operator==( TracerOptions const & other ) const {
return level == other.level &&
print_channel_name == other.print_channel_name &&
timestamp == other.timestamp &&
muted == other.muted &&
unmuted == other.unmuted &&
levels == other.levels;
}
bool
TracerOptions::operator!=( TracerOptions const & other ) const {
return !(*this == other);
}
/////////////////////// TracerImpl //////////////////////////////////////
std::string TracerImpl::output_prefix_;
#ifdef MULTI_THREADED
/// @brief This mutex ensures that any time static data is read from or written to by
/// a tracer object, that the thread gets exclusive access to it.
/// See the TracerImpl datamembers for items which need to be mutex protected
std::mutex & tracer_static_data_mutex() {
// Construct On First Use Idiom, to avoid static initialization order fiasco with static tracers.
// In C++11, static locals are constructed only once, in a threadsafe manner.
static std::mutex * mutex = new std::mutex;
return *mutex;
}
#endif
TracerImpl::OstreamPointer &TracerImpl::final_stream()
{
static std::ostream * final_stream_ = &std::cout;
return final_stream_;
}
void TracerImpl::set_new_final_stream(std::ostream *new_final_stream)
{
if ( dynamic_cast< TracerImpl* >(new_final_stream) != nullptr || dynamic_cast< TracerImpl::TracerProxyImpl* >(new_final_stream) != nullptr ) {
utility_exit_with_message("Error: Setting the final_stream on a Tracer to be another Tracer or a TracerProxy is only going to end in grief! (Try a PyTracer instead.)");
}
final_stream() = new_final_stream;
}
void TracerImpl::set_default_final_stream()
{
final_stream() = &std::cout;
}
otstreamOP &TracerImpl::ios_hook()
{
static otstreamOP hook;
return hook;
}
utility::vector1< std::string > &
TracerImpl::monitoring_list_()
{
static utility::vector1< std::string > monitoring_list;
return monitoring_list;
}
//std::string const TracerImpl::AllChannels("_Really_Unique_String_Object_To_Identify_All_Tracer_Channels__qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM");
std::string const & TracerImpl::get_all_channels_string() {
static std::string const all_channels("_Really_Unique_String_Object_To_Identify_All_Tracer_Channels__qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM");
return all_channels;
}
TracerOptionsOP TracerImpl::tracer_options_;
void TracerImpl::set_tracer_options( TracerOptions const & to) {
#ifdef MULTI_THREADED
std::lock_guard< std::mutex > lock( tracer_static_data_mutex() );
#endif
if ( tracer_options_ && to != *tracer_options_ ) {
// Unit tests reset the options a lot, but it's always with an identical value
std::cout << "[ WARNING ] Resetting the global tracer options, which have already been set." << std::endl;
std::cout << "[ WARNING ] This will not affect Tracers which are already initialized." << std::endl;
}
tracer_options_ = utility::pointer::make_shared< TracerOptions >( to );
}
/// @brief Set whether we're printing the channel name.
/// @details This overrides the *local* setting, but does not alter the *global* setting.
/// @author Vikram K. Mulligan (vmulligan@flatironinstitute.org)
void
TracerImpl::set_local_print_channel_name( bool const setting ) {
local_print_channel_name_ = setting;
}
bool & TracerImpl::super_mute_()
{
static bool mute = false;
return mute;
}
int TracerImpl::mpi_rank_( 0 );
/// @details Static objects holding various ASCII CSI codes (see utility/CSI_Sequence.hh)
utility::CSI_Sequence TracerImpl::Reset(utility::CSI_Reset()), TracerImpl::Bold(utility::CSI_Bold()), TracerImpl::Underline(utility::CSI_Underline()),
TracerImpl::Black(utility::CSI_Black()), TracerImpl::Red(utility::CSI_Red()), TracerImpl::Green(utility::CSI_Green()), TracerImpl::Yellow(utility::CSI_Yellow()), TracerImpl::Blue(utility::CSI_Blue()), TracerImpl::Magenta(utility::CSI_Magenta()), TracerImpl::Cyan(utility::CSI_Cyan()), TracerImpl::White(utility::CSI_White()),
TracerImpl::bgBlack(utility::CSI_bgBlack()), TracerImpl::bgRed(utility::CSI_bgRed()), TracerImpl::bgGreen(utility::CSI_bgGreen()), TracerImpl::bgYellow(utility::CSI_bgYellow()), TracerImpl::bgBlue(utility::CSI_bgBlue()), TracerImpl::bgMagenta(utility::CSI_bgMagenta()), TracerImpl::bgCyan(utility::CSI_bgCyan()), TracerImpl::bgWhite(utility::CSI_bgWhite());
TracerImpl::TracerProxyImpl::TracerProxyImpl(
TracerImpl & tracer,
int priority,
std::string channel
) :
tracer_(tracer),
priority_(priority),
channel_(std::move(channel)),
visible_(true)
{}
void
TracerImpl::TracerProxyImpl::calculate_visibility()
{
bool muted; int mute_level;
TracerImpl::calculate_visibility( channel_, priority_, visible_, muted, mute_level, tracer_.muted_by_default_ );
}
TracerImpl::TracerProxyImpl &
TracerImpl::get_proxy_by_priority( TracerPriority priority) {
if ( priority <= t_fatal ) {
return Fatal;
} else if ( priority <= t_error ) {
return Error;
} else if ( priority <= t_warning ) {
return Warning;
} else if ( priority <= t_info ) {
return Info;
} else if ( priority <= t_debug ) {
return Debug;
} else {
return Trace;
}
}
/// Flush inner buffer: send it to bound Tracer object, and clean it.
void TracerImpl::TracerProxyImpl::t_flush(std::string const & s)
{
int pr = tracer_.priority();
tracer_.priority(priority_);
tracer_ << s;
tracer_.flush();
tracer_.priority(pr);
}
TracerImpl::TracerProxyImpl::~TracerProxyImpl()
{
/// Do nothing here - contents will get flushed in Tracer destructor.
}
/// @details Constructor of Tracer object.
/// Since most of the Tracer object will be created as static - they Constuctor will be called before
/// Option system is initialized. So we can't really calculate any vizibility or priority here.
/// Such calculation should be done later, whe first IO operation happend.
/// @todo Default Tracer level should probably be modified to t_info here and in options defn.
TracerImpl::TracerImpl(std::string const & channel, TracerPriority priority, bool muted_by_default) :
Fatal( *this, t_fatal, channel ),
Error( *this, t_error, channel ),
Warning( *this, t_warning, channel ),
Info( *this, t_info, channel ),
Debug( *this, t_debug, channel ),
Trace( *this, t_trace, channel )
{
init(channel, utility::CSI_Nothing(), utility::CSI_Nothing(), priority, muted_by_default);
}
TracerImpl::TracerImpl(std::string const & channel, utility::CSI_Sequence const & channel_color, utility::CSI_Sequence const & channel_name_color, TracerPriority priority, bool muted_by_default) :
Fatal( *this, t_fatal, channel ),
Error( *this, t_error, channel ),
Warning( *this, t_warning, channel ),
Info( *this, t_info, channel ),
Debug( *this, t_debug, channel ),
Trace( *this, t_trace, channel )
{
init(channel, channel_color, channel_name_color, priority, muted_by_default);
}
void TracerImpl::init(std::string const & channel, utility::CSI_Sequence const & channel_color, utility::CSI_Sequence const & channel_name_color, TracerPriority priority, bool muted_by_default)
{
mute_level_ = -1;
visible_ = true;
muted_ = false;
muted_by_default_ = muted_by_default;
channel_ = channel;
local_print_channel_name_ = true;
priority_ = priority;
channel_color_ = channel_color;
channel_name_color_ = channel_name_color;
// TracerImpl should only be initialized after the TracerOptions object is initialized.
calculate_visibility();
}
TracerImpl::~TracerImpl()
{
/// We could not gurantee that option system was not deleted already, so we must disable
/// options access. However we don't want channel to withhold any output since it can be important.
/// We check if anything still present in channel buffer, and if it is - print it contents with warning.
std::vector< otstream* > v = utility::tools::make_vector< otstream* >(
this, &Fatal, &Error, &Warning,
&Info, &Debug, &Trace);
/// PyRosetta final stream could be redirected to some Python object which might be already got destroyed during Python exit
#ifndef PYROSETTA
//set_new_final_stream( &std::cerr );
//set_ios_hook(otstreamOP(), "");
//bool need_flush = false;
for ( auto & i : v ) {
if ( !i->is_flushed() ) {
//v[i]->flush();
(*i) << std::endl;
(*i) << "[ WARNING ] Message(s) above was printed in the end instead of proper place because this Tracer object has some contents left in inner buffer when destructor was called. Explicitly call Tracer::flush() or end your IO with std::endl to disable this warning.\n" << std::endl;
}
}
#endif
}
/// @details re-init using data from another tracer object.
void TracerImpl::init( TracerImpl const & tr )
{
channel_ = tr.channel_;
priority_ = tr.priority_;
visible_ = true;
muted_ = false;
mute_level_ = -1;
// TracerImpl is only likely to be called after the options are set
calculate_visibility();
}
/// @brief set/get globale string-prefix for all Tracer output strings
void TracerImpl::output_prefix(std::string const &new_output_prefix)
{
#ifdef MULTI_THREADED
std::lock_guard< std::mutex > lock( tracer_static_data_mutex() );
#endif
output_prefix_ = new_output_prefix;
}
std::string TracerImpl::output_prefix()
{
#ifdef MULTI_THREADED
std::lock_guard< std::mutex > lock( tracer_static_data_mutex() );
#endif
return output_prefix_;
}
void TracerImpl::flush_all_channels()
{
std::vector< otstream* > v = utility::tools::make_vector< otstream* >(
this, &Fatal, &Error, &Warning,
&Info, &Debug, &Trace);
for ( auto & i : v ) {
i->flush();
}
}
bool TracerImpl::visible( int priority ) {
if ( muted_ ) return false;
if ( priority > mute_level_ ) return false;
return true;
}
TracerImpl &
TracerImpl::operator ()(int priority)
{
this->priority(priority);
return *this;
}
void TracerImpl::priority(int priority)
{
priority_ = priority;
visible_ = !muted_ && ( priority <= mute_level_ );
}
/// @details Calculate visibility of current Tracer object and all of its proxies
void TracerImpl::calculate_visibility()
{
bool options_set = false; // Indirection is so we don't have to lock around the sub-calculate_visibility calls
{
#ifdef MULTI_THREADED
std::lock_guard< std::mutex > lock( tracer_static_data_mutex() );
#endif
options_set = tracer_options_ != nullptr;
}
if ( options_set ) { // Small chance of race conditions with resetting to nullptr, but that's handled with asserts below.
calculate_visibility(channel_, priority_, visible_, muted_, mute_level_, muted_by_default_);
Fatal.calculate_visibility();
Error.calculate_visibility();
Warning.calculate_visibility();
Info.calculate_visibility();
Debug.calculate_visibility();
Trace.calculate_visibility();
} else {
// Can't have a direct-exit error here, as we might try to call un-initialized tracers during errors in Option system parsing
std::cout << std::endl;
std::cout << "[ WARNING ] Tried to calculate the visibility of Tracer '"+channel_+"' before init() was called!" << std::endl;
std::cout << "[ WARNING ] This tracer will not obey commandline options." << std::endl;
std::cout << std::endl;
}
}
/// @details Calculate visibility (static version) of current Tracer object using channel name and priority.
/// result stored in 'muted' and 'visible'.
void TracerImpl::calculate_visibility(
std::string const & channel,
int priority,
bool & visible,
bool & muted,
int & mute_level,
bool muted_by_default
)
{
#ifdef MULTI_THREADED
std::lock_guard< std::mutex > lock( tracer_static_data_mutex() );
#endif
assert( tracer_options_ );
visible = false;
if ( in(tracer_options_->muted, "all", true) ) {
if ( in(tracer_options_->unmuted, channel, false) ) visible = true;
else visible = false;
} else {
if ( in(tracer_options_->unmuted, "all", true) ) {
if ( in(tracer_options_->muted, channel, false) ) visible = false;
else visible = true;
} else { /// default bechavior: unmute unless muted_by_default is true
if ( muted_by_default ) {
if ( in(tracer_options_->unmuted, channel, false) ) visible = true;
else visible = false;
} else {
if ( in(tracer_options_->muted, channel, false) ) visible = false;
else visible = true;
}
}
}
//if we are in MPI mode --- most of the time one doesn't want to see output from all nodes just the master and 1st client is plenty ..
#ifdef USEMPI
int already_initialized = 0;
int already_finalized = 0;
MPI_Initialized( &already_initialized );
MPI_Finalized( &already_finalized );
if ( already_initialized != 0 && already_finalized == 0 ) {
int mpi_rank, mpi_nprocs;
MPI_Comm_rank (MPI_COMM_WORLD, &mpi_rank);/* get current process id */
MPI_Comm_size (MPI_COMM_WORLD, &mpi_nprocs);/* get number of processes */
mpi_rank_=mpi_rank;
}
if ( in(tracer_options_->muted, "all_high_mpi_rank", true ) ) {
if ( mpi_rank_>=2 ) visible = false; //* visible: master and 1st client: rank 0 and rank1
}
if ( in(tracer_options_->muted, "all_high_mpi_rank_filebuf", true ) ) {
if ( mpi_rank_>=4 ) visible = false; //* visible: master, filebuf and 1st client: rank 0, 1, 2
}
#endif
muted = !visible;
mute_level = tracer_options_->level;
calculate_tracer_level(tracer_options_->levels, channel, false, mute_level);
//std::cout << "levels:" << tracer_options_->levels <<" ch:" << channel << " mute_level:" << mute_level << " priority:" << priority << std::endl;
if ( priority > mute_level ) visible = false;
}
/// @details Check if string representing channel 'ch' is in vector<string> v. Return true if channel
/// is in vector, false otherwise.
/// Two mode of operation:
/// Strict: strict==true - channels compared verbatim.
/// Regular: strict==false - comparing with hierarchy in mind,
/// ie: ch='basic.pose' v[0]='basic' --> will yield true.
bool TracerImpl::in(utility::vector1<std::string> const & v, std::string const & ch, bool strict)
{
for ( size_t i=1; i<=v.size(); i++ ) {
if ( v[i] == ch ) return true;
if ( !strict ) {
if ( ch.size() > v[i].size() ) {
std::string s(ch); s.resize(v[i].size());
if ( s == v[i] ) return true;
}
}
}
return false;
}
/// @brief Output a message in a manner that is safe if the Tracers/output are poorly initialized.
void TracerImpl::safe_output(std::string const & message ) {
if ( ios_hook() ) {
*ios_hook() << message << std::endl;
} else if ( final_stream() ) {
*final_stream() << message << std::endl;
} else {
std::cerr << "Tracer Error: " << message << std::endl;
}
}
/// Same as before but return integer value for matched channel or closest match (we asume that 'v' in levels format, ie like: <channel name>:level )
bool TracerImpl::calculate_tracer_level(utility::vector1<std::string> const & v, std::string const & ch, bool strict, int &res)
{
unsigned int len = 0;
bool math = false;
//std::cout << "Entring:calculate_tracer_level: v=" << v << " ch:" << ch << std::endl;
for ( size_t i=1; i<=v.size(); i++ ) {
bool flag = false;
utility::vector1< std::string > spl = utility::string_split(v[i], ':');
if ( spl.size() != 2 ) {
safe_output("WARNING: Cannot parse -out:levels setting '"+v[i]+"'. Does not follow the format of 'tracer:level'. Ignoring.");
continue;
}
//std::cout << "Split:" << spl << " size:" << spl[1].size() << std::endl;
if ( spl[1] == "all" && len == 0 ) flag = true; // we can asume that 'all' is shorter then any valid core/protocol path... but we don't!
if ( spl[1] == ch ) flag=true;
if ( !strict ) {
if ( ch.size() > spl[1].size() ) {
std::string s(ch); s.resize(spl[1].size());
if ( s == spl[1] ) flag=true;
}
}
if ( flag && ( len <= spl[1].size() ) ) { // If specified twice, use the later one.
math = true;
len = spl[1].size();
res = utility::string2int(spl[2]);
std::string const spl2_lower = ObjexxFCL::lowercased( spl[2] );
if ( spl2_lower == "fatal" ) res = t_fatal;
if ( spl2_lower == "error" || spl2_lower == "errors" ) res = t_error;
if ( spl2_lower == "warning" || spl2_lower == "warnings" ) res = t_warning;
if ( spl2_lower == "info" ) res = t_info;
if ( spl2_lower == "debug" ) res = t_debug;
if ( spl2_lower == "trace" ) res = t_trace;
if ( res == -1 ) {
safe_output( "WARNING: The setting '" + spl[2] + "' is not recognized as a valid tracer level." );
res = t_info; // Set such that you get standard amount of output instead of none.
}
//std::cout << "Match:" << spl << " ch:" << ch << " res:"<< res << std::endl;
} else {
//std::cout << "Fail:" << spl << " ch:" << ch << " res:"<< res << std::endl;
}
}
//std::cout << "Leaving:calculate_tracer_level: v=" << v << " ch:" << ch << " match:" << math <<" res:"<< res << std::endl;
return math;
}
/// @details Write the contents of str to sout prepending the channel
/// name on each line if the print_channel_name flag is set.
template <class out_stream>
void TracerImpl::prepend_channel_name( out_stream & sout, std::string const &str )
{
// This is only called from TracerImpl::t_flush() -- That function holds the tracer_static_data_mutex
if ( str.empty() ) { return; } // Don't bother printing nothing (an empty line will have at least a carriage return.)
// If we're calling this function, we're at the begining of the line.
sout << this->Reset;
sout << output_prefix_;
if ( local_print_channel_name_ && tracer_options_ && tracer_options_->print_channel_name ) {
sout << channel_name_color_;
sout << channel_ << ": ";
#ifdef USEMPI
//Append MPI process index to the tracer output:
#ifdef MULTI_THREADED
sout << "(" << mpi_rank_ << ")";
if( !basic::thread_manager::RosettaThreadManager::thread_manager_was_initialized() ) { sout << " "; }
#else //MULTI_THREADED
sout << "(" << mpi_rank_ << ") ";
#endif //MULTI_THREADED
#endif
#ifdef MULTI_THREADED
//Append thread index to the tracer output:
if ( basic::thread_manager::RosettaThreadManager::thread_manager_initialization_begun() ) {
if ( basic::thread_manager::RosettaThreadManager::thread_manager_was_initialized() ) {
sout << "{" << basic::thread_manager::RosettaThreadManager::get_instance()->get_rosetta_thread_index() << "} ";
} else {
sout << "{?} "; //This must be thread zero if we have not yet launched threads. However, if we're in the middle of
//launching threads and the thread manager hasn't yet been marked as initialized, there can still be some messages
//from the threads, in which case we don't know which thread is producing them.
}
} else {
//If we haven't started launching threads, this must be thread zero.
sout << "{0} ";
}
#endif
if ( tracer_options_ && tracer_options_->timestamp ) {
sout << utility::timestamp() << " ";
}
sout << this->Reset;
}
// If the priority levels warrant it, add additional labeling.
// Note that the stylings here are somewhat arbitrary.
// (More important priorities get lower numbers.)
if ( priority_ <= t_warning ) { // Quick short-circuit for most output.
if ( priority_ <= t_fatal ) {
sout << this->Red << this->Bold << "[ FATAL ]" << this->Reset << ' ';
} else if ( priority_ <= t_error ) {
sout << this->Red << this->Bold << "[ ERROR ]" << this->Reset << ' ';
} else if ( priority_ <= t_warning ) {
sout << this->Bold << "[ WARNING ]" << this->Reset << ' ';
}
}
sout << channel_color_;
sout << str;
}
/// @details Inform Tracer that is contents was modified, and IO is in order.
void TracerImpl::t_flush(std::string const &str)
{
#ifdef MULTI_THREADED
std::lock_guard< std::mutex > lock( tracer_static_data_mutex() );
#endif
if ( visible() ) {
bool use_ios_hook = ios_hook() && ios_hook().get()!=this;
use_ios_hook = use_ios_hook && ( in(monitoring_list_(), channel_, false) || in(monitoring_list_(), get_all_channels_string(), true ) );
if ( use_ios_hook ) {
prepend_channel_name<otstream>( *ios_hook(), str );
ios_hook()->flush();
}
if ( !super_mute_() ) {
prepend_channel_name<std::ostream>( *final_stream(), str );
}
}
}
/// @details Set OStringStream object to which all Tracers output
/// listed in the monitoring_channels_list should be copied.
///
/// The boolean parameter is left for backward compatibility.
/// (It used to control the ability to ignore visibility settings.)
void TracerImpl::set_ios_hook(otstreamOP tr, std::string const & monitoring_channels_list, bool)
{
#ifdef MULTI_THREADED
std::lock_guard< std::mutex > lock( tracer_static_data_mutex() );
#endif
if ( utility::pointer::dynamic_pointer_cast< TracerImpl >(tr) != nullptr || utility::pointer::dynamic_pointer_cast< TracerImpl::TracerProxyImpl >(tr) != nullptr ) {
utility_exit_with_message("Error: Setting the ios_hook() to be a true Tracer or a TracerProxy is only going to end in grief! (Use a PyTracer instead.)");
}
ios_hook() = tr;
monitoring_list_() = utility::split(monitoring_channels_list);
}
} // namespace basic
| [
"lzhangbk@connect.ust.hk"
] | lzhangbk@connect.ust.hk |
98e183b981b772c8361e882a120e0d39d71cdd97 | f950882940764ace71e51a1512c16a5ac3bc47bc | /src/EmbDB/Tests/TestSpatialTree/TestSpatialTree.cpp | f1371ebc5f15e886e76b060e7903ee82a144404a | [] | no_license | ViacheslavN/GIS | 3291a5685b171dc98f6e82595dccc9f235e67bdf | e81b964b866954de9db6ee6977bbdf6635e79200 | refs/heads/master | 2021-01-23T19:45:24.548502 | 2018-03-12T09:55:02 | 2018-03-12T09:55:02 | 22,220,159 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 806 | cpp | // TestSpatialTree.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "CommonLibrary/SpatialKey.h"
#include "../../EmbDB/SpatialPointQuery.h"
#include <iostream>
void testZPoint();
void testZPoint1();
void testZRect1();
void TestPointSpatialTree();
void TestRectSpatialTree();
void TestPointZorder();
void TestRectZorder();
void TestRectZorder(int Xmax, int Ymax, int qXmin, int qYmin, int qXmax, int qYmax);
void WriteZorderTable(uint16 nBegin, uint16 nEnd);
void TestRectSpatialTreeFromShape();
int _tmain(int argc, _TCHAR* argv[])
{
//testZRect1();
//testZPoint();
// testZPoint1();
// TestPointSpatialTree();
//WriteZorderTable(0, 10);
// TestRectSpatialTree();
//TestPointZorder();
//TestRectZorder();
TestRectSpatialTreeFromShape();
return 0;
}
| [
"nk.viacheslav@gmail.com"
] | nk.viacheslav@gmail.com |
927ab3439e937c8818f268e6621c9b70ddc94b39 | cfeac52f970e8901871bd02d9acb7de66b9fb6b4 | /generated/src/aws-cpp-sdk-databrew/source/model/CreateRulesetRequest.cpp | f15410208e7ac419f13a63fd076636146ceaf837 | [
"Apache-2.0",
"MIT",
"JSON"
] | permissive | aws/aws-sdk-cpp | aff116ddf9ca2b41e45c47dba1c2b7754935c585 | 9a7606a6c98e13c759032c2e920c7c64a6a35264 | refs/heads/main | 2023-08-25T11:16:55.982089 | 2023-08-24T18:14:53 | 2023-08-24T18:14:53 | 35,440,404 | 1,681 | 1,133 | Apache-2.0 | 2023-09-12T15:59:33 | 2015-05-11T17:57:32 | null | UTF-8 | C++ | false | false | 1,481 | cpp | /**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/databrew/model/CreateRulesetRequest.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <utility>
using namespace Aws::GlueDataBrew::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
CreateRulesetRequest::CreateRulesetRequest() :
m_nameHasBeenSet(false),
m_descriptionHasBeenSet(false),
m_targetArnHasBeenSet(false),
m_rulesHasBeenSet(false),
m_tagsHasBeenSet(false)
{
}
Aws::String CreateRulesetRequest::SerializePayload() const
{
JsonValue payload;
if(m_nameHasBeenSet)
{
payload.WithString("Name", m_name);
}
if(m_descriptionHasBeenSet)
{
payload.WithString("Description", m_description);
}
if(m_targetArnHasBeenSet)
{
payload.WithString("TargetArn", m_targetArn);
}
if(m_rulesHasBeenSet)
{
Aws::Utils::Array<JsonValue> rulesJsonList(m_rules.size());
for(unsigned rulesIndex = 0; rulesIndex < rulesJsonList.GetLength(); ++rulesIndex)
{
rulesJsonList[rulesIndex].AsObject(m_rules[rulesIndex].Jsonize());
}
payload.WithArray("Rules", std::move(rulesJsonList));
}
if(m_tagsHasBeenSet)
{
JsonValue tagsJsonMap;
for(auto& tagsItem : m_tags)
{
tagsJsonMap.WithString(tagsItem.first, tagsItem.second);
}
payload.WithObject("Tags", std::move(tagsJsonMap));
}
return payload.View().WriteReadable();
}
| [
"sdavtaker@users.noreply.github.com"
] | sdavtaker@users.noreply.github.com |
fd5024e95a845abc7dae622141e05d8f0937ba43 | cd50eac7166505a8d2a9ef35a1e2992072abac92 | /solutions/codeforces/sgu404.cpp | a4bdb97aaec221e67dde28390f1295b6c0247d84 | [] | no_license | AvaLovelace1/competitive-programming | 8cc8e6c8de13cfdfca9a63e125e648ec60d1e0f7 | a0e37442fb7e9bf1dba4b87210f02ef8a134e463 | refs/heads/master | 2022-06-17T04:01:08.461081 | 2022-04-28T00:08:16 | 2022-04-28T00:08:16 | 123,814,632 | 8 | 5 | null | null | null | null | UTF-8 | C++ | false | false | 763 | cpp | /*
Solution to Fortune-telling with camomile by Ava Pun
Key concepts: implementation, simple math
*/
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
const int INF = 0x3F3F3F3F;
const ll INFL = 0x3F3F3F3F3F3F3F3FLL;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;
const double EPS = 1e-9;
int N, M;
string arr[105];
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for (int i = 1; i <= M; i++) {
cin >> arr[i];
}
arr[0] = arr[M];
cout << arr[N % M] << '\n';
return 0;
}
| [
"noreply@github.com"
] | AvaLovelace1.noreply@github.com |
df138942d19cb8e104f78a8e8240246921d2eb76 | 4ba0b403637e7aa3e18c9bafae32034e3c394fe4 | /cplusplus/loxpp-learn/src13/callable.h | 06d251158644c771fefd78f786534f9d85811d7d | [] | no_license | ASMlover/study | 3767868ddae63ac996e91b73700d40595dd1450f | 1331c8861fcefbef2813a2bdd1ee09c1f1ee46d6 | refs/heads/master | 2023-09-06T06:45:45.596981 | 2023-09-01T08:19:49 | 2023-09-01T08:19:49 | 7,519,677 | 23 | 6 | null | null | null | null | UTF-8 | C++ | false | false | 3,640 | h | // Copyright (c) 2019 ASMlover. 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 ofconditions 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 materialsprovided with the
// distribution.
//
// 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 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.
#pragma once
#include <memory>
#include <vector>
#include <unordered_map>
#include "common.h"
#include "value.h"
#include "ast.h"
namespace lox {
class Token;
class Environment;
class Interpreter;
using EnvironmentPtr = std::shared_ptr<Environment>;
using InterpreterPtr = std::shared_ptr<Interpreter>;
struct Callable : private UnCopyable {
virtual ~Callable(void) {}
virtual bool check_arity(void) const { return true; }
virtual Value call(
const InterpreterPtr& interp, const std::vector<Value>& arguments) = 0;
virtual std::size_t arity(void) const = 0;
virtual std::string to_string(void) const = 0;
};
class Function
: public Callable, public std::enable_shared_from_this<Function> {
FunctionStmtPtr decl_;
EnvironmentPtr closure_;
public:
Function(const FunctionStmtPtr& decl, const EnvironmentPtr& closure)
: decl_(decl)
, closure_(closure) {
}
virtual Value call(const InterpreterPtr& interp,
const std::vector<Value>& arguments) override;
virtual std::size_t arity(void) const override;
virtual std::string to_string(void) const override;
};
using FunctionPtr = std::shared_ptr<Function>;
class Class
: public Callable, public std::enable_shared_from_this<Class> {
std::string name_;
std::unordered_map<std::string, FunctionPtr> methods_;
public:
Class(const std::string& name,
const std::unordered_map<std::string, FunctionPtr>& methods)
: name_(name)
, methods_(methods) {
}
const std::string name(void) const { return name_; }
virtual Value call(const InterpreterPtr& interp,
const std::vector<Value>& arguments) override;
virtual std::size_t arity(void) const override;
virtual std::string to_string(void) const override;
FunctionPtr get_method(const InstancePtr& inst, const std::string& name);
};
using ClassPtr = std::shared_ptr<Class>;
class Instance
: private UnCopyable, public std::enable_shared_from_this<Instance> {
ClassPtr class_;
std::unordered_map<std::string, Value> properties_;
public:
Instance(const ClassPtr& cls)
: class_(cls) {
}
std::string to_string(void) const;
void set_property(const Token& name, const Value& value);
Value get_property(const Token& name);
};
using InstancePtr = std::shared_ptr<Instance>;
}
| [
"asmlover@126.com"
] | asmlover@126.com |
d48cce54cf67f245e0ce79090059d0b02425d460 | ddd30393b9abab40d0607db4f6e75123ba6257c0 | /CPP-Pool/d01/ex03/main.cpp | 66760b403aef4510b6a637a6dd90117b24cfe274 | [] | no_license | kuenane/42_Projects | 9db8e49725f791af26c064abed71ad3b2b2407d2 | 52038ee97265d75aaef44e62beb015c77633d0dd | refs/heads/master | 2021-08-26T08:36:58.022274 | 2017-11-22T15:45:42 | 2017-11-22T15:45:42 | 113,833,003 | 0 | 1 | null | 2017-12-11T08:32:17 | 2017-12-11T08:32:16 | null | UTF-8 | C++ | false | false | 1,019 | cpp | // ************************************************************************** //
// //
// ::: :::::::: //
// main.cpp :+: :+: :+: //
// +:+ +:+ +:+ //
// By: wide-aze <wide-aze@student.42.fr> +#+ +:+ +#+ //
// +#+#+#+#+#+ +#+ //
// Created: 2015/03/12 16:43:34 by wide-aze #+# #+# //
// Updated: 2015/03/13 16:08:38 by wide-aze ### ########.fr //
// //
// ************************************************************************** //
#include "Zombie.hpp"
#include "ZombieHorde.hpp"
int main(void)
{
ZombieHorde horde(10);
horde.announce();
return (0);
}
| [
"wide-aze@student.42.fr"
] | wide-aze@student.42.fr |
86818330eddc899cc098aebfc08f202f04a1ac41 | b6fc83d4bf6a207f3a412f048a2c3cc8e8750775 | /src/primitives/block.cpp | 30361bf3bafc932d5c5267cc2f827231247ff4e6 | [
"MIT"
] | permissive | Aryacoin/Aryacoin | 053211bfcb3efcb3e95eb0299413048de7981cbf | ff8af6d1ff3ce9aa227270f06a75066ed531626c | refs/heads/master | 2023-06-24T10:44:38.498741 | 2023-06-13T14:53:37 | 2023-06-13T14:53:37 | 173,964,186 | 22 | 6 | MIT | 2023-06-13T14:53:38 | 2019-03-05T14:42:14 | C++ | UTF-8 | C++ | false | false | 1,081 | cpp | // Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <primitives/block.h>
#include <hash.h>
#include <tinyformat.h>
#include <util/strencodings.h>
#include <crypto/common.h>
#include <crypto/scrypt.h>
uint256 CBlockHeader::GetHash() const
{
return SerializeHash(*this);
}
uint256 CBlockHeader::GetPoWHash() const
{
uint256 thash;
scrypt_1024_1_1_256(BEGIN(nVersion), BEGIN(thash));
return thash;
}
std::string CBlock::ToString() const
{
std::stringstream s;
s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
GetHash().ToString(),
nVersion,
hashPrevBlock.ToString(),
hashMerkleRoot.ToString(),
nTime, nBits, nNonce,
vtx.size());
for (const auto& tx : vtx) {
s << " " << tx->ToString() << "\n";
}
return s.str();
}
| [
"34451068+sillyghost@users.noreply.github.com"
] | 34451068+sillyghost@users.noreply.github.com |
5877cf806630251ad4e5653c3a7f96b09aaa2175 | 9c7da1343719aa3f7c5324d385cf66cd114626dd | /quickSort.cpp | 4ad5eb9b7863dd9b518e83b704c9944a0eca694c | [] | no_license | Ting0887/sort_algorithm | af43068c3017b1eeb7f049fd197a09e0fb7bd7d7 | c20f29926de147b626bc825923883e8b47e85f7e | refs/heads/main | 2023-08-31T06:20:07.776571 | 2021-10-28T15:08:59 | 2021-10-28T15:08:59 | 419,614,077 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 885 | cpp | #include<iostream>
using namespace std;
void swap(int *a,int *b){
int temp = *a;
*a = *b;
*b = temp;
}
int Partition(int *arr, int front, int end){
int pivot = arr[end];
int i = front -1;
for(int j= front; j < end; j++){
if (arr[j]< pivot){
i++;
swap(&arr[i],&arr[j]);
}
}
i++;
swap(&arr[i], &arr[end]);
return i;
}
void QuickSort(int *arr,int front, int end){
if(front < end){
int pivot = Partition(arr,front,end);
QuickSort(arr,front,pivot -1);
QuickSort(arr,pivot +1 , end);
}
}
void PrintArray(int *arr,int size){
for(int i=0; i<size; i++){
std::cout << arr[i] << " ";
}
std::cout << std::endl;
}
int main(){
int n = 7;
int arr[] = {1,7,9,5,2,4,3};
std::cout << "original:\n";
PrintArray(arr,n);
QuickSort(arr, 0, n-1);
std::cout << "sorted:\n";
PrintArray(arr,n);
return 0;
}
| [
"noreply@github.com"
] | Ting0887.noreply@github.com |
c70f6c9924fbf01acdf1f35410ac3fde6f0cf4e1 | 0d87d119aa8aa2cc4d486f49b553116b9650da50 | /src/scheduler.h | 11369133c239c8579a6284413066787adc0d070e | [
"MIT"
] | permissive | KingricharVD/Nests | af330cad884745cc68feb460d8b5547d3182e169 | 7b2ff6d27ccf19c94028973b7da20bdadef134a7 | refs/heads/main | 2023-07-07T12:21:09.232244 | 2021-08-05T01:25:23 | 2021-08-05T01:25:23 | 386,196,221 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,877 | h | // Copyright (c) 2015 The Bitcoin Core developers
// Copyright (c) 2017-2019 The PIVX developers
// Copyright (c) 2020-2021 The NestEgg Core Developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_SCHEDULER_H
#define BITCOIN_SCHEDULER_H
//
// NOTE:
// boost::thread / boost::chrono should be ported to std::thread / std::chrono
// when we support C++11.
//
#include <boost/chrono/chrono.hpp>
#include <boost/thread.hpp>
#include <map>
//
// Simple class for background tasks that should be run
// periodically or once "after a while"
//
// Usage:
//
// CScheduler* s = new CScheduler();
// s->scheduleFromNow(doSomething, 11); // Assuming a: void doSomething() { }
// s->scheduleFromNow(boost::bind(Class::func, this, argument), 3);
// boost::thread* t = new boost::thread(boost::bind(CScheduler::serviceQueue, s));
//
// ... then at program shutdown, clean up the thread running serviceQueue:
// t->interrupt();
// t->join();
// delete t;
// delete s; // Must be done after thread is interrupted/joined.
//
class CScheduler
{
public:
CScheduler();
~CScheduler();
typedef std::function<void(void)> Function;
// Call func at/after time t
void schedule(Function f, boost::chrono::system_clock::time_point t);
// Convenience method: call f once deltaSeconds from now
void scheduleFromNow(Function f, int64_t deltaSeconds);
// Another convenience method: call f approximately
// every deltaSeconds forever, starting deltaSeconds from now.
// To be more precise: every time f is finished, it
// is rescheduled to run deltaSeconds later. If you
// need more accurate scheduling, don't use this method.
void scheduleEvery(Function f, int64_t deltaSeconds);
// To keep things as simple as possible, there is no unschedule.
// Services the queue 'forever'. Should be run in a thread,
// and interrupted using boost::interrupt_thread
void serviceQueue();
// Tell any threads running serviceQueue to stop as soon as they're
// done servicing whatever task they're currently servicing (drain=false)
// or when there is no work left to be done (drain=true)
void stop(bool drain=false);
// Returns number of tasks waiting to be serviced,
// and first and last task times
size_t getQueueInfo(boost::chrono::system_clock::time_point &first,
boost::chrono::system_clock::time_point &last) const;
private:
std::multimap<boost::chrono::system_clock::time_point, Function> taskQueue;
boost::condition_variable newTaskScheduled;
mutable boost::mutex newTaskMutex;
int nThreadsServicingQueue;
bool stopRequested;
bool stopWhenEmpty;
bool shouldStop() { return stopRequested || (stopWhenEmpty && taskQueue.empty()); }
};
#endif
| [
"northerncommunity1@gmail.com"
] | northerncommunity1@gmail.com |
3b4f4e5a073faa339f518498640e200c1dd1e33b | a06515f4697a3dbcbae4e3c05de2f8632f8d5f46 | /corpus/taken_from_cppcheck_tests/stolen_6158.cpp | 9a6e2ba8ecc1667ff64e04c8c75326c90fef85a5 | [] | no_license | pauldreik/fuzzcppcheck | 12d9c11bcc182cc1f1bb4893e0925dc05fcaf711 | 794ba352af45971ff1f76d665b52adeb42dcab5f | refs/heads/master | 2020-05-01T01:55:04.280076 | 2019-03-22T21:05:28 | 2019-03-22T21:05:28 | 177,206,313 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 37 | cpp | void f(){double x; scanf("%lf", &x);} | [
"github@pauldreik.se"
] | github@pauldreik.se |
a3f4a54da69873e4e938d0c5eb498c28ca3c76ee | e1e641d29a48cf5c96b63857c5dc783ebe1cbd7b | /Labs/Lab1/ProcessB.cpp | d5604da7fd97ccd28ddc52caff1fe134a3129d06 | [] | no_license | BSUIR450503/450503_korotkina | e6819257eb454a17ca51f9a1394339c885845a2f | 7ed17fc2ab7ccb3ee6e32b06a65368772b7b1abc | refs/heads/master | 2021-01-17T07:10:01.854837 | 2016-06-19T23:18:18 | 2016-06-19T23:18:18 | 52,334,896 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 621 | cpp | #include <fstream>
#include <iostream>
#ifdef _WIN32
#include <string>
#include <math.h>
#include <conio.h>
#endif
#ifdef _linux
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#endif
using namespace std;
int main(int argc, char* argv[])
{
int out;
int in;
fstream inFile;
inFile.open("mFile.bin", ios::app | ios::binary | ios::in );
if (!inFile){
cout << "error";
return 0;
}
inFile>>in;
inFile.close();
out = in*in;
inFile.open("mFile.bin", ios::binary | ios_base::trunc |ios::out );
if(!inFile){
cout<<"error";
return 0;
}
inFile<<out;
inFile.close();
return 0;
}
| [
"juliakorotkina@gmail.com"
] | juliakorotkina@gmail.com |
662eaa4eb4089da280291a8610a6fea8388c7e44 | bc0945070d150c8af7cc56bf6e045a8c2cc7873d | /1014/2053304_RE.cpp | 8af48c17c1905d71d95b4cb422184562720be46e | [] | no_license | fengrenchang86/PKU | ab889d88cd62b3c0b3e00cde5d5c3a652a16221a | 0c4adf6b740d2186b7f23124673cd56520d1c818 | refs/heads/master | 2021-01-10T12:12:18.100884 | 2016-03-07T14:14:33 | 2016-03-07T14:14:33 | 53,328,385 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,767 | cpp | #include <iostream>
using namespace std;
const int MAX = 1200;
int a[MAX];
int h[6];
bool l[MAX]={0};
int flag = 0;
void dfs ( int t, int sum, int position, int num )
{
if ( t == sum )
{
flag = 1;
return;
}
while ( t+a[position] > sum || l[position] == 1 )
{
if ( position > num )
break;
position++;
}
if ( position > num )
return;
if ( t + a[position] == sum )
{
flag = 1;
return;
}
t += a[position];
if ( a[position] != a[position-1] )
{
if ( t -a[position] + h[a[position]] == sum )
{
flag = 1;
return;
}
else if ( t + h[a[position]] > sum )
{
l[position] = 1;
dfs(t,sum,position+1,num);
l[position] = 0;
}
}
else if ( l[position-1] == 1 )
{
l[position] = 1;
dfs(t,sum,position+1,num);
l[position] = 0;
}
if ( flag == 1 )
return;
t -= a[position];
dfs(t,sum,position+1,num);
}
int main ()
{
int v[6];
int i,j,sum,num;
int tcase = 1;
while ( scanf("%d %d %d %d %d %d",&v[0],&v[1],&v[2],&v[3],&v[4],&v[5]) )
{
num = v[0] + v[1] + v[2] + v[3] + v[4] + v[5];
if ( num == 0 )
break;
printf("Collection #%d:\n",tcase);
tcase++;
sum = v[0]+2*v[1]+3*v[2]+4*v[3]+5*v[4]+6*v[5];
if ( sum %2==1 )
{
printf("Can't be divided.\n\n");
continue;
}
sum /= 2;
j = 1;
for ( i = 0; i < v[5]; i++ )
a[j++] = 6;
for ( i = 0; i < v[4]; i++ )
a[j++] = 5;
for ( i = 0; i < v[3]; i++ )
a[j++] = 4;
for ( i = 0; i < v[2]; i++ )
a[j++] = 3;
for ( i = 0; i < v[1]; i++ )
a[j++] = 2;
for ( i = 0; i < v[0]; i++ )
a[j++] = 1;
h[0] = v[0];
for ( i = 1; i < 6; i++ )
h[i] = h[i-1] + (i+1)*v[i];
dfs(0,sum,1,num);
if ( flag == 1 )
printf("Can be divided.\n");
else
printf("Can't be divided.\n");
flag = 0;
printf("\n");
}
return 0;
} | [
"fengrenchang86@gmail.com"
] | fengrenchang86@gmail.com |
1629bf90da04347b767d3b5f91d97a3da82d4b24 | e4d688f22075ba0dea975b681aeb5a86cb36ec4e | /src/mplfe/common/include/fe_file_type.h | 93d3e419f7f541def56f71c0c55885236d943530 | [
"LicenseRef-scancode-mulanpsl-2.0-en"
] | permissive | MapleSystem/OpenArkCompiler | e265822f08358ad316597dc3be2ff730035c21eb | 06a1511e6c1db559bc058717677d2714fc2c3c09 | refs/heads/master | 2023-08-25T11:29:58.461311 | 2021-09-27T05:54:08 | 2021-09-27T05:54:08 | 250,312,645 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,068 | h | /*
* Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved.
*
* OpenArkCompiler is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR
* FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef MPLFE_INCLUDE_COMMON_FE_FILE_TYPE_H
#define MPLFE_INCLUDE_COMMON_FE_FILE_TYPE_H
#include <string>
#include <map>
#include "types_def.h"
#include "basic_io.h"
namespace maple {
class FEFileType {
public:
enum FileType {
kUnknownType,
kClass,
kJar,
kDex,
kAST
};
inline static FEFileType &GetInstance() {
return fileType;
}
FileType GetFileTypeByExtName(const std::string &extName) const;
FileType GetFileTypeByPathName(const std::string &pathName) const;
FileType GetFileTypeByMagicNumber(const std::string &pathName) const;
FileType GetFileTypeByMagicNumber(BasicIOMapFile &file) const;
FileType GetFileTypeByMagicNumber(uint32 magic) const;
void Reset();
void LoadDefault();
void RegisterExtName(FileType fileType, const std::string &extName);
void RegisterMagicNumber(FileType fileType, uint32 magicNumber);
static std::string GetPath(const std::string &pathName);
static std::string GetName(const std::string &pathName, bool withExt = true);
static std::string GetExtName(const std::string &pathName);
private:
static FEFileType fileType;
static const uint32 kMagicClass = 0xBEBAFECA;
static const uint32 kMagicZip = 0x04034B50;
static const uint32 kMagicDex = 0x0A786564;
static const uint32 kMagicAST = 0x48435043;
std::map<std::string, FileType> mapExtNameType;
std::map<FileType, uint32> mapTypeMagic;
std::map<uint32, FileType> mapMagicType;
FEFileType();
~FEFileType() = default;
};
}
#endif
| [
"fuzhou@huawei.com"
] | fuzhou@huawei.com |
63591157afb7c78f0008cf13e337d8ed6519a15f | 7f3e9c3c64c7666b89de9f1ce9f0aaff5137ff7b | /rdf/NTriplesReader.cpp | fade34c6ee153d4547b06139f1c30145f9d684b2 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"LicenseRef-scancode-unicode"
] | permissive | jrweave/jrweave | 5b5b01ba6bea08c00336693a64a62fd48daab3c4 | fe2ca3d694e16fb9c627e031eaae58110df793be | refs/heads/master | 2021-01-13T01:55:18.361610 | 2012-09-10T20:17:39 | 2012-09-10T20:17:39 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,718 | cpp | /* Copyright 2012 Jesse Weaver
*
* 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 "rdf/NTriplesReader.h"
namespace rdf {
NTriplesReader::NTriplesReader(InputStream *is) throw()
: input(is), buffer(NULL), offset(0) {
if (this->input != NULL) {
this->buffer = this->input->read();
}
}
NTriplesReader::~NTriplesReader() throw() {
if (this->input != NULL) {
DELETE(this->input);
if (this->buffer != NULL) {
this->buffer->drop();
}
}
}
bool NTriplesReader::read(RDFTriple &triple) {
if (this->buffer == NULL) {
return false;
}
if (this->offset >= this->buffer->size()) {
this->buffer->drop();
try {
this->buffer = this->input->read();
} JUST_RETHROW(IOException, "(rethrow)")
if (this->buffer == NULL) {
return false;
}
this->offset = 0;
}
const uint8_t *begin = this->buffer->dptr() + this->offset;
const uint8_t *end = this->buffer->dptr() + this->buffer->size();
const uint8_t *p;
do {
for (p = begin; p != end && *p == to_ascii('\n'); ++p) {
// skip blank lines
}
if (p == end) {
this->buffer->drop();
try {
this->buffer = this->input->read();
} JUST_RETHROW(IOException, "(rethrow)")
if (this->buffer == NULL) {
return false;
}
this->offset = 0;
begin = this->buffer->dptr();
end = begin + this->buffer->size();
}
} while (p == end);
for (; p != end && *p != to_ascii('\n'); ++p) {
// find end of line/triple
}
DPtr<uint8_t> *triplestr = this->buffer->sub(this->offset, p - begin);
this->offset += triplestr->size() + 1; // skip '\n'
if (p != end) {
try {
triple = RDFTriple::parse(triplestr);
} catch (BadAllocException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (InvalidEncodingException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (InvalidCodepointException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (MalformedIRIRefException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (MalformedLangTagException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (BaseException<IRIRef> &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (TraceableException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
}
triplestr->drop();
return true;
}
vector<void*> parts;
if (!triplestr->standable()) {
THROW(TraceableException, "CANNOT STAND POINTER!");
}
triplestr = triplestr->stand();
size_t len = triplestr->size();
parts.push_back((void*) triplestr);
do {
this->buffer->drop();
try {
this->buffer = this->input->read();
} catch (IOException &e) {
vector<void*>::iterator it = parts.begin();
for (; it != parts.end(); ++it) {
((DPtr<uint8_t>*)(*it))->drop();
}
RETHROW(e, "(rethrow)");
}
if (this->buffer == NULL) {
break;
}
begin = this->buffer->dptr();
end = begin + this->buffer->size();
p = begin;
for (; p != end && *p != to_ascii('\n'); ++p) {
// find end of line/triple
}
triplestr = this->buffer->sub(0, p - begin);
this->offset = triplestr->size() + 1;
if (!triplestr->standable()) {
THROW(TraceableException, "CANNOT STAND POINTER!");
}
triplestr->stand();
len += triplestr->size();
parts.push_back((void*) triplestr);
} while (p == end);
if (len <= 0) {
vector<void*>::iterator it = parts.begin();
for (; it != parts.end(); ++it) {
((DPtr<uint8_t>*)(*it))->drop();
}
return false;
}
try {
NEW(triplestr, MPtr<uint8_t>, len);
} catch (bad_alloc &e) {
vector<void*>::iterator it = parts.begin();
for (; it != parts.end(); ++it) {
((DPtr<uint8_t>*)(*it))->drop();
}
THROW(BadAllocException, sizeof(MPtr<uint8_t>));
} catch (BadAllocException &e) {
vector<void*>::iterator it = parts.begin();
for (; it != parts.end(); ++it) {
((DPtr<uint8_t>*)(*it))->drop();
}
RETHROW(e, "(rethrow)");
}
uint8_t *write_to = triplestr->dptr();
vector<void*>::iterator it = parts.begin();
for (; it != parts.end(); ++it) {
DPtr<uint8_t> *part = (DPtr<uint8_t>*)(*it);
memcpy(write_to, part->dptr(), part->size() * sizeof(uint8_t));
write_to += part->size();
part->drop();
}
try {
triple = RDFTriple::parse(triplestr);
} catch (BadAllocException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (InvalidEncodingException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (InvalidCodepointException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (MalformedIRIRefException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (MalformedLangTagException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
} catch (TraceableException &e) {
triplestr->drop();
RETHROW(e, "(rethrow)");
}
triplestr->drop();
return true;
}
void NTriplesReader::close() {
try {
this->input->close();
} JUST_RETHROW(IOException, "(rethrow)")
}
}
| [
"jrweave@gmail.com"
] | jrweave@gmail.com |
dbf44397ed95171459eba71796f8045adc5a02db | 1c23ceebe81db4105252727d2c7d2232cc191aac | /proj/detail/transform.hpp | abbddea0825c1bc35badbac38bfb0412bd3fcc90 | [
"MIT"
] | permissive | MAPSWorks/bark-NanoGIS-Qt-GIS | 07f317f1f7dbba1d8130687df5e01c22d74ac397 | fc201e844498bbba068abbe714ceac5d6967513f | refs/heads/master | 2020-09-22T12:56:03.514237 | 2019-11-17T17:35:46 | 2019-11-17T17:35:46 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,113 | hpp | // Andrew Naplavkov
#ifndef BARK_PROJ_TRANSFORM_HPP
#define BARK_PROJ_TRANSFORM_HPP
#include <algorithm>
#include <bark/detail/grid.hpp>
#include <bark/geometry/geometry.hpp>
#include <cmath>
#include <iterator>
#include <proj_api.h>
#include <stdexcept>
#include <vector>
namespace bark::proj {
inline void transform(projPJ from, projPJ to, double* first, double* last)
{
if (pj_is_latlong(from))
std::transform(
first, last, first, [](double v) { return v * DEG_TO_RAD; });
auto size = std::distance(first, last);
auto res =
pj_transform(from, to, (long)size / 2, 2, first, first + 1, nullptr);
if (res != 0)
throw std::runtime_error(pj_strerrno(res));
if (pj_is_latlong(to))
std::transform(
first, last, first, [](double v) { return v * RAD_TO_DEG; });
}
inline geometry::point transformed(projPJ from,
projPJ to,
const geometry::point& v)
{
double coords[] = {v.x(), v.y()};
transform(from, to, std::begin(coords), std::end(coords));
return {coords[0], coords[1]};
}
inline geometry::box transformed(projPJ from, projPJ to, const geometry::box& v)
{
grid gr(v, 32, 32);
transform(from, to, gr.begin(), gr.end());
auto points = gr.rows() * gr.cols();
std::vector<double> xs, ys;
xs.reserve(points);
ys.reserve(points);
for (size_t row = 0; row < gr.rows(); ++row)
for (size_t col = 0; col < gr.cols(); ++col) {
auto x = gr.x(row, col);
auto y = gr.y(row, col);
if (std::isfinite(x))
xs.push_back(x);
if (std::isfinite(y))
ys.push_back(y);
}
if (xs.empty() || ys.empty())
throw std::runtime_error("transformed box");
auto minmax_x = std::minmax_element(xs.begin(), xs.end());
auto minmax_y = std::minmax_element(ys.begin(), ys.end());
return {{*minmax_x.first, *minmax_y.first},
{*minmax_x.second, *minmax_y.second}};
}
} // namespace bark::proj
#endif // BARK_PROJ_TRANSFORM_HPP
| [
"andrew.naplavkov@gmail.com"
] | andrew.naplavkov@gmail.com |
2f8227f3a3bf315cfaff7e2cc03da7787c1aec87 | 0078a70d4cde0ab5f9d00bbe7b19e82d8c760f27 | /examen/controller.h | 85ca08a905dfbc51f6ae575b2a9e3b121d077fe7 | [] | no_license | denisaungur/projects | 68362221d891b756a8bab8bb7124598597b18d71 | 020755320815b150266bd96b16879c58d69cb436 | refs/heads/master | 2020-06-26T21:17:09.729467 | 2017-07-12T16:30:42 | 2017-07-12T16:30:42 | 97,029,218 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 530 | h | #ifndef CONTROLLER_H
#define CONTROLLER_H
#include "domain.h"
#include "filerepo.h"
#include <vector>
using namespace std;
class Controller{
private:
FileRepo repo;
public:
Controller(FileRepo r){repo=r;};
vector<Product> get_all(){
return repo.get_all_records();
}
void add(Product p){
try{
repo.store(p);
}
catch(const char* msg){ throw msg;}
}
vector<Product> filter_products(double p){
return repo.filter(p);
}
};
#endif // CONTROLLER_H
| [
"denisaungur@yahoo.com"
] | denisaungur@yahoo.com |
0b5a9bc4080bd3fcd83cdaaf612abc9ca1e68c98 | f5690d05b3156379c85f0e5b27240a609c540bf8 | /qt5/ftpupload/mainwindow.h | b188ddfdc2b55e36b5e1cde0d8af15efd81cf420 | [] | no_license | aeternu/qt-1 | 01c71253c8e56ac1e73606e0e029e43057e5aa56 | b1c6cb162947d0766c54b9efa9062b1481fdf334 | refs/heads/master | 2021-05-26T19:31:11.564047 | 2014-01-05T14:28:19 | 2014-01-05T14:28:19 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 375 | h | #ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_btnBrowse_clicked();
void on_btnInsertImg_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
| [
"steewsc@gmail.com"
] | steewsc@gmail.com |
a4cc2854a27d500abb25ef7ba8de15be2871dcfd | 4e8f53a51ac928556adce378b42a9e3baed6415e | /BST.hpp | ff52e10ab0dd5c12205c6010fc7a6c8b9610081b | [] | no_license | oliviamaciejewska/hash_tables | ef436c1e44a35bf6287a6f41461059e026f2602b | 151264682f6f815475edb0049b49693af5113b11 | refs/heads/master | 2020-12-01T04:26:02.607319 | 2019-12-28T04:14:00 | 2019-12-28T04:14:00 | 230,556,929 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 827 | hpp | #ifndef BST_HPP
#define BST_HPP
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <time.h>
#include <windows.h>
#include <iomanip>
#include <algorithm>
#include <random>
#define TABLE_SIZE 10009
using namespace std;
struct HashNode
{
int key;
HashNode *left=NULL;
HashNode* right=NULL;
};
class HashTable {
private:
HashNode* table[TABLE_SIZE];
int h(int k, int functionOption);
int M;
public:
HashTable();
void insert(int k, int functionOption);
HashNode* search(int k, int functionOption);
void deleteKey(int k, int functionOption);
void printTable();
void insertTimer(vector<int> &dataSet, int functionOption);
void deleteTimer(vector<int> &dataSet, int functionOption);
void searchTimer(vector<int> &dataSet, int functionOption);
};
#endif
| [
"oliviamaciejewska@gmail.com"
] | oliviamaciejewska@gmail.com |
432cba6275523f17e070aa76f7e728916d85a077 | c4617bb18dee000848aee5593e8668c3d1516b97 | /Experiment_Controller_V6/Addon/sectionediter.cpp | 4ed3c69eee0769c15d9d4e82a2a471d079cd9c7e | [] | no_license | liangqibox/Lithium6_ATI | 469f688dbea6a128b53e159cc4b9e9562f0a9640 | b81cea8895ed15db941019a8c00101499317b731 | refs/heads/master | 2020-12-26T10:32:39.611130 | 2020-01-31T18:26:17 | 2020-01-31T18:26:17 | 237,481,429 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 16,401 | cpp | #include "sectionediter.h"
#include "ui_sectionediter.h"
Sectionediter::Sectionediter(QWidget *parent, int AO, int DiO) :
QDialog(parent),
ui(new Ui::Sectionediter)
{
ui->setupUi(this);
this->installEventFilter(this);
connect(ui->Scroll_maina->verticalScrollBar(),SIGNAL(valueChanged(int)),ui->Scroll_timea->verticalScrollBar(),SLOT(setValue(int)));
connect(ui->Scroll_timea->verticalScrollBar(),SIGNAL(valueChanged(int)),ui->Scroll_maina->verticalScrollBar(),SLOT(setValue(int)));
connect(ui->Scroll_maind->verticalScrollBar(),SIGNAL(valueChanged(int)),ui->Scroll_timed->verticalScrollBar(),SLOT(setValue(int)));
connect(ui->Scroll_timed->verticalScrollBar(),SIGNAL(valueChanged(int)),ui->Scroll_maind->verticalScrollBar(),SLOT(setValue(int)));
Analog_output_channel = AO;
Digital_output_channel = DiO;
current = new QList<Sequence*> *[Analog_output_channel+Digital_output_channel];
widgets = new QList<Editerwidget*> *[Analog_output_channel+Digital_output_channel];
cyc = new QLCDNumber *[Analog_output_channel+Digital_output_channel];
QPixmap temp = QPixmap(135,82);
temp.fill(QColor(225,225,225));
moveable = new QLabel(this);
moveable->setPixmap(temp);
moveable->setGeometry(0,0,135,82);
moveable->setFrameShape(QFrame::Panel);
moveable->setFrameShadow(QFrame::Raised);
moveable->setLineWidth(2);
moveable->hide();
}
Sectionediter::~Sectionediter()
{
emit Closed();
delete ui;
}
void Sectionediter::initial(QList<Variable *> *ivari, VariableClass *vc, QList<QList<Sequence *> **> *isec, QList<QString> *iname, QList<QString> *chl_name, int *total_run){
QFont lab;
lab.setPixelSize(13);
lab.setBold(true);
variables = ivari;
variableClass = vc;
sections = isec;
sections_name = iname;
channel_name = chl_name;
total_number_of_run = total_run;
adding = false;
dragging = false;
if(!sections->isEmpty()){
for(int i=0; i<sections->size(); i++){
QListWidgetItem *listitem = new QListWidgetItem(ui->Section_list);
listitem->setText(sections_name->at(i));
listitem->setFlags(listitem->flags()|Qt::ItemIsEditable);
ui->Section_list->addItem(listitem);
}
ui->Section_list->item(0)->setSelected(true);
for(int i=0; i<Analog_output_channel+Digital_output_channel; i++)current[i] = sections->first()[i];
// load_section();
}
for(int i=0; i<Analog_output_channel; i++){
widgets[i] = new QList<Editerwidget*>;
current[i] = new QList<Sequence*>;
QLabel *temp = new QLabel(ui->timea);
temp->setText(channel_name->at(i));
temp->setAlignment(Qt::AlignHCenter);
temp->setGeometry(10,15+85*i,90,25);
temp->setFont(lab);
cyc[i] = new QLCDNumber(ui->timea);
cyc[i]->setGeometry(10,45+85*i,91,25);
cyc[i]->setDigitCount(6);
temp->show();
cyc[i]->show();
}
for(int i=0; i<Analog_output_channel-1; i++){
QFrame *line = new QFrame(ui->timea);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
line->setGeometry(0,85*i+82,110,3);
line->show();
}
for(int i=0; i<Digital_output_channel; i++){
widgets[i+Analog_output_channel] = new QList<Editerwidget*>;
current[i+Analog_output_channel] = new QList<Sequence*>;
QLabel *temp = new QLabel(ui->timed);
temp->setText(channel_name->at(Analog_output_channel+i));
temp->setAlignment(Qt::AlignHCenter);
temp->setGeometry(10,15+85*i,90,25);
temp->setFont(lab);
cyc[Analog_output_channel+i] = new QLCDNumber(ui->timed);
cyc[Analog_output_channel+i]->setGeometry(10,45+85*i,91,25);
cyc[Analog_output_channel+i]->setDigitCount(6);
temp->show();
cyc[Analog_output_channel+i]->show();
}
for(int i=0; i<Digital_output_channel-1; i++){
QFrame *line = new QFrame(ui->timed);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
line->setGeometry(0,85*i+82,110,3);
line->show();
}
change_window_size(400);
ui->timea->setMinimumHeight(85*Analog_output_channel);
ui->maina->setMinimumHeight(85*Analog_output_channel);
ui->timed->setMinimumHeight(85*Digital_output_channel);
ui->maind->setMinimumHeight(85*Digital_output_channel);
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(calculate_time()));
timer->start(250);
}
void Sectionediter::resizeEvent(QResizeEvent *a){
ui->Scroll_maina->setGeometry(110,0,this->width()-309,this->height()-69);
ui->Scroll_timea->setGeometry(0,0,111,this->height()-86);
ui->Scroll_maind->setGeometry(110,0,this->width()-309,this->height()-69);
ui->Scroll_timed->setGeometry(0,0,111,this->height()-86);
ui->line->setGeometry(173,0,21,this->height());
ui->Tab->setGeometry(190,45,this->width()-193,this->height()-47);
}
bool Sectionediter::eventFilter(QObject *obj, QEvent *event){
if(event->type()==QEvent::MouseButtonPress){
QMouseEvent *a = static_cast<QMouseEvent*>(event);
if(a->button()==Qt::LeftButton){
if(190<a->x()&&a->x()<300&&10<a->y()&&a->y()<40){
moveable->move(a->x()-67,a->y()-41);
moveable->show();
dragging = true;
adding = true;
return true;
}
else if(obj->parent()==ui->maina){
Editerwidget *w = static_cast<Editerwidget*>(obj);
moveable->move(a->x()-67+300+w->x()-ui->Scroll_maina->horizontalScrollBar()->value(),a->y()-41+60+w->y()-ui->Scroll_maina->verticalScrollBar()->value());
moveable->show();
dragging = true;
w->hide();
return true;
}
else if(obj->parent()==ui->maind){
Editerwidget *w = static_cast<Editerwidget*>(obj);
moveable->move(a->x()-67+300+w->x()-ui->Scroll_maind->horizontalScrollBar()->value(),a->y()-41+60+w->y()-ui->Scroll_maind->verticalScrollBar()->value());
moveable->show();
dragging = true;
w->hide();
return true;
}
return false;
}
return false;
}
else if(event->type()==QEvent::MouseMove){
QMouseEvent *a = static_cast<QMouseEvent*>(event);
if(dragging&&adding){
moveable->move(a->x()-67,a->y()-41);
return true;
}
else if(dragging){
QWidget *w = static_cast<QWidget*>(obj);
if(ui->Tab->currentIndex()==0)moveable->move(a->x()-67+300+w->x()-ui->Scroll_maina->horizontalScrollBar()->value(),a->y()-41+60+w->y()-ui->Scroll_maina->verticalScrollBar()->value());
if(ui->Tab->currentIndex()==1)moveable->move(a->x()-67+300+w->x()-ui->Scroll_maind->horizontalScrollBar()->value(),a->y()-41+60+w->y()-ui->Scroll_maind->verticalScrollBar()->value());
return true;
}
return false;
}
else if(event->type()==QEvent::MouseButtonRelease){
QMouseEvent *a = static_cast<QMouseEvent*>(event);
if(dragging&&adding){
moveable->hide();
dragging = false;
adding = false;
int channel;
int position;
bool analog = !ui->Tab->currentIndex();
if(a->x()>300 && a->y()>60){
if(analog){
channel = (a->y()-60+ui->Scroll_maina->verticalScrollBar()->value())/85;
position = (a->x()-301+ui->Scroll_maina->horizontalScrollBar()->value())/136;
}
else{
channel = (a->y()-60+ui->Scroll_maind->verticalScrollBar()->value())/85;
position = (a->x()-301+ui->Scroll_maind->horizontalScrollBar()->value())/136;
}
add_widget(channel,position,analog);
}
return true;
}
else if(dragging){
QWidget *w = static_cast<QWidget*>(obj);
moveable->hide();
dragging = false;
bool analog = !ui->Tab->currentIndex();
int x,y;
if(analog){
x = a->x()+w->x()+300-ui->Scroll_maina->horizontalScrollBar()->value();
y = a->y()+w->y()+60-ui->Scroll_maina->verticalScrollBar()->value();
}
else{
x = a->x()+w->x()+300-ui->Scroll_maind->horizontalScrollBar()->value();
y = a->y()+w->y()+60-ui->Scroll_maind->verticalScrollBar()->value();
}
if(x<300 || (x>300+ui->maina->width()) || y<60 || (y>60+ui->maina->height())){
delete_widget(w,analog);
}
else{
int channel,position;
if(a->x()<0)position = a->x()/136 - 1;
else position = a->x()/136;
if(a->y()<0)channel = a->y()/85 - 1;
else channel = a->y()/85;
w->show();
move_widget(channel,position,w,analog);
}
return true;
}
return false;
}
return false;
}
void Sectionediter::change_window_size(int x){
ui->maina->setMinimumWidth(x);
ui->maind->setMinimumWidth(x);
}
void Sectionediter::load_section(){
for(int i=0; i<Analog_output_channel+Digital_output_channel; i++){
for(int j=0; j<widgets[i]->size(); j++)delete widgets[i]->at(j);
if(!widgets[i]->isEmpty())widgets[i]->clear();
}
int wid = 0;
for(int i=0; i<Analog_output_channel; i++){
if(!current[i]->isEmpty()){
for(int j=0; j<current[i]->size(); j++){
Editerwidget *w = new Editerwidget(ui->maina);
w->initial(current[i]->at(j),variables);
w->move(1+136*j,85*i);
w->installEventFilter(this);
widgets[i]->append(w);
w->show();
if(j>wid)wid = j;
}
}
}
for(int i=Analog_output_channel; i<Analog_output_channel+Digital_output_channel; i++){
if(!current[i]->isEmpty()){
for(int j=0; j<current[i]->size(); j++){
Editerwidget *w = new Editerwidget(ui->maind);
w->initial(current[i]->at(j),variables);
w->move(1+136*j,85*(i-Analog_output_channel));
w->installEventFilter(this);
widgets[i]->append(w);
w->show();
if(j>wid)wid = j;
}
}
}
change_window_size(wid*136+300);
}
void Sectionediter::on_Close_clicked()
{
this->accept();
}
void Sectionediter::on_Section_add_clicked()
{
QListWidgetItem *name = new QListWidgetItem;
QList<Sequence*> **sec;
sec = new QList<Sequence*>*[Analog_output_channel+Digital_output_channel];
for(int i=0; i<Analog_output_channel+Digital_output_channel; i++){
sec[i]=new QList<Sequence*>;
current[i] = sec[i];
}
name->setText("New section");
ui->Section_list->addItem(name);
name->setFlags(name->flags()|Qt::ItemIsEditable);
sections_name->append("New Section");
sections->append(sec);
name->setSelected(true);
load_section();
emit section_change();
}
void Sectionediter::on_Section_copy_clicked()
{
if(ui->Section_list->count()==0)return;
int index = 0;
for(int i=0; i<sections->size(); i++)if(ui->Section_list->item(i)->isSelected())index = i;
QListWidgetItem *name = new QListWidgetItem;
QList<Sequence*> **sec;
sec = new QList<Sequence*>*[Analog_output_channel+Digital_output_channel];
for(int i=0; i<Analog_output_channel+Digital_output_channel; i++){
sec[i]=new QList<Sequence*>;
for(int j=0; j<current[i]->size(); j++){
bool isDiO = false;
if(i>=Analog_output_channel)isDiO = true;
Sequence *s = new Sequence(0,isDiO,variables,variableClass);
*s = *current[i]->at(j);
sec[i]->append(s);
}
current[i] = sec[i];
}
name->setText(ui->Section_list->item(index)->text()+"_copy");
ui->Section_list->addItem(name);
name->setFlags(name->flags()|Qt::ItemIsEditable);
sections_name->append(ui->Section_list->item(index)->text()+"_copy");
sections->append(sec);
name->setSelected(true);
load_section();
emit section_change();
}
void Sectionediter::on_Section_delete_clicked()
{
int index = 0;
for(int i=0; i<sections->size(); i++)if(ui->Section_list->item(i)->isSelected())index = i;
for(int i=0; i<Analog_output_channel+Digital_output_channel; i++){
for(int j=0; j<sections->at(index)[i]->size(); j++){
delete sections->at(index)[i]->at(j);
}
sections->at(index)[i]->clear();
}
delete sections->at(index);
sections->removeAt(index);
sections_name->removeAt(index);
delete ui->Section_list->item(index);
if(!sections->isEmpty()){
ui->Section_list->item(0)->setSelected(true);
for(int i=0; i<Analog_output_channel+Digital_output_channel; i++)current[i] = sections->first()[i];
}
load_section();
emit section_change();
}
void Sectionediter::on_Section_list_itemChanged(QListWidgetItem *item)
{
sections_name->removeAt(ui->Section_list->row(item));
sections_name->insert(ui->Section_list->row(item),item->text());
emit section_change();
}
void Sectionediter::on_Section_list_clicked(const QModelIndex &index)
{
if(current!=sections->at(index.row()))for(int i=0; i<Analog_output_channel+Digital_output_channel; i++)current[i] = sections->at(index.row())[i];
load_section();
}
void Sectionediter::add_widget(int channel, int position, bool analog){
Editerwidget *w = new Editerwidget();
Sequence *s = new Sequence(0,!analog,variables,variableClass);
if(analog)w->setParent(ui->maina);
else{
w->setParent(ui->maind);
channel = channel + Analog_output_channel;
}
if(current[channel]->size()<position)position = current[channel]->size();
w->initial(s,variables);
w->installEventFilter(this);
widgets[channel]->insert(position,w);
current[channel]->insert(position,s);
w->move(position*136+1,channel*85);
w->show();
sort_widget();
}
void Sectionediter::delete_widget(QWidget *w, bool analog){
int channel = w->y()/85;
int position = (w->x()-1)/136;
if(!analog)channel = channel + Analog_output_channel;
Editerwidget *e = static_cast<Editerwidget*>(w);
current[channel]->removeAt(position);
widgets[channel]->removeAt(position);
delete e->seq;
delete w;
sort_widget();
}
void Sectionediter::move_widget(int tochannel, int toposition, QWidget *w, bool analog){
if(tochannel==0 && toposition==0)return;
int channel = w->y()/85;
int position = (w->x()-1)/136;
if(!analog)channel = channel + Analog_output_channel;
Editerwidget *e = static_cast<Editerwidget*>(w);
if(widgets[channel+tochannel]->size()>position+toposition)toposition = widgets[channel+tochannel]->size()-position;
current[channel]->removeAt(position);
widgets[channel]->removeAt(position);
current[channel+tochannel]->insert(position+toposition,e->seq);
widgets[channel+tochannel]->insert(position+toposition,e);
sort_widget();
}
void Sectionediter::sort_widget(){
int wid=0;
for(int i=0; i<Analog_output_channel+Digital_output_channel; i++){
for(int j=0; j<widgets[i]->size(); j++){
if(i<Analog_output_channel)widgets[i]->at(j)->move(j*136+1,i*85);
else widgets[i]->at(j)->move(j*136+1,(i-Analog_output_channel)*85);
if(j>wid)wid = j;
}
}
change_window_size(wid*136+300);
}
void Sectionediter::calculate_time(){
double sec_time = 0;
for(int j=0; j<Analog_output_channel+Digital_output_channel; j++){
double channel_time = 0;
for(int k=0; k<current[j]->size(); k++){
double seq_time = current[j]->at(k)->get_time(current_run);
if(seq_time>0)channel_time += seq_time;
}
cyc[j]->display(channel_time);
if(channel_time>sec_time)sec_time = channel_time;
}
ui->Section_time->display(sec_time);
}
| [
"60519181+liangqibox@users.noreply.github.com"
] | 60519181+liangqibox@users.noreply.github.com |
c422f2d747f09ee75b708106c6ea62bf1ba0c38e | 428d2b6a65b96db964525b6d4148deb3a67dd3d6 | /include/system/NetworkNamespace.h | 4f41c8ad36451d1cfee73926fb59a8a37e27f4c3 | [
"Apache-2.0"
] | permissive | dgoltzsche/faasm | eb0f54ebeee6461d31d7359ba6985d06ca97fda1 | 017df7caadb847d9876a3673ee8943c5ce9dbd1c | refs/heads/master | 2023-06-05T10:20:03.973198 | 2021-03-23T08:31:28 | 2021-03-23T08:31:28 | 312,252,415 | 0 | 0 | Apache-2.0 | 2021-06-22T05:27:17 | 2020-11-12T11:11:34 | C++ | UTF-8 | C++ | false | false | 444 | h | #pragma once
#include <string>
#define BASE_NETNS_NAME "faasmns"
namespace isolation {
enum NetworkIsolationMode
{
ns_off,
ns_on
};
class NetworkNamespace
{
public:
explicit NetworkNamespace(const std::string& name);
void addCurrentThread();
void removeCurrentThread();
const std::string getName();
const NetworkIsolationMode getMode();
private:
std::string name;
NetworkIsolationMode mode;
};
}
| [
"noreply@github.com"
] | dgoltzsche.noreply@github.com |
4a7d8c247ab89e4f8f095c09f5f2fc3bb4cf0449 | 6fb66c4e503d24ab0e52d538da4edf7d0841cecc | /src/test/net_tests.cpp | df4691c644b68352478b551da77f772a0c39bfe2 | [
"MIT"
] | permissive | EnzoNodes/ENZO | 936b0e35a25d3a7f9efbd8b75669c6469cc58e4e | 3f607ab55261ec22a02f3eba4b32699eed187620 | refs/heads/master | 2023-08-12T04:06:36.428514 | 2021-10-12T06:47:57 | 2021-10-12T06:47:57 | 413,684,010 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,341 | cpp | // Copyright (c) 2012-2016 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "addrman.h"
#include "chainparams.h"
#include "hash.h"
#include "net.h"
#include "netbase.h"
#include "serialize.h"
#include "streams.h"
#include "test/test_enzo.h"
#include <string>
#include <boost/test/unit_test.hpp>
class CAddrManSerializationMock : public CAddrMan
{
public:
virtual void Serialize(CDataStream::CBaseDataStream& s) const = 0;
//! Ensure that bucket placement is always the same for testing purposes.
void MakeDeterministic()
{
nKey.SetNull();
SeedInsecureRand(true);
}
};
class CAddrManUncorrupted : public CAddrManSerializationMock
{
public:
void Serialize(CDataStream::CBaseDataStream& s) const
{
CAddrMan::Serialize(s);
}
};
class CAddrManCorrupted : public CAddrManSerializationMock
{
public:
void Serialize(CDataStream::CBaseDataStream& s) const
{
// Produces corrupt output that claims addrman has 20 addrs when it only has one addr.
unsigned char nVersion = 1;
s << nVersion;
s << ((unsigned char)32);
s << nKey;
s << 10; // nNew
s << 10; // nTried
int nUBuckets = ADDRMAN_NEW_BUCKET_COUNT ^ (1 << 30);
s << nUBuckets;
CService serv;
Lookup("252.1.1.1", serv, 7777, false);
CAddress addr = CAddress(serv, NODE_NONE);
CNetAddr resolved;
LookupHost("252.2.2.2", resolved, false);
CAddrInfo info = CAddrInfo(addr, resolved);
s << info;
}
};
CDataStream AddrmanToStream(CAddrManSerializationMock& addrman)
{
CDataStream ssPeersIn(SER_DISK, CLIENT_VERSION);
ssPeersIn << FLATDATA(Params().MessageStart());
ssPeersIn << addrman;
std::string str = ssPeersIn.str();
std::vector<unsigned char> vchData(str.begin(), str.end());
return CDataStream(vchData, SER_DISK, CLIENT_VERSION);
}
BOOST_FIXTURE_TEST_SUITE(net_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(caddrdb_read)
{
CAddrManUncorrupted addrmanUncorrupted;
addrmanUncorrupted.MakeDeterministic();
CService addr1, addr2, addr3;
Lookup("250.7.1.1", addr1, 8333, false);
Lookup("250.7.2.2", addr2, 9999, false);
Lookup("250.7.3.3", addr3, 9999, false);
// Add three addresses to new table.
CService source;
Lookup("252.5.1.1", source, 8333, false);
addrmanUncorrupted.Add(CAddress(addr1, NODE_NONE), source);
addrmanUncorrupted.Add(CAddress(addr2, NODE_NONE), source);
addrmanUncorrupted.Add(CAddress(addr3, NODE_NONE), source);
// Test that the de-serialization does not throw an exception.
CDataStream ssPeers1 = AddrmanToStream(addrmanUncorrupted);
bool exceptionThrown = false;
CAddrMan addrman1;
BOOST_CHECK(addrman1.size() == 0);
try {
unsigned char pchMsgTmp[4];
ssPeers1 >> FLATDATA(pchMsgTmp);
ssPeers1 >> addrman1;
} catch (const std::exception& e) {
exceptionThrown = true;
}
BOOST_CHECK(addrman1.size() == 3);
BOOST_CHECK(exceptionThrown == false);
// Test that CAddrDB::Read creates an addrman with the correct number of addrs.
CDataStream ssPeers2 = AddrmanToStream(addrmanUncorrupted);
CAddrMan addrman2;
CAddrDB adb;
BOOST_CHECK(addrman2.size() == 0);
adb.Read(addrman2, ssPeers2);
BOOST_CHECK(addrman2.size() == 3);
}
BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted)
{
CAddrManCorrupted addrmanCorrupted;
addrmanCorrupted.MakeDeterministic();
// Test that the de-serialization of corrupted addrman throws an exception.
CDataStream ssPeers1 = AddrmanToStream(addrmanCorrupted);
bool exceptionThrown = false;
CAddrMan addrman1;
BOOST_CHECK(addrman1.size() == 0);
try {
unsigned char pchMsgTmp[4];
ssPeers1 >> FLATDATA(pchMsgTmp);
ssPeers1 >> addrman1;
} catch (const std::exception& e) {
exceptionThrown = true;
}
// Even through de-serialization failed addrman is not left in a clean state.
BOOST_CHECK(addrman1.size() == 1);
BOOST_CHECK(exceptionThrown);
// Test that CAddrDB::Read leaves addrman in a clean state if de-serialization fails.
CDataStream ssPeers2 = AddrmanToStream(addrmanCorrupted);
CAddrMan addrman2;
CAddrDB adb;
BOOST_CHECK(addrman2.size() == 0);
adb.Read(addrman2, ssPeers2);
BOOST_CHECK(addrman2.size() == 0);
}
BOOST_AUTO_TEST_CASE(cnode_simple_test)
{
SOCKET hSocket = INVALID_SOCKET;
NodeId id = 0;
int height = 0;
in_addr ipv4Addr;
ipv4Addr.s_addr = 0xa0b0c001;
CAddress addr = CAddress(CService(ipv4Addr, 7777), NODE_NETWORK);
std::string pszDest = "";
bool fInboundIn = false;
// Test that fFeeler is false by default.
std::unique_ptr<CNode> pnode1(new CNode(id++, NODE_NETWORK, height, hSocket, addr, 0, 0, pszDest, fInboundIn));
BOOST_CHECK(pnode1->fInbound == false);
BOOST_CHECK(pnode1->fFeeler == false);
fInboundIn = true;
std::unique_ptr<CNode> pnode2(new CNode(id++, NODE_NETWORK, height, hSocket, addr, 1, 1, pszDest, fInboundIn));
BOOST_CHECK(pnode2->fInbound == true);
BOOST_CHECK(pnode2->fFeeler == false);
}
BOOST_AUTO_TEST_SUITE_END()
| [
"82832566+EnzoNodes@users.noreply.github.com"
] | 82832566+EnzoNodes@users.noreply.github.com |
460637cbfb52d750b8671cd64b33aae9d08fcb9f | 9ac887713ffc194682d6f088b690b76b8525b260 | /books/pc_data_structure/appendix/boat_travel.cpp | 1cf6e679b971982f7d2231cdbc275b4ca340e3b9 | [] | no_license | ganmacs/playground | 27b3e0625796f6ee5324a70b06d3d3e5c77e1511 | a007f9fabc337561784b2a6040b5be77361460f8 | refs/heads/master | 2022-05-25T05:52:49.583453 | 2022-05-09T03:39:12 | 2022-05-09T04:06:15 | 36,348,909 | 6 | 0 | null | 2019-06-18T07:23:16 | 2015-05-27T06:50:59 | C++ | UTF-8 | C++ | false | false | 1,327 | cpp | #include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef pair<int, int> P;
static const int MAX = 110;
static const int INF = 1000010;
int n;
int main() {
int n, m, a, b, c, d;
while (cin >> n >> m, n || m) {
vector<P> ils[MAX];
int dist[MAX];
for (int i = 0; i < m; i++) {
cin >> a;
if (a == 0) {
cin >> b >> c;
b--; c--;
// dijkstra
bool vist[MAX];
fill_n(dist, n, INF);
fill_n(vist, n, false);
dist[b] = 0;
priority_queue<P> que;
que.push(P(0, b));
while (!que.empty()) {
P p = que.top(); que.pop();
int v = p.second;
if (dist[v] < p.first) continue;
for (int i = 0; i < (int)ils[v].size(); i++) {
P vv = ils[v][i];
if (dist[v] + vv.first < dist[vv.second]) {
dist[vv.second] = dist[p.second] + vv.first;
que.push(vv);
}
}
}
cout << (dist[c] == INF ? -1 : dist[c]) << endl;
} else {
cin >> b >> c >> d;
b--;c--;
ils[b].push_back(P(d, c));
ils[c].push_back(P(d, b));
}
}
}
}
| [
"ganmacs@gmail.com"
] | ganmacs@gmail.com |
c08b9be8234e559fd1cf352960787f96a621df2d | 16044e3f6f48f33a270867eef13d41b6a0617186 | /boost/library/boost/asio/ip/basic_resolver.hpp | 56d5ed918656574effbeb1ee54c343fe553b4079 | [] | no_license | esoobservatory/fitsliberator | 47350be9b99ff7ba3c16bae9766621d1f324d2ef | 02e11d9bd718dfb68b3d729cafc49915c8962b8e | refs/heads/master | 2021-01-18T16:30:10.922487 | 2015-08-19T15:14:58 | 2015-08-19T15:14:58 | 41,041,169 | 38 | 11 | null | null | null | null | UTF-8 | C++ | false | false | 8,401 | hpp | //
// basic_resolver.hpp
// ~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// 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_ASIO_IP_BASIC_RESOLVER_HPP
#define BOOST_ASIO_IP_BASIC_RESOLVER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/push_options.hpp>
#include <boost/asio/basic_io_object.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/ip/resolver_service.hpp>
#include <boost/asio/detail/throw_error.hpp>
namespace boost {
namespace asio {
namespace ip {
/// Provides endpoint resolution functionality.
/**
* The basic_resolver class template provides the ability to resolve a query
* to a list of endpoints.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
template <typename InternetProtocol,
typename ResolverService = resolver_service<InternetProtocol> >
class basic_resolver
: public basic_io_object<ResolverService>
{
public:
/// The protocol type.
typedef InternetProtocol protocol_type;
/// The endpoint type.
typedef typename InternetProtocol::endpoint endpoint_type;
/// The query type.
typedef typename InternetProtocol::resolver_query query;
/// The iterator type.
typedef typename InternetProtocol::resolver_iterator iterator;
/// Constructor.
/**
* This constructor creates a basic_resolver.
*
* @param io_service The io_service object that the resolver will use to
* dispatch handlers for any asynchronous operations performed on the timer.
*/
explicit basic_resolver(boost::asio::io_service& io_service)
: basic_io_object<ResolverService>(io_service)
{
}
/// Cancel any asynchronous operations that are waiting on the resolver.
/**
* This function forces the completion of any pending asynchronous
* operations on the host resolver. The handler for each cancelled operation
* will be invoked with the boost::asio::error::operation_aborted error code.
*/
void cancel()
{
return this->service.cancel(this->implementation);
}
/// Resolve a query to a list of entries.
/**
* This function is used to resolve a query into a list of endpoint entries.
*
* @param q A query object that determines what endpoints will be returned.
*
* @returns A forward-only iterator that can be used to traverse the list
* of endpoint entries.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note A default constructed iterator represents the end of the list.
*
* A successful call to this function is guaranteed to return at least one
* entry.
*/
iterator resolve(const query& q)
{
boost::system::error_code ec;
iterator i = this->service.resolve(this->implementation, q, ec);
boost::asio::detail::throw_error(ec);
return i;
}
/// Resolve a query to a list of entries.
/**
* This function is used to resolve a query into a list of endpoint entries.
*
* @param q A query object that determines what endpoints will be returned.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns A forward-only iterator that can be used to traverse the list
* of endpoint entries. Returns a default constructed iterator if an error
* occurs.
*
* @note A default constructed iterator represents the end of the list.
*
* A successful call to this function is guaranteed to return at least one
* entry.
*/
iterator resolve(const query& q, boost::system::error_code& ec)
{
return this->service.resolve(this->implementation, q, ec);
}
/// Asynchronously resolve a query to a list of entries.
/**
* This function is used to asynchronously resolve a query into a list of
* endpoint entries.
*
* @param q A query object that determines what endpoints will be returned.
*
* @param handler The handler to be called when the resolve operation
* completes. Copies will be made of the handler as required. The function
* signature of the handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* resolver::iterator iterator // Forward-only iterator that can
* // be used to traverse the list
* // of endpoint entries.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
* boost::asio::io_service::post().
*
* @note A default constructed iterator represents the end of the list.
*
* A successful resolve operation is guaranteed to pass at least one entry to
* the handler.
*/
template <typename ResolveHandler>
void async_resolve(const query& q, ResolveHandler handler)
{
return this->service.async_resolve(this->implementation, q, handler);
}
/// Resolve an endpoint to a list of entries.
/**
* This function is used to resolve an endpoint into a list of endpoint
* entries.
*
* @param e An endpoint object that determines what endpoints will be
* returned.
*
* @returns A forward-only iterator that can be used to traverse the list
* of endpoint entries.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note A default constructed iterator represents the end of the list.
*
* A successful call to this function is guaranteed to return at least one
* entry.
*/
iterator resolve(const endpoint_type& e)
{
boost::system::error_code ec;
iterator i = this->service.resolve(this->implementation, e, ec);
boost::asio::detail::throw_error(ec);
return i;
}
/// Resolve an endpoint to a list of entries.
/**
* This function is used to resolve an endpoint into a list of endpoint
* entries.
*
* @param e An endpoint object that determines what endpoints will be
* returned.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns A forward-only iterator that can be used to traverse the list
* of endpoint entries. Returns a default constructed iterator if an error
* occurs.
*
* @note A default constructed iterator represents the end of the list.
*
* A successful call to this function is guaranteed to return at least one
* entry.
*/
iterator resolve(const endpoint_type& e, boost::system::error_code& ec)
{
return this->service.resolve(this->implementation, e, ec);
}
/// Asynchronously resolve an endpoint to a list of entries.
/**
* This function is used to asynchronously resolve an endpoint into a list of
* endpoint entries.
*
* @param e An endpoint object that determines what endpoints will be
* returned.
*
* @param handler The handler to be called when the resolve operation
* completes. Copies will be made of the handler as required. The function
* signature of the handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* resolver::iterator iterator // Forward-only iterator that can
* // be used to traverse the list
* // of endpoint entries.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
* boost::asio::io_service::post().
*
* @note A default constructed iterator represents the end of the list.
*
* A successful resolve operation is guaranteed to pass at least one entry to
* the handler.
*/
template <typename ResolveHandler>
void async_resolve(const endpoint_type& e, ResolveHandler handler)
{
return this->service.async_resolve(this->implementation, e, handler);
}
};
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_BASIC_RESOLVER_HPP
| [
"kaspar@localhost"
] | kaspar@localhost |
d288698bf33d3271c0498e9679f2e839f8e42a19 | 5b7f5229df3e1f61eb264df8aa9c67fbcccb6ba0 | /cocos2d/extensions/Particle3D/PU/CCPUScaleVelocityAffector.cpp | cf3612684645f9173977dbd285102d7572d573cd | [
"MIT"
] | permissive | IoriKobayashi/BluetoothChecker | cac73371b264522210b181b13e6a9ea555e9f4e8 | fb0127d756a2794be89e5a98b031109cdabfc977 | refs/heads/main | 2023-03-29T21:16:08.104908 | 2021-04-06T13:19:22 | 2021-04-06T13:19:22 | 354,246,675 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,411 | cpp | /****************************************************************************
Copyright (C) 2013 Henry van Merode. All rights reserved.
Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
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.
****************************************************************************/
#include "CCPUScaleVelocityAffector.h"
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
NS_CC_BEGIN
// Constants
const float PUScaleVelocityAffector::DEFAULT_VELOCITY_SCALE = 1.0f;
//-----------------------------------------------------------------------
PUScaleVelocityAffector::PUScaleVelocityAffector(void) :
PUAffector(),
_sinceStartSystem(false),
_stopAtFlip(false)
{
_dynScaleVelocity = new (std::nothrow) PUDynamicAttributeFixed();
(static_cast<PUDynamicAttributeFixed*>(_dynScaleVelocity))->setValue(DEFAULT_VELOCITY_SCALE);
}
//-----------------------------------------------------------------------
PUScaleVelocityAffector::~PUScaleVelocityAffector(void)
{
if (_dynScaleVelocity)
{
CC_SAFE_DELETE(_dynScaleVelocity);
}
}
//-----------------------------------------------------------------------
void PUScaleVelocityAffector::updatePUAffector( PUParticle3D *particle, float deltaTime )
{
//for (auto iter : _particleSystem->getParticles())
{
// PUParticle3D *particle = iter;
float ds = 0;
if (_sinceStartSystem)
{
// If control points are used (curved type), the first value of each control point is seconds from the start of the system
ds = deltaTime * _dynamicAttributeHelper.calculate(_dynScaleVelocity, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart());
}
else
{
// If control points are used (curved type), the first value of each control point is the fraction of the particle lifetime [0..1]
ds = deltaTime * _dynamicAttributeHelper.calculate(_dynScaleVelocity, particle->timeFraction);
}
float length = particle->direction.length(); // Use length for a better delta direction value
Vec3 calculated = particle->direction;
calculated.x += ds * (particle->direction.x / length);
calculated.y += ds * (particle->direction.y / length);
calculated.z += ds * (particle->direction.z / length);
if (_stopAtFlip)
{
if ((calculated.x > 0.0f && particle->direction.x < 0.0f) ||
(calculated.y > 0.0f && particle->direction.y < 0.0f) ||
(calculated.z > 0.0f && particle->direction.z < 0.0f) ||
(calculated.x < 0.0f && particle->direction.x > 0.0f) ||
(calculated.y < 0.0f && particle->direction.y > 0.0f) ||
(calculated.z < 0.0f && particle->direction.z > 0.0f))
return;
}
particle->direction = calculated;
}
}
//-----------------------------------------------------------------------
void PUScaleVelocityAffector::setDynScaleVelocity(PUDynamicAttribute* dynScaleVelocity)
{
if (_dynScaleVelocity)
CC_SAFE_DELETE(_dynScaleVelocity);
_dynScaleVelocity = dynScaleVelocity;
}
//-----------------------------------------------------------------------
void PUScaleVelocityAffector::resetDynScaleVelocity(bool resetToDefault)
{
if (resetToDefault)
{
CC_SAFE_DELETE(_dynScaleVelocity);
_dynScaleVelocity = new (std::nothrow) PUDynamicAttributeFixed();
(static_cast<PUDynamicAttributeFixed*>(_dynScaleVelocity))->setValue(DEFAULT_VELOCITY_SCALE);
}
}
PUScaleVelocityAffector* PUScaleVelocityAffector::create()
{
auto psva = new (std::nothrow) PUScaleVelocityAffector();
psva->autorelease();
return psva;
}
void PUScaleVelocityAffector::copyAttributesTo( PUAffector* affector )
{
PUAffector::copyAttributesTo(affector);
PUScaleVelocityAffector* scaleVelocityAffector = static_cast<PUScaleVelocityAffector*>(affector);
scaleVelocityAffector->setDynScaleVelocity(getDynScaleVelocity()->clone());
scaleVelocityAffector->_sinceStartSystem = _sinceStartSystem;
scaleVelocityAffector->_stopAtFlip = _stopAtFlip;
}
NS_CC_END
| [
"iori.kobayashi.mail@gmail.com"
] | iori.kobayashi.mail@gmail.com |
f8086b23337551f2996f4d7fcf25fb6346b8e96a | 5d262c088ed241cdefde532dd12a2b0040348bcf | /6.Haizei_oj/83.cpp | 6b3fc1dd9f140c356e5083e1b1af8f4a3834c43a | [] | no_license | loveskycloud/LeetCode | a6acd0a41cb0adb6543a42cee213ea51d99d30a9 | 40aa34f177fa639d8d05bc6b4629fc9e32d0b53a | refs/heads/master | 2021-12-14T23:16:58.126192 | 2021-12-13T02:43:55 | 2021-12-13T02:43:55 | 242,975,740 | 1 | 1 | null | 2021-12-13T02:43:56 | 2020-02-25T10:45:41 | C++ | UTF-8 | C++ | false | false | 394 | cpp | #include <iostream>
using namespace std;
int func(int s, int left, int cnt) {
if (left == 0) {
if (cnt == 0) {
return 1;
}
return 0;
}
int ans = 0;
for (int i = s; i <= left; i++) {
ans += func(i, left - i, cnt - 1);
}
return ans;
}
int main()
{
int n, m;
cin >> n >> m;
cout << func(1, n, m);
return 0;
}
| [
"896275569@qq.com"
] | 896275569@qq.com |
a7c3fde2a0fd7d831cd77547a99b639cb5f214b7 | c238d370c8259897b8c3b95a12c81e4d8691de64 | /src/rx/render/backend/gl3.cpp | b7958b642fcb35324527b425c9468effb9daf012 | [
"MIT"
] | permissive | ttvd/rex | 4f66966166c422b7c7c356e764bdff3fcf11e800 | bfe49a11e255e7be9e739641924adad2fd82a861 | refs/heads/main | 2022-11-25T23:04:23.994615 | 2020-08-04T13:55:55 | 2020-08-04T13:55:55 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 75,798 | cpp | #include "rx/render/backend/gl.h"
#include "rx/render/backend/gl3.h"
#include "rx/render/frontend/target.h"
#include "rx/render/frontend/program.h"
#include "rx/core/algorithm/max.h"
#include "rx/core/math/log2.h"
#include "rx/core/profiler.h"
#include "rx/core/log.h"
#include "rx/core/abort.h"
namespace Rx::Render::Backend {
RX_LOG("render/gl3", logger);
// 16MiB buffer slab size for unspecified buffer sizes
static constexpr const Size k_buffer_slab_size{16 << 20};
// buffers
static void (GLAPIENTRYP pglGenBuffers)(GLsizei, GLuint*);
static void (GLAPIENTRYP pglDeleteBuffers)(GLsizei, const GLuint*);
static void (GLAPIENTRYP pglBufferData)(GLenum, GLsizeiptr, const GLvoid*, GLenum);
static void (GLAPIENTRYP pglBufferSubData)(GLenum, GLintptr, GLsizeiptr, const GLvoid*);
static void (GLAPIENTRYP pglBindBuffer)(GLenum, GLuint);
// vertex arrays
static void (GLAPIENTRYP pglGenVertexArrays)(GLsizei, GLuint*);
static void (GLAPIENTRYP pglDeleteVertexArrays)(GLsizei, const GLuint*);
static void (GLAPIENTRYP pglEnableVertexAttribArray)(GLuint);
static void (GLAPIENTRYP pglVertexAttribPointer)(GLuint, GLuint, GLenum, GLboolean, GLsizei, const GLvoid*);
static void (GLAPIENTRYP pglBindVertexArray)(GLuint);
static void (GLAPIENTRYP pglVertexAttribDivisor)(GLuint, GLuint);
// textures
static void (GLAPIENTRYP pglGenTextures)(GLsizei, GLuint* );
static void (GLAPIENTRYP pglDeleteTextures)(GLsizei, const GLuint*);
static void (GLAPIENTRYP pglTexImage1D)(GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, const GLvoid*);
static void (GLAPIENTRYP pglTexImage2D)(GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid*);
static void (GLAPIENTRYP pglTexImage3D)(GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid*);
static void (GLAPIENTRYP pglTexSubImage1D)(GLenum, GLint, GLint, GLsizei, GLenum, GLenum, const GLvoid*);
static void (GLAPIENTRYP pglTexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid*);
static void (GLAPIENTRYP pglTexSubImage3D)(GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid*);
static void (GLAPIENTRYP pglCompressedTexImage1D)(GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid*);
static void (GLAPIENTRYP pglCompressedTexImage2D)(GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*);
static void (GLAPIENTRYP pglCompressedTexImage3D)(GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*);
static void (GLAPIENTRYP pglTexParameteri)(GLenum, GLenum, GLint);
static void (GLAPIENTRYP pglTexParameteriv)(GLenum, GLenum, const GLint*);
static void (GLAPIENTRYP pglTexParameterf)(GLenum, GLenum, GLfloat);
static void (GLAPIENTRYP pglBindTexture)(GLuint, GLuint);
static void (GLAPIENTRYP pglActiveTexture)(GLenum);
static void (GLAPIENTRYP pglPixelStorei)(GLenum, GLint);
// framebuffers
static void (GLAPIENTRYP pglGenFramebuffers)(GLsizei, GLuint*);
static void (GLAPIENTRYP pglDeleteFramebuffers)(GLsizei, const GLuint*);
static void (GLAPIENTRYP pglFramebufferTexture2D)(GLenum, GLenum, GLenum, GLuint, GLint);
static void (GLAPIENTRYP pglBindFramebuffer)(GLenum, GLuint);
static void (GLAPIENTRYP pglDrawBuffers)(GLsizei, const GLenum*);
static void (GLAPIENTRYP pglDrawBuffer)(GLenum);
static void (GLAPIENTRYP pglReadBuffer)(GLenum);
static void (GLAPIENTRYP pglBlitFramebuffer)(GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum);
// shaders and programs
static void (GLAPIENTRYP pglShaderSource)(GLuint, GLsizei, const GLchar**, const GLint*);
static GLuint (GLAPIENTRYP pglCreateShader)(GLenum);
static void (GLAPIENTRYP pglDeleteShader)(GLuint);
static void (GLAPIENTRYP pglCompileShader)(GLuint);
static void (GLAPIENTRYP pglGetShaderiv)(GLuint, GLenum, GLint*);
static void (GLAPIENTRYP pglGetShaderInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*);
static void (GLAPIENTRYP pglGetProgramiv)(GLuint, GLenum, GLint*);
static void (GLAPIENTRYP pglGetProgramInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*);
static void (GLAPIENTRYP pglAttachShader)(GLuint, GLuint );
static void (GLAPIENTRYP pglLinkProgram)(GLuint);
static void (GLAPIENTRYP pglDetachShader)(GLuint, GLuint);
static GLuint (GLAPIENTRYP pglCreateProgram)();
static void (GLAPIENTRYP pglDeleteProgram)(GLuint);
static void (GLAPIENTRYP pglUseProgram)(GLuint);
static GLuint (GLAPIENTRYP pglGetUniformLocation)(GLuint, const GLchar*);
//static void (GLAPIENTRYP pglBindAttribLocation)(GLuint, GLuint, const char*);
//static void (GLAPIENTRYP pglBindFragDataLocation)(GLuint, GLuint, const char*);
static void (GLAPIENTRYP pglUniform1i)(GLint, GLint);
static void (GLAPIENTRYP pglUniform2iv)(GLint, GLsizei, const GLint*);
static void (GLAPIENTRYP pglUniform3iv)(GLint, GLsizei, const GLint*);
static void (GLAPIENTRYP pglUniform4iv)(GLint, GLsizei, const GLint*);
static void (GLAPIENTRYP pglUniform1fv)(GLint, GLsizei, const GLfloat*);
static void (GLAPIENTRYP pglUniform2fv)(GLint, GLsizei, const GLfloat*);
static void (GLAPIENTRYP pglUniform3fv)(GLint, GLsizei, const GLfloat*);
static void (GLAPIENTRYP pglUniform4fv)(GLint, GLsizei, const GLfloat*);
static void (GLAPIENTRYP pglUniformMatrix3fv)(GLint, GLsizei, GLboolean, const GLfloat*);
static void (GLAPIENTRYP pglUniformMatrix4fv)(GLint, GLsizei, GLboolean, const GLfloat*);
static void (GLAPIENTRYP pglUniformMatrix3x4fv)(GLint, GLsizei, GLboolean, const GLfloat*);
// state
static void (GLAPIENTRYP pglEnable)(GLenum);
static void (GLAPIENTRYP pglDisable)(GLenum);
static void (GLAPIENTRYP pglScissor)(GLint, GLint, GLsizei, GLsizei);
static void (GLAPIENTRYP pglColorMask)(GLboolean, GLboolean, GLboolean, GLboolean);
static void (GLAPIENTRYP pglBlendFuncSeparate)( GLenum, GLenum, GLenum, GLenum);
static void (GLAPIENTRYP pglDepthFunc)(GLenum);
static void (GLAPIENTRYP pglDepthMask)(GLboolean);
static void (GLAPIENTRYP pglFrontFace)(GLenum);
static void (GLAPIENTRYP pglCullFace)(GLenum);
static void (GLAPIENTRYP pglStencilMask)(GLuint);
static void (GLAPIENTRYP pglStencilFunc)(GLenum, GLint, GLuint);
static void (GLAPIENTRYP pglStencilOpSeparate)(GLenum, GLenum, GLenum, GLenum);
static void (GLAPIENTRYP pglPolygonMode)(GLenum, GLenum);
static void (GLAPIENTRYP pglViewport)(GLint, GLint, GLsizei, GLsizei);
static void (GLAPIENTRYP pglClearBufferfi)(GLenum, GLint, GLfloat, GLint);
static void (GLAPIENTRYP pglClearBufferfv)(GLenum, GLint, const GLfloat*);
static void (GLAPIENTRYP pglClearBufferiv)(GLenum, GLint, const GLint*);
// query
static void (GLAPIENTRYP pglGetIntegerv)(GLenum, GLint*);
static void (GLAPIENTRYP pglGetFloatv)(GLenum, GLfloat*);
static const GLubyte* (GLAPIENTRYP pglGetString)(GLenum);
static const GLubyte* (GLAPIENTRYP pglGetStringi)(GLenum, GLuint);
// draw calls
static void (GLAPIENTRYP pglDrawArrays)(GLenum, GLint, GLsizei);
static void (GLAPIENTRYP pglDrawArraysInstanced)(GLenum, GLint, GLsizei, GLsizei);
static void (GLAPIENTRYP pglDrawElements)(GLenum, GLsizei, GLenum, const GLvoid*);
static void (GLAPIENTRYP pglDrawElementsBaseVertex)(GLenum, GLsizei, GLenum, const GLvoid*, GLint);
static void (GLAPIENTRYP pglDrawElementsInstanced)(GLenum, GLsizei, GLenum, const GLvoid*, GLsizei);
static void (GLAPIENTRYP pglDrawElementsInstancedBaseVertex)(GLenum, GLsizei, GLenum, const GLvoid*, GLsizei, GLint);
// flush
static void (GLAPIENTRYP pglFinish)(void);
// GL_ARB_base_instance
static void (GLAPIENTRYP pglDrawArraysInstancedBaseInstance)(GLenum, GLint, GLsizei, GLsizei, GLuint);
static void (GLAPIENTRYP pglDrawElementsInstancedBaseInstance)(GLenum, GLsizei, GLenum, const GLvoid*, GLsizei, GLuint);
static void (GLAPIENTRYP pglDrawElementsInstancedBaseVertexBaseInstance)(GLenum, GLsizei, GLenum, const GLvoid*, GLsizei, GLint, GLuint);
template<typename F>
static void fetch(const char* _name, F& function_) {
auto address = SDL_GL_GetProcAddress(_name);
logger->verbose("loaded %08p '%s'", address, _name);
*reinterpret_cast<void**>(&function_) = address;
}
namespace detail_gl3 {
struct buffer {
buffer() {
pglGenBuffers(3, bo);
pglGenVertexArrays(1, &va);
}
~buffer() {
pglDeleteBuffers(3, bo);
pglDeleteVertexArrays(1, &va);
}
GLuint bo[3];
GLuint va;
Size elements_size;
Size vertices_size;
Size instances_size;
};
struct target {
target()
: owned{true}
{
pglGenFramebuffers(1, &fbo);
}
target(GLuint _fbo)
: fbo{_fbo}
, owned{false}
{
}
~target() {
if (owned) {
pglDeleteFramebuffers(1, &fbo);
}
}
GLuint fbo;
bool owned;
Frontend::Buffers draw_buffers;
Frontend::Buffers read_buffers;
};
struct program {
program() {
handle = pglCreateProgram();
}
~program() {
pglDeleteProgram(handle);
}
GLuint handle;
Vector<GLint> uniforms;
};
struct texture1D {
texture1D() {
pglGenTextures(1, &tex);
}
~texture1D() {
pglDeleteTextures(1, &tex);
}
GLuint tex;
};
struct texture2D {
texture2D() {
pglGenTextures(1, &tex);
}
~texture2D() {
pglDeleteTextures(1, &tex);
}
GLuint tex;
};
struct texture3D {
texture3D() {
pglGenTextures(1, &tex);
}
~texture3D() {
pglDeleteTextures(1, &tex);
}
GLuint tex;
};
struct textureCM {
textureCM() {
pglGenTextures(1, &tex);
}
~textureCM() {
pglDeleteTextures(1, &tex);
}
GLuint tex;
};
struct state
: Frontend::State
{
state(SDL_GLContext _context)
: m_color_mask{0xff}
, m_empty_vao{0}
, m_bound_vbo{0}
, m_bound_ebo{0}
, m_bound_vao{0}
, m_bound_draw_fbo{0}
, m_bound_read_fbo{0}
, m_bound_program{0}
, m_swap_chain_fbo{0}
, m_active_texture{0}
, m_context{_context}
{
memset(m_texture_units, 0, sizeof m_texture_units);
// There's no unsigned variant of glGetIntegerv
GLint swap_chain_fbo;
pglGetIntegerv(GL_FRAMEBUFFER_BINDING, &swap_chain_fbo);
m_swap_chain_fbo = static_cast<GLuint>(swap_chain_fbo);
pglEnable(GL_CULL_FACE);
pglEnable(GL_PROGRAM_POINT_SIZE);
pglCullFace(GL_BACK);
pglFrontFace(GL_CW);
pglDepthFunc(GL_LEQUAL);
pglDisable(GL_MULTISAMPLE);
pglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pglGenVertexArrays(1, &m_empty_vao);
const auto vendor{reinterpret_cast<const char*>(pglGetString(GL_VENDOR))};
const auto renderer{reinterpret_cast<const char*>(pglGetString(GL_RENDERER))};
const auto version{reinterpret_cast<const char*>(pglGetString(GL_VERSION))};
logger->info("GL %s %s %s", vendor, version, renderer);
GLint extensions{0};
pglGetIntegerv(GL_NUM_EXTENSIONS, &extensions);
bool has_arb_base_instance = false;
for (GLint i{0}; i < extensions; i++) {
const auto name = reinterpret_cast<const char*>(pglGetStringi(GL_EXTENSIONS, i));
logger->verbose("extension '%s' supported", name);
// GL_ARB_base_instance
if (!strcmp(name, "GL_ARB_base_instance")) {
fetch("glDrawArraysInstancedBaseInstance", pglDrawArraysInstancedBaseInstance);
fetch("glDrawElementsInstancedBaseInstance", pglDrawElementsInstancedBaseInstance);
fetch("glDrawElementsInstancedBaseVertexBaseInstance", pglDrawElementsInstancedBaseVertexBaseInstance);
has_arb_base_instance = true;
}
}
if (!has_arb_base_instance) {
abort("GPU does not support GL_ARB_base_instance");
}
}
~state() {
pglDeleteVertexArrays(1, &m_empty_vao);
SDL_GL_DeleteContext(m_context);
}
void use_enable(GLenum _thing, bool _enable) {
if (_enable) {
pglEnable(_thing);
} else {
pglDisable(_thing);
}
}
void use_state(const Frontend::State* _render_state) {
RX_PROFILE_CPU("use_state");
const auto& scissor{_render_state->scissor};
const auto& blend{_render_state->blend};
const auto& cull{_render_state->cull};
const auto& stencil{_render_state->stencil};
const auto& polygon{_render_state->polygon};
const auto& depth{_render_state->depth};
const auto& viewport{_render_state->viewport};
if (this->scissor != scissor) {
const auto enabled{scissor.enabled()};
const auto offset{scissor.offset()};
const auto size{scissor.size()};
if (this->scissor.enabled() != enabled) {
use_enable(GL_SCISSOR_TEST, enabled);
this->scissor.record_enable(enabled);
}
if (enabled) {
if (this->scissor.offset() != offset || this->scissor.size() != size) {
pglScissor(offset.x, offset.y, size.w, size.h);
this->scissor.record_offset(offset);
this->scissor.record_size(size);
}
}
}
if (this->blend != blend) {
const auto enabled{blend.enabled()};
const auto color_src_factor{blend.color_src_factor()};
const auto color_dst_factor{blend.color_dst_factor()};
const auto alpha_src_factor{blend.alpha_src_factor()};
const auto alpha_dst_factor{blend.alpha_dst_factor()};
const auto write_mask{blend.write_mask()};
if (this->blend.enabled() != enabled) {
use_enable(GL_BLEND, enabled);
this->blend.record_enable(enabled);
}
if (enabled) {
if (this->blend.write_mask() != write_mask) {
if (write_mask != m_color_mask) {
const bool r{!!(write_mask & (1 << 0))};
const bool g{!!(write_mask & (1 << 1))};
const bool b{!!(write_mask & (1 << 2))};
const bool a{!!(write_mask & (1 << 3))};
pglColorMask(r, g, b, a);
m_color_mask = write_mask;
this->blend.record_write_mask(write_mask);
}
}
if (this->blend.color_src_factor() != color_src_factor ||
this->blend.color_dst_factor() != color_dst_factor ||
this->blend.alpha_src_factor() != alpha_src_factor ||
this->blend.alpha_dst_factor() != alpha_dst_factor)
{
pglBlendFuncSeparate(
convert_blend_factor(color_src_factor),
convert_blend_factor(color_dst_factor),
convert_blend_factor(alpha_src_factor),
convert_blend_factor(alpha_dst_factor));
this->blend.record_color_blend_factors(color_src_factor, color_dst_factor);
this->blend.record_alpha_blend_factors(alpha_src_factor, alpha_dst_factor);
}
}
}
if (this->depth != depth) {
const auto test{depth.test()};
const auto write{depth.write()};
if (this->depth.test() != test) {
use_enable(GL_DEPTH_TEST, test);
this->depth.record_test(test);
}
if (test) {
if (this->depth.write() != write) {
pglDepthMask(write ? GL_TRUE : GL_FALSE);
this->depth.record_write(write);
}
}
}
if (this->cull != cull) {
const auto front_face{cull.front_face()};
const auto cull_face{cull.cull_face()};
const auto enabled{cull.enabled()};
if (this->cull.enabled() != enabled) {
use_enable(GL_CULL_FACE, enabled);
this->cull.record_enable(enabled);
}
if (enabled) {
if (this->cull.front_face() != front_face) {
switch (front_face) {
case Frontend::CullState::FrontFaceType::k_clock_wise:
pglFrontFace(GL_CW);
break;
case Frontend::CullState::FrontFaceType::k_counter_clock_wise:
pglFrontFace(GL_CCW);
break;
}
this->cull.record_front_face(front_face);
}
if (this->cull.cull_face() != cull_face) {
switch (cull_face) {
case Frontend::CullState::CullFaceType::k_front:
pglCullFace(GL_FRONT);
break;
case Frontend::CullState::CullFaceType::k_back:
pglCullFace(GL_BACK);
break;
}
this->cull.record_cull_face(cull_face);
}
}
}
if (this->stencil != stencil) {
const auto enabled{stencil.enabled()};
const auto write_mask{stencil.write_mask()};
const auto function{stencil.function()};
const auto reference{stencil.reference()};
const auto mask{stencil.mask()};
const auto front_fail_action{stencil.front_fail_action()};
const auto front_depth_fail_action{stencil.front_depth_fail_action()};
const auto front_depth_pass_action{stencil.front_depth_pass_action()};
const auto back_fail_action{stencil.back_fail_action()};
const auto back_depth_fail_action{stencil.back_depth_fail_action()};
const auto back_depth_pass_action{stencil.back_depth_pass_action()};
if (this->stencil.enabled() != enabled) {
use_enable(GL_STENCIL_TEST, enabled);
this->stencil.record_enable(enabled);
}
if (enabled) {
if (this->stencil.write_mask() != write_mask) {
pglStencilMask(write_mask);
this->stencil.record_write_mask(write_mask);
}
if (this->stencil.function() != function ||
this->stencil.reference() != reference ||
this->stencil.mask() != mask)
{
pglStencilFunc(
convert_stencil_function(function),
static_cast<GLint>(reference),
static_cast<GLuint>(mask));
this->stencil.record_function(function);
this->stencil.record_reference(reference);
this->stencil.record_mask(mask);
}
if (this->stencil.front_fail_action() != front_fail_action ||
this->stencil.front_depth_fail_action() != front_depth_fail_action ||
this->stencil.front_depth_pass_action() != front_depth_pass_action)
{
pglStencilOpSeparate(
GL_FRONT,
convert_stencil_operation(front_fail_action),
convert_stencil_operation(front_depth_fail_action),
convert_stencil_operation(front_depth_pass_action));
this->stencil.record_front_fail_action(front_fail_action);
this->stencil.record_front_depth_fail_action(front_depth_fail_action);
this->stencil.record_front_depth_pass_action(front_depth_pass_action);
}
if (this->stencil.back_fail_action() != back_fail_action ||
this->stencil.back_depth_fail_action() != back_depth_fail_action ||
this->stencil.back_depth_pass_action() != back_depth_pass_action)
{
pglStencilOpSeparate(
GL_BACK,
convert_stencil_operation(back_fail_action),
convert_stencil_operation(back_depth_fail_action),
convert_stencil_operation(back_depth_pass_action));
this->stencil.record_back_fail_action(back_fail_action);
this->stencil.record_back_depth_fail_action(back_depth_fail_action);
this->stencil.record_back_depth_pass_action(back_depth_pass_action);
}
}
}
if (this->polygon != polygon) {
const auto mode{polygon.mode()};
pglPolygonMode(GL_FRONT_AND_BACK, convert_polygon_mode(mode));
this->polygon.record_mode(mode);
}
if (this->viewport != viewport) {
const auto& offset{viewport.offset().cast<GLuint>()};
const auto& dimensions{viewport.dimensions().cast<GLsizei>()};
pglViewport(offset.x, offset.y, dimensions.w, dimensions.h);
this->viewport.record_offset(viewport.offset());
this->viewport.record_dimensions(viewport.dimensions());
}
// flush all changes to this for updated hash
flush();
}
void use_draw_target(Frontend::Target* _render_target, const Frontend::Buffers* _draw_buffers) {
RX_PROFILE_CPU("use_draw_target");
auto this_target{reinterpret_cast<target*>(_render_target + 1)};
if (m_bound_draw_fbo != this_target->fbo) {
pglBindFramebuffer(GL_DRAW_FRAMEBUFFER, this_target->fbo);
m_bound_draw_fbo = this_target->fbo;
}
// Changing draw buffers?
if (_draw_buffers && !_render_target->is_swapchain()) {
// The draw buffers changed.
if (this_target->draw_buffers != *_draw_buffers) {
if (_draw_buffers->is_empty()) {
pglDrawBuffer(GL_NONE);
} else {
Vector<GLenum> draw_buffers;
for (Size i{0}; i < _draw_buffers->size(); i++) {
draw_buffers.push_back(GL_COLOR_ATTACHMENT0 + (*_draw_buffers)[i]);
}
pglDrawBuffers(static_cast<GLsizei>(draw_buffers.size()), draw_buffers.data());
}
this_target->draw_buffers = *_draw_buffers;
}
}
}
void use_read_target(Frontend::Target* _render_target, const Frontend::Buffers* _read_buffers) {
RX_PROFILE_CPU("use_read_target");
auto this_target{reinterpret_cast<target*>(_render_target + 1)};
if (m_bound_read_fbo != this_target->fbo) {
pglBindFramebuffer(GL_READ_FRAMEBUFFER, this_target->fbo);
m_bound_read_fbo = this_target->fbo;
}
// Changing read buffer?
if (_read_buffers && !_render_target->is_swapchain()) {
// The read buffer changed.
if (this_target->read_buffers != *_read_buffers) {
if (_read_buffers->is_empty()) {
pglReadBuffer(GL_NONE);
} else {
pglReadBuffer(GL_COLOR_ATTACHMENT0 + _read_buffers->last());
}
}
this_target->read_buffers = *_read_buffers;
}
}
void use_program(const Frontend::Program* _render_program) {
RX_PROFILE_CPU("use_program");
const auto this_program{reinterpret_cast<const program*>(_render_program + 1)};
if (this_program->handle != m_bound_program) {
pglUseProgram(this_program->handle);
m_bound_program = this_program->handle;
}
}
void use_buffer(const Frontend::Buffer* _render_buffer) {
RX_PROFILE_CPU("use_buffer");
if (_render_buffer) {
const auto this_buffer{reinterpret_cast<const buffer*>(_render_buffer + 1)};
if (this_buffer->va != m_bound_vao) {
pglBindVertexArray(this_buffer->va);
m_bound_vao = this_buffer->va;
}
} else if (!m_bound_vao) {
pglBindVertexArray(m_empty_vao);
m_bound_vao = m_empty_vao;
}
}
void use_vbo(GLuint _vbo) {
RX_PROFILE_CPU("use_vbo");
if (m_bound_vbo != _vbo) {
pglBindBuffer(GL_ARRAY_BUFFER, _vbo);
m_bound_vbo = _vbo;
}
}
void use_ebo(GLuint _ebo) {
RX_PROFILE_CPU("use_ebo");
if (m_bound_ebo != _ebo) {
pglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo);
m_bound_ebo = _ebo;
}
}
struct texture_unit {
GLuint texture1D;
GLuint texture2D;
GLuint texture3D;
GLuint textureCM;
};
template<GLuint texture_unit::*name, typename Bt, typename Ft>
void use_texture_template(GLenum _type, const Ft* _render_texture) {
RX_PROFILE_CPU("use_texture");
const auto this_texture{reinterpret_cast<const Bt*>(_render_texture + 1)};
auto& texture_unit{m_texture_units[m_active_texture]};
if (texture_unit.*name != this_texture->tex) {
texture_unit.*name = this_texture->tex;
pglBindTexture(_type, this_texture->tex);
}
}
template<GLuint texture_unit::*name, typename Bt, typename Ft>
void use_active_texture_template(GLenum _type, const Ft* _render_texture, Size _unit) {
const auto this_texture{reinterpret_cast<const Bt*>(_render_texture + 1)};
auto& texture_unit{m_texture_units[_unit]};
if (texture_unit.*name != this_texture->tex) {
if (m_active_texture != _unit) {
pglActiveTexture(static_cast<GLenum>(GL_TEXTURE0 + _unit));
m_active_texture = _unit;
}
texture_unit.*name = this_texture->tex;
pglBindTexture(_type, this_texture->tex);
}
}
template<typename Ft, typename Bt, GLuint texture_unit::*name>
void invalidate_texture_template(const Ft* _render_texture) {
const auto this_texture{reinterpret_cast<const Bt*>(_render_texture + 1)};
for (auto& texture_unit : m_texture_units) {
if (texture_unit.*name == this_texture->tex) {
texture_unit.*name = 0;
}
}
}
void use_active_texture(const Frontend::Texture1D* _render_texture, Size _unit) {
use_active_texture_template<&texture_unit::texture1D, detail_gl3::texture1D>(GL_TEXTURE_1D, _render_texture, _unit);
}
void use_active_texture(const Frontend::Texture2D* _render_texture, Size _unit) {
use_active_texture_template<&texture_unit::texture2D, detail_gl3::texture2D>(GL_TEXTURE_2D, _render_texture, _unit);
}
void use_active_texture(const Frontend::Texture3D* _render_texture, Size _unit) {
use_active_texture_template<&texture_unit::texture1D, detail_gl3::texture1D>(GL_TEXTURE_1D, _render_texture, _unit);
}
void use_active_texture(const Frontend::TextureCM* _render_texture, Size _unit) {
use_active_texture_template<&texture_unit::textureCM, detail_gl3::textureCM>(GL_TEXTURE_CUBE_MAP, _render_texture, _unit);
}
void use_texture(const Frontend::Texture1D* _render_texture) {
use_texture_template<&texture_unit::texture1D, detail_gl3::texture1D>(GL_TEXTURE_1D, _render_texture);
}
void use_texture(const Frontend::Texture2D* _render_texture) {
use_texture_template<&texture_unit::texture2D, detail_gl3::texture2D>(GL_TEXTURE_2D, _render_texture);
}
void use_texture(const Frontend::Texture3D* _render_texture) {
use_texture_template<&texture_unit::texture3D, detail_gl3::texture3D>(GL_TEXTURE_3D, _render_texture);
}
void use_texture(const Frontend::TextureCM* _render_texture) {
use_texture_template<&texture_unit::textureCM, detail_gl3::textureCM>(GL_TEXTURE_CUBE_MAP, _render_texture);
}
void invalidate_texture(const Frontend::Texture1D* _render_texture) {
invalidate_texture_template<Frontend::Texture1D, texture1D, &texture_unit::texture1D>(_render_texture);
}
void invalidate_texture(const Frontend::Texture2D* _render_texture) {
invalidate_texture_template<Frontend::Texture2D, texture2D, &texture_unit::texture2D>(_render_texture);
}
void invalidate_texture(const Frontend::Texture3D* _render_texture) {
invalidate_texture_template<Frontend::Texture3D, texture3D, &texture_unit::texture3D>(_render_texture);
}
void invalidate_texture(const Frontend::TextureCM* _render_texture) {
invalidate_texture_template<Frontend::TextureCM, textureCM, &texture_unit::textureCM>(_render_texture);
}
Uint8 m_color_mask;
GLuint m_empty_vao;
GLuint m_bound_vbo;
GLuint m_bound_ebo;
GLuint m_bound_vao;
GLuint m_bound_draw_fbo;
GLuint m_bound_read_fbo;
GLuint m_bound_program;
GLuint m_swap_chain_fbo;
texture_unit m_texture_units[Frontend::Textures::k_max_textures];
Size m_active_texture;
SDL_GLContext m_context;
};
};
static constexpr const char* inout_to_string(Frontend::Shader::InOutType _type) {
switch (_type) {
case Frontend::Shader::InOutType::k_mat4x4f:
return "mat4";
case Frontend::Shader::InOutType::k_mat3x3f:
return "mat3";
case Frontend::Shader::InOutType::k_vec2f:
return "vec2f";
case Frontend::Shader::InOutType::k_vec3f:
return "vec3f";
case Frontend::Shader::InOutType::k_vec4f:
return "vec4f";
case Frontend::Shader::InOutType::k_vec2i:
return "vec2i";
case Frontend::Shader::InOutType::k_vec3i:
return "vec3i";
case Frontend::Shader::InOutType::k_vec4i:
return "vec4i";
case Frontend::Shader::InOutType::k_vec4b:
return "vec4b";
case Frontend::Shader::InOutType::k_float:
return "float";
}
return nullptr;
}
static constexpr const char* uniform_to_string(Frontend::Uniform::Type _type) {
switch (_type) {
case Frontend::Uniform::Type::k_sampler1D:
return "rx_sampler1D";
case Frontend::Uniform::Type::k_sampler2D:
return "rx_sampler2D";
case Frontend::Uniform::Type::k_sampler3D:
return "rx_sampler3D";
case Frontend::Uniform::Type::k_samplerCM:
return "rx_samplerCM";
case Frontend::Uniform::Type::k_bool:
return "bool";
case Frontend::Uniform::Type::k_int:
return "int";
case Frontend::Uniform::Type::k_float:
return "float";
case Frontend::Uniform::Type::k_vec2i:
return "vec2i";
case Frontend::Uniform::Type::k_vec3i:
return "vec3i";
case Frontend::Uniform::Type::k_vec4i:
return "vec4i";
case Frontend::Uniform::Type::k_vec2f:
return "vec2f";
case Frontend::Uniform::Type::k_vec3f:
return "vec3f";
case Frontend::Uniform::Type::k_vec4f:
return "vec4f";
case Frontend::Uniform::Type::k_mat4x4f:
return "mat4x4f";
case Frontend::Uniform::Type::k_mat3x3f:
return "mat3x3f";
case Frontend::Uniform::Type::k_bonesf:
return "bonesf";
}
return nullptr;
}
static GLuint compile_shader(const Vector<Frontend::Uniform>& _uniforms,
const Frontend::Shader& _shader)
{
// emit prelude to every shader
static constexpr const char* k_prelude =
"#version 330 core\n"
"#define vec2f vec2\n"
"#define vec3f vec3\n"
"#define vec4f vec4\n"
"#define vec2i ivec2\n"
"#define vec3i ivec3\n"
"#define vec4i ivec4\n"
"#define vec4b vec4\n"
"#define mat3x3f mat3\n"
"#define mat4x4f mat4\n"
"#define mat3x4f mat3x4\n"
"#define bonesf mat3x4f[80]\n"
"#define rx_sampler1D sampler1D\n"
"#define rx_sampler2D sampler2D\n"
"#define rx_sampler3D sampler3D\n"
"#define rx_samplerCM samplerCube\n"
"#define rx_texture1D texture\n"
"#define rx_texture2D texture\n"
"#define rx_texture3D texture\n"
"#define rx_textureCM texture\n"
"#define rx_texture1DLod textureLod\n"
"#define rx_texture2DLod textureLod\n"
"#define rx_texture3DLod textureLod\n"
"#define rx_textureCMLod textureLod\n"
"#define rx_position gl_Position\n"
"#define rx_vertex_id gl_VertexID\n"
"#define rx_point_size gl_PointSize\n"
"#define rx_point_coord gl_PointCoord\n";
String contents{k_prelude};
GLenum type = 0;
switch (_shader.kind) {
case Frontend::Shader::Type::k_vertex:
type = GL_VERTEX_SHADER;
// emit vertex attributes inputs
_shader.inputs.each_pair([&](const String& _name, const Frontend::Shader::InOut& _inout) {
contents.append(String::format("layout(location = %zu) in %s %s;\n", _inout.index, inout_to_string(_inout.kind), _name));
});
// emit vertex outputs
_shader.outputs.each_pair([&](const String& _name, const Frontend::Shader::InOut& _inout) {
contents.append(String::format("out %s %s;\n", inout_to_string(_inout.kind), _name));
});
break;
case Frontend::Shader::Type::k_fragment:
type = GL_FRAGMENT_SHADER;
// emit fragment inputs
_shader.inputs.each_pair([&](const String& _name, const Frontend::Shader::InOut& _inout) {
contents.append(String::format("in %s %s;\n", inout_to_string(_inout.kind), _name));
});
// emit fragment outputs
_shader.outputs.each_pair([&](const String& _name, const Frontend::Shader::InOut& _inout) {
contents.append(String::format("layout(location = %d) out %s %s;\n", _inout.index, inout_to_string(_inout.kind), _name));
});
break;
}
// emit uniforms
_uniforms.each_fwd([&](const Frontend::Uniform& _uniform) {
// Don't emit padding uniforms.
if (!_uniform.is_padding()) {
contents.append(String::format("uniform %s %s;\n", uniform_to_string(_uniform.type()), _uniform.name()));
}
});
// append the user shader source now
contents.append(_shader.source);
const GLchar* data{static_cast<const GLchar*>(contents.data())};
const GLint size{static_cast<GLint>(contents.size())};
GLuint handle{pglCreateShader(type)};
pglShaderSource(handle, 1, &data, &size);
pglCompileShader(handle);
GLint status{0};
pglGetShaderiv(handle, GL_COMPILE_STATUS, &status);
if (status != GL_TRUE) {
GLint log_size{0};
pglGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_size);
logger->error("failed compiling shader");
if (log_size) {
Vector<char> error_log{Memory::SystemAllocator::instance(), static_cast<Size>(log_size)};
pglGetShaderInfoLog(handle, log_size, &log_size, error_log.data());
logger->error("\n%s\n%s", error_log.data(), contents);
}
pglDeleteShader(handle);
return 0;
}
return handle;
}
AllocationInfo GL3::query_allocation_info() const {
AllocationInfo info;
info.buffer_size = sizeof(detail_gl3::buffer);
info.target_size = sizeof(detail_gl3::target);
info.program_size = sizeof(detail_gl3::program);
info.texture1D_size = sizeof(detail_gl3::texture1D);
info.texture2D_size = sizeof(detail_gl3::texture2D);
info.texture3D_size = sizeof(detail_gl3::texture3D);
info.textureCM_size = sizeof(detail_gl3::textureCM);
return info;
}
DeviceInfo GL3::query_device_info() const {
return {
reinterpret_cast<const char*>(pglGetString(GL_VENDOR)),
reinterpret_cast<const char*>(pglGetString(GL_RENDERER)),
reinterpret_cast<const char*>(pglGetString(GL_VERSION))
};
}
GL3::GL3(Memory::Allocator& _allocator, void* _data)
: m_allocator{_allocator}
, m_data{_data}
{
}
GL3::~GL3() {
m_allocator.destroy<detail_gl3::state>(m_impl);
}
bool GL3::init() {
SDL_GLContext context =
SDL_GL_CreateContext(reinterpret_cast<SDL_Window*>(m_data));
if (!context) {
return false;
}
// buffers
fetch("glGenBuffers", pglGenBuffers);
fetch("glDeleteBuffers", pglDeleteBuffers);
fetch("glBufferData", pglBufferData);
fetch("glBufferSubData", pglBufferSubData);
fetch("glBindBuffer", pglBindBuffer);
// vertex arrays
fetch("glGenVertexArrays", pglGenVertexArrays);
fetch("glDeleteVertexArrays", pglDeleteVertexArrays);
fetch("glEnableVertexAttribArray", pglEnableVertexAttribArray);
fetch("glVertexAttribPointer", pglVertexAttribPointer);
fetch("glBindVertexArray", pglBindVertexArray);
fetch("glVertexAttribDivisor", pglVertexAttribDivisor);
// textures
fetch("glGenTextures", pglGenTextures);
fetch("glDeleteTextures", pglDeleteTextures);
fetch("glTexImage1D", pglTexImage1D);
fetch("glTexImage2D", pglTexImage2D);
fetch("glTexImage3D", pglTexImage3D);
fetch("glTexSubImage1D", pglTexSubImage1D);
fetch("glTexSubImage2D", pglTexSubImage2D);
fetch("glTexSubImage3D", pglTexSubImage3D);
fetch("glCompressedTexImage1D", pglCompressedTexImage1D);
fetch("glCompressedTexImage2D", pglCompressedTexImage2D);
fetch("glCompressedTexImage3D", pglCompressedTexImage3D);
fetch("glTexParameteri", pglTexParameteri);
fetch("glTexParameteriv", pglTexParameteriv);
fetch("glTexParameterf", pglTexParameterf);
fetch("glBindTexture", pglBindTexture);
fetch("glActiveTexture", pglActiveTexture);
fetch("glPixelStorei", pglPixelStorei);
// frame buffers
fetch("glGenFramebuffers", pglGenFramebuffers);
fetch("glDeleteFramebuffers", pglDeleteFramebuffers);
fetch("glFramebufferTexture2D", pglFramebufferTexture2D);
fetch("glBindFramebuffer", pglBindFramebuffer);
fetch("glDrawBuffers", pglDrawBuffers);
fetch("glDrawBuffer", pglDrawBuffer);
fetch("glReadBuffer", pglReadBuffer);
fetch("glBlitFramebuffer", pglBlitFramebuffer);
fetch("glClearBufferfv", pglClearBufferfv);
fetch("glClearBufferiv", pglClearBufferiv);
fetch("glClearBufferfi", pglClearBufferfi);
// shaders and programs
fetch("glShaderSource", pglShaderSource);
fetch("glCreateShader", pglCreateShader);
fetch("glDeleteShader", pglDeleteShader);
fetch("glCompileShader", pglCompileShader);
fetch("glGetShaderiv", pglGetShaderiv);
fetch("glGetShaderInfoLog", pglGetShaderInfoLog);
fetch("glGetProgramiv", pglGetProgramiv);
fetch("glGetProgramInfoLog", pglGetProgramInfoLog);
fetch("glAttachShader", pglAttachShader);
fetch("glLinkProgram", pglLinkProgram);
fetch("glDetachShader", pglDetachShader);
fetch("glCreateProgram", pglCreateProgram);
fetch("glDeleteProgram", pglDeleteProgram);
fetch("glUseProgram", pglUseProgram);
fetch("glGetUniformLocation", pglGetUniformLocation);
fetch("glUniform1i", pglUniform1i);
fetch("glUniform2iv", pglUniform2iv);
fetch("glUniform3iv", pglUniform3iv);
fetch("glUniform4iv", pglUniform4iv);
fetch("glUniform1fv", pglUniform1fv);
fetch("glUniform2fv", pglUniform2fv);
fetch("glUniform3fv", pglUniform3fv);
fetch("glUniform4fv", pglUniform4fv);
fetch("glUniformMatrix3fv", pglUniformMatrix3fv);
fetch("glUniformMatrix4fv", pglUniformMatrix4fv);
fetch("glUniformMatrix3x4fv", pglUniformMatrix3x4fv);
// state
fetch("glEnable", pglEnable);
fetch("glDisable", pglDisable);
fetch("glScissor", pglScissor);
fetch("glColorMask", pglColorMask);
fetch("glBlendFuncSeparate", pglBlendFuncSeparate);
fetch("glDepthFunc", pglDepthFunc);
fetch("glDepthMask", pglDepthMask);
fetch("glFrontFace", pglFrontFace);
fetch("glCullFace", pglCullFace);
fetch("glStencilMask", pglStencilMask);
fetch("glStencilFunc", pglStencilFunc);
fetch("glStencilOpSeparate", pglStencilOpSeparate);
fetch("glPolygonMode", pglPolygonMode);
fetch("glViewport", pglViewport);
// query
fetch("glGetIntegerv", pglGetIntegerv);
fetch("glGetFloatv", pglGetFloatv);
fetch("glGetString", pglGetString);
fetch("glGetStringi", pglGetStringi);
// draw calls
fetch("glDrawArrays", pglDrawArrays);
fetch("glDrawArraysInstanced", pglDrawArraysInstanced);
fetch("glDrawElements", pglDrawElements);
fetch("glDrawElementsBaseVertex", pglDrawElementsBaseVertex);
fetch("glDrawElementsInstanced", pglDrawElementsInstanced);
fetch("glDrawElementsInstancedBaseVertex", pglDrawElementsInstancedBaseVertex);
// flush
fetch("glFinish", pglFinish);
m_impl = m_allocator.create<detail_gl3::state>(context);
return m_impl != nullptr;
}
void GL3::process(const Vector<Byte*>& _commands) {
_commands.each_fwd([this](Byte* _command) {
process(_command);
});
}
void GL3::process(Byte* _command) {
RX_PROFILE_CPU("GL3::process");
auto state{reinterpret_cast<detail_gl3::state*>(m_impl)};
auto header{reinterpret_cast<Frontend::CommandHeader*>(_command)};
switch (header->type) {
case Frontend::CommandType::k_resource_allocate:
{
const auto resource{reinterpret_cast<const Frontend::ResourceCommand*>(header + 1)};
switch (resource->type) {
case Frontend::ResourceCommand::Type::k_buffer:
Utility::construct<detail_gl3::buffer>(resource->as_buffer + 1);
break;
case Frontend::ResourceCommand::Type::k_target:
{
const auto render_target{resource->as_target};
if (render_target->is_swapchain()) {
Utility::construct<detail_gl3::target>(resource->as_target + 1, state->m_swap_chain_fbo);
} else {
Utility::construct<detail_gl3::target>(resource->as_target + 1);
}
}
break;
case Frontend::ResourceCommand::Type::k_program:
Utility::construct<detail_gl3::program>(resource->as_program + 1);
break;
case Frontend::ResourceCommand::Type::k_texture1D:
Utility::construct<detail_gl3::texture1D>(resource->as_texture1D + 1);
break;
case Frontend::ResourceCommand::Type::k_texture2D:
if (resource->as_texture2D->is_swapchain()) {
break;
}
Utility::construct<detail_gl3::texture2D>(resource->as_texture2D + 1);
break;
case Frontend::ResourceCommand::Type::k_texture3D:
Utility::construct<detail_gl3::texture3D>(resource->as_texture3D + 1);
break;
case Frontend::ResourceCommand::Type::k_textureCM:
Utility::construct<detail_gl3::textureCM>(resource->as_textureCM + 1);
break;
}
}
break;
case Frontend::CommandType::k_resource_destroy:
{
const auto resource{reinterpret_cast<const Frontend::ResourceCommand*>(header + 1)};
switch (resource->type) {
case Frontend::ResourceCommand::Type::k_buffer:
{
auto buffer{reinterpret_cast<detail_gl3::buffer*>(resource->as_buffer + 1)};
if (state->m_bound_vbo == buffer->bo[0]) {
state->m_bound_vbo = 0;
}
if (state->m_bound_ebo == buffer->bo[1]) {
state->m_bound_ebo = 0;
}
if (state->m_bound_vao == buffer->va) {
state->m_bound_vao = 0;
}
Utility::destruct<detail_gl3::buffer>(resource->as_buffer + 1);
}
break;
case Frontend::ResourceCommand::Type::k_target:
{
auto target{reinterpret_cast<detail_gl3::target*>(resource->as_target + 1)};
if (state->m_bound_draw_fbo == target->fbo) {
state->m_bound_draw_fbo = 0;
}
if (state->m_bound_read_fbo == target->fbo) {
state->m_bound_read_fbo = 0;
}
Utility::destruct<detail_gl3::target>(resource->as_target + 1);
}
break;
case Frontend::ResourceCommand::Type::k_program:
Utility::destruct<detail_gl3::program>(resource->as_program + 1);
break;
case Frontend::ResourceCommand::Type::k_texture1D:
state->invalidate_texture(resource->as_texture1D);
Utility::destruct<detail_gl3::texture1D>(resource->as_texture1D + 1);
break;
case Frontend::ResourceCommand::Type::k_texture2D:
if (resource->as_texture2D->is_swapchain()) {
break;
}
state->invalidate_texture(resource->as_texture2D);
Utility::destruct<detail_gl3::texture2D>(resource->as_texture2D + 1);
break;
case Frontend::ResourceCommand::Type::k_texture3D:
state->invalidate_texture(resource->as_texture3D);
Utility::destruct<detail_gl3::texture3D>(resource->as_texture3D + 1);
break;
case Frontend::ResourceCommand::Type::k_textureCM:
state->invalidate_texture(resource->as_textureCM);
Utility::destruct<detail_gl3::textureCM>(resource->as_textureCM + 1);
break;
}
}
break;
case Frontend::CommandType::k_resource_construct:
{
const auto resource{reinterpret_cast<const Frontend::ResourceCommand*>(header + 1)};
switch (resource->type) {
case Frontend::ResourceCommand::Type::k_buffer:
{
auto render_buffer = resource->as_buffer;
auto buffer = reinterpret_cast<detail_gl3::buffer*>(render_buffer + 1);
const auto type = render_buffer->type() == Frontend::Buffer::Type::k_dynamic
? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;
state->use_buffer(render_buffer);
auto setup_attributes = [](const Vector<Frontend::Buffer::Attribute>& attributes,
Size _stride,
Size _index_offset,
bool _instanced)
{
const auto n_attributes = attributes.size();
Size count = 0;
for (Size i = 0; i < n_attributes; i++) {
const auto& attribute = attributes[i];
const auto index = static_cast<GLuint>(i + _index_offset);
const auto result = convert_attribute(attribute);
Size offset = attribute.offset;
for (GLsizei j = 0; j < result.instances; j++) {
pglEnableVertexAttribArray(index + j);
pglVertexAttribPointer(
index + j,
result.components,
result.type_enum,
GL_FALSE,
_stride,
reinterpret_cast<const GLvoid*>(offset));
if (_instanced) {
pglVertexAttribDivisor(index + j, 1);
}
offset += result.type_size * result.components;
count++;
}
}
return count;
};
Size current_attribute = 0;
// Setup element buffer.
if (render_buffer->is_indexed()) {
const auto& elements = render_buffer->elements();
state->use_ebo(buffer->bo[0]);
if (elements.is_empty()) {
pglBufferData(GL_ELEMENT_ARRAY_BUFFER, k_buffer_slab_size, nullptr, type);
buffer->elements_size = k_buffer_slab_size;
} else {
pglBufferData(GL_ELEMENT_ARRAY_BUFFER, elements.size(), elements.data(), type);
buffer->elements_size = elements.size();
}
}
// Setup vertex buffer and attributes.
const auto& vertices = render_buffer->vertices();
state->use_vbo(buffer->bo[1]);
if (vertices.is_empty()) {
pglBufferData(GL_ARRAY_BUFFER, k_buffer_slab_size, nullptr, type);
buffer->vertices_size = k_buffer_slab_size;
} else {
pglBufferData(GL_ARRAY_BUFFER, vertices.size(), vertices.data(), type);
buffer->vertices_size = vertices.size();
}
current_attribute = setup_attributes(
render_buffer->vertex_attributes(),
render_buffer->vertex_stride(),
current_attribute,
false);
// Setup instance buffer and attributes.
if (render_buffer->is_instanced()) {
const auto& instances = render_buffer->instances();
state->use_vbo(buffer->bo[2]);
if (instances.is_empty()) {
pglBufferData(GL_ARRAY_BUFFER, k_buffer_slab_size, nullptr, type);
buffer->instances_size = k_buffer_slab_size;
} else {
pglBufferData(GL_ARRAY_BUFFER, instances.size(), instances.data(), type);
buffer->instances_size = instances.size();
}
current_attribute = setup_attributes(
render_buffer->instance_attributes(),
render_buffer->instance_stride(),
current_attribute,
true);
}
}
break;
case Frontend::ResourceCommand::Type::k_target:
{
const auto render_target{resource->as_target};
if (render_target->is_swapchain()) {
// Swap chain targets don't have an user-defined attachments.
break;
}
state->use_draw_target(render_target, nullptr);
if (render_target->has_depth_stencil()) {
const auto depth_stencil{render_target->depth_stencil()};
// combined depth stencil format
const auto texture{reinterpret_cast<const detail_gl3::texture2D*>(depth_stencil + 1)};
pglFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texture->tex, 0);
} else {
if (render_target->has_depth()) {
const auto depth{render_target->depth()};
const auto texture{reinterpret_cast<const detail_gl3::texture2D*>(depth + 1)};
pglFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture->tex, 0);
} else if (render_target->has_stencil()) {
const auto stencil{render_target->stencil()};
const auto texture{reinterpret_cast<const detail_gl3::texture2D*>(stencil + 1)};
pglFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texture->tex, 0);
}
}
// color attachments
const auto& attachments{render_target->attachments()};
for (Size i{0}; i < attachments.size(); i++) {
const auto& attachment{attachments[i]};
const auto attachment_enum{static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i)};
switch (attachment.kind) {
case Frontend::Target::Attachment::Type::k_texture2D:
pglFramebufferTexture2D(
GL_DRAW_FRAMEBUFFER,
attachment_enum,
GL_TEXTURE_2D,
reinterpret_cast<detail_gl3::texture2D*>(attachment.as_texture2D.texture + 1)->tex,
static_cast<GLint>(attachment.level));
break;
case Frontend::Target::Attachment::Type::k_textureCM:
pglFramebufferTexture2D(
GL_DRAW_FRAMEBUFFER,
attachment_enum,
GL_TEXTURE_CUBE_MAP_POSITIVE_X + static_cast<GLenum>(attachment.as_textureCM.face),
reinterpret_cast<detail_gl3::textureCM*>(attachment.as_textureCM.texture + 1)->tex,
static_cast<GLint>(attachment.level));
break;
}
}
}
break;
case Frontend::ResourceCommand::Type::k_program:
{
const auto render_program{resource->as_program};
const auto program{reinterpret_cast<detail_gl3::program*>(render_program + 1)};
const auto shaders{render_program->shaders()};
Vector<GLuint> shader_handles;
shaders.each_fwd([&](const Frontend::Shader& _shader) {
GLuint shader_handle{compile_shader(render_program->uniforms(), _shader)};
if (shader_handle != 0) {
pglAttachShader(program->handle, shader_handle);
shader_handles.push_back(shader_handle);
}
});
pglLinkProgram(program->handle);
GLint status{0};
pglGetProgramiv(program->handle, GL_LINK_STATUS, &status);
if (status != GL_TRUE) {
GLint log_size{0};
pglGetProgramiv(program->handle, GL_INFO_LOG_LENGTH, &log_size);
logger->error("failed linking program");
if (log_size) {
Vector<char> error_log{Memory::SystemAllocator::instance(), static_cast<Size>(log_size)};
pglGetProgramInfoLog(program->handle, log_size, &log_size, error_log.data());
logger->error("\n%s", error_log.data());
}
}
shader_handles.each_fwd([&](GLuint _shader) {
pglDetachShader(program->handle, _shader);
pglDeleteShader(_shader);
});
// fetch uniform locations
render_program->uniforms().each_fwd([program](const Frontend::Uniform& _uniform) {
if (_uniform.is_padding()) {
// Padding uniforms have index -1.
program->uniforms.push_back(-1);
} else {
program->uniforms.push_back(pglGetUniformLocation(program->handle, _uniform.name().data()));
}
});
}
break;
case Frontend::ResourceCommand::Type::k_texture1D:
{
const auto render_texture{resource->as_texture1D};
const auto wrap{render_texture->wrap()};
const auto wrap_s{convert_texture_wrap(wrap)};
const auto format{render_texture->format()};
const auto filter{convert_texture_filter(render_texture->filter())};
const auto& data{render_texture->data()};
const auto levels{static_cast<GLint>(render_texture->levels())};
state->use_texture(render_texture);
pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, filter.min);
pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, filter.mag);
pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, wrap_s);
pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_BASE_LEVEL, 0);
pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_LEVEL, levels - 1);
if (requires_border_color(wrap_s)) {
const Math::Vec4i color{(render_texture->border() * 255.0f).cast<Sint32>()};
pglTexParameteriv(GL_TEXTURE_1D, GL_TEXTURE_BORDER_COLOR, color.data());
}
for (GLint i{0}; i < levels; i++) {
const auto level_info{render_texture->info_for_level(i)};
if (render_texture->is_compressed_format()) {
pglCompressedTexImage1D(
GL_TEXTURE_1D,
i,
convert_texture_data_format(format),
static_cast<GLsizei>(level_info.dimensions),
0,
level_info.size,
data.is_empty() ? nullptr : data.data() + level_info.offset);
} else {
pglTexImage1D(
GL_TEXTURE_1D,
i,
convert_texture_data_format(format),
static_cast<GLsizei>(level_info.dimensions),
0,
convert_texture_format(format),
convert_texture_data_type(format),
data.is_empty() ? nullptr : data.data() + level_info.offset);
}
}
}
break;
case Frontend::ResourceCommand::Type::k_texture2D:
{
const auto render_texture{resource->as_texture2D};
if (render_texture->is_swapchain()) {
break;
}
const auto wrap{render_texture->wrap()};
const auto wrap_s{convert_texture_wrap(wrap.s)};
const auto wrap_t{convert_texture_wrap(wrap.t)};
const auto format{render_texture->format()};
const auto filter{convert_texture_filter(render_texture->filter())};
const auto& data{render_texture->data()};
const auto levels{static_cast<GLint>(render_texture->levels())};
state->use_texture(render_texture);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter.min);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter.mag);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, levels - 1);
if (requires_border_color(wrap_s, wrap_t)) {
const Math::Vec4i color{(render_texture->border() * 255.0f).cast<Sint32>()};
pglTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color.data());
}
for (GLint i{0}; i < levels; i++) {
const auto level_info{render_texture->info_for_level(i)};
if (render_texture->is_compressed_format()) {
pglCompressedTexImage2D(
GL_TEXTURE_2D,
i,
convert_texture_data_format(format),
static_cast<GLsizei>(level_info.dimensions.w),
static_cast<GLsizei>(level_info.dimensions.h),
0,
level_info.size,
data.is_empty() ? nullptr : data.data() + level_info.offset);
} else {
pglTexImage2D(
GL_TEXTURE_2D,
i,
convert_texture_data_format(format),
static_cast<GLsizei>(level_info.dimensions.w),
static_cast<GLsizei>(level_info.dimensions.h),
0,
convert_texture_format(format),
convert_texture_data_type(format),
data.is_empty() ? nullptr : data.data() + level_info.offset);
}
}
}
break;
case Frontend::ResourceCommand::Type::k_texture3D:
{
const auto render_texture{resource->as_texture3D};
const auto wrap{render_texture->wrap()};
const auto wrap_s{convert_texture_wrap(wrap.s)};
const auto wrap_t{convert_texture_wrap(wrap.t)};
const auto wrap_r{convert_texture_wrap(wrap.p)};
const auto format{render_texture->format()};
const auto filter{convert_texture_filter(render_texture->filter())};
const auto& data{render_texture->data()};
const auto levels{static_cast<GLint>(render_texture->levels())};
state->use_texture(render_texture);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, filter.min);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, filter.mag);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, wrap_s);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, wrap_t);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, wrap_r);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, levels - 1);
if (requires_border_color(wrap_s, wrap_t, wrap_r)) {
const Math::Vec4i color{(render_texture->border() * 255.0f).cast<Sint32>()};
pglTexParameteriv(GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, color.data());
}
for (GLint i{0}; i < levels; i++) {
const auto level_info{render_texture->info_for_level(i)};
if (render_texture->is_compressed_format()) {
pglCompressedTexImage3D(
GL_TEXTURE_3D,
i,
convert_texture_data_format(format),
static_cast<GLsizei>(level_info.dimensions.w),
static_cast<GLsizei>(level_info.dimensions.h),
static_cast<GLsizei>(level_info.dimensions.d),
0,
level_info.size,
data.is_empty() ? nullptr : data.data() + level_info.offset);
} else {
pglTexImage3D(
GL_TEXTURE_3D,
i,
convert_texture_data_format(format),
static_cast<GLsizei>(level_info.dimensions.w),
static_cast<GLsizei>(level_info.dimensions.h),
static_cast<GLsizei>(level_info.dimensions.d),
0,
convert_texture_format(format),
convert_texture_data_type(format),
data.is_empty() ? nullptr : data.data() + level_info.offset);
}
}
}
break;
case Frontend::ResourceCommand::Type::k_textureCM:
{
const auto render_texture{resource->as_textureCM};
const auto wrap{render_texture->wrap()};
const auto wrap_s{convert_texture_wrap(wrap.s)};
const auto wrap_t{convert_texture_wrap(wrap.t)};
const auto wrap_p{convert_texture_wrap(wrap.p)};
const auto format{render_texture->format()};
const auto filter{convert_texture_filter(render_texture->filter())};
const auto& data{render_texture->data()};
const auto levels{static_cast<GLint>(render_texture->levels())};
state->use_texture(render_texture);
pglTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, filter.min);
pglTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, filter.mag);
pglTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, wrap_s);
pglTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, wrap_t);
pglTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, wrap_p);
pglTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0);
pglTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, levels - 1);
if (requires_border_color(wrap_s, wrap_t, wrap_p)) {
const Math::Vec4i color{(render_texture->border() * 255.0f).cast<Sint32>()};
pglTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BORDER_COLOR, color.data());
}
for (GLint i{0}; i < levels; i++) {
const auto level_info{render_texture->info_for_level(i)};
for (GLint j{0}; j < 6; j++) {
if (render_texture->is_compressed_format()) {
pglCompressedTexImage2D(
GL_TEXTURE_CUBE_MAP_POSITIVE_X + j,
i,
convert_texture_data_format(format),
static_cast<GLsizei>(level_info.dimensions.w),
static_cast<GLsizei>(level_info.dimensions.h),
0,
level_info.size / 6,
data.is_empty() ? nullptr : data.data() + level_info.offset + level_info.size / 6 * j);
} else {
pglTexImage2D(
GL_TEXTURE_CUBE_MAP_POSITIVE_X + j,
i,
convert_texture_data_format(format),
static_cast<GLsizei>(level_info.dimensions.w),
static_cast<GLsizei>(level_info.dimensions.h),
0,
convert_texture_format(format),
convert_texture_data_type(format),
data.is_empty() ? nullptr : data.data() + level_info.offset + level_info.size / 6 * j);
}
}
}
}
break;
}
}
break;
case Frontend::CommandType::k_resource_update:
{
const auto resource{reinterpret_cast<const Frontend::UpdateCommand*>(header + 1)};
switch (resource->type) {
case Frontend::UpdateCommand::Type::k_buffer:
{
const auto render_buffer = resource->as_buffer;
const auto& vertices = render_buffer->vertices();
const auto type = render_buffer->type() == Frontend::Buffer::Type::k_dynamic
? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;
bool use_vertices_edits = false;
bool use_elements_edits = false;
bool use_instances_edits = false;
auto buffer = reinterpret_cast<detail_gl3::buffer*>(render_buffer + 1);
state->use_buffer(render_buffer);
// Check for element updates.
if (render_buffer->is_indexed()) {
const auto& elements = render_buffer->elements();
if (elements.size() > buffer->elements_size) {
state->use_ebo(buffer->bo[0]);
pglBufferData(GL_ELEMENT_ARRAY_BUFFER, elements.size(), elements.data(), type);
buffer->elements_size = elements.size();
} else {
use_elements_edits = true;
}
}
if (vertices.size() > buffer->vertices_size) {
state->use_vbo(buffer->bo[1]);
pglBufferData(GL_ARRAY_BUFFER, vertices.size(), vertices.data(), type);
buffer->vertices_size = vertices.size();
} else {
use_vertices_edits = true;
}
// Check for instance updates.
if (render_buffer->is_instanced()) {
const auto& instances = render_buffer->instances();
if (instances.size() > buffer->instances_size) {
state->use_vbo(buffer->bo[2]);
pglBufferData(GL_ARRAY_BUFFER, instances.size(), instances.data(), type);
buffer->instances_size = instances.size();
} else {
use_instances_edits = true;
}
}
// Enumerate and apply all buffer edits.
if (use_vertices_edits || use_elements_edits || use_instances_edits) {
const Size* edit = resource->edit();
for (Size i{0}; i < resource->edits; i++) {
switch (edit[0]) {
case 0:
if (use_elements_edits) {
const auto& elements = render_buffer->elements();
state->use_ebo(buffer->bo[0]);
pglBufferSubData(GL_ELEMENT_ARRAY_BUFFER, edit[1], edit[2], elements.data() + edit[1]);
}
break;
case 1:
if (use_vertices_edits) {
state->use_vbo(buffer->bo[1]);
pglBufferSubData(GL_ARRAY_BUFFER, edit[1], edit[2], vertices.data() + edit[1]);
}
break;
case 2:
if (use_instances_edits) {
const auto& instances = render_buffer->instances();
state->use_vbo(buffer->bo[2]);
pglBufferSubData(GL_ARRAY_BUFFER, edit[1], edit[2], instances.data() + edit[1]);
}
}
edit += 3;
}
}
}
break;
case Frontend::UpdateCommand::Type::k_texture1D:
{
// TODO(dweiler): implement
}
break;
case Frontend::UpdateCommand::Type::k_texture2D:
{
// TODO(dweiler): implement
}
break;
case Frontend::UpdateCommand::Type::k_texture3D:
{
// TODO(dweiler): implement
}
break;
default:
break;
}
}
break;
case Frontend::CommandType::k_clear:
{
RX_PROFILE_CPU("clear");
const auto command{reinterpret_cast<Frontend::ClearCommand*>(header + 1)};
const auto render_state{&command->render_state};
const auto render_target{command->render_target};
const bool clear_depth{command->clear_depth};
const bool clear_stencil{command->clear_stencil};
state->use_state(render_state);
state->use_draw_target(render_target, &command->draw_buffers);
if (command->clear_colors) {
for (Uint32 i{0}; i < sizeof command->color_values / sizeof *command->color_values; i++) {
if (command->clear_colors & (1 << i)) {
pglClearBufferfv(GL_COLOR, static_cast<GLint>(i),
command->color_values[i].data());
}
}
}
if (clear_depth && clear_stencil) {
pglClearBufferfi(GL_DEPTH_STENCIL, 0, command->depth_value,
command->stencil_value);
} else if (clear_depth) {
pglClearBufferfv(GL_DEPTH, 0, &command->depth_value);
} else if (clear_stencil) {
const GLint value{command->stencil_value};
pglClearBufferiv(GL_STENCIL, 0, &value);
}
}
break;
case Frontend::CommandType::k_draw:
{
RX_PROFILE_CPU("draw");
const auto command{reinterpret_cast<Frontend::DrawCommand*>(header + 1)};
const auto render_state{&command->render_state};
const auto render_target{command->render_target};
const auto render_buffer{command->render_buffer};
const auto render_program{command->render_program};
const auto this_program{reinterpret_cast<detail_gl3::program*>(render_program + 1)};
state->use_draw_target(render_target, &command->draw_buffers);
state->use_buffer(render_buffer);
state->use_program(render_program);
state->use_state(render_state);
// check for and apply uniform deltas
if (command->dirty_uniforms_bitset) {
const auto& program_uniforms{render_program->uniforms()};
const Byte* draw_uniforms{command->uniforms()};
for (Size i{0}; i < 64; i++) {
if (command->dirty_uniforms_bitset & (1_u64 << i)) {
const auto& uniform{program_uniforms[i]};
const auto location{this_program->uniforms[i]};
if (location == -1) {
draw_uniforms += uniform.size();
continue;
}
switch (uniform.type()) {
case Frontend::Uniform::Type::k_sampler1D:
[[fallthrough]];
case Frontend::Uniform::Type::k_sampler2D:
[[fallthrough]];
case Frontend::Uniform::Type::k_sampler3D:
[[fallthrough]];
case Frontend::Uniform::Type::k_samplerCM:
pglUniform1i(location,
*reinterpret_cast<const Sint32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_bool:
pglUniform1i(location,
*reinterpret_cast<const bool*>(draw_uniforms) ? 1 : 0);
break;
case Frontend::Uniform::Type::k_int:
pglUniform1i(location,
*reinterpret_cast<const Sint32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_float:
pglUniform1fv(location, 1,
reinterpret_cast<const Float32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_vec2i:
pglUniform2iv(location, 1,
reinterpret_cast<const Sint32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_vec3i:
pglUniform3iv(location, 1,
reinterpret_cast<const Sint32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_vec4i:
pglUniform4iv(location, 1,
reinterpret_cast<const Sint32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_vec2f:
pglUniform2fv(location, 1,
reinterpret_cast<const Float32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_vec3f:
pglUniform3fv(location, 1,
reinterpret_cast<const Float32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_vec4f:
pglUniform4fv(location, 1,
reinterpret_cast<const Float32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_mat3x3f:
pglUniformMatrix3fv(location, 1, GL_FALSE,
reinterpret_cast<const Float32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_mat4x4f:
pglUniformMatrix4fv(location, 1, GL_FALSE,
reinterpret_cast<const Float32*>(draw_uniforms));
break;
case Frontend::Uniform::Type::k_bonesf:
pglUniformMatrix3x4fv(location,
static_cast<GLsizei>(uniform.size() / sizeof(Math::Mat3x4f)),
GL_FALSE, reinterpret_cast<const Float32*>(draw_uniforms));
}
draw_uniforms += uniform.size();
}
}
}
// apply any textures
for (Size i{0}; i < command->draw_textures.size(); i++) {
Frontend::Texture* texture{command->draw_textures[i]};
switch (texture->resource_type()) {
case Frontend::Resource::Type::k_texture1D:
state->use_active_texture(static_cast<Frontend::Texture1D*>(texture), i);
break;
case Frontend::Resource::Type::k_texture2D:
state->use_active_texture(static_cast<Frontend::Texture2D*>(texture), i);
break;
case Frontend::Resource::Type::k_texture3D:
state->use_active_texture(static_cast<Frontend::Texture3D*>(texture), i);
break;
case Frontend::Resource::Type::k_textureCM:
state->use_active_texture(static_cast<Frontend::TextureCM*>(texture), i);
break;
default:
RX_HINT_UNREACHABLE();
}
}
const auto offset = static_cast<GLint>(command->offset);
const auto count = static_cast<GLsizei>(command->count);
const auto primitive_type = convert_primitive_type(command->type);
if (render_buffer) {
const auto element_type = convert_element_type(render_buffer->element_type());
const auto indices = reinterpret_cast<const GLvoid*>(render_buffer->element_size() * command->offset);
if (command->instances) {
const bool base_instance = command->base_instance != 0;
if (render_buffer->is_indexed()) {
const bool base_vertex = command->base_vertex != 0;
if (base_vertex) {
if (base_instance) {
pglDrawElementsInstancedBaseVertexBaseInstance(
primitive_type,
count,
element_type,
indices,
static_cast<GLsizei>(command->instances),
static_cast<GLint>(command->base_vertex),
static_cast<GLuint>(command->base_instance));
} else {
pglDrawElementsInstancedBaseVertex(
primitive_type,
count,
element_type,
indices,
static_cast<GLsizei>(command->instances),
static_cast<GLint>(command->base_vertex));
}
} else if (base_instance) {
pglDrawElementsInstancedBaseInstance(
primitive_type,
count,
element_type,
indices,
static_cast<GLsizei>(command->instances),
static_cast<GLint>(command->base_instance));
} else {
pglDrawElementsInstanced(
primitive_type,
count,
element_type,
indices,
static_cast<GLsizei>(command->instances));
}
} else {
if (base_instance) {
pglDrawArraysInstancedBaseInstance(
primitive_type,
offset,
count,
static_cast<GLsizei>(command->instances),
static_cast<GLuint>(command->base_instance));
} else {
pglDrawArraysInstanced(
primitive_type,
offset,
count,
static_cast<GLsizei>(command->instances));
}
}
} else {
if (render_buffer->is_indexed()) {
if (command->base_vertex) {
pglDrawElementsBaseVertex(
primitive_type,
count,
element_type,
indices,
static_cast<GLint>(command->base_vertex));
} else {
pglDrawElements(primitive_type, count, element_type, indices);
}
} else {
pglDrawArrays(primitive_type, offset, count);
}
}
} else {
// Bufferless draw calls
pglDrawArrays(primitive_type, 0, count);
}
}
break;
case Frontend::CommandType::k_blit:
{
RX_PROFILE_CPU("blit");
const auto command{reinterpret_cast<Frontend::BlitCommand*>(header + 1)};
const auto render_state{&command->render_state};
// TODO(dweiler): optimize use_state to only consider the things that matter
// during a blit operation:
//
// * scissor test
// * blend write mask
state->use_state(render_state);
auto* src_render_target{command->src_target};
auto* dst_render_target{command->dst_target};
const auto src_attachment{command->src_attachment};
const auto dst_attachment{command->dst_attachment};
const auto src_dimensions{src_render_target->attachments()[src_attachment].as_texture2D.texture->dimensions().cast<GLint>()};
const auto dst_dimensions{dst_render_target->attachments()[dst_attachment].as_texture2D.texture->dimensions().cast<GLint>()};
Frontend::Buffers draw_buffers;
Frontend::Buffers read_buffers;
draw_buffers.add(dst_attachment);
read_buffers.add(src_attachment);
state->use_read_target(src_render_target, &read_buffers);
state->use_draw_target(dst_render_target, &draw_buffers);
pglBlitFramebuffer(
0,
0,
src_dimensions.w,
src_dimensions.h,
0,
0,
dst_dimensions.w,
dst_dimensions.h,
GL_COLOR_BUFFER_BIT,
GL_NEAREST);
break;
}
case Frontend::CommandType::k_profile:
break;
}
}
void GL3::swap() {
RX_PROFILE_CPU("swap");
SDL_GL_SwapWindow(reinterpret_cast<SDL_Window*>(m_data));
}
} // namespace rx::backend
| [
"weilercdale@gmail.com"
] | weilercdale@gmail.com |
8d29269c8b67d4548f59b66d94f76f8728fdcf89 | 71b61cc453db28c0e3c9c0a4a0408baf9b6ed3e6 | /FigureZ.h | d22e143715ca1455de5dbec858cace5d69620109 | [] | no_license | liretta/Tetris | 0de00b848da750a09c1659770a47589a6806ca64 | e41cd8c29d34551d301db7f19e31aa4bd012cc22 | refs/heads/master | 2020-03-25T19:45:30.223222 | 2018-08-11T08:13:29 | 2018-08-11T08:13:29 | 144,098,955 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 153 | h | #pragma once
#include "stdafx.h"
#include "defines.h"
#include "Figure.h"
class FigureZ : public Figure
{
public:
FigureZ();
virtual ~FigureZ();
};
| [
"liretta26@gmail.com"
] | liretta26@gmail.com |
fbd0009dfab742083f32717dad99527268129797 | a74af4b480bf2962dc8ec6e4bca793fed7c7a2ab | /Metin2-Loading-Tip-Info-master/1.Svn/Client/UserInterface/PythonBackground.cpp | 09039342a00473f9171fd5fa7fc51a4934c00540 | [] | no_license | Bobo199/Metin2 | 50c372d0f99fe37741e1c8826342898451f10ae7 | 43e90898df54ad201011b3bd8a6fec63cdb6a842 | refs/heads/master | 2022-11-14T21:20:04.196159 | 2020-06-28T15:39:14 | 2020-06-28T15:39:14 | 275,601,572 | 2 | 0 | null | 2020-06-28T15:34:35 | 2020-06-28T14:27:03 | C++ | UTF-8 | C++ | false | false | 90 | cpp | //Find
m_strMapName="";
///Add
#if defined(__LOADING_TIP__)
l_WarpMapIndex = 0;
#endif | [
"noreply@github.com"
] | Bobo199.noreply@github.com |
05cdfd7c401458f65ff25b2418bf4d56e7e211c9 | 02c43cda5f67158c01edbef30866bb5b03206663 | /RiverCityGirls_DontSleep_pt/playerWait.h | f7fe5c9621f71dc686b18d1ffddeeb1a578fb802 | [] | no_license | RKJH-jin/RK_Projects | 81c102a208f2a1a31428154067e67b26ce82c2fe | e568ca59b0a5335805f307aa46c397b8c890117a | refs/heads/master | 2023-03-09T05:59:36.021119 | 2021-02-23T02:51:45 | 2021-02-23T02:51:45 | 341,404,963 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 177 | h | #pragma once
#include "IPlayerState.h"
class playerWait :public IPlayerState
{
public:
virtual void EnterState();
virtual void UpdateState();
virtual void ExitState();
};
| [
"rk.jh.jin@gmail.com"
] | rk.jh.jin@gmail.com |
2f24b7fe3df97bd845881421d5a59b5e25d79601 | 073e34174c9b566337ceda7693672b03579e7b12 | /aStarScene.h | 4232ac2b1b362c6d8a6c8fe9309c56ffe0c1ea92 | [
"MIT"
] | permissive | ArrowManga/first_project | a578347fbb1f9d1392637b7693303dc6237f94a9 | 39352a8d93ff7da6c71bf9743d09ed91dcae1511 | refs/heads/master | 2020-03-28T18:38:01.694450 | 2018-09-15T12:16:16 | 2018-09-15T12:16:16 | 148,897,008 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 234 | h | #pragma once
#include "gameNode.h"
#include "aStarTest.h"
class aStarScene : public gameNode
{
private:
aStarTest* _ast;
public:
aStarScene();
~aStarScene();
HRESULT init();
void release();
void update();
void render();
};
| [
"43293922+ArrowManga@users.noreply.github.com"
] | 43293922+ArrowManga@users.noreply.github.com |
57f3d6aeb1a4f164b0c369cf6582e601258aa9c0 | c78aa600facc3b05e79519565493a89c550d6c61 | /zadacha6-8/zadacha3/Fraction.cpp | 20561cf6b5c44b0171d499973a1e1a6210ef68a5 | [] | no_license | VVMig/labs-prog | baf6eaa80f942113a6ad2504480abb25dbcda39c | f7c5c26f596b86633b8f1379aacd9ae9908ab17c | refs/heads/master | 2023-02-03T08:47:09.280199 | 2020-12-19T08:19:18 | 2020-12-19T08:19:18 | 322,797,654 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 728 | cpp | #include "Fraction.h"
#include <string>
#include <cmath>
using namespace std;
double toDouble(const char* a) {
string cc = "", dd = "";
double c = 0.0, d = 0.0;
bool cel = true;
for (int i = 0;a[i]; i++)
{
if (a[i] == '.') cel = false;
if (a[i] >= '0' && a[i] <= '9') {
if (cel)
cc += a[i];
else dd += a[i];
}
}
c = atoi(cc.c_str());
d = atoi(dd.c_str());
d= d/pow(10, dd.size());
c += d;
return c;
}
void Fraction::addElement(const char* a)
{
double res = toDouble(a) + toDouble(this->c_str());
string b = to_string(res);
int i = b.size() - 1;
for (i; b[i] == '0'; i--);
b = b.substr(0, i + 1);
str = new char[b.size() + 1];
n = b.size();
strcpy_s(str, n + 1, b.c_str());
}
| [
"vova.migay123@gmail.com"
] | vova.migay123@gmail.com |
66021326fbaa9fc195626df827234412e556a6a7 | 2c642ac5e22d15055ebf54936898a8f542e24f14 | /Example/Pods/Headers/Public/boost/boost/mpl/aux_/preprocessed/gcc/not_equal_to.hpp | 2e31a89487c197338570249f3a278eedf5c7ffb4 | [
"Apache-2.0"
] | permissive | TheClimateCorporation/geofeatures-ios | 488d95084806f69fb6e42d7d0da73bb2f818f19e | cf6a5c4eb2918bb5f3dcd0898501d52d92de7b1f | refs/heads/master | 2020-04-15T05:34:06.491186 | 2015-08-14T20:28:31 | 2015-08-14T20:28:31 | 40,622,132 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 90 | hpp | ../../../../../../../../boost/Pod/Classes/boost/mpl/aux_/preprocessed/gcc/not_equal_to.hpp | [
"tony@mobilegridinc.com"
] | tony@mobilegridinc.com |
a1148e86b57b3d1b6ee929fc71d30ace952e5432 | c995761406386ebd0aaeae62998bc43029d66045 | /employeeform.h | e340c9b7eab62ee07b314cf7615a38fb66fde4f3 | [] | no_license | zhongming2013/dynamicLocation | 1589fba7a381899ae32fbafe8504dfd8c09676ac | 72837c34cb6ddfc3d92e199e2917c09b3887b17a | refs/heads/master | 2016-09-03T00:30:42.667422 | 2013-03-17T12:36:25 | 2013-03-17T12:36:25 | null | 0 | 0 | null | null | null | null | GB18030 | C++ | false | false | 1,291 | h | #ifndef EMPLOYEEFORM_H
#define EMPLOYEEFORM_H
#include <QDialog>
#include <QSqlTableModel>
#include <QDataWidgetMapper>
#include <QLabel>
#include <QLineEdit>
#include <QDateEdit>
#include <QPushButton>
#include <QDialogButtonBox>
class EmployeeForm : public QDialog
{
Q_OBJECT
public:
EmployeeForm(int id, QWidget *parent = 0);
void done(int result);
private slots:
void addEmployee();
void deleteEmployee();
private:
enum
{
Employee_Id = 0,
Employee_NetId,
Employee_Name,
Employee_Department,
Employee_Extension,//分机号
Employee_Email,
Employee_StartDate//进入公司的日期
};
QSqlTableModel *tableModel;
QDataWidgetMapper *mapper;
QLabel *nameLabel;
QLineEdit *nameEdit;
QLabel *departmentLabel;
QLineEdit *departmentEdit;
QLabel *extensionLabel;
QLineEdit *extensionEdit;
QLabel *emailLabel;
QLineEdit *emailEdit;
QLabel *startDateLabel;
QDateEdit *startDateEdit;
QPushButton *firstButton;
QPushButton *previousButton;
QPushButton *nextButton;
QPushButton *lastButton;
QPushButton *addButton;
QPushButton *deleteButton;
QPushButton *closeButton;
QDialogButtonBox *buttonBox;
};
#endif // EMPLOYEEFORM_H
| [
"zhongming_sysu@qq.com"
] | zhongming_sysu@qq.com |
2620516fd4c3fffc5925676ebd0a26c5d4006921 | 6f0f1096542beb4e299af24136cbe9d8079e3c90 | /edge/src/TCPclient/TCPclient.cpp | 8e63271808383eebe3a0da183bdf73983763ef3b | [
"MIT"
] | permissive | yanboyang713/Radio-Telescope | f4bf87433830674a405cc615feff849e1bb39861 | 6dace01f6ad8b9361d52fa8405b0ee787cfc37d8 | refs/heads/master | 2023-08-28T05:52:55.733649 | 2021-10-12T03:22:08 | 2021-10-12T03:22:08 | 416,167,343 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,057 | cpp | /*************************************************************
* Name: Boyang Yan
* Email Address: boyyan@microsoft.com
* Last modification: 17/07/2020
* Function: TCP Client
************************************************************/
#include "TCPclient.h"
TCPclient::TCPclient(){
valread = 0;
sock = 0;
IP = "127.0.0.1";
port = 8080;
successStatus = false;
message = NULL;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(8080);
successStatus = init();
}
TCPclient::TCPclient(std::string IP, int port){
valread = 0;
sock = 0;
successStatus = false;
this->IP = IP;
this->port = port;
message = NULL;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(port);
successStatus = init();
}
TCPclient::~TCPclient(){
}
bool TCPclient::getSuccessStatus() const{
return successStatus;
}
bool TCPclient::init(){
/*
* sockfd = socket(domain, type, protocol)
* sockfd: socket descriptor, an integer (like a file-handle)
* domain: integer, communication domain e.g., AF_INET (IPv4 protocol) , AF_INET6 (IPv6 protocol)
* type: communication type SOCK_STREAM: TCP(reliable, connection oriented) SOCK_DGRAM: UDP(unreliable, connectionless)
* protocol: Protocol value for Internet Protocol(IP), which is 0. This is the same number which appears on protocol field in the IP header of a packet.(man protocols for more details)
*/
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
printf("\n Socket creation error \n");
return false;
}
// Convert IPv4 and IPv6 addresses from text to binary form
if(inet_pton(AF_INET, IP.c_str(), &serv_addr.sin_addr)<=0){
printf("\nInvalid address/ Address not supported \n");
return false;
}
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0){
printf("\nConnection Failed \n");
return false;
}
return true;
}
std::string TCPclient::sendMSG(std::string msg){
char Buffer[1024] = {0};
send(sock , msg.c_str() , msg.length() , 0 );
//printf("message sent success\n");
valread = read( sock , Buffer, 1024);
return convertToString(Buffer, 1024);
}
void TCPclient::onlySendMSG(std::string msg){
char Buffer[1024] = {0};
send(sock , msg.c_str() , msg.length() , 0 );
//printf("message sent success\n");
return;
}
void TCPclient::read_message() {
char data;
ssize_t data_read;
while ((data_read = recv(sock, &data, 1, 0)) > 0 && data != '\0')
*message++ = data;
if (data_read == -1) {
perror("CLIENT: ERROR recv()");
exit(EXIT_FAILURE);
}
*message = '\0';
std::cout << message << std::endl;
return;
}
// converts character array
// to string and returns it
std::string TCPclient::convertToString(char* array, int size)
{
std::string stringReturn = "";
for (int i = 0; i < size; i++) {
stringReturn = stringReturn + array[i];
}
return stringReturn;
}
| [
"yanboyang713@gmail.com"
] | yanboyang713@gmail.com |
84cccc3dd0038099f827056fcee93cc6d466cdc4 | 9334e57592c643aa98a01e78683243fd2b420560 | /3Cats/Graph-visitor/visitor.h | 188f8c1fb43dd6b1fd7af5ebec465de4ca755a46 | [] | no_license | tikhonow/cpp-programming | bae0cb7d7f55fbf1e41a21073ffbced924d8c651 | 65c86042a1ee668b0d15e267fdebe07027bb204f | refs/heads/master | 2023-02-02T21:15:53.835876 | 2020-12-15T08:21:40 | 2020-12-15T08:21:40 | 298,247,752 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 965 | h | #pragma once
#include <memory>
template<class Vertex>
class BfsVisitor {
public:
BfsVisitor() {
a = std::make_shared<Grag>();
a->v = 222222222 ;
}
void ExamineVertex(const Vertex& vertex) {
if (a->v == 222222222) {
a->v = Vertex(vertex);
return;
}
a->v = vertex;
}
void DiscoverVertex(const Vertex& vertex) {
if (a->v == 222222222) {
a->p.insert({ vertex, vertex });
return;
}
a->p.insert({ vertex, a->v });
}
size_t DistanceTo(const Vertex& target) const {
size_t path = 0;
for (Vertex i = target; i != a->p.at(i); i = a->p.at(i))
path++;
return path;
}
Vertex Parent(const Vertex& vertex) const {
return a->p.at(vertex);
}
private:
struct Grag {
public:
Vertex v;
std::unordered_map<Vertex, Vertex> p;
};
std::shared_ptr<Grag>a;
};
| [
"tihoo99@icloud.com"
] | tihoo99@icloud.com |
4a213034d5635a22a4fd78f86fad6798a4b94474 | 95cc023556e96743b1b47f4459181a81bf592be7 | /drivers/bluetooth/lib/gap/bredr_connection_manager.cc | 1c9d868def2f4ee71b3e1e6f01c906b89d72d1ed | [
"BSD-3-Clause"
] | permissive | return/garnet | 5034ae8b8083455aa66da10040098c908f3de532 | f14e7e50a1b6b55eaa8013755201a25fc83bd389 | refs/heads/master | 2020-03-23T16:13:28.763852 | 2018-07-21T07:24:31 | 2018-07-21T07:24:31 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 15,682 | cc | // Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "bredr_connection_manager.h"
#include "garnet/drivers/bluetooth/lib/gap/remote_device_cache.h"
#include "garnet/drivers/bluetooth/lib/hci/connection.h"
#include "garnet/drivers/bluetooth/lib/hci/hci_constants.h"
#include "garnet/drivers/bluetooth/lib/hci/sequential_command_runner.h"
#include "garnet/drivers/bluetooth/lib/hci/transport.h"
namespace btlib {
namespace gap {
namespace {
void SetPageScanEnabled(bool enabled, fxl::RefPtr<hci::Transport> hci,
async_dispatcher_t* dispatcher, hci::StatusCallback cb) {
FXL_DCHECK(cb);
auto read_enable = hci::CommandPacket::New(hci::kReadScanEnable);
auto finish_enable_cb = [enabled, dispatcher, hci, finish_cb = std::move(cb)](
auto, const hci::EventPacket& event) mutable {
if (BTEV_TEST_WARN(event, "gap (BR/EDR): Read Scan Enable failed")) {
finish_cb(event.ToStatus());
return;
}
auto params = event.return_params<hci::ReadScanEnableReturnParams>();
uint8_t scan_type = params->scan_enable;
if (enabled) {
scan_type |= static_cast<uint8_t>(hci::ScanEnableBit::kPage);
} else {
scan_type &= ~static_cast<uint8_t>(hci::ScanEnableBit::kPage);
}
auto write_enable = hci::CommandPacket::New(
hci::kWriteScanEnable, sizeof(hci::WriteScanEnableCommandParams));
write_enable->mutable_view()
->mutable_payload<hci::WriteScanEnableCommandParams>()
->scan_enable = scan_type;
hci->command_channel()->SendCommand(
std::move(write_enable), dispatcher,
[cb = std::move(finish_cb), enabled](
auto, const hci::EventPacket& event) { cb(event.ToStatus()); });
};
hci->command_channel()->SendCommand(std::move(read_enable), dispatcher,
std::move(finish_enable_cb));
}
} // namespace
hci::CommandChannel::EventHandlerId BrEdrConnectionManager::AddEventHandler(
const hci::EventCode& code, hci::CommandChannel::EventCallback cb) {
auto self = weak_ptr_factory_.GetWeakPtr();
auto event_id = hci_->command_channel()->AddEventHandler(
code,
[self, callback = std::move(cb)](const auto& event) {
if (self) {
callback(event);
}
},
dispatcher_);
FXL_DCHECK(event_id);
return event_id;
}
BrEdrConnectionManager::BrEdrConnectionManager(fxl::RefPtr<hci::Transport> hci,
RemoteDeviceCache* device_cache,
bool use_interlaced_scan)
: hci_(hci),
cache_(device_cache),
interrogator_(cache_, hci_, async_get_default_dispatcher()),
page_scan_interval_(0),
page_scan_window_(0),
use_interlaced_scan_(use_interlaced_scan),
dispatcher_(async_get_default_dispatcher()),
weak_ptr_factory_(this) {
FXL_DCHECK(hci_);
FXL_DCHECK(cache_);
FXL_DCHECK(dispatcher_);
hci_cmd_runner_ =
std::make_unique<hci::SequentialCommandRunner>(dispatcher_, hci_);
// Register event handlers
conn_complete_handler_id_ = AddEventHandler(
hci::kConnectionCompleteEventCode,
fbl::BindMember(this, &BrEdrConnectionManager::OnConnectionComplete));
conn_request_handler_id_ = AddEventHandler(
hci::kConnectionRequestEventCode,
fbl::BindMember(this, &BrEdrConnectionManager::OnConnectionRequest));
disconn_cmpl_handler_id_ = AddEventHandler(
hci::kDisconnectionCompleteEventCode,
fbl::BindMember(this, &BrEdrConnectionManager::OnDisconnectionComplete));
io_cap_req_handler_id_ = AddEventHandler(
hci::kIOCapabilityRequestEventCode,
fbl::BindMember(this, &BrEdrConnectionManager::OnIOCapabilitiesRequest));
user_conf_handler_id_ = AddEventHandler(
hci::kUserConfirmationRequestEventCode,
fbl::BindMember(this,
&BrEdrConnectionManager::OnUserConfirmationRequest));
};
BrEdrConnectionManager::~BrEdrConnectionManager() {
// Disconnect any connections that we're holding.
connections_.clear();
SetPageScanEnabled(false, hci_, dispatcher_, [](const auto) {});
hci_->command_channel()->RemoveEventHandler(conn_request_handler_id_);
hci_->command_channel()->RemoveEventHandler(conn_complete_handler_id_);
hci_->command_channel()->RemoveEventHandler(disconn_cmpl_handler_id_);
hci_->command_channel()->RemoveEventHandler(io_cap_req_handler_id_);
hci_->command_channel()->RemoveEventHandler(user_conf_handler_id_);
}
void BrEdrConnectionManager::SetConnectable(bool connectable,
hci::StatusCallback status_cb) {
auto self = weak_ptr_factory_.GetWeakPtr();
if (!connectable) {
SetPageScanEnabled(false, hci_, dispatcher_,
[self, cb = std::move(status_cb)](const auto& status) {
if (self) {
self->page_scan_interval_ = 0;
self->page_scan_window_ = 0;
} else if (status) {
cb(hci::Status(common::HostError::kFailed));
return;
}
cb(status);
});
return;
}
WritePageScanSettings(
hci::kPageScanR1Interval, hci::kPageScanR1Window, use_interlaced_scan_,
[self, cb = std::move(status_cb)](const auto& status) mutable {
if (!status) {
FXL_LOG(WARNING) << "gap (BR/EDR): Write Page Scan Settings failed: "
<< status.ToString();
cb(status);
return;
}
if (!self) {
cb(hci::Status(common::HostError::kFailed));
return;
}
SetPageScanEnabled(true, self->hci_, self->dispatcher_, std::move(cb));
});
}
void BrEdrConnectionManager::SetPairingDelegate(
fxl::WeakPtr<PairingDelegate> delegate) {
// TODO(armansito): implement
}
void BrEdrConnectionManager::WritePageScanSettings(uint16_t interval,
uint16_t window,
bool interlaced,
hci::StatusCallback cb) {
auto self = weak_ptr_factory_.GetWeakPtr();
if (!hci_cmd_runner_->IsReady()) {
// TODO(jamuraa): could run the three "settings" commands in parallel and
// remove the sequence runner.
cb(hci::Status(common::HostError::kInProgress));
return;
}
auto write_activity =
hci::CommandPacket::New(hci::kWritePageScanActivity,
sizeof(hci::WritePageScanActivityCommandParams));
auto* activity_params =
write_activity->mutable_view()
->mutable_payload<hci::WritePageScanActivityCommandParams>();
activity_params->page_scan_interval = htole16(interval);
activity_params->page_scan_window = htole16(window);
hci_cmd_runner_->QueueCommand(
std::move(write_activity),
[self, interval, window](const hci::EventPacket& event) {
if (BTEV_TEST_WARN(event,
"gap (BR/EDR): write page scan activity failed")) {
return;
}
if (!self) {
return;
}
self->page_scan_interval_ = interval;
self->page_scan_window_ = window;
FXL_VLOG(2) << "gap (BR/EDR): page scan activity updated";
});
auto write_type = hci::CommandPacket::New(
hci::kWritePageScanType, sizeof(hci::WritePageScanTypeCommandParams));
auto* type_params =
write_type->mutable_view()
->mutable_payload<hci::WritePageScanTypeCommandParams>();
type_params->page_scan_type = (interlaced ? hci::PageScanType::kInterlacedScan
: hci::PageScanType::kStandardScan);
hci_cmd_runner_->QueueCommand(
std::move(write_type), [self, interlaced](const hci::EventPacket& event) {
if (BTEV_TEST_WARN(event,
"gap (BR/EDR): write page scan type failed")) {
return;
}
if (!self) {
return;
}
self->page_scan_type_ = (interlaced ? hci::PageScanType::kInterlacedScan
: hci::PageScanType::kStandardScan);
FXL_VLOG(2) << "gap (BR/EDR): page scan type updated";
});
hci_cmd_runner_->RunCommands(std::move(cb));
}
void BrEdrConnectionManager::OnConnectionRequest(
const hci::EventPacket& event) {
FXL_DCHECK(event.event_code() == hci::kConnectionRequestEventCode);
const auto& params =
event.view().payload<hci::ConnectionRequestEventParams>();
std::string link_type_str =
params.link_type == hci::LinkType::kACL ? "ACL" : "(e)SCO";
FXL_VLOG(1) << "gap (BR/EDR): " << link_type_str << " conn request from "
<< params.bd_addr.ToString() << "("
<< params.class_of_device.ToString() << ")";
if (params.link_type == hci::LinkType::kACL) {
// Accept the connection, performing a role switch. We receive a
// Connection Complete event when the connection is complete, and finish
// the link then.
FXL_LOG(INFO) << "gap (BR/EDR): accept incoming connection";
auto accept = hci::CommandPacket::New(
hci::kAcceptConnectionRequest,
sizeof(hci::AcceptConnectionRequestCommandParams));
auto accept_params =
accept->mutable_view()
->mutable_payload<hci::AcceptConnectionRequestCommandParams>();
accept_params->bd_addr = params.bd_addr;
accept_params->role = hci::ConnectionRole::kMaster;
hci_->command_channel()->SendCommand(std::move(accept), dispatcher_,
nullptr, hci::kCommandStatusEventCode);
return;
}
// Reject this connection.
FXL_LOG(INFO) << "gap (BR/EDR): reject unsupported connection";
auto reject = hci::CommandPacket::New(
hci::kRejectConnectionRequest,
sizeof(hci::RejectConnectionRequestCommandParams));
auto reject_params =
reject->mutable_view()
->mutable_payload<hci::RejectConnectionRequestCommandParams>();
reject_params->bd_addr = params.bd_addr;
reject_params->reason = hci::StatusCode::kConnectionRejectedBadBdAddr;
hci_->command_channel()->SendCommand(std::move(reject), dispatcher_, nullptr,
hci::kCommandStatusEventCode);
}
void BrEdrConnectionManager::OnConnectionComplete(
const hci::EventPacket& event) {
FXL_DCHECK(event.event_code() == hci::kConnectionCompleteEventCode);
const auto& params =
event.view().payload<hci::ConnectionCompleteEventParams>();
FXL_VLOG(1) << "gap (BR/EDR): " << params.bd_addr.ToString()
<< fxl::StringPrintf(
" connection complete (status: 0x%02x handle: 0x%04x)",
params.status, params.connection_handle);
if (BTEV_TEST_WARN(event, "gap (BR/EDR): connection error")) {
return;
}
common::DeviceAddress addr(common::DeviceAddress::Type::kBREDR,
params.bd_addr);
// TODO(jamuraa): support non-master connections.
auto conn_ptr = hci::Connection::CreateACL(
params.connection_handle, hci::Connection::Role::kMaster,
common::DeviceAddress(), // TODO(armansito): Pass local BD_ADDR here.
addr, hci_);
if (params.link_type != hci::LinkType::kACL) {
// Drop the connection if we don't support it.
return;
}
RemoteDevice* device = cache_->FindDeviceByAddress(addr);
if (!device) {
device = cache_->NewDevice(addr, true);
}
// Interrogate this device to find out it's version/capabilities.
interrogator_.Start(
device->identifier(), std::move(conn_ptr),
[device, self = weak_ptr_factory_.GetWeakPtr()](auto status,
auto conn_ptr) {
if (BT_TEST_WARN(
status,
"gap (BR/EDR): interrogate failed, dropping connection")) {
return;
}
self->connections_.emplace(device->identifier(), std::move(conn_ptr));
// TODO(NET-406, NET-407): set up the L2CAP signalling channel and
// start SDP service discovery.
});
}
void BrEdrConnectionManager::OnDisconnectionComplete(
const hci::EventPacket& event) {
FXL_DCHECK(event.event_code() == hci::kDisconnectionCompleteEventCode);
const auto& params =
event.view().payload<hci::DisconnectionCompleteEventParams>();
hci::ConnectionHandle handle = le16toh(params.connection_handle);
if (BTEV_TEST_WARN(
event,
fxl::StringPrintf(
"gap (BR/EDR): HCI disconnection error handle 0x%04x", handle))) {
return;
}
auto it = std::find_if(
connections_.begin(), connections_.end(),
[handle](const auto& p) { return (p.second->handle() == handle); });
if (it == connections_.end()) {
FXL_VLOG(1) << fxl::StringPrintf(
"gap (BR/EDR): disconnect from unknown handle 0x%04x", handle);
return;
}
std::string device = it->first;
auto conn = std::move(it->second);
connections_.erase(it);
FXL_LOG(INFO) << fxl::StringPrintf(
"gap (BR/EDR): %s disconnected - %s, handle: 0x%04x, reason: 0x%02x",
device.c_str(), event.ToStatus().ToString().c_str(), handle,
params.reason);
// TODO(NET-406): Inform L2CAP that the connection has been disconnected.
// Connection is already closed, so we don't need to send a disconnect.
conn->set_closed();
}
void BrEdrConnectionManager::OnIOCapabilitiesRequest(
const hci::EventPacket& event) {
FXL_DCHECK(event.event_code() == hci::kIOCapabilityRequestEventCode);
const auto& params =
event.view().payload<hci::IOCapabilityRequestEventParams>();
auto reply = hci::CommandPacket::New(
hci::kIOCapabilityRequestReply,
sizeof(hci::IOCapabilityRequestReplyCommandParams));
auto reply_params =
reply->mutable_view()
->mutable_payload<hci::IOCapabilityRequestReplyCommandParams>();
reply_params->bd_addr = params.bd_addr;
// TODO(jamuraa, NET-882): ask the PairingDelegate if it's set what the IO
// capabilities it has.
reply_params->io_capability = hci::IOCapability::kNoInputNoOutput;
// TODO(NET-1155): Add OOB status from RemoteDeviceCache.
reply_params->oob_data_present = 0x00; // None present.
// TODO(jamuraa): Determine this based on the service requirements.
reply_params->auth_requirements = hci::AuthRequirements::kNoBonding;
hci_->command_channel()->SendCommand(std::move(reply), dispatcher_, nullptr);
}
void BrEdrConnectionManager::OnUserConfirmationRequest(
const hci::EventPacket& event) {
FXL_DCHECK(event.event_code() == hci::kUserConfirmationRequestEventCode);
const auto& params =
event.view().payload<hci::UserConfirmationRequestEventParams>();
FXL_LOG(INFO) << "gap (BR/EDR): auto-confirming to " << params.bd_addr << " ("
<< params.numeric_value << ")";
// TODO(jamuraa, NET-882): if we are not NoInput/NoOutput then we need to ask
// the pairing delegate. This currently will auto accept any pairing
// (JustWorks)
auto reply = hci::CommandPacket::New(
hci::kUserConfirmationRequestReply,
sizeof(hci::UserConfirmationRequestReplyCommandParams));
auto reply_params =
reply->mutable_view()
->mutable_payload<hci::UserConfirmationRequestReplyCommandParams>();
reply_params->bd_addr = params.bd_addr;
hci_->command_channel()->SendCommand(std::move(reply), dispatcher_, nullptr);
}
} // namespace gap
} // namespace btlib
| [
"commit-bot@chromium.org"
] | commit-bot@chromium.org |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.