hexsha
stringlengths
40
40
size
int64
19
11.4M
ext
stringclasses
13 values
lang
stringclasses
1 value
max_stars_repo_path
stringlengths
3
270
max_stars_repo_name
stringlengths
5
110
max_stars_repo_head_hexsha
stringlengths
40
40
max_stars_repo_licenses
listlengths
1
9
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
3
270
max_issues_repo_name
stringlengths
5
116
max_issues_repo_head_hexsha
stringlengths
40
78
max_issues_repo_licenses
listlengths
1
9
max_issues_count
float64
1
67k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
3
270
max_forks_repo_name
stringlengths
5
116
max_forks_repo_head_hexsha
stringlengths
40
78
max_forks_repo_licenses
listlengths
1
9
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
19
11.4M
avg_line_length
float64
1.93
229k
max_line_length
int64
12
688k
alphanum_fraction
float64
0.07
0.99
matches
listlengths
1
10
9a32776e83779eaa3237921437666f5f1209d051
1,470
cpp
C++
String Matching Problems/CF-Palindrome Degree.cpp
Sohieb/competitive-programming
fe3fca0d4d2a242053d097c7ae71667a135cfc45
[ "MIT" ]
1
2021-07-17T12:59:08.000Z
2021-07-17T12:59:08.000Z
String Matching Problems/CF-Palindrome Degree.cpp
Sohieb/competitive-programming
fe3fca0d4d2a242053d097c7ae71667a135cfc45
[ "MIT" ]
null
null
null
String Matching Problems/CF-Palindrome Degree.cpp
Sohieb/competitive-programming
fe3fca0d4d2a242053d097c7ae71667a135cfc45
[ "MIT" ]
null
null
null
#include <bits/stdc++.h> using namespace std; using namespace __gnu_cxx; typedef double db; typedef long long ll; typedef pair<int,int> ii; #define F first #define S second #define pnl printf("\n") #define sz(x) (int)x.size() #define sf(x) scanf("%d",&x) #define pf(x) printf("%d\n",x) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define FOR(a,b) for(int i = a; i < b; ++i) const db eps = 1e-12; const db pi = acos(-1); const int inf = 0x3f3f3f3f; const ll INF = inf * 2LL * inf; const int mod = 1000 * 1000 * 1000 + 7; vector<int> z_function(string s){ int n = sz(s); vector<int> z(n); for(int i = 1, l = 0, r = 0; i < n; ++i){ if(i <= r) z[i] = min(r - i + 1, z[i - l]); while(i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; if(i + z[i] - 1 > r) l = i, r = i + z[i] - 1; } return z; } char s[5000005]; int deg[5000005]; ll res = 0; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); #endif scanf("%s", s); string str = s; string rev = s; reverse(all(rev)); str = str + "#" + rev; vector<int> z = z_function(str); deg[0] = 1; //cout << 0 << deg[0] << endl; for(int i = sz(str) - 1; i > sz(rev); --i) if(i + z[i] == sz(str)){ int j = sz(str) - i - 1; deg[j] = 1 + deg[(j + 1) / 2 - 1]; res += deg[j]; //cout << j << deg[j] << endl; } printf("%lld\n", res); return 0; }
22.615385
49
0.510884
[ "vector" ]
9a32fdde294fef54751dc2f898803c494712fb76
746
cpp
C++
app/src/main/jni/glesNative/dateLib.cpp
flopshot/GLDemo
ebc65d58b78b76474f393ea7e536a4570127a447
[ "Apache-2.0" ]
null
null
null
app/src/main/jni/glesNative/dateLib.cpp
flopshot/GLDemo
ebc65d58b78b76474f393ea7e536a4570127a447
[ "Apache-2.0" ]
null
null
null
app/src/main/jni/glesNative/dateLib.cpp
flopshot/GLDemo
ebc65d58b78b76474f393ea7e536a4570127a447
[ "Apache-2.0" ]
null
null
null
#include <jni.h> extern "C" JNIEXPORT jstring JNICALL Java_com_sean_gldemo_DateUtil_dateFromJNI(JNIEnv *env) { // Get a class reference for DateUtil class and get constructor method id jclass dateUtilClass = (env)->FindClass("com/sean/gldemo/DateUtil"); jmethodID dateUtilConstructor = (env)->GetMethodID(dateUtilClass, "<init>", "()V"); // Create DateUtil object and get non-static methodID of getFormattedDate() jobject dateUtilObject = (env)->NewObject(dateUtilClass, dateUtilConstructor); jmethodID dateMethodId = (env)->GetMethodID(dateUtilClass,"getFormattedDate","()Ljava/lang/String;"); // Execute & return getFormattedDate method return (jstring) env->CallObjectMethod(dateUtilObject, dateMethodId); }
43.882353
105
0.75067
[ "object" ]
9a352042e5f3ec10f2406d919982ea7fd2f03ee6
929
cpp
C++
android-28/android/hardware/SensorManager_DynamicSensorCallback.cpp
YJBeetle/QtAndroidAPI
1468b5dc6eafaf7709f0b00ba1a6ec2b70684266
[ "Apache-2.0" ]
12
2020-03-26T02:38:56.000Z
2022-03-14T08:17:26.000Z
android-28/android/hardware/SensorManager_DynamicSensorCallback.cpp
YJBeetle/QtAndroidAPI
1468b5dc6eafaf7709f0b00ba1a6ec2b70684266
[ "Apache-2.0" ]
1
2021-01-27T06:07:45.000Z
2021-11-13T19:19:43.000Z
android-30/android/hardware/SensorManager_DynamicSensorCallback.cpp
YJBeetle/QtAndroidAPI
1468b5dc6eafaf7709f0b00ba1a6ec2b70684266
[ "Apache-2.0" ]
3
2021-02-02T12:34:55.000Z
2022-03-08T07:45:57.000Z
#include "./Sensor.hpp" #include "./SensorManager_DynamicSensorCallback.hpp" namespace android::hardware { // Fields // QJniObject forward SensorManager_DynamicSensorCallback::SensorManager_DynamicSensorCallback(QJniObject obj) : JObject(obj) {} // Constructors SensorManager_DynamicSensorCallback::SensorManager_DynamicSensorCallback() : JObject( "android.hardware.SensorManager$DynamicSensorCallback", "()V" ) {} // Methods void SensorManager_DynamicSensorCallback::onDynamicSensorConnected(android::hardware::Sensor arg0) const { callMethod<void>( "onDynamicSensorConnected", "(Landroid/hardware/Sensor;)V", arg0.object() ); } void SensorManager_DynamicSensorCallback::onDynamicSensorDisconnected(android::hardware::Sensor arg0) const { callMethod<void>( "onDynamicSensorDisconnected", "(Landroid/hardware/Sensor;)V", arg0.object() ); } } // namespace android::hardware
25.108108
108
0.758881
[ "object" ]
9a374736af5b252f7092b491e6010dddb51e6161
2,647
cpp
C++
CPP/cdx/File.cpp
ThyMYthOS/cdx
46f2a976824d07d87a99789a671623c0b83a07c9
[ "BSD-2-Clause" ]
null
null
null
CPP/cdx/File.cpp
ThyMYthOS/cdx
46f2a976824d07d87a99789a671623c0b83a07c9
[ "BSD-2-Clause" ]
null
null
null
CPP/cdx/File.cpp
ThyMYthOS/cdx
46f2a976824d07d87a99789a671623c0b83a07c9
[ "BSD-2-Clause" ]
null
null
null
/** * \file File.cpp * * \date Mar 18, 2015 * \author: Frank Schubert */ #include "File.h" #include <stdexcept> using namespace std; /** * \addtogroup cpp_implementation * @{ */ namespace CDX { File::File(std::string _file_name) : file_name(_file_name), h5file(file_name.c_str(), H5F_ACC_RDONLY), c0_m_s( read_double_h5(h5file, "/parameters/c0_m_s")), cir_rate_Hz( read_double_h5(h5file, "/parameters/cir_rate_Hz")), transmitter_frequency_Hz( read_double_h5(h5file, "/parameters/transmitter_frequency_Hz")), delay_type( read_string_h5(h5file, "/parameters/delay_type")), links_group( h5file.openGroup("/links")), nof_links(links_group.getNumObjs()) { // open groups, one for each link: for (size_t k = 0; k < nof_links; k++) { std::string link_name = links_group.getObjnameByIdx(k); link_names.push_back(link_name); link_groups[link_name] = new H5::Group( links_group.openGroup(link_name)); } } File::File(std::string _file_name, double _c0_m_s, double _cir_rate_Hz, double _transmitter_frequency_Hz, const std::vector<std::string> &_link_names) : file_name(_file_name), h5file(file_name.c_str(), H5F_ACC_TRUNC), c0_m_s( _c0_m_s), cir_rate_Hz(_cir_rate_Hz), transmitter_frequency_Hz( _transmitter_frequency_Hz), link_names(_link_names), links_group( h5file.createGroup("/links")), nof_links(link_names.size()) { } File::~File() { // close link groups which were openend in constructor: for (size_t k = 0; k < link_names.size(); k++) { delete link_groups[link_names.at(k)]; } } double File::read_double_h5(H5::H5File file, std::string dataset_name) { H5::DataSet dataset = file.openDataSet(dataset_name); H5::DataSpace dataspace(dataset.getSpace()); // get rank of data: const int rank = dataspace.getSimpleExtentNdims(); if (rank > 1) { std::stringstream ss; ss << "read_double_h5: error: Dataset " << dataset_name << " has rank > 1 (rank = " << rank << ")."; throw std::runtime_error(ss.str()); } double data = 0.0; dataset.read(&data, H5::PredType::NATIVE_DOUBLE); return data; } std::string File::read_string_h5(H5::H5File file, std::string path) { H5::DataSet delay_type_set = H5::DataSet(file.openDataSet(path)); H5::DataType delay_type_type = delay_type_set.getDataType(); int delay_type_len = delay_type_type.getSize(); H5::DataSpace delay_type_space = H5::DataSpace(delay_type_set.getSpace()); char delay_type[delay_type_len + 1]; delay_type_set.read(delay_type, delay_type_type, delay_type_space); delay_type[delay_type_len] = 0; const std::string out = delay_type; return out; } } // end of namespace CDX /** * @} */
27.010204
81
0.71326
[ "vector" ]
9a3a9cd3008b1a7e6e6d447e8c480a809a616992
6,903
hpp
C++
include/stl2/detail/iterator/operations.hpp
marehr/cmcstl2
7a7cae1e23beacb18fd786240baef4ae121d813f
[ "MIT" ]
null
null
null
include/stl2/detail/iterator/operations.hpp
marehr/cmcstl2
7a7cae1e23beacb18fd786240baef4ae121d813f
[ "MIT" ]
null
null
null
include/stl2/detail/iterator/operations.hpp
marehr/cmcstl2
7a7cae1e23beacb18fd786240baef4ae121d813f
[ "MIT" ]
null
null
null
// cmcstl2 - A concept-enabled C++ standard library // // Copyright Casey Carter 2015 // // Use, modification and distribution is subject to 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) // // Project home: https://github.com/caseycarter/cmcstl2 // #ifndef STL2_DETAIL_ITERATOR_OPERATIONS_HPP #define STL2_DETAIL_ITERATOR_OPERATIONS_HPP #include <stl2/detail/fwd.hpp> #include <stl2/detail/algorithm/tagspec.hpp> #include <stl2/detail/iterator/concepts.hpp> #include <stl2/detail/concepts/object.hpp> /////////////////////////////////////////////////////////////////////////// // Iterator operations [iterator.operations] STL2_OPEN_NAMESPACE { // advance namespace __advance { template<class I> requires Iterator<I> // Pre: 0 <= n && [i,i+n) constexpr void impl(I& i, iter_difference_t<I> n) noexcept(noexcept(++std::declval<I&>())) { STL2_EXPECT(0 <= n); while (n != 0) { --n; ++i; } } } Iterator{I} // Pre: 0 <= n && [i,i+n) constexpr void advance(I& i, iter_difference_t<I> n) noexcept(noexcept(++std::declval<I&>())) { __advance::impl(i, n); } BidirectionalIterator{I} // Pre: 0 <= n ? [i,i+n) : [i+n,i) constexpr void advance(I& i, iter_difference_t<I> n) noexcept(noexcept(++std::declval<I&>(), --std::declval<I&>())) { if (0 <= n) { __advance::impl(i, n); } else { do { ++n; --i; } while (n != 0); } } RandomAccessIterator{I} // Pre: 0 <= n ? [i,i+n) : [i+n,i) constexpr void advance(I& i, iter_difference_t<I> n) STL2_NOEXCEPT_RETURN( (void)(i += n) ) template<class I, class S> requires Sentinel<S, I> // Pre: [i,bound) constexpr void advance(I& i, S bound) noexcept(noexcept(++i != bound)) { while (i != bound) { ++i; } } template<class I, class S> requires Sentinel<S, I> && Assignable<I&, S&&> constexpr void advance(I& i, S bound) STL2_NOEXCEPT_RETURN( (void)(i = std::move(bound)) ) template<class I, class S> requires Sentinel<S, I> && !Assignable<I&, S&&> && SizedSentinel<S, I> // Pre: [i,bound) constexpr void advance(I& i, S bound) noexcept(noexcept(__stl2::advance(i, bound - i))) { iter_difference_t<I> d = bound - i; STL2_EXPECT(0 <= d); __stl2::advance(i, d); } namespace __advance { template<class I, class S> requires Sentinel<S, I> // Pre: 0 == n || (0 < n && [i,bound)) constexpr iter_difference_t<I> impl(I& i, iter_difference_t<I> n, const S& bound) noexcept(noexcept(++i != bound)) { STL2_EXPECT(0 <= n); while (n != 0 && i != bound) { ++i; --n; } return n; } } template<class I, class S> requires Sentinel<S, I> // Pre: 0 == n || (0 < n && [i,bound)) constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound) STL2_NOEXCEPT_RETURN( __advance::impl(i, n, bound) ) template<class I, class S> requires Sentinel<S, I> && SizedSentinel<S, I> // Pre: 0 <= n && [i,bound) constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound) noexcept(noexcept( __stl2::advance(i, std::move(bound)), __stl2::advance(i, bound - i))) { STL2_EXPECT(0 <= n); auto d = iter_difference_t<I>{bound - i}; STL2_EXPECT(0 <= d); if (d <= n) { __stl2::advance(i, std::move(bound)); return n - d; } __stl2::advance(i, n); return 0; } template<class I> requires BidirectionalIterator<I> // Pre: 0 == n || (0 < n ? [i,bound) : [bound,i)) constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, I bound) noexcept(noexcept( __advance::impl(i, n, bound), --i != bound)) { if (0 <= n) { return __advance::impl(i, n, bound); } do { --i; ++n; } while (n != 0 && i != bound); return n; } template<class I> requires BidirectionalIterator<I> && SizedSentinel<I, I> // Pre: 0 == n ? ([i,bound) || [bound,i)) : (0 < n ? [i,bound) : [bound,i)) constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, I bound) noexcept(noexcept( i = std::move(bound), __stl2::advance(i, bound - i))) { auto d = iter_difference_t<I>{bound - i}; STL2_EXPECT(0 <= n ? 0 <= d : 0 >= d); if (0 <= n ? d <= n : d >= n) { i = std::move(bound); return n - d; } __stl2::advance(i, n); return 0; } // next Iterator{I} constexpr I next(I x, iter_difference_t<I> n = 1) STL2_NOEXCEPT_RETURN( __stl2::advance(x, n), x ) template<class S, class I> requires Sentinel<__f<S>, I> constexpr I next(I x, S&& bound) STL2_NOEXCEPT_RETURN( __stl2::advance(x, std::forward<S>(bound)), x ) template<class S, class I> requires Sentinel<__f<S>, I> constexpr I next(I x, iter_difference_t<I> n, S&& bound) STL2_NOEXCEPT_RETURN( __stl2::advance(x, n, std::forward<S>(bound)), x ) // prev BidirectionalIterator{I} constexpr I prev(I x, iter_difference_t<I> n = 1) STL2_NOEXCEPT_RETURN( __stl2::advance(x, -n), x ) BidirectionalIterator{I} constexpr I prev(I x, iter_difference_t<I> n, I bound) STL2_NOEXCEPT_RETURN( __stl2::advance(x, -n, std::move(bound)), x ) namespace ext { Sentinel{S, I} constexpr tagged_pair<tag::count(iter_difference_t<I>), tag::end(I)> enumerate(I first, S last) noexcept(noexcept(++first != last) && std::is_nothrow_move_constructible<I>::value) { iter_difference_t<I> n = 0; while (first != last) { ++n; ++first; } return {n, std::move(first)}; } SizedSentinel{S, I} constexpr tagged_pair<tag::count(iter_difference_t<I>), tag::end(I)> enumerate(I first, S last) noexcept(noexcept(__stl2::next(std::move(first), std::move(last))) && std::is_nothrow_move_constructible<I>::value) { auto d = last - first; STL2_EXPECT((Same<I, S> || d >= 0)); return {d, __stl2::next(std::move(first), std::move(last))}; } template<class S, class I> requires Sentinel<S, I> && !SizedSentinel<S, I> && SizedSentinel<I, I> constexpr tagged_pair<tag::count(iter_difference_t<I>), tag::end(I)> enumerate(I first, S last) noexcept(noexcept(__stl2::next(first, std::move(last))) && std::is_nothrow_move_constructible<I>::value) { auto end = __stl2::next(first, std::move(last)); auto n = end - first; return {n, std::move(end)}; } } // distance Sentinel{S, I} // Pre: [first, last) constexpr iter_difference_t<I> distance(I first, S last) STL2_NOEXCEPT_RETURN( ext::enumerate(std::move(first), std::move(last)).first ) SizedSentinel{S, I} // Pre: [first, last) constexpr iter_difference_t<I> distance(I first, S last) noexcept(noexcept(last - first)) { auto d = last - first; STL2_EXPECT(d >= 0); return d; } template<class I> requires SizedSentinel<I, I> // Pre: [first, last) || [last, first) constexpr iter_difference_t<I> distance(I first, I last) STL2_NOEXCEPT_RETURN( last - first ) } STL2_CLOSE_NAMESPACE #endif
22.782178
77
0.623207
[ "object" ]
9a503ae41c10422085abf8e3fdd3c63d0e3e405a
1,507
cpp
C++
BRAC University Competitive Programming training/Beginner Classes/Graph traversal/BFS.cpp
mitul3737/Mitul-s-Competitive-Programming-March-May
d1ce08f549b4a923623436b2ca750a20230094ca
[ "MIT" ]
1
2021-04-23T16:53:35.000Z
2021-04-23T16:53:35.000Z
BRAC University Competitive Programming training/Beginner Classes/Graph traversal/BFS.cpp
mitul3737/Mitul-s-Competitive-Programming-March-May
d1ce08f549b4a923623436b2ca750a20230094ca
[ "MIT" ]
null
null
null
BRAC University Competitive Programming training/Beginner Classes/Graph traversal/BFS.cpp
mitul3737/Mitul-s-Competitive-Programming-March-May
d1ce08f549b4a923623436b2ca750a20230094ca
[ "MIT" ]
1
2021-03-27T19:56:19.000Z
2021-03-27T19:56:19.000Z
//BFS // lets have a graph who has 6 nodes and 7 edges and edges are 1to 2 ,1 to 5,1to 3, 5 to , 3 to 4, 2 to 4, 2 to 3 //Input: //6 //7 //1 2 //1 5 //1 3 //2 3 //2 4 //3 4 //5 6 //Output: //Calling Bfs at 1 //BFS at 1 //BFS at 2 //BFS at 5 //BFS at 3 //BFS at 4 //BFS at 6 #include <bits/stdc++.h> using namespace std; const int nmax=100000+10; vector<int>adjacentlist[nmax]; bool visited[nmax];//to make notified that one node has been visited or not void bfs(int u){ queue<int> q; q.push(u); visited[u]=true; while(!q.empty()){ // till it is not empty, u ets the next alue to do the process u=q.front(); q.pop();// fromt the queue q, the first value will then be removed cout<<"BFS at "<<u<<endl; for(int v: adjacentlist[u]){ // inserting the adjacent indexes to v and checking if they were visited or not if(!visited[v]){ visited[v]= true; q.push(v); } } } } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int v,e;// v= nodes, e = edges cin>>v>>e; for(int i=0; i<e;i++){ int u,v; cin>>u>>v; //store adjacentlist[u].push_back(v);//in list of u ,keep v //if undirected, need this adjacentlist[v].push_back(u); } for(int i=1; i<=v;i++){ if(!visited[i]){ cout<<"Calling Bfs from "<<i<<endl; bfs(i); } } return 0; }
17.523256
116
0.528865
[ "vector" ]
9a646c01855a96cc963eb51d2d0799233593bf8a
4,188
cpp
C++
t/08-markers.cpp
HungMingWu/cpp-bredis
5665bf36d0400eab8d773ae95fa71e5c84a81dd7
[ "MIT" ]
null
null
null
t/08-markers.cpp
HungMingWu/cpp-bredis
5665bf36d0400eab8d773ae95fa71e5c84a81dd7
[ "MIT" ]
null
null
null
t/08-markers.cpp
HungMingWu/cpp-bredis
5665bf36d0400eab8d773ae95fa71e5c84a81dd7
[ "MIT" ]
null
null
null
#include <boost/asio/buffer.hpp> #include <string> #include <vector> #include "bredis/MarkerHelpers.hpp" #include "bredis/Protocol.hpp" #include "catch.hpp" namespace r = bredis; namespace asio = boost::asio; using Iterator = std::string::iterator; TEST_CASE("subscription mixed case", "[markers]") { std::string cmd_subscribe{"subscribe"}; std::string cmd_psubscribe{"psubscribe"}; std::string cmd_channel1 = "channel1"; std::string cmd_channel2 = "channel2"; std::string cmd_idx_1 = "1"; std::string cmd_idx_2 = "2"; std::string cmd_idx_5 = "5"; r::markers::redis_result_t reply_1{ r::markers::array_holder_t{ {r::markers::string_t{cmd_subscribe}, r::markers::string_t{cmd_channel1}, r::markers::int_t{ {cmd_idx_1}}}}}; r::markers::redis_result_t reply_2{ r::markers::array_holder_t{ {r::markers::string_t{cmd_subscribe}, r::markers::string_t{cmd_channel2}, r::markers::int_t{ {cmd_idx_1}}}}}; r::markers::redis_result_t reply_3{ r::markers::array_holder_t{ {r::markers::string_t{cmd_subscribe}, r::markers::string_t{cmd_channel2}, r::markers::int_t{ {cmd_idx_2}}}}}; r::markers::redis_result_t reply_wrong_1; r::markers::redis_result_t reply_wrong_2{ r::markers::array_holder_t{ {r::markers::string_t{cmd_psubscribe}, r::markers::string_t{cmd_channel2}, r::markers::int_t{ {cmd_idx_1}}}}}; r::markers::redis_result_t reply_wrong_3{ r::markers::array_holder_t{{ r::markers::int_t{{cmd_idx_1}}, r::markers::int_t{{cmd_idx_1}}, r::markers::int_t{{cmd_idx_1}}, }}}; r::markers::redis_result_t reply_wrong_4{ r::markers::array_holder_t{{ r::markers::int_t{{cmd_idx_1}}, r::markers::int_t{{cmd_idx_1}}, r::markers::int_t{{cmd_idx_1}}, r::markers::int_t{{cmd_idx_1}}, }}}; r::markers::redis_result_t reply_wrong_5{ r::markers::array_holder_t{{ r::markers::string_t{cmd_psubscribe}, r::markers::string_t{cmd_channel2}, r::markers::string_t{cmd_psubscribe} }}}; r::markers::redis_result_t reply_wrong_6{ r::markers::array_holder_t{{ r::markers::string_t{cmd_psubscribe}, r::markers::string_t{cmd_channel2}, r::markers::int_t{ {cmd_channel2}}, }}}; r::markers::redis_result_t reply_wrong_7{ r::markers::array_holder_t{ {r::markers::string_t{cmd_subscribe}, r::markers::string_t{cmd_channel1}, r::markers::int_t{ {cmd_idx_5}}}}}; r::single_command_t subscribe_1{"subscribe", cmd_channel1}; r::single_command_t subscribe_2{"SUBSCRIBE", cmd_channel2}; r::single_command_t subscribe_3{"SUBSCRIBE", cmd_channel1, cmd_channel2}; r::marker_helpers::check_subscription check_subscription_1{ std::move(subscribe_1)}; REQUIRE(std::visit(check_subscription_1, reply_1)); REQUIRE(!std::visit(check_subscription_1, reply_2)); REQUIRE(!std::visit(check_subscription_1, reply_wrong_1)); REQUIRE(!std::visit(check_subscription_1, reply_wrong_2)); REQUIRE(!std::visit(check_subscription_1, reply_wrong_3)); REQUIRE(!std::visit(check_subscription_1, reply_wrong_4)); REQUIRE(!std::visit(check_subscription_1, reply_wrong_5)); REQUIRE(!std::visit(check_subscription_1, reply_wrong_6)); REQUIRE(!std::visit(check_subscription_1, reply_wrong_7)); r::marker_helpers::check_subscription check_subscription_2{ std::move(subscribe_2)}; REQUIRE(std::visit(check_subscription_2, reply_2)); REQUIRE(!std::visit(check_subscription_2, reply_1)); r::marker_helpers::check_subscription check_subscription_3{ std::move(subscribe_3)}; REQUIRE(std::visit(check_subscription_3, reply_1)); REQUIRE(std::visit(check_subscription_3, reply_3)); REQUIRE(!std::visit(check_subscription_3, reply_2)); }
37.72973
77
0.634193
[ "vector" ]
9a6ad0072453f083cef104ecb79ad6c800d171ae
210,933
cpp
C++
PrototypeEngine/src/opengl/PrototypeOpenglUI.cpp
o-micron/Prototype
5b9d60d9dd80e7c8a1a2b0aaf19c2d90c1814139
[ "Apache-2.0" ]
2
2021-08-19T17:15:49.000Z
2021-12-28T22:48:47.000Z
PrototypeEngine/src/opengl/PrototypeOpenglUI.cpp
o-micron/Prototype
5b9d60d9dd80e7c8a1a2b0aaf19c2d90c1814139
[ "Apache-2.0" ]
null
null
null
PrototypeEngine/src/opengl/PrototypeOpenglUI.cpp
o-micron/Prototype
5b9d60d9dd80e7c8a1a2b0aaf19c2d90c1814139
[ "Apache-2.0" ]
null
null
null
/// Copyright 2021 Omar Sherif Fathy /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. #include "../core/PrototypePipelines.h" #include "PrototypeOpenglUI.h" #include "PrototypeOpenglRenderer.h" #include "../core/PrototypeDatabase.h" #include "../core/PrototypeCameraSystem.h" #include "../core/PrototypeScene.h" #include "../core/PrototypeSceneLayer.h" #include "../core/PrototypeSceneNode.h" #include "../core/PrototypeMaterial.h" #include "../core/PrototypeMeshBuffer.h" #include "../core/PrototypePluginInstance.h" #include "../core/PrototypeShaderBuffer.h" #include "../core/PrototypeShortcuts.h" #include "../core/PrototypeTextureBuffer.h" #include "../core/PrototypeEngine.h" #include "../core/PrototypeWindow.h" #include "../core/PrototypePhysics.h" #include "../core/PrototypeProfiler.h" #include <PrototypeCommon/IO.h> #include <PrototypeCommon/Logger.h> #include <PrototypeTraitSystem/PrototypeTraitSystem.h> #define FMT_HEADER_ONLY #include <fmt/format.h> #include <fmt/printf.h> #include <inttypes.h> #include <sstream> #define GLSL_VERSION std::string("#version 410 core") #define COMPONENT_UI_HEADER(NAME) \ static ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_OpenOnArrow | \ ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_Framed | \ ImGuiTreeNodeFlags_SpanAvailWidth; \ { \ static bool is_open = true; \ ImGuiHelpers::BeginGroupPanel(#NAME, ImVec2(-1.0f, 0.0f), is_open, _awesomeFontTrait); \ if (is_open) { \ ImGui::Indent(16.0f); #define COMPONENT_UI_FOOTER() \ } \ ImGui::Unindent(16.0f); \ ImGuiHelpers::EndGroupPanel(); \ } static float TEXT_BASE_WIDTH = 1.0f; static float TEXT_BASE_HEIGHT = 1.0f; static ImFont* _defaultFont = nullptr; // 8 bytes static ImFont* _awesomeFont = nullptr; // 8 bytes static ImFont* _awesomeFontTrait = nullptr; // 8 bytes static ImFont* _awesomeFontTitle = nullptr; // 8 bytes static ImFont* _awesomeFontBtnIcons = nullptr; // 8 bytes static PrototypeConfigurationSelection _assetConfigSelection; static void onCameraEditDispatch(PrototypeObject* o) { COMPONENT_UI_HEADER(Camera) void* VoidSceneCamera; ((PrototypeOpenglRenderer*)PrototypeEngineInternalApplication::renderer)->fetchCamera("SceneCamera", &VoidSceneCamera); PglCamera& camera = *((PglCamera*)VoidSceneCamera); Camera* cam = o->getCameraTrait(); static glm::vec3 translation; static glm::vec2 rotation; translation = cam->position(); rotation = cam->rotation(); static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("camera content table", 2, tableFlags)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Position"); ImGui::TableSetColumnIndex(1); PrototypeImguiVec3WidgetUntitled( 20.0f, if (ImGui::DragFloat("##camera position x", &translation.x, 0.1f, -1000.0f, 1000.0f)) { CameraSystemSetTranslation(cam, translation); }, if (ImGui::DragFloat("##camera position y", &translation.y, 0.1f, -1000.0f, 1000.0f)) { CameraSystemSetTranslation(cam, translation); }, if (ImGui::DragFloat("##camera position z", &translation.z, 0.1f, -1000.0f, 1000.0f)) { CameraSystemSetTranslation(cam, translation); }, 3.0f, -2.0f, "X", "Y", "Z") {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Rotation"); ImGui::TableSetColumnIndex(1); PrototypeImguiVec2WidgetUntitled( 20.0f, if (ImGui::DragFloat("##camera rotation x", &rotation.x, 0.1f, -90.0f, 90.0f)) { CameraSystemSetRotation(cam, rotation); }, if (ImGui::DragFloat("##camera rotation y", &rotation.y, 0.1f, -360.0f, 360.0f)) { CameraSystemSetRotation(cam, rotation); }, 3.0f, -2.0f, "X", "Y") {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Look Sensitivity"); ImGui::TableSetColumnIndex(1); if (ImGui::DragFloat("##Look Sensitivity", &cam->lookSensitivityMut(), 0.001f, 0.001f, 10.0f)) {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Move Sensitivity"); ImGui::TableSetColumnIndex(1); if (ImGui::DragFloat("##Move Sensitivity", &cam->moveSensitivityMut(), 0.001f, 0.001f, 10.0f)) {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Field of view"); ImGui::TableSetColumnIndex(1); if (ImGui::DragFloat("##Field of view", &cam->fovMut(), 0.01f, 5.0f, 120.0f)) {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Near plane"); ImGui::TableSetColumnIndex(1); if (ImGui::DragFloat("##Near plane", &cam->nearMut(), 0.1f, 0.1f, 100.0f)) {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Far plane"); ImGui::TableSetColumnIndex(1); if (ImGui::DragFloat("##Far plane", &cam->farMut(), 1.0f, 1.0f, 10000.0f)) {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Orbital"); ImGui::TableSetColumnIndex(1); if (ImGui::Checkbox("##Orbital", &cam->orbitalMut())) {} // deferred stage { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Deferred pass"); ImGui::TableSetColumnIndex(1); ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::InputText( "##Deferred pass", (char*)camera.deferredFramebuffer->name.c_str(), camera.deferredFramebuffer->name.size()); ImGui::PopItemFlag(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_FRAMEBUFFER")) { IM_ASSERT(payload->DataSize == sizeof(PglFramebuffer*)); auto framebuffer = *(PglFramebuffer**)payload->Data; camera.deferredFramebuffer = framebuffer; PrototypeEngineInternalApplication::renderer->scheduleRecordPass(); } ImGui::EndDragDropTarget(); } for (auto& pair : camera.deferredFramebuffer->shader->floatData) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat(fmt::format("##{}", pair.first).c_str(), &pair.second); } for (auto& pair : camera.deferredFramebuffer->shader->vec2Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat2(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } for (auto& pair : camera.deferredFramebuffer->shader->vec3Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat3(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } for (auto& pair : camera.deferredFramebuffer->shader->vec4Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat4(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } } // gbuffer stage { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("GBuffer pass"); ImGui::TableSetColumnIndex(1); ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::InputText( "##GBuffer pass", (char*)camera.gbufferFramebuffer->name.c_str(), camera.gbufferFramebuffer->name.size()); ImGui::PopItemFlag(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_FRAMEBUFFER")) { IM_ASSERT(payload->DataSize == sizeof(PglFramebuffer*)); auto framebuffer = *(PglFramebuffer**)payload->Data; camera.gbufferFramebuffer = framebuffer; PrototypeEngineInternalApplication::renderer->scheduleRecordPass(); } ImGui::EndDragDropTarget(); } for (auto& pair : camera.gbufferFramebuffer->shader->floatData) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat(fmt::format("##{}", pair.first).c_str(), &pair.second); } for (auto& pair : camera.gbufferFramebuffer->shader->vec2Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat2(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } for (auto& pair : camera.gbufferFramebuffer->shader->vec3Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat3(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } for (auto& pair : camera.gbufferFramebuffer->shader->vec4Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat4(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } } // post processing stage { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Post-processing pass"); ImGui::TableSetColumnIndex(1); ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::InputText("##Post-processing pass", (char*)camera.postprocessingFramebuffer->name.c_str(), camera.postprocessingFramebuffer->name.size()); ImGui::PopItemFlag(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_FRAMEBUFFER")) { IM_ASSERT(payload->DataSize == sizeof(PglFramebuffer*)); auto framebuffer = *(PglFramebuffer**)payload->Data; camera.postprocessingFramebuffer = framebuffer; PrototypeEngineInternalApplication::renderer->scheduleRecordPass(); } ImGui::EndDragDropTarget(); } for (auto& pair : camera.postprocessingFramebuffer->shader->floatData) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat(fmt::format("##{}", pair.first).c_str(), &pair.second); } for (auto& pair : camera.postprocessingFramebuffer->shader->vec2Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat2(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } for (auto& pair : camera.postprocessingFramebuffer->shader->vec3Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat3(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } for (auto& pair : camera.postprocessingFramebuffer->shader->vec4Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat4(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } } ImGui::EndTable(); } COMPONENT_UI_FOOTER() } static void onColliderEditDispatch(PrototypeObject* o) { COMPONENT_UI_HEADER(Collider) Collider* collider = o->getColliderTrait(); static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("collider content table", 2, tableFlags)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Shape"); ImGui::TableSetColumnIndex(1); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::Button((char*)collider->nameRef().c_str(), ImVec2(ImGui::GetContentRegionAvailWidth(), 30.0f)); ImGui::PopStyleColor(4); ImGui::PopStyleVar(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_COLLIDER")) { IM_ASSERT(payload->DataSize == sizeof(PrototypeClipboard)); PrototypeClipboard clipboard = *(PrototypeClipboard*)payload->Data; PrototypeEngineInternalApplication::physics->updateCollider(o, clipboard.data[0]); } ImGui::EndDragDropTarget(); } ImGui::EndTable(); } COMPONENT_UI_FOOTER() } static void onMeshRendererEditDispatch(PrototypeObject* o) { COMPONENT_UI_HEADER(MeshRenderer) MeshRenderer* mr = o->getMeshRendererTrait(); static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("mesh renderer content table", 2, tableFlags)) { static int numberOfAttachedMeshMaterialPairs = 1; numberOfAttachedMeshMaterialPairs = mr->data().size(); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Count"); ImGui::TableSetColumnIndex(1); if (ImGui::InputInt("##numberOfAttachedMeshMaterialPairs", &numberOfAttachedMeshMaterialPairs)) { if (numberOfAttachedMeshMaterialPairs < 1) { numberOfAttachedMeshMaterialPairs = 1; } size_t originalSize = mr->data().size(); mr->data().resize(numberOfAttachedMeshMaterialPairs, mr->data()[originalSize - 1]); } for (size_t mmi = 0; mmi < mr->data().size(); ++mmi) { ImGui::PushID(mmi); MeshRendererPolygonMode_& polygonMode = mr->data()[mmi].polygonMode; std::string& meshName = mr->data()[mmi].mesh; std::string& materialName = mr->data()[mmi].material; { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Material"); ImGui::TableSetColumnIndex(1); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); if (ImGui::Button((char*)fmt::format("{}##{}", materialName, mmi).c_str(), ImVec2(ImGui::GetContentRegionAvailWidth(), 30.0f))) { PglMaterial* material; PrototypeEngineInternalApplication::renderer->fetchMaterial(materialName, (void**)&material); if (material) { _assetConfigSelection.type = PrototypeConfigurationSelectionAssetType_Material; _assetConfigSelection.material = material; } } if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_MATERIAL")) { IM_ASSERT(payload->DataSize == sizeof(PglMaterial*)); PglMaterial* material = *(PglMaterial**)payload->Data; materialName = material->name; PrototypeEngineInternalApplication::renderer->scheduleRecordPass(); } ImGui::EndDragDropTarget(); } ImGui::PopStyleColor(4); ImGui::PopStyleVar(); } { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Mesh"); ImGui::TableSetColumnIndex(1); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); if (ImGui::Button((char*)fmt::format("{}##{}", meshName, mmi).c_str(), ImVec2(ImGui::GetContentRegionAvailWidth(), 30.0f))) { PglGeometry* mesh; PrototypeEngineInternalApplication::renderer->fetchMesh(meshName, (void**)&mesh); if (mesh) { _assetConfigSelection.type = PrototypeConfigurationSelectionAssetType_Mesh; _assetConfigSelection.mesh = mesh; } } if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_MESH")) { IM_ASSERT(payload->DataSize == sizeof(PglGeometry*)); PglGeometry* mesh = *(PglGeometry**)payload->Data; meshName = mesh->name; PrototypeEngineInternalApplication::renderer->scheduleRecordPass(); } ImGui::EndDragDropTarget(); } ImGui::PopStyleColor(4); ImGui::PopStyleVar(); } { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Polygon mode"); ImGui::TableSetColumnIndex(1); const char* polygonModes[MeshRendererPolygonMode_COUNT] = { "POINT", "LINE", "FILL" }; if (ImGui::Combo("##PolygonMode", (int*)&polygonMode, polygonModes, MeshRendererPolygonMode_COUNT)) { PrototypeEngineInternalApplication::renderer->scheduleRecordPass(); } } ImGui::PopID(); } ImGui::EndTable(); } COMPONENT_UI_FOOTER() } static void onRigidbodyEditDispatch(PrototypeObject* o) { COMPONENT_UI_HEADER(Rigidbody) Rigidbody* rb = o->getRigidbodyTrait(); static glm::vec3 linearVelocity; static f32 linearDamping; static glm::vec3 angularVelocity; static f32 angularDamping; static f32 mass; linearVelocity = rb->linearVelocity(); linearDamping = rb->linearDamping(); angularVelocity = rb->angularVelocity(); angularDamping = rb->angularDamping(); mass = rb->mass(); static bool isTriggerCollider; isTriggerCollider = rb->isTrigger(); static bool isStaticCollider; isStaticCollider = rb->isStatic(); static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("rigidbody content table", 2, tableFlags)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("trigger"); ImGui::TableSetColumnIndex(1); if (ImGui::Checkbox("##trigger", &isTriggerCollider)) { rb->setTrigger(isTriggerCollider); PrototypeEngineInternalApplication::physics->updateRigidbodyTrigger(o); } ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("static"); ImGui::TableSetColumnIndex(1); if (ImGui::Checkbox("##static", &isStaticCollider)) { rb->setStatic(isStaticCollider); PrototypeEngineInternalApplication::physics->updateRigidbodyStatic(o); } if (!rb->isStatic()) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Linear velocity"); ImGui::TableSetColumnIndex(1); PrototypeImguiVec3WidgetUntitled( 20.0f, if (ImGui::DragFloat("##linear velocity x", &linearVelocity.x, 0.1f, -1000.0f, 1000.0f)) { rb->setLinearVelocity(linearVelocity); PrototypeEngineInternalApplication::physics->updateRigidbodyLinearVelocity(o); }, if (ImGui::DragFloat("##linear velocity y", &linearVelocity.y, 0.1f, -1000.0f, 1000.0f)) { rb->setLinearVelocity(linearVelocity); PrototypeEngineInternalApplication::physics->updateRigidbodyLinearVelocity(o); }, if (ImGui::DragFloat("##linear velocity z", &linearVelocity.z, 0.1f, -1000.0f, 1000.0f)) { rb->setLinearVelocity(linearVelocity); PrototypeEngineInternalApplication::physics->updateRigidbodyLinearVelocity(o); }, 3.0f, -2.0f, "X", "Y", "Z") {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Linear damping"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::DragFloat("##linear damping", &linearDamping, 0.1f, 0.01f, 1000.0f)) { rb->setLinearDamping(linearDamping); PrototypeEngineInternalApplication::physics->updateRigidbodyLinearDamping(o); } ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Angular velocity"); ImGui::TableSetColumnIndex(1); PrototypeImguiVec3WidgetUntitled( 20.0f, if (ImGui::DragFloat("##angular velocity x", &angularVelocity.x, 0.1f, -1000.0f, 1000.0f)) { rb->setAngularVelocity(angularVelocity); PrototypeEngineInternalApplication::physics->updateRigidbodyAngularVelocity(o); }, if (ImGui::DragFloat("##angular velocity y", &angularVelocity.y, 0.1f, -1000.0f, 1000.0f)) { rb->setAngularVelocity(angularVelocity); PrototypeEngineInternalApplication::physics->updateRigidbodyAngularVelocity(o); }, if (ImGui::DragFloat("##angular velocity z", &angularVelocity.z, 0.1f, -1000.0f, 1000.0f)) { rb->setAngularVelocity(angularVelocity); PrototypeEngineInternalApplication::physics->updateRigidbodyAngularVelocity(o); }, 3.0f, -2.0f, "X", "Y", "Z") {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Angular damping"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::DragFloat("##angular damping", &angularDamping, 0.1f, 0.01f, 1000.0f)) { rb->setAngularDamping(angularDamping); PrototypeEngineInternalApplication::physics->updateRigidbodyAngularDamping(o); } ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Mass"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::DragFloat("##mass", &mass, 0.1f, 0.0f, 1000.0f)) { rb->setMass(mass); PrototypeEngineInternalApplication::physics->updateRigidbodyMass(o); } ImGuiWindow* window = ImGui::GetCurrentWindow(); // Lock Linear { static bool linearLocked = false; ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Lock Position"); ImGui::TableSetColumnIndex(1); PrototypeImguiVec3WidgetUntitled( 20.0f, if (ImGui::Checkbox("##Lock linear X", &rb->lockLinearXMut())) linearLocked = true, if (ImGui::Checkbox("##Lock linear Y", &rb->lockLinearYMut())) linearLocked = true, if (ImGui::Checkbox("##Lock linear Z", &rb->lockLinearZMut())) linearLocked = true, 3.0f, -2.0f, "X", "Y", "Z") {} if (linearLocked) { PrototypeEngineInternalApplication::physics->updateRigidbodyLockLinear(o); } } // Lock Angles { static bool angularLocked = false; ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Lock Rotation"); ImGui::TableSetColumnIndex(1); PrototypeImguiVec3WidgetUntitled( 20.0f, if (ImGui::Checkbox("##Lock angular X", &rb->lockAngularXMut())) angularLocked = true, if (ImGui::Checkbox("##Lock angular Y", &rb->lockAngularYMut())) angularLocked = true, if (ImGui::Checkbox("##Lock angular Z", &rb->lockAngularZMut())) angularLocked = true, 3.0f, -2.0f, "X", "Y", "Z") {} if (angularLocked) { PrototypeEngineInternalApplication::physics->updateRigidbodyLockAngular(o); } } } ImGui::EndTable(); } COMPONENT_UI_FOOTER() } static void onScriptEditDispatch(PrototypeObject* o) { COMPONENT_UI_HEADER(Script) Script* script = o->getScriptTrait(); if (script->codeLinks.empty()) { ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::Button((char*)"Drag and drop your scripts here", ImVec2(ImGui::GetContentRegionAvailWidth(), 60.0f)); ImGui::PopStyleColor(4); ImGui::PopStyleVar(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_SCRIPT")) { IM_ASSERT(payload->DataSize == sizeof(PrototypePluginInstance*)); PrototypePluginInstance* pluginInstance = *(PrototypePluginInstance**)payload->Data; ScriptCodeLink link = {}; pluginInstance->linkScript(&link); if (script->codeLinks.find(link.filepath) == script->codeLinks.end()) { script->codeLinks.insert({ link.filepath, link }); PrototypePluginInstance::safeCallStartProtocol(&link, o); } } ImGui::EndDragDropTarget(); } } else { static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("script content table", 2, tableFlags)) { { int i = 0; for (auto codeLinkPair : script->codeLinks) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::Text("Script %i", i); ImGui::TableSetColumnIndex(1); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::Button((char*)codeLinkPair.second.filepath.c_str(), ImVec2(ImGui::GetContentRegionAvailWidth() - 35.0f, 30.0f)); ImGui::PopStyleColor(4); ImGui::PopStyleVar(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_SCRIPT")) { IM_ASSERT(payload->DataSize == sizeof(PrototypePluginInstance*)); PrototypePluginInstance* pluginInstance = *(PrototypePluginInstance**)payload->Data; PrototypePluginInstance::safeCallEndProtocol(&codeLinkPair.second, o); pluginInstance->linkScript(&codeLinkPair.second); PrototypePluginInstance::safeCallStartProtocol(&codeLinkPair.second, o); } ImGui::EndDragDropTarget(); } ImGui::SameLine(); ImGui::PushID(++i); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_WHITE, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); if (ImGui::Button(fmt::format("X##script remove button {}", i).c_str(), ImVec2(ImGui::GetContentRegionAvailWidth(), 30.0f))) { PrototypePipelineQueue queue = {}; auto cmd = std::make_unique<PrototypePipelineCommand_shortcutEditorRemoveScriptFromObject>(); cmd->object = o; cmd->codeLink = codeLinkPair.second.filepath; queue.record(std::move(cmd)); PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } ImGui::PopStyleColor(4); ImGui::PopStyleVar(); ImGui::PopID(); } } ImGui::EndTable(); } if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_SCRIPT")) { IM_ASSERT(payload->DataSize == sizeof(PrototypePluginInstance*)); PrototypePluginInstance* pluginInstance = *(PrototypePluginInstance**)payload->Data; ScriptCodeLink link = {}; pluginInstance->linkScript(&link); if (script->codeLinks.find(link.filepath) == script->codeLinks.end()) { script->codeLinks.insert({ link.filepath, link }); PrototypePluginInstance::safeCallStartProtocol(&link, o); } } ImGui::EndDragDropTarget(); } } COMPONENT_UI_FOOTER() } static void onTransformEditDispatch(PrototypeObject* o) { COMPONENT_UI_HEADER(Transform) static glm::vec3 position, rotation, scale; Transform* tr = o->getTransformTrait(); position = tr->position(); rotation = tr->rotation(); scale = tr->scale(); bool positionChanged = false, rotationChanged = false, scaleChanged = false; static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("transform content table", 2, tableFlags)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Position"); ImGui::TableSetColumnIndex(1); PrototypeImguiVec3WidgetUntitled( 20.0f, if (ImGui::DragFloat("##position x", &position.x, 0.1f, -1000.0f, 1000.0f)) { positionChanged = true; }, if (ImGui::DragFloat("##position y", &position.y, 0.1f, -1000.0f, 1000.0f)) { positionChanged = true; }, if (ImGui::DragFloat("##position z", &position.z, 0.1f, -1000.0f, 1000.0f)) { positionChanged = true; }, 3.0f, -2.0f, "X", "Y", "Z") {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Rotation"); ImGui::TableSetColumnIndex(1); PrototypeImguiVec3WidgetUntitled( 20.0f, if (ImGui::DragFloat("##rotation x", &rotation.x, 0.1f, -360.0f, 360.0f)) { rotationChanged = true; }, if (ImGui::DragFloat("##rotation y", &rotation.y, 0.1f, -360.0f, 360.0f)) { rotationChanged = true; }, if (ImGui::DragFloat("##rotation z", &rotation.z, 0.1f, -360.0f, 360.0f)) { rotationChanged = true; }, 3.0f, -2.0f, "X", "Y", "Z") {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("scale"); ImGui::TableSetColumnIndex(1); PrototypeImguiVec3WidgetUntitled( 20.0f, if (ImGui::DragFloat("##scale x", &scale.x, 0.1f, 0.1f, 10.0f)) { if (scale.x >= 0.1f) { scaleChanged = true; } }, if (ImGui::DragFloat("##scale y", &scale.y, 0.1f, 0.1f, 10.0f)) { if (scale.y >= 0.1f) { scaleChanged = true; } }, if (ImGui::DragFloat("##scale z", &scale.z, 0.1f, 0.1f, 10.0f)) { if (scale.z >= 0.1f) { scaleChanged = true; } }, 3.0f, -2.0f, "X", "Y", "Z") {} ImGui::EndTable(); } if (positionChanged || rotationChanged) { ImGuizmo::Enable(false); glm::mat4 model; PrototypeMaths::buildModelMatrix(model, tr->position(), rotation); PrototypeMaths::buildModelMatrixWithScale(model, tr->scale()); tr->setModelScaled(&model[0][0]); tr->updateComponentsFromMatrix(); if (o->hasColliderTrait()) { tr->setNeedsPhysicsSync(true); } ImGuizmo::Enable(true); tr->positionMut().x = position.x; tr->positionMut().y = position.y; tr->positionMut().z = position.z; tr->rotationMut().x = rotation.x; tr->rotationMut().y = rotation.y; tr->rotationMut().z = rotation.z; } if (scaleChanged) { ImGuizmo::Enable(false); glm::mat4 model; PrototypeMaths::buildModelMatrix(model, position, rotation); tr->setModel(&model[0][0]); if (o->hasColliderTrait()) { PrototypeEngineInternalApplication::physics->scaleCollider(o, scale); } PrototypeMaths::buildModelMatrixWithScale(model, scale); tr->setModelScaled(&model[0][0]); tr->updateComponentsFromMatrix(); tr->scaleMut().x = scale.x; tr->scaleMut().y = scale.y; tr->scaleMut().z = scale.z; ImGuizmo::Enable(true); } COMPONENT_UI_FOOTER() } static void onVehicleChasisEditDispatch(PrototypeObject* o) { COMPONENT_UI_HEADER(VehicleChasis); VehicleChasis* vch = o->getVehicleChasisTrait(); static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("transform content table", 2, tableFlags)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Acceleration Pedal"); ImGui::TableSetColumnIndex(1); static bool accelerationPedal; accelerationPedal = vch->accelerationPedal(); if (ImGui::Checkbox("##Acceleration Pedal", &accelerationPedal)) { vch->setAccelerationPedal(accelerationPedal); } ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Brake Pedal"); ImGui::TableSetColumnIndex(1); static bool brakePedal; brakePedal = vch->brakePedal(); if (ImGui::Checkbox("##Brake Pedal", &brakePedal)) { vch->setBrakePedal(brakePedal); } ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Right Steer"); ImGui::TableSetColumnIndex(1); static bool rightSteer; rightSteer = vch->rightSteer(); if (ImGui::Checkbox("##Right Steer", &rightSteer)) { vch->setRightSteer(rightSteer); } ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Left Steer"); ImGui::TableSetColumnIndex(1); static bool leftSteer; leftSteer = vch->leftSteer(); if (ImGui::Checkbox("##Left Steer", &leftSteer)) { vch->setLeftSteer(leftSteer); } { // Front Right Wheel { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Front right wheel"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); char* name = ""; PrototypeObject* wheelFRObject = vch->wheelFRObject(); if (wheelFRObject) { PrototypeSceneNode* wheelFRNode = (PrototypeSceneNode*)wheelFRObject->parentNode(); name = (char*)wheelFRNode->name().c_str(); } ImGui::Button(name, ImVec2(ImGui::GetContentRegionAvailWidth(), 30.0f)); ImGui::PopStyleColor(4); ImGui::PopStyleVar(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_TREENODE")) { IM_ASSERT(payload->DataSize == sizeof(PrototypeSceneNode*)); PrototypeSceneNode* node = *(PrototypeSceneNode**)payload->Data; auto optObj = node->object(); if (optObj.has_value()) { auto obj = optObj.value(); vch->setWheelFRObject(obj); } } ImGui::EndDragDropTarget(); } } // Front Left Wheel { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Front left wheel"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); char* name = ""; PrototypeObject* wheelFLObject = vch->wheelFLObject(); if (wheelFLObject) { PrototypeSceneNode* wheelFLNode = (PrototypeSceneNode*)wheelFLObject->parentNode(); name = (char*)wheelFLNode->name().c_str(); } ImGui::Button(name, ImVec2(ImGui::GetContentRegionAvailWidth(), 30.0f)); ImGui::PopStyleColor(4); ImGui::PopStyleVar(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_TREENODE")) { IM_ASSERT(payload->DataSize == sizeof(PrototypeSceneNode*)); PrototypeSceneNode* node = *(PrototypeSceneNode**)payload->Data; auto optObj = node->object(); if (optObj.has_value()) { auto obj = optObj.value(); vch->setWheelFLObject(obj); } } ImGui::EndDragDropTarget(); } } // Backward Right Wheel { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Back right wheel"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); char* name = ""; PrototypeObject* wheelBRObject = vch->wheelBRObject(); if (wheelBRObject) { PrototypeSceneNode* wheelBRNode = (PrototypeSceneNode*)wheelBRObject->parentNode(); name = (char*)wheelBRNode->name().c_str(); } ImGui::Button(name, ImVec2(ImGui::GetContentRegionAvailWidth(), 30.0f)); ImGui::PopStyleColor(4); ImGui::PopStyleVar(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_TREENODE")) { IM_ASSERT(payload->DataSize == sizeof(PrototypeSceneNode*)); PrototypeSceneNode* node = *(PrototypeSceneNode**)payload->Data; auto optObj = node->object(); if (optObj.has_value()) { auto obj = optObj.value(); vch->setWheelBRObject(obj); } } ImGui::EndDragDropTarget(); } } // Backward Left Wheel { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Back left wheel"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); char* name = ""; PrototypeObject* wheelBLObject = vch->wheelBLObject(); if (wheelBLObject) { PrototypeSceneNode* wheelBLNode = (PrototypeSceneNode*)wheelBLObject->parentNode(); name = (char*)wheelBLNode->name().c_str(); } ImGui::Button(name, ImVec2(ImGui::GetContentRegionAvailWidth(), 30.0f)); ImGui::PopStyleColor(4); ImGui::PopStyleVar(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_TREENODE")) { IM_ASSERT(payload->DataSize == sizeof(PrototypeSceneNode*)); PrototypeSceneNode* node = *(PrototypeSceneNode**)payload->Data; auto optObj = node->object(); if (optObj.has_value()) { auto obj = optObj.value(); vch->setWheelBLObject(obj); } } ImGui::EndDragDropTarget(); } } } ImGui::EndTable(); } COMPONENT_UI_FOOTER(); } PrototypeOpenglUI::PrototypeOpenglUI() : _clipboard({}) , _playBtnImg(0) , _reloadBtnImg(0) , _pauseBtnImg(0) , _importBtnImg(0) , _exportBtnImg(0) , _isBuffersChanged(false) , _freezeResizingViews(false) , _recordMask(PrototypeUiViewMaskAll) , _openViewsMask(PrototypeUiViewMaskAll) , _sceneView({}) {} bool PrototypeOpenglUI::init() { _recordedInstructions = PrototypeOpenglUIInstructions(); _assetConfigSelection = PrototypeConfigurationSelection(); ImGui::CreateContext(); ImPlot::CreateContext(); ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; (void)io; io.IniFilename = nullptr; // default font { _defaultFont = io.Fonts->AddFontFromFileTTF(PROTOTYPE_FONT_PATH("RobotoMono-Bold.ttf"), 18); } // awesome font { static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true; icons_config.GlyphOffset.y = 0.0f; _awesomeFont = io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_FAS, 10.0f, &icons_config, icons_ranges); } // awesome font traits { static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; ImFontConfig icons_config; icons_config.MergeMode = false; icons_config.PixelSnapH = true; icons_config.GlyphOffset.y = 2.0f; _awesomeFontTrait = io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_FAS, 13.0f, &icons_config, icons_ranges); } // awesome font title { static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; ImFontConfig icons_config; icons_config.MergeMode = false; icons_config.PixelSnapH = true; icons_config.GlyphOffset.y = 0.0f; _awesomeFontTitle = io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_FAS, 18.0f, &icons_config, icons_ranges); } // awesome font button icons { static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; ImFontConfig icons_config; icons_config.MergeMode = false; icons_config.PixelSnapH = true; icons_config.GlyphOffset.y = -1.0f; _awesomeFontBtnIcons = io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_FAS, 20.0f, &icons_config, icons_ranges); } ImGui_ImplGlfw_InitForOpenGL((GLFWwindow*)PrototypeEngineInternalApplication::window->handle(), true); ImGui_ImplOpenGL3_Init(GLSL_VERSION.c_str()); ImGui::StyleColorsDark(); ImGuiStyle& style = ImGui::GetStyle(); style.AntiAliasedLines = false; style.AntiAliasedLinesUseTex = false; style.AntiAliasedFill = false; style.CurveTessellationTol = 0.1f; style.CircleSegmentMaxError = 100.0f; style.ChildRounding = 0.f; style.GrabRounding = 0.f; style.WindowRounding = 0.f; style.ScrollbarRounding = 0.f; style.ScrollbarSize = 10.0f; style.FrameRounding = 0.f; style.TabRounding = 0.f; style.TabBorderSize = 0.0f; style.WindowTitleAlign = ImVec2(0.01f, 0.5f); // style.Colors[ImGuiCol_Text] = ImVec4(PROTOTYPE_WHITE, 1.00f); // style.Colors[ImGuiCol_TextDisabled] = ImVec4(PROTOTYPE_LIGHTESTGRAY, 1.00f); // style.Colors[ImGuiCol_WindowBg] = ImVec4(PROTOTYPE_DARKESTGRAY, 1.0f); // style.Colors[ImGuiCol_ChildBg] = ImVec4(PROTOTYPE_DARKESTGRAY, 1.0f); // style.Colors[ImGuiCol_PopupBg] = ImVec4(PROTOTYPE_DARKESTGRAY, 1.00f); // // style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.76f, 0.26f, 0.26f, 1.00f); // // style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.76f, 0.26f, 1.00f); // // style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.26f, 0.76f, 1.00f); // style.Colors[ImGuiCol_Border] = ImVec4(PROTOTYPE_DARKGRAY, 1.00f); // style.Colors[ImGuiCol_BorderShadow] = ImVec4(PROTOTYPE_DARKGRAY, 1.00f); // style.Colors[ImGuiCol_FrameBg] = ImVec4(PROTOTYPE_DARKERGRAY, 1.00f); // style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(PROTOTYPE_DARKERGRAY, 1.00f); // style.Colors[ImGuiCol_FrameBgActive] = ImVec4(PROTOTYPE_DARKERGRAY, 1.00f); // style.Colors[ImGuiCol_TitleBg] = ImVec4(PROTOTYPE_DARKGRAY, 1.00f); // style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(PROTOTYPE_DARKGRAY, 1.00f); // style.Colors[ImGuiCol_TitleBgActive] = ImVec4(PROTOTYPE_DARKGRAY, 1.00f); // style.Colors[ImGuiCol_MenuBarBg] = ImVec4(PROTOTYPE_DARKGRAY, 1.00f); // style.Colors[ImGuiCol_Tab] = ImVec4(PROTOTYPE_DARKGRAY, 1.00f); // style.Colors[ImGuiCol_TabUnfocused] = ImVec4(PROTOTYPE_DARKGRAY, 1.00f); // style.Colors[ImGuiCol_TabHovered] = ImVec4(PROTOTYPE_DARKERGRAY, 1.00f); // style.Colors[ImGuiCol_TabActive] = ImVec4(PROTOTYPE_DARKESTGRAY, 1.00f); // style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(PROTOTYPE_DARKESTGRAY, 1.00f); // // style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.21f, 0.21f, 0.21f, 1.00f); // // style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.36f, 0.36f, 0.36f, 1.00f); // // style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.36f, 0.36f, 0.36f, 1.00f); // // style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.36f, 0.36f, 0.36f, 1.00f); // // style.Colors[ImGuiCol_CheckMark] = ImVec4(0.78f, 0.78f, 0.78f, 1.00f); // style.Colors[ImGuiCol_SliderGrab] = ImVec4(PROTOTYPE_DARKGRAY, 1.00f); // style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(PROTOTYPE_GRAY, 1.00f); // style.Colors[ImGuiCol_Button] = ImVec4(0.193f, 0.193f, 0.193f, 1.000f); // style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.314f, 0.315f, 0.317f, 1.000f); // style.Colors[ImGuiCol_ButtonActive] = ImVec4(1.000f, 1.000f, 1.000f, 1.000f); // style.Colors[ImGuiCol_Header] = ImVec4(PROTOTYPE_DARKGRAY, 1.00f); // style.Colors[ImGuiCol_HeaderHovered] = ImVec4(PROTOTYPE_GRAY, 1.00f); // style.Colors[ImGuiCol_HeaderActive] = ImVec4(PROTOTYPE_GRAY, 1.00f); // style.Colors[ImGuiCol_PlotLines] = ImVec4(PROTOTYPE_GRAY, 1.00f); // style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(PROTOTYPE_LIGHTESTGRAY, 1.00f); // style.Colors[ImGuiCol_PlotHistogram] = ImVec4(PROTOTYPE_GRAY, 1.00f); // style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(PROTOTYPE_LIGHTESTGRAY, 1.00f); // // style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.32f, 0.52f, 0.65f, 1.00f); // // style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.50f); style.Colors[ImGuiCol_Border] = ImVec4(0.08f, 0.10f, 0.12f, 1.00f); style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); style.Colors[ImGuiCol_Button] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f); style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f); style.Colors[ImGuiCol_ButtonHovered] = ImVec4(1.0f, 0.232f, 0.0f, 1.00f); style.Colors[ImGuiCol_ChildBg] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f); style.Colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f); style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.09f, 0.12f, 0.14f, 1.00f); style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.12f, 0.20f, 0.28f, 1.00f); style.Colors[ImGuiCol_Header] = ImVec4(1.0f, 0.231f, 0.0f, 0.784f); style.Colors[ImGuiCol_HeaderActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.70f); style.Colors[ImGuiCol_HeaderHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.38f); style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.15f, 0.18f, 0.22f, 1.00f); style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); style.Colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); style.Colors[ImGuiCol_PopupBg] = ImVec4(0.05f, 0.09f, 0.11f, 1.00f); style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f); style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.39f); style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f); style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.09f, 0.21f, 0.31f, 1.00f); style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.18f, 0.22f, 0.25f, 1.00f); style.Colors[ImGuiCol_Tab] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); style.Colors[ImGuiCol_TabHovered] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f); style.Colors[ImGuiCol_TabActive] = ImVec4(0.33f, 0.33f, 0.33f, 1.00f); style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.33f, 0.33f, 0.33f, 1.00f); style.Colors[ImGuiCol_Text] = ImVec4(0.95f, 0.96f, 0.98f, 1.00f); style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.36f, 0.42f, 0.47f, 1.00f); style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); style.Colors[ImGuiCol_TitleBg] = ImVec4(0.09f, 0.12f, 0.14f, 0.65f); style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.08f, 0.10f, 0.12f, 1.00f); style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); style.Colors[ImGuiCol_WindowBg] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f); style.Colors[ImGuiCol_CheckMark] = ImVec4(0.28f, 0.56f, 1.00f, 1.00f); style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.28f, 0.56f, 1.00f, 1.00f); style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.37f, 0.61f, 1.00f, 1.00f); style.Colors[ImGuiCol_Separator] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f); style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f); style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f); style.Colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); style.Colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f); style.Colors[ImGuiCol_DockingPreview] = ImVec4(0.85f, 0.85f, 0.85f, 0.28f); if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) style.Colors[ImGuiCol_WindowBg].w = 1.0f; // register traits onEdits Camera::setOnEditDispatchHandler(onCameraEditDispatch); Collider::setOnEditDispatchHandler(onColliderEditDispatch); MeshRenderer::setOnEditDispatchHandler(onMeshRendererEditDispatch); Rigidbody::setOnEditDispatchHandler(onRigidbodyEditDispatch); Script::setOnEditDispatchHandler(onScriptEditDispatch); Transform::setOnEditDispatchHandler(onTransformEditDispatch); VehicleChasis::setOnEditDispatchHandler(onVehicleChasisEditDispatch); { PglTexture* playBtnTexture; PrototypeEngineInternalApplication::renderer->fetchTexture("icons/play.png", (void**)&playBtnTexture); if (playBtnTexture) { _playBtnImg = playBtnTexture->id; } else { _playBtnImg = 0; } } { PglTexture* pauseBtnTexture; PrototypeEngineInternalApplication::renderer->fetchTexture("icons/pause.png", (void**)&pauseBtnTexture); if (pauseBtnTexture) { _pauseBtnImg = pauseBtnTexture->id; } else { _pauseBtnImg = 0; } } { PglTexture* reloadBtnTexture; PrototypeEngineInternalApplication::renderer->fetchTexture("icons/reload.png", (void**)&reloadBtnTexture); if (reloadBtnTexture) { _reloadBtnImg = reloadBtnTexture->id; } else { _reloadBtnImg = 0; } } { PglTexture* importBtnTexture; PrototypeEngineInternalApplication::renderer->fetchTexture("icons/import.png", (void**)&importBtnTexture); if (importBtnTexture) { _importBtnImg = importBtnTexture->id; } else { _importBtnImg = 0; } } { PglTexture* exportBtnTexture; PrototypeEngineInternalApplication::renderer->fetchTexture("icons/export.png", (void**)&exportBtnTexture); if (exportBtnTexture) { _exportBtnImg = exportBtnTexture->id; } else { _exportBtnImg = 0; } } _sceneView.onInit(); return true; } void PrototypeOpenglUI::deInit() { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImPlot::DestroyContext(); ImGui::DestroyContext(); } void PrototypeOpenglUI::scheduleRecordPass(PrototypeUiViewMaskType mask) { _recordMask |= mask; } void PrototypeOpenglUI::beginRecordPass() { if (_recordMask == 0) return; // filter nodes /*{ _recordedInstructions.sceneNodes.clear(); const auto& layers = PrototypeEngineInternalApplication::scene->layers(); int layersChildrenCount = layers.size(); std::unordered_map<u32, PrototypeSceneNode*> nextGeneration; for (const auto& pair : layers) { size_t validChildrenCount = 0; for (auto pair : pair.second->nodes()) { if (pair.second->name().find(_recordedInstructions.sceneNodesSearchBuffer) != std::string::npos) { nextGeneration[pair.first] = pair.second; ++validChildrenCount; } } PrototypeOpenglUIInstructions::InternalSceneNode node = {}; node.layer = pair.second; node.isLayer = true; node.ChildIdx = layersChildrenCount; node.ChildCount = validChildrenCount; layersChildrenCount += node.ChildCount; _recordedInstructions.sceneNodes.push_back(std::move(node)); } while (!nextGeneration.empty()) { std::unordered_map<u32, PrototypeSceneNode*> nextChildren; for (const auto& pair : nextGeneration) { size_t validChildrenCount = 0; for (auto pair : pair.second->nodes()) { if (pair.second->name().find(_recordedInstructions.sceneNodesSearchBuffer) != std::string::npos) { nextChildren[pair.first] = pair.second; ++validChildrenCount; } } PrototypeOpenglUIInstructions::InternalSceneNode node = {}; node.node = pair.second; node.isLayer = false; node.ChildIdx = layersChildrenCount; node.ChildCount = validChildrenCount; layersChildrenCount += node.ChildCount; _recordedInstructions.sceneNodes.push_back(std::move(node)); } nextGeneration.clear(); nextGeneration = nextChildren; } }*/ // Filter nodes dfs if ((_recordMask & PrototypeUiViewMaskHierarchy) == PrototypeUiViewMaskHierarchy) { _recordMask &= ~PrototypeUiViewMaskHierarchy; _recordedInstructions.sceneNodes.clear(); const auto& layers = PrototypeEngineInternalApplication::scene->layers(); std::function<bool(PrototypeSceneNode*)> lambda = [&](PrototypeSceneNode* node) -> bool { node->unsetMatched(); node->unsetPartialMatched(); for (const auto& pair : node->nodes()) { if (lambda(pair.second)) { node->setPartialMatched(); } } if (node->name().find(_recordedInstructions.sceneNodesSearchBuffer) != std::string::npos) { node->setMatched(); } return node->isMatching() | node->isPartialMatching(); }; for (const auto& layerPair : layers) { layerPair.second->unsetMatched(); layerPair.second->unsetPartialMatched(); for (const auto& nodePair : layerPair.second->nodes()) { if (lambda(nodePair.second)) { layerPair.second->setPartialMatched(); } } if (layerPair.second->name().find(_recordedInstructions.sceneNodesSearchBuffer) != std::string::npos) { layerPair.second->setMatched(); } } } // Filter meshes if ((_recordMask & PrototypeUiViewMaskMeshes) == PrototypeUiViewMaskMeshes) { _recordMask &= ~PrototypeUiViewMaskMeshes; _recordedInstructions.meshes.clear(); for (const auto& pair : PrototypeEngineInternalApplication::database->meshBuffers) { size_t matchIndex = pair.first.find(_recordedInstructions.meshesSearchBuff); if (matchIndex != std::string::npos) { PglGeometry* mesh; PrototypeEngineInternalApplication::renderer->fetchMesh(pair.first, (void**)&mesh); if (mesh) { _recordedInstructions.meshes.push_back(mesh); } } } } // Filter colliders if ((_recordMask & PrototypeUiViewMaskColliders) == PrototypeUiViewMaskColliders) { _recordMask &= ~PrototypeUiViewMaskColliders; _recordedInstructions.colliders.clear(); const static std::vector<std::string> defaultColliders = { "PLANE", "CUBE", "SPHERE" }; for (const std::string& defCol : defaultColliders) { size_t matchIndex = defCol.find(_recordedInstructions.collidersSearchBuff); if (matchIndex != std::string::npos) { _recordedInstructions.colliders.push_back({ "", defCol }); } } for (const auto& pair : PrototypeEngineInternalApplication::database->meshBuffers) { size_t matchIndex = pair.first.find(_recordedInstructions.collidersSearchBuff); if (matchIndex != std::string::npos) { // CONVEX // _recordedInstructions.colliders.push_back({ "(CONVEX) ", pair.first }); // TRIMESH // _recordedInstructions.colliders.push_back({ "(TRIMESH) ", pair.first }); } } } // Filter shaders if ((_recordMask & PrototypeUiViewMaskShaders) == PrototypeUiViewMaskShaders) { _recordMask &= ~PrototypeUiViewMaskShaders; _recordedInstructions.shaders.clear(); for (const auto& pair : PrototypeEngineInternalApplication::database->shaderBuffers) { size_t matchIndex = pair.first.find(_recordedInstructions.shadersSearchBuff); if (matchIndex != std::string::npos) { PglShader* shader; PrototypeEngineInternalApplication::renderer->fetchShader(pair.first, (void**)&shader); if (shader) { _recordedInstructions.shaders.push_back(shader); } } } } // Filter textures if ((_recordMask & PrototypeUiViewMaskTextures) == PrototypeUiViewMaskTextures) { _recordMask &= ~PrototypeUiViewMaskTextures; _recordedInstructions.textures.clear(); for (const auto& pair : PrototypeEngineInternalApplication::database->textureBuffers) { size_t matchIndex = pair.first.find(_recordedInstructions.texturesSearchBuff); if (matchIndex != std::string::npos) { PglTexture* texture; PrototypeEngineInternalApplication::renderer->fetchTexture(pair.first, (void**)&texture); if (texture) { _recordedInstructions.textures.push_back(texture); } } } } // Filter materials if ((_recordMask & PrototypeUiViewMaskMaterials) == PrototypeUiViewMaskMaterials) { _recordMask &= ~PrototypeUiViewMaskMaterials; _recordedInstructions.materials.clear(); for (const auto& pair : PrototypeEngineInternalApplication::database->materials) { size_t matchIndex = pair.first.find(_recordedInstructions.materialsSearchBuff); if (matchIndex != std::string::npos) { PglMaterial* material; PrototypeEngineInternalApplication::renderer->fetchMaterial(pair.first, (void**)&material); if (material) { _recordedInstructions.materials.push_back(material); } } } } _recordMask = 0; PrototypeEngineInternalApplication::window->resetDeltaTime(); } void PrototypeOpenglUI::endRecordPass() {} void PrototypeOpenglUI::beginFrame(bool changed) { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); ImGuizmo::BeginFrame(); } PrototypeUIState_ PrototypeOpenglUI::drawFrame(u32 fbid, i32 width, i32 height) { enum class DockingUILayouts { LayoutA, LayoutB, Count }; static DockingUILayouts layout = DockingUILayouts::LayoutA; const char* layoutsNames[static_cast<int>(DockingUILayouts::Count)] = { PROTOTYPE_STRINGIFY(LayoutA), PROTOTYPE_STRINGIFY(LayoutB) }; static int layoutComboIndex = static_cast<int>(DockingUILayouts::LayoutA); PrototypeUIState_ state = PrototypeUIState_None; ImGuiWindowFlags mainWindowFlags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus; ImGuiViewport* viewport = ImGui::GetMainViewport(); ImGui::SetNextWindowPos(viewport->Pos); ImGui::SetNextWindowSize(viewport->Size); ImGui::SetNextWindowViewport(viewport->ID); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); { if (ImGui::Begin("Main DockSpace", (bool*)0, mainWindowFlags)) { { if (ImGui::BeginChild("Toolbar", ImVec2(ImGui::GetContentRegionAvailWidth(), 35.0f), false, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar)) { ImGui::Dummy(ImVec2(0.0f, 2.0f)); float barWidth = ImGui::GetContentRegionAvailWidth(); f32 leftPosX = ImGui::GetCursorPosX() + 5.0f; f32 rightPosX = barWidth - 5.0f; f32 midPosX = (rightPosX - leftPosX) / 2.0f; // left side { ImGui::SetCursorPosX(leftPosX); ImGui::SetNextItemWidth(135.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(50.0f, 5.0f)); { if (ImGui::Combo("##DockingLayouts", &layoutComboIndex, layoutsNames, static_cast<int>(DockingUILayouts::Count))) {} } ImGui::PopStyleVar(); leftPosX += 135.0f; } // mid side { midPosX -= 25.0f; ImGui::SameLine(); ImGui::SetCursorPosX(midPosX); static bool isPlaying = true; isPlaying = PrototypeEngineInternalApplication::physics->isPlaying(); if (ImGui::Button(isPlaying ? ICON_FA_PAUSE : ICON_FA_PLAY, ImVec2(25.0f, 25.0f))) { if (isPlaying) { PrototypeEngineInternalApplication::physics->pause(); } else { PrototypeEngineInternalApplication::physics->play(); } } midPosX += 25.0f; ImGui::SameLine(); ImGui::SetCursorPosX(midPosX); if (!_isBuffersChanged) { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); ImGui::Button(ICON_FA_BOLT, ImVec2(25.0f, 25.0f)); ImGui::PopStyleVar(); ImGui::PopItemFlag(); } else { if (ImGui::Button(ICON_FA_BOLT, ImVec2(25.0f, 25.0f))) { _isBuffersChanged = false; for (const auto& pair : PrototypeEngineInternalApplication::database->meshBuffers) { pair.second->commitChange(); } for (const auto& pair : PrototypeEngineInternalApplication::database->shaderBuffers) { pair.second->commitChange(); } for (const auto& pair : PrototypeEngineInternalApplication::database->textureBuffers) { pair.second->commitChange(); } for (const auto& pair : PrototypeEngineInternalApplication::database->textureBuffers) { pair.second->commitChange(); } PrototypePipelineQueue queue = {}; for (const auto& pair : PrototypeEngineInternalApplication::database->pluginInstances) { auto cmd = std::make_unique<PrototypePipelineCommand_shortcutEditorCommitReloadPlugin>(); cmd->pluginInstance = pair.second; queue.record(std::move(cmd)); } PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } if (ImGui::IsItemHovered()) { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10.0f, 10.0f)); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_LIGHTERGRAY, 1.0f)); ImGui::SetTooltip("Reload"); ImGui::PopStyleColor(); ImGui::PopStyleVar(); } } midPosX += 25.0f; } // right side {} } ImGui::EndChild(); } if (ImGui::DockBuilderGetNode(ImGui::GetID("TheDockspace")) == nullptr || _freezeResizingViews || layoutComboIndex != static_cast<int>(layout)) { layout = static_cast<DockingUILayouts>(layoutComboIndex); ImGuiID dockspaceId = ImGui::GetID("TheDockspace"); ImGui::DockBuilderRemoveNode(dockspaceId); // Clear out existing layout ImGui::DockBuilderAddNode(dockspaceId, ImGuiDockNodeFlags_DockSpace); // Add empty node ImGuiID dock_main_id = dockspaceId; // This variable will track the document node, however we are not using it // here as we aren't docking anything into it. // Default Layout // ------------------------------------------------------ ------------------------------------------------------ // | | | | | | | | // | | | | | | | | // | | | | | | | | // | E | G | | | | G | | // | | | | | | | | // | | | A | | A | | H | // | | | | | | | | // |----------------------------------------| | | |-------------------------------------------| // | C | | | | | | // | | | | | E | F | // ------------------------------------------------------ ------------------------------------------------------ { switch (layout) { case DockingUILayouts::LayoutA: { ImGuiID dock_id_a, dock_id_b, dock_id_c, dock_id_d, dock_id_e, dock_id_f, dock_id_g; ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Right, 0.25f, &dock_id_a, &dock_id_b); ImGui::DockBuilderSplitNode(dock_id_b, ImGuiDir_Down, 0.25f, &dock_id_c, &dock_id_d); ImGui::DockBuilderSplitNode(dock_id_d, ImGuiDir_Left, 0.25f, &dock_id_e, &dock_id_f); ImGui::DockBuilderSplitNode(dock_id_f, ImGuiDir_Right, 0.25f, nullptr, &dock_id_g); { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_main_id); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_a); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_b); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_c); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_d); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_e); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_f); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_g); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } ImGui::DockBuilderDockWindow("3D View", dock_id_g); ImGui::DockBuilderDockWindow("3D Paint", dock_id_g); ImGui::DockBuilderDockWindow("Game", dock_id_g); ImGui::DockBuilderDockWindow("Texture Editor", dock_id_g); ImGui::DockBuilderDockWindow("Text Editor", dock_id_g); ImGui::DockBuilderDockWindow("Input Settings", dock_id_g); ImGui::DockBuilderDockWindow("Hierarchy", dock_id_e); ImGui::DockBuilderDockWindow("Traits", dock_id_a); ImGui::DockBuilderDockWindow("Properties", dock_id_a); ImGui::DockBuilderDockWindow("Settings", dock_id_a); #if defined(PROTOTYPE_ENABLE_PROFILER) ImGui::DockBuilderDockWindow("Profiler", dock_id_c); #endif ImGui::DockBuilderDockWindow("Colliders", dock_id_c); ImGui::DockBuilderDockWindow("Materials", dock_id_c); ImGui::DockBuilderDockWindow("Textures", dock_id_c); ImGui::DockBuilderDockWindow("Shaders", dock_id_c); ImGui::DockBuilderDockWindow("Meshes", dock_id_c); ImGui::DockBuilderDockWindow("Scenes", dock_id_c); ImGui::DockBuilderDockWindow("Framebuffers", dock_id_c); ImGui::DockBuilderDockWindow("Console", dock_id_c); ImGui::DockBuilderDockWindow("Scripts", dock_id_c); ImGui::DockBuilderDockWindow("Blueprints", dock_id_c); } break; case DockingUILayouts::LayoutB: { ImGuiID dock_id_a, dock_id_b, dock_id_c, dock_id_d, dock_id_e, dock_id_f, dock_id_g, dock_id_h, dock_id_i; ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Left, 0.15f, &dock_id_a, &dock_id_b); ImGui::DockBuilderSplitNode(dock_id_b, ImGuiDir_Down, 0.25f, &dock_id_c, &dock_id_d); ImGui::DockBuilderSplitNode(dock_id_c, ImGuiDir_Left, 0.25f, &dock_id_e, &dock_id_f); ImGui::DockBuilderSplitNode(dock_id_d, ImGuiDir_Right, 0.25f, &dock_id_h, &dock_id_g); ImGui::DockBuilderSplitNode(dock_id_g, ImGuiDir_Right, 0.25f, nullptr, &dock_id_i); { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_main_id); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_a); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_b); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_c); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_d); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_e); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_f); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_g); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_h); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } { ImGuiDockNode* node = ImGui::DockBuilderGetNode(dock_id_i); node->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } ImGui::DockBuilderDockWindow("3D View", dock_id_i); ImGui::DockBuilderDockWindow("3D Paint", dock_id_i); ImGui::DockBuilderDockWindow("Game", dock_id_i); ImGui::DockBuilderDockWindow("Texture Editor", dock_id_i); ImGui::DockBuilderDockWindow("Text Editor", dock_id_i); ImGui::DockBuilderDockWindow("Input Settings", dock_id_i); ImGui::DockBuilderDockWindow("Hierarchy", dock_id_a); ImGui::DockBuilderDockWindow("Traits", dock_id_h); ImGui::DockBuilderDockWindow("Properties", dock_id_h); ImGui::DockBuilderDockWindow("Settings", dock_id_h); #if defined(PROTOTYPE_ENABLE_PROFILER) ImGui::DockBuilderDockWindow("Profiler", dock_id_e); #endif ImGui::DockBuilderDockWindow("Colliders", dock_id_f); ImGui::DockBuilderDockWindow("Materials", dock_id_f); ImGui::DockBuilderDockWindow("Textures", dock_id_f); ImGui::DockBuilderDockWindow("Shaders", dock_id_f); ImGui::DockBuilderDockWindow("Meshes", dock_id_f); ImGui::DockBuilderDockWindow("Scenes", dock_id_f); ImGui::DockBuilderDockWindow("Framebuffers", dock_id_f); ImGui::DockBuilderDockWindow("Console", dock_id_f); ImGui::DockBuilderDockWindow("Scripts", dock_id_f); ImGui::DockBuilderDockWindow("Blueprints", dock_id_f); } break; } } ImGui::DockBuilderFinish(dockspaceId); _freezeResizingViews = false; TEXT_BASE_WIDTH = ImGui::CalcTextSize("A").x; TEXT_BASE_HEIGHT = ImGui::GetTextLineHeightWithSpacing(); } ImGui::PushStyleColor(ImGuiCol_DockingEmptyBg, ImVec4(PROTOTYPE_DARKERGRAY, 1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); ImGuiID dockspaceId = ImGui::GetID("TheDockspace"); ImGui::DockSpace(dockspaceId, ImVec2(0.0f, 0.0f), 0); ImGui::PopStyleVar(); ImGui::PopStyleColor(); } ImGui::End(); } ImGui::PopStyleVar(4); static ImVec2 WindowPadding1 = ImVec2(1.0f, 1.0f); static ImVec2 WindowPadding2 = ImVec2(2.0f, 2.0f); static ImVec2 WindowPadding3 = ImVec2(3.0f, 3.0f); static ImVec2 WindowPadding4 = ImVec2(4.0f, 4.0f); static ImVec2 WindowPadding5 = ImVec2(5.0f, 5.0f); ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoCollapse; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding1); { if (ImGui::Begin("Hierarchy", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskHierarchy; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } static char* hierarchySearchBuff = &_recordedInstructions.sceneNodesSearchBuffer[0]; // table { static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("##scene table", 1, flags)) { // The first column will use the default _WidthStretch when ScrollX is Off and _WidthFixed when ScrollX is // On char buf[256]; snprintf(buf, sizeof(buf), " %s", PrototypeEngineInternalApplication::scene->name().c_str()); ImGui::TableSetupColumn(buf, 0); ImGui::TableHeadersRow(); ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::InputTextWithHint("##hierarchy search input text", ICON_FA_SEARCH " Search for objects ...", hierarchySearchBuff, sizeof(_recordedInstructions.sceneNodesSearchBuffer))) { scheduleRecordPass(PrototypeUiViewMaskHierarchy); } /*struct MySceneTreeNode { static void DisplayNode(const PrototypeOpenglUIInstructions::InternalSceneNode* node, const std::vector<PrototypeOpenglUIInstructions::InternalSceneNode>& all_nodes, PrototypeUIState_& state, ImGuiListClipper& clipper, int& row_n, bool& clipperHasSpace) { const bool is_folder = (node->ChildCount > 0); ImGui::TableNextRow(); ImGui::TableNextColumn(); if (is_folder) { static ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_NoAutoOpenOnLog | ImGuiTreeNodeFlags_OpenOnDoubleClick; bool open; if (!node->isLayer) { if (node->node->isSelected()) { ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(PROTOTYPE_GREEN, 1.0f)); } else { ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(PROTOTYPE_GRAY, 1.0f)); } open = ImGui::TreeNodeEx(node->node->name().c_str(), base_flags, "%s [%i/%zu]", node->node->name().c_str(), node->ChildCount, node->node->nodes().size()); ImGui::PopStyleColor(); } else { open = ImGui::TreeNodeEx(node->layer->name().c_str(), base_flags, "%s [%i/%zu]", node->layer->name().c_str(), node->ChildCount, node->layer->nodes().size()); } if (open) { for (int child_n = 0; child_n < node->ChildCount; child_n++) { DisplayNode( &all_nodes[node->ChildIdx + child_n], all_nodes, state, clipper, ++row_n, clipperHasSpace); } ImGui::TreePop(); } } else { ImGuiTreeNodeFlags nodeTreeNodeFlags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_NoAutoOpenOnLog | ImGuiTreeNodeFlags_OpenOnDoubleClick; if (!node->isLayer) { if (node->node->isSelected()) { ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(PROTOTYPE_GREEN, 1.0f)); } else { ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(PROTOTYPE_GRAY, 1.0f)); } bool open = ImGui::TreeNodeEx( node->node->name().c_str(), nodeTreeNodeFlags, "%s", node->node->name().c_str()); ImGui::PopStyleColor(); if (ImGui::IsMouseReleased(ImGuiMouseButton_Left) && ImGui::IsItemHovered(ImGuiHoveredFlags_None)) { ImVec2 dragDelta = ImGui::GetMouseDragDelta(); if (dragDelta.x == 0.0f && dragDelta.y == 0.0f) { PrototypeEngineInternalApplication::scene->clearSelectedNodes(); node->node->select(); } } if (open) { ImGui::TreePop(); } } else { if (ImGui::TreeNodeEx( node->layer->name().c_str(), nodeTreeNodeFlags, "%s", node->layer->name().c_str())) { ImGui::TreePop(); } } } } }; if (!_recordedInstructions.sceneNodes.empty()) { ImGuiListClipper clipper; clipper.Begin(_recordedInstructions.sceneNodes.size()); bool clipperHasSpace = (clipper.Step()); int row_n = clipper.DisplayStart; ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(PROTOTYPE_LIGHTGRAY, 1.0f)); MySceneTreeNode::DisplayNode(&_recordedInstructions.sceneNodes[0], _recordedInstructions.sceneNodes, state, clipper, row_n, clipperHasSpace); ImGui::PopStyleColor(); }*/ // The first column will use the default _WidthStretch when ScrollX is Off and _WidthFixed when ScrollX is // On // Simple storage to output a dummy file-system. struct MyTreeNode { static void DisplayNodeDetails(PrototypeSceneNode* node, PrototypeUIState_& state) { auto optObj = node->object(); PrototypeObject* object = optObj.value(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10.0f, 10.0f)); if (ImGui::BeginPopupContextItem(node->name().c_str())) { if (ImGui::Selectable("Add child node")) { PrototypePipelineQueue queue = {}; auto cmd = std::make_unique<PrototypePipelineCommand_shortcutEditorAddSceneNodeToNode>(); cmd->parentNode = node; cmd->position = glm::vec3(0.0f, 2.0f, 0.0f); cmd->rotation = glm::vec3(0.0f, 0.0f, 0.0f); cmd->dir = glm::vec3(0.0f, 0.0f, 0.0f); queue.record(std::move(cmd)); PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } if (ImGui::Selectable("Delete")) { PrototypePipelineQueue queue = {}; auto cmd = std::make_unique<PrototypePipelineCommand_shortcutEditorRemoveSceneNode>(); cmd->node = node; queue.record(std::move(cmd)); PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } ImGui::Separator(); for (MASK_TYPE itrait = 0; itrait < PrototypeTraitTypeCount; ++itrait) { if (ImGui::Selectable(((object->has(1ULL << itrait) ? ICON_FA_CHECK " " : " ") + PrototypeTraitTypeAbsoluteStringArray[itrait] + " trait") .c_str())) { if (object->has(1ULL << itrait)) { PrototypePipelineQueue queue = {}; auto cmd = std::make_unique< PrototypePipelineCommand_shortcutEditorSelectedSceneNodeRemoveTraits>(); cmd->object = object; cmd->traitMask = (1ULL << itrait); queue.record(std::move(cmd)); PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } else { PrototypePipelineQueue queue = {}; auto cmd = std::make_unique< PrototypePipelineCommand_shortcutEditorSelectedSceneNodeAddTraits>(); cmd->object = object; cmd->traitMask = (1ULL << itrait); queue.record(std::move(cmd)); PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } } } ImGui::EndPopup(); } ImGui::PopStyleVar(); // 0 left btn // 1 right btn // 2 middle btn if (ImGui::IsMouseReleased(0) && ImGui::IsItemHovered(ImGuiHoveredFlags_None)) { ImVec2 dragDelta = ImGui::GetMouseDragDelta(); if (dragDelta.x == 0.0f && dragDelta.y == 0.0f) { PrototypeEngineInternalApplication::scene->clearSelectedNodes(); node->select(); } } if (ImGui::BeginDragDropSource()) { ImGui::SetDragDropPayload("_TREENODE", &node, sizeof(PrototypeSceneNode*)); ImGui::Text("%s", node->name().c_str()); ImGui::EndDragDropSource(); } if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_TREENODE")) { IM_ASSERT(payload->DataSize == sizeof(PrototypeSceneNode*)); PrototypeSceneNode* payloadNode = *(PrototypeSceneNode**)payload->Data; PrototypeSceneNode* oldParentNode = payloadNode->parentNode(); if (oldParentNode) { oldParentNode->moveNode(payloadNode, node); state |= PrototypeUIState_HierarchyChanged; } else { PrototypeSceneLayer* oldParentLayer = payloadNode->parentLayer(); if (oldParentLayer) { oldParentLayer->moveNode(payloadNode, node); state |= PrototypeUIState_HierarchyChanged; } } } ImGui::EndDragDropTarget(); } } static void DisplayNode(PrototypeSceneNode* node, PrototypeUIState_& state) { ImGuiTreeNodeFlags nodeTreeNodeFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_ClipLabelForTrailingButton | ImGuiTreeNodeFlags_NavLeftJumpsBackHere | ImGuiTreeNodeFlags_NoAutoOpenOnLog | ImGuiTreeNodeFlags_OpenOnDoubleClick; if (node->nodes().empty()) { nodeTreeNodeFlags |= ImGuiTreeNodeFlags_Leaf; } if (node->isSelected()) { nodeTreeNodeFlags |= ImGuiTreeNodeFlags_Selected; } bool open = false; if (node->isMatching()) { ImGui::TableNextRow(); ImGui::TableNextColumn(); open = ImGui::TreeNodeEx(node->name().c_str(), nodeTreeNodeFlags, "%s", node->name().c_str()); DisplayNodeDetails(node, state); } else if (node->isPartialMatching()) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(PROTOTYPE_GRAY, 1.0f)); open = ImGui::TreeNodeEx(node->name().c_str(), nodeTreeNodeFlags, "%s", node->name().c_str()); DisplayNodeDetails(node, state); ImGui::PopStyleColor(); } if (open) { for (const auto& pair : node->nodes()) { MyTreeNode::DisplayNode(pair.second, state); } ImGui::TreePop(); } } static void DisplayLayerDetails(PrototypeSceneLayer* layer, PrototypeUIState_& state) { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10.0f, 10.0f)); if (ImGui::BeginPopupContextItem(layer->name().c_str())) { if (ImGui::Selectable("Add child node")) { PrototypePipelineQueue queue = {}; auto cmd = std::make_unique<PrototypePipelineCommand_shortcutEditorAddSceneNodeToLayer>(); cmd->parentLayer = layer; cmd->position = glm::vec3(0.0f, 2.0f, 0.0f); cmd->rotation = glm::vec3(0.0f, 0.0f, 0.0f); cmd->dir = glm::vec3(0.0f, 0.0f, 0.0f); queue.record(std::move(cmd)); PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } ImGui::EndPopup(); } ImGui::PopStyleVar(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_TREENODE")) { IM_ASSERT(payload->DataSize == sizeof(PrototypeSceneNode*)); PrototypeSceneNode* payloadNode = *(PrototypeSceneNode**)payload->Data; PrototypeSceneNode* oldParentNode = payloadNode->parentNode(); if (oldParentNode) { oldParentNode->moveNode(payloadNode, layer); state |= PrototypeUIState_HierarchyChanged; } else { PrototypeSceneLayer* oldParentLayer = payloadNode->parentLayer(); if (oldParentLayer) { oldParentLayer->moveNode(payloadNode, layer); } } } ImGui::EndDragDropTarget(); } } static void DisplayLayer(PrototypeSceneLayer* layer, PrototypeUIState_& state) { ImGuiTreeNodeFlags layerTreeNodeFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_ClipLabelForTrailingButton | ImGuiTreeNodeFlags_NavLeftJumpsBackHere | ImGuiTreeNodeFlags_NoAutoOpenOnLog | ImGuiTreeNodeFlags_OpenOnDoubleClick; const auto& nodes = layer->nodes(); if (nodes.empty()) { layerTreeNodeFlags |= ImGuiTreeNodeFlags_Leaf; } bool open = false; if (layer->isMatching()) { ImGui::TableNextRow(); ImGui::TableNextColumn(); open = ImGui::TreeNodeEx(layer->name().c_str(), layerTreeNodeFlags, "%s", layer->name().c_str()); DisplayLayerDetails(layer, state); } else if (layer->isPartialMatching()) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(PROTOTYPE_GRAY, 1.0f)); open = ImGui::TreeNodeEx(layer->name().c_str(), layerTreeNodeFlags, "%s", layer->name().c_str()); DisplayLayerDetails(layer, state); ImGui::PopStyleColor(); } if (open) { for (const auto& pair : nodes) { MyTreeNode::DisplayNode(pair.second, state); } ImGui::TreePop(); } } }; const auto& layers = PrototypeEngineInternalApplication::scene->layers(); for (const auto& pair : layers) { MyTreeNode::DisplayLayer(pair.second, state); } ImGui::EndTable(); } } } else { _openViewsMask &= ~PrototypeUiViewMaskHierarchy; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); { if (ImGui::Begin("3D View", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMask3DView; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } state = _sceneView.onDrawFrame(state, _awesomeFontTitle); } else { _openViewsMask &= ~PrototypeUiViewMask3DView; state |= PrototypeUIState_Iconified; } ImGui::End(); if (ImGui::Begin("3D Paint", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMask3DPaint; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } } else { _openViewsMask &= ~PrototypeUiViewMask3DPaint; } ImGui::End(); if (ImGui::Begin("Game", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskGame; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } } else { _openViewsMask &= ~PrototypeUiViewMaskGame; } ImGui::End(); if (ImGui::Begin("Texture Editor", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskTextureEditor; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } } else { _openViewsMask &= ~PrototypeUiViewMaskTextureEditor; } ImGui::End(); #if defined(PROTOTYPE_ENABLE_PROFILER) if (ImGui::Begin("Profiler", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskProfiler; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } auto& timelineItems = PrototypeEngineInternalApplication::profiler->getTimelineItems(); ImVec2 available = ImGui::GetContentRegionAvail(); ImVec2 graphSize(available.x, (available.y / timelineItems.size()) - (timelineItems.size() - 1)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10.0f, 10.0f)); { ImPlot::SetNextPlotLimitsX(-25, PROTOTYPE_PROFILER_BUFFER_LENGTH + 25, ImGuiCond_FirstUseEver); ImPlot::SetNextPlotLimitsY(0, 6000, ImGuiCond_FirstUseEver); if (ImPlot::BeginPlot("##RollingProfiler", NULL, "microseconds", ImGui::GetContentRegionAvail(), 0, 0, 0)) { const auto& xaxis = PrototypeEngineInternalApplication::profiler->xaxis(); for (const auto& item : timelineItems) { if (!item.second.isVisisble) continue; ImPlot::PushStyleColor(ImPlotCol_Line, *((ImVec4*)&item.second.color.x)); // ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f); // ImPlot::PlotShaded(identifier.name, &xvalues[0], &yvalues[0], xvalues.size(), 0.0f); // ImPlot::PopStyleVar(); ImPlot::PlotLine( item.second.name.c_str(), &xaxis[0], &item.second.values[0], xaxis.size(), 0, sizeof(float)); } ImPlot::EndPlot(); } } ImGui::PopStyleVar(); } else { _openViewsMask &= ~PrototypeUiViewMaskProfiler; } ImGui::End(); #endif // #if defined(PROTOTYPE_ENABLE_PROFILER) } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(45.0f, 45.0f)); { if (ImGui::Begin("Input Settings", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskInputSettings; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; const std::vector<std::pair<std::string, std::string>> mouseShortcuts = { { " Mouse Left click", "Select an object in Scene View" }, { " Mouse Right click + Drag Left", "Look Left" }, { " Mouse Right click + Drag Right", "Look Right" }, { " Mouse Right click + Drag Up", "Look Up" }, { " Mouse Right click + Drag Down", "Look Down" }, }; if (ImGui::BeginTable("##inputs mouse shortcuts table", 2, tableFlags)) { ImGui::TableSetupColumn(" " ICON_FA_MOUSE " Mouse", 0); ImGui::TableHeadersRow(); ImGuiListClipper clipper; clipper.Begin(mouseShortcuts.size()); while (clipper.Step()) { for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) { ImGui::TableNextRow(); ImGui::TableNextColumn(); const auto& pair = mouseShortcuts[row]; ImGui::Text("%s", pair.first.c_str()); ImGui::TableNextColumn(); ImGui::Text("%s", pair.second.c_str()); } } ImGui::EndTable(); } ImGui::NewLine(); const std::vector<std::pair<std::string, std::string>> keyboardShortcuts = { { " Left Shift + T", "Switch guizmo to translation mode" }, { " Left Shift + S", "Switch guizmo to scaling mode" }, { " Left Shift + R", "Switch guizmo to rotation mode" }, { " Tab", "Switch guizmo between World/Local transformation" }, { " Arrow Up", "Accelerate vehicle" }, { " Arrow Down", "Brake vehicle" }, { " Arrow Right", "Stear vehicle right" }, { " Arrow Left", "Stear vehicle left" }, { " G", "Toggle vehicle gears Backward/Forward" }, { " 0", "Flip car" }, { " 7", "Spawn car" }, { " 1", "Spawn Sphere" }, { " 2", "Spawn Cube" }, { " 3", "Spawn icosphere" }, { " 4", "Spawn monkey" }, { " 5", "Spawn capsule" }, { " 6", "Spawn cylinder" }, { " W", "Move camera forward" }, { " S", "Move camera backward" }, { " D", "Move camera right" }, { " A", "Move camera left" }, { " i", "Move camera up" }, { " k", "Move camera down" } }; if (ImGui::BeginTable("##inputs keyboard shortcuts table", 2, tableFlags)) { ImGui::TableSetupColumn(" " ICON_FA_KEYBOARD " Keyboard", 0); ImGui::TableHeadersRow(); ImGuiListClipper clipper; clipper.Begin(keyboardShortcuts.size()); while (clipper.Step()) { for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) { ImGui::TableNextRow(); ImGui::TableNextColumn(); const auto& pair = keyboardShortcuts[row]; ImGui::Text("%s", pair.first.c_str()); ImGui::TableNextColumn(); ImGui::Text("%s", pair.second.c_str()); } } ImGui::EndTable(); } ImGui::NewLine(); } else { _openViewsMask &= ~PrototypeUiViewMaskInputSettings; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15.0f, 15.0f)); { if (ImGui::Begin("Text Editor", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskTextEditor; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } static auto current_shaderBuffer_item = PrototypeEngineInternalApplication::database->shaderBuffers.begin(); static auto current_shaderBuffer_type_item = current_shaderBuffer_item->second->sources().begin(); static const char* current_shaderBuffer_type_item_name = "Vertex Shader"; static char shader_code_buf[102400] = { 0 }; bool value_changed = false; ImGui::PushFont((ImFont*)_awesomeFontTitle); if (ImGui::Button(ICON_FA_SAVE, ImVec2(25.0f, 25.0f))) { std::string code(shader_code_buf, strlen(shader_code_buf)); PrototypeIo::writeFileBlock((*current_shaderBuffer_type_item)->fullpath.c_str(), code); } ImGui::PopFont(); ImGui::SameLine(); if (ImGui::BeginCombo("##shader files text editor", current_shaderBuffer_item->first.c_str(), ImGuiComboFlags_None)) { for (auto it = PrototypeEngineInternalApplication::database->shaderBuffers.begin(); it != PrototypeEngineInternalApplication::database->shaderBuffers.end(); ++it) { ImGui::PushID((void*)it->first.c_str()); const bool item_selected = (it == current_shaderBuffer_item); const char* item_text; if (ImGui::Selectable(it->first.c_str(), item_selected)) { value_changed = true; memset(shader_code_buf, 0, sizeof(shader_code_buf)); current_shaderBuffer_item = it; current_shaderBuffer_type_item = it->second->sources().begin(); switch ((*current_shaderBuffer_type_item)->type) { case PrototypeShaderBufferSourceType_VertexShader: current_shaderBuffer_type_item_name = "Vertex Shader"; break; case PrototypeShaderBufferSourceType_FragmentShader: current_shaderBuffer_type_item_name = "Fragment Shader"; break; default: break; } } if (item_selected) ImGui::SetItemDefaultFocus(); ImGui::PopID(); } ImGui::EndCombo(); } if (ImGui::BeginCombo("##shader file type text editor", current_shaderBuffer_type_item_name, ImGuiComboFlags_None)) { for (auto it = current_shaderBuffer_item->second->sources().begin(); it != current_shaderBuffer_item->second->sources().end(); ++it) { ImGui::PushID((void*)(*it)->type); const bool item_selected = (current_shaderBuffer_type_item == it); const char* item_text; switch ((*it)->type) { case PrototypeShaderBufferSourceType_VertexShader: item_text = "Vertex Shader"; break; case PrototypeShaderBufferSourceType_FragmentShader: item_text = "Fragment Shader"; break; default: break; } if (ImGui::Selectable(item_text, item_selected)) { value_changed = true; memset(shader_code_buf, 0, sizeof(shader_code_buf)); current_shaderBuffer_type_item = it; current_shaderBuffer_type_item_name = item_text; } if (item_selected) ImGui::SetItemDefaultFocus(); ImGui::PopID(); } ImGui::EndCombo(); } if (shader_code_buf[0] == '\0') { std::string code; PrototypeIo::readFileBlock((*current_shaderBuffer_type_item)->fullpath.c_str(), code); memcpy(shader_code_buf, code.c_str(), code.size()); } ImGui::InputTextMultiline("##shader multiline input", shader_code_buf, sizeof(shader_code_buf), ImGui::GetContentRegionAvail(), ImGuiInputTextFlags_AllowTabInput); } else { _openViewsMask &= ~PrototypeUiViewMaskTextEditor; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Traits", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskTraits; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } const auto& selectedNodes = PrototypeEngineInternalApplication::scene->selectedNodes(); if (!selectedNodes.empty()) { PrototypeSceneNode* first = *selectedNodes.begin(); static PrototypeObject* object = nullptr; object = first->object().value(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10.0f, 10.0f)); if (ImGui::BeginPopupContextWindow(first->name().c_str())) { if (ImGui::Selectable("Add child node")) { PrototypePipelineQueue queue = {}; auto cmd = std::make_unique<PrototypePipelineCommand_shortcutEditorAddSceneNodeToNode>(); cmd->parentNode = first; cmd->position = glm::vec3(0.0f, 2.0f, 0.0f); cmd->rotation = glm::vec3(0.0f, 0.0f, 0.0f); cmd->dir = glm::vec3(0.0f, 0.0f, 0.0f); queue.record(std::move(cmd)); PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } if (ImGui::Selectable("Delete")) { PrototypePipelineQueue queue = {}; auto cmd = std::make_unique<PrototypePipelineCommand_shortcutEditorRemoveSceneNode>(); cmd->node = first; queue.record(std::move(cmd)); PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } ImGui::Separator(); for (MASK_TYPE itrait = 0; itrait < PrototypeTraitTypeCount; ++itrait) { if (ImGui::Selectable(((object->has(1ULL << itrait) ? ICON_FA_CHECK " " : " ") + PrototypeTraitTypeAbsoluteStringArray[itrait] + " trait") .c_str())) { if (object->has(1ULL << itrait)) { PrototypePipelineQueue queue = {}; auto cmd = std::make_unique<PrototypePipelineCommand_shortcutEditorSelectedSceneNodeRemoveTraits>(); cmd->object = object; cmd->traitMask = (1ULL << itrait); queue.record(std::move(cmd)); PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } else { PrototypePipelineQueue queue = {}; auto cmd = std::make_unique<PrototypePipelineCommand_shortcutEditorSelectedSceneNodeAddTraits>(); cmd->object = object; cmd->traitMask = (1ULL << itrait); queue.record(std::move(cmd)); PrototypePipelines::shortcutsQueue.push_back(std::move(queue)); } } } ImGui::EndPopup(); } ImGui::PopStyleVar(); static char nodeNameBuffer[128]; snprintf(nodeNameBuffer, sizeof(nodeNameBuffer), "%s", first->name().c_str()); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::InputText("##Node Name", nodeNameBuffer, sizeof(nodeNameBuffer))) { first->renameNode(std::string(nodeNameBuffer)); } auto optObj = first->object(); if (optObj.has_value()) { auto obj = optObj.value(); ImGui::NewLine(); obj->onEdit(); } } } else { _openViewsMask &= ~PrototypeUiViewMaskTraits; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Properties", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskProperties; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } switch (_assetConfigSelection.type) { case PrototypeConfigurationSelectionAssetType_Mesh: { if (_assetConfigSelection.mesh) { static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("mesh configuration content table", 2, tableFlags)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("name"); ImGui::TableSetColumnIndex(1); ImGui::Text("%s", _assetConfigSelection.mesh->name.c_str()); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("type"); ImGui::TableSetColumnIndex(1); ImGui::Text("%i", _assetConfigSelection.mesh->type); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Indices count"); ImGui::TableSetColumnIndex(1); ImGui::Text("%lu", _assetConfigSelection.mesh->indexCount); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("vertex array object"); ImGui::TableSetColumnIndex(1); ImGui::Text("%lu", _assetConfigSelection.mesh->vao); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("vertex buffer object"); ImGui::TableSetColumnIndex(1); ImGui::Text("%lu", _assetConfigSelection.mesh->vbo); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Element array buffer object"); ImGui::TableSetColumnIndex(1); ImGui::Text("%lu", _assetConfigSelection.mesh->eabo); ImGui::EndTable(); } } } break; case PrototypeConfigurationSelectionAssetType_Shader: { if (_assetConfigSelection.shader) { static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("shader configuration content table", 2, tableFlags)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("name"); ImGui::TableSetColumnIndex(1); ImGui::Text("%s", _assetConfigSelection.shader->name.c_str()); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("program"); ImGui::TableSetColumnIndex(1); ImGui::Text("%lu", _assetConfigSelection.shader->program); for (const auto& texture : _assetConfigSelection.shader->textureData) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::Text("2D Texture"); ImGui::TableSetColumnIndex(1); ImGui::TextUnformatted(texture.c_str()); } for (const auto& pair : _assetConfigSelection.shader->floatData) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::Text("%f", pair.second); } for (const auto& pair : _assetConfigSelection.shader->vec2Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::Text("%f, %f", pair.second.r, pair.second.g); } for (const auto& pair : _assetConfigSelection.shader->vec3Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::Text("%f, %f, %f", pair.second.r, pair.second.g, pair.second.b); } for (const auto& pair : _assetConfigSelection.shader->vec4Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::Text("%f, %f, %f, %f", pair.second.r, pair.second.g, pair.second.b, pair.second.a); } ImGui::EndTable(); } } } break; case PrototypeConfigurationSelectionAssetType_Texture: { if (_assetConfigSelection.texture) { static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("texture configuration content table", 2, tableFlags)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("name"); ImGui::TableSetColumnIndex(1); ImGui::Text("%s", _assetConfigSelection.texture->name.c_str()); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("type"); ImGui::TableSetColumnIndex(1); ImGui::Text("%i", _assetConfigSelection.texture->type); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("id"); ImGui::TableSetColumnIndex(1); ImGui::Text("%lu", _assetConfigSelection.texture->id); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("width"); ImGui::TableSetColumnIndex(1); ImGui::Text("%zu", _assetConfigSelection.texture->width); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("height"); ImGui::TableSetColumnIndex(1); ImGui::Text("%zu", _assetConfigSelection.texture->height); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("internal format"); ImGui::TableSetColumnIndex(1); ImGui::Text("%i", _assetConfigSelection.texture->internalFormat); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("format"); ImGui::TableSetColumnIndex(1); ImGui::Text("%i", _assetConfigSelection.texture->format); ImGui::EndTable(); } } } break; case PrototypeConfigurationSelectionAssetType_Material: { if (_assetConfigSelection.material) { static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; if (ImGui::BeginTable("material configuration content table", 2, tableFlags)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("name"); ImGui::TableSetColumnIndex(1); ImGui::Text("%s", _assetConfigSelection.material->name.c_str()); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("shader"); ImGui::TableSetColumnIndex(1); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::Button((char*)_assetConfigSelection.material->shader->name.c_str(), ImVec2(ImGui::GetContentRegionAvailWidth(), 30.0f)); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_SHADER")) { IM_ASSERT(payload->DataSize == sizeof(PglShader*)); PglShader* shader = *(PglShader**)payload->Data; size_t originalSize = _assetConfigSelection.material->textureData.size(); _assetConfigSelection.material->shader = shader; ((PrototypeOpenglRenderer*)PrototypeEngineInternalApplication::renderer) ->onMaterialShaderUpdate(_assetConfigSelection.material, shader); _assetConfigSelection.material->textures.resize( _assetConfigSelection.material->textureData.size()); _assetConfigSelection.material->textures.shrink_to_fit(); for (size_t s = originalSize; s < _assetConfigSelection.material->textures.size(); ++s) { PrototypeEngineInternalApplication::renderer->fetchDefaultTexture( (void**)&_assetConfigSelection.material->textures[s]); } PrototypeEngineInternalApplication::renderer->scheduleRecordPass(); } ImGui::EndDragDropTarget(); } ImGui::PopStyleColor(4); ImGui::PopStyleVar(); for (size_t t = 0; t < _assetConfigSelection.material->textures.size(); ++t) { auto tdata = _assetConfigSelection.material->textureData.begin(); std::advance(tdata, t); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::Text("%s", (*tdata).c_str()); ImGui::TableSetColumnIndex(1); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_GRAY, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(PROTOTYPE_DARKESTGRAY, 0.0f)); ImGui::Button((char*)_assetConfigSelection.material->textures[t]->name.c_str(), ImVec2(ImGui::GetContentRegionAvailWidth(), 30.0f)); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_TEXTURE")) { IM_ASSERT(payload->DataSize == sizeof(PglTexture*)); PglTexture* texture = *(PglTexture**)payload->Data; _assetConfigSelection.material->textures[t] = texture; PrototypeEngineInternalApplication::renderer->scheduleRecordPass(); } ImGui::EndDragDropTarget(); } ImGui::PopStyleColor(4); ImGui::PopStyleVar(); } ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Base Color"); ImGui::TableSetColumnIndex(1); if (ImGui::ColorEdit3("##Base Color", &_assetConfigSelection.material->baseColor[0], ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_PickerHueBar | ImGuiColorEditFlags_DisplayRGB)) {} ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Metallic"); ImGui::TableSetColumnIndex(1); if (ImGui::DragFloat("##Metallic", &_assetConfigSelection.material->metallic, 0.01f, 0.0f, 1.0f)) { glm::clamp(_assetConfigSelection.material->metallic, 0.0f, 1.0f); } ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("Roughness"); ImGui::TableSetColumnIndex(1); if (ImGui::DragFloat("##Roughness", &_assetConfigSelection.material->roughness, 0.01f, 0.0f, 1.0f)) { glm::clamp(_assetConfigSelection.material->roughness, 0.0f, 1.0f); } // VALUES for (auto& pair : _assetConfigSelection.material->floatData) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat(fmt::format("##{}", pair.first).c_str(), &pair.second); } for (auto& pair : _assetConfigSelection.material->vec2Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat2(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } for (auto& pair : _assetConfigSelection.material->vec3Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat3(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } for (auto& pair : _assetConfigSelection.material->vec4Data) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::DragFloat4(fmt::format("##{}", pair.first).c_str(), &pair.second[0]); } ImGui::EndTable(); } } } break; case PrototypeConfigurationSelectionAssetType_None: case PrototypeConfigurationSelectionAssetType_Count: default: break; } } else { _openViewsMask &= ~PrototypeUiViewMaskProperties; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Settings", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskSettings; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } static char searchBuffer[128]; ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::InputTextWithHint( "##settings search input text", ICON_FA_FILTER " Filter settings ...", searchBuffer, sizeof(searchBuffer))) {} ImGui::NewLine(); static ImGuiTableFlags tableFlags = ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_PreciseWidths; #if defined(PROTOTYPE_ENABLE_PROFILER) static bool isProfilerOpen = false; ImGuiHelpers::BeginGroupPanel("Profiler", ImVec2(-1.0f, 0.0f), isProfilerOpen, _awesomeFont); if (isProfilerOpen) { ImGui::Indent(16.0f); auto& timelineItems = PrototypeEngineInternalApplication::profiler->getTimelineItems(); for (auto& item : timelineItems) { ImGui::PushID(item.first.c_str()); { ImGuiHelpers::BeginGroupPanel(item.first.c_str(), ImVec2(-1.0f, 0.0f), item.second.isOpen, _awesomeFont); if (item.second.isOpen) { ImGui::Indent(16.0f); if (ImGui::BeginTable("##profiler content table", 2, tableFlags)) { { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("visible"); ImGui::TableSetColumnIndex(1); ImGui::Checkbox("##visible", &item.second.isVisisble); } { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted("color"); ImGui::TableSetColumnIndex(1); ImGui::ColorEdit4("##color", &item.second.color.x, ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_PickerHueBar | ImGuiColorEditFlags_DisplayRGB); } ImGui::EndTable(); } ImGui::Unindent(16.0f); ImGuiHelpers::EndGroupPanel(); } } ImGui::PopID(); } ImGui::Unindent(16.0f); ImGuiHelpers::EndGroupPanel(); } #endif // #if defined(PROTOTYPE_ENABLE_PROFILER) static bool isThemeOpen = false; ImGuiHelpers::BeginGroupPanel("Theme", ImVec2(-1.0f, 0.0f), isThemeOpen, _awesomeFont); if (isThemeOpen) { ImGui::Indent(16.0f); if (ImGui::BeginTable("##settings color content table", 2, tableFlags)) { ImGuiStyle& style = ImGui::GetStyle(); static const std::map<std::string, std::pair<std::string, bool*>> boolProperties = { { "Anti-aliased lines", { "##UI [Bool] Anti-aliased lines", &style.AntiAliasedLines } }, { "Anti-aliased lines use tex", { "##UI [Bool] Anti-aliased lines use tex", &style.AntiAliasedLinesUseTex } }, { "Anti-aliased fill", { "##UI [Bool] Anti-aliased fill", &style.AntiAliasedFill } } }; static const std::map<std::string, std::pair<std::string, float*>> floatProperties = { { "Curve tessellation tol", { "##UI [Float] Curve tessellation tol", &style.CurveTessellationTol } }, { "Circle segment max error", { "##UI [Float] Circle segment max error", &style.CircleSegmentMaxError } }, { "Child rounding", { "##UI [Float] Child rounding", &style.ChildRounding } }, { "Window rounding", { "##UI [Float] Window rounding", &style.WindowRounding } }, { "Grab rounding", { "##UI [Float] Grab rounding", &style.GrabRounding } }, { "Scrollbar rounding", { "##UI [Float] Scrollbar rounding", &style.ScrollbarRounding } }, { "Scrollbar size", { "##UI [Float] Scrollbar size", &style.ScrollbarSize } }, { "Frame rounding", { "##UI [Float] Frame rounding", &style.FrameRounding } }, { "Tab rounding", { "##UI [Float] Tab rounding", &style.TabRounding } }, { "Tab border size", { "##UI [Float] Tab border size", &style.TabBorderSize } } }; static const std::map<std::string, std::pair<std::string, float*>> vec2Properties = { { "Window title align", { "##UI [Vec2] Window title align", &style.WindowTitleAlign.x } } }; static const std::map<std::string, std::pair<std::string, float*>> vec4Properties = { { "Button", { "##UI [Vec4] Button", &style.Colors[ImGuiCol_Button].x } }, { "Button hovered", { "##UI [Vec4] Button hovered", &style.Colors[ImGuiCol_ButtonHovered].x } }, { "Button active", { "##UI [Vec4] Button active", &style.Colors[ImGuiCol_ButtonActive].x } }, { "Text", { "##UI [Vec4] Text", &style.Colors[ImGuiCol_Text].x } }, { "Text selected bg", { "##UI [Vec4] Text selected bg", &style.Colors[ImGuiCol_TextSelectedBg].x } }, { "Text disabled", { "##UI [Vec4] Text disabled", &style.Colors[ImGuiCol_TextDisabled].x } }, { "Window bg", { "##UI [Vec4] Window bg", &style.Colors[ImGuiCol_WindowBg].x } }, { "Child bg", { "##UI [Vec4] Child bg", &style.Colors[ImGuiCol_ChildBg].x } }, { "Popup bg", { "##UI [Vec4] Popup bg", &style.Colors[ImGuiCol_PopupBg].x } }, { "Border", { "##UI [Vec4] Border", &style.Colors[ImGuiCol_Border].x } }, { "Border shadow", { "##UI [Vec4] Border shadow", &style.Colors[ImGuiCol_BorderShadow].x } }, { "Frame bg", { "##UI [Vec4] Frame bg", &style.Colors[ImGuiCol_FrameBg].x } }, { "Frame bg hovered", { "##UI [Vec4] Frame bg hovered", &style.Colors[ImGuiCol_FrameBgHovered].x } }, { "Frame bg active", { "##UI [Vec4] Frame bg active", &style.Colors[ImGuiCol_FrameBgActive].x } }, { "Title bg", { "##UI [Vec4] Title bg", &style.Colors[ImGuiCol_TitleBg].x } }, { "Title bg collapsed", { "##UI [Vec4] Title bg collapsed", &style.Colors[ImGuiCol_TitleBgCollapsed].x } }, { "Title bg active", { "##UI [Vec4] Title bg active", &style.Colors[ImGuiCol_TitleBgActive].x } }, { "Menubar bg", { "##UI [Vec4] Menubar bg", &style.Colors[ImGuiCol_MenuBarBg].x } }, { "Tab", { "##UI [Vec4] Tab", &style.Colors[ImGuiCol_Tab].x } }, { "Tab unfocused", { "##UI [Vec4] Tab unfocused", &style.Colors[ImGuiCol_TabUnfocused].x } }, { "Tab hovered", { "##UI [Vec4] Tab hovered", &style.Colors[ImGuiCol_TabHovered].x } }, { "Tab active", { "##UI [Vec4] Tab active", &style.Colors[ImGuiCol_TabActive].x } }, { "Tab unfocused active", { "##UI [Vec4] Tab unfocused active", &style.Colors[ImGuiCol_TabUnfocusedActive].x } }, { "Scrollbar bg", { "##UI [Vec4] Scrollbar bg", &style.Colors[ImGuiCol_ScrollbarBg].x } }, { "Scrollbar grab", { "##UI [Vec4] Scrollbar grab", &style.Colors[ImGuiCol_ScrollbarGrab].x } }, { "Scrollbar grab hovered", { "##UI [Vec4] Scrollbar grab hovered", &style.Colors[ImGuiCol_ScrollbarGrabHovered].x } }, { "Scrollbar grab active", { "##UI [Vec4] Scrollbar grab active", &style.Colors[ImGuiCol_ScrollbarGrabActive].x } }, { "Header", { "##UI [Vec4] Header", &style.Colors[ImGuiCol_Header].x } }, { "Header hovered", { "##UI [Vec4] Header hovered", &style.Colors[ImGuiCol_HeaderHovered].x } }, { "Header active", { "##UI [Vec4] Header active", &style.Colors[ImGuiCol_HeaderActive].x } }, { "Plot lines", { "##UI [Vec4] Plot lines", &style.Colors[ImGuiCol_PlotLines].x } }, { "Plot lines hovered", { "##UI [Vec4] Plot lines hovered", &style.Colors[ImGuiCol_PlotLinesHovered].x } }, { "Plot histogram", { "##UI [Vec4] Plot histogram", &style.Colors[ImGuiCol_PlotHistogram].x } }, { "Plot histogram hovered", { "##UI [Vec4] Plot histogram hovered", &style.Colors[ImGuiCol_PlotHistogramHovered].x } }, { "Resize grip", { "##UI [Vec4] Resize grip", &style.Colors[ImGuiCol_ResizeGrip].x } }, { "Resize grip hovered", { "##UI [Vec4] Resize grip hovered", &style.Colors[ImGuiCol_ResizeGripHovered].x } }, { "Resize grip active", { "##UI [Vec4] Resize grip active", &style.Colors[ImGuiCol_ResizeGripActive].x } } }; for (const auto& pair : boolProperties) { if (pair.first.find(searchBuffer) != std::string::npos) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); ImGui::Checkbox(pair.second.first.c_str(), pair.second.second); } } for (const auto& pair : floatProperties) { if (pair.first.find(searchBuffer) != std::string::npos) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); ImGui::DragFloat(pair.second.first.c_str(), pair.second.second); } } for (const auto& pair : vec2Properties) { if (pair.first.find(searchBuffer) != std::string::npos) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); ImGui::DragFloat2(pair.second.first.c_str(), pair.second.second); } } for (const auto& pair : vec4Properties) { if (pair.first.find(searchBuffer) != std::string::npos) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(pair.first.c_str()); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); ImGui::ColorEdit4(pair.second.first.c_str(), pair.second.second, ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_PickerHueBar | ImGuiColorEditFlags_DisplayRGB); } } ImGui::EndTable(); } ImGui::Unindent(16.0f); ImGuiHelpers::EndGroupPanel(); } } else { _openViewsMask &= ~PrototypeUiViewMaskSettings; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Scenes", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskScenes; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("##scenes table", 1, flags)) { for (const auto& pair : PrototypeEngineInternalApplication::database->scenes) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::Text("%s", pair.first.c_str()); if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) { PrototypeEngineInternalApplication::renderer->switchScenes(pair.second); } } ImGui::EndTable(); } } else { _openViewsMask &= ~PrototypeUiViewMaskScenes; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Meshes", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskMeshes; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } float posx = ImGui::GetContentRegionAvailWidth(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::InputTextWithHint("##meshes search input text", ICON_FA_FILTER " Filter meshes ...", _recordedInstructions.meshesSearchBuff, sizeof(_recordedInstructions.meshesSearchBuff))) { scheduleRecordPass(PrototypeUiViewMaskMeshes); } ImGui::TextColored(ImVec4(PROTOTYPE_GREEN, 1.0f), "%zu items", _recordedInstructions.meshes.size()); static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("##meshes table", 1, flags)) { ImGuiListClipper clipper; clipper.Begin(_recordedInstructions.meshes.size()); while (clipper.Step()) { for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) { ImGui::TableNextRow(); ImGui::TableNextColumn(); PglGeometry* mesh = _recordedInstructions.meshes[row]; ImGui::Text("%s", mesh->name.c_str()); if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { _assetConfigSelection.mesh = mesh; _assetConfigSelection.type = PrototypeConfigurationSelectionAssetType_Mesh; } if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { ImGui::SetDragDropPayload("_MESH", &mesh, sizeof(PglGeometry*)); ImGui::Text("%s", mesh->name.c_str()); ImGui::EndDragDropSource(); } } } ImGui::EndTable(); } } else { _openViewsMask &= ~PrototypeUiViewMaskMeshes; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Shaders", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskShaders; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } float posx = ImGui::GetContentRegionAvailWidth(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::InputTextWithHint("##shaders search input text", ICON_FA_FILTER " Filter shaders ...", _recordedInstructions.shadersSearchBuff, sizeof(_recordedInstructions.shadersSearchBuff))) { scheduleRecordPass(PrototypeUiViewMaskShaders); } ImGui::TextColored(ImVec4(PROTOTYPE_GREEN, 1.0f), "%zu items", _recordedInstructions.shaders.size()); static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("##shaders table", 1, flags)) { ImGuiListClipper clipper; clipper.Begin(_recordedInstructions.shaders.size()); while (clipper.Step()) { for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) { ImGui::TableNextRow(); ImGui::TableNextColumn(); PglShader* shader = _recordedInstructions.shaders[row]; ImGui::Text("%s", shader->name.c_str()); if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { _assetConfigSelection.shader = shader; _assetConfigSelection.type = PrototypeConfigurationSelectionAssetType_Shader; } if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { ImGui::SetDragDropPayload("_SHADER", &shader, sizeof(PglShader*)); ImGui::Text("%s", shader->name.c_str()); ImGui::EndDragDropSource(); } } } ImGui::EndTable(); } } else { _openViewsMask &= ~PrototypeUiViewMaskShaders; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Textures", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskTextures; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } float posx = ImGui::GetContentRegionAvailWidth(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::InputTextWithHint("##textures search input text", ICON_FA_FILTER " Filter textures ...", _recordedInstructions.texturesSearchBuff, sizeof(_recordedInstructions.texturesSearchBuff))) { scheduleRecordPass(PrototypeUiViewMaskTextures); } ImGui::TextColored(ImVec4(PROTOTYPE_GREEN, 1.0f), "%zu items", _recordedInstructions.textures.size()); static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("##textures table", 1, flags)) { ImGuiListClipper clipper; clipper.Begin(_recordedInstructions.textures.size()); while (clipper.Step()) { for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) { ImGui::TableNextRow(); ImGui::TableNextColumn(); PglTexture* texture = _recordedInstructions.textures[row]; ImGui::Text("%s", texture->name.c_str()); if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { _assetConfigSelection.texture = texture; _assetConfigSelection.type = PrototypeConfigurationSelectionAssetType_Texture; } if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { ImGui::SetDragDropPayload("_TEXTURE", &texture, sizeof(PglTexture*)); ImGui::Text("%s", texture->name.c_str()); ImGui::EndDragDropSource(); } } } ImGui::EndTable(); } } else { _openViewsMask &= ~PrototypeUiViewMaskTextures; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Materials", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskMaterials; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } if (ImGui::BeginPopupContextWindow("##materials popup context menu")) { if (ImGui::Selectable("Add new material")) { static std::vector<const char*> shadersCombo; static std::vector<const char*> texturesCombo; shadersCombo.clear(); texturesCombo.clear(); for (const auto& shaderPair : PrototypeEngineInternalApplication::database->shaderBuffers) { shadersCombo.push_back(shaderPair.first.c_str()); } for (const auto& texturePair : PrototypeEngineInternalApplication::database->textureBuffers) { texturesCombo.push_back(texturePair.first.c_str()); } PrototypeUiMaterialForm form = {}; auto shaderIt = PrototypeEngineInternalApplication::database->shaderBuffers.find(shadersCombo[form.shader()]); if (shaderIt != PrototypeEngineInternalApplication::database->shaderBuffers.end()) { size_t originalSize = shaderIt->second->sources()[1]->bindingSource.textureData.size(); form.textures().resize(shaderIt->second->sources()[1]->bindingSource.textureData.size()); for (size_t i = originalSize; i < form.textures().size(); ++i) { form.textures()[i] = 0; } } form.configure([&](PrototypeUiMaterialForm& thisForm) { ImGui::PushID(_materialforms.size()); ImGui::Text("Material name"); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(PROTOTYPE_LIGHTGRAY, 1.0f)); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); ImGui::InputText("##Add new material", thisForm.name(), thisForm.sizeofName()); ImGui::PopStyleColor(); if (ImGui::Combo( "##add new material shader combo", &thisForm.shader(), shadersCombo.data(), shadersCombo.size())) { auto shaderIt = PrototypeEngineInternalApplication::database->shaderBuffers.find(shadersCombo[thisForm.shader()]); if (shaderIt != PrototypeEngineInternalApplication::database->shaderBuffers.end()) { size_t originalSize = shaderIt->second->sources()[1]->bindingSource.textureData.size(); thisForm.textures().resize(shaderIt->second->sources()[1]->bindingSource.textureData.size()); for (size_t i = originalSize; i < thisForm.textures().size(); ++i) { thisForm.textures()[i] = 0; } } } for (size_t i = 0; i < thisForm.textures().size(); ++i) { ImGui::PushID(i); if (ImGui::Combo("##add new material texture combo", &thisForm.textures()[i], texturesCombo.data(), texturesCombo.size())) {} ImGui::PopID(); } if (ImGui::ColorEdit3("##Add new material base Color", &thisForm.baseColor().x, ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_PickerHueBar | ImGuiColorEditFlags_DisplayRGB)) {} if (ImGui::DragFloat("##Metallic", &thisForm.metallic(), 0.01f, 0.0f, 1.0f)) { glm::clamp(thisForm.metallic(), 0.0f, 1.0f); } if (ImGui::DragFloat("##Roughness", &thisForm.roughness(), 0.01f, 0.0f, 1.0f)) { glm::clamp(thisForm.roughness(), 0.0f, 1.0f); } if (ImGui::Button("Create")) { std::vector<std::string> namedTextures(thisForm.textures().size()); for (size_t i = 0; i < namedTextures.size(); ++i) { namedTextures[i] = texturesCombo[thisForm.textures()[i]]; } nlohmann::json j = { { "name", std::string(thisForm.name()) }, { "shader", std::string(shadersCombo[thisForm.shader()]) }, { "textures", namedTextures }, { "baseColor", { thisForm.baseColor().x, thisForm.baseColor().y, thisForm.baseColor().z } }, { "metallic", thisForm.metallic() }, { "roughness", thisForm.roughness() } }; PrototypeMaterial::from_json(j); auto materialIt = PrototypeEngineInternalApplication::database->materials.find(std::string(thisForm.name())); if (materialIt != PrototypeEngineInternalApplication::database->materials.end()) { PrototypeEngineInternalApplication::renderer->mapPrototypeMaterial(materialIt->second); scheduleRecordPass(PrototypeUiViewMaskMaterials); } ImGui::PopID(); return true; } ImGui::PopID(); return false; }); _materialforms.push(std::move(form)); } ImGui::EndPopup(); } float posx = ImGui::GetContentRegionAvailWidth(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::InputTextWithHint("##materials search input text", ICON_FA_FILTER " Filter materials ...", _recordedInstructions.materialsSearchBuff, sizeof(_recordedInstructions.materialsSearchBuff))) { scheduleRecordPass(PrototypeUiViewMaskMaterials); } ImGui::TextColored(ImVec4(PROTOTYPE_GREEN, 1.0f), "%zu items", _recordedInstructions.materials.size()); static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("##materials table", 1, flags)) { ImGuiListClipper clipper; clipper.Begin(_recordedInstructions.materials.size()); while (clipper.Step()) { for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) { ImGui::TableNextRow(); ImGui::TableNextColumn(); PglMaterial* material = _recordedInstructions.materials[row]; ImGui::Text("%s", material->name.c_str()); if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { _assetConfigSelection.material = material; _assetConfigSelection.type = PrototypeConfigurationSelectionAssetType_Material; } if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { ImGui::SetDragDropPayload("_MATERIAL", &material, sizeof(PglMaterial*)); ImGui::Text("%s", material->name.c_str()); ImGui::EndDragDropSource(); } } } ImGui::EndTable(); } } else { _openViewsMask &= ~PrototypeUiViewMaskMaterials; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Framebuffers", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskFramebuffers; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } static char framebuffersSearchBuff[128]; float posx = ImGui::GetContentRegionAvailWidth(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::InputTextWithHint("##framebuffers search input text", ICON_FA_FILTER " Filter framebuffers ...", framebuffersSearchBuff, sizeof(framebuffersSearchBuff))) {} static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("##framebuffers table", 1, flags)) { for (const auto& pair : PrototypeEngineInternalApplication::database->framebuffers) { size_t matchIndex = pair.first.find(framebuffersSearchBuff); if (matchIndex != std::string::npos) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::Text("%s", pair.first.substr(0, matchIndex).c_str()); if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { PglFramebuffer* framebuffer; PrototypeEngineInternalApplication::renderer->fetchFramebuffer(pair.first, (void**)&framebuffer); ImGui::SetDragDropPayload("_FRAMEBUFFER", &framebuffer, sizeof(PglFramebuffer*)); ImGui::Text("%s", pair.first.c_str()); ImGui::EndDragDropSource(); } ImGui::SameLine(0.0f, 0.0f); ImGui::TextColored(ImVec4(PROTOTYPE_BLUE, 1.0f), "%s", pair.first.substr(matchIndex, strlen(framebuffersSearchBuff)).c_str()); if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { PglFramebuffer* framebuffer; PrototypeEngineInternalApplication::renderer->fetchFramebuffer(pair.first, (void**)&framebuffer); ImGui::SetDragDropPayload("_FRAMEBUFFER", &framebuffer, sizeof(PglFramebuffer*)); ImGui::Text("%s", pair.first.c_str()); ImGui::EndDragDropSource(); } ImGui::SameLine(0.0f, 0.0f); ImGui::Text("%s", pair.first.substr(matchIndex + strlen(framebuffersSearchBuff)).c_str()); if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { PglFramebuffer* framebuffer; PrototypeEngineInternalApplication::renderer->fetchFramebuffer(pair.first, (void**)&framebuffer); ImGui::SetDragDropPayload("_FRAMEBUFFER", &framebuffer, sizeof(PglFramebuffer*)); ImGui::Text("%s", pair.first.c_str()); ImGui::EndDragDropSource(); } } } ImGui::EndTable(); } } else { _openViewsMask &= ~PrototypeUiViewMaskFramebuffers; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Console", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskConsole; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } static char consoleSearchBuff[128]; float posx = ImGui::GetContentRegionAvailWidth(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth() - 70.0f); if (ImGui::InputTextWithHint("##console search input text", ICON_FA_FILTER " Filter logs ...", consoleSearchBuff, sizeof(consoleSearchBuff))) {} ImGui::SameLine(); ImGui::SetCursorPosX(posx - 55.0f); if (ImGui::Button("Clear##console logs")) { PrototypeLogger::data()->logs.clear(); } { static const float TEXT_BASE_WIDTH = ImGui::CalcTextSize("A").x; static const float TEXT_BASE_HEIGHT = ImGui::GetTextLineHeightWithSpacing(); static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("##console table", 1, flags)) { for (const auto& refLog : PrototypeLogger::data()->logs) { size_t matchIndex = refLog.text.find(consoleSearchBuff); if (matchIndex != std::string::npos) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::TextColored(ImVec4(PROTOTYPE_GREEN, 1.0f), "[LOG] "); ImGui::SameLine(); ImGui::Text("%s", refLog.text.substr(0, matchIndex).c_str()); ImGui::SameLine(0.0f, 0.0f); ImGui::TextColored(ImVec4(PROTOTYPE_BLUE, 1.0f), "%s", refLog.text.substr(matchIndex, strlen(consoleSearchBuff)).c_str()); ImGui::SameLine(0.0f, 0.0f); ImGui::Text("%s", refLog.text.substr(matchIndex + strlen(consoleSearchBuff)).c_str()); if (ImGui::IsItemHovered()) { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10.0f, 10.0f)); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(PROTOTYPE_LIGHTERGRAY, 1.0f)); ImGui::SetTooltip("%s:%i", refLog.filepath.c_str(), refLog.line); ImGui::PopStyleColor(); ImGui::PopStyleVar(); } } } ImGui::EndTable(); } } } else { _openViewsMask &= ~PrototypeUiViewMaskConsole; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Scripts", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskScripts; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } static PrototypeUiPrompt pr = {}; static char scriptsSearchBuff[128]; float posx = ImGui::GetContentRegionAvailWidth(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::InputTextWithHint("##scripts search input text", ICON_FA_FILTER " Filter scripts ...", scriptsSearchBuff, sizeof(scriptsSearchBuff))) {} if (ImGui::BeginPopupContextWindow("##scripts popup context menu")) { if (ImGui::Selectable("Add new C++ script")) { pr.configure( "Create a new C++ script", "Pick a name for your C++ script", "Create", true, [this](std::string name) { if (name.size() < 5) { PrototypeErrorDialog errDialog = {}; errDialog.configure("Error", "Name is too short.\n5 < CppScriptNameLength < 30", true, true); _errorDialogs.push(std::move(errDialog)); return false; } if (name.size() >= 30) { PrototypeErrorDialog errDialog = {}; errDialog.configure("Error", "Name is too long.\n5 < CppScriptNameLength < 30", true, true); _errorDialogs.push(std::move(errDialog)); return false; } if (std::find_if(name.begin(), name.end(), [](char a) { return !isalpha(a); }) != name.end()) { PrototypeErrorDialog errDialog = {}; errDialog.configure( "Error", "Name must contain only alphabetic characters.\na .. z, A .. Z", true, true); _errorDialogs.push(std::move(errDialog)); return false; } if (PrototypeIo::checkIfPluginProjectExists(name.c_str())) { PrototypeErrorDialog errDialog = {}; errDialog.configure("Error", "There's already C++/Rust script with that name.\nTry picking another name.", true, true); _errorDialogs.push(std::move(errDialog)); return false; } PrototypeIo::createNewCppPluginProject(name.c_str()); return true; }, []() { return true; }); _prompts.push(pr); } else if (ImGui::Selectable("Add new Rust script")) { pr.configure( "Create a new rust script", "Pick a name for your rust script", "Create", true, [this](std::string name) { if (name.size() < 5) { PrototypeErrorDialog errDialog = {}; errDialog.configure("Error", "Name is too short.\n5 < RustScriptNameLength < 30", true, true); _errorDialogs.push(std::move(errDialog)); return false; } if (name.size() >= 30) { PrototypeErrorDialog errDialog = {}; errDialog.configure("Error", "Name is too long.\n5 < RustScriptNameLength < 30", true, true); _errorDialogs.push(std::move(errDialog)); return false; } if (std::find_if(name.begin(), name.end(), [](char a) { return !isalpha(a); }) != name.end()) { PrototypeErrorDialog errDialog = {}; errDialog.configure( "Error", "Name must contain only alphabetic characters.\na .. z, A .. Z", true, true); _errorDialogs.push(std::move(errDialog)); return false; } if (PrototypeIo::checkIfPluginProjectExists(name.c_str())) { PrototypeErrorDialog errDialog = {}; errDialog.configure("Error", "There's already C++/Rust script with that name.\nTry picking another name.", true, true); _errorDialogs.push(std::move(errDialog)); return false; } PrototypeIo::createNewRustPluginProject(name.c_str()); return true; }, []() { return true; }); _prompts.push(pr); } ImGui::EndPopup(); } static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("##scripts table", 1, flags)) { for (const auto& pair : PrototypeEngineInternalApplication::database->pluginInstances) { size_t matchIndex = pair.second->name().find(scriptsSearchBuff); if (matchIndex != std::string::npos) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::Text("%s", pair.second->name().substr(0, matchIndex).c_str()); if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { ImGui::SetDragDropPayload("_SCRIPT", &pair.second, sizeof(PrototypePluginInstance*)); ImGui::Text("%s", pair.second->name().c_str()); ImGui::EndDragDropSource(); } ImGui::SameLine(0.0f, 0.0f); ImGui::TextColored(ImVec4(PROTOTYPE_BLUE, 1.0f), "%s", pair.second->name().substr(matchIndex, strlen(scriptsSearchBuff)).c_str()); if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { ImGui::SetDragDropPayload("_SCRIPT", &pair.second, sizeof(PrototypePluginInstance*)); ImGui::Text("%s", pair.second->name().c_str()); ImGui::EndDragDropSource(); } ImGui::SameLine(0.0f, 0.0f); ImGui::Text("%s", pair.second->name().substr(matchIndex + strlen(scriptsSearchBuff)).c_str()); if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { ImGui::SetDragDropPayload("_SCRIPT", &pair.second, sizeof(PrototypePluginInstance*)); ImGui::Text("%s", pair.second->name().c_str()); ImGui::EndDragDropSource(); } } } ImGui::EndTable(); } } else { _openViewsMask &= ~PrototypeUiViewMaskScripts; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Blueprints", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskBlueprints; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } } else { _openViewsMask &= ~PrototypeUiViewMaskBlueprints; } ImGui::End(); } ImGui::PopStyleVar(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, WindowPadding4); { if (ImGui::Begin("Colliders", (bool*)0, windowFlags)) { _openViewsMask |= PrototypeUiViewMaskColliders; { ImGuiDockNode* dockNode = ImGui::GetWindowDockNode(); if (dockNode) dockNode->LocalFlags |= ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton; } float posx = ImGui::GetContentRegionAvailWidth(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); if (ImGui::InputTextWithHint("##colliders search input text", ICON_FA_FILTER " Filter colliders ...", _recordedInstructions.collidersSearchBuff, sizeof(_recordedInstructions.collidersSearchBuff))) { scheduleRecordPass(PrototypeUiViewMaskColliders); } ImGui::TextColored(ImVec4(PROTOTYPE_GREEN, 1.0f), "%zu items", _recordedInstructions.colliders.size()); static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("##colliders table", 1, flags)) { ImGuiListClipper clipper; clipper.Begin(_recordedInstructions.colliders.size()); while (clipper.Step()) { for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) { ImGui::TableNextRow(); ImGui::TableNextColumn(); auto colliderPair = _recordedInstructions.colliders[row]; ImGui::Text("%s%s", colliderPair.first.c_str(), colliderPair.second.c_str()); if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { _clipboard.type[0] = "_COLLIDER"; _clipboard.data[0] = colliderPair.first.append(colliderPair.second); ImGui::SetDragDropPayload("_COLLIDER", &_clipboard, sizeof(PrototypeClipboard)); ImGui::Text("%s", _clipboard.data[0].c_str()); ImGui::EndDragDropSource(); } } } ImGui::EndTable(); } } else { _openViewsMask &= ~PrototypeUiViewMaskColliders; } ImGui::End(); } ImGui::PopStyleVar(); // draw forms { if (!_materialforms.empty()) { ImGuiWindowFlags promptWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoMove; ImVec2 window_pos = ImVec2(ImGui::GetIO().DisplaySize.x / 2, ImGui::GetIO().DisplaySize.y / 2); ImVec2 window_pos_pivot = ImVec2(0.5f, 0.5f); ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); auto resolution = PrototypeEngineInternalApplication::window->resolution(); ImGui::SetNextWindowSize(ImVec2(resolution.x / 3, 300), ImGuiCond_FirstUseEver); ImGui::SetNextWindowBgAlpha(1.0f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(PROTOTYPE_DARKGRAY, 1.0f)); if (ImGui::Begin("Add new material", (bool*)0, promptWindowFlags)) { PrototypeUiMaterialForm& form = _materialforms.top(); if (form.content()(form)) { _materialforms.pop(); } ImGui::End(); } ImGui::PopStyleColor(); } } // draw prompts { if (_errorDialogs.empty()) { if (!_prompts.empty()) { ImGuiWindowFlags promptWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoMove; ImVec2 window_pos = ImVec2(ImGui::GetIO().DisplaySize.x / 2, ImGui::GetIO().DisplaySize.y / 2); ImVec2 window_pos_pivot = ImVec2(0.5f, 0.5f); ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); auto resolution = PrototypeEngineInternalApplication::window->resolution(); ImGui::SetNextWindowSize(ImVec2(resolution.x / 3, 200), ImGuiCond_FirstUseEver); ImGui::SetNextWindowBgAlpha(1.0f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(PROTOTYPE_DARKGRAY, 1.0f)); if (ImGui::Begin(_prompts.top().title().c_str(), (bool*)0, promptWindowFlags)) { ImGui::Text("%s", _prompts.top().text().c_str()); static char buffer[32]; static char label[256]; sprintf(label, "##%zu%s", _prompts.size(), _prompts.top().title().c_str()); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(PROTOTYPE_LIGHTGRAY, 1.0f)); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth()); ImGui::InputText(label, buffer, sizeof(buffer)); ImGui::PopStyleColor(); if (ImGui::Button(_prompts.top().buttonText().c_str())) { if (_prompts.top().onSuccess()(std::string(buffer))) { _prompts.pop(); } } if (ImGui::Button("cancel")) { _prompts.pop(); } ImGui::End(); } ImGui::PopStyleColor(); } } } // draw shader erros { if (!_errorDialogs.empty()) { ImGuiWindowFlags errorWindowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoMove; ImVec2 window_pos = ImVec2(ImGui::GetIO().DisplaySize.x / 2, ImGui::GetIO().DisplaySize.y / 2); ImVec2 window_pos_pivot = ImVec2(0.5f, 0.5f); ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); ImGui::SetNextWindowBgAlpha(1.0f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(PROTOTYPE_DARKGRAY, 1.0f)); if (ImGui::Begin(_errorDialogs.top().title().c_str(), (bool*)0, errorWindowFlags)) { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImVec2 avail = ImGui::GetContentRegionAvail(); ImVec2 inputTextSize = _errorDialogs.top().canCancel() ? ImVec2(avail.x, avail.y - 60.0f) : avail; ImGui::InputTextMultiline("##draw shader error input text", (char*)_errorDialogs.top().text().c_str(), _errorDialogs.top().text().size(), inputTextSize, ImGuiInputTextFlags_Multiline | ImGuiInputTextFlags_ReadOnly); ImGui::PopItemFlag(); if (_errorDialogs.top().canCancel()) { if (ImGui::Button("cancel", ImGui::GetContentRegionAvail())) { _errorDialogs.pop(); } } ImGui::End(); } ImGui::PopStyleColor(); } } return state; } void PrototypeOpenglUI::endFrame() { ImGui::EndFrame(); } void PrototypeOpenglUI::update() { _sceneView.onUpdate(); } void PrototypeOpenglUI::render(i32 x, i32 y, i32 width, i32 height) { ImGui::Render(); glViewport(x, y, width, height); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); // ImGuiIO& io = ImGui::GetIO(); // if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { // GLFWwindow* backup_current_context = glfwGetCurrentContext(); // ImGui::UpdatePlatformWindows(); // ImGui::RenderPlatformWindowsDefault(); // glfwMakeContextCurrent(backup_current_context); // } } void PrototypeOpenglUI::pushErrorDialog(PrototypeErrorDialog errDialog) { _errorDialogs.push(errDialog); } void PrototypeOpenglUI::popErrorDialog() { if (!_errorDialogs.empty()) { _errorDialogs.pop(); } } void PrototypeOpenglUI::signalBuffersChanged(bool status) { _isBuffersChanged = status; } bool PrototypeOpenglUI::isBuffersChanged() { return _isBuffersChanged; } bool PrototypeOpenglUI::needsMouse() { ImGuiIO& io = ImGui::GetIO(); return io.WantCaptureMouse; } bool PrototypeOpenglUI::needsKeyboard() { ImGuiIO& io = ImGui::GetIO(); return io.WantCaptureKeyboard; } PrototypeUiViewMaskType PrototypeOpenglUI::openedViewsMask() { return _openViewsMask; } PrototypeUiView* PrototypeOpenglUI::sceneView() { return &_sceneView; }
55.596468
131
0.500799
[ "mesh", "render", "object", "shape", "vector", "model", "transform", "3d" ]
9a7782c5a9ec1eef5bf7c81ad6c3d552556183ca
11,415
cc
C++
rlclientlib/extensions/onnx/src/tensor_parser.cc
cirvine-MSFT/reinforcement_learning
c006b21d0a027b78d9285bf2597b503669bac82c
[ "MIT" ]
63
2018-10-22T17:11:02.000Z
2021-12-08T17:26:41.000Z
rlclientlib/extensions/onnx/src/tensor_parser.cc
cirvine-MSFT/reinforcement_learning
c006b21d0a027b78d9285bf2597b503669bac82c
[ "MIT" ]
160
2018-10-09T02:34:57.000Z
2022-03-31T15:43:48.000Z
rlclientlib/extensions/onnx/src/tensor_parser.cc
cirvine-MSFT/reinforcement_learning
c006b21d0a027b78d9285bf2597b503669bac82c
[ "MIT" ]
36
2018-10-08T21:44:05.000Z
2022-03-22T16:20:03.000Z
#include "tensor_parser.h" #include <algorithm> #include <sstream> namespace reinforcement_learning { namespace onnx { namespace tensor_parser { enum CONSUME_TYPE : bool { EXCLUSIVE = false, INCLUSIVE = true }; enum KNOWN_CHARS : char { END = '\0', DOUBLE_QUOTE = '\"', SEMICOLON = ';', COMMA = ',', OPEN_BRACE = '{', CLOSE_BRACE = '}', BACKSLASH = '\\', COLON = ':' }; namespace errors { struct error_context { private: const std::string _prefix; std::vector<std::string>& _errors; tensor_parser::parser_context& _parser_context; public: inline error_context(std::vector<std::string>& target, const std::string& prefix, tensor_parser::parser_context& parser_context) : _errors(target), _prefix(prefix), _parser_context(parser_context) { } inline error_context with_prefix(const std::string& prefix) { return error_context(_errors, prefix, _parser_context); } inline bool append_error(const std::string& detail) { std::stringstream error_builder; error_builder << "Parse failure at position " << _parser_context.position(); if (_prefix.size() > 0) { error_builder << " " << _prefix; } error_builder << ": " << detail; _errors.push_back(error_builder.str()); // This is intended to be used as an || append during the consume/consume_exact API pattern return false; } }; } namespace primitives { struct none {}; template <typename parse_context_t, const char ch> struct check_exact { static const char _ch = ch; inline static bool invoke(const char c, parse_context_t&) { return invoke(c); } inline static bool invoke(const char c) { return (ch == c); } }; template <typename parse_context_t, const char ch> using until = check_exact<parse_context_t, ch>; template <typename parse_context_t, bool returns = true> struct no_op { inline static bool invoke(const char, parse_context_t&) { return returns; } inline static bool end(parse_context_t&) { return returns; } }; template <typename parse_context_t> struct routing_action { inline static bool invoke(const char c, parse_context_t& context) { return context.invoke(c); } inline static bool end(parse_context_t& context) { return context.end(); } }; template <typename parse_context_t, typename until_t, typename action_t = no_op<parse_context_t, true>> struct parse_frame { inline static bool until(parse_context_t& context, const char c) { return until_t::invoke(c, context); } inline static bool action(parse_context_t& context, const char c) { return action_t::invoke(c, context); } inline static bool end(parse_context_t& context) { return action_t::end(context); } }; template <bool inclusive, typename parse_frame_t, typename parse_context_t> inline bool consume(const char*& reading_head, parse_context_t& context) { while (reading_head != nullptr && *reading_head != END) { const char& curr_c = *reading_head; if (parse_frame_t::until(context, curr_c)) { if (inclusive) reading_head++; return parse_frame_t::end(context); } if (!parse_frame_t::action(context, curr_c)) { return false; } reading_head++; } return false; } template <char ch> inline static bool consume_exact(const char*& reading_head) { if (reading_head == nullptr || *reading_head != ch) { return false; } reading_head++; return true; } } namespace base64 { struct parse_context { private: size_t _count; uint32_t _running; size_t _padding_count; std::vector<uint8_t>& _bytes; errors::error_context& _error_context; public: inline parse_context(std::vector<uint8_t>& target, errors::error_context& errors_target) : _bytes(target), _error_context(errors_target), _count(0), _running(0), _padding_count(0) { } inline bool invoke(const char c) { _running = _running << 6; _count++; if (_padding_count || c == '=') { _padding_count++; } else if (!_padding_count) { if (c >= 'A' /* 65 */ && c <= 'Z' /* 90 */) { _running = _running | (c - 'A' + 0); // 0 - 25 } else if (c >= 'a' /* 97 */ && c <= 'z' /* 122 */) { _running = _running | (c - 'a' + 26); // 26 - 51 } else if (c >= '0' /* 48 */ && c <= '9' /* 57 */) { _running = _running | (c - '0' + 52); // 52 - 61 } else if (c == '+') { _running = _running | 62; } else if (c == '/') { _running = _running | 63; } else { // TODO: Bad character std::stringstream error_detail_builder; error_detail_builder << "Invalid base64 character: '" << c << "'."; return _error_context.append_error(std::string(error_detail_builder.str())); } if (_count % 4 == 0) { _bytes.push_back((_running >> 16) & 0xFF); _bytes.push_back((_running >> 8) & 0xFF); _bytes.push_back(_running & 0xFF); _running = 0; } } return true; } inline bool end() { if (_count % 4 != 0) { std::stringstream error_detail_builder; error_detail_builder << "Invalid number of base64 characters: '" << _count << "'."; return _error_context.append_error(std::string(error_detail_builder.str())); } switch (_padding_count) { case 0: break; case 1: _bytes.push_back((_running >> 16) & 0xFF); _bytes.push_back((_running >> 8) & 0xFF); break; case 2: _bytes.push_back((_running >> 16) & 0xFF); break; default: std::stringstream error_detail_builder; error_detail_builder << "Invalid number of base64 padding characters: '" << _padding_count << "'."; return _error_context.append_error(std::string(error_detail_builder.str())); } return true; } }; using parse_action = primitives::routing_action<parse_context>; template <typename until_t> using frame = primitives::parse_frame<parse_context, until_t, parse_action>; template <char ch> using until = primitives::until<parse_context, ch>; template <bool inclusive, typename until_t> inline bool consume(const char*& c, parse_context& context) { return primitives::consume<inclusive, frame<until_t>, parse_context>(c, context); } } template <char escape> class escaped_string { public: struct parse_context { bool _in_escape; std::string& _value; public: parse_context(std::string& target) : _value(target), _in_escape(false) { } inline bool invoke(const char c) { if (c != escape || _in_escape) { _value.push_back(c); _in_escape = false; } else if (c == escape) { _in_escape = true; } return true; } inline bool end() { return true; } }; using parse_action = primitives::routing_action<parse_context>; template <typename until_t> using frame = primitives::parse_frame<parse_context, until_t, parse_action>; template <char ch> using until = primitives::until<parse_context, ch>; template <bool inclusive, typename until_t> static inline bool consume(const char*& c, parse_context& context) { return primitives::consume<inclusive, frame<until_t>, parse_context>(c, context); } }; using primitives::consume_exact; using primitives::consume; using primitives::until; using escaped = escaped_string<BACKSLASH>; bool parse_tensor_value(const char*& reading_head, std::vector<byte_t>& dims, std::vector<byte_t>& data, errors::error_context& error_target) { errors::error_context error_context = error_target.with_prefix("while parsing tensor value"); auto dims_context = base64::parse_context(dims, error_context); auto data_context = base64::parse_context(data, error_context); // " <base64 dimensions> ; <base64 data> " return consume_exact<DOUBLE_QUOTE>(reading_head) && base64::consume<INCLUSIVE, base64::until<SEMICOLON>>(reading_head, dims_context) && base64::consume<INCLUSIVE, base64::until<DOUBLE_QUOTE>>(reading_head, data_context); } bool parse_tensor_name_value(const char*& reading_head, std::string& name, bytes_t& shape_bytes, bytes_t& value_bytes, errors::error_context& error_target) { auto name_context = escaped::parse_context(name); // " <escaped_name> " : <tensor_value> return consume_exact<DOUBLE_QUOTE>(reading_head) && (escaped::consume<INCLUSIVE, escaped::until<DOUBLE_QUOTE>>(reading_head, name_context) || // on error: error_target.with_prefix("while parsing tensor name").append_error("Expected '\"'.")) && consume_exact<COLON>(reading_head) && parse_tensor_value(reading_head, shape_bytes, value_bytes, error_target); } bool parse(parser_context& context) { // PERF: Can the branchiness here be made nicer through computed jumps? if (context._parsed) { return false; } // Treat empty lines as empty examples, similar to VW if (context.line().empty()) { return true; } const char*& reading_head = context._reading_head; // '{' <tensor_name_value> [ ',' <tensor_name_value> ]* if (!consume_exact<OPEN_BRACE>(reading_head)) { return false; } // Empty objects are valid, empty examples (match VWJSON parser behaviour) if (consume_exact<CLOSE_BRACE>(reading_head)) { return true; } errors::error_context error_context(context._errors, "while parsing tensor notation", context); do { std::string name; bytes_t tensor_shape_bytes; bytes_t tensor_data_bytes; if (!parse_tensor_name_value(reading_head, name, tensor_shape_bytes, tensor_data_bytes, error_context)) { return false; } context._input_builder.push_input( std::move(name), std::move(std::make_pair(tensor_shape_bytes, tensor_data_bytes))); } while (consume_exact<COMMA>(reading_head)); // consume's API is to move reading_head until after success or before first failure. // in the case of consume_exact, it can be used to switch based on whether the // character at the reading_head is what is expected, or no. return consume_exact<CLOSE_BRACE>(reading_head) || // the OR condition here only runs on error error_context.append_error("Expected '}'."); } } }}
27.841463
185
0.597898
[ "vector" ]
9a7845ae8e6570f1a25f61cac687beafe6b1f9c9
3,316
cpp
C++
lib/winss/sha256.cpp
taylorb-microsoft/winss
ede93f84a5d9585502db5190f2ec6365858f695a
[ "Apache-2.0" ]
52
2017-01-05T23:39:38.000Z
2020-06-04T03:00:11.000Z
lib/winss/sha256.cpp
morganstanley/winss
ede93f84a5d9585502db5190f2ec6365858f695a
[ "Apache-2.0" ]
24
2017-01-05T05:07:34.000Z
2018-03-09T00:50:58.000Z
lib/winss/sha256.cpp
morganstanley/winss
ede93f84a5d9585502db5190f2ec6365858f695a
[ "Apache-2.0" ]
7
2016-12-27T20:55:20.000Z
2018-03-09T00:32:19.000Z
/* * Copyright 2016-2017 Morgan Stanley * * 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 "sha256.hpp" #include <windows.h> #include <wincrypt.h> #include <vector> #include "winss/windows_interface.hpp" #include "easylogging/easylogging++.hpp" class ScopedHCRYPTPROV { private: HCRYPTPROV provider = NULL; public: ScopedHCRYPTPROV() { std::memset(&provider, 0, sizeof(HCRYPTPROV)); } HCRYPTPROV Get() { return provider; } HCRYPTPROV* Receive() { return &provider; } ~ScopedHCRYPTPROV() { if (provider) { WINDOWS.CryptReleaseContext(provider, 0); } } }; class ScopedHCRYPTHASH { private: HCRYPTHASH hash; public: ScopedHCRYPTHASH() { std::memset(&hash, 0, sizeof(HCRYPTHASH)); } HCRYPTHASH Get() { return hash; } HCRYPTPROV* Receive() { return &hash; } ~ScopedHCRYPTHASH() { if (hash) { WINDOWS.CryptDestroyHash(hash); } } }; std::string winss::SHA256::CalculateDigest(const std::string& value) { ScopedHCRYPTPROV provider; if (!WINDOWS.CryptAcquireContext(provider.Receive(), nullptr, nullptr, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) { VLOG(1) << "CryptAcquireContext failed: " << WINDOWS.GetLastError(); return value; } ScopedHCRYPTHASH hash; if (!WINDOWS.CryptCreateHash(provider.Get(), CALG_SHA_256, 0, 0, hash.Receive())) { VLOG(1) << "CryptCreateHash failed: " << WINDOWS.GetLastError(); return value; } if (!WINDOWS.CryptHashData(hash.Get(), const_cast<unsigned char*>( reinterpret_cast<const unsigned char*>(value.c_str())), static_cast<DWORD>(value.length()), 0)) { VLOG(1) << "CryptHashData failed: " << WINDOWS.GetLastError(); return value; } DWORD hash_len = 0; DWORD buffer_size = sizeof(DWORD); if (!WINDOWS.CryptGetHashParam(hash.Get(), HP_HASHSIZE, reinterpret_cast<unsigned char*>(&hash_len), &buffer_size, 0)) { VLOG(1) << "CryptGetHashParam(HP_HASHSIZE) failed: " << WINDOWS.GetLastError(); return value; } std::vector<unsigned char> buffer(hash_len); if (!WINDOWS.CryptGetHashParam(hash.Get(), HP_HASHVAL, reinterpret_cast<unsigned char*>(&buffer[0]), &hash_len, 0)) { VLOG(1) << "CryptGetHashParam(HP_HASHVAL) failed: " << WINDOWS.GetLastError(); return value; } std::ostringstream oss; std::vector<unsigned char>::const_iterator it; for (it = buffer.begin(); it != buffer.end(); ++it) { oss.fill('0'); oss.width(2); oss << std::hex << static_cast<const int>(*it); } return oss.str(); }
26.741935
76
0.621834
[ "vector" ]
9a89e0bbd079737ad6a6c78fe677cb499108bd88
24,437
cpp
C++
source/games/duke/src/hudweapon_r.cpp
madame-rachelle/Raze
67c8187d620e6cf9e99543cab5c5746dd31007af
[ "RSA-MD" ]
null
null
null
source/games/duke/src/hudweapon_r.cpp
madame-rachelle/Raze
67c8187d620e6cf9e99543cab5c5746dd31007af
[ "RSA-MD" ]
null
null
null
source/games/duke/src/hudweapon_r.cpp
madame-rachelle/Raze
67c8187d620e6cf9e99543cab5c5746dd31007af
[ "RSA-MD" ]
null
null
null
//------------------------------------------------------------------------- /* Copyright (C) 1996, 2003 - 3D Realms Entertainment Copyright (C) 2017-2019 Nuke.YKT Copyright (C) 2020 - Christoph Oelckers This file is part of Duke Nukem 3D version 1.5 - Atomic Edition Duke Nukem 3D is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Original Source: 1996 - Todd Replogle Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms */ //------------------------------------------------------------------------- #include "ns.h" #include "global.h" #include "names_r.h" BEGIN_DUKE_NS //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- inline static void hud_drawpal(double x, double y, int tilenum, int shade, int orientation, int p, int scale = 32768) { hud_drawsprite(x, y, scale, 0, tilenum, shade, p, 2 | orientation); } inline static void rdmyospal(double x, double y, int tilenum, int shade, int orientation, int p) { hud_drawpal(x, y, tilenum, shade, orientation, p, 36700); } inline static void rd2myospal(double x, double y, int tilenum, int shade, int orientation, int p) { hud_drawpal(x, y, tilenum, shade, orientation, p, 44040); } inline static void rd3myospal(double x, double y, int tilenum, int shade, int orientation, int p) { hud_drawpal(x, y, tilenum, shade, orientation, p, 47040); } //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- void displaymasks_r(int snum, double smoothratio) { short p; if (sprite[ps[snum].i].pal == 1) p = 1; else p = sector[ps[snum].cursectnum].floorpal; if (ps[snum].scuba_on) { //int pin = 0; // to get the proper clock value with regards to interpolation we have add a smoothratio based offset to the value. double interpclock = ud.levelclock + (TICSPERFRAME/65536.) * smoothratio; int pin = RS_STRETCH; hud_drawsprite((320 - (tilesiz[SCUBAMASK].x >> 1) - 15), (200 - (tilesiz[SCUBAMASK].y >> 1) + (calcSinTableValue(interpclock) / 1024.)), 49152, 0, SCUBAMASK, 0, p, 2 + 16 + pin); hud_drawsprite((320 - tilesiz[SCUBAMASK + 4].x), (200 - tilesiz[SCUBAMASK + 4].y), 65536, 0, SCUBAMASK + 4, 0, p, 2 + 16 + pin); hud_drawsprite(tilesiz[SCUBAMASK + 4].x, (200 - tilesiz[SCUBAMASK + 4].y), 65536, 0, SCUBAMASK + 4, 0, p, 2 + 4 + 16 + pin); hud_drawsprite(35, (-1), 65536, 0, SCUBAMASK + 3, 0, p, 2 + 16 + pin); hud_drawsprite(285, 200, 65536, 1024, SCUBAMASK + 3, 0, p, 2 + 16 + pin); } } //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- void ShowMotorcycle(double x, double y, int tilenum, int shade, int orientation, int p, double a) { hud_drawsprite(x, y, 34816, a, tilenum, shade, p, 2 | orientation); } void ShowBoat(double x, double y, int tilenum, int shade, int orientation, int p, double a) { hud_drawsprite(x, y, 66048, a, tilenum, shade, p, 2 | orientation); } //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- void displayweapon_r(int snum, double smoothratio) { int cw; int i, j; double weapon_sway, weapon_xoffset, gun_pos, looking_arc, look_anghalf, TiltStatus; char o,pal; signed char gs; auto p = &ps[snum]; auto kb = &p->kickback_pic; o = 0; look_anghalf = getHalfLookAng(p->oq16look_ang, p->q16look_ang, cl_syncinput, smoothratio); looking_arc = fabs(look_anghalf) / 4.5; weapon_sway = p->oweapon_sway + fmulscale16((p->weapon_sway - p->oweapon_sway), smoothratio); TiltStatus = !cl_syncinput ? p->TiltStatus : p->oTiltStatus + fmulscale16((p->TiltStatus - p->oTiltStatus), smoothratio); if (shadedsector[p->cursectnum] == 1) gs = 16; else gs = sprite[p->i].shade; if(gs > 24) gs = 24; if(p->newowner >= 0 || ud.camerasprite >= 0 || (sprite[p->i].pal != 1 && sprite[p->i].extra <= 0)) return; int opos = p->oweapon_pos * p->oweapon_pos; int npos = p->weapon_pos * p->weapon_pos; gun_pos = 80 - (opos + fmulscale16(npos - opos, smoothratio)); weapon_xoffset = (160)-90; weapon_xoffset -= calcSinTableValue((weapon_sway / 2.) + 512) / (1024. + 512.); weapon_xoffset -= 58 + p->weapon_ang; if( sprite[p->i].xrepeat < 8 ) gun_pos -= fabs(calcSinTableValue(weapon_sway * 4.) / 512.); else gun_pos -= fabs(calcSinTableValue(weapon_sway / 2.) / 1024.); gun_pos -= (p->ohard_landing + fmulscale16(p->hard_landing - p->ohard_landing, smoothratio)) * 8.; if(p->last_weapon >= 0) cw = p->last_weapon; else cw = p->curr_weapon; j = 14-p->quick_kick; if(j != 14) { if(sprite[p->i].pal == 1) pal = 1; else pal = p->palookup; } if (p->OnMotorcycle) { int temp_kb; if (numplayers == 1) { if (*kb) { gs = 0; if (*kb == 1) { if ((krand()&1) == 1) temp_kb = MOTOHIT+1; else temp_kb = MOTOHIT+2; } else if (*kb == 4) { if ((krand()&1) == 1) temp_kb = MOTOHIT+3; else temp_kb = MOTOHIT+4; } else temp_kb = MOTOHIT; } else temp_kb = MOTOHIT; } else { if (*kb) { gs = 0; if (*kb == 1) temp_kb = MOTOHIT+1; else if (*kb == 2) temp_kb = MOTOHIT+2; else if (*kb == 3) temp_kb = MOTOHIT+3; else if (*kb == 4) temp_kb = MOTOHIT+4; else temp_kb = MOTOHIT; } else temp_kb = MOTOHIT; } if (sprite[p->i].pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; if (TiltStatus >= 0) ShowMotorcycle(160-look_anghalf, 174, temp_kb, gs, 0, pal, TiltStatus*5); else if (p->TiltStatus < 0) ShowMotorcycle(160-look_anghalf, 174, temp_kb, gs, 0, pal, TiltStatus*5+2047); return; } if (p->OnBoat) { int temp2, temp_kb, temp3; temp2 = 0; if (TiltStatus > 0) { if (*kb == 0) temp_kb = BOATHIT+1; else if (*kb <= 3) { temp_kb = BOATHIT+5; temp2 = 1; } else if (*kb <= 6) { temp_kb = BOATHIT+6; temp2 = 1; } else temp_kb = BOATHIT+1; } else if (TiltStatus < 0) { if (*kb == 0) temp_kb = BOATHIT+2; else if (*kb <= 3) { temp_kb = BOATHIT+7; temp2 = 1; } else if (*kb <= 6) { temp_kb = BOATHIT+8; temp2 = 1; } else temp_kb = BOATHIT+2; } else { if (*kb == 0) temp_kb = BOATHIT; else if (*kb <= 3) { temp_kb = BOATHIT+3; temp2 = 1; } else if (*kb <= 6) { temp_kb = BOATHIT+4; temp2 = 1; } else temp_kb = BOATHIT; } if (sprite[p->i].pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; if (p->NotOnWater) temp3 = 170; else temp3 = 170 + (*kb>>2); if (temp2) gs = -96; if (TiltStatus >= 0) ShowBoat(160-look_anghalf, temp3, temp_kb, gs, 0, pal, TiltStatus); else if (p->TiltStatus < 0) ShowBoat(160-look_anghalf, temp3, temp_kb, gs, 0, pal, TiltStatus+2047); return; } if( sprite[p->i].xrepeat < 8 ) { static int fistsign; if(p->jetpack_on == 0 ) { i = sprite[p->i].xvel; looking_arc += 32-(i>>1); fistsign += i>>1; } cw = weapon_xoffset; weapon_xoffset += calcSinTableValue(fistsign) / 1024.; hud_draw(weapon_xoffset+250-look_anghalf, looking_arc+258-abs(calcSinTableValue(fistsign) / 256.), FIST,gs,o); weapon_xoffset = cw; weapon_xoffset -= calcSinTableValue(fistsign) / 1024.; hud_draw(weapon_xoffset+40-look_anghalf, looking_arc+200+abs(calcSinTableValue(fistsign) / 256.), FIST,gs,o|4); } else { int pin = 0; if (sprite[p->i].pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displaycrowbar = [&] { static const short kb_frames[] = { 0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7 }; static const short kb_ox[] = { 310,342,364,418,350,316,282,288,0,0 }; static const short kb_oy[] = { 300,362,320,268,248,248,277,420,0,0 }; double x; short y; x = weapon_xoffset + ((kb_ox[kb_frames[*kb]] >> 1) - 12); y = 200 - (244 - kb_oy[kb_frames[*kb]]); hud_drawpal(x - look_anghalf, looking_arc + y - gun_pos, KNEE + kb_frames[*kb], gs, 0, pal); }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displayslingblade = [&] { static const short kb_frames[] = { 0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7 }; static const short kb_ox[] = { 580,676,310,491,356,210,310,614 }; static const short kb_oy[] = { 369,363,300,323,371,400,300,440 }; double x; short y; x = weapon_xoffset + ((kb_ox[kb_frames[*kb]] >> 1) - 12); y = 210 - (244 - kb_oy[kb_frames[*kb]]); hud_drawpal(x - look_anghalf + 20, looking_arc + y - gun_pos - 80, SLINGBLADE + kb_frames[*kb], gs, 0, pal); }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displaybowlingball = [&] { weapon_xoffset += 8; gun_pos -= 10; if (p->ammo_amount[BOWLING_WEAPON]) { hud_drawpal(weapon_xoffset + 162 - look_anghalf, looking_arc + 214 - gun_pos + (*kb << 3), BOWLINGBALLH, gs, o, pal); } else { rdmyospal(weapon_xoffset + 162 - look_anghalf, looking_arc + 214 - gun_pos, HANDTHROW + 5, gs, o, pal); } }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displaypowderkeg = [&] { weapon_xoffset += 8; gun_pos -= 10; if (p->ammo_amount[POWDERKEG_WEAPON]) { rdmyospal(weapon_xoffset + 180 - look_anghalf, looking_arc + 214 - gun_pos + (*kb << 3), POWDERH, gs, o, pal); rdmyospal(weapon_xoffset + 90 - look_anghalf, looking_arc + 214 - gun_pos + (*kb << 3), POWDERH, gs, o | 4, pal); } else { rdmyospal(weapon_xoffset + 162 - look_anghalf, looking_arc + 214 - gun_pos, HANDTHROW + 5, gs, o, pal); } }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displaycrossbow = [&] { //if (!(duke3d_globalflags & DUKE3D_NO_WIDESCREEN_PINNING)) pin = RS_ALIGN_R; static const uint8_t kb_frames[] = { 0,1,1,2,2,3,2,3,2,3,2,2,2,2,2,2,2,2,2,4,4,4,4,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7 }; if (kb_frames[*kb] == 2 || kb_frames[*kb] == 3) { rdmyospal((weapon_xoffset + 200) - look_anghalf, looking_arc + 250 - gun_pos, RPGGUN + kb_frames[*kb], gs, o | pin, pal); } else if (kb_frames[*kb] == 1) { rdmyospal((weapon_xoffset + 200) - look_anghalf, looking_arc + 250 - gun_pos, RPGGUN + kb_frames[*kb], 0, o | pin, pal); } else { rdmyospal((weapon_xoffset + 210) - look_anghalf, looking_arc + 255 - gun_pos, RPGGUN + kb_frames[*kb], gs, o | pin, pal); } }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displaychicken = [&] { //if (!(duke3d_globalflags & DUKE3D_NO_WIDESCREEN_PINNING)) pin = RS_ALIGN_R; if (*kb) { static const uint8_t kb_frames[] = { 0,1,1,2,2,3,2,3,2,3,2,2,2,2,2,2,2,2,2,4,4,4,4,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7 }; if (kb_frames[*kb] == 2 || kb_frames[*kb] == 3) { rdmyospal((weapon_xoffset + 200) - look_anghalf, looking_arc + 250 - gun_pos, RPGGUN2 + kb_frames[*kb], gs, o | pin, pal); } else if (kb_frames[*kb] == 1) { rdmyospal((weapon_xoffset + 200) - look_anghalf, looking_arc + 250 - gun_pos, RPGGUN2 + kb_frames[*kb], 0, o | pin, pal); } else { rdmyospal((weapon_xoffset + 210) - look_anghalf, looking_arc + 255 - gun_pos, RPGGUN2 + kb_frames[*kb], gs, o | pin, pal); } } else { if (ud.multimode < 2) { if (chickenphase) { rdmyospal((weapon_xoffset + 210) - look_anghalf, looking_arc + 222 - gun_pos, RPGGUN2 + 7, gs, o | pin, pal); } else if ((krand() & 15) == 5) { S_PlayActorSound(327, p->i); rdmyospal((weapon_xoffset + 210) - look_anghalf, looking_arc + 222 - gun_pos, RPGGUN2 + 7, gs, o | pin, pal); chickenphase = 6; } else { rdmyospal((weapon_xoffset + 210) - look_anghalf, looking_arc + 225 - gun_pos, RPGGUN2, gs, o | pin, pal); } } else { rdmyospal((weapon_xoffset + 210) - look_anghalf, looking_arc + 225 - gun_pos, RPGGUN2, gs, o | pin, pal); } } }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displayshotgun = [&] { weapon_xoffset -= 8; if (sprite[p->i].pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; { double x; short y; static const short kb_frames3[] = { 0,0,1,1,2,2,5,5,6,6,7,7,8,8,0,0,0,0,0,0,0 }; static const short kb_frames2[] = { 0,0,3,3,4,4,5,5,6,6,7,7,8,8,0,0,20,20,21,21,21,21,20,20,20,20,0,0 }; static const short kb_frames[] = { 0,0,1,1,2,2,3,3,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,0,0,20,20,21,21,21,21,20,20,20,20,0,0 }; static const short kb_ox[] = { 300,300,300,300,300,330,320,310,305,306,302 }; static const short kb_oy[] = { 315,300,302,305,302,302,303,306,302,404,384 }; short tm; tm = 180; if (p->shotgun_state[1]) { if ((*kb) < 26) { if (kb_frames[*kb] == 3 || kb_frames[*kb] == 4) gs = 0; x = weapon_xoffset + ((kb_ox[kb_frames[*kb]] >> 1) - 12); y = tm - (244 - kb_oy[kb_frames[*kb]]); hud_drawpal(x + 64 - look_anghalf, y + looking_arc - gun_pos, SHOTGUN + kb_frames[*kb], gs, 0, pal); } else { if (kb_frames[*kb] > 0) { x = weapon_xoffset + ((kb_ox[kb_frames[(*kb) - 11]] >> 1) - 12); y = tm - (244 - kb_oy[kb_frames[(*kb) - 11]]); } else { x = weapon_xoffset + ((kb_ox[kb_frames[*kb]] >> 1) - 12); y = tm - (244 - kb_oy[kb_frames[*kb]]); } switch (*kb) { case 23: y += 60; break; case 24: y += 30; break; } hud_drawpal(x + 64 - look_anghalf, y + looking_arc - gun_pos, SHOTGUN + kb_frames[*kb], gs, 0, pal); if (kb_frames[*kb] == 21) hud_drawpal(x + 96 - look_anghalf, y + looking_arc - gun_pos, SHOTGUNSHELLS, gs, 0, pal); } } else { if ((*kb) < 16) { if (p->shotgun_state[0]) { if (kb_frames2[*kb] == 3 || kb_frames2[*kb] == 4) gs = 0; x = weapon_xoffset + ((kb_ox[kb_frames2[*kb]] >> 1) - 12); y = tm - (244 - kb_oy[kb_frames2[*kb]]); hud_drawpal(x + 64 - look_anghalf, y + looking_arc - gun_pos, SHOTGUN + kb_frames2[*kb], gs, 0, pal); } else { if (kb_frames3[*kb] == 1 || kb_frames3[*kb] == 2) gs = 0; x = weapon_xoffset + ((kb_ox[kb_frames3[*kb]] >> 1) - 12); y = tm - (244 - kb_oy[kb_frames3[*kb]]); hud_drawpal(x + 64 - look_anghalf, y + looking_arc - gun_pos, SHOTGUN + kb_frames3[*kb], gs, 0, pal); } } else if (p->shotgun_state[0]) { if (kb_frames2[*kb] > 0) { x = weapon_xoffset + ((kb_ox[kb_frames2[(*kb) - 11]] >> 1) - 12); y = tm - (244 - kb_oy[kb_frames2[(*kb) - 11]]); } else { x = weapon_xoffset + ((kb_ox[kb_frames2[*kb]] >> 1) - 12); y = tm - (244 - kb_oy[kb_frames2[*kb]]); } switch (*kb) { case 23: y += 60; break; case 24: y += 30; break; } hud_drawpal(x + 64 - look_anghalf, y + looking_arc - gun_pos, SHOTGUN + kb_frames2[*kb], gs, 0, pal); if (kb_frames2[*kb] == 21) hud_drawpal(x + 96 - look_anghalf, y + looking_arc - gun_pos, SHOTGUNSHELLS, gs, 0, pal); } } } }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displayrifle = [&] { if (*kb > 0) gun_pos -= calcSinTableValue((*kb) << 7) / 4096.; if (*kb > 0 && sprite[p->i].pal != 1) weapon_xoffset += 1 - (rand() & 3); switch (*kb) { case 0: hud_drawpal(weapon_xoffset + 178 - look_anghalf + 30, looking_arc + 233 - gun_pos + 5, CHAINGUN, gs, o, pal); break; default: gs = 0; if (*kb < 8) { i = rand() & 7; hud_drawpal(weapon_xoffset + 178 - look_anghalf + 30, looking_arc + 233 - gun_pos + 5, CHAINGUN + 1, gs, o, pal); } else hud_drawpal(weapon_xoffset + 178 - look_anghalf + 30, looking_arc + 233 - gun_pos + 5, CHAINGUN + 2, gs, o, pal); break; } }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displaypistol = [&] { if ((*kb) < 22) { static const uint8_t kb_frames[] = { 0,0,1,1,2,2,3,3,4,4,6,6,6,6,5,5,4,4,3,3,0,0 }; static const short kb_ox[] = { 194,190,185,208,215,215,216,216,201,170 }; static const short kb_oy[] = { 256,249,248,238,228,218,208,256,245,258 }; double x; short y; x = weapon_xoffset + (kb_ox[kb_frames[*kb]] - 12); y = 244 - (244 - kb_oy[kb_frames[*kb]]); if (kb_frames[*kb]) gs = 0; rdmyospal(x - look_anghalf, y + looking_arc - gun_pos, FIRSTGUN + kb_frames[*kb], gs, 0, pal); } else { static const short kb_frames[] = { 0,0,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,0,0 }; static const short kb_ox[] = { 244,244,244 }; static const short kb_oy[] = { 256,249,248 }; double x; short dx; short y; short dy; x = weapon_xoffset + (kb_ox[kb_frames[(*kb) - 22]] - 12); y = 244 - (244 - kb_oy[kb_frames[(*kb) - 22]]); switch (*kb) { case 28: dy = 10; dx = 5; break; case 29: dy = 20; dx = 10; break; case 30: dy = 30; dx = 15; break; case 31: dy = 40; dx = 20; break; case 32: dy = 50; dx = 25; break; case 33: dy = 40; dx = 20; break; case 34: dy = 30; dx = 15; break; case 35: dy = 20; dx = 10; break; case 36: dy = 10; dx = 5; break; default: dy = 0; dx = 0; break; } rdmyospal(x - look_anghalf - dx, y + looking_arc - gun_pos + dy, FIRSTGUNRELOAD + kb_frames[(*kb) - 22], gs, 0, pal); } }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displaydynamite = [&] { gun_pos -= 9 * (*kb); rdmyospal(weapon_xoffset + 190 - look_anghalf, looking_arc + 260 - gun_pos, HANDTHROW, gs, o, pal); }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displaythrowingdynamite = [&] { int dx; int x; int dy; dx = 25; x = 100; dy = 20; if ((*kb) < 20) { //if (!(duke3d_globalflags & DUKE3D_NO_WIDESCREEN_PINNING)) pin = RS_ALIGN_R; static const int8_t remote_frames[] = { 1,1,1,1,1,2,2,2,2,3,3,3,4,4,4,5,5,5,5,5,6,6,6 }; if (*kb) { if ((*kb) < 5) { rdmyospal(weapon_xoffset + x + 190 - look_anghalf - dx, looking_arc + 258 - gun_pos - 64 + p->detonate_count - dy, RRTILE1752, 0, o | pin, pal); } rdmyospal(weapon_xoffset + x + 190 - look_anghalf, looking_arc + 258 - gun_pos - dy, HANDTHROW + remote_frames[*kb], gs, o | pin, pal); } else { if ((*kb) < 5) { rdmyospal(weapon_xoffset + x + 190 - look_anghalf - dx, looking_arc + 258 - gun_pos - 64 + p->detonate_count - dy, RRTILE1752, 0, o | pin, pal); } rdmyospal(weapon_xoffset + x + 190 - look_anghalf, looking_arc + 258 - gun_pos - dy, HANDTHROW + 1, gs, o | pin, pal); } } }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displaytits = [&] { if (*kb) { gs = 0; rd3myospal(150 + (weapon_xoffset / 2.) - look_anghalf, 266 + (looking_arc / 2.) - gun_pos, DEVISTATOR, gs, o, pal); } else rd3myospal(150 + (weapon_xoffset / 2.) - look_anghalf, 266 + (looking_arc / 2.) - gun_pos, DEVISTATOR + 1, gs, o, pal); }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displayblaster = [&] { //if (!(duke3d_globalflags & DUKE3D_NO_WIDESCREEN_PINNING)) pin = RS_ALIGN_R; if ((*kb)) { char cat_frames[] = { 0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; rdmyospal(weapon_xoffset + 260 - look_anghalf, looking_arc + 215 - gun_pos, FREEZE + cat_frames[*kb], -32, o | pin, pal); } else rdmyospal(weapon_xoffset + 260 - look_anghalf, looking_arc + 215 - gun_pos, FREEZE, gs, o | pin, pal); }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- auto displaysaw = [&] { weapon_xoffset += 28; looking_arc += 18; if ((*kb) == 0) { rd2myospal(weapon_xoffset + 188 - look_anghalf, looking_arc + 240 - gun_pos, SHRINKER, gs, o, pal); } else { if (sprite[p->i].pal != 1) { weapon_xoffset += rand() & 3; gun_pos += (rand() & 3); } if (cw == BUZZSAW_WEAPON) { rd2myospal(weapon_xoffset + 184 - look_anghalf, looking_arc + 240 - gun_pos, GROWSPARK + ((*kb) & 2), gs, o, 0); } else { signed char kb_frames[] = { 1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0 }; short frm = kb_frames[*kb]; rd2myospal(weapon_xoffset + 184 - look_anghalf, looking_arc + 240 - gun_pos, SHRINKER + frm, gs, o, 0); } } }; //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- switch (cw) { case KNEE_WEAPON: displaycrowbar(); break; case SLINGBLADE_WEAPON: displayslingblade(); break; case POWDERKEG_WEAPON: displaypowderkeg(); break; case BOWLING_WEAPON: displaybowlingball(); break; case CROSSBOW_WEAPON: displaycrossbow(); break; case CHICKEN_WEAPON: displaychicken(); break; case SHOTGUN_WEAPON: displayshotgun(); break; case RIFLEGUN_WEAPON: displayrifle(); break; case PISTOL_WEAPON: displaypistol(); break; case DYNAMITE_WEAPON: displaydynamite(); break; case THROWINGDYNAMITE_WEAPON: displaythrowingdynamite(); break; case TIT_WEAPON: displaytits(); break; case MOTORCYCLE_WEAPON: case BOAT_WEAPON: break; case ALIENBLASTER_WEAPON: displayblaster(); break; case THROWSAW_WEAPON: case BUZZSAW_WEAPON: displaysaw(); break; } } } END_DUKE_NS
26.163812
180
0.497156
[ "3d" ]
893d5a449a293788717e7654241ed66e9e95519a
724
cc
C++
uva/chapter_5/10673.cc
metaflow/contests
5e9ffcb72c3e7da54b5e0818b1afa59f5778ffa2
[ "MIT" ]
1
2019-05-12T23:41:00.000Z
2019-05-12T23:41:00.000Z
uva/chapter_5/10673.cc
metaflow/contests
5e9ffcb72c3e7da54b5e0818b1afa59f5778ffa2
[ "MIT" ]
null
null
null
uva/chapter_5/10673.cc
metaflow/contests
5e9ffcb72c3e7da54b5e0818b1afa59f5778ffa2
[ "MIT" ]
null
null
null
#include<bits/stdc++.h> using namespace std; using vi = vector<int>; using ii = pair<int,int>; using ll = long long; using llu = unsigned long long; const int INF = numeric_limits<int>::max(); ll x, y, d; void euclid(ll a, ll b) { if (b == 0) { x = 1; y = 0; d = a; return; } euclid(b, a % b); ll t = x; x = y; y = t - a / b * y; } int main() { int tcc; cin >> tcc; while (tcc--) { ll n, k; cin >> n >> k; ll a = n / k; ll b = a; if (n % k != 0) b++; if (a == b) { printf("%lld 0\n", k); } else { euclid(a, b); x *= n / d; y *= n / d; ll t = (x + y) / (a - b) * d; printf("%lld %lld\n", (x + b / d * t), (y - a / d * t)); } } }
17.238095
62
0.424033
[ "vector" ]
893fedd4e7ced98c06c2e9b6231bf092c9e4545f
1,113
cc
C++
src/linear/tred2_pt.cc
Seeenman/Draco
8540aeb8bbbf467c3aa1caa9521d0910e0ca7917
[ "BSD-3-Clause-Open-MPI" ]
null
null
null
src/linear/tred2_pt.cc
Seeenman/Draco
8540aeb8bbbf467c3aa1caa9521d0910e0ca7917
[ "BSD-3-Clause-Open-MPI" ]
null
null
null
src/linear/tred2_pt.cc
Seeenman/Draco
8540aeb8bbbf467c3aa1caa9521d0910e0ca7917
[ "BSD-3-Clause-Open-MPI" ]
null
null
null
//--------------------------------------------*-C++-*---------------------------------------------// /*! * \file linear/tred2_pt.cc * \author Kent Budge * \date Thu Sep 2 14:49:55 2004 * \brief Specializations of tred2 * \note Copyright (C) 2016-2020 Triad National Security, LLC., All rights reserved. */ //------------------------------------------------------------------------------------------------// #include "tred2.i.hh" #include <cmath> #include <vector> namespace rtt_linear { //------------------------------------------------------------------------------------------------// // T1=T2=T3=vector<double> //------------------------------------------------------------------------------------------------// template void tred2(std::vector<double> &a, unsigned n, std::vector<double> &d, std::vector<double> &e); } // end namespace rtt_linear //------------------------------------------------------------------------------------------------// // end of tred2_pt.cc //------------------------------------------------------------------------------------------------//
41.222222
100
0.300988
[ "vector" ]
89443572a658773674336105538ae2a4854fea51
795
cpp
C++
1626.cpp
pengzhezhe/LeetCode
305ec0c5b4cb5ea7cd244b3308132dee778138bc
[ "Apache-2.0" ]
null
null
null
1626.cpp
pengzhezhe/LeetCode
305ec0c5b4cb5ea7cd244b3308132dee778138bc
[ "Apache-2.0" ]
null
null
null
1626.cpp
pengzhezhe/LeetCode
305ec0c5b4cb5ea7cd244b3308132dee778138bc
[ "Apache-2.0" ]
null
null
null
// // Created by pzz on 2022/5/25. // #include <iostream> #include <algorithm> #include <vector> using namespace std; class Solution { public: int bestTeamScore(vector<int> &scores, vector<int> &ages) { int n = scores.size(); vector<vector<int>> mp(n, vector<int>(2)); for (int i = 0; i < n; i++) { mp[i] = {ages[i], scores[i]}; } sort(mp.begin(), mp.end()); vector<int> dp(n, 0); int ans = 0; for (int i = 0; i < n; i++) { for (int j = i - 1; j >= 0; j--) { if (mp[j][1] <= mp[i][1]) dp[i] = max(dp[i], dp[j]); } dp[i] += mp[i][1]; ans = max(ans, dp[i]); } return ans; } }; int main() { return 0; }
19.875
63
0.422642
[ "vector" ]
89562d582aaf75f061af1ce3870bd1b956359dcd
1,939
hh
C++
include/renoir_controller_abstract_interface.hh
xelofox/renoir_controller_abstract_interface
d04d287e7045ab15b3fc96ed8f8ce0bdedafd22d
[ "Apache-2.0" ]
null
null
null
include/renoir_controller_abstract_interface.hh
xelofox/renoir_controller_abstract_interface
d04d287e7045ab15b3fc96ed8f8ce0bdedafd22d
[ "Apache-2.0" ]
null
null
null
include/renoir_controller_abstract_interface.hh
xelofox/renoir_controller_abstract_interface
d04d287e7045ab15b3fc96ed8f8ce0bdedafd22d
[ "Apache-2.0" ]
null
null
null
// // Copyright 2021, // Olivier Stasse, CNRS // // CNRS // // 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. #ifndef RENOIR_CONTROLLER_ABSTRACT_INTERFACE_HH #define RENOIR_CONTROLLER_ABSTRACT_INTERFACE_HH #include <map> #include <string> #include <vector> namespace renoir_controller { class NamedVector { private: std::string name_; std::vector<double> values_; public: NamedVector() {} ~NamedVector() {} const std::string &getName() const { return name_; } void setName(const std::string &aname) { name_ = aname; } const std::vector<double> &getValues() const { return values_; } void setValues(const std::vector<double> &values) { values_ = values; } }; typedef NamedVector SensorValues; typedef NamedVector ControlValues; class AbstractExternalInterface { public: AbstractExternalInterface() {} virtual ~AbstractExternalInterface() {} virtual void setupSetSensors(std::map<std::string, SensorValues> &sensorsIn) = 0; virtual void nominalSetSensors(std::map<std::string, SensorValues> &sensorsIn) = 0; virtual void cleanupSetSensors(std::map<std::string, SensorValues> &sensorsIn) = 0; virtual void getControl(std::map<std::string, ControlValues> &) = 0; }; } // namespace renoir_controller typedef renoir_controller::AbstractExternalInterface * createExternalInterface_t(); typedef void destroyExternalInterface_t( renoir_controller::AbstractExternalInterface *); #endif
25.853333
75
0.745745
[ "vector" ]
89612edacc452b72e5e4d0a875f1e9ea2d138788
9,165
cpp
C++
src/Geno/C++/GUI/Platform/Win32/Win32DropTarget.cpp
Starkshat/Geno
64e52e802eda97c48d90080b774bd51b4d873321
[ "Zlib" ]
33
2021-06-14T15:40:38.000Z
2022-03-16T01:23:40.000Z
src/Geno/C++/GUI/Platform/Win32/Win32DropTarget.cpp
Starkshat/Geno
64e52e802eda97c48d90080b774bd51b4d873321
[ "Zlib" ]
9
2021-06-18T13:15:05.000Z
2022-01-05T11:48:28.000Z
src/Geno/C++/GUI/Platform/Win32/Win32DropTarget.cpp
Starkshat/Geno
64e52e802eda97c48d90080b774bd51b4d873321
[ "Zlib" ]
11
2021-06-14T17:01:00.000Z
2022-03-16T01:44:42.000Z
/* * Copyright (c) 2021 Sebastian Kylander https://gaztin.com/ * * This software is provided 'as-is', without any express or implied warranty. In no event will * the authors be held liable for any damages arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, including commercial * applications, and to alter it and redistribute it freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the * original software. If you use this software in a product, an acknowledgment in the product * documentation would be appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as * being the original software. * 3. This notice may not be removed or altered from any source distribution. */ #if defined( _WIN32 ) #include "GUI/Platform/Win32/Win32DropTarget.h" #include "GUI/MainWindow.h" #include <Common/Platform/Win32/Win32Error.h> #include <Common/Drop.h> #include <iostream> #include <GLFW/glfw3.h> #include <GLFW/glfw3native.h> #include <ShlObj.h> ////////////////////////////////////////////////////////////////////////// static constexpr short FormatPriority( const FORMATETC& rFormat ) { switch( rFormat.cfFormat ) { default: return 0; // Bitmap case CF_DIBV5: return 10; case CF_DIB: return 9; case CF_TIFF: return 8; case CF_BITMAP: return 7; // Audio case CF_RIFF: return 6; case CF_WAVE: return 5; // Text case CF_UNICODETEXT: return 4; case CF_OEMTEXT: return 3; case CF_TEXT: return 2; // Paths case CF_HDROP: return 1; } } // FormatPriority ////////////////////////////////////////////////////////////////////////// static constexpr bool PrioritySortFormatsPred( const FORMATETC& rA, const FORMATETC& rB ) { return FormatPriority( rA ) > FormatPriority( rB ); } // PrioritySortFormatsPred ////////////////////////////////////////////////////////////////////////// Win32DropTarget::Win32DropTarget( void ) { HWND WindowHandle = glfwGetWin32Window( glfwGetCurrentContext() ); WIN32_CALL( OleInitialize( nullptr ) ); WIN32_CALL( CoLockObjectExternal( this, true, false ) ); WIN32_CALL( RegisterDragDrop( WindowHandle, this ) ); } // Win32DropTarget ////////////////////////////////////////////////////////////////////////// Win32DropTarget::~Win32DropTarget( void ) { HWND WindowHandle = glfwGetWin32Window( glfwGetCurrentContext() ); WIN32_CALL( CoLockObjectExternal( this, false, false ) ); WIN32_CALL( RevokeDragDrop( WindowHandle ) ); OleUninitialize(); } // ~Win32DropTarget ////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE Win32DropTarget::QueryInterface( const IID& rIID, void** ppObject ) { if( rIID == IID_IUnknown || rIID == IID_IDropTarget ) { *ppObject = this; AddRef(); return S_OK; } else { *ppObject = NULL; return E_NOINTERFACE; } } // QueryInterface ////////////////////////////////////////////////////////////////////////// ULONG STDMETHODCALLTYPE Win32DropTarget::AddRef( void ) { return InterlockedIncrement( &m_RefCount ); } // AddRef ////////////////////////////////////////////////////////////////////////// ULONG STDMETHODCALLTYPE Win32DropTarget::Release( void ) { const LONG Ref = InterlockedDecrement( &m_RefCount ); if( Ref == 0 ) delete this; return Ref; } // Release ////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE Win32DropTarget::DragEnter( IDataObject* pDataObject, DWORD /*KeyState*/, POINTL Point, DWORD* /*pEffect*/ ) { ::Drop Drop; if( DropFromDataObject( pDataObject, Drop ) ) { MainWindow::Instance().DragEnter( std::move( Drop ), Point.x, Point.y ); } return S_OK; } // DragEnter ////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE Win32DropTarget::DragOver( DWORD /*KeyState*/, POINTL Point, DWORD* /*pEffect*/ ) { MainWindow::Instance().DragOver( Point.x, Point.y ); return S_OK; } // DragOver ////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE Win32DropTarget::DragLeave( void ) { MainWindow::Instance().DragLeave(); return S_OK; } // DragLeave ////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE Win32DropTarget::Drop( IDataObject* pDataObject, DWORD /*KeyState*/, POINTL Point, DWORD* /*pEffect*/ ) { ::Drop Drop; if( DropFromDataObject( pDataObject, Drop ) ) { MainWindow::Instance().DragDrop( Drop, Point.x, Point.y ); } return S_OK; } // Drop ////////////////////////////////////////////////////////////////////////// bool Win32DropTarget::DropFromDataObject( IDataObject* pDataObject, ::Drop& rOutDrop ) { std::vector< FORMATETC > SupportedFormats; IEnumFORMATETC* pFormatEnumerator; if( pDataObject->EnumFormatEtc( DATADIR_GET, &pFormatEnumerator ) == S_OK ) { FORMATETC Format; while( pFormatEnumerator->Next( 1, &Format, nullptr ) == S_OK ) { if( Format.cfFormat < CF_MAX ) SupportedFormats.push_back( Format ); } std::sort( SupportedFormats.begin(), SupportedFormats.end(), PrioritySortFormatsPred ); } for( FORMATETC& rFormat : SupportedFormats ) { if( pDataObject->QueryGetData( &rFormat ) == S_OK ) { // STGMEDIUM with garbage collector struct CSTGMEDIUM : STGMEDIUM { ~CSTGMEDIUM() { ReleaseStgMedium( this ); } }; CSTGMEDIUM Medium{ }; if( pDataObject->GetData( &rFormat, &Medium ) == S_OK ) { switch( Medium.tymed ) { case TYMED_HGLOBAL: { void* pGlobalData = GlobalLock( Medium.hGlobal ); // Unlock HGLOBAL at the end of scope struct GC { HGLOBAL GlobalHandle; ~GC( void ) { GlobalUnlock( GlobalHandle ); } } gc{ Medium.hGlobal }; switch( rFormat.cfFormat ) { case CF_DIBV5: { BITMAPV5HEADER* pBitmapV5Header = static_cast< LPBITMAPV5HEADER >( pGlobalData ); HCOLORSPACE ColorSpaceHandle = reinterpret_cast< HCOLORSPACE >( pBitmapV5Header + 1 ); BYTE* pBits = reinterpret_cast< LPBYTE >( ColorSpaceHandle + 1 ); Drop::Bitmap Bitmap; Bitmap.width = pBitmapV5Header->bV5Width; Bitmap.height = pBitmapV5Header->bV5Height; Bitmap.data = std::make_unique< uint8_t[] >( pBitmapV5Header->bV5SizeImage ); std::memcpy( Bitmap.data.get(), pBits, pBitmapV5Header->bV5SizeImage ); rOutDrop.SetBitmap( std::move( Bitmap ) ); return true; } case CF_DIB: { BITMAPINFO* pBitmapInfo = static_cast< LPBITMAPINFO >( pGlobalData ); BYTE* pBits = reinterpret_cast< LPBYTE >( pBitmapInfo + 1 ); Drop::Bitmap Bitmap; Bitmap.width = pBitmapInfo->bmiHeader.biWidth; Bitmap.height = pBitmapInfo->bmiHeader.biHeight; Bitmap.data = std::make_unique< uint8_t[] >( pBitmapInfo->bmiHeader.biSizeImage ); std::memcpy( Bitmap.data.get(), pBits, pBitmapInfo->bmiHeader.biSizeImage ); rOutDrop.SetBitmap( std::move( Bitmap ) ); return true; } case CF_UNICODETEXT: { Drop::Text Text = static_cast< LPCWSTR >( pGlobalData ); rOutDrop.SetText( std::move( Text ) ); return true; } case CF_OEMTEXT: { const char* pChars = static_cast< const char* >( pGlobalData ); int Length = static_cast< int >( strlen( pChars ) ); Drop::Text Text( Length, L'\0' ); MultiByteToWideChar( CP_OEMCP, 0, pChars, Length, Text.data(), Length ); rOutDrop.SetText( std::move( Text ) ); return true; } case CF_TEXT: { const char* pChars = static_cast< const char* >( pGlobalData ); int Length = static_cast< int >( strlen( pChars ) ); Drop::Text Text( Length, L'\0' ); MultiByteToWideChar( CP_ACP, 0, pChars, Length, Text.data(), Length ); rOutDrop.SetText( std::move( Text ) ); return true; } case CF_HDROP: { HDROP DropHandle = static_cast< HDROP >( pGlobalData ); UINT DropCount = DragQueryFileW( DropHandle, 0xFFFFFFFF, nullptr, 0 ); Drop::Paths Paths; for( UINT i = 0; i < DropCount; ++i ) { const UINT Length = DragQueryFileW( DropHandle, i, nullptr, 0 ); std::wstring Path( Length, '\0' ); DragQueryFileW( DropHandle, i, Path.data(), static_cast< UINT >( Path.size() ) + 1 ); Paths.emplace_back( std::move( Path ) ); } rOutDrop.SetPaths( std::move( Paths ) ); return true; } } } break; default: { std::cerr << "Unsupported medium type for drop\n"; } break; } } } } return false; } // DropFromDataObject #endif // _WIN32
28.640625
134
0.581124
[ "vector" ]
896f5d628bbeb0ae8510d3be53ee2937ebe0b3dd
5,573
cpp
C++
examples/seek_raw_viewer.cpp
raptor419/libseekthermal-compact
dec104f778fd1fff7d0ab2d90303f2a91c785f0d
[ "MIT" ]
null
null
null
examples/seek_raw_viewer.cpp
raptor419/libseekthermal-compact
dec104f778fd1fff7d0ab2d90303f2a91c785f0d
[ "MIT" ]
null
null
null
examples/seek_raw_viewer.cpp
raptor419/libseekthermal-compact
dec104f778fd1fff7d0ab2d90303f2a91c785f0d
[ "MIT" ]
null
null
null
// based on Seek Thermal Viewer/Streamer by http://github.com/fnoop/maverick #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include "seek.h" #include "SeekCam.h" #include <iostream> #include <string> #include <signal.h> #include <math.h> #include <memory> #include "args.h" #include <fstream> #include <iostream> #include <iomanip> #include <limits> #include <chrono> using namespace LibSeek; // Setup sig handling static volatile sig_atomic_t sigflag = 0; void handle_sig(int sig) { (void)sig; sigflag = 1; } /* * custom write pgm function since opencv does not support comments */ void writepgm( const cv::Mat & seekframe, const std::string & prefix, const int framenumber, const std::string & comment, const bool ascii ) { std::ostringstream pgmfilename; pgmfilename << prefix; pgmfilename << std::internal << std::setfill('0') << std::setw(6); pgmfilename << framenumber; pgmfilename << ".pgm"; std::ofstream pgmfile; pgmfile.open(pgmfilename.str()); if (ascii) { pgmfile << "P2\n"; } else { pgmfile << "P5\n"; } pgmfile << "# " << comment << "\n"; pgmfile << seekframe.cols << " " << seekframe.rows << "\n"; pgmfile << std::to_string(std::numeric_limits<uint16_t>::max()) << "\n"; if (ascii) { for (int y = 0; y < seekframe.rows; y++) { for (int x = 0; x < seekframe.cols; x++) { pgmfile << std::to_string(seekframe.at<uint16_t>(y,x)) << " "; } } } else { // TODO: check endianess pgmfile.write(reinterpret_cast<char*>(seekframe.data), seekframe.total()*seekframe.elemSize()); } pgmfile.close(); } int main(int argc, char** argv) { // Setup arguments for parser args::ArgumentParser parser("Seek Thermal Viewer"); args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"}); args::ValueFlag<std::string> _ffc(parser, "FFC", "Additional Flat Field calibration - provide ffc file", {'F', "FFC"}); args::ValueFlag<std::string> _camtype(parser, "camtype", "Seek Thermal Camera Model - seek or seekpro", {'t', "camtype"}); args::ValueFlag<int> _interval(parser, "interval", "Interval of images to store on disk. Chose 1 for every image. Default: Every tenth frame.", {'i', "interval"}); // Parse arguments try { parser.ParseCLI(argc, argv); } catch (args::Help) { std::cout << parser; return 0; } catch (args::ParseError e) { std::cerr << e.what() << std::endl; std::cerr << parser; return 1; } catch (args::ValidationError e) { std::cerr << e.what() << std::endl; std::cerr << parser; return 1; } std::string camtype = "seek"; if (_camtype) camtype = args::get(_camtype); int interval = 10; if (_interval) { interval = args::get(_interval); } // Register signals signal(SIGINT, handle_sig); signal(SIGTERM, handle_sig); // Setup seek camera LibSeek::SeekCam* seek; LibSeek::SeekThermalPro seekpro(args::get(_ffc)); LibSeek::SeekThermal seekclassic(args::get(_ffc)); if (camtype == "seekpro") seek = &seekpro; else seek = &seekclassic; if (!seek->open()) { std::cout << "Error accessing camera" << std::endl; return 1; } printf("#rmin rmax central devtempsns\n"); // Mat containers for seek frames cv::Mat seekframe, outframe; int outframenumber = 0; auto time_start = std::chrono::high_resolution_clock::now(); // Main loop to retrieve frames from camera and output // If signal for interrupt/termination was received, break out of main loop and exit while (!sigflag) { // Retrieve frame from seek and process if (!seek->read(seekframe)) { std::cout << "Failed to read frame from camera, exiting" << std::endl; return -1; } auto time_frame = std::chrono::high_resolution_clock::now(); // get raw max/min/central values double min, max, central; cv::minMaxIdx(seekframe, &min, &max); cv::Point center(seekframe.cols/2.0, seekframe.rows/2.0); cv::Rect middle(center-cv::Point(1,1), cv::Size(3,3)); cv::Scalar mean = cv::mean(seekframe(middle)); central = mean(0); printf("%d %d %d %d\n", int(min), int(max), int(central), seek->device_temp_sensor()); //int framenumber = seek->frame_counter(); if (outframenumber % interval == 0) { auto frametime = std::chrono::duration_cast<std::chrono::nanoseconds>(time_frame-time_start).count(); // nanoseconds since recording started (for variable framerate presentation) std::string comment = std::to_string(int(central)) +" "+std::to_string(seek->device_temp_sensor()) +" "+std::to_string(frametime); writepgm( seekframe, "seekframe_", outframenumber, comment, true ); } outframenumber++; seekframe.convertTo(outframe, CV_8U, 1, 128-central); if (!outframe.empty()) { cv::imshow("SeekThermal", outframe); } char c = cv::waitKey(10); if (c == 'q') { break; } } if (sigflag) { std::cout << "Break signal detected, exiting" << std::endl; } return 0; }
30.453552
190
0.580657
[ "model" ]
8971d2b64350f610e88886ca9113f34a86be4f11
7,216
hpp
C++
src/render_tasks/d3d12_imgui_render_task.hpp
LaisoEmilio/WispRenderer
8186856a7b3e1f0a19f6f6c8a9b99d8ccff38572
[ "Apache-2.0" ]
203
2019-04-26T10:52:22.000Z
2022-03-15T17:42:44.000Z
src/render_tasks/d3d12_imgui_render_task.hpp
LaisoEmilio/WispRenderer
8186856a7b3e1f0a19f6f6c8a9b99d8ccff38572
[ "Apache-2.0" ]
90
2018-11-23T09:07:05.000Z
2019-04-13T10:44:03.000Z
src/render_tasks/d3d12_imgui_render_task.hpp
LaisoEmilio/WispRenderer
8186856a7b3e1f0a19f6f6c8a9b99d8ccff38572
[ "Apache-2.0" ]
14
2019-06-19T00:52:00.000Z
2021-02-19T13:44:01.000Z
/*! * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) * * 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. */ #pragma once #include "../window.hpp" #include "../d3d12/d3d12_renderer.hpp" #include "../d3d12/d3d12_functions.hpp" #include "../frame_graph/frame_graph.hpp" #include "../imgui/ImGuizmo.h" #include "../imgui/imgui.hpp" #include "../imgui/imgui_impl_win32.hpp" #include "../imgui/imgui_impl_dx12.hpp" namespace wr { struct ImGuiTaskData { std::function<void(ImTextureID)> in_imgui_func; inline static d3d12::DescriptorHeap* out_descriptor_heap = nullptr; }; namespace internal { inline void SetupImGuiTask(RenderSystem& rs, FrameGraph&, RenderTaskHandle, bool resize) { auto& n_render_system = static_cast<D3D12RenderSystem&>(rs); if (!n_render_system.m_window.has_value()) { LOGC("Tried using imgui without a window!"); } if (resize) { ImGui_ImplDX12_CreateDeviceObjects(); return; } if (ImGui_ImplDX12_IsInitialized()) { return; } d3d12::desc::DescriptorHeapDesc heap_desc; heap_desc.m_num_descriptors = 2; heap_desc.m_shader_visible = true; heap_desc.m_type = DescriptorHeapType::DESC_HEAP_TYPE_CBV_SRV_UAV; ImGuiTaskData::out_descriptor_heap = d3d12::CreateDescriptorHeap(n_render_system.m_device, heap_desc); SetName(ImGuiTaskData::out_descriptor_heap, L"ImGui Descriptor Heap"); IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls //io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows (FIXME: Currently broken in DX12 back-end, need some work!) io.ConfigDockingWithShift = true; ImGui_ImplWin32_Init(n_render_system.m_window.value()->GetWindowHandle()); ImGui_ImplDX12_Init(n_render_system.m_device->m_native, d3d12::settings::num_back_buffers, (DXGI_FORMAT)d3d12::settings::back_buffer_format, d3d12::GetCPUHandle(ImGuiTaskData::out_descriptor_heap, 0 /* TODO: Solve versioning for ImGui */).m_native, d3d12::GetGPUHandle(ImGuiTaskData::out_descriptor_heap, 0 /* TODO: Solve versioning for ImGui */).m_native); ImGui::StyleColorsCherry(); } template<typename T> inline void ExecuteImGuiTask(RenderSystem& rs, FrameGraph& fg, SceneGraph& sg, RenderTaskHandle handle) { auto& n_render_system = static_cast<D3D12RenderSystem&>(rs); auto& data = fg.GetData<ImGuiTaskData>(handle); auto cmd_list = fg.GetCommandList<d3d12::CommandList>(handle); // Temp rendering if (n_render_system.m_render_window.has_value()) { auto frame_idx = n_render_system.GetFrameIdx(); // Create handle to the render target you want to display. and put it in descriptor slot 2. auto display_rt = static_cast<d3d12::RenderTarget*>(fg.GetPredecessorRenderTarget<T>()); auto cpu_handle = d3d12::GetCPUHandle(data.out_descriptor_heap, frame_idx, 1); d3d12::CreateSRVFromSpecificRTV(display_rt, cpu_handle, 0, display_rt->m_create_info.m_rtv_formats[frame_idx]); // Prepare imgui ImGui_ImplDX12_NewFrame(); ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); ImGuizmo::BeginFrame(); data.in_imgui_func(ImTextureID(d3d12::GetGPUHandle(data.out_descriptor_heap, frame_idx, 1).m_native.ptr)); // Render imgui d3d12::Transition(cmd_list, display_rt, wr::ResourceState::COPY_SOURCE, wr::ResourceState::PIXEL_SHADER_RESOURCE); //EXCEPTION CODE START d3d12::BindDescriptorHeap(cmd_list, data.out_descriptor_heap, data.out_descriptor_heap->m_create_info.m_type, n_render_system.GetFrameIdx()); d3d12::BindDescriptorHeaps(cmd_list); for (int i = 0; i < D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES; ++i) { cmd_list->m_dynamic_descriptor_heaps[i]->CommitStagedDescriptorsForDraw(*cmd_list); } //EXCEPTION CODE END. Don't copy this outside of imgui render task. Since imgui doesn't use our Draw functions, this is needed to make it work with the dynamic descriptor heaps. ImGui::Render(); ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), cmd_list->m_native); // Update and Render additional Platform Windows (Beta-Viewport) if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { ImGui::UpdatePlatformWindows(); ImGui::RenderPlatformWindowsDefault(NULL, (void*)cmd_list->m_native); } d3d12::Transition(cmd_list, display_rt, wr::ResourceState::PIXEL_SHADER_RESOURCE, wr::ResourceState::COPY_SOURCE); } } inline void DestroyImGuiTask(FrameGraph&, RenderTaskHandle, bool resize) { if (resize) { ImGui_ImplDX12_InvalidateDeviceObjects(); } else if (ImGui_ImplDX12_IsInitialized()) { ImGui_ImplDX12_Shutdown(); ImGui_ImplWin32_Shutdown(); ImGui::DestroyContext(); delete ImGuiTaskData::out_descriptor_heap; } } } /* internal */ template<typename T> [[nodiscard]] inline RenderTaskDesc GetImGuiTask(std::function<void(ImTextureID)> imgui_func) { RenderTargetProperties rt_properties { RenderTargetProperties::IsRenderWindow(true), RenderTargetProperties::Width(std::nullopt), RenderTargetProperties::Height(std::nullopt), RenderTargetProperties::ExecuteResourceState(std::nullopt), RenderTargetProperties::FinishedResourceState(std::nullopt), RenderTargetProperties::CreateDSVBuffer(false), RenderTargetProperties::DSVFormat(Format::UNKNOWN), RenderTargetProperties::RTVFormats({ wr::Format::R16G16B16A16_FLOAT }), RenderTargetProperties::NumRTVFormats(1), RenderTargetProperties::Clear(false), RenderTargetProperties::ClearDepth(false), }; RenderTaskDesc desc; desc.m_setup_func = [imgui_func](RenderSystem& rs, FrameGraph& fg, RenderTaskHandle handle, bool resize) { fg.GetData<ImGuiTaskData>(handle).in_imgui_func = imgui_func; internal::SetupImGuiTask(rs, fg, handle, resize); }; desc.m_execute_func = [](RenderSystem& rs, FrameGraph& fg, SceneGraph& sg, RenderTaskHandle handle) { internal::ExecuteImGuiTask<T>(rs, fg, sg, handle); }; desc.m_destroy_func = [](FrameGraph& fg, RenderTaskHandle handle, bool resize) { internal::DestroyImGuiTask(fg, handle, resize); }; desc.m_properties = rt_properties; desc.m_type = RenderTaskType::DIRECT; desc.m_allow_multithreading = false; return desc; } } /* wr */
37.583333
204
0.742794
[ "render" ]
897afa6d4b497181feab81a0057664ab3863dcd7
1,826
hpp
C++
src/editor/modes/tile_interaction_renderer.hpp
mnewhouse/tselements
bd1c6724018e862156948a680bb1bc70dd28bef6
[ "MIT" ]
null
null
null
src/editor/modes/tile_interaction_renderer.hpp
mnewhouse/tselements
bd1c6724018e862156948a680bb1bc70dd28bef6
[ "MIT" ]
null
null
null
src/editor/modes/tile_interaction_renderer.hpp
mnewhouse/tselements
bd1c6724018e862156948a680bb1bc70dd28bef6
[ "MIT" ]
null
null
null
/* * TS Elements * Copyright 2015-2018 M. Newhouse * Released under the MIT license. */ #pragma once #include "resources/geometry.hpp" #include "graphics/texture.hpp" #include "graphics/shader.hpp" #include "graphics/buffer.hpp" #include <SFML/Graphics/Transform.hpp> namespace ts { namespace resources { struct PlacedTile; } namespace scene { class TextureMapping; } namespace editor { class TileInteractionRenderer { public: TileInteractionRenderer(); void set_transform(const sf::Transform& model_matrix); void render(const sf::Transform& view_matrix, Vector2f track_size) const; void update_tile_geometry(const resources::PlacedTile*, std::size_t tile_count, const scene::TextureMapping& texture_mapping); void clear_tile_geometry(); private: void assign_vao_state(); graphics::ShaderProgram selected_geometry_shader_; graphics::ShaderProgram default_geometry_shader_; graphics::Buffer vertex_buffer_; graphics::Buffer index_buffer_; graphics::VertexArray vertex_array_; std::uint32_t default_view_matrix_location_; std::uint32_t default_sampler_location_; std::uint32_t default_min_corner_location_; std::uint32_t default_max_corner_location_; std::uint32_t selected_view_matrix_location_; std::uint32_t selected_sampler_location_; struct Component { const graphics::Texture* texture = nullptr; const std::uint32_t* buffer_offset = nullptr; std::uint32_t element_count = 0; }; std::vector<Component> render_components_; std::vector<resources::Vertex> vertex_cache_; std::vector<resources::Face> face_cache_; sf::Transform model_matrix_; }; } }
24.026316
85
0.692223
[ "geometry", "render", "vector", "transform" ]
8986708cd62b47c85d9d290d1c763050792d9bd0
23,360
cpp
C++
TMessagesProj/jni/TgNetWrapper.cpp
Fghgfh/Reyhangram
4ffba4522ad889f16dfe5b159ae169265d09ff34
[ "Apache-2.0" ]
null
null
null
TMessagesProj/jni/TgNetWrapper.cpp
Fghgfh/Reyhangram
4ffba4522ad889f16dfe5b159ae169265d09ff34
[ "Apache-2.0" ]
null
null
null
TMessagesProj/jni/TgNetWrapper.cpp
Fghgfh/Reyhangram
4ffba4522ad889f16dfe5b159ae169265d09ff34
[ "Apache-2.0" ]
null
null
null
#include <jni.h> #include "tgnet/ApiScheme.h" #include "tgnet/BuffersStorage.h" #include "tgnet/NativeByteBuffer.h" #include "tgnet/ConnectionsManager.h" #include "tgnet/MTProtoScheme.h" #include "tgnet/FileLoadOperation.h" JavaVM *java; jclass jclass_RequestDelegateInternal; jmethodID jclass_RequestDelegateInternal_run; jclass jclass_QuickAckDelegate; jmethodID jclass_QuickAckDelegate_run; jclass jclass_WriteToSocketDelegate; jmethodID jclass_WriteToSocketDelegate_run; jclass jclass_FileLoadOperationDelegate; jmethodID jclass_FileLoadOperationDelegate_onFinished; jmethodID jclass_FileLoadOperationDelegate_onFailed; jmethodID jclass_FileLoadOperationDelegate_onProgressChanged; jclass jclass_ConnectionsManager; jmethodID jclass_ConnectionsManager_onUnparsedMessageReceived; jmethodID jclass_ConnectionsManager_onUpdate; jmethodID jclass_ConnectionsManager_onSessionCreated; jmethodID jclass_ConnectionsManager_onLogout; jmethodID jclass_ConnectionsManager_onConnectionStateChanged; jmethodID jclass_ConnectionsManager_onInternalPushReceived; jmethodID jclass_ConnectionsManager_onUpdateConfig; jmethodID jclass_ConnectionsManager_onBytesSent; jmethodID jclass_ConnectionsManager_onBytesReceived; jmethodID jclass_ConnectionsManager_onRequestNewServerIpAndPort; jint createLoadOpetation(JNIEnv *env, jclass c, jint dc_id, jlong id, jlong volume_id, jlong access_hash, jint local_id, jbyteArray encKey, jbyteArray encIv, jstring extension, jint version, jint size, jstring dest, jstring temp, jobject delegate) { if (encKey != nullptr && encIv == nullptr || encKey == nullptr && encIv != nullptr || extension == nullptr || dest == nullptr || temp == nullptr) { return 0; } FileLoadOperation *loadOperation = nullptr; bool error = false; const char *extensionStr = env->GetStringUTFChars(extension, NULL); const char *destStr = env->GetStringUTFChars(dest, NULL); const char *tempStr = env->GetStringUTFChars(temp, NULL); if (extensionStr == nullptr || destStr == nullptr || tempStr == nullptr) { error = true; } jbyte *keyBuff = nullptr; jbyte *ivBuff = nullptr; if (!error && encKey != nullptr) { keyBuff = env->GetByteArrayElements(encKey, NULL); ivBuff = env->GetByteArrayElements(encIv, NULL); if (keyBuff == nullptr || ivBuff == nullptr) { error = true; } } if (!error) { if (delegate != nullptr) { delegate = env->NewGlobalRef(delegate); } loadOperation = new FileLoadOperation(dc_id, id, volume_id, access_hash, local_id, (uint8_t *) keyBuff, (uint8_t *) ivBuff, extensionStr, version, size, destStr, tempStr); loadOperation->setDelegate([delegate](std::string path) { jstring pathText = jniEnv->NewStringUTF(path.c_str()); if (delegate != nullptr) { jniEnv->CallVoidMethod(delegate, jclass_FileLoadOperationDelegate_onFinished, pathText); } if (pathText != nullptr) { jniEnv->DeleteLocalRef(pathText); } }, [delegate](FileLoadFailReason reason) { if (delegate != nullptr) { jniEnv->CallVoidMethod(delegate, jclass_FileLoadOperationDelegate_onFailed, reason); } }, [delegate](float progress) { if (delegate != nullptr) { jniEnv->CallVoidMethod(delegate, jclass_FileLoadOperationDelegate_onProgressChanged, progress); } }); loadOperation->ptr1 = delegate; } if (keyBuff != nullptr) { env->ReleaseByteArrayElements(encKey, keyBuff, JNI_ABORT); } if (ivBuff != nullptr) { env->ReleaseByteArrayElements(encIv, ivBuff, JNI_ABORT); } if (extensionStr != nullptr) { env->ReleaseStringUTFChars(extension, extensionStr); } if (destStr != nullptr) { env->ReleaseStringUTFChars(dest, destStr); } if (tempStr != nullptr) { env->ReleaseStringUTFChars(temp, tempStr); } return (jint) loadOperation; } void startLoadOperation(JNIEnv *env, jclass c, jint address) { if (address != 0) { ((FileLoadOperation *) address)->start(); } } void cancelLoadOperation(JNIEnv *env, jclass c, jint address) { if (address != 0) { ((FileLoadOperation *) address)->cancel(); } } static const char *FileLoadOperationClassPathName = "org/telegram/tgnet/FileLoadOperation"; static JNINativeMethod FileLoadOperationMethods[] = { {"native_createLoadOpetation", "(IJJJI[B[BLjava/lang/String;IILjava/lang/String;Ljava/lang/String;Ljava/lang/Object;)I", (void *) createLoadOpetation}, {"native_startLoadOperation", "(I)V", (void *) startLoadOperation}, {"native_cancelLoadOperation", "(I)V", (void *) cancelLoadOperation} }; jint getFreeBuffer(JNIEnv *env, jclass c, jint length) { return (jint) BuffersStorage::getInstance().getFreeBuffer(length); } jint limit(JNIEnv *env, jclass c, jint address) { NativeByteBuffer *buffer = (NativeByteBuffer *) address; return buffer->limit(); } jint position(JNIEnv *env, jclass c, jint address) { NativeByteBuffer *buffer = (NativeByteBuffer *) address; return buffer->position(); } void reuse(JNIEnv *env, jclass c, jint address) { NativeByteBuffer *buffer = (NativeByteBuffer *) address; buffer->reuse(); } jobject getJavaByteBuffer(JNIEnv *env, jclass c, jint address) { NativeByteBuffer *buffer = (NativeByteBuffer *) address; return buffer->getJavaByteBuffer(); } static const char *NativeByteBufferClassPathName = "org/telegram/tgnet/NativeByteBuffer"; static JNINativeMethod NativeByteBufferMethods[] = { {"native_getFreeBuffer", "(I)I", (void *) getFreeBuffer}, {"native_limit", "(I)I", (void *) limit}, {"native_position", "(I)I", (void *) position}, {"native_reuse", "(I)V", (void *) reuse}, {"native_getJavaByteBuffer", "(I)Ljava/nio/ByteBuffer;", (void *) getJavaByteBuffer} }; jlong getCurrentTimeMillis(JNIEnv *env, jclass c) { return ConnectionsManager::getInstance().getCurrentTimeMillis(); } jint getCurrentTime(JNIEnv *env, jclass c) { return ConnectionsManager::getInstance().getCurrentTime(); } jint isTestBackend(JNIEnv *env, jclass c) { return ConnectionsManager::getInstance().isTestBackend() ? 1 : 0; } jint getTimeDifference(JNIEnv *env, jclass c) { return ConnectionsManager::getInstance().getTimeDifference(); } void sendRequest(JNIEnv *env, jclass c, jint object, jobject onComplete, jobject onQuickAck, jobject onWriteToSocket, jint flags, jint datacenterId, jint connetionType, jboolean immediate, jint token) { TL_api_request *request = new TL_api_request(); request->request = (NativeByteBuffer *) object; if (onComplete != nullptr) { onComplete = env->NewGlobalRef(onComplete); } if (onQuickAck != nullptr) { onQuickAck = env->NewGlobalRef(onQuickAck); } if (onWriteToSocket != nullptr) { onWriteToSocket = env->NewGlobalRef(onWriteToSocket); } ConnectionsManager::getInstance().sendRequest(request, ([onComplete](TLObject *response, TL_error *error, int32_t networkType) { TL_api_response *resp = (TL_api_response *) response; jint ptr = 0; jint errorCode = 0; jstring errorText = nullptr; if (resp != nullptr) { ptr = (jint) resp->response.get(); } else if (error != nullptr) { errorCode = error->code; errorText = jniEnv->NewStringUTF(error->text.c_str()); } if (onComplete != nullptr) { jniEnv->CallVoidMethod(onComplete, jclass_RequestDelegateInternal_run, ptr, errorCode, errorText, networkType); } if (errorText != nullptr) { jniEnv->DeleteLocalRef(errorText); } }), ([onQuickAck] { if (onQuickAck != nullptr) { jniEnv->CallVoidMethod(onQuickAck, jclass_QuickAckDelegate_run); } }), ([onWriteToSocket] { if (onWriteToSocket != nullptr) { jniEnv->CallVoidMethod(onWriteToSocket, jclass_WriteToSocketDelegate_run); } }), flags, datacenterId, (ConnectionType) connetionType, immediate, token, onComplete, onQuickAck, onWriteToSocket); } void cancelRequest(JNIEnv *env, jclass c, jint token, jboolean notifyServer) { return ConnectionsManager::getInstance().cancelRequest(token, notifyServer); } void cleanUp(JNIEnv *env, jclass c) { return ConnectionsManager::getInstance().cleanUp(); } void cancelRequestsForGuid(JNIEnv *env, jclass c, jint guid) { return ConnectionsManager::getInstance().cancelRequestsForGuid(guid); } void bindRequestToGuid(JNIEnv *env, jclass c, jint requestToken, jint guid) { return ConnectionsManager::getInstance().bindRequestToGuid(requestToken, guid); } void applyDatacenterAddress(JNIEnv *env, jclass c, jint datacenterId, jstring ipAddress, jint port) { const char *valueStr = env->GetStringUTFChars(ipAddress, 0); ConnectionsManager::getInstance().applyDatacenterAddress(datacenterId, std::string(valueStr), port); if (valueStr != 0) { env->ReleaseStringUTFChars(ipAddress, valueStr); } } void setProxySettings(JNIEnv *env, jclass c, jstring address, jint port, jstring username, jstring password) { const char *addressStr = env->GetStringUTFChars(address, 0); const char *usernameStr = env->GetStringUTFChars(username, 0); const char *passwordStr = env->GetStringUTFChars(password, 0); ConnectionsManager::getInstance().setProxySettings(addressStr, (uint16_t) port, usernameStr, passwordStr); if (addressStr != 0) { env->ReleaseStringUTFChars(address, addressStr); } if (usernameStr != 0) { env->ReleaseStringUTFChars(username, usernameStr); } if (passwordStr != 0) { env->ReleaseStringUTFChars(password, passwordStr); } } jint getConnectionState(JNIEnv *env, jclass c) { return ConnectionsManager::getInstance().getConnectionState(); } void setUserId(JNIEnv *env, jclass c, int32_t id) { ConnectionsManager::getInstance().setUserId(id); } void switchBackend(JNIEnv *env, jclass c) { ConnectionsManager::getInstance().switchBackend(); } void pauseNetwork(JNIEnv *env, jclass c) { ConnectionsManager::getInstance().pauseNetwork(); } void resumeNetwork(JNIEnv *env, jclass c, jboolean partial) { ConnectionsManager::getInstance().resumeNetwork(partial); } void updateDcSettings(JNIEnv *env, jclass c) { ConnectionsManager::getInstance().updateDcSettings(0, false); } void setUseIpv6(JNIEnv *env, jclass c, bool value) { ConnectionsManager::getInstance().setUseIpv6(value); } void setNetworkAvailable(JNIEnv *env, jclass c, jboolean value, jint networkType) { ConnectionsManager::getInstance().setNetworkAvailable(value, networkType); } void setPushConnectionEnabled(JNIEnv *env, jclass c, jboolean value) { ConnectionsManager::getInstance().setPushConnectionEnabled(value); } void applyDnsConfig(JNIEnv *env, jclass c, jint address) { ConnectionsManager::getInstance().applyDnsConfig((NativeByteBuffer *) address); } class Delegate : public ConnectiosManagerDelegate { void onUpdate() { jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onUpdate); } void onSessionCreated() { jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onSessionCreated); } void onConnectionStateChanged(ConnectionState state) { jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onConnectionStateChanged, state); } void onUnparsedMessageReceived(int64_t reqMessageId, NativeByteBuffer *buffer, ConnectionType connectionType) { if (connectionType == ConnectionTypeGeneric) { jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onUnparsedMessageReceived, buffer); } } void onLogout() { jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onLogout); } void onUpdateConfig(TL_config *config) { NativeByteBuffer *buffer = BuffersStorage::getInstance().getFreeBuffer(config->getObjectSize()); config->serializeToStream(buffer); buffer->position(0); jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onUpdateConfig, buffer); buffer->reuse(); } void onInternalPushReceived() { jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onInternalPushReceived); } void onBytesReceived(int32_t amount, int32_t networkType) { jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onBytesReceived, amount, networkType); } void onBytesSent(int32_t amount, int32_t networkType) { jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onBytesSent, amount, networkType); } void onRequestNewServerIpAndPort(int32_t second) { jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onRequestNewServerIpAndPort, second); } }; void setLangCode(JNIEnv *env, jclass c, jstring langCode) { const char *langCodeStr = env->GetStringUTFChars(langCode, 0); ConnectionsManager::getInstance().setLangCode(std::string(langCodeStr)); if (langCodeStr != 0) { env->ReleaseStringUTFChars(langCode, langCodeStr); } } void init(JNIEnv *env, jclass c, jint version, jint layer, jint apiId, jstring deviceModel, jstring systemVersion, jstring appVersion, jstring langCode, jstring systemLangCode, jstring configPath, jstring logPath, jint userId, jboolean enablePushConnection, jboolean hasNetwork, jint networkType) { const char *deviceModelStr = env->GetStringUTFChars(deviceModel, 0); const char *systemVersionStr = env->GetStringUTFChars(systemVersion, 0); const char *appVersionStr = env->GetStringUTFChars(appVersion, 0); const char *langCodeStr = env->GetStringUTFChars(langCode, 0); const char *systemLangCodeStr = env->GetStringUTFChars(systemLangCode, 0); const char *configPathStr = env->GetStringUTFChars(configPath, 0); const char *logPathStr = env->GetStringUTFChars(logPath, 0); ConnectionsManager::getInstance().init(version, layer, apiId, std::string(deviceModelStr), std::string(systemVersionStr), std::string(appVersionStr), std::string(langCodeStr), std::string(systemLangCodeStr), std::string(configPathStr), std::string(logPathStr), userId, true, enablePushConnection, hasNetwork, networkType); if (deviceModelStr != 0) { env->ReleaseStringUTFChars(deviceModel, deviceModelStr); } if (systemVersionStr != 0) { env->ReleaseStringUTFChars(systemVersion, systemVersionStr); } if (appVersionStr != 0) { env->ReleaseStringUTFChars(appVersion, appVersionStr); } if (langCodeStr != 0) { env->ReleaseStringUTFChars(langCode, langCodeStr); } if (systemLangCodeStr != 0) { env->ReleaseStringUTFChars(systemLangCode, systemLangCodeStr); } if (configPathStr != 0) { env->ReleaseStringUTFChars(configPath, configPathStr); } if (logPathStr != 0) { env->ReleaseStringUTFChars(logPath, logPathStr); } } void setJava(JNIEnv *env, jclass c, jboolean useJavaByteBuffers) { ConnectionsManager::useJavaVM(java, useJavaByteBuffers); ConnectionsManager::getInstance().setDelegate(new Delegate()); } static const char *ConnectionsManagerClassPathName = "org/telegram/tgnet/ConnectionsManager"; static JNINativeMethod ConnectionsManagerMethods[] = { {"native_getCurrentTimeMillis", "()J", (void *) getCurrentTimeMillis}, {"native_getCurrentTime", "()I", (void *) getCurrentTime}, {"native_isTestBackend", "()I", (void *) isTestBackend}, {"native_getTimeDifference", "()I", (void *) getTimeDifference}, {"native_sendRequest", "(ILorg/telegram/tgnet/RequestDelegateInternal;Lorg/telegram/tgnet/QuickAckDelegate;Lorg/telegram/tgnet/WriteToSocketDelegate;IIIZI)V", (void *) sendRequest}, {"native_cancelRequest", "(IZ)V", (void *) cancelRequest}, {"native_cleanUp", "()V", (void *) cleanUp}, {"native_cancelRequestsForGuid", "(I)V", (void *) cancelRequestsForGuid}, {"native_bindRequestToGuid", "(II)V", (void *) bindRequestToGuid}, {"native_applyDatacenterAddress", "(ILjava/lang/String;I)V", (void *) applyDatacenterAddress}, {"native_setProxySettings", "(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V", (void *) setProxySettings}, {"native_getConnectionState", "()I", (void *) getConnectionState}, {"native_setUserId", "(I)V", (void *) setUserId}, {"native_init", "(IIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZI)V", (void *) init}, {"native_setLangCode", "(Ljava/lang/String;)V", (void *) setLangCode}, {"native_switchBackend", "()V", (void *) switchBackend}, {"native_pauseNetwork", "()V", (void *) pauseNetwork}, {"native_resumeNetwork", "(Z)V", (void *) resumeNetwork}, {"native_updateDcSettings", "()V", (void *) updateDcSettings}, {"native_setUseIpv6", "(Z)V", (void *) setUseIpv6}, {"native_setNetworkAvailable", "(ZI)V", (void *) setNetworkAvailable}, {"native_setPushConnectionEnabled", "(Z)V", (void *) setPushConnectionEnabled}, {"native_setJava", "(Z)V", (void *) setJava}, {"native_applyDnsConfig", "(I)V", (void *) applyDnsConfig} }; inline int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods, int methodsCount) { jclass clazz; clazz = env->FindClass(className); if (clazz == NULL) { return JNI_FALSE; } if (env->RegisterNatives(clazz, methods, methodsCount) < 0) { return JNI_FALSE; } return JNI_TRUE; } extern "C" int registerNativeTgNetFunctions(JavaVM *vm, JNIEnv *env) { java = vm; if (!registerNativeMethods(env, NativeByteBufferClassPathName, NativeByteBufferMethods, sizeof(NativeByteBufferMethods) / sizeof(NativeByteBufferMethods[0]))) { return JNI_FALSE; } if (!registerNativeMethods(env, FileLoadOperationClassPathName, FileLoadOperationMethods, sizeof(FileLoadOperationMethods) / sizeof(FileLoadOperationMethods[0]))) { return JNI_FALSE; } if (!registerNativeMethods(env, ConnectionsManagerClassPathName, ConnectionsManagerMethods, sizeof(ConnectionsManagerMethods) / sizeof(ConnectionsManagerMethods[0]))) { return JNI_FALSE; } jclass_RequestDelegateInternal = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/tgnet/RequestDelegateInternal")); if (jclass_RequestDelegateInternal == 0) { return JNI_FALSE; } jclass_RequestDelegateInternal_run = env->GetMethodID(jclass_RequestDelegateInternal, "run", "(IILjava/lang/String;I)V"); if (jclass_RequestDelegateInternal_run == 0) { return JNI_FALSE; } jclass_QuickAckDelegate = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/tgnet/QuickAckDelegate")); if (jclass_RequestDelegateInternal == 0) { return JNI_FALSE; } jclass_QuickAckDelegate_run = env->GetMethodID(jclass_QuickAckDelegate, "run", "()V"); if (jclass_QuickAckDelegate_run == 0) { return JNI_FALSE; } jclass_WriteToSocketDelegate = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/tgnet/WriteToSocketDelegate")); if (jclass_WriteToSocketDelegate == 0) { return JNI_FALSE; } jclass_WriteToSocketDelegate_run = env->GetMethodID(jclass_WriteToSocketDelegate, "run", "()V"); if (jclass_WriteToSocketDelegate_run == 0) { return JNI_FALSE; } jclass_FileLoadOperationDelegate = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/tgnet/FileLoadOperationDelegate")); if (jclass_FileLoadOperationDelegate == 0) { return JNI_FALSE; } jclass_FileLoadOperationDelegate_onFinished = env->GetMethodID(jclass_FileLoadOperationDelegate, "onFinished", "(Ljava/lang/String;)V"); if (jclass_FileLoadOperationDelegate_onFinished == 0) { return JNI_FALSE; } jclass_FileLoadOperationDelegate_onFailed = env->GetMethodID(jclass_FileLoadOperationDelegate, "onFailed", "(I)V"); if (jclass_FileLoadOperationDelegate_onFailed == 0) { return JNI_FALSE; } jclass_FileLoadOperationDelegate_onProgressChanged = env->GetMethodID(jclass_FileLoadOperationDelegate, "onProgressChanged", "(F)V"); if (jclass_FileLoadOperationDelegate_onProgressChanged == 0) { return JNI_FALSE; } jclass_ConnectionsManager = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/tgnet/ConnectionsManager")); if (jclass_ConnectionsManager == 0) { return JNI_FALSE; } jclass_ConnectionsManager_onUnparsedMessageReceived = env->GetStaticMethodID(jclass_ConnectionsManager, "onUnparsedMessageReceived", "(I)V"); if (jclass_ConnectionsManager_onUnparsedMessageReceived == 0) { return JNI_FALSE; } jclass_ConnectionsManager_onUpdate = env->GetStaticMethodID(jclass_ConnectionsManager, "onUpdate", "()V"); if (jclass_ConnectionsManager_onUpdate == 0) { return JNI_FALSE; } jclass_ConnectionsManager_onSessionCreated = env->GetStaticMethodID(jclass_ConnectionsManager, "onSessionCreated", "()V"); if (jclass_ConnectionsManager_onSessionCreated == 0) { return JNI_FALSE; } jclass_ConnectionsManager_onLogout = env->GetStaticMethodID(jclass_ConnectionsManager, "onLogout", "()V"); if (jclass_ConnectionsManager_onLogout == 0) { return JNI_FALSE; } jclass_ConnectionsManager_onConnectionStateChanged = env->GetStaticMethodID(jclass_ConnectionsManager, "onConnectionStateChanged", "(I)V"); if (jclass_ConnectionsManager_onConnectionStateChanged == 0) { return JNI_FALSE; } jclass_ConnectionsManager_onInternalPushReceived = env->GetStaticMethodID(jclass_ConnectionsManager, "onInternalPushReceived", "()V"); if (jclass_ConnectionsManager_onInternalPushReceived == 0) { return JNI_FALSE; } jclass_ConnectionsManager_onUpdateConfig = env->GetStaticMethodID(jclass_ConnectionsManager, "onUpdateConfig", "(I)V"); if (jclass_ConnectionsManager_onUpdateConfig == 0) { return JNI_FALSE; } jclass_ConnectionsManager_onBytesSent = env->GetStaticMethodID(jclass_ConnectionsManager, "onBytesSent", "(II)V"); if (jclass_ConnectionsManager_onBytesSent == 0) { return JNI_FALSE; } jclass_ConnectionsManager_onBytesReceived = env->GetStaticMethodID(jclass_ConnectionsManager, "onBytesReceived", "(II)V"); if (jclass_ConnectionsManager_onBytesReceived == 0) { return JNI_FALSE; } jclass_ConnectionsManager_onRequestNewServerIpAndPort = env->GetStaticMethodID(jclass_ConnectionsManager, "onRequestNewServerIpAndPort", "(I)V"); if (jclass_ConnectionsManager_onRequestNewServerIpAndPort == 0) { return JNI_FALSE; } ConnectionsManager::getInstance().setDelegate(new Delegate()); return JNI_TRUE; }
42.941176
326
0.71524
[ "object" ]
89882ccb929134b126e33a1e8505ea81f5546f7a
777
cpp
C++
lua/CLuaHook.cpp
DomesticTerrorist/Doubletap.Space-v3-SRC
caa2e09fc5e15a268ed735debe811a19fe96a08c
[ "MIT" ]
3
2021-08-18T10:19:25.000Z
2021-08-31T04:45:26.000Z
lua/CLuaHook.cpp
DomesticTerrorist/Doubletap.Space-v3-SRC
caa2e09fc5e15a268ed735debe811a19fe96a08c
[ "MIT" ]
null
null
null
lua/CLuaHook.cpp
DomesticTerrorist/Doubletap.Space-v3-SRC
caa2e09fc5e15a268ed735debe811a19fe96a08c
[ "MIT" ]
4
2021-08-18T06:57:26.000Z
2021-09-02T15:22:36.000Z
// This is an independent project of an individual developer. Dear PVS-Studio, please check it. // PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com #include "CLuaHook.h" void c_lua_hookManager::registerHook(std::string eventName, int scriptId, sol::protected_function func) { //-V813 c_lua_hook hk = { scriptId, func }; this->hooks[eventName].push_back(hk); } void c_lua_hookManager::unregisterHooks(int scriptId) { for (auto& ev : this->hooks) { int pos = 0; for (auto& hk : ev.second) { if (hk.scriptId == scriptId) ev.second.erase(ev.second.begin() + pos); pos++; } } } std::vector<c_lua_hook> c_lua_hookManager::getHooks(std::string eventName) { //-V813 return this->hooks[eventName]; }
27.75
114
0.671815
[ "vector" ]
899c3b39b631e254393bdc1a103fda346473c6fc
1,201
cpp
C++
examples/enumerate_examples.cpp
nd-nuclear-theory/cppitertools
539a5be8359c4330b3f88ed1821f32bb5c89f5f6
[ "BSD-2-Clause" ]
1,050
2015-01-12T21:20:01.000Z
2022-03-31T12:50:10.000Z
examples/enumerate_examples.cpp
nd-nuclear-theory/cppitertools
539a5be8359c4330b3f88ed1821f32bb5c89f5f6
[ "BSD-2-Clause" ]
67
2015-02-14T18:53:26.000Z
2022-03-30T06:03:38.000Z
examples/enumerate_examples.cpp
nd-nuclear-theory/cppitertools
539a5be8359c4330b3f88ed1821f32bb5c89f5f6
[ "BSD-2-Clause" ]
121
2015-01-21T00:21:22.000Z
2022-03-12T01:27:42.000Z
#include <enumerate.hpp> #include <string> #include <iostream> #include <vector> #include <cassert> int main() { std::cout << "enumerating the characters of a string \"hello\":\n"; const std::string const_string("hello"); for (auto&& [i, c] : iter::enumerate(const_string)) { std::cout << '(' << i << ", " << c << ") "; } std::cout << '\n'; std::vector<int> vec = {20, 30, 50}; std::cout << "enumerating a vector of {20, 30, 50}:\n"; for (auto&& [i, n] : iter::enumerate(vec)) { std::cout << '(' << i << ", " << n << ") "; n = 0; } std::cout << '\n'; assert(vec[0] == 0); assert(vec[1] == 0); assert(vec[2] == 0); // itertools supports raw arrays std::cout << "statically sized arrays can be enumerated\n"; int array[] = {1, 9, 8, 11}; for (auto&& [i, n] : iter::enumerate(array)) { std::cout << '(' << i << ", " << n << ") "; } std::cout << '\n'; // itertools supports temporaries std::cout << "vector temporary of {5, 2}\n"; for (auto&& [i, n] : iter::enumerate(std::vector<int>(5,2))) { std::cout << '(' << i << ", " << n << ") "; } std::cout << '\n'; }
27.930233
71
0.4796
[ "vector" ]
899dc070882db417914d65f6576541b1ebb6f452
315
hpp
C++
husky-sql/rexnode/dummy_combiner.hpp
Alice3150/husky-sql
40dc95b5543c079bb4ab070fca2ac2a287514333
[ "Apache-2.0" ]
null
null
null
husky-sql/rexnode/dummy_combiner.hpp
Alice3150/husky-sql
40dc95b5543c079bb4ab070fca2ac2a287514333
[ "Apache-2.0" ]
null
null
null
husky-sql/rexnode/dummy_combiner.hpp
Alice3150/husky-sql
40dc95b5543c079bb4ab070fca2ac2a287514333
[ "Apache-2.0" ]
null
null
null
#pragma once #include <string> #include <vector> namespace husky { namespace sql { class DummyCombiner { using ValT = std::vector<std::string>; public: static void combine(ValT& val, const ValT& inc) { /* do nothing */ } }; } // namespace sql } // namespace husky
16.578947
55
0.584127
[ "vector" ]
89bc882eb63f1a88f911c55a970612064ceb6fdb
1,072
cc
C++
ui/ozone/platform/dri/hardware_display_plane.cc
kjthegod/chromium
cf940f7f418436b77e15b1ea23e6fa100ca1c91a
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
1
2019-11-28T10:46:52.000Z
2019-11-28T10:46:52.000Z
ui/ozone/platform/dri/hardware_display_plane.cc
kjthegod/chromium
cf940f7f418436b77e15b1ea23e6fa100ca1c91a
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
null
null
null
ui/ozone/platform/dri/hardware_display_plane.cc
kjthegod/chromium
cf940f7f418436b77e15b1ea23e6fa100ca1c91a
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
2
2015-03-27T11:15:39.000Z
2016-08-17T14:19:56.000Z
// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/dri/hardware_display_plane.h" #include <drm.h> #include <errno.h> #include <xf86drm.h> #include "base/logging.h" #include "ui/gfx/geometry/rect.h" #include "ui/ozone/platform/dri/dri_wrapper.h" namespace ui { HardwareDisplayPlane::HardwareDisplayPlane(ScopedDrmPlanePtr plane) : plane_id_(plane->plane_id), possible_crtcs_(plane->possible_crtcs), owning_crtc_(0), in_use_(false) { } HardwareDisplayPlane::HardwareDisplayPlane(uint32_t plane_id, uint32_t possible_crtcs) : plane_id_(plane_id), possible_crtcs_(possible_crtcs), in_use_(false) { } HardwareDisplayPlane::~HardwareDisplayPlane() { } bool HardwareDisplayPlane::CanUseForCrtc(uint32_t crtc_index) { return possible_crtcs_ & (1 << crtc_index); } bool HardwareDisplayPlane::Initialize(DriWrapper* drm) { return true; } } // namespace ui
26.146341
76
0.725746
[ "geometry" ]
89c155f93298efdc6e3e5e7709b5fe4bb222d0a8
5,010
cpp
C++
imate/_c_linear_operator/c_csr_matrix.cpp
ameli/TraceInv
fe759af016c5845d88ca98e56994b6c86c132792
[ "BSD-3-Clause" ]
1
2021-08-21T12:12:28.000Z
2021-08-21T12:12:28.000Z
imate/_c_linear_operator/c_csr_matrix.cpp
ameli/TraceInv
fe759af016c5845d88ca98e56994b6c86c132792
[ "BSD-3-Clause" ]
null
null
null
imate/_c_linear_operator/c_csr_matrix.cpp
ameli/TraceInv
fe759af016c5845d88ca98e56994b6c86c132792
[ "BSD-3-Clause" ]
1
2021-08-21T12:12:44.000Z
2021-08-21T12:12:44.000Z
/* * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu> * SPDX-License-Identifier: BSD-3-Clause * SPDX-FileType: SOURCE * * This program is free software: you can redistribute it and/or modify it * under the terms of the license found in the LICENSE.txt file in the root * directory of this source tree. */ // ======= // Headers // ======= #include "./c_csr_matrix.h" #include <cstddef> // NULL #include "../_c_basic_algebra/c_matrix_operations.h" // cMatrixOperations // ============= // constructor 1 // ============= template <typename DataType> cCSRMatrix<DataType>::cCSRMatrix(): A_data(NULL), A_indices(NULL), A_index_pointer(NULL) { } // ============= // constructor 2 // ============= template <typename DataType> cCSRMatrix<DataType>::cCSRMatrix( const DataType* A_data_, const LongIndexType* A_indices_, const LongIndexType* A_index_pointer_, const LongIndexType num_rows_, const LongIndexType num_columns_): // Base class constructor cLinearOperator<DataType>(num_rows_, num_columns_), // Initializer list A_data(A_data_), A_indices(A_indices_), A_index_pointer(A_index_pointer_) { } // ========== // destructor // ========== template <typename DataType> cCSRMatrix<DataType>::~cCSRMatrix() { } // ================== // is identity matrix // ================== /// \brief Checks whether the matrix is identity. /// /// \details The identity check is primarily performed in the \c /// cAffineMatrixFunction class. /// /// \return Returns \c 1 if the input matrix is identity, and \c 0 otherwise. /// /// \sa cAffineMatrixFunction template <typename DataType> FlagType cCSRMatrix<DataType>::is_identity_matrix() const { FlagType matrix_is_identity = 1; LongIndexType index_pointer; LongIndexType column; // Check matrix element-wise for (LongIndexType row=0; row < this->num_rows; ++row) { for (index_pointer=this->A_index_pointer[row]; index_pointer < this->A_index_pointer[row+1]; ++index_pointer) { column = this->A_indices[index_pointer]; if ((row == column) && \ (this->A_data[index_pointer] != 1.0)) { matrix_is_identity = 0; return matrix_is_identity; } else if (this->A_data[index_pointer] != 0.0) { matrix_is_identity = 0; return matrix_is_identity; } } } return matrix_is_identity; } // ======= // get nnz // ======= /// \brief Returns the number of non-zero elements of the sparse matrix. /// /// \details The nnz of a CSR matrix can be obtained from the last element of /// \c A_index_pointer. The size of array \c A_index_pointer is one /// plus the number of rows of the matrix. /// /// \return The nnz of the matrix. template <typename DataType> LongIndexType cCSRMatrix<DataType>::get_nnz() const { return this->A_index_pointer[this->num_rows]; } // === // dot // === template <typename DataType> void cCSRMatrix<DataType>::dot( const DataType* vector, DataType* product) { cMatrixOperations<DataType>::csr_matvec( this->A_data, this->A_indices, this->A_index_pointer, vector, this->num_rows, product); } // ======== // dot plus // ======== template <typename DataType> void cCSRMatrix<DataType>::dot_plus( const DataType* vector, const DataType alpha, DataType* product) { cMatrixOperations<DataType>::csr_matvec_plus( this->A_data, this->A_indices, this->A_index_pointer, vector, alpha, this->num_rows, product); } // ============= // transpose dot // ============= template <typename DataType> void cCSRMatrix<DataType>::transpose_dot( const DataType* vector, DataType* product) { cMatrixOperations<DataType>::csr_transposed_matvec( this->A_data, this->A_indices, this->A_index_pointer, vector, this->num_rows, this->num_columns, product); } // ================== // transpose dot plus // ================== template <typename DataType> void cCSRMatrix<DataType>::transpose_dot_plus( const DataType* vector, const DataType alpha, DataType* product) { cMatrixOperations<DataType>::csr_transposed_matvec_plus( this->A_data, this->A_indices, this->A_index_pointer, vector, alpha, this->num_rows, product); } // =============================== // Explicit template instantiation // =============================== template class cCSRMatrix<float>; template class cCSRMatrix<double>; template class cCSRMatrix<long double>;
22.669683
79
0.583832
[ "vector" ]
89c627e8e1cb41d6a6078818251e5d912199e74d
803
cpp
C++
2022_03_15-QPainter/75-j-bol_cd.cpp
ss-di/1580-2021-08Z-Qt
2940d2f7f064a7f11e953925d0f8f19b0350af22
[ "MIT" ]
null
null
null
2022_03_15-QPainter/75-j-bol_cd.cpp
ss-di/1580-2021-08Z-Qt
2940d2f7f064a7f11e953925d0f8f19b0350af22
[ "MIT" ]
null
null
null
2022_03_15-QPainter/75-j-bol_cd.cpp
ss-di/1580-2021-08Z-Qt
2940d2f7f064a7f11e953925d0f8f19b0350af22
[ "MIT" ]
null
null
null
#include <bits/stdc++.h> #define fn(n) for (long _ = 0; _ < n; _ += 1) #define fin(i, n) for (i = 0; i < n; i += 1) using namespace std; int main() { long a; vector<long> v; while (cin >> a) v.push_back(a); long n = long(v.size()) - 1; long k = v.back(); v.resize(n); k = (n - k % n) % n; long st = 0; long cur = st; a = v[st]; long next = (cur + k) % n; fn(n) { if (next != st) { v[cur] = v[next]; cur = next; next = (next + k) % n; } else { v[cur] = a; st += 1; cur = st; a = v[st]; next = (cur + k) % n; } } long i; fin(i, n) { cout << v[i] << " "; } return 0; }
16.729167
45
0.347447
[ "vector" ]
89c6b185e1c5f535eee28961968a91f390e8e9fe
13,430
cc
C++
src/ui/a11y/lib/screen_reader/tests/explore_action_unittest.cc
casey/fuchsia
2b965e9a1e8f2ea346db540f3611a5be16bb4d6b
[ "BSD-3-Clause" ]
null
null
null
src/ui/a11y/lib/screen_reader/tests/explore_action_unittest.cc
casey/fuchsia
2b965e9a1e8f2ea346db540f3611a5be16bb4d6b
[ "BSD-3-Clause" ]
null
null
null
src/ui/a11y/lib/screen_reader/tests/explore_action_unittest.cc
casey/fuchsia
2b965e9a1e8f2ea346db540f3611a5be16bb4d6b
[ "BSD-3-Clause" ]
null
null
null
// Copyright 2019 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 "src/ui/a11y/lib/screen_reader/explore_action.h" #include <fuchsia/accessibility/cpp/fidl.h> #include <fuchsia/accessibility/semantics/cpp/fidl.h> #include <lib/gtest/test_loop_fixture.h> #include <lib/sys/cpp/component_context.h> #include <lib/sys/cpp/testing/component_context_provider.h> #include <src/ui/a11y/lib/screen_reader/tests/mocks/mock_tts_engine.h> #include <src/ui/a11y/lib/semantics/tests/mocks/mock_semantic_provider.h> #include "src/ui/a11y/bin/a11y_manager/tests/util/util.h" #include "src/ui/a11y/lib/screen_reader/focus/tests/mocks/mock_a11y_focus_manager.h" #include "src/ui/a11y/lib/screen_reader/screen_reader_context.h" #include "src/ui/a11y/lib/tts/tts_manager.h" #include "src/ui/a11y/lib/util/util.h" namespace accesibility_test { namespace { using fuchsia::accessibility::semantics::Attributes; using fuchsia::accessibility::semantics::Node; using fuchsia::accessibility::semantics::Role; // Arbitrary number to set a local coordinate when sending for hit testing. static const int kLocalCoordForTesting = 10; class ExploreActionTest : public gtest::TestLoopFixture { public: ExploreActionTest() : view_manager_(std::make_unique<a11y::SemanticTreeServiceFactory>(), context_provider_.context()->outgoing()->debug_dir()), tts_manager_(context_provider_.context()), semantic_provider_(&view_manager_) { action_context_.view_manager = &view_manager_; view_manager_.SetSemanticsEnabled(true); tts_manager_.OpenEngine(action_context_.tts_engine_ptr.NewRequest(), [](fuchsia::accessibility::tts::TtsManager_OpenEngine_Result result) { EXPECT_TRUE(result.is_response()); }); auto a11y_focus_manager = std::make_unique<accessibility_test::MockA11yFocusManager>(); a11y_focus_manager_ptr_ = a11y_focus_manager.get(); screen_reader_context_ = std::make_unique<a11y::ScreenReaderContext>(std::move(a11y_focus_manager)); // Setup tts and basic semantic support for this test. fidl::InterfaceHandle<fuchsia::accessibility::tts::Engine> engine_handle = mock_tts_engine_.GetHandle(); tts_manager_.RegisterEngine( std::move(engine_handle), [](fuchsia::accessibility::tts::EngineRegistry_RegisterEngine_Result result) { EXPECT_TRUE(result.is_response()); }); RunLoopUntilIdle(); // Creating test node to update. std::vector<Node> update_nodes; Node node = accessibility_test::CreateTestNode(0, "Label A"); update_nodes.push_back(std::move(node)); // Update the node created above. semantic_provider_.UpdateSemanticNodes(std::move(update_nodes)); RunLoopUntilIdle(); // Commit nodes. semantic_provider_.CommitUpdates(); RunLoopUntilIdle(); } ~ExploreActionTest() override = default; vfs::PseudoDir* debug_dir() { return context_provider_.context()->outgoing()->debug_dir(); } sys::testing::ComponentContextProvider context_provider_; a11y::ViewManager view_manager_; a11y::ScreenReaderAction::ActionContext action_context_; a11y::TtsManager tts_manager_; accessibility_test::MockSemanticProvider semantic_provider_; accessibility_test::MockTtsEngine mock_tts_engine_; std::unique_ptr<a11y::ScreenReaderContext> screen_reader_context_; accessibility_test::MockA11yFocusManager* a11y_focus_manager_ptr_; }; TEST_F(ExploreActionTest, SuccessfulExploreActionReadsLabel) { a11y::ExploreAction explore_action(&action_context_, screen_reader_context_.get()); a11y::ExploreAction::ActionData action_data; action_data.current_view_koid = semantic_provider_.koid(); // Note that x and y are set just for completeness of the data type. the semantic provider is // responsible for returning what was the hit based on these numbers. action_data.local_point.x = kLocalCoordForTesting; action_data.local_point.y = kLocalCoordForTesting; semantic_provider_.SetHitTestResult(0); EXPECT_FALSE(a11y_focus_manager_ptr_->IsSetA11yFocusCalled()); explore_action.Run(action_data); RunLoopUntilIdle(); // Checks that a new a11y focus was set. EXPECT_TRUE(a11y_focus_manager_ptr_->IsSetA11yFocusCalled()); auto focus = a11y_focus_manager_ptr_->GetA11yFocus(); ASSERT_TRUE(focus); EXPECT_EQ(focus->node_id, 0u); EXPECT_EQ(focus->view_ref_koid, semantic_provider_.koid()); EXPECT_TRUE(mock_tts_engine_.ReceivedSpeak()); // Check if Utterance and Speak functions are called in Tts. ASSERT_EQ(mock_tts_engine_.ExamineUtterances().size(), 1u); EXPECT_EQ(mock_tts_engine_.ExamineUtterances()[0].message(), "Label A"); } TEST_F(ExploreActionTest, HitTestFails) { a11y::ExploreAction explore_action(&action_context_, screen_reader_context_.get()); a11y::ExploreAction::ActionData action_data; action_data.current_view_koid = semantic_provider_.koid(); // Note that x and y are set just for completeness of the data type. the semantic provider is // responsible for returning what was the hit based on these numbers. action_data.local_point.x = 10; action_data.local_point.y = 10; // No node will be hit. semantic_provider_.SetHitTestResult(std::nullopt); explore_action.Run(action_data); RunLoopUntilIdle(); EXPECT_FALSE(a11y_focus_manager_ptr_->IsSetA11yFocusCalled()); EXPECT_TRUE(mock_tts_engine_.ExamineUtterances().empty()); EXPECT_FALSE(mock_tts_engine_.ReceivedSpeak()); } TEST_F(ExploreActionTest, SetA11yFocusFails) { a11y::ExploreAction explore_action(&action_context_, screen_reader_context_.get()); a11y::ExploreAction::ActionData action_data; action_data.current_view_koid = semantic_provider_.koid(); // Note that x and y are set just for completeness of the data type. the semantic provider is // responsible for returning what was the hit based on these numbers. action_data.local_point.x = 10; action_data.local_point.y = 10; semantic_provider_.SetHitTestResult(0); a11y_focus_manager_ptr_->set_should_set_a11y_focus_fail(true); explore_action.Run(action_data); RunLoopUntilIdle(); EXPECT_TRUE(a11y_focus_manager_ptr_->IsSetA11yFocusCalled()); auto focus = a11y_focus_manager_ptr_->GetA11yFocus(); ASSERT_TRUE(focus); EXPECT_NE(focus->node_id, 0u); EXPECT_NE(focus->view_ref_koid, semantic_provider_.koid()); EXPECT_TRUE(mock_tts_engine_.ExamineUtterances().empty()); EXPECT_FALSE(mock_tts_engine_.ReceivedSpeak()); } TEST_F(ExploreActionTest, GettingA11yFocusFails) { a11y::ExploreAction explore_action(&action_context_, screen_reader_context_.get()); a11y::ExploreAction::ActionData action_data; action_data.current_view_koid = semantic_provider_.koid(); // Note that x and y are set just for completeness of the data type. the semantic provider is // responsible for returning what was the hit based on these numbers. action_data.local_point.x = 10; action_data.local_point.y = 10; semantic_provider_.SetHitTestResult(0); a11y_focus_manager_ptr_->set_should_get_a11y_focus_fail(true); explore_action.Run(action_data); RunLoopUntilIdle(); EXPECT_TRUE(a11y_focus_manager_ptr_->IsSetA11yFocusCalled()); // We need to inspect the focus that was set by us, so flip the mock behavior. a11y_focus_manager_ptr_->set_should_get_a11y_focus_fail(false); auto focus = a11y_focus_manager_ptr_->GetA11yFocus(); ASSERT_TRUE(focus); EXPECT_EQ(focus->node_id, 0u); EXPECT_EQ(focus->view_ref_koid, semantic_provider_.koid()); EXPECT_TRUE(mock_tts_engine_.ExamineUtterances().empty()); EXPECT_FALSE(mock_tts_engine_.ReceivedSpeak()); } TEST_F(ExploreActionTest, HitTestNodeIDResultIsNotPresentInTheTree) { a11y::ExploreAction explore_action(&action_context_, screen_reader_context_.get()); a11y::ExploreAction::ActionData action_data; action_data.current_view_koid = semantic_provider_.koid(); // Note that x and y are set just for completeness of the data type. the semantic provider is // responsible for returning what was the hit based on these numbers. action_data.local_point.x = 10; action_data.local_point.y = 10; semantic_provider_.SetHitTestResult(100); explore_action.Run(action_data); RunLoopUntilIdle(); EXPECT_TRUE(a11y_focus_manager_ptr_->IsSetA11yFocusCalled()); EXPECT_TRUE(mock_tts_engine_.ExamineUtterances().empty()); EXPECT_FALSE(mock_tts_engine_.ReceivedSpeak()); } TEST_F(ExploreActionTest, NodeIsMissingLabelToBuildUtterance) { a11y::ExploreAction explore_action(&action_context_, screen_reader_context_.get()); a11y::ExploreAction::ActionData action_data; action_data.current_view_koid = semantic_provider_.koid(); // Note that x and y are set just for completeness of the data type. the semantic provider is // responsible for returning what was the hit based on these numbers. action_data.local_point.x = 10; action_data.local_point.y = 10; semantic_provider_.SetHitTestResult(2); Node node; node.set_node_id(2); // Do not set label, and update the node. std::vector<Node> updates; updates.push_back(std::move(node)); semantic_provider_.UpdateSemanticNodes(std::move(updates)); semantic_provider_.CommitUpdates(); RunLoopUntilIdle(); explore_action.Run(action_data); RunLoopUntilIdle(); EXPECT_TRUE(a11y_focus_manager_ptr_->IsSetA11yFocusCalled()); EXPECT_TRUE(mock_tts_engine_.ExamineUtterances().empty()); EXPECT_FALSE(mock_tts_engine_.ReceivedSpeak()); } TEST_F(ExploreActionTest, EnqueueTtsUtteranceFails) { a11y::ExploreAction explore_action(&action_context_, screen_reader_context_.get()); a11y::ExploreAction::ActionData action_data; action_data.current_view_koid = semantic_provider_.koid(); // Note that x and y are set just for completeness of the data type. the semantic provider is // responsible for returning what was the hit based on these numbers. action_data.local_point.x = 10; action_data.local_point.y = 10; semantic_provider_.SetHitTestResult(0); mock_tts_engine_.set_should_fail_enqueue(true); explore_action.Run(action_data); RunLoopUntilIdle(); EXPECT_TRUE(a11y_focus_manager_ptr_->IsSetA11yFocusCalled()); EXPECT_TRUE(mock_tts_engine_.ExamineUtterances().empty()); EXPECT_FALSE(mock_tts_engine_.ReceivedSpeak()); } TEST_F(ExploreActionTest, SpeakFails) { a11y::ExploreAction explore_action(&action_context_, screen_reader_context_.get()); a11y::ExploreAction::ActionData action_data; action_data.current_view_koid = semantic_provider_.koid(); // Note that x and y are set just for completeness of the data type. the semantic provider is // responsible for returning what was the hit based on these numbers. action_data.local_point.x = 10; action_data.local_point.y = 10; semantic_provider_.SetHitTestResult(0); mock_tts_engine_.set_should_fail_speak(true); explore_action.Run(action_data); RunLoopUntilIdle(); EXPECT_TRUE(a11y_focus_manager_ptr_->IsSetA11yFocusCalled()); // It received the utterances, but failed Speak() later. ASSERT_EQ(mock_tts_engine_.ExamineUtterances().size(), 1u); EXPECT_EQ(mock_tts_engine_.ExamineUtterances()[0].message(), "Label A"); EXPECT_FALSE(mock_tts_engine_.ReceivedSpeak()); } TEST_F(ExploreActionTest, ContinuousExploreSpeaksNodeWhenA11yFocusIsDifferent) { a11y::ExploreAction explore_action(&action_context_, screen_reader_context_.get()); a11y::ExploreAction::ActionData action_data; action_data.current_view_koid = semantic_provider_.koid(); // Note that x and y are set just for completeness of the data type. the semantic provider is // responsible for returning what was the hit based on these numbers. action_data.local_point.x = kLocalCoordForTesting; action_data.local_point.y = kLocalCoordForTesting; semantic_provider_.SetHitTestResult(0); screen_reader_context_->set_mode( a11y::ScreenReaderContext::ScreenReaderMode::kContinuousExploration); explore_action.Run(action_data); RunLoopUntilIdle(); // Checks that a new a11y focus was set. EXPECT_TRUE(a11y_focus_manager_ptr_->IsSetA11yFocusCalled()); auto focus = a11y_focus_manager_ptr_->GetA11yFocus(); ASSERT_TRUE(focus); EXPECT_EQ(focus->node_id, 0u); EXPECT_EQ(focus->view_ref_koid, semantic_provider_.koid()); EXPECT_TRUE(mock_tts_engine_.ReceivedSpeak()); } TEST_F(ExploreActionTest, ContinuousExploreDropsWhenA11yFocusIsTheSame) { a11y::ExploreAction explore_action(&action_context_, screen_reader_context_.get()); a11y::ExploreAction::ActionData action_data; action_data.current_view_koid = semantic_provider_.koid(); // Note that x and y are set just for completeness of the data type. the semantic provider is // responsible for returning what was the hit based on these numbers. action_data.local_point.x = kLocalCoordForTesting; action_data.local_point.y = kLocalCoordForTesting; semantic_provider_.SetHitTestResult(0); screen_reader_context_->set_mode( a11y::ScreenReaderContext::ScreenReaderMode::kContinuousExploration); a11y_focus_manager_ptr_->SetA11yFocus(semantic_provider_.koid(), 0, [](auto...) {}); explore_action.Run(action_data); RunLoopUntilIdle(); EXPECT_FALSE(mock_tts_engine_.ReceivedSpeak()); EXPECT_TRUE(mock_tts_engine_.ExamineUtterances().empty()); } } // namespace } // namespace accesibility_test
41.070336
98
0.777811
[ "vector" ]
89cdd70ee4be50aff7ca6699b4ab00c1a9b128dd
4,577
hpp
C++
src/math/ipp_dft.hpp
mfkiwl/ugsdr
7ce479c17ecbf00cf06b5e17bb00fb3d2d45d5d3
[ "MIT" ]
4
2021-09-18T03:13:45.000Z
2021-12-17T07:52:17.000Z
src/math/ipp_dft.hpp
mfkiwl/ugsdr
7ce479c17ecbf00cf06b5e17bb00fb3d2d45d5d3
[ "MIT" ]
3
2021-11-27T01:24:22.000Z
2022-02-22T21:02:55.000Z
src/math/ipp_dft.hpp
mfkiwl/ugsdr
7ce479c17ecbf00cf06b5e17bb00fb3d2d45d5d3
[ "MIT" ]
2
2021-09-18T01:30:11.000Z
2021-09-18T05:22:05.000Z
#pragma once #ifdef HAS_IPP #include "dft.hpp" #include "ipp.h" #include "../../external/plusifier/Plusifier.hpp" #include "../../external/type_map/include/type_map.hpp" #include <type_traits> namespace ugsdr { class IppDft : public DiscreteFourierTransform<IppDft> { private: static auto GetConversionWrapper() { static auto conversion_wrapper = plusifier::FunctionWrapper( ippsConvert_8u32f, ippsConvert_8s32f, ippsConvert_16u32f, ippsConvert_16s32f, ippsConvert_32s32f); // if required, add lambdas for 32u32f, 64s32f etc return conversion_wrapper; } static auto& GetSpec() { static thread_local auto spec = plusifier::PointerWrapper<Ipp8u, ippsFree>(); return spec; } static auto& GetInitializationBuffer() { static thread_local auto init_buf = plusifier::PointerWrapper<Ipp8u, ippsFree>(); return init_buf; } static auto& GetWorkBuffer() { static thread_local auto work_buf = plusifier::PointerWrapper<Ipp8u, ippsFree>(); return work_buf; } template <typename UnderlyingType> static void SetDftSizes(std::size_t signal_size) { static thread_local std::size_t current_size = 0; if (current_size == signal_size) return; current_size = signal_size; Ipp32s spec_size = 0; Ipp32s init_size = 0; Ipp32s work_size = 0; IppDftFunctions<UnderlyingType>::GetSize(static_cast<int>(signal_size), IPP_FFT_DIV_INV_BY_N, ippAlgHintNone, &spec_size, &init_size, &work_size); GetSpec() = plusifier::PointerWrapper<Ipp8u, ippsFree>(ippsMalloc_8u, spec_size); GetInitializationBuffer() = plusifier::PointerWrapper<Ipp8u, ippsFree>(ippsMalloc_8u, init_size); GetWorkBuffer() = plusifier::PointerWrapper<Ipp8u, ippsFree>(ippsMalloc_8u, work_size); Ipp8u* spec_ptr = GetSpec(); using DftSpecType = typename IppDftFunctions<UnderlyingType>::SpecType; IppDftFunctions<UnderlyingType>::GetInit(static_cast<int>(signal_size), IPP_FFT_DIV_INV_BY_N, ippAlgHintNone, reinterpret_cast<DftSpecType*>(spec_ptr), GetInitializationBuffer()); } protected: friend class DiscreteFourierTransform<IppDft>; template <typename T> struct IppDftFunctions { using DftGetSize = mk::TypeMap< mk::TypeValuePair<float, ippsDFTGetSize_C_32fc>, mk::TypeValuePair<double, ippsDFTGetSize_C_64fc> >; using DftInit = mk::TypeMap< mk::TypeValuePair<float, ippsDFTInit_C_32fc>, mk::TypeValuePair<double, ippsDFTInit_C_64fc> >; using DftInverse = mk::TypeMap< mk::TypeValuePair<float, ippsDFTInv_CToC_32fc>, mk::TypeValuePair<double, ippsDFTInv_CToC_64fc> >; using DftForward = mk::TypeMap< mk::TypeValuePair<float, ippsDFTFwd_CToC_32fc>, mk::TypeValuePair<double, ippsDFTFwd_CToC_64fc> >; using DftSpecType = mk::TypeMap< mk::TypePair<float, IppsDFTSpec_C_32fc>, mk::TypePair<double, IppsDFTSpec_C_64fc> >; template <typename ... Args> static auto GetSize(Args &&... args) { return DftGetSize::GetValueByType<T>()(args...); } template <typename ... Args> static auto GetInit(Args &&... args) { return DftInit::GetValueByType<T>()(args...); } static auto GetInverse() { return DftInverse::GetValueByType<T>(); } static auto GetForward() { return DftForward::GetValueByType<T>(); } using SpecType = DftSpecType::GetTypeByType<T>; }; template <typename UnderlyingType> static void Process(std::vector<std::complex<UnderlyingType>>& src_dst, bool is_inverse = false) { static_assert(std::is_floating_point_v<UnderlyingType>, R"(Only floating point types are supported, convert integers in the const overload)"); SetDftSizes<UnderlyingType>(src_dst.size()); Ipp8u* spec_ptr = GetSpec(); using DftSpecType = typename IppDftFunctions<UnderlyingType>::SpecType; using IppType = typename IppTypeToComplex<UnderlyingType>::Type; auto dft_routine = is_inverse ? IppDftFunctions<UnderlyingType>::GetInverse() : IppDftFunctions<UnderlyingType>::GetForward(); dft_routine(reinterpret_cast<IppType*>(src_dst.data()), reinterpret_cast<IppType*>(src_dst.data()), reinterpret_cast<DftSpecType*>(spec_ptr), GetWorkBuffer()); } template <typename T> static auto Process(const std::vector<T>& src, bool is_inverse = false) { std::vector<std::complex<T>> dst(src.begin(), src.end()); Process(dst, is_inverse); return dst; } template <typename UnderlyingType> static auto Process(const std::vector<std::complex<UnderlyingType>>& src, bool is_inverse = false) { auto dst = src; Process(dst, is_inverse); return dst; } }; } #endif
34.156716
182
0.728862
[ "vector" ]
89d326604a252699f686061520ab7ab690313430
2,126
cpp
C++
samples/cifar10_conv/readCIFAR10.cpp
adajed/DeepLearningCPP
2fa4d57b75c145e918a8906b7404284628baa116
[ "MIT" ]
10
2019-03-04T09:37:19.000Z
2021-12-08T03:09:44.000Z
samples/cifar10_conv/readCIFAR10.cpp
adajed/DeepLearningCPP
2fa4d57b75c145e918a8906b7404284628baa116
[ "MIT" ]
null
null
null
samples/cifar10_conv/readCIFAR10.cpp
adajed/DeepLearningCPP
2fa4d57b75c145e918a8906b7404284628baa116
[ "MIT" ]
1
2021-12-08T03:09:44.000Z
2021-12-08T03:09:44.000Z
#include "readCIFAR10.h" #include <algorithm> #include <cassert> #include <fstream> #include <iostream> #include <numeric> #include <random> bool fileExists(const std::string& path) { std::ifstream f(path.c_str()); if (!f.good()) { std::cout << "File \"" << path << "\" does not exists, please download it." << std::endl; return false; } return true; } void parse(const std::string& path, std::vector<std::vector<float>>& xs, std::vector<std::vector<float>>& ys) { std::ifstream file(path); for (int n = 0; n < 10000; ++n) { std::vector<float> x(3072); std::vector<float> y(10, 0.); char byte; file.read(&byte, sizeof(char)); y[int(byte)] = 1.; for (int c = 0; c < 3; ++c) { for (int i = 0; i < 1024; ++i) { file.read(&byte, sizeof(char)); x[3 * i + c] = float(byte) / 127. - 1.; } } ys.push_back(y); xs.push_back(x); } } Cifar10Dataset::Cifar10Dataset(const std::vector<std::string>& paths, int batchSize) : mBatchSize(batchSize), mPos(0) { for (const auto& path : paths) assert(fileExists(path)); for (const auto& path : paths) parse(path, mX, mY); mIndexes = std::vector<int>(mX.size()); std::iota(mIndexes.begin(), mIndexes.end(), 0); std::shuffle(mIndexes.begin(), mIndexes.end(), std::mt19937(std::random_device()())); } int Cifar10Dataset::getNumBatches() const { return mX.size() / mBatchSize; } std::vector<std::vector<float>> Cifar10Dataset::getNextBatch() { std::vector<float> batchX, batchY; for (int n = 0; n < mBatchSize; ++n) { int i = mIndexes[mPos + n]; for (float f : mX[i]) batchX.push_back(f); for (float f : mY[i]) batchY.push_back(f); } mPos += mBatchSize; return {batchX, batchY}; } void Cifar10Dataset::reset() { mPos = 0; std::shuffle(mIndexes.begin(), mIndexes.end(), std::mt19937(std::random_device()())); }
24.159091
76
0.537159
[ "vector" ]
89d386edc52ce0aa49222a130b93043f5cfdd078
5,140
cpp
C++
export/windows/obj/src/lime/graphics/opengl/ext/APPLE_rgb_422.cpp
seanbashaw/frozenlight
47c540d30d63e946ea2dc787b4bb602cc9347d21
[ "MIT" ]
null
null
null
export/windows/obj/src/lime/graphics/opengl/ext/APPLE_rgb_422.cpp
seanbashaw/frozenlight
47c540d30d63e946ea2dc787b4bb602cc9347d21
[ "MIT" ]
null
null
null
export/windows/obj/src/lime/graphics/opengl/ext/APPLE_rgb_422.cpp
seanbashaw/frozenlight
47c540d30d63e946ea2dc787b4bb602cc9347d21
[ "MIT" ]
null
null
null
// Generated by Haxe 3.4.7 #include <hxcpp.h> #ifndef INCLUDED_lime_graphics_opengl_ext_APPLE_rgb_422 #include <lime/graphics/opengl/ext/APPLE_rgb_422.h> #endif HX_DEFINE_STACK_FRAME(_hx_pos_7884905029fdefd8_6_new,"lime.graphics.opengl.ext.APPLE_rgb_422","new",0x2a5502cd,"lime.graphics.opengl.ext.APPLE_rgb_422.new","lime/graphics/opengl/ext/APPLE_rgb_422.hx",6,0xcbee61e5) namespace lime{ namespace graphics{ namespace opengl{ namespace ext{ void APPLE_rgb_422_obj::__construct(){ HX_STACKFRAME(&_hx_pos_7884905029fdefd8_6_new) HXLINE( 11) this->UNSIGNED_SHORT_8_8_REV_APPLE = (int)34235; HXLINE( 10) this->UNSIGNED_SHORT_8_8_APPLE = (int)34234; HXLINE( 9) this->RGB_422_APPLE = (int)35359; } Dynamic APPLE_rgb_422_obj::__CreateEmpty() { return new APPLE_rgb_422_obj; } void *APPLE_rgb_422_obj::_hx_vtable = 0; Dynamic APPLE_rgb_422_obj::__Create(hx::DynamicArray inArgs) { hx::ObjectPtr< APPLE_rgb_422_obj > _hx_result = new APPLE_rgb_422_obj(); _hx_result->__construct(); return _hx_result; } bool APPLE_rgb_422_obj::_hx_isInstanceOf(int inClassId) { return inClassId==(int)0x00000001 || inClassId==(int)0x293b7713; } APPLE_rgb_422_obj::APPLE_rgb_422_obj() { } hx::Val APPLE_rgb_422_obj::__Field(const ::String &inName,hx::PropertyAccess inCallProp) { switch(inName.length) { case 13: if (HX_FIELD_EQ(inName,"RGB_422_APPLE") ) { return hx::Val( RGB_422_APPLE ); } break; case 24: if (HX_FIELD_EQ(inName,"UNSIGNED_SHORT_8_8_APPLE") ) { return hx::Val( UNSIGNED_SHORT_8_8_APPLE ); } break; case 28: if (HX_FIELD_EQ(inName,"UNSIGNED_SHORT_8_8_REV_APPLE") ) { return hx::Val( UNSIGNED_SHORT_8_8_REV_APPLE ); } } return super::__Field(inName,inCallProp); } hx::Val APPLE_rgb_422_obj::__SetField(const ::String &inName,const hx::Val &inValue,hx::PropertyAccess inCallProp) { switch(inName.length) { case 13: if (HX_FIELD_EQ(inName,"RGB_422_APPLE") ) { RGB_422_APPLE=inValue.Cast< int >(); return inValue; } break; case 24: if (HX_FIELD_EQ(inName,"UNSIGNED_SHORT_8_8_APPLE") ) { UNSIGNED_SHORT_8_8_APPLE=inValue.Cast< int >(); return inValue; } break; case 28: if (HX_FIELD_EQ(inName,"UNSIGNED_SHORT_8_8_REV_APPLE") ) { UNSIGNED_SHORT_8_8_REV_APPLE=inValue.Cast< int >(); return inValue; } } return super::__SetField(inName,inValue,inCallProp); } void APPLE_rgb_422_obj::__GetFields(Array< ::String> &outFields) { outFields->push(HX_HCSTRING("RGB_422_APPLE","\x5d","\x91","\xdf","\xea")); outFields->push(HX_HCSTRING("UNSIGNED_SHORT_8_8_APPLE","\xff","\x40","\x5e","\x85")); outFields->push(HX_HCSTRING("UNSIGNED_SHORT_8_8_REV_APPLE","\x43","\x98","\x55","\x0b")); super::__GetFields(outFields); }; #if HXCPP_SCRIPTABLE static hx::StorageInfo APPLE_rgb_422_obj_sMemberStorageInfo[] = { {hx::fsInt,(int)offsetof(APPLE_rgb_422_obj,RGB_422_APPLE),HX_HCSTRING("RGB_422_APPLE","\x5d","\x91","\xdf","\xea")}, {hx::fsInt,(int)offsetof(APPLE_rgb_422_obj,UNSIGNED_SHORT_8_8_APPLE),HX_HCSTRING("UNSIGNED_SHORT_8_8_APPLE","\xff","\x40","\x5e","\x85")}, {hx::fsInt,(int)offsetof(APPLE_rgb_422_obj,UNSIGNED_SHORT_8_8_REV_APPLE),HX_HCSTRING("UNSIGNED_SHORT_8_8_REV_APPLE","\x43","\x98","\x55","\x0b")}, { hx::fsUnknown, 0, null()} }; static hx::StaticInfo *APPLE_rgb_422_obj_sStaticStorageInfo = 0; #endif static ::String APPLE_rgb_422_obj_sMemberFields[] = { HX_HCSTRING("RGB_422_APPLE","\x5d","\x91","\xdf","\xea"), HX_HCSTRING("UNSIGNED_SHORT_8_8_APPLE","\xff","\x40","\x5e","\x85"), HX_HCSTRING("UNSIGNED_SHORT_8_8_REV_APPLE","\x43","\x98","\x55","\x0b"), ::String(null()) }; static void APPLE_rgb_422_obj_sMarkStatics(HX_MARK_PARAMS) { HX_MARK_MEMBER_NAME(APPLE_rgb_422_obj::__mClass,"__mClass"); }; #ifdef HXCPP_VISIT_ALLOCS static void APPLE_rgb_422_obj_sVisitStatics(HX_VISIT_PARAMS) { HX_VISIT_MEMBER_NAME(APPLE_rgb_422_obj::__mClass,"__mClass"); }; #endif hx::Class APPLE_rgb_422_obj::__mClass; void APPLE_rgb_422_obj::__register() { hx::Object *dummy = new APPLE_rgb_422_obj; APPLE_rgb_422_obj::_hx_vtable = *(void **)dummy; hx::Static(__mClass) = new hx::Class_obj(); __mClass->mName = HX_HCSTRING("lime.graphics.opengl.ext.APPLE_rgb_422","\x5b","\x98","\xf6","\x0a"); __mClass->mSuper = &super::__SGetClass(); __mClass->mConstructEmpty = &__CreateEmpty; __mClass->mConstructArgs = &__Create; __mClass->mGetStaticField = &hx::Class_obj::GetNoStaticField; __mClass->mSetStaticField = &hx::Class_obj::SetNoStaticField; __mClass->mMarkFunc = APPLE_rgb_422_obj_sMarkStatics; __mClass->mStatics = hx::Class_obj::dupFunctions(0 /* sStaticFields */); __mClass->mMembers = hx::Class_obj::dupFunctions(APPLE_rgb_422_obj_sMemberFields); __mClass->mCanCast = hx::TCanCast< APPLE_rgb_422_obj >; #ifdef HXCPP_VISIT_ALLOCS __mClass->mVisitFunc = APPLE_rgb_422_obj_sVisitStatics; #endif #ifdef HXCPP_SCRIPTABLE __mClass->mMemberStorageInfo = APPLE_rgb_422_obj_sMemberStorageInfo; #endif #ifdef HXCPP_SCRIPTABLE __mClass->mStaticStorageInfo = APPLE_rgb_422_obj_sStaticStorageInfo; #endif hx::_hx_RegisterClass(__mClass->mName, __mClass); } } // end namespace lime } // end namespace graphics } // end namespace opengl } // end namespace ext
36.978417
213
0.759144
[ "object" ]
89d918175050e3c1f77b14efde2e61e783907b55
964
cpp
C++
Stp/Json/JsonError.cpp
markazmierczak/Polonite
240f099cafc5c38dc1ae1cc6fc5773e13f65e9de
[ "MIT" ]
1
2019-07-11T12:47:52.000Z
2019-07-11T12:47:52.000Z
Stp/Json/JsonError.cpp
Polonite/Polonite
240f099cafc5c38dc1ae1cc6fc5773e13f65e9de
[ "MIT" ]
null
null
null
Stp/Json/JsonError.cpp
Polonite/Polonite
240f099cafc5c38dc1ae1cc6fc5773e13f65e9de
[ "MIT" ]
1
2019-07-11T12:47:53.000Z
2019-07-11T12:47:53.000Z
// Copyright 2017 Polonite Authors. All rights reserved. // Distributed under MIT license that can be found in the LICENSE file. #include "Json/JsonError.h" #include "Base/Io/TextWriter.h" namespace stp { void JsonError::ToFormat(TextWriter& out, const StringSpan& opts) const { if (line > 0) { out << '['; out << line; if (column > 0) { out << ':'; out << column; } out << "] "; } out << CodeToMessage(code); } static constexpr StringSpan Messages[] = { "ok", "invalid escape sequence", "syntax error", "unexpected token", "trailing comma not allowed", "too much nesting", "unexpected data after root element", "unsupported encoding", "object keys must be quoted", "loss of precision", "invalid number", "key already assigned", }; static_assert(isizeofArray(Messages) == JsonError::CodeCount, "!"); StringSpan JsonError::CodeToMessage(Code code) { return Messages[code]; } } // namespace stp
21.909091
73
0.657676
[ "object" ]
89e30e6eab87c8552f1e9799b468837a6cc41169
955
cpp
C++
src/jw/leetcode/1654/main.cpp
wanyaworld/algo-study
d540e9a72bb251a6bf2b04bc3aa7edbf17bee974
[ "MIT" ]
1
2020-10-31T15:28:43.000Z
2020-10-31T15:28:43.000Z
src/jw/leetcode/1654/main.cpp
wanyaworld/algo-study
d540e9a72bb251a6bf2b04bc3aa7edbf17bee974
[ "MIT" ]
null
null
null
src/jw/leetcode/1654/main.cpp
wanyaworld/algo-study
d540e9a72bb251a6bf2b04bc3aa7edbf17bee974
[ "MIT" ]
null
null
null
class Solution { public: int visited[2][2000001]; unordered_map<int, int> forb{}; int thr = 10000000; int dfs(vector<int>& forbidden, int a, int b, int x, int cur, bool prv_was_back) { if (cur == x) return 0; if (cur > 100000 || cur < 0) return thr; if (forb.find(cur) != forb.end()) return thr; if (visited[(int)prv_was_back][cur]) return thr; visited[(int)prv_was_back][cur] = 1; if (prv_was_back) return dfs(forbidden, a, b, x, cur + a, false) + 1; return min(dfs(forbidden, a, b, x, cur + a, false), dfs(forbidden, a, b, x, cur - b, true)) + 1; } int minimumJumps(vector<int>& forbidden, int a, int b, int x) { for (auto it = forbidden.begin() ; it != forbidden.end() ; it++) { forb[*it] = 1; } auto ret = dfs(forbidden, a, b, x, 0, false); if (ret >= thr) return -1; return ret; } };
35.37037
86
0.528796
[ "vector" ]
8851f99697b9ca7bd7550d04d918ebce19711a38
7,470
cpp
C++
examples/basic.cpp
KeinR/Etermal
9bf66f6be6ae8585b763dd902701e72013a5abcc
[ "MIT" ]
null
null
null
examples/basic.cpp
KeinR/Etermal
9bf66f6be6ae8585b763dd902701e72013a5abcc
[ "MIT" ]
null
null
null
examples/basic.cpp
KeinR/Etermal
9bf66f6be6ae8585b763dd902701e72013a5abcc
[ "MIT" ]
null
null
null
/** * Basic Etermal example using the built * in ETerminal and EShell implementations. * This particular example uses glfw. */ #include <etermal/etermal.h> #include <iostream> #include <chrono> #include <thread> // Re-using the GLAD files used by Etermal itself - // you can generate your own. #define GLFW_DLL 1 #include "../extern/glad/glad.h" #include <glfw/glfw3.h> static void mouseScroll(GLFWwindow* window, double xoffset, double yoffset); static void keyPress(GLFWwindow* window, int key, int scancode, int action, int mods); static void mouseClick(GLFWwindow* window, int button, int action, int mods); static void mouseMove(GLFWwindow* window, double xpos, double ypos); static void charCallback(GLFWwindow* window, unsigned int codepoint); static void errorCallback(int error, const char* description); // This is only for demonstrative purposes - // obviously, you won't actually have it global. static etm::Terminal terminal( std::make_shared<etm::Font>("c:\\windows\\fonts\\lucon.ttf"), // Font to use true // `true` to postpone initialization (because there's no active OpenGL context) ); int main() { // Just in case glfwSetErrorCallback(errorCallback); if (glfwInit() == GLFW_FALSE) { std::cerr << "Failed to initialze GLFW" << std::endl; return 1; } glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_SAMPLES, 0); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); GLFWwindow *window = glfwCreateWindow(1000, 700, "Etermal example", NULL, NULL); if (window == NULL) { std::cerr << "Failed to make GLFW window" << std::endl; return 1; } glfwMakeContextCurrent(window); if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { std::cerr << "Failed to initialize GLAD" << std::endl; return 1; } // Set all the callbacks glfwSetScrollCallback(window, mouseScroll); glfwSetKeyCallback(window, keyPress); glfwSetMouseButtonCallback(window, mouseClick); glfwSetCursorPosCallback(window, mouseMove); glfwSetInputMode(window, GLFW_LOCK_KEY_MODS, GLFW_TRUE); glfwSetCharCallback(window, charCallback); // Cursor for terminal hover GLFWcursor* ibeam = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); terminal.setWidth(700); terminal.setHeight(700); terminal.setScrollCooldown(75); terminal.setScrollWait(200); terminal.setCursorDefault([window]()->void{ glfwSetCursor(window, NULL); }); terminal.setCursorIBeam([window, ibeam]()->void{ glfwSetCursor(window, ibeam); }); terminal.setMaxLines(200); std::ostream stream(&terminal); etm::Shell shell; shell.setPrompt("\n\e[B\e[f199e3d;example@\e[b4c1b4f;some terminal somewhere\e[B \e[fb8b816;~\e[F\n$ "); terminal.setShell(shell); shell.setTerminal(terminal); etm::ArgFilter clearFilter; clearFilter.setUsage("Usage: clear\n"); clearFilter.setMaxArrayArgs(0); shell.addCommand("clear", clearFilter, [](etm::Shell&,etm::ETerminal &terminal,etm::Args&)->void{ terminal.clear(); }); etm::ArgFilter exitFilter; exitFilter.setMaxArrayArgs(0); exitFilter.setUsage("Usage: [exit|leave|stop|terminate|cya|bye]\n"); shell.addCommand("exit", exitFilter, [window](etm::Shell&,etm::ETerminal &terminal,etm::Args&)->void{ glfwSetWindowShouldClose(window, true); }); shell.alias("leave"); shell.alias("stop"); shell.alias("terminate"); shell.alias("cya"); shell.alias("bye"); etm::ArgFilter echoFilter; echoFilter.setUsage("Usage: echo [string]\n"); echoFilter.setMaxArrayArgs(10000); shell.addCommand("echo", echoFilter, [&stream](etm::Shell&,etm::ETerminal&,etm::Args &args)->void{ for (std::string &s : args.getArrayArgs()) { stream << s << " "; } stream << "\n"; }); ///////////////// // Make extra sure that the window is current // before initializing the terminal! glfwMakeContextCurrent(window); // Since we set late initialization to true, // MUST call init before render! terminal.init(); ///////////////// // 60 FPS constexpr float secondsPerFrame = 1.0f / 60.0f; float endTime = 0; while (!glfwWindowShouldClose(window)) { // Don't render until frame cooldown is done if (glfwGetTime() >= endTime) { endTime = glfwGetTime() + secondsPerFrame; glClearColor(0.8f, 0.8f, 0.8f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // Render the terminal terminal.render(); glfwSwapBuffers(window); } else { // Sleep a little so that our CPU usage isn't super high std::this_thread::sleep_for(std::chrono::milliseconds(1)); } glfwPollEvents(); } // Free OpenGL resources before we terminate the context terminal.deInit(); glfwDestroyWindow(window); glfwTerminate(); return 0; } void mouseScroll(GLFWwindow* window, double xoffset, double yoffset) { double mouseX, mouseY; glfwGetCursorPos(glfwGetCurrentContext(), &mouseX, &mouseY); terminal.inputMouseScroll( static_cast<float>(yoffset), static_cast<float>(mouseX), static_cast<float>(mouseY) ); } void keyPress(GLFWwindow *window, int key, int scancode, int action, int mods) { if (action == GLFW_RELEASE) return; if (terminal.isFocused()) { switch (key) { case GLFW_KEY_ENTER: terminal.inputActionKey(etm::actionKey::ENTER); break; case GLFW_KEY_BACKSPACE: terminal.inputActionKey(etm::actionKey::BACKSPACE); break; case GLFW_KEY_UP: terminal.inputActionKey(etm::actionKey::UP); break; case GLFW_KEY_DOWN: terminal.inputActionKey(etm::actionKey::DOWN); break; case GLFW_KEY_LEFT: terminal.inputActionKey(etm::actionKey::LEFT); break; case GLFW_KEY_RIGHT: terminal.inputActionKey(etm::actionKey::RIGHT); break; case GLFW_KEY_C: if ((mods & GLFW_MOD_CONTROL) == GLFW_MOD_CONTROL) { glfwSetClipboardString(window, terminal.getTextSelection().c_str()); } break; case GLFW_KEY_V: if ((mods & GLFW_MOD_CONTROL) == GLFW_MOD_CONTROL) { terminal.inputString(glfwGetClipboardString(window)); } break; } } } static void charCallback(GLFWwindow* window, unsigned int codepoint) { terminal.inputChar(codepoint); } void mouseClick(GLFWwindow* window, int button, int action, int mods) { double mouseX, mouseY; glfwGetCursorPos(glfwGetCurrentContext(), &mouseX, &mouseY); terminal.inputMouseClick( action == GLFW_PRESS, static_cast<float>(mouseX), static_cast<float>(mouseY) ); } void mouseMove(GLFWwindow* window, double xpos, double ypos) { terminal.inputMouseMove(static_cast<float>(xpos), static_cast<float>(ypos)); } void errorCallback(int error, const char* description) { std::cerr << "GLFW ERROR: " << description << std::endl; }
32.198276
108
0.641633
[ "render" ]
885ca7b6a48fa374afac359b7391c948b1701778
2,906
hh
C++
src/PerplexityFuncs.hh
psmit/variKN
9623c5909bb43a5e3f9bb4df850284e30784e957
[ "BSD-3-Clause" ]
null
null
null
src/PerplexityFuncs.hh
psmit/variKN
9623c5909bb43a5e3f9bb4df850284e30784e957
[ "BSD-3-Clause" ]
null
null
null
src/PerplexityFuncs.hh
psmit/variKN
9623c5909bb43a5e3f9bb4df850284e30784e957
[ "BSD-3-Clause" ]
null
null
null
// Functions for calculating perplexity #ifndef PERPLEXITY_HH #define PERPLEXITY_HH #include <iostream> #include <deque> #include <string> #include <vector> #include <math.h> #include "io.hh" #include "NGram.hh" class Perplexity { public: Perplexity(const char *); Perplexity(NGram *lm, const std::string ccs_name, const std::string wb_name, const std::string mb_name, const std::string unk_symbol, bool skip_unk_prob=true); Perplexity(const std::string lm_name, const int type, const std::string ccs_name, const std::string wb_name, const std::string mb_name, const std::string unk_symbol, const int hashgram, bool skip_unk_prob=true); ~Perplexity(); double logprob_file(FILE *in, FILE *out, const int interval=1); float logprob(const char *word, float &cur_word_lp); inline float token_logprob(const char *word) { float tmp; return logprob(word, tmp); }; float sentence_logprob(const char *sentence); void print_hitrates(FILE *out); double print_results(FILE *out); enum wb_type { EVERYTIME=0, LISTED=1, MB_LISTED=2 }; void set_wb_type(wb_type type) {m_wb_type=type;} void set_unk_warn(bool w) {m_print_unk_warn=w;} bool bryan_wc; // For interpolation inline void set_alpha(float a) {assert(a>=0 && a<=1.0);m_alpha=a;} // The interpolated language models must have the same vocabulary ! void set_interpolation(std::string lm_name); inline void set_init_hist(int i) {m_init_hist=m_cur_init_hist=i;} // For interspeech2010 analysis void reset_hitrates(); int get_hitorder(int i); void clear_history() { history.clear(); m_cur_init_hist=m_init_hist; } inline int get_num_tunks() { return m_num_tunks; } private: NGram *m_lm; NGram *m_lm2; std::vector<int> ccs_vector; std::vector<int> wb_vector; std::vector<std::string> mb_vector; std::deque<int> history; std::vector<int> ngram_hits; void find_indices(const std::string,std::vector<int> &); void load_mbs(const std::string, std::vector<std::string> &); void init_variables(); void init_special_symbols(const std::string ccs_name, const std::string wb_name, const std::string mb_name); char *m_tmpstring; int m_tmpstring_length; wb_type m_wb_type; bool is_wb(int idx); bool is_mb(std::string w); bool m_print_unk_warn; bool m_skip_unk_prob; bool m_need_destruct_m_lm; int m_init_hist; int m_cur_init_hist; /* Statistics */ double m_logprob; double m_word_logprob; bool m_use_unk; bool m_use_ccs; /* use_ccs=1 not implemented... */ int m_num_unks; int m_num_tunks; int m_num_ccs; int m_num_pwords; int m_num_ptokens; int m_num_sent_ends; double m_perplexity; double m_perplexity_wo_sent_ends; double m_token_perplexity; // For interpolations float m_alpha; // For getting unknown words correct with subword models bool m_unkflag; float m_cw_lpsum; }; #endif
28.490196
89
0.725396
[ "vector" ]
886562c21f668a97f119a88d6ed7613c600412c7
8,671
hpp
C++
libspace/plugins/prox/LibproxProximityBase.hpp
pathorn/sirikata
5d366a822ef2fb57cd9f64cc4f6085c0a635fdfa
[ "BSD-3-Clause" ]
1
2016-05-09T03:34:51.000Z
2016-05-09T03:34:51.000Z
libspace/plugins/prox/LibproxProximityBase.hpp
pathorn/sirikata
5d366a822ef2fb57cd9f64cc4f6085c0a635fdfa
[ "BSD-3-Clause" ]
null
null
null
libspace/plugins/prox/LibproxProximityBase.hpp
pathorn/sirikata
5d366a822ef2fb57cd9f64cc4f6085c0a635fdfa
[ "BSD-3-Clause" ]
null
null
null
// Copyright (c) 2011 Sirikata Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can // be found in the LICENSE file. #ifndef _SIRIKATA_LIBPROX_PROXIMITY_BASE_HPP_ #define _SIRIKATA_LIBPROX_PROXIMITY_BASE_HPP_ #include <sirikata/space/Proximity.hpp> #include "CBRLocationServiceCache.hpp" namespace Sirikata { /** Base class for Libprox-based Proximity implementations, providing a bit of * utility code that gets reused across different implementations. */ class LibproxProximityBase : public Proximity { public: LibproxProximityBase(SpaceContext* ctx, LocationService* locservice, CoordinateSegmentation* cseg, SpaceNetwork* net, AggregateManager* aggmgr); ~LibproxProximityBase(); protected: // Helper types & methods enum ObjectClass { OBJECT_CLASS_STATIC = 0, OBJECT_CLASS_DYNAMIC = 1, NUM_OBJECT_CLASSES = 2 }; static const std::string& ObjectClassToString(ObjectClass c); static BoundingBox3f aggregateBBoxes(const BoundingBoxList& bboxes); static bool velocityIsStatic(const Vector3f& vel); // BOTH Threads: These are read-only. // To support a static/dynamic split but also support mixing them for // comparison purposes track which we are doing and, for most places, use a // simple index to control whether they point to different query handlers or // the same one. bool mSeparateDynamicObjects; int mNumQueryHandlers; // MAIN Thread: Utility methods that should only be called from the main // strand // Server-to-server messages Router<Message*>* mProxServerMessageService; // Server-to-Object, Server-to-ObjectHost streams // ProxStreamInfo manages *most* of the state for sending data to // a client. This data is managed by the main thread, where // messaging is performed. See SeqNoInfo for how sequence numbers // are stored -- they need to be accessed in the Prox thread so // they are managed separately. template<typename EndpointType, typename StreamType> struct ProxStreamInfo { public: typedef std::tr1::shared_ptr<StreamType> StreamTypePtr; typedef std::tr1::shared_ptr<ProxStreamInfo> Ptr; typedef std::tr1::weak_ptr<ProxStreamInfo> WPtr; // Start a fresh ProxStreamInfo, which will require requesting // a new substream ProxStreamInfo() : iostream_requested(false), writing(false) {} // Start a ProxStreamInfo on an existing stream. ProxStreamInfo(StreamTypePtr strm) : iostream(strm), iostream_requested(true), writing(false) {} void disable() { if (iostream) iostream->close(false); } // Setup reading of frames from the stream. ProxStreamInfo // takes care of queueing up messages until complete frames // are available, giving just a callback per message. typedef std::tr1::function<void(String&)> FrameReceivedCallback; void readFramesFromStream(Ptr prox_stream, FrameReceivedCallback cb); // The actual stream we send on StreamTypePtr iostream; // Whether we've requested the iostream bool iostream_requested; // Outstanding data to be sent. FIXME efficiency std::queue<std::string> outstanding; // If writing is currently in progress bool writing; // Stored callback for writing std::tr1::function<void()> writecb; // Stored callback for reading frames FrameReceivedCallback read_frame_cb; // Backlog of data, i.e. incomplete frame String partial_frame; // Defined safely in cpp since these are only used from // LibproxProximityBase // Handle reads from the underlying stream, decoding frames // and invoking the read callback static void handleRead(WPtr w_prox_stream, uint8* data, int size); // The driver for getting data to the OH, initially triggered by sendObjectResults static void writeSomeObjectResults(Context* ctx, WPtr prox_stream); // Helper for setting up the initial proximity stream. Retries automatically // until successful. static void requestProxSubstream(LibproxProximityBase* parent, Context* ctx, const EndpointType& oref, Ptr prox_stream); // Helper that handles callbacks about prox stream setup static void proxSubstreamCallback(LibproxProximityBase* parent, Context* ctx, int x, const EndpointType& oref, StreamTypePtr parent_stream, StreamTypePtr substream, Ptr prox_stream_info); }; typedef ODPSST::Stream::Ptr ProxObjectStreamPtr; typedef ProxStreamInfo<ObjectReference, ODPSST::Stream> ProxObjectStreamInfo; typedef std::tr1::shared_ptr<ProxObjectStreamInfo> ProxObjectStreamInfoPtr; typedef OHDPSST::Stream::Ptr ProxObjectHostStreamPtr; typedef ProxStreamInfo<OHDP::NodeID, OHDPSST::Stream> ProxObjectHostStreamInfo; typedef std::tr1::shared_ptr<ProxObjectHostStreamInfo> ProxObjectHostStreamInfoPtr; // Utility for implementations. Start listening on the stream and // read each Network::Frame, emitting a callback for each. void readFramesFromObjectStream(const ObjectReference& oref, ProxObjectStreamInfo::FrameReceivedCallback cb); void readFramesFromObjectHostStream(const OHDP::NodeID& node, ProxObjectHostStreamInfo::FrameReceivedCallback cb); // Utility for poll. Queues a message for delivery, encoding it and putting // it on the send stream. If necessary, starts send processing on the stream. void sendObjectResult(Sirikata::Protocol::Object::ObjectMessage*); void sendObjectHostResult(const OHDP::NodeID& node, Sirikata::Protocol::Object::ObjectMessage*); // Helpers that are protocol-specific bool validSession(const ObjectReference& oref) const; bool validSession(const OHDP::NodeID& node) const; ProxObjectStreamPtr getBaseStream(const ObjectReference& oref) const; ProxObjectHostStreamPtr getBaseStream(const OHDP::NodeID& node) const; // Use these to setup ProxStreamInfo's when the client initiates // the stream that will be used to communicate with it. void addObjectProxStreamInfo(ODPSST::Stream::Ptr); void addObjectHostProxStreamInfo(OHDPSST::Stream::Ptr); // Handle various events in the main thread that are triggered in the prox thread void handleAddObjectLocSubscription(const UUID& subscriber, const UUID& observed); void handleRemoveObjectLocSubscription(const UUID& subscriber, const UUID& observed); void handleRemoveAllObjectLocSubscription(const UUID& subscriber); void handleAddOHLocSubscription(const OHDP::NodeID& subscriber, const UUID& observed); void handleRemoveOHLocSubscription(const OHDP::NodeID& subscriber, const UUID& observed); void handleRemoveAllOHLocSubscription(const OHDP::NodeID& subscriber); void handleAddServerLocSubscription(const ServerID& subscriber, const UUID& observed, SeqNoPtr seqPtr); void handleRemoveServerLocSubscription(const ServerID& subscriber, const UUID& observed); void handleRemoveAllServerLocSubscription(const ServerID& subscriber); typedef std::tr1::unordered_map<UUID, ProxObjectStreamInfoPtr, UUID::Hasher> ObjectProxStreamMap; ObjectProxStreamMap mObjectProxStreams; typedef std::tr1::unordered_map<OHDP::NodeID, ProxObjectHostStreamInfoPtr, OHDP::NodeID::Hasher> ObjectHostProxStreamMap; ObjectHostProxStreamMap mObjectHostProxStreams; // PROX Thread - Should only be accessed in methods used by the prox thread Network::IOStrand* mProxStrand; CBRLocationServiceCache* mLocCache; // Query-Type-Agnostic AggregateListener Interface -- manages adding to Loc // and passing to AggregateManager, but you need to delegate to these // yourself since the AggregateListener interface depends on the type of // query/query handler being used. virtual void aggregateCreated(const UUID& objid); virtual void aggregateChildAdded(const UUID& objid, const UUID& child, const BoundingSphere3f& bnds); virtual void aggregateChildRemoved(const UUID& objid, const UUID& child, const BoundingSphere3f& bnds); virtual void aggregateBoundsUpdated(const UUID& objid, const BoundingSphere3f& bnds); virtual void aggregateDestroyed(const UUID& objid); virtual void aggregateObserved(const UUID& objid, uint32 nobservers); // Helper for updating aggregates void updateAggregateLoc(const UUID& objid, const BoundingSphere3f& bnds); }; // class LibproxProximityBase } // namespace Sirikata #endif //_SIRIKATA_LIBPROX_PROXIMITY_BASE_HPP_
47.382514
195
0.74236
[ "object" ]
8865a5076a4455a55ad977699d043eb11433e24f
3,096
cpp
C++
ProblemsSolved/Trie/hyperPrefixSet.cpp
searleser97/Algorithms
af791541d416c29867213d705375cbb3361f486c
[ "Apache-2.0" ]
7
2019-06-06T17:54:20.000Z
2021-03-24T02:31:55.000Z
ProblemsSolved/Trie/hyperPrefixSet.cpp
searleser97/Algorithms
af791541d416c29867213d705375cbb3361f486c
[ "Apache-2.0" ]
null
null
null
ProblemsSolved/Trie/hyperPrefixSet.cpp
searleser97/Algorithms
af791541d416c29867213d705375cbb3361f486c
[ "Apache-2.0" ]
1
2021-03-24T02:31:57.000Z
2021-03-24T02:31:57.000Z
#include<bits/stdc++.h> using namespace std; class Trie { private: class TrieNode { public: unordered_map<char, TrieNode*> children; // map<char, TrieNode*> children; bool endOfWord; int numberOfWords; TrieNode() { this->numberOfWords = 0; this->endOfWord = false; } ~TrieNode() { unordered_map<char, TrieNode*> thisNodeChildren = this->children; unordered_map<char, TrieNode*>::iterator i = thisNodeChildren.begin(); // map<char, TrieNode*> thisNodeChildren = this->children; // map<char, TrieNode*>::iterator i = thisNodeChildren.begin(); while (i != thisNodeChildren.end()) { delete i->second; i++; } thisNodeChildren.clear(); } }; private: TrieNode* root = nullptr; int maximo; public: Trie() { maximo = 0; root = new TrieNode(); } ~Trie() { delete root; } void insert(string &word) { TrieNode *current = this->root; current->numberOfWords++; for (int i = 0; i < word.size(); i++) { char symbol = word[i]; if (current->children.count(symbol) == 0) current->children[symbol] = new TrieNode(); current = current->children[symbol]; current->numberOfWords++; } current->endOfWord = true; } void getWords(TrieNode* node, vector<string> &words, string word) { int goodness = word.size() * node->numberOfWords; if (goodness > this->maximo) this->maximo = goodness; if (node->endOfWord) words.push_back(word); for (auto i : node->children) getWords(i.second, words, word + i.first); } vector<string> getWords() { vector<string> words; this->maximo = 0; getWords(this->root, words, ""); cout << this->maximo << endl; this->maximo = 0; return words; } vector<string> getWords(string &prefix) { vector<string> words; TrieNode *current = this->root; for (int i = 0; i < prefix.size(); i++) { if (current->children.count(prefix[i]) == 0) return words; current = current->children[prefix[i]]; } current->endOfWord = false; getWords(current, words, prefix); current->endOfWord = true; return words; } }; void printv(vector<string> v) { if (v.size() == 0) { cout << "No match." << '\n'; return; } for (int i = 0; i < v.size(); i++) cout << v[i] << endl; } int main() { std::ios_base::sync_with_stdio(0); int t; cin >> t; for (int i = 0; i < t; ++i) { Trie *tr = new Trie(); int n; cin >> n; for (int j = 0; j < n; ++j) { string str; cin >> str; tr->insert(str); } tr->getWords(); delete tr; } return 0; }
25.8
82
0.495478
[ "vector" ]
8865cf822a8f01c6a72ed79982cbd2dbe55ce43b
4,040
cpp
C++
src/jumpnode/jumpnode.cpp
ptitSeb/freespace2
500ee249f7033aac9b389436b1737a404277259c
[ "Linux-OpenIB" ]
1
2020-07-14T07:29:18.000Z
2020-07-14T07:29:18.000Z
src/jumpnode/jumpnode.cpp
ptitSeb/freespace2
500ee249f7033aac9b389436b1737a404277259c
[ "Linux-OpenIB" ]
2
2019-01-01T22:35:56.000Z
2022-03-14T07:34:00.000Z
src/jumpnode/jumpnode.cpp
ptitSeb/freespace2
500ee249f7033aac9b389436b1737a404277259c
[ "Linux-OpenIB" ]
2
2021-03-07T11:40:42.000Z
2021-12-26T21:40:39.000Z
/* * Copyright (C) Volition, Inc. 1999. All rights reserved. * * All source code herein is the property of Volition, Inc. You may not sell * or otherwise commercially exploit the source or things you created based on * the source. */ /* * $Logfile: /Freespace2/code/JumpNode/JumpNode.cpp $ * $Revision: 110 $ * $Date: 2002-06-09 06:41:30 +0200 (Sun, 09 Jun 2002) $ * $Author: relnev $ * * Module for everything to do with jump nodes * * $Log$ * Revision 1.4 2002/06/09 04:41:22 relnev * added copyright header * * Revision 1.3 2002/06/02 04:26:34 relnev * warning cleanup * * Revision 1.2 2002/05/07 03:16:46 theoddone33 * The Great Newline Fix * * Revision 1.1.1.1 2002/05/03 03:28:09 root * Initial import. * * * 2 10/07/98 10:53a Dave * Initial checkin. * * 1 10/07/98 10:49a Dave * * 9 6/13/98 6:01p Hoffoss * Externalized all new (or forgot to be added) strings to all the code. * * 8 5/12/98 2:03p Adam * make jumpnode less bright * * 7 4/01/98 8:38p Lawrance * Add support for jump node icons in the briefings. * * 6 3/24/98 4:27p Lawrance * Use new method for dimming lines * * 5 3/24/98 12:05p Lawrance * Don't set alpha color for jumpnode * * 4 3/23/98 11:05a Lawrance * Dim jump node as it get farther away * * 3 3/21/98 7:43p Lawrance * Disable jump node dimming until bug with alpha colors is fixed * * 2 3/21/98 7:36p Lawrance * Move jump nodes to own lib. * * 1 3/21/98 3:53p Lawrance * * $NoKeywords: $ */ int Num_jump_nodes = 0; #include "object.h" #include "jumpnode.h" #include "model.h" #include "hud.h" jump_node_struct Jump_nodes[MAX_JUMP_NODES]; void jumpnode_render(object *jumpnode_objp, vector *pos, vector *view_pos) { jump_node_struct *node; matrix node_orient = IDENTITY_MATRIX; node = &Jump_nodes[jumpnode_objp->instance]; if ( Fred_running ) { model_set_outline_color(0, 255, 0); model_render(node->modelnum, &node_orient, pos, MR_NO_LIGHTING | MR_LOCK_DETAIL | MR_NO_POLYS | MR_SHOW_OUTLINE ); } else { if ( view_pos ) { int alpha_index = HUD_color_alpha; // generate alpha index based on distance to jump node float dist; dist = vm_vec_dist_quick(view_pos, pos); // linearly interpolate alpha. At 1000m or less, full intensity. At 10000m or more 1/2 intensity. if ( dist < 1000 ) { alpha_index = HUD_COLOR_ALPHA_USER_MAX - 2; } else if ( dist > 10000 ) { alpha_index = HUD_COLOR_ALPHA_USER_MIN; } else { alpha_index = fl2i( HUD_COLOR_ALPHA_USER_MAX - 2 + (dist-1000) * (HUD_COLOR_ALPHA_USER_MIN-HUD_COLOR_ALPHA_USER_MAX-2) / (9000) + 0.5f); if ( alpha_index < HUD_COLOR_ALPHA_USER_MIN ) { alpha_index = HUD_COLOR_ALPHA_USER_MIN; } } // nprintf(("Alan","alpha index is: %d\n", alpha_index)); gr_set_color_fast(&HUD_color_defaults[alpha_index]); // model_set_outline_color(HUD_color_red, HUD_color_green, HUD_color_blue); } else { gr_set_color(HUD_color_red, HUD_color_green, HUD_color_blue); } model_render(node->modelnum, &node_orient, pos, MR_NO_LIGHTING | MR_LOCK_DETAIL | MR_NO_POLYS | MR_SHOW_OUTLINE_PRESET ); } } // create a jump node object and return index to it. int jumpnode_create(vector *pos) { int obj; Assert(Num_jump_nodes < MAX_JUMP_NODES); Jump_nodes[Num_jump_nodes].modelnum = model_load(NOX("subspacenode.pof"), 0, NULL); if ( Jump_nodes[Num_jump_nodes].modelnum < 0 ) { Int3(); return -1; } obj = obj_create(OBJ_JUMP_NODE, -1, Num_jump_nodes, NULL, pos, model_get_radius(Jump_nodes[Num_jump_nodes].modelnum), OF_RENDERS); sprintf(Jump_nodes[Num_jump_nodes].name, XSTR( "Jump Node %d", 632), Num_jump_nodes); if (obj >= 0) { Jump_nodes[Num_jump_nodes].objnum = obj; Num_jump_nodes++; } return obj; } // only called by FRED void jumpnode_render_all() { int i; object *jumpnode_objp; for ( i = 0; i < Num_jump_nodes; i++ ) { jumpnode_objp = &Objects[Jump_nodes[i].objnum]; jumpnode_render(jumpnode_objp, &jumpnode_objp->pos); } }
26.754967
140
0.687376
[ "object", "vector", "model" ]
88663a1437a470b52fccc4926e4b8d114334c613
3,403
hh
C++
packages/MC/mc/Particle.hh
GCZhang/Profugus
d4d8fe295a92a257b26b6082224226ca1edbff5d
[ "BSD-2-Clause" ]
19
2015-06-04T09:02:41.000Z
2021-04-27T19:32:55.000Z
packages/MC/mc/Particle.hh
GCZhang/Profugus
d4d8fe295a92a257b26b6082224226ca1edbff5d
[ "BSD-2-Clause" ]
null
null
null
packages/MC/mc/Particle.hh
GCZhang/Profugus
d4d8fe295a92a257b26b6082224226ca1edbff5d
[ "BSD-2-Clause" ]
5
2016-10-05T20:48:28.000Z
2021-06-21T12:00:54.000Z
//----------------------------------*-C++-*----------------------------------// /*! * \file MC/mc/Particle.hh * \author Thomas M. Evans * \date Fri Apr 25 11:26:16 2014 * \brief Particle class definition. * \note Copyright (C) 2014 Oak Ridge National Laboratory, UT-Battelle, LLC. */ //---------------------------------------------------------------------------// #ifndef MC_mc_Particle_hh #define MC_mc_Particle_hh #include "utils/Definitions.hh" #include "utils/Metaclass.hh" #include "rng/RNG.hh" #include "geometry/RTK_State.hh" #include "Definitions.hh" namespace profugus { //===========================================================================// /*! * \class Particle * \brief Particle class for MC transport. */ /*! * \example mc/test/tstParticle.cc * * Test of Particle. */ //===========================================================================// template <class Geometry> class Particle { public: //@{ //! Typedefs. typedef def::Space_Vector Space_Vector; typedef events::Event Event_Type; typedef RNG RNG_t; typedef typename Geometry::Geo_State_t Geo_State_t; typedef Metaclass<Particle> Metadata; //@} private: // >>> DATA // Material id in current region. int d_matid; // Particle group index. int d_group; // Particle weight. double d_wt; // Random number generator (reference counted). RNG d_rng; // Alive/dead status. bool d_alive; // Latest particle event. Event_Type d_event; // Particle geometric state. Geo_State_t d_geo_state; // Problem/application specific metadata. Metadata d_metadata; public: // Constructor Particle(); // >>> PARTICLE FUNCTIONS //! Set a new weight. void set_wt(double wt) { d_wt = wt; } //! Set particle group. void set_group(int g) { d_group = g; } //! Multiply weight. void multiply_wt(double wt) { d_wt *= wt; } //! Set a new random number generator. void set_rng(const RNG &rng) { d_rng = rng; } //! Set the particle event flag. void set_event(Event_Type event) { d_event = event; } //! Set the material id of the region occupied by the particle. void set_matid(int matid) { d_matid = matid; } //! Kill the particle. void kill() { d_alive = false; } //! Set particle status to alive. void live() { d_alive = true; } //@{ //! Get a handle to the geometric state of the particle. Geo_State_t& geo_state() { return d_geo_state; } const Geo_State_t& geo_state() const { return d_geo_state; } //@} //@{ //! Access particle data. bool alive() const { return d_alive; } double wt() const { return d_wt; } const RNG& rng() const { return d_rng; } Event_Type event() const { return d_event; } int matid() const { return d_matid; } int group() const { return d_group; } //@} //@{ //! Get particle metadata. const Metadata& metadata() const { return d_metadata; } Metadata& metadata() { return d_metadata; } //@} }; } // end namespace profugus #endif // MC_mc_Particle_hh //---------------------------------------------------------------------------// // end of Particle.hh //---------------------------------------------------------------------------//
25.207407
79
0.529827
[ "geometry" ]
8869ecb90e40e359020d50cf3830adb55292c9c5
30,104
cpp
C++
Engine/Source/Editor/PixelInspector/Private/PixelInspector.cpp
windystrife/UnrealEngine_NVIDIAGameWork
b50e6338a7c5b26374d66306ebc7807541ff815e
[ "MIT" ]
1
2022-01-29T18:36:12.000Z
2022-01-29T18:36:12.000Z
Engine/Source/Editor/PixelInspector/Private/PixelInspector.cpp
windystrife/UnrealEngine_NVIDIAGameWork
b50e6338a7c5b26374d66306ebc7807541ff815e
[ "MIT" ]
null
null
null
Engine/Source/Editor/PixelInspector/Private/PixelInspector.cpp
windystrife/UnrealEngine_NVIDIAGameWork
b50e6338a7c5b26374d66306ebc7807541ff815e
[ "MIT" ]
null
null
null
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved. #include "PixelInspector.h" #include "Modules/ModuleManager.h" #include "Widgets/SBoxPanel.h" #include "Widgets/SOverlay.h" #include "Styling/CoreStyle.h" #include "SlateOptMacros.h" #include "Framework/Application/SlateApplication.h" #include "Widgets/Layout/SBorder.h" #include "Widgets/Images/SImage.h" #include "Widgets/Text/STextBlock.h" #include "Widgets/Layout/SBox.h" #include "Widgets/Input/SButton.h" #include "Engine/TextureRenderTarget2D.h" #include "PixelInspectorView.h" #include "PixelInspectorStyle.h" #include "EngineGlobals.h" #include "EditorViewportClient.h" #include "Editor.h" #include "PropertyEditorModule.h" #include "IDetailsView.h" #include "LevelEditor.h" #include "Widgets/Input/SNumericEntryBox.h" #define PIXEL_INSPECTOR_REQUEST_TIMEOUT 10 #define MINIMUM_TICK_BETWEEN_CREATE_REQUEST 10 #define LOCTEXT_NAMESPACE "PixelInspector" namespace PixelInspector { SPixelInspector::SPixelInspector() { DisplayResult = nullptr; LastViewportInspectionPosition = FIntPoint(-1, -1); LastViewportId = 0; LastViewportInspectionSize = FIntPoint(1, 1); bIsPixelInspectorEnable = false; Buffer_FinalColor_RGB8[0] = nullptr; Buffer_FinalColor_RGB8[1] = nullptr; Buffer_SceneColor_Float[0] = nullptr; Buffer_SceneColor_Float[1] = nullptr; Buffer_HDR_Float[0] = nullptr; Buffer_HDR_Float[1] = nullptr; Buffer_Depth_Float[0] = nullptr; Buffer_Depth_Float[1] = nullptr; Buffer_A_Float[0] = nullptr; Buffer_A_Float[1] = nullptr; Buffer_A_RGB8[0] = nullptr; Buffer_A_RGB8[1] = nullptr; Buffer_A_RGB10[0] = nullptr; Buffer_A_RGB10[1] = nullptr; Buffer_BCDE_Float[0] = nullptr; Buffer_BCDE_Float[1] = nullptr; Buffer_BCDE_RGB8[0] = nullptr; Buffer_BCDE_RGB8[1] = nullptr; TickSinceLastCreateRequest = 0; LastBufferIndex = 0; OnLevelActorDeletedDelegateHandle = GEngine->OnLevelActorDeleted().AddRaw(this, &SPixelInspector::OnLevelActorDeleted); OnEditorCloseHandle = GEditor->OnEditorClose().AddRaw(this, &SPixelInspector::ReleaseRessource); FLevelEditorModule& LevelEditor = FModuleManager::GetModuleChecked<FLevelEditorModule>(FName(TEXT("LevelEditor"))); OnRedrawViewportHandle = LevelEditor.OnRedrawLevelEditingViewports().AddRaw(this, &SPixelInspector::OnRedrawViewport); OnApplicationPreInputKeyDownListenerHandle = FSlateApplication::Get().OnApplicationPreInputKeyDownListener().AddRaw(this, &SPixelInspector::OnApplicationPreInputKeyDownListener); } SPixelInspector::~SPixelInspector() { ReleaseRessource(); } void SPixelInspector::OnApplicationPreInputKeyDownListener(const FKeyEvent& InKeyEvent) { if (InKeyEvent.GetKey() == EKeys::Escape && (bIsPixelInspectorEnable)) { // disable the pixel inspector bIsPixelInspectorEnable = false; } } void SPixelInspector::ReleaseRessource() { if (DisplayResult != nullptr) { DisplayResult->RemoveFromRoot(); DisplayResult->ClearFlags(RF_Standalone); DisplayResult = nullptr; } ReleaseAllRequests(); if (OnLevelActorDeletedDelegateHandle.IsValid()) { GEngine->OnLevelActorDeleted().Remove(OnLevelActorDeletedDelegateHandle); OnLevelActorDeletedDelegateHandle = FDelegateHandle(); } if (OnEditorCloseHandle.IsValid()) { GEditor->OnEditorClose().Remove(OnEditorCloseHandle); OnEditorCloseHandle = FDelegateHandle(); } if (OnRedrawViewportHandle.IsValid()) { FLevelEditorModule& LevelEditor = FModuleManager::GetModuleChecked<FLevelEditorModule>(FName(TEXT("LevelEditor"))); LevelEditor.OnRedrawLevelEditingViewports().Remove(OnRedrawViewportHandle); OnRedrawViewportHandle = FDelegateHandle(); } if (OnApplicationPreInputKeyDownListenerHandle.IsValid()) { FSlateApplication::Get().OnApplicationPreInputKeyDownListener().Remove(OnApplicationPreInputKeyDownListenerHandle); OnApplicationPreInputKeyDownListenerHandle = FDelegateHandle(); } if (DisplayDetailsView.IsValid()) { DisplayDetailsView->SetObject(nullptr); DisplayDetailsView = nullptr; } } void SPixelInspector::ReleaseAllRequests() { //Clear all pending requests because buffer will be clear by the graphic for (int i = 0; i < 2; ++i) { Requests[i].RenderingCommandSend = true; Requests[i].RequestComplete = true; ReleaseBuffers(i); } if (DisplayResult != nullptr) { DisplayResult->RemoveFromRoot(); DisplayResult->ClearFlags(RF_Standalone); DisplayResult = nullptr; } } void SPixelInspector::OnLevelActorDeleted(AActor* Actor) { ReleaseAllRequests(); } void SPixelInspector::OnRedrawViewport(bool bInvalidateHitProxies) { ReleaseAllRequests(); } BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION void SPixelInspector::Construct(const FArguments& InArgs) { //Set the LastViewportId to point on the active viewport FViewport *ActiveViewport = GEditor->GetActiveViewport(); for (FEditorViewportClient *EditorViewport : GEditor->AllViewportClients) { if (ActiveViewport == EditorViewport->Viewport && EditorViewport->ViewState.GetReference() != nullptr) { LastViewportId = EditorViewport->ViewState.GetReference()->GetViewKey(); } } TSharedPtr<SBox> InspectorBox; //Create the PixelInspector UI TSharedPtr<SVerticalBox> VerticalBox = SNew(SVerticalBox) + SVerticalBox::Slot() .AutoHeight() [ SNew(SHorizontalBox) + SHorizontalBox::Slot() .Padding(0.0f, 3.0f, 0.0f, 3.0f) .AutoWidth() [ SNew(SButton) .HAlign(HAlign_Center) .ToolTipText(this, &SPixelInspector::GetPixelInspectorEnableButtonTooltipText) .OnClicked(this, &SPixelInspector::HandleTogglePixelInspectorEnableButton) [ SNew(SImage) .Image(this, &SPixelInspector::GetPixelInspectorEnableButtonBrush) ] ] + SHorizontalBox::Slot() .Padding(6.0f, 3.0f, 0.0f, 3.0f) .VAlign(VAlign_Center) .AutoWidth() [ SNew(STextBlock) .MinDesiredWidth(75) .Text(this, &SPixelInspector::GetPixelInspectorEnableButtonText) ] ] + SVerticalBox::Slot() .AutoHeight() [ SNew(SHorizontalBox) + SHorizontalBox::Slot() .AutoWidth() .Padding(0.0f, 3.0f, 16.0f, 3.0f) .VAlign(VAlign_Center) [ SNew(STextBlock) .MinDesiredWidth(75) .Text(LOCTEXT("PixelInspector_ViewportIdValue", "Viewport Id")) ] + SHorizontalBox::Slot() .AutoWidth() .Padding(0.0f, 3.0f, 0.0f, 3.0f) [ SNew(SNumericEntryBox<uint32>) .IsEnabled(false) .MinDesiredValueWidth(75) .Value(this, &SPixelInspector::GetCurrentViewportId) ] ] + SVerticalBox::Slot() .AutoHeight() [ SNew(SHorizontalBox) + SHorizontalBox::Slot() .AutoWidth() .Padding(0.0f, 3.0f, 16.0f, 3.0f) .VAlign(VAlign_Center) [ SNew(STextBlock) .MinDesiredWidth(75) .Text(LOCTEXT("PixelInspector_ViewportCoordinate", "Coordinate")) .ToolTipText(LOCTEXT("PixelInspector_ViewportCoordinateTooltip", "Coordinate relative to the inspected viewport")) ] + SHorizontalBox::Slot() .AutoWidth() .Padding(0.0f, 3.0f, 8.0f, 3.0f) [ SNew(SNumericEntryBox<int32>) .IsEnabled(this, &SPixelInspector::IsPixelInspectorEnable) .Value(this, &SPixelInspector::GetCurrentCoordinateX) .OnValueChanged(this, &SPixelInspector::SetCurrentCoordinateX) .OnValueCommitted(this, &SPixelInspector::SetCurrentCoordinateXCommit) .AllowSpin(true) .MinValue(0) .MaxSliderValue(this, &SPixelInspector::GetMaxCoordinateX) .MinDesiredValueWidth(75) .Label() [ SNew(SBox) .VAlign(VAlign_Center) [ SNew(STextBlock) .Text(LOCTEXT("CoordinateViewport_X", "X")) ] ] ] + SHorizontalBox::Slot() .Padding(0.0f, 3.0f, 8.0f, 3.0f) .AutoWidth() [ SNew(SNumericEntryBox<int32>) .IsEnabled(this, &SPixelInspector::IsPixelInspectorEnable) .Value(this, &SPixelInspector::GetCurrentCoordinateY) .OnValueChanged(this, &SPixelInspector::SetCurrentCoordinateY) .OnValueCommitted(this, &SPixelInspector::SetCurrentCoordinateYCommit) .AllowSpin(true) .MinValue(0) .MaxSliderValue(this, &SPixelInspector::GetMaxCoordinateY) .MinDesiredValueWidth(75) .Label() [ SNew(SBox) .VAlign(VAlign_Center) [ SNew(STextBlock) .Text(LOCTEXT("CoordinateViewport_Y", "Y")) ] ] ] ] + SVerticalBox::Slot() .Padding(0.0f, 12.0f, 0.0f, 3.0f) .FillHeight(1.0f) [ SAssignNew(InspectorBox, SBox) ]; FPropertyEditorModule& PropertyEditorModule = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor"); FDetailsViewArgs DetailsViewArgs; DetailsViewArgs.bAllowSearch = false; DetailsViewArgs.bLockable = false; DetailsViewArgs.bShowActorLabel = false; DetailsViewArgs.bShowOptions = false; DetailsViewArgs.bUpdatesFromSelection = false; DetailsViewArgs.bHideSelectionTip = true; DetailsViewArgs.bSearchInitialKeyFocus = false; DetailsViewArgs.NameAreaSettings = FDetailsViewArgs::HideNameArea; DisplayDetailsView = PropertyEditorModule.CreateDetailView(DetailsViewArgs); InspectorBox->SetContent(DisplayDetailsView->AsShared()); //Create a property Detail view ChildSlot [ SNew(SBorder) .BorderImage(FCoreStyle::Get().GetBrush("ToolPanel.GroupBorder")) [ SNew(SOverlay) // Overlay slot for the main HLOD window area + SOverlay::Slot() [ VerticalBox.ToSharedRef() ] ] ]; } END_SLATE_FUNCTION_BUILD_OPTIMIZATION FReply SPixelInspector::HandleTogglePixelInspectorEnableButton() { bIsPixelInspectorEnable = !bIsPixelInspectorEnable; if (bIsPixelInspectorEnable) { if (LastViewportInspectionPosition == FIntPoint(-1, -1)) { //Let the system inspect a pixel so the user can see the UI appear LastViewportInspectionPosition = FIntPoint(0, 0); } //Make sure the viewport is switch to realtime SetCurrentViewportInRealtime(); } return FReply::Handled(); } FText SPixelInspector::GetPixelInspectorEnableButtonText() const { if (bIsPixelInspectorEnable) { return LOCTEXT("PixelInspector_EnableCheckbox_Inspecting", "Inspecting"); } return LOCTEXT("PixelInspectorMouseHover_EnableCheckbox", "Start Pixel Inspector"); } FText SPixelInspector::GetPixelInspectorEnableButtonTooltipText() const { if (bIsPixelInspectorEnable) { return LOCTEXT("PixelInspector_EnableCheckbox_ESC", "Inspecting (ESC to stop)"); } return LOCTEXT("PixelInspectorMouseHover_EnableCheckbox", "Start Pixel Inspector"); } const FSlateBrush* SPixelInspector::GetPixelInspectorEnableButtonBrush() const { return bIsPixelInspectorEnable ? FPixelInspectorStyle::Get()->GetBrush("PixelInspector.Enabled") : FPixelInspectorStyle::Get()->GetBrush("PixelInspector.Disabled"); } void SPixelInspector::SetCurrentCoordinateXCommit(int32 NewValue, ETextCommit::Type) { ReleaseAllRequests(); SetCurrentCoordinateX(NewValue); } void SPixelInspector::SetCurrentCoordinateX(int32 NewValue) { LastViewportInspectionPosition.X = NewValue; } void SPixelInspector::SetCurrentCoordinateYCommit(int32 NewValue, ETextCommit::Type) { ReleaseAllRequests(); SetCurrentCoordinateY(NewValue); } void SPixelInspector::SetCurrentCoordinateY(int32 NewValue) { LastViewportInspectionPosition.Y = NewValue; } void SPixelInspector::SetCurrentCoordinate(FIntPoint NewCoordinate, bool ReleaseAllRequest) { if (ReleaseAllRequest) { ReleaseAllRequests(); } LastViewportInspectionPosition.X = NewCoordinate.X; LastViewportInspectionPosition.Y = NewCoordinate.Y; } TOptional<int32> SPixelInspector::GetMaxCoordinateX() const { return LastViewportInspectionSize.X - 1; } TOptional<int32> SPixelInspector::GetMaxCoordinateY() const { return LastViewportInspectionSize.Y - 1; } void SPixelInspector::SetCurrentViewportInRealtime() { //Force viewport refresh for (FEditorViewportClient *EditorViewport : GEditor->AllViewportClients) { if (EditorViewport->ViewState.GetReference() != nullptr) { if (EditorViewport->ViewState.GetReference()->GetViewKey() == LastViewportId) { if (!EditorViewport->IsRealtime()) { EditorViewport->SetRealtime(true); } } } } } void SPixelInspector::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) { SCompoundWidget::Tick(AllottedGeometry, InCurrentTime, InDeltaTime); TickSinceLastCreateRequest++; } void SPixelInspector::CreatePixelInspectorRequest(FIntPoint ScreenPosition, int32 viewportUniqueId, FSceneInterface *SceneInterface, bool bInGameViewMode) { if (TickSinceLastCreateRequest < MINIMUM_TICK_BETWEEN_CREATE_REQUEST) return; if (ScreenPosition == FIntPoint(-1, -1)) { return; } //Make sure we dont get value outside the viewport size if ( ScreenPosition.X >= LastViewportInspectionSize.X || ScreenPosition.Y >= LastViewportInspectionSize.Y ) { return; } TickSinceLastCreateRequest = 0; // We need to know if the GBuffer is in low, default or high precision buffer const auto CVarGBufferFormat = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.GBufferFormat")); //0: lower precision (8bit per component, for profiling) //1: low precision (default) //5: high precision const int32 GBufferFormat = CVarGBufferFormat != nullptr ? CVarGBufferFormat->GetValueOnGameThread() : 1; // We need to know the static lighting mode to decode properly the buffers const auto CVarAllowStaticLighting = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.AllowStaticLighting")); //0: false //1: true //default: true const bool AllowStaticLighting = CVarAllowStaticLighting != nullptr ? CVarAllowStaticLighting->GetValueOnGameThread() == 1 : true; //Try to create the request buffer int32 BufferIndex = CreateRequestBuffer(SceneInterface, GBufferFormat, bInGameViewMode); if (BufferIndex == -1) return; Requests[BufferIndex].SetRequestData(ScreenPosition, BufferIndex, viewportUniqueId, GBufferFormat, AllowStaticLighting); SceneInterface->AddPixelInspectorRequest(&(Requests[BufferIndex])); } void SPixelInspector::ReleaseBuffers(int32 BufferIndex) { check(BufferIndex >= 0 && BufferIndex < 2); if (Buffer_FinalColor_RGB8[BufferIndex] != nullptr) { Buffer_FinalColor_RGB8[BufferIndex]->ClearFlags(RF_Standalone); Buffer_FinalColor_RGB8[BufferIndex]->RemoveFromRoot(); Buffer_FinalColor_RGB8[BufferIndex] = nullptr; } if (Buffer_SceneColor_Float[BufferIndex] != nullptr) { Buffer_SceneColor_Float[BufferIndex]->ClearFlags(RF_Standalone); Buffer_SceneColor_Float[BufferIndex]->RemoveFromRoot(); Buffer_SceneColor_Float[BufferIndex] = nullptr; } if (Buffer_HDR_Float[BufferIndex] != nullptr) { Buffer_HDR_Float[BufferIndex]->ClearFlags(RF_Standalone); Buffer_HDR_Float[BufferIndex]->RemoveFromRoot(); Buffer_HDR_Float[BufferIndex] = nullptr; } if (Buffer_Depth_Float[BufferIndex] != nullptr) { Buffer_Depth_Float[BufferIndex]->ClearFlags(RF_Standalone); Buffer_Depth_Float[BufferIndex]->RemoveFromRoot(); Buffer_Depth_Float[BufferIndex] = nullptr; } if (Buffer_A_Float[BufferIndex] != nullptr) { Buffer_A_Float[BufferIndex]->ClearFlags(RF_Standalone); Buffer_A_Float[BufferIndex]->RemoveFromRoot(); Buffer_A_Float[BufferIndex] = nullptr; } if (Buffer_A_RGB8[BufferIndex] != nullptr) { Buffer_A_RGB8[BufferIndex]->ClearFlags(RF_Standalone); Buffer_A_RGB8[BufferIndex]->RemoveFromRoot(); Buffer_A_RGB8[BufferIndex] = nullptr; } if (Buffer_A_RGB10[BufferIndex] != nullptr) { Buffer_A_RGB10[BufferIndex]->ClearFlags(RF_Standalone); Buffer_A_RGB10[BufferIndex]->RemoveFromRoot(); Buffer_A_RGB10[BufferIndex] = nullptr; } if (Buffer_BCDE_Float[BufferIndex] != nullptr) { Buffer_BCDE_Float[BufferIndex]->ClearFlags(RF_Standalone); Buffer_BCDE_Float[BufferIndex]->RemoveFromRoot(); Buffer_BCDE_Float[BufferIndex] = nullptr; } if (Buffer_BCDE_RGB8[BufferIndex] != nullptr) { Buffer_BCDE_RGB8[BufferIndex]->ClearFlags(RF_Standalone); Buffer_BCDE_RGB8[BufferIndex]->RemoveFromRoot(); Buffer_BCDE_RGB8[BufferIndex] = nullptr; } } int32 SPixelInspector::CreateRequestBuffer(FSceneInterface *SceneInterface, const int32 GBufferFormat, bool bInGameViewMode) { //Toggle the last buffer Index LastBufferIndex = (LastBufferIndex + 1) % 2; //Check if we have an available request if (Requests[LastBufferIndex].RequestComplete == false) { //Put back the last buffer position LastBufferIndex = (LastBufferIndex - 1) % 2; return -1; } //Release the old buffer ReleaseBuffers(LastBufferIndex); FTextureRenderTargetResource* FinalColorRenderTargetResource = nullptr; FTextureRenderTargetResource* SceneColorRenderTargetResource = nullptr; FTextureRenderTargetResource* HDRRenderTargetResource = nullptr; FTextureRenderTargetResource* DepthRenderTargetResource = nullptr; FTextureRenderTargetResource* BufferARenderTargetResource = nullptr; FTextureRenderTargetResource* BufferBCDERenderTargetResource = nullptr; //Final color is in RGB8 format Buffer_FinalColor_RGB8[LastBufferIndex] = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), TEXT("PixelInspectorBufferFinalColorTarget"), RF_Standalone); Buffer_FinalColor_RGB8[LastBufferIndex]->AddToRoot(); Buffer_FinalColor_RGB8[LastBufferIndex]->InitCustomFormat(FinalColorContextGridSize, FinalColorContextGridSize, PF_B8G8R8A8, true); Buffer_FinalColor_RGB8[LastBufferIndex]->ClearColor = FLinearColor::Black; Buffer_FinalColor_RGB8[LastBufferIndex]->UpdateResourceImmediate(true); FinalColorRenderTargetResource = Buffer_FinalColor_RGB8[LastBufferIndex]->GameThread_GetRenderTargetResource(); //Scene color is in RGB8 format Buffer_SceneColor_Float[LastBufferIndex] = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), TEXT("PixelInspectorBufferSceneColorTarget"), RF_Standalone); Buffer_SceneColor_Float[LastBufferIndex]->AddToRoot(); Buffer_SceneColor_Float[LastBufferIndex]->InitCustomFormat(1, 1, PF_FloatRGBA, true); Buffer_SceneColor_Float[LastBufferIndex]->ClearColor = FLinearColor::Black; Buffer_SceneColor_Float[LastBufferIndex]->UpdateResourceImmediate(true); SceneColorRenderTargetResource = Buffer_SceneColor_Float[LastBufferIndex]->GameThread_GetRenderTargetResource(); //HDR is in float RGB format Buffer_HDR_Float[LastBufferIndex] = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), TEXT("PixelInspectorBufferHDRTarget"), RF_Standalone); Buffer_HDR_Float[LastBufferIndex]->AddToRoot(); if (!bInGameViewMode) { Buffer_HDR_Float[LastBufferIndex]->InitCustomFormat(1, 1, PF_FloatRGBA, true); } else { Buffer_HDR_Float[LastBufferIndex]->InitCustomFormat(1, 1, PF_FloatRGB, true); } Buffer_HDR_Float[LastBufferIndex]->ClearColor = FLinearColor::Black; Buffer_HDR_Float[LastBufferIndex]->UpdateResourceImmediate(true); HDRRenderTargetResource = Buffer_HDR_Float[LastBufferIndex]->GameThread_GetRenderTargetResource(); //TODO support Non render buffer to be able to read the depth stencil /* Buffer_Depth_Float[LastBufferIndex] = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), TEXT("PixelInspectorBufferDepthTarget"), RF_Standalone); Buffer_Depth_Float[LastBufferIndex]->AddToRoot(); Buffer_Depth_Float[LastBufferIndex]->InitCustomFormat(1, 1, PF_DepthStencil, true); Buffer_Depth_Float[LastBufferIndex]->ClearColor = FLinearColor::Black; Buffer_Depth_Float[LastBufferIndex]->UpdateResourceImmediate(true); DepthRenderTargetResource = Buffer_Depth_Float[LastBufferIndex]->GameThread_GetRenderTargetResource();*/ //Low precision GBuffer if (GBufferFormat == EGBufferFormat::Force8BitsPerChannel) { //All buffer are PF_B8G8R8A8 Buffer_A_RGB8[LastBufferIndex] = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), TEXT("PixelInspectorBufferATarget"), RF_Standalone ); Buffer_A_RGB8[LastBufferIndex]->AddToRoot(); Buffer_A_RGB8[LastBufferIndex]->InitCustomFormat(1, 1, PF_B8G8R8A8, true); Buffer_A_RGB8[LastBufferIndex]->ClearColor = FLinearColor::Black; Buffer_A_RGB8[LastBufferIndex]->UpdateResourceImmediate(true); BufferARenderTargetResource = Buffer_A_RGB8[LastBufferIndex]->GameThread_GetRenderTargetResource(); Buffer_BCDE_RGB8[LastBufferIndex] = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), TEXT("PixelInspectorBufferBTarget"), RF_Standalone ); Buffer_BCDE_RGB8[LastBufferIndex]->AddToRoot(); Buffer_BCDE_RGB8[LastBufferIndex]->InitCustomFormat(4, 1, PF_B8G8R8A8, true); Buffer_BCDE_RGB8[LastBufferIndex]->ClearColor = FLinearColor::Black; Buffer_BCDE_RGB8[LastBufferIndex]->UpdateResourceImmediate(true); BufferBCDERenderTargetResource = Buffer_BCDE_RGB8[LastBufferIndex]->GameThread_GetRenderTargetResource(); } else if(GBufferFormat == EGBufferFormat::Default) { //Default is PF_A2B10G10R10 Buffer_A_RGB10[LastBufferIndex] = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), TEXT("PixelInspectorBufferATarget"), RF_Standalone ); Buffer_A_RGB10[LastBufferIndex]->AddToRoot(); Buffer_A_RGB10[LastBufferIndex]->InitCustomFormat(1, 1, PF_A2B10G10R10, true); Buffer_A_RGB10[LastBufferIndex]->ClearColor = FLinearColor::Black; Buffer_A_RGB10[LastBufferIndex]->UpdateResourceImmediate(true); BufferARenderTargetResource = Buffer_A_RGB10[LastBufferIndex]->GameThread_GetRenderTargetResource(); //Default is PF_B8G8R8A8 Buffer_BCDE_RGB8[LastBufferIndex] = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), TEXT("PixelInspectorBufferBTarget"), RF_Standalone ); Buffer_BCDE_RGB8[LastBufferIndex]->AddToRoot(); Buffer_BCDE_RGB8[LastBufferIndex]->InitCustomFormat(4, 1, PF_B8G8R8A8, true); Buffer_BCDE_RGB8[LastBufferIndex]->ClearColor = FLinearColor::Black; Buffer_BCDE_RGB8[LastBufferIndex]->UpdateResourceImmediate(true); BufferBCDERenderTargetResource = Buffer_BCDE_RGB8[LastBufferIndex]->GameThread_GetRenderTargetResource(); } else if (GBufferFormat == EGBufferFormat::HighPrecisionNormals || GBufferFormat == EGBufferFormat::Force16BitsPerChannel) { //All buffer are PF_FloatRGBA Buffer_A_Float[LastBufferIndex] = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), TEXT("PixelInspectorBufferATarget"), RF_Standalone ); Buffer_A_Float[LastBufferIndex]->AddToRoot(); Buffer_A_Float[LastBufferIndex]->InitCustomFormat(1, 1, PF_FloatRGBA, true); Buffer_A_Float[LastBufferIndex]->ClearColor = FLinearColor::Black; Buffer_A_Float[LastBufferIndex]->UpdateResourceImmediate(true); BufferARenderTargetResource = Buffer_A_Float[LastBufferIndex]->GameThread_GetRenderTargetResource(); Buffer_BCDE_Float[LastBufferIndex] = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), TEXT("PixelInspectorBufferBTarget"), RF_Standalone ); Buffer_BCDE_Float[LastBufferIndex]->AddToRoot(); Buffer_BCDE_Float[LastBufferIndex]->InitCustomFormat(4, 1, PF_FloatRGBA, true); Buffer_BCDE_Float[LastBufferIndex]->ClearColor = FLinearColor::Black; Buffer_BCDE_Float[LastBufferIndex]->UpdateResourceImmediate(true); BufferBCDERenderTargetResource = Buffer_BCDE_Float[LastBufferIndex]->GameThread_GetRenderTargetResource(); } else { checkf(0, TEXT("Unhandled gbuffer format (%i) during pixel inspector initializtion."), GBufferFormat); } SceneInterface->InitializePixelInspector(FinalColorRenderTargetResource, SceneColorRenderTargetResource, DepthRenderTargetResource, HDRRenderTargetResource, BufferARenderTargetResource, BufferBCDERenderTargetResource, LastBufferIndex); return LastBufferIndex; } void SPixelInspector::ReadBackRequestData() { for (int RequestIndex = 0; RequestIndex < 2; ++RequestIndex) { if (Requests[RequestIndex].RequestComplete == false && Requests[RequestIndex].RenderingCommandSend == true) { if (Requests[RequestIndex].FrameCountAfterRenderingCommandSend >= WAIT_FRAMENUMBER_BEFOREREADING) { if (Requests[RequestIndex].SourcePixelPosition == FIntPoint(-1, -1)) { continue; } PixelInspectorResult PixelResult; PixelResult.ScreenPosition = Requests[RequestIndex].SourcePixelPosition; PixelResult.ViewUniqueId = Requests[RequestIndex].ViewId; TArray<FColor> BufferFinalColorValue; FTextureRenderTargetResource* RTResourceFinalColor = Buffer_FinalColor_RGB8[Requests[RequestIndex].BufferIndex]->GameThread_GetRenderTargetResource(); if (RTResourceFinalColor->ReadPixels(BufferFinalColorValue) == false) { BufferFinalColorValue.Empty(); } PixelResult.DecodeFinalColor(BufferFinalColorValue); TArray<FLinearColor> BufferSceneColorValue; FTextureRenderTargetResource* RTResourceSceneColor = Buffer_SceneColor_Float[Requests[RequestIndex].BufferIndex]->GameThread_GetRenderTargetResource(); if (RTResourceSceneColor->ReadLinearColorPixels(BufferSceneColorValue) == false) { BufferSceneColorValue.Empty(); } PixelResult.DecodeSceneColor(BufferSceneColorValue); if (Buffer_Depth_Float[Requests[RequestIndex].BufferIndex] != nullptr) { TArray<FLinearColor> BufferDepthValue; FTextureRenderTargetResource* RTResourceDepth = Buffer_Depth_Float[Requests[RequestIndex].BufferIndex]->GameThread_GetRenderTargetResource(); if (RTResourceDepth->ReadLinearColorPixels(BufferDepthValue) == false) { BufferDepthValue.Empty(); } PixelResult.DecodeDepth(BufferDepthValue); } TArray<FLinearColor> BufferHDRValue; FTextureRenderTargetResource* RTResourceHDR = Buffer_HDR_Float[Requests[RequestIndex].BufferIndex]->GameThread_GetRenderTargetResource(); if (RTResourceHDR->ReadLinearColorPixels(BufferHDRValue) == false) { BufferHDRValue.Empty(); } PixelResult.DecodeHDR(BufferHDRValue); if (Requests[RequestIndex].GBufferPrecision == EGBufferFormat::Force8BitsPerChannel) { TArray<FColor> BufferAValue; FTextureRenderTargetResource* RTResourceA = Buffer_A_RGB8[Requests[RequestIndex].BufferIndex]->GameThread_GetRenderTargetResource(); if (RTResourceA->ReadPixels(BufferAValue) == false) { BufferAValue.Empty(); } TArray<FColor> BufferBCDEValue; FTextureRenderTargetResource* RTResourceBCDE = Buffer_BCDE_RGB8[Requests[RequestIndex].BufferIndex]->GameThread_GetRenderTargetResource(); if (RTResourceA->ReadPixels(BufferBCDEValue) == false) { BufferBCDEValue.Empty(); } PixelResult.DecodeBufferData(BufferAValue, BufferBCDEValue, Requests[RequestIndex].AllowStaticLighting); } else if (Requests[RequestIndex].GBufferPrecision == EGBufferFormat::Default) { //PF_A2B10G10R10 format is not support yet TArray<FLinearColor> BufferAValue; FTextureRenderTargetResource* RTResourceA = Buffer_A_RGB10[Requests[RequestIndex].BufferIndex]->GameThread_GetRenderTargetResource(); if (RTResourceA->ReadLinearColorPixels(BufferAValue) == false) { BufferAValue.Empty(); } TArray<FColor> BufferBCDEValue; FTextureRenderTargetResource* RTResourceBCDE = Buffer_BCDE_RGB8[Requests[RequestIndex].BufferIndex]->GameThread_GetRenderTargetResource(); if (RTResourceBCDE->ReadPixels(BufferBCDEValue) == false) { BufferBCDEValue.Empty(); } PixelResult.DecodeBufferData(BufferAValue, BufferBCDEValue, Requests[RequestIndex].AllowStaticLighting); } else if (Requests[RequestIndex].GBufferPrecision == EGBufferFormat::HighPrecisionNormals || Requests[RequestIndex].GBufferPrecision == EGBufferFormat::Force16BitsPerChannel) { //PF_A2B10G10R10 format is not support yet TArray<FFloat16Color> BufferAValue; FTextureRenderTargetResource* RTResourceA = Buffer_A_Float[Requests[RequestIndex].BufferIndex]->GameThread_GetRenderTargetResource(); if (RTResourceA->ReadFloat16Pixels(BufferAValue) == false) { BufferAValue.Empty(); } TArray<FFloat16Color> BufferBCDEValue; FTextureRenderTargetResource* RTResourceBCDE = Buffer_BCDE_Float[Requests[RequestIndex].BufferIndex]->GameThread_GetRenderTargetResource(); if (RTResourceA->ReadFloat16Pixels(BufferBCDEValue) == false) { BufferBCDEValue.Empty(); } PixelResult.DecodeBufferData(BufferAValue, BufferBCDEValue, Requests[RequestIndex].AllowStaticLighting); } else { checkf(0, TEXT("Unhandled gbuffer format (%i) during pixel inspector readback."), Requests[RequestIndex].GBufferPrecision); } AccumulationResult.Add(PixelResult); ReleaseBuffers(RequestIndex); Requests[RequestIndex].RequestComplete = true; Requests[RequestIndex].RenderingCommandSend = true; Requests[RequestIndex].FrameCountAfterRenderingCommandSend = 0; Requests[RequestIndex].RequestTickSinceCreation = 0; } else { Requests[RequestIndex].FrameCountAfterRenderingCommandSend++; } } else if (Requests[RequestIndex].RequestComplete == false) { Requests[RequestIndex].RequestTickSinceCreation++; if (Requests[RequestIndex].RequestTickSinceCreation > PIXEL_INSPECTOR_REQUEST_TIMEOUT) { ReleaseBuffers(RequestIndex); Requests[RequestIndex].RequestComplete = true; Requests[RequestIndex].RenderingCommandSend = true; Requests[RequestIndex].FrameCountAfterRenderingCommandSend = 0; Requests[RequestIndex].RequestTickSinceCreation = 0; } } } if (AccumulationResult.Num() > 0) { if (DisplayResult == nullptr) { DisplayResult = NewObject<UPixelInspectorView>(GetTransientPackage(), FName(TEXT("PixelInspectorDisplay")), RF_Standalone); DisplayResult->AddToRoot(); } DisplayResult->SetFromResult(AccumulationResult[0]); DisplayDetailsView->SetObject(DisplayResult, true); if (AccumulationResult[0].ScreenPosition != LastViewportInspectionPosition) { LastViewportInspectionPosition = AccumulationResult[0].ScreenPosition; } LastViewportId = AccumulationResult[0].ViewUniqueId; AccumulationResult.RemoveAt(0); } } }; #undef LOCTEXT_NAMESPACE
37.303594
237
0.763819
[ "render" ]
886b950741a365540d3c431a001cd7524edc503a
23,309
cpp
C++
pgc1000/pgc1000.cpp
kielnow/PGC1000
61db890326f7954a8d1aa9466547eb50e62e5f76
[ "MIT" ]
null
null
null
pgc1000/pgc1000.cpp
kielnow/PGC1000
61db890326f7954a8d1aa9466547eb50e62e5f76
[ "MIT" ]
null
null
null
pgc1000/pgc1000.cpp
kielnow/PGC1000
61db890326f7954a8d1aa9466547eb50e62e5f76
[ "MIT" ]
null
null
null
#include "pgc1000.h" using namespace pgc1000; const Lcd::Desc Lcd::DefaultDesc = { D8, // di D15, // rw D10, // e A4, // db0 A5, // db1 D2, // db2 D3, // db3 D4, // db4 D5, // db5 D6, // db6 D7, // db7 D11, // cs1 D12, // cs2 D9, // res }; Lcd::Lcd(const Desc &desc) : mDI(desc.di) , mRW(desc.rw) , mE(desc.e) , mDB(desc.db0, desc.db1, desc.db2, desc.db3, desc.db4, desc.db5, desc.db6, desc.db7) , mCS(desc.cs1, desc.cs2) , mRES(desc.res) { mDB = 0; mDI = 0; mE = 0; mCS = 0; mRES = 0; } void Lcd::write(u8 cs, u8 di, u8 data) { mCS = cs; mDI = di; mDB = data; mE = 1; wait_us(TIME_E_HIGH); mE = 0; wait_us(TIME_E_LOW); } void Lcd::init() { mRES = 0; wait_us(TIME_RES_LOW); mRES = 1; wait_ms(30); displayStartLine(CS_BOTH, 0); displayOn(CS_BOTH); } void Lcd::blit(u8* pdata) { setAddress(CS_BOTH, 0); for (u8 y = 0; y < LCD_PAGE_MAX; ++y) { setPage(CS_BOTH, y); for (u8 x = 0; x < LCD_LINE_MAX_2; ++x) { writeDisplayData(CS_LEFT, pdata[x * LCD_PAGE_MAX + y]); } for (u8 x = LCD_LINE_MAX_2; x < LCD_LINE_MAX; ++x) { writeDisplayData(CS_RIGHT, pdata[x * LCD_PAGE_MAX + y]); } } } void Lcd::blit(u8* pdata, u8* pdirty) { for (u8 y = 0; y < LCD_PAGE_MAX; ++y) { setPage(CS_BOTH, y); const u8 mask = 1 << y; #if 0//debug for (u8 x = 0; x < LCD_LINE_MAX_2; ++x) { writeDisplayData(CS_LEFT, (pdirty[x] & mask) ? 0xFF : 0x00); } for (u8 x = LCD_LINE_MAX_2; x < LCD_LINE_MAX; ++x) { writeDisplayData(CS_RIGHT, (pdirty[x] & mask) ? 0xFF : 0x00); } #else for (u8 x = 0; x < LCD_LINE_MAX_2; ++x) { if (pdirty[x] & mask) { setAddress(CS_LEFT, x); writeDisplayData(CS_LEFT, pdata[x * LCD_PAGE_MAX + y]); } } for (u8 x = LCD_LINE_MAX_2; x < LCD_LINE_MAX; ++x) { if (pdirty[x] & mask) { setAddress(CS_RIGHT, x); writeDisplayData(CS_RIGHT, pdata[x * LCD_PAGE_MAX + y]); } } #endif } } const u8 pgc1000::font[96][5] = { { 0x00, 0x00, 0x00, 0x00, 0x00 }, // whitespace { 0x00, 0x00, 0x17, 0x00, 0x00 }, // ! { 0x00, 0x03, 0x00, 0x03, 0x00 }, // " { 0x0A, 0x1F, 0x0A, 0x1F, 0x0A }, // # { 0x12, 0x15, 0x1F, 0x15, 0x09 }, // $ { 0x13, 0x0B, 0x04, 0x1A, 0x19 }, // % { 0x0A, 0x15, 0x16, 0x08, 0x14 }, // & { 0x00, 0x02, 0x01, 0x00, 0x00 }, // ' { 0x00, 0x0E, 0x11, 0x00, 0x00 }, // ( { 0x00, 0x11, 0x0E, 0x00, 0x00 }, // ) { 0x11, 0x0A, 0x1F, 0x0A, 0x11 }, // * { 0x04, 0x04, 0x1F, 0x04, 0x04 }, // + { 0x10, 0x08, 0x00, 0x00, 0x00 }, // , { 0x04, 0x04, 0x04, 0x04, 0x04 }, // - { 0x00, 0x10, 0x00, 0x00, 0x00 }, // . { 0x10, 0x08, 0x04, 0x02, 0x01 }, // / { 0x0E, 0x19, 0x15, 0x13, 0x0E }, // 0 { 0x00, 0x12, 0x1F, 0x10, 0x00 }, // 1 { 0x12, 0x19, 0x15, 0x12, 0x00 }, // 2 { 0x15, 0x15, 0x15, 0x0A, 0x00 }, // 3 { 0x0C, 0x0A, 0x09, 0x1F, 0x08 }, // 4 { 0x17, 0x15, 0x15, 0x09, 0x00 }, // 5 { 0x1E, 0x15, 0x15, 0x1D, 0x00 }, // 6 { 0x01, 0x19, 0x05, 0x03, 0x00 }, // 7 { 0x1F, 0x15, 0x15, 0x1F, 0x00 }, // 8 { 0x17, 0x15, 0x15, 0x0F, 0x00 }, // 9 { 0x00, 0x00, 0x0A, 0x00, 0x00 }, // : { 0x00, 0x10, 0x0A, 0x00, 0x00 }, // ; { 0x04, 0x0A, 0x11, 0x00, 0x00 }, // < { 0x0A, 0x0A, 0x0A, 0x0A, 0x00 }, // = { 0x11, 0x0A, 0x04, 0x00, 0x00 }, // > { 0x02, 0x01, 0x15, 0x05, 0x02 }, // ? { 0x0E, 0x11, 0x17, 0x17, 0x16 }, // @ { 0x1E, 0x09, 0x09, 0x1E, 0x00 }, // A { 0x1F, 0x15, 0x15, 0x1E, 0x00 }, // B { 0x0E, 0x11, 0x11, 0x11, 0x00 }, // C { 0x1F, 0x11, 0x11, 0x0E, 0x00 }, // D { 0x1F, 0x15, 0x15, 0x15, 0x00 }, // E { 0x1F, 0x05, 0x05, 0x01, 0x00 }, // F { 0x0E, 0x11, 0x15, 0x0D, 0x00 }, // G { 0x1F, 0x04, 0x04, 0x1F, 0x00 }, // H { 0x00, 0x11, 0x1F, 0x11, 0x00 }, // I { 0x08, 0x10, 0x10, 0x0F, 0x00 }, // J { 0x1F, 0x04, 0x0A, 0x11, 0x00 }, // K { 0x1F, 0x10, 0x10, 0x10, 0x00 }, // L { 0x1F, 0x01, 0x1E, 0x01, 0x1F }, // M { 0x1F, 0x02, 0x04, 0x08, 0x1F }, // N { 0x0E, 0x11, 0x11, 0x0E, 0x00 }, // O { 0x1F, 0x09, 0x09, 0x06, 0x00 }, // P { 0x0E, 0x11, 0x15, 0x0E, 0x10 }, // Q { 0x1F, 0x09, 0x09, 0x16, 0x00 }, // R { 0x12, 0x15, 0x15, 0x09, 0x00 }, // S { 0x01, 0x01, 0x1F, 0x01, 0x01 }, // T { 0x0F, 0x10, 0x10, 0x0F, 0x00 }, // U { 0x03, 0x0C, 0x10, 0x0C, 0x03 }, // V { 0x0F, 0x10, 0x0F, 0x10, 0x0F }, // W { 0x11, 0x0A, 0x04, 0x0A, 0x11 }, // X { 0x01, 0x02, 0x1C, 0x02, 0x01 }, // Y { 0x11, 0x19, 0x15, 0x13, 0x11 }, // Z { 0x00, 0x1F, 0x11, 0x00, 0x00 }, // [ { 0x01, 0x02, 0x04, 0x08, 0x10 }, // backslash { 0x00, 0x11, 0x1F, 0x00, 0x00 }, // ] { 0x00, 0x02, 0x01, 0x02, 0x00 }, // ^ { 0x10, 0x10, 0x10, 0x10, 0x00 }, // _ { 0x00, 0x00, 0x01, 0x02, 0x00 }, // ` { 0x0C, 0x12, 0x1E, 0x10, 0x00 }, // a { 0x1F, 0x14, 0x0C, 0x00, 0x00 }, // b { 0x0C, 0x12, 0x12, 0x00, 0x00 }, // c { 0x18, 0x14, 0x1F, 0x00, 0x00 }, // d { 0x1C, 0x1A, 0x16, 0x00, 0x00 }, // e { 0x04, 0x1F, 0x05, 0x00, 0x00 }, // f { 0x12, 0x15, 0x0E, 0x00, 0x00 }, // g { 0x1F, 0x04, 0x18, 0x00, 0x00 }, // h { 0x00, 0x1D, 0x00, 0x00, 0x00 }, // i { 0x10, 0x1D, 0x00, 0x00, 0x00 }, // j { 0x1F, 0x08, 0x14, 0x00, 0x00 }, // k { 0x00, 0x1F, 0x10, 0x00, 0x00 }, // l { 0x1E, 0x02, 0x1E, 0x02, 0x1C }, // m { 0x1E, 0x02, 0x1C, 0x00, 0x00 }, // n { 0x0C, 0x12, 0x0C, 0x00, 0x00 }, // o { 0x1F, 0x05, 0x03, 0x00, 0x00 }, // p { 0x06, 0x05, 0x1F, 0x00, 0x00 }, // q { 0x1E, 0x04, 0x02, 0x00, 0x00 }, // r { 0x14, 0x1A, 0x0A, 0x00, 0x00 }, // s { 0x02, 0x1F, 0x12, 0x00, 0x00 }, // t { 0x0E, 0x10, 0x1E, 0x00, 0x00 }, // u { 0x0E, 0x10, 0x0E, 0x00, 0x00 }, // v { 0x0E, 0x10, 0x1E, 0x10, 0x1E }, // w { 0x12, 0x0C, 0x12, 0x00, 0x00 }, // x { 0x16, 0x14, 0x0E, 0x00, 0x00 }, // y { 0x12, 0x1A, 0x16, 0x00, 0x00 }, // z { 0x04, 0x1B, 0x11, 0x00, 0x00 }, // { { 0x00, 0x00, 0x1F, 0x00, 0x00 }, // | { 0x00, 0x11, 0x1B, 0x04, 0x00 }, // } { 0x02, 0x01, 0x02, 0x01, 0x00 }, // ~ { 0x00, 0x00, 0x00, 0x00, 0x00 }, // }; Render::Render() : mLcd() , mBufferIndex(0) , mDrawMode(DM_POSITIVE) , mFrameCount(0) , mAnimSpeed(4) , mAnimPat(PAT_0) { } void Render::init() { mDrawMode = DM_POSITIVE; mAnimPat = PAT_0; mAnimSpeed = 4; mFrameCount = 0; memset(mVRAM, 0, VRAM_SIZE * BUFFER_MAX); memset(mDirty, 0, sizeof(mDirty)); mBufferIndex = 0; mLcd.init(); mLcd.blit(mVRAM[mBufferIndex]); } void Render::update() { ++mFrameCount; } void Render::present() { #if RENDER_ENABLE_DIRTY_CHECK //mLcd.blit(mVRAM[mBufferIndex], mDirty); //memset(mDirty, 0, sizeof(mDirty)); const u8 prevIndex = (mBufferIndex + BUFFER_MAX - 1) % BUFFER_MAX; for (u8 x = 0; x < SCREEN_WIDTH; ++x) { u8 d = 0; for (u8 y = 0; y < 8; ++y) { const u32 i = (x << 3) + y; d |= (mVRAM[mBufferIndex][i] ^ mVRAM[prevIndex][i]) ? (1 << y) : 0; } mDirty[x] = d; } mLcd.blit(mVRAM[mBufferIndex], mDirty); const u8 nextIndex = (mBufferIndex + 1) % BUFFER_MAX; memcpy(mVRAM[nextIndex], mVRAM[mBufferIndex], VRAM_SIZE); mBufferIndex = nextIndex; #else mLcd.blit(mVRAM); #endif } bool Render::readPixel(u8 x, u8 y) { return mVRAM[mBufferIndex][(x << 3) + (y >> 3)] & (1 << (y & 0x7)); } void Render::unmap() { #if RENDER_ENABLE_DIRTY_CHECK //memset(mDirty, 0xFF, sizeof(mDirty)); #else /* nop */ #endif } void Render::clear() { memset(mVRAM[mBufferIndex], 0, VRAM_SIZE); #if RENDER_ENABLE_DIRTY_CHECK //memset(mDirty, 0xFF, sizeof(mDirty)); #endif } void Render::combine(u8 x, u8 y, u8 src, u8 mask) { u8 &dst = mVRAM[mBufferIndex][(x << 3) + (y >> 3)]; #if RENDER_ENABLE_DIRTY_CHECK //const u8 old = dst; #endif if (mDrawMode & DM_NEGATIVE) src = ~src; if (mDrawMode & 0xFF) mAnimPat = mDrawMode & 0xFF; if (mDrawMode & DM_PAT) src &= genAnimPat(x, y, src, mask); if (mDrawMode & DM_NPAT) src &= ~genAnimPat(x, y, src, mask); switch (mDrawMode & DM_OP_MASK) { case DM_POSITIVE: default: dst = (dst & mask) | (src & ~mask); break; case DM_ADD: dst = dst | (src & ~mask); break; case DM_INVERSE: dst = dst ^ (src & ~mask); break; case DM_SUBTRACT: dst = dst & ~(src & ~mask); break; } #if RENDER_ENABLE_DIRTY_CHECK //if (dst != old) // mDirty[x] |= 1 << (y >> 3); #endif } u8 Render::genAnimPat(u8 x, u8 y, u8 src, u8 mask) { u8 res = 0; const u8 anim = mFrameCount >> mAnimSpeed; for (u8 i = y & 0x7, s = (src & ~mask) >> i; s != 0; ++i, s >>= 1, ++y) { if (!(s & 0x1)) continue; u8 pat = 0xFF; switch (mAnimPat) { case PAT_0: // . # // # . pat = ((x + y + anim) & 0x1) ? 0xFF : 0x00; break; case PAT_1: // . # # # // # # # . // # # . # // # . # # pat = ((x + y + anim) & 0x3) ? 0xFF : 0x00; break; case PAT_2: // . # # # // # . # . // # # . # // # . # . pat = ((y & 0x1) ? !((x + anim) & 0x1) : ((x + y + anim) & 0x3)) ? 0xFF : 0x00; //pat = (anim & 0x1) ? ~pat : pat; break; case PAT_3: // . # > # . > # # > # # // # # > # # > . # > # . pat = (((x + anim) & 0x1) || ((y + (anim >> 1)) & 0x1)) ? 0xFF : 0x00; break; case PAT_4: // inverse of PAT_3 pat = !(((x + anim) & 0x1) || ((y + (anim >> 1)) & 0x1)) ? 0xFF : 0x00; break; case PAT_5: // . # # . > # . . # > # # # # > # # # # // # # # # > # # # # > . # # . > # . . # // # # # # > # # # # > . # # . > # . . # // . # # . > # . . # > # # # # > # # # # pat = ((((x >> 1) + x + anim) & 0x1) || (((y >> 1) + y + (anim >> 1)) & 0x1)) ? 0xFF : 0x00; // # . # . > . # . # // # . # . > . # . # // . # . # > # . # . // . # . # > # . # . pat |= ((x + (y >> 1) + (anim >> 2)) & 0x1) ? 0xFF : 0x00; //pat |= ((x + (y >> 1) + (anim >> 2)) & 0x1) ? (((x + y + anim) & 0x1) ? 0xFF : 0x00) : 0x00; // # # . . > # # . . // . . # # > . . # # // # # . . > # # . . // . . # # > . . # # //pat |= (((x >> 1) + y + (anim >> 2)) & 0x1) ? 0xFF : 0x00; break; case PAT_6: // inverse of PAT_5 pat = ((((x >> 1) + x + anim) & 0x1) || (((y >> 1) + y + (anim >> 1)) & 0x1)) ? 0xFF : 0x00; pat |= ((x + (y >> 1) + (anim >> 2)) & 0x1) ? 0xFF : 0x00; //pat |= ((x + (y >> 1) + (anim >> 2)) & 0x1) ? (((x + y + anim) & 0x1) ? 0xFF : 0x00) : 0x00; pat ^= 0xFF; break; default: break; } res |= pat & (1 << i); } return res; } void Render::drawPixel(s16 x, s16 y) { if (x < 0 || SCREEN_WIDTH <= x || y < 0 || SCREEN_HEIGHT <= y) return; const u8 mask = 1 << (y & 0x7); #if 1 combine(x, y, mask, ~mask); #else u8 &dst = mVRAM[(x << 3) + (y >> 3)]; switch (mDrawMode) { case DM_POSITIVE: default: dst |= mask; break; case DM_NEGATIVE: dst &= ~mask; break; case DM_INVERSE: dst ^= mask; break; } #endif } void Render::fillRect(s16 x, s16 y, u8 w, u8 h) { const s16 l = x + w; const s16 b = y + h; if (l < 0 || b < 0) return; for (s16 i = x; i < l; ++i) { for (s16 j = y; j < b; ++j) { drawPixel(i, j); } } } void Render::drawLine(s16 x1, s16 y1, s16 x2, s16 y2, bool conservative) { const s16 dx = abs(x2 - x1); const s16 dy = abs(y2 - y1); const s16 vx = x1 < x2 ? 1 : -1; const s16 vy = y1 < y2 ? 1 : -1; s16 error = 0; if (conservative) { x2 += vx; y2 += vy; } if (dx > dy) { for (s16 x = x1, y = y1; x != x2; x += vx) { drawPixel(x, y); error += dy << 1; if (error > dx) { y += vy; error -= dx << 1; } } } else { for (s16 x = x1, y = y1; y != y2; y += vy) { drawPixel(x, y); error += dx << 1; if (error > dy) { x += vx; error -= dy << 1; } } } } void Render::drawPolygon(u8 n, const s16* x, const s16* y) { for (u8 i = 0; i < n; ++i) { const u8 j = (i + 1) % n; drawLine(x[i], y[i], x[j], y[j], false); } } void Render::drawImage(s16 x, s16 y, const u8* img, u8 w, u8 h) { const s16 l = x + w; const s16 b = y + h; if (l < 0 || SCREEN_WIDTH <= x || b < 0 || SCREEN_HEIGHT <= y) return; u8 shift1 = y & 0x7; u8 shift2 = h - (b & 0x7); u8 mask1 = ~((0xFF >> (8 - h)) << shift1) & 0xFF; u8 mask2 = (0xFF << (h - shift2)) & 0xFF; for (u8 i = 0; i < w; ++i) { const s16 xi = x + i; if (xi < 0) continue; if (xi >= SCREEN_WIDTH) break; const u8 page = img[i]; if (0 <= y) combine(xi, y, page << shift1, mask1); if (b < SCREEN_HEIGHT && (y >> 3) != (b >> 3)) combine(xi, b & 0xF8, page >> shift2, mask2); } } void Render::drawImageShift(s8 sx, s8 sy, s16 x, s16 y, const u8* img, u8 w, u8 h) { const s16 l = x + w; const s16 b = y + h; if (l < 0 || SCREEN_WIDTH <= x || b < 0 || SCREEN_HEIGHT <= y) return; u8 shift1 = y & 0x7; u8 shift2 = h - (b & 0x7); u8 mask1 = ~((0xFF >> (8 - h)) << shift1) & 0xFF; u8 mask2 = (0xFF << (h - shift2)) & 0xFF; sx %= w; sy %= 8; if (sy < 0) sy += 8; for (u8 i = 0; i < w; ++i) { const s16 xi = x + i; if (xi < 0) continue; if (xi >= SCREEN_WIDTH) break; u8 page = img[(i + sx + w) % w]; page = (page << sy) | (page >> (8 - sy)); if (0 <= y) combine(xi, y, page << shift1, mask1); if (b < SCREEN_HEIGHT && (y >> 3) != (b >> 3)) combine(xi, b & 0xF8, page >> shift2, mask2); } } void Render::drawString(s16 x, s16 y, const char* fmt, ...) { if (SCREEN_WIDTH <= x || SCREEN_HEIGHT <= y) return; char buf[256]; va_list args; va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); s16 b = y + FONT_SIZE; s16 cx = 0; u8 shift1, shift2, mask1, mask2; for (u8 i = 0; buf[i]; ++i, ++cx) { const char c = buf[i]; if (i == 0 || c == '\n') { if (c == '\n') { y += FONT_SIZE; if (y >= SCREEN_HEIGHT) break; b = y + FONT_SIZE; cx = -1; } shift1 = y & 0x7; shift2 = FONT_SIZE - (b & 0x7); mask1 = ~((0xFF >> (8 - FONT_SIZE)) << shift1) & 0xFF; mask2 = (0xFF << (FONT_SIZE - shift2)) & 0xFF; } if (b < 0 || c < 0x20 || 0x7F < c) continue; const s16 fx = x + cx * FONT_SIZE; if (fx + FONT_SIZE < 0) continue; const u8 fi = c - 0x20; for (u8 j = 0; j < FONT_SIZE; ++j) { const s16 fxj = fx + j; if (fxj < 0) continue; if (fxj >= SCREEN_WIDTH) break; const u8 page = j == 0 ? 0 : font[fi][j - 1]; if (0 <= y) combine(fxj, y, page << shift1, mask1); if (b < SCREEN_HEIGHT && (y >> 3) != (b >> 3)) combine(fxj, b & 0xF8, page >> shift2, mask2); } } } void System::BtnInfo::update(bool now) { on = now; trg = on && !old; rel = old && !on; old = on; rep = trg; if (on) { if (++count >= (rep1 ? rep_count : rep1_count)) { rep = true; rep1 = true; count = 0; } } else { rep1 = false; count = 0; } } const System::Desc System::DefaultDesc = { LED1, // led1 A1, // btn_black A0, // btn_red A2, // joy_x A3, // joy_y USBTX, // serial_tx USBRX, // serial_rx #if ENABLE_PGC2000 PC_4, // led2 PC_2, // btn_green PC_3, // btn_blue PB_9, // btn_white PB_8, // btn_orange PB_12, // dip1 PB_13, // dip2 PB_14, // dip3 PB_15, // dip4 #endif }; System::System(const Desc &desc) : FPS(0) , MICROSEC_PER_FRAME(0) , FRAME_PER_MICROSEC(0.f) , mFrameWait(true) , mFrameCount(0) , mPrevTime(0) , mFrameTime(0.f) , mDeltaTime(0.f) , mFPS(0.f) , mFrameCountTemp(0) , mPrevTimeTemp(0) , mAnalogX(0.f) , mAnalogY(0.f) , mLed1(desc.led1) , mBtnBlack(desc.btn_black, PullUp) , mBtnRed(desc.btn_red, PullUp) , mJoyX(desc.joy_x) , mJoyY(desc.joy_y) , mSerial(desc.serial_tx, desc.serial_rx) #if ENABLE_PGC2000 , mLed2(desc.led2) , mBtnGreen(desc.btn_green, PullUp) , mBtnBlue(desc.btn_blue, PullUp) , mBtnWhite(desc.btn_white, PullUp) , mBtnOrange(desc.btn_orange, PullUp) , mDip(desc.dip1, desc.dip2, desc.dip3, desc.dip4) #endif { } void System::init() { setFPS(30); mSerial.baud(115200); mFrameWait = true; mFrameTime = mFPS = 0.f; mFrameCount = mFrameCountTemp = 0; mPrevTime = mPrevTimeTemp = us_ticker_read(); memset(&mBtnInfoBlack, 0, sizeof(BtnInfo)); memset(&mBtnInfoRed, 0, sizeof(BtnInfo)); #if ENABLE_PGC2000 memset(&mBtnInfoGreen, 0, sizeof(BtnInfo)); memset(&mBtnInfoBlue, 0, sizeof(BtnInfo)); memset(&mBtnInfoWhite, 0, sizeof(BtnInfo)); memset(&mBtnInfoOrange, 0, sizeof(BtnInfo)); #endif memset(&mBtnInfoLeft, 0, sizeof(BtnInfo)); memset(&mBtnInfoRight, 0, sizeof(BtnInfo)); memset(&mBtnInfoUp, 0, sizeof(BtnInfo)); memset(&mBtnInfoDown, 0, sizeof(BtnInfo)); mBtnInfoBlack.rep1_count = mBtnInfoRed.rep1_count = 15; mBtnInfoBlack.rep_count = mBtnInfoRed.rep_count = 5; mBtnInfoLeft.rep1_count = mBtnInfoRight.rep1_count = 5; mBtnInfoLeft.rep_count = mBtnInfoRight.rep_count = 3; mBtnInfoUp.rep1_count = mBtnInfoDown.rep1_count = 5; mBtnInfoUp.rep_count = mBtnInfoDown.rep_count = 2; #if ENABLE_PGC2000 mDip.mode(PullUp); #endif } void System::update() { ++mFrameCount; //mLed1 = mFrameCount & 1; //mSerial.printf("%d ", mFrameCount); mBtnInfoBlack.update(!mBtnBlack.read()); mBtnInfoRed.update(!mBtnRed.read()); #if ENABLE_PGC2000 mBtnInfoGreen.update(!mBtnGreen.read()); mBtnInfoBlue.update(!mBtnBlue.read()); mBtnInfoWhite.update(!mBtnWhite.read()); mBtnInfoOrange.update(!mBtnOrange.read()); #endif mAnalogX = mJoyX.read() - 0.5f; mBtnInfoLeft.update(mAnalogX < -0.1f); mBtnInfoRight.update(mAnalogX > 0.1f); mAnalogY = 0.5f - mJoyY.read(); mBtnInfoUp.update(mAnalogY < -0.1f); mBtnInfoDown.update(mAnalogY > 0.1f); wait_us(100); #if SYSTEM_ENABLE_MEASURE_FPS if (++mFrameCountTemp > FPS) { const u32 current = us_ticker_read(); const u32 elapsed = current - mPrevTimeTemp; mFPS = 1000000.f * FPS / elapsed; mFrameCountTemp = 0; mPrevTimeTemp = current; } #endif } void System::frameWait() { #if SYSTEM_ENABLE_FRAME_WAIT const u32 elapsed = us_ticker_read() - mPrevTime; mFrameTime = elapsed * 0.001f; if (elapsed < MICROSEC_PER_FRAME) { mLed1 = 1; wait_us(MICROSEC_PER_FRAME - elapsed); } const u32 current = us_ticker_read(); mDeltaTime = static_cast<f32>(current - mPrevTime) * FRAME_PER_MICROSEC; mPrevTime = current; mLed1 = 0; #endif } void System::drawInfo(Render &render) { const u32 dm = render.getDrawMode(); render.drawString(0, 0, "%.1fFPS", mFPS); render.drawString(0, 6, "%.1fms", mFrameTime); render.setDrawMode(DM_POSITIVE); render.drawFillRect(0, 12, 12, 12); render.setDrawMode(DM_NEGATIVE); render.drawFillRect(12, 12, 12, 12); render.setDrawMode(DM_INVERSE); render.drawString(3 + mAnalogX * 6, 16 + mAnalogY * 6, "+"); render.drawString(12, 16, "%c%c", (mBtnInfoBlack.on ? (mBtnInfoBlack.rep ? 'X' : 'O') : '-'), (mBtnInfoRed.on ? (mBtnInfoRed.rep ? 'X' : 'O') : '-')); render.setDrawMode(dm); } void System::printf(char* fmt, ...) { va_list args; va_start(args, fmt); mSerial.vprintf(fmt, args); va_end(args); } void System::scanf(char* fmt, ...) { va_list args; va_start(args, fmt); mSerial.vscanf(fmt, args); va_end(args); } #if ENABLE_PGC2000 const Psg::Desc Psg::DefaultDesc = { PC_6, // wr PC_5, // cs PA_12, // a0 PC_8, // ic PB_7, // d0 PA_15, // d1 PC_9, // d2 PB_2, // d3 PC_12, // d4 PA_11, // d5 PC_10, // d6 PC_11, // d7 }; Psg::Psg(const Desc &desc) : mAddress(0xFF) , mWR(desc.wr) , mCS(desc.cs) , mA0(desc.a0) , mIC(desc.ic) , mD(desc.d0, desc.d1, desc.d2, desc.d3, desc.d4, desc.d5, desc.d6, desc.d7) { } void Psg::init() { mAddress = 0xFF; mCS = 0; mWR = 1; mIC = 0; wait_us(5); mIC = 1; } void Psg::writeAddress(u8 adr) { //mCS = 0; mAddress = 0xFF; mD = adr; mA0 = 0; mWR = 0; wait_us(1); mWR = 1; wait_us(1); } void Psg::writeData(u8 data) { //mCS = 0; mD = data; mA0 = 1; mWR = 0; wait_us(1); mWR = 1; wait_us(1); } void Psg::write(u8 adr, u8 data) { //mCS = 0; if (mAddress != adr) { mD = mAddress = adr; mA0 = 0; mWR = 0; wait_us(1); mWR = 1; wait_us(1); } mD = data; mA0 = 1; mWR = 0; wait_us(1); mWR = 1; wait_us(1); } Sound::Sound() : mPsg() { } void Sound::init() { mPsg.init(); } #endif App::App() { } App::~App() { } void App::init() { mSystem.init(); mRender.init(); #if ENABLE_PGC2000 mSound.init(); #endif } void App::exec() { init(); while (true) { update(); #if SYSTEM_ENABLE_FRAME_WAIT if (mSystem.isFrameWait()) mSystem.frameWait(); #endif } } void App::update() { mRender.update(); mSystem.update(); }
25.812846
154
0.472092
[ "render" ]
886c953f5995e9ef6e5f7080e0c23a50e234f7b7
28,778
cpp
C++
modules/3d/src/rgbd/normal.cpp
Gabrielreisribeiro/opencv
39df6d2f035ca6822494fe4234e163895828b23b
[ "Apache-2.0" ]
null
null
null
modules/3d/src/rgbd/normal.cpp
Gabrielreisribeiro/opencv
39df6d2f035ca6822494fe4234e163895828b23b
[ "Apache-2.0" ]
null
null
null
modules/3d/src/rgbd/normal.cpp
Gabrielreisribeiro/opencv
39df6d2f035ca6822494fe4234e163895828b23b
[ "Apache-2.0" ]
1
2021-04-30T18:00:41.000Z
2021-04-30T18:00:41.000Z
// This file is part of OpenCV project. // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html #include "../precomp.hpp" namespace cv { /** Just compute the norm of a vector * @param vec a vector of size 3 and any type T * @return */ template<typename T> T inline norm_vec(const Vec<T, 3>& vec) { return std::sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]); } template<typename T> T inline norm_vec(const Vec<T, 4>& vec) { return std::sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]); } /** Given 3d points, compute their distance to the origin * @param points * @return */ template<typename T> Mat_<T> computeRadius(const Mat& points) { typedef Vec<T, 4> PointT; // Compute the Size size(points.cols, points.rows); Mat_<T> r(size); if (points.isContinuous()) size = Size(points.cols * points.rows, 1); for (int y = 0; y < size.height; ++y) { const PointT* point = points.ptr < PointT >(y), * point_end = points.ptr < PointT >(y) + size.width; T* row = r[y]; for (; point != point_end; ++point, ++row) *row = norm_vec(*point); } return r; } // Compute theta and phi according to equation 3 of // ``Fast and Accurate Computation of Surface Normals from Range Images`` // by H. Badino, D. Huber, Y. Park and T. Kanade template<typename T> void computeThetaPhi(int rows, int cols, const Matx<T, 3, 3>& K, Mat& cos_theta, Mat& sin_theta, Mat& cos_phi, Mat& sin_phi) { // Create some bogus coordinates Mat depth_image = K(0, 0) * Mat_<T> ::ones(rows, cols); Mat points3d; depthTo3d(depth_image, Mat(K), points3d); //typedef Vec<T, 3> Vec3T; typedef Vec<T, 4> Vec4T; cos_theta = Mat_<T>(rows, cols); sin_theta = Mat_<T>(rows, cols); cos_phi = Mat_<T>(rows, cols); sin_phi = Mat_<T>(rows, cols); Mat r = computeRadius<T>(points3d); for (int y = 0; y < rows; ++y) { T* row_cos_theta = cos_theta.ptr <T>(y), * row_sin_theta = sin_theta.ptr <T>(y); T* row_cos_phi = cos_phi.ptr <T>(y), * row_sin_phi = sin_phi.ptr <T>(y); const Vec4T* row_points = points3d.ptr <Vec4T>(y), * row_points_end = points3d.ptr <Vec4T>(y) + points3d.cols; const T* row_r = r.ptr < T >(y); for (; row_points < row_points_end; ++row_cos_theta, ++row_sin_theta, ++row_cos_phi, ++row_sin_phi, ++row_points, ++row_r) { // In the paper, z goes away from the camera, y goes down, x goes right // OpenCV has the same conventions // Theta goes from z to x (and actually goes from -pi/2 to pi/2, phi goes from z to y float theta = (float)std::atan2(row_points->val[0], row_points->val[2]); *row_cos_theta = std::cos(theta); *row_sin_theta = std::sin(theta); float phi = (float)std::asin(row_points->val[1] / (*row_r)); *row_cos_phi = std::cos(phi); *row_sin_phi = std::sin(phi); } } } /** Modify normals to make sure they point towards the camera * @param normals */ template<typename T> inline void signNormal(const Vec<T, 3>& normal_in, Vec<T, 3>& normal_out) { Vec<T, 3> res; if (normal_in[2] > 0) res = -normal_in / norm_vec(normal_in); else res = normal_in / norm_vec(normal_in); normal_out[0] = res[0]; normal_out[1] = res[1]; normal_out[2] = res[2]; } template<typename T> inline void signNormal(const Vec<T, 3>& normal_in, Vec<T, 4>& normal_out) { Vec<T, 3> res; if (normal_in[2] > 0) res = -normal_in / norm_vec(normal_in); else res = normal_in / norm_vec(normal_in); normal_out[0] = res[0]; normal_out[1] = res[1]; normal_out[2] = res[2]; normal_out[3] = 0; } /** Modify normals to make sure they point towards the camera * @param normals */ template<typename T> inline void signNormal(T a, T b, T c, Vec<T, 3>& normal) { T norm = 1 / std::sqrt(a * a + b * b + c * c); if (c > 0) { normal[0] = -a * norm; normal[1] = -b * norm; normal[2] = -c * norm; } else { normal[0] = a * norm; normal[1] = b * norm; normal[2] = c * norm; } } template<typename T> inline void signNormal(T a, T b, T c, Vec<T, 4>& normal) { T norm = 1 / std::sqrt(a * a + b * b + c * c); if (c > 0) { normal[0] = -a * norm; normal[1] = -b * norm; normal[2] = -c * norm; normal[3] = 0; } else { normal[0] = a * norm; normal[1] = b * norm; normal[2] = c * norm; normal[3] = 0; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template<typename T> class RgbdNormalsImpl : public RgbdNormals { public: static const int dtype = cv::traits::Depth<T>::value; RgbdNormalsImpl(int _rows, int _cols, int _windowSize, const Mat& _K, RgbdNormals::RgbdNormalsMethod _method) : rows(_rows), cols(_cols), windowSize(_windowSize), method(_method), cacheIsDirty(true) { CV_Assert(_K.cols == 3 && _K.rows == 3); _K.convertTo(K, dtype); _K.copyTo(K_ori); } virtual ~RgbdNormalsImpl() CV_OVERRIDE { } virtual int getDepth() const CV_OVERRIDE { return dtype; } virtual int getRows() const CV_OVERRIDE { return rows; } virtual void setRows(int val) CV_OVERRIDE { rows = val; cacheIsDirty = true; } virtual int getCols() const CV_OVERRIDE { return cols; } virtual void setCols(int val) CV_OVERRIDE { cols = val; cacheIsDirty = true; } virtual int getWindowSize() const CV_OVERRIDE { return windowSize; } virtual void setWindowSize(int val) CV_OVERRIDE { windowSize = val; cacheIsDirty = true; } virtual void getK(OutputArray val) const CV_OVERRIDE { K.copyTo(val); } virtual void setK(InputArray val) CV_OVERRIDE { K = val.getMat(); cacheIsDirty = true; } virtual RgbdNormalsMethod getMethod() const CV_OVERRIDE { return method; } virtual void setMethod(RgbdNormalsMethod val) CV_OVERRIDE { method = val; cacheIsDirty = true; } // Helper functions for apply() virtual void assertOnBadArg(const Mat& points3d_ori) const = 0; virtual void calcRadiusAnd3d(const Mat& points3d_ori, Mat& points3d, Mat& radius) const { // Make the points have the right depth if (points3d_ori.depth() == dtype) points3d = points3d_ori; else points3d_ori.convertTo(points3d, dtype); // Compute the distance to the points radius = computeRadius<T>(points3d); } virtual void compute(const Mat& in, Mat& normals) const = 0; /** Given a set of 3d points in a depth image, compute the normals at each point * @param points3d_in depth a float depth image. Or it can be rows x cols x 3 is they are 3d points * @param normals a rows x cols x 3 matrix */ virtual void apply(InputArray points3d_in, OutputArray normals_out) const CV_OVERRIDE { Mat points3d_ori = points3d_in.getMat(); CV_Assert(points3d_ori.dims == 2); // Either we have 3d points or a depth image assertOnBadArg(points3d_ori); // Initialize the pimpl cache(); // Precompute something for RGBD_NORMALS_METHOD_SRI and RGBD_NORMALS_METHOD_FALS Mat points3d, radius; calcRadiusAnd3d(points3d_ori, points3d, radius); // Get the normals normals_out.create(points3d_ori.size(), CV_MAKETYPE(dtype, 4)); if (points3d_in.empty()) return; Mat normals = normals_out.getMat(); if ((method == RGBD_NORMALS_METHOD_FALS) || (method == RGBD_NORMALS_METHOD_SRI)) { compute(radius, normals); } else // LINEMOD { compute(points3d_ori, normals); } } int rows, cols; Mat K, K_ori; int windowSize; RgbdNormalsMethod method; mutable bool cacheIsDirty; }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** Given a set of 3d points in a depth image, compute the normals at each point * using the FALS method described in * ``Fast and Accurate Computation of Surface Normals from Range Images`` * by H. Badino, D. Huber, Y. Park and T. Kanade */ template<typename T> class FALS : public RgbdNormalsImpl<T> { public: typedef Matx<T, 3, 3> Mat33T; typedef Vec<T, 9> Vec9T; typedef Vec<T, 4> Vec4T; typedef Vec<T, 3> Vec3T; FALS(int _rows, int _cols, int _windowSize, const Mat& _K) : RgbdNormalsImpl<T>(_rows, _cols, _windowSize, _K, RgbdNormals::RGBD_NORMALS_METHOD_FALS) { } virtual ~FALS() CV_OVERRIDE { } /** Compute cached data */ virtual void cache() const CV_OVERRIDE { if (!this->cacheIsDirty) return; // Compute theta and phi according to equation 3 Mat cos_theta, sin_theta, cos_phi, sin_phi; computeThetaPhi<T>(this->rows, this->cols, this->K, cos_theta, sin_theta, cos_phi, sin_phi); // Compute all the v_i for every points std::vector<Mat> channels(3); channels[0] = sin_theta.mul(cos_phi); channels[1] = sin_phi; channels[2] = cos_theta.mul(cos_phi); merge(channels, V_); // Compute M Mat_<Vec9T> M(this->rows, this->cols); Mat33T VVt; const Vec3T* vec = V_[0]; Vec9T* M_ptr = M[0], * M_ptr_end = M_ptr + this->rows * this->cols; for (; M_ptr != M_ptr_end; ++vec, ++M_ptr) { VVt = (*vec) * vec->t(); *M_ptr = Vec9T(VVt.val); } boxFilter(M, M, M.depth(), Size(this->windowSize, this->windowSize), Point(-1, -1), false); // Compute M's inverse Mat33T M_inv; M_inv_.create(this->rows, this->cols); Vec9T* M_inv_ptr = M_inv_[0]; for (M_ptr = &M(0); M_ptr != M_ptr_end; ++M_inv_ptr, ++M_ptr) { // We have a semi-definite matrix invert(Mat33T(M_ptr->val), M_inv, DECOMP_CHOLESKY); *M_inv_ptr = Vec9T(M_inv.val); } this->cacheIsDirty = false; } /** Compute the normals * @param r * @return */ virtual void compute(const Mat& r, Mat& normals) const CV_OVERRIDE { // Compute B Mat_<Vec3T> B(this->rows, this->cols); const T* row_r = r.ptr < T >(0), * row_r_end = row_r + this->rows * this->cols; const Vec3T* row_V = V_[0]; Vec3T* row_B = B[0]; for (; row_r != row_r_end; ++row_r, ++row_B, ++row_V) { Vec3T val = (*row_V) / (*row_r); if (cvIsInf(val[0]) || cvIsNaN(val[0]) || cvIsInf(val[1]) || cvIsNaN(val[1]) || cvIsInf(val[2]) || cvIsNaN(val[2])) *row_B = Vec3T(); else *row_B = val; } // Apply a box filter to B boxFilter(B, B, B.depth(), Size(this->windowSize, this->windowSize), Point(-1, -1), false); // compute the Minv*B products row_r = r.ptr < T >(0); const Vec3T* B_vec = B[0]; const Mat33T* M_inv = reinterpret_cast<const Mat33T*>(M_inv_.ptr(0)); //Vec3T* normal = normals.ptr<Vec3T>(0); Vec4T* normal = normals.ptr<Vec4T>(0); for (; row_r != row_r_end; ++row_r, ++B_vec, ++normal, ++M_inv) if (cvIsNaN(*row_r)) { (*normal)[0] = *row_r; (*normal)[1] = *row_r; (*normal)[2] = *row_r; (*normal)[3] = 0; } else { Mat33T Mr = *M_inv; Vec3T Br = *B_vec; Vec3T MBr(Mr(0, 0) * Br[0] + Mr(0, 1) * Br[1] + Mr(0, 2) * Br[2], Mr(1, 0) * Br[0] + Mr(1, 1) * Br[1] + Mr(1, 2) * Br[2], Mr(2, 0) * Br[0] + Mr(2, 1) * Br[1] + Mr(2, 2) * Br[2]); signNormal(MBr, *normal); } } virtual void assertOnBadArg(const Mat& points3d_ori) const CV_OVERRIDE { //CV_Assert(points3d_ori.channels() == 3); CV_Assert(points3d_ori.channels() == 4); CV_Assert(points3d_ori.depth() == CV_32F || points3d_ori.depth() == CV_64F); } // Cached data mutable Mat_<Vec3T> V_; mutable Mat_<Vec9T> M_inv_; }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** Function that multiplies K_inv by a vector. It is just meant to speed up the product as we know * that K_inv is upper triangular and K_inv(2,2)=1 * @param K_inv * @param a * @param b * @param c * @param res */ template<typename T, typename U> void multiply_by_K_inv(const Matx<T, 3, 3>& K_inv, U a, U b, U c, Vec<T, 3>& res) { res[0] = (T)(K_inv(0, 0) * a + K_inv(0, 1) * b + K_inv(0, 2) * c); res[1] = (T)(K_inv(1, 1) * b + K_inv(1, 2) * c); res[2] = (T)c; } /** Given a depth image, compute the normals as detailed in the LINEMOD paper * ``Gradient Response Maps for Real-Time Detection of Texture-Less Objects`` * by S. Hinterstoisser, C. Cagniart, S. Ilic, P. Sturm, N. Navab, P. Fua, and V. Lepetit */ template<typename T> class LINEMOD : public RgbdNormalsImpl<T> { public: typedef Vec<T, 4> Vec4T; typedef Vec<T, 3> Vec3T; typedef Matx<T, 3, 3> Mat33T; LINEMOD(int _rows, int _cols, int _windowSize, const Mat& _K) : RgbdNormalsImpl<T>(_rows, _cols, _windowSize, _K, RgbdNormals::RGBD_NORMALS_METHOD_LINEMOD) { } /** Compute cached data */ virtual void cache() const CV_OVERRIDE { } /** Compute the normals * @param r * @param normals the output normals */ virtual void compute(const Mat& points3d, Mat& normals) const CV_OVERRIDE { // Only focus on the depth image for LINEMOD Mat depth_in; //if (points3d.channels() == 3) if (points3d.channels() == 4) { std::vector<Mat> channels; split(points3d, channels); depth_in = channels[2]; } else depth_in = points3d; switch (depth_in.depth()) { case CV_16U: { const Mat_<unsigned short>& d(depth_in); computeImpl<unsigned short, long>(d, normals); break; } case CV_32F: { const Mat_<float>& d(depth_in); computeImpl<float, float>(d, normals); break; } case CV_64F: { const Mat_<double>& d(depth_in); computeImpl<double, double>(d, normals); break; } } } /** Compute the normals * @param r * @return */ template<typename DepthDepth, typename ContainerDepth> Mat computeImpl(const Mat_<DepthDepth>& depthIn, Mat& normals) const { const int r = 5; // used to be 7 const int sample_step = r; const int square_size = ((2 * r / sample_step) + 1); long offsets[square_size * square_size]; long offsets_x[square_size * square_size]; long offsets_y[square_size * square_size]; long offsets_x_x[square_size * square_size]; long offsets_x_y[square_size * square_size]; long offsets_y_y[square_size * square_size]; for (int j = -r, index = 0; j <= r; j += sample_step) for (int i = -r; i <= r; i += sample_step, ++index) { offsets_x[index] = i; offsets_y[index] = j; offsets_x_x[index] = i * i; offsets_x_y[index] = i * j; offsets_y_y[index] = j * j; offsets[index] = j * this->cols + i; } // Define K_inv by hand, just for higher accuracy Mat33T K_inv = Matx<T, 3, 3>::eye(), kmat; this->K.copyTo(kmat); K_inv(0, 0) = 1.0f / kmat(0, 0); K_inv(0, 1) = -kmat(0, 1) / (kmat(0, 0) * kmat(1, 1)); K_inv(0, 2) = (kmat(0, 1) * kmat(1, 2) - kmat(0, 2) * kmat(1, 1)) / (kmat(0, 0) * kmat(1, 1)); K_inv(1, 1) = 1 / kmat(1, 1); K_inv(1, 2) = -kmat(1, 2) / kmat(1, 1); Vec3T X1_minus_X, X2_minus_X; ContainerDepth difference_threshold = 50; normals.setTo(std::numeric_limits<DepthDepth>::quiet_NaN()); for (int y = r; y < this->rows - r - 1; ++y) { const DepthDepth* p_line = reinterpret_cast<const DepthDepth*>(depthIn.ptr(y, r)); Vec4T* normal = normals.ptr<Vec4T>(y, r); for (int x = r; x < this->cols - r - 1; ++x) { DepthDepth d = p_line[0]; // accum long A[4]; A[0] = A[1] = A[2] = A[3] = 0; ContainerDepth b[2]; b[0] = b[1] = 0; for (unsigned int i = 0; i < square_size * square_size; ++i) { // We need to cast to ContainerDepth in case we have unsigned DepthDepth ContainerDepth delta = ContainerDepth(p_line[offsets[i]]) - ContainerDepth(d); if (std::abs(delta) > difference_threshold) continue; A[0] += offsets_x_x[i]; A[1] += offsets_x_y[i]; A[3] += offsets_y_y[i]; b[0] += offsets_x[i] * delta; b[1] += offsets_y[i] * delta; } // solve for the optimal gradient D of equation (8) long det = A[0] * A[3] - A[1] * A[1]; // We should divide the following two by det, but instead, we multiply // X1_minus_X and X2_minus_X by det (which does not matter as we normalize the normals) // Therefore, no division is done: this is only for speedup ContainerDepth dx = (A[3] * b[0] - A[1] * b[1]); ContainerDepth dy = (-A[1] * b[0] + A[0] * b[1]); // Compute the dot product //Vec3T X = K_inv * Vec3T(x, y, 1) * depth(y, x); //Vec3T X1 = K_inv * Vec3T(x + 1, y, 1) * (depth(y, x) + dx); //Vec3T X2 = K_inv * Vec3T(x, y + 1, 1) * (depth(y, x) + dy); //Vec3T nor = (X1 - X).cross(X2 - X); multiply_by_K_inv(K_inv, d * det + (x + 1) * dx, y * dx, dx, X1_minus_X); multiply_by_K_inv(K_inv, x * dy, d * det + (y + 1) * dy, dy, X2_minus_X); Vec3T nor = X1_minus_X.cross(X2_minus_X); signNormal(nor, *normal); ++p_line; ++normal; } } return normals; } virtual void assertOnBadArg(const Mat& points3d_ori) const CV_OVERRIDE { CV_Assert(((points3d_ori.channels() == 4) && (points3d_ori.depth() == CV_32F || points3d_ori.depth() == CV_64F)) || ((points3d_ori.channels() == 1) && (points3d_ori.depth() == CV_16U || points3d_ori.depth() == CV_32F || points3d_ori.depth() == CV_64F))); } virtual void calcRadiusAnd3d(const Mat& /*points3d_ori*/, Mat& /*points3d*/, Mat& /*radius*/) const CV_OVERRIDE { } }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** Given a set of 3d points in a depth image, compute the normals at each point * using the SRI method described in * ``Fast and Accurate Computation of Surface Normals from Range Images`` * by H. Badino, D. Huber, Y. Park and T. Kanade */ template<typename T> class SRI : public RgbdNormalsImpl<T> { public: typedef Matx<T, 3, 3> Mat33T; typedef Vec<T, 9> Vec9T; typedef Vec<T, 4> Vec4T; typedef Vec<T, 3> Vec3T; SRI(int _rows, int _cols, int _windowSize, const Mat& _K) : RgbdNormalsImpl<T>(_rows, _cols, _windowSize, _K, RgbdNormals::RGBD_NORMALS_METHOD_SRI), phi_step_(0), theta_step_(0) { } /** Compute cached data */ virtual void cache() const CV_OVERRIDE { if (!this->cacheIsDirty) return; Mat_<T> cos_theta, sin_theta, cos_phi, sin_phi; computeThetaPhi<T>(this->rows, this->cols, this->K, cos_theta, sin_theta, cos_phi, sin_phi); // Create the derivative kernels getDerivKernels(kx_dx_, ky_dx_, 1, 0, this->windowSize, true, this->dtype); getDerivKernels(kx_dy_, ky_dy_, 0, 1, this->windowSize, true, this->dtype); // Get the mapping function for SRI float min_theta = (float)std::asin(sin_theta(0, 0)), max_theta = (float)std::asin(sin_theta(0, this->cols - 1)); float min_phi = (float)std::asin(sin_phi(0, this->cols / 2 - 1)), max_phi = (float)std::asin(sin_phi(this->rows - 1, this->cols / 2 - 1)); std::vector<Point3f> points3d(this->cols * this->rows); R_hat_.create(this->rows, this->cols); phi_step_ = float(max_phi - min_phi) / (this->rows - 1); theta_step_ = float(max_theta - min_theta) / (this->cols - 1); for (int phi_int = 0, k = 0; phi_int < this->rows; ++phi_int) { float phi = min_phi + phi_int * phi_step_; for (int theta_int = 0; theta_int < this->cols; ++theta_int, ++k) { float theta = min_theta + theta_int * theta_step_; // Store the 3d point to project it later points3d[k] = Point3f(std::sin(theta) * std::cos(phi), std::sin(phi), std::cos(theta) * std::cos(phi)); // Cache the rotation matrix and negate it Mat_<T> mat = (Mat_ < T >(3, 3) << 0, 1, 0, 0, 0, 1, 1, 0, 0) * ((Mat_ < T >(3, 3) << std::cos(theta), -std::sin(theta), 0, std::sin(theta), std::cos(theta), 0, 0, 0, 1)) * ((Mat_ < T >(3, 3) << std::cos(phi), 0, -std::sin(phi), 0, 1, 0, std::sin(phi), 0, std::cos(phi))); for (unsigned char i = 0; i < 3; ++i) mat(i, 1) = mat(i, 1) / std::cos(phi); // The second part of the matrix is never explained in the paper ... but look at the wikipedia normal article mat(0, 0) = mat(0, 0) - 2 * std::cos(phi) * std::sin(theta); mat(1, 0) = mat(1, 0) - 2 * std::sin(phi); mat(2, 0) = mat(2, 0) - 2 * std::cos(phi) * std::cos(theta); R_hat_(phi_int, theta_int) = Vec9T((T*)(mat.data)); } } map_.create(this->rows, this->cols); projectPoints(points3d, Mat(3, 1, CV_32FC1, Scalar::all(0.0f)), Mat(3, 1, CV_32FC1, Scalar::all(0.0f)), this->K, Mat(), map_); map_ = map_.reshape(2, this->rows); convertMaps(map_, Mat(), xy_, fxy_, CV_16SC2); //map for converting from Spherical coordinate space to Euclidean space euclideanMap_.create(this->rows, this->cols); Matx<T, 3, 3> km(this->K); float invFx = (float)(1.0f / km(0, 0)), cx = (float)(km(0, 2)); double invFy = 1.0f / (km(1, 1)), cy = km(1, 2); for (int i = 0; i < this->rows; i++) { float y = (float)((i - cy) * invFy); for (int j = 0; j < this->cols; j++) { float x = (j - cx) * invFx; float theta = std::atan(x); float phi = std::asin(y / std::sqrt(x * x + y * y + 1.0f)); euclideanMap_(i, j) = Vec2f((theta - min_theta) / theta_step_, (phi - min_phi) / phi_step_); } } //convert map to 2 maps in short format for increasing speed in remap function convertMaps(euclideanMap_, Mat(), invxy_, invfxy_, CV_16SC2); // Update the kernels: the steps are due to the fact that derivatives will be computed on a grid where // the step is not 1. Only need to do it on one dimension as it computes derivatives in only one direction kx_dx_ /= theta_step_; ky_dy_ /= phi_step_; this->cacheIsDirty = false; } /** Compute the normals * @param r * @return */ virtual void compute(const Mat& in, Mat& normals_out) const CV_OVERRIDE { const Mat_<T>& r_non_interp = in; // Interpolate the radial image to make derivatives meaningful Mat_<T> r; // higher quality remapping does not help here remap(r_non_interp, r, xy_, fxy_, INTER_LINEAR); // Compute the derivatives with respect to theta and phi // TODO add bilateral filtering (as done in kinfu) Mat_<T> r_theta, r_phi; sepFilter2D(r, r_theta, r.depth(), kx_dx_, ky_dx_); //current OpenCV version sometimes corrupts r matrix after second call of sepFilter2D //it depends on resolution, be careful sepFilter2D(r, r_phi, r.depth(), kx_dy_, ky_dy_); // Fill the result matrix Mat_<Vec4T> normals(this->rows, this->cols); const T* r_theta_ptr = r_theta[0], * r_theta_ptr_end = r_theta_ptr + this->rows * this->cols; const T* r_phi_ptr = r_phi[0]; const Mat33T* R = reinterpret_cast<const Mat33T*>(R_hat_[0]); const T* r_ptr = r[0]; Vec4T* normal = normals[0]; for (; r_theta_ptr != r_theta_ptr_end; ++r_theta_ptr, ++r_phi_ptr, ++R, ++r_ptr, ++normal) { if (cvIsNaN(*r_ptr)) { (*normal)[0] = *r_ptr; (*normal)[1] = *r_ptr; (*normal)[2] = *r_ptr; (*normal)[3] = 0; } else { T r_theta_over_r = (*r_theta_ptr) / (*r_ptr); T r_phi_over_r = (*r_phi_ptr) / (*r_ptr); // R(1,1) is 0 signNormal((*R)(0, 0) + (*R)(0, 1) * r_theta_over_r + (*R)(0, 2) * r_phi_over_r, (*R)(1, 0) + (*R)(1, 2) * r_phi_over_r, (*R)(2, 0) + (*R)(2, 1) * r_theta_over_r + (*R)(2, 2) * r_phi_over_r, *normal); } } remap(normals, normals_out, invxy_, invfxy_, INTER_LINEAR); normal = normals_out.ptr<Vec4T>(0); Vec4T* normal_end = normal + this->rows * this->cols; for (; normal != normal_end; ++normal) signNormal((*normal)[0], (*normal)[1], (*normal)[2], *normal); } virtual void assertOnBadArg(const Mat& points3d_ori) const CV_OVERRIDE { CV_Assert(((points3d_ori.channels() == 4) && (points3d_ori.depth() == CV_32F || points3d_ori.depth() == CV_64F))); } // Cached data /** Stores R */ mutable Mat_<Vec9T> R_hat_; mutable float phi_step_, theta_step_; /** Derivative kernels */ mutable Mat kx_dx_, ky_dx_, kx_dy_, ky_dy_; /** mapping function to get an SRI image */ mutable Mat_<Vec2f> map_; mutable Mat xy_, fxy_; mutable Mat_<Vec2f> euclideanMap_; mutable Mat invxy_, invfxy_; }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Ptr<RgbdNormals> RgbdNormals::create(int rows, int cols, int depth, InputArray K, int windowSize, RgbdNormalsMethod method) { CV_Assert(rows > 0 && cols > 0 && (depth == CV_32F || depth == CV_64F)); CV_Assert(windowSize == 1 || windowSize == 3 || windowSize == 5 || windowSize == 7); CV_Assert(K.cols() == 3 && K.rows() == 3 && (K.depth() == CV_32F || K.depth() == CV_64F)); Mat mK = K.getMat(); CV_Assert(method == RGBD_NORMALS_METHOD_FALS || method == RGBD_NORMALS_METHOD_LINEMOD || method == RGBD_NORMALS_METHOD_SRI); Ptr<RgbdNormals> ptr; switch (method) { case (RGBD_NORMALS_METHOD_FALS): { if (depth == CV_32F) ptr = makePtr<FALS<float> >(rows, cols, windowSize, mK); else ptr = makePtr<FALS<double>>(rows, cols, windowSize, mK); break; } case (RGBD_NORMALS_METHOD_LINEMOD): { if (depth == CV_32F) ptr = makePtr<LINEMOD<float> >(rows, cols, windowSize, mK); else ptr = makePtr<LINEMOD<double>>(rows, cols, windowSize, mK); break; } case RGBD_NORMALS_METHOD_SRI: { if (depth == CV_32F) ptr = makePtr<SRI<float> >(rows, cols, windowSize, mK); else ptr = makePtr<SRI<double>>(rows, cols, windowSize, mK); break; } } return ptr; } } // namespace cv
34.882424
156
0.539857
[ "vector", "3d" ]
886e1f9df2540e52fc54130cbbc14156e58c1dce
3,884
hpp
C++
dev/Basic/long/role/impl/RealEstateSellerRole.hpp
gusugusu1018/simmobility-prod
d30a5ba353673f8fd35f4868c26994a0206a40b6
[ "MIT" ]
50
2018-12-21T08:21:38.000Z
2022-01-24T09:47:59.000Z
dev/Basic/long/role/impl/RealEstateSellerRole.hpp
gusugusu1018/simmobility-prod
d30a5ba353673f8fd35f4868c26994a0206a40b6
[ "MIT" ]
2
2018-12-19T13:42:47.000Z
2019-05-13T04:11:45.000Z
dev/Basic/long/role/impl/RealEstateSellerRole.hpp
gusugusu1018/simmobility-prod
d30a5ba353673f8fd35f4868c26994a0206a40b6
[ "MIT" ]
27
2018-11-28T07:30:34.000Z
2022-02-05T02:22:26.000Z
//Copyright (c) 2013 Singapore-MIT Alliance for Research and Technology //Licensed under the terms of the MIT License, as described in the file: // license.txt (http://opensource.org/licenses/MIT) /* * File: RealEstateSellerRole.hpp * Author: Chetan Rogbeer <chetan.rogbeer@smart.mit.edu> * * Created on Jan 30, 2015, 5:13 PM */ #pragma once #include <boost/unordered_map.hpp> #include "database/entity/Bid.hpp" #include "database/entity/Household.hpp" #include "database/entity/Unit.hpp" namespace sim_mob { namespace long_term { class RealEstateAgent; class HM_Model; class HousingMarket; /** * RealEstate Seller role. * * Seller will receive N bids each day and it will choose * the maximum bid *of the time unit* (in this case is DAY) * that satisfies the seller's asking price. */ class RealEstateSellerRole { public: RealEstateSellerRole(RealEstateAgent* parent); virtual ~RealEstateSellerRole(); bool isActive() const; void setActive(bool active); /** * Method that will update the seller on each tick. * @param currTime */ virtual void update(timeslice currTime); RealEstateAgent* getParent(); /** * Inherited from LT_Role */ virtual void HandleMessage(messaging::Message::MessageType type, const messaging::Message& message); private: friend class RealEstateAgent; /** * Notify the bidders that have their bid were accepted. */ void notifyWinnerBidders(); /** * Adjust parameters of all units that were not sold. */ void adjustNotSoldUnits(); /** * Calculates the unit expectations to the maximum period of time * that the seller is expecting to be in the market. * @param unit to cal */ void calculateUnitExpectations(const Unit& unit); /** * Gets current expectation entry for given unit. * @param unitId to get the expectation. * @param outEntry (outParameter) to fill with the expectation. * If it not exists the values should be 0. * @return true if exists valid expectation, false otherwise. */ bool getCurrentExpectation(const BigSerial& unitId, ExpectationEntry& outEntry); public: typedef boost::unordered_map<BigSerial, unsigned int> CounterMap; public: typedef std::vector<ExpectationEntry> ExpectationList; struct SellingUnitInfo { SellingUnitInfo(); ExpectationList expectations; int startedDay; //day when the unit was added on market. int daysOnMarket; //number of days to stay on market. int interval; //interval to re-evaluate the expectation. int numExpectations; //ceil(daysOnMarket/interval) to re-evaluate the expectation. }; typedef boost::unordered_map<BigSerial, SellingUnitInfo> UnitsInfoMap; typedef boost::unordered_map<BigSerial, Bid> Bids; timeslice currentTime; volatile bool hasUnitsToSale; //Current max bid information. Bids maxBidsOfDay; UnitsInfoMap sellingUnitsMap; volatile bool selling; CounterMap dailyBids; int timeOnMarket; int timeOffMarket; int marketLifespan; RealEstateAgent *parent; bool active; }; } }
32.915254
112
0.57415
[ "vector" ]
88781db04c2a8f8b4e043b757c4dd0b441900400
794,413
cpp
C++
test/bidi_test_577.cpp
eightysquirrels/text
d935545648777786dc196a75346cde8906da846a
[ "BSL-1.0" ]
null
null
null
test/bidi_test_577.cpp
eightysquirrels/text
d935545648777786dc196a75346cde8906da846a
[ "BSL-1.0" ]
1
2021-03-05T12:56:59.000Z
2021-03-05T13:11:53.000Z
test/bidi_test_577.cpp
eightysquirrels/text
d935545648777786dc196a75346cde8906da846a
[ "BSL-1.0" ]
3
2019-10-30T18:38:15.000Z
2021-03-05T12:10:13.000Z
// Warning! This file is autogenerated. #include <boost/text/bidirectional.hpp> #include "bidi_tests.hpp" #include <gtest/gtest.h> #include <algorithm> std::vector<int> expected_levels; std::vector<int> expected_reordered_indices; TEST(bidi, bidi_577_000) { expected_levels = { 1, -1, 4, 4 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRO CS ON; 4 ('RTL') (line 288501) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x002C, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO NSM L; 4 ('RTL') (line 288502) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0300, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO NSM R; 4 ('RTL') (line 288503) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0300, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO NSM AL; 4 ('RTL') (line 288504) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0300, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO NSM EN; 4 ('RTL') (line 288505) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0300, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO NSM ES; 4 ('RTL') (line 288506) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0300, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO NSM ET; 4 ('RTL') (line 288507) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0300, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO NSM AN; 4 ('RTL') (line 288508) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0300, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO NSM CS; 4 ('RTL') (line 288509) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0300, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO NSM NSM; 4 ('RTL') (line 288510) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0300, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_001) { expected_levels = { 1, -1, 4, 4 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRO NSM ON; 4 ('RTL') (line 288511) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0300, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO WS L; 4 ('RTL') (line 288512) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0020, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO WS R; 4 ('RTL') (line 288513) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0020, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO WS AL; 4 ('RTL') (line 288514) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0020, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO WS EN; 4 ('RTL') (line 288515) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0020, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO WS ES; 4 ('RTL') (line 288516) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0020, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO WS ET; 4 ('RTL') (line 288517) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0020, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO WS AN; 4 ('RTL') (line 288518) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0020, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO WS CS; 4 ('RTL') (line 288519) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0020, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO WS NSM; 4 ('RTL') (line 288520) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0020, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_002) { expected_levels = { 1, -1, 4, 4 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRO WS ON; 4 ('RTL') (line 288521) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0020, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO ON L; 4 ('RTL') (line 288522) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0021, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO ON R; 4 ('RTL') (line 288523) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0021, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO ON AL; 4 ('RTL') (line 288524) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0021, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO ON EN; 4 ('RTL') (line 288525) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0021, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO ON ES; 4 ('RTL') (line 288526) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0021, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO ON ET; 4 ('RTL') (line 288527) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0021, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO ON AN; 4 ('RTL') (line 288528) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0021, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO ON CS; 4 ('RTL') (line 288529) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0021, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO ON NSM; 4 ('RTL') (line 288530) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0021, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_003) { expected_levels = { 1, -1, 4, 4 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRO ON ON; 4 ('RTL') (line 288531) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x0021, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE L L; 4 ('RTL') (line 288532) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0041, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE L EN; 4 ('RTL') (line 288533) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0041, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE L AN; 4 ('RTL') (line 288534) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0041, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE L NSM; 4 ('RTL') (line 288535) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0041, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE EN L; 4 ('RTL') (line 288536) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0030, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE EN EN; 4 ('RTL') (line 288537) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0030, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE EN ET; 4 ('RTL') (line 288538) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0030, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE EN AN; 4 ('RTL') (line 288539) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0030, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE EN NSM; 4 ('RTL') (line 288540) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0030, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_004) { expected_levels = { 1, -1, 4, 4 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI RLE ET EN; 4 ('RTL') (line 288541) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0023, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE AN L; 4 ('RTL') (line 288542) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0660, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE AN EN; 4 ('RTL') (line 288543) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0660, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE AN AN; 4 ('RTL') (line 288544) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0660, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI RLE AN NSM; 4 ('RTL') (line 288545) std::vector<uint32_t> const cps = { 0x2068, 0x202B, 0x0660, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI PDF AN AN; 4 ('RTL') (line 288546) std::vector<uint32_t> const cps = { 0x2068, 0x202C, 0x0660, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI PDF AN NSM; 4 ('RTL') (line 288547) std::vector<uint32_t> const cps = { 0x2068, 0x202C, 0x0660, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI BN AN AN; 4 ('RTL') (line 288548) std::vector<uint32_t> const cps = { 0x2068, 0x00AD, 0x0660, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI BN AN NSM; 4 ('RTL') (line 288549) std::vector<uint32_t> const cps = { 0x2068, 0x00AD, 0x0660, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI LRE AN AN; 4 ('RTL') (line 288550) std::vector<uint32_t> const cps = { 0x2069, 0x202A, 0x0660, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_005) { expected_levels = { 1, -1, 4, 4 }; expected_reordered_indices = { 2, 3, 0 }; { // PDI LRE AN NSM; 4 ('RTL') (line 288551) std::vector<uint32_t> const cps = { 0x2069, 0x202A, 0x0660, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE L L; 4 ('RTL') (line 288552) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0041, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE L EN; 4 ('RTL') (line 288553) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0041, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE L AN; 4 ('RTL') (line 288554) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0041, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE L NSM; 4 ('RTL') (line 288555) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0041, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE EN L; 4 ('RTL') (line 288556) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0030, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE EN EN; 4 ('RTL') (line 288557) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0030, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE EN ET; 4 ('RTL') (line 288558) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0030, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE EN AN; 4 ('RTL') (line 288559) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0030, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE EN NSM; 4 ('RTL') (line 288560) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0030, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_006) { expected_levels = { 1, -1, 4, 4 }; expected_reordered_indices = { 2, 3, 0 }; { // PDI RLE ET EN; 4 ('RTL') (line 288561) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0023, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE AN L; 4 ('RTL') (line 288562) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0660, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE AN EN; 4 ('RTL') (line 288563) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0660, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE AN AN; 4 ('RTL') (line 288564) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0660, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // PDI RLE AN NSM; 4 ('RTL') (line 288565) std::vector<uint32_t> const cps = { 0x2069, 0x202B, 0x0660, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRE L R; 4 ('RTL') (line 288571) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0041, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE L AL; 4 ('RTL') (line 288572) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0041, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE EN R; 4 ('RTL') (line 288573) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0030, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE EN AL; 4 ('RTL') (line 288574) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0030, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE ES R; 4 ('RTL') (line 288575) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x002B, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_007) { expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRE ES AL; 4 ('RTL') (line 288576) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x002B, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE ET R; 4 ('RTL') (line 288577) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0023, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE ET AL; 4 ('RTL') (line 288578) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0023, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE CS R; 4 ('RTL') (line 288579) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x002C, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE CS AL; 4 ('RTL') (line 288580) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x002C, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE NSM R; 4 ('RTL') (line 288581) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0300, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE NSM AL; 4 ('RTL') (line 288582) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0300, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE WS R; 4 ('RTL') (line 288583) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0020, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE WS AL; 4 ('RTL') (line 288584) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0020, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE ON R; 4 ('RTL') (line 288585) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0021, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_008) { expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRE ON AL; 4 ('RTL') (line 288586) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0021, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE RLI R; 4 ('RTL') (line 288587) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2067, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE RLI AL; 4 ('RTL') (line 288588) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2067, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE RLI ES; 4 ('RTL') (line 288589) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2067, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE RLI ET; 4 ('RTL') (line 288590) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2067, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE RLI CS; 4 ('RTL') (line 288591) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2067, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE RLI NSM; 4 ('RTL') (line 288592) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2067, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE RLI ON; 4 ('RTL') (line 288593) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2067, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE FSI R; 4 ('RTL') (line 288594) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2068, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE FSI AL; 4 ('RTL') (line 288595) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2068, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_009) { expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRO RLI R; 4 ('RTL') (line 288596) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2067, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO RLI AL; 4 ('RTL') (line 288597) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2067, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO RLI ES; 4 ('RTL') (line 288598) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2067, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO RLI ET; 4 ('RTL') (line 288599) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2067, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO RLI CS; 4 ('RTL') (line 288600) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2067, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO RLI NSM; 4 ('RTL') (line 288601) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2067, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO RLI ON; 4 ('RTL') (line 288602) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2067, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO FSI R; 4 ('RTL') (line 288603) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2068, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO FSI AL; 4 ('RTL') (line 288604) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2068, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE L R; 4 ('RTL') (line 288605) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0041, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_010) { expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRE L AL; 4 ('RTL') (line 288606) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0041, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE EN R; 4 ('RTL') (line 288607) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0030, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE EN AL; 4 ('RTL') (line 288608) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0030, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE ES R; 4 ('RTL') (line 288609) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x002B, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE ES AL; 4 ('RTL') (line 288610) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x002B, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE ET R; 4 ('RTL') (line 288611) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0023, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE ET AL; 4 ('RTL') (line 288612) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0023, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE CS R; 4 ('RTL') (line 288613) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x002C, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE CS AL; 4 ('RTL') (line 288614) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x002C, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE NSM R; 4 ('RTL') (line 288615) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0300, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_011) { expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRE NSM AL; 4 ('RTL') (line 288616) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0300, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE WS R; 4 ('RTL') (line 288617) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0020, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE WS AL; 4 ('RTL') (line 288618) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0020, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE ON R; 4 ('RTL') (line 288619) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0021, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE ON AL; 4 ('RTL') (line 288620) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0021, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE RLI R; 4 ('RTL') (line 288621) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2067, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE RLI AL; 4 ('RTL') (line 288622) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2067, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE RLI ES; 4 ('RTL') (line 288623) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2067, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE RLI ET; 4 ('RTL') (line 288624) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2067, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE RLI CS; 4 ('RTL') (line 288625) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2067, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_012) { expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRE RLI NSM; 4 ('RTL') (line 288626) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2067, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE RLI ON; 4 ('RTL') (line 288627) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2067, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE FSI R; 4 ('RTL') (line 288628) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2068, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE FSI AL; 4 ('RTL') (line 288629) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2068, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO RLI R; 4 ('RTL') (line 288630) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2067, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO RLI AL; 4 ('RTL') (line 288631) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2067, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO RLI ES; 4 ('RTL') (line 288632) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2067, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO RLI ET; 4 ('RTL') (line 288633) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2067, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO RLI CS; 4 ('RTL') (line 288634) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2067, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO RLI NSM; 4 ('RTL') (line 288635) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2067, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_013) { expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRO RLI ON; 4 ('RTL') (line 288636) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2067, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO FSI R; 4 ('RTL') (line 288637) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2068, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO FSI AL; 4 ('RTL') (line 288638) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2068, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE L R; 4 ('RTL') (line 288639) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0041, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE L AL; 4 ('RTL') (line 288640) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0041, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE EN R; 4 ('RTL') (line 288641) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0030, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE EN AL; 4 ('RTL') (line 288642) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0030, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE ES R; 4 ('RTL') (line 288643) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x002B, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE ES AL; 4 ('RTL') (line 288644) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x002B, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE ET R; 4 ('RTL') (line 288645) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0023, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_014) { expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRE ET AL; 4 ('RTL') (line 288646) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0023, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE CS R; 4 ('RTL') (line 288647) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x002C, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE CS AL; 4 ('RTL') (line 288648) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x002C, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE NSM R; 4 ('RTL') (line 288649) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0300, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE NSM AL; 4 ('RTL') (line 288650) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0300, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE WS R; 4 ('RTL') (line 288651) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0020, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE WS AL; 4 ('RTL') (line 288652) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0020, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE ON R; 4 ('RTL') (line 288653) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0021, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE ON AL; 4 ('RTL') (line 288654) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0021, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE RLI R; 4 ('RTL') (line 288655) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2067, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_015) { expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRE RLI AL; 4 ('RTL') (line 288656) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2067, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE RLI ES; 4 ('RTL') (line 288657) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2067, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE RLI ET; 4 ('RTL') (line 288658) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2067, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE RLI CS; 4 ('RTL') (line 288659) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2067, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE RLI NSM; 4 ('RTL') (line 288660) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2067, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE RLI ON; 4 ('RTL') (line 288661) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2067, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE FSI R; 4 ('RTL') (line 288662) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2068, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE FSI AL; 4 ('RTL') (line 288663) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2068, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO RLI R; 4 ('RTL') (line 288664) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2067, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO RLI AL; 4 ('RTL') (line 288665) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2067, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_016) { expected_levels = { 1, -1, 4, 5 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRO RLI ES; 4 ('RTL') (line 288666) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2067, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO RLI ET; 4 ('RTL') (line 288667) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2067, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO RLI CS; 4 ('RTL') (line 288668) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2067, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO RLI NSM; 4 ('RTL') (line 288669) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2067, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO RLI ON; 4 ('RTL') (line 288670) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2067, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO FSI R; 4 ('RTL') (line 288671) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2068, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO FSI AL; 4 ('RTL') (line 288672) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2068, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRE L AN; 4 ('RTL') (line 288678) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0041, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE EN AN; 4 ('RTL') (line 288679) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0030, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE ES AN; 4 ('RTL') (line 288680) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x002B, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_017) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRE ET AN; 4 ('RTL') (line 288681) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0023, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE CS AN; 4 ('RTL') (line 288682) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x002C, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE NSM AN; 4 ('RTL') (line 288683) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0300, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE WS AN; 4 ('RTL') (line 288684) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0020, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE ON AN; 4 ('RTL') (line 288685) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0021, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE LRI L; 4 ('RTL') (line 288686) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2066, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE LRI EN; 4 ('RTL') (line 288687) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2066, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE LRI ES; 4 ('RTL') (line 288688) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2066, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE LRI ET; 4 ('RTL') (line 288689) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2066, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE LRI CS; 4 ('RTL') (line 288690) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2066, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_018) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRE LRI NSM; 4 ('RTL') (line 288691) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2066, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE LRI ON; 4 ('RTL') (line 288692) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2066, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE RLI L; 4 ('RTL') (line 288693) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2067, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE RLI EN; 4 ('RTL') (line 288694) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2067, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE RLI AN; 4 ('RTL') (line 288695) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2067, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE FSI L; 4 ('RTL') (line 288696) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2068, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE FSI EN; 4 ('RTL') (line 288697) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2068, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE FSI ES; 4 ('RTL') (line 288698) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2068, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE FSI ET; 4 ('RTL') (line 288699) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2068, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE FSI CS; 4 ('RTL') (line 288700) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2068, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_019) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRE FSI NSM; 4 ('RTL') (line 288701) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2068, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE FSI ON; 4 ('RTL') (line 288702) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2068, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO LRI L; 4 ('RTL') (line 288703) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2066, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO LRI EN; 4 ('RTL') (line 288704) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2066, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO LRI ES; 4 ('RTL') (line 288705) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2066, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO LRI ET; 4 ('RTL') (line 288706) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2066, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO LRI CS; 4 ('RTL') (line 288707) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2066, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO LRI NSM; 4 ('RTL') (line 288708) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2066, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO LRI ON; 4 ('RTL') (line 288709) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2066, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO RLI L; 4 ('RTL') (line 288710) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2067, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_020) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRO RLI EN; 4 ('RTL') (line 288711) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2067, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO RLI AN; 4 ('RTL') (line 288712) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2067, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO FSI L; 4 ('RTL') (line 288713) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2068, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO FSI EN; 4 ('RTL') (line 288714) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2068, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO FSI ES; 4 ('RTL') (line 288715) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2068, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO FSI ET; 4 ('RTL') (line 288716) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2068, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO FSI CS; 4 ('RTL') (line 288717) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2068, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO FSI NSM; 4 ('RTL') (line 288718) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2068, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO FSI ON; 4 ('RTL') (line 288719) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2068, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE L AN; 4 ('RTL') (line 288720) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0041, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_021) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRE EN AN; 4 ('RTL') (line 288721) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0030, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE ES AN; 4 ('RTL') (line 288722) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x002B, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE ET AN; 4 ('RTL') (line 288723) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0023, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE CS AN; 4 ('RTL') (line 288724) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x002C, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE NSM AN; 4 ('RTL') (line 288725) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0300, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE WS AN; 4 ('RTL') (line 288726) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0020, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE ON AN; 4 ('RTL') (line 288727) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0021, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE LRI L; 4 ('RTL') (line 288728) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2066, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE LRI EN; 4 ('RTL') (line 288729) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2066, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE LRI ES; 4 ('RTL') (line 288730) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2066, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_022) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRE LRI ET; 4 ('RTL') (line 288731) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2066, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE LRI CS; 4 ('RTL') (line 288732) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2066, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE LRI NSM; 4 ('RTL') (line 288733) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2066, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE LRI ON; 4 ('RTL') (line 288734) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2066, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE RLI L; 4 ('RTL') (line 288735) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2067, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE RLI EN; 4 ('RTL') (line 288736) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2067, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE RLI AN; 4 ('RTL') (line 288737) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2067, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE FSI L; 4 ('RTL') (line 288738) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2068, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE FSI EN; 4 ('RTL') (line 288739) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2068, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE FSI ES; 4 ('RTL') (line 288740) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2068, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_023) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRE FSI ET; 4 ('RTL') (line 288741) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2068, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE FSI CS; 4 ('RTL') (line 288742) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2068, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE FSI NSM; 4 ('RTL') (line 288743) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2068, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE FSI ON; 4 ('RTL') (line 288744) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2068, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO LRI L; 4 ('RTL') (line 288745) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2066, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO LRI EN; 4 ('RTL') (line 288746) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2066, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO LRI ES; 4 ('RTL') (line 288747) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2066, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO LRI ET; 4 ('RTL') (line 288748) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2066, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO LRI CS; 4 ('RTL') (line 288749) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2066, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO LRI NSM; 4 ('RTL') (line 288750) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2066, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_024) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRO LRI ON; 4 ('RTL') (line 288751) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2066, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO RLI L; 4 ('RTL') (line 288752) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2067, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO RLI EN; 4 ('RTL') (line 288753) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2067, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO RLI AN; 4 ('RTL') (line 288754) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2067, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO FSI L; 4 ('RTL') (line 288755) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2068, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO FSI EN; 4 ('RTL') (line 288756) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2068, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO FSI ES; 4 ('RTL') (line 288757) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2068, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO FSI ET; 4 ('RTL') (line 288758) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2068, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO FSI CS; 4 ('RTL') (line 288759) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2068, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO FSI NSM; 4 ('RTL') (line 288760) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2068, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_025) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRO FSI ON; 4 ('RTL') (line 288761) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2068, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE L AN; 4 ('RTL') (line 288762) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0041, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE EN AN; 4 ('RTL') (line 288763) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0030, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE ES AN; 4 ('RTL') (line 288764) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x002B, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE ET AN; 4 ('RTL') (line 288765) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0023, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE CS AN; 4 ('RTL') (line 288766) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x002C, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE NSM AN; 4 ('RTL') (line 288767) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0300, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE WS AN; 4 ('RTL') (line 288768) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0020, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE ON AN; 4 ('RTL') (line 288769) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0021, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE LRI L; 4 ('RTL') (line 288770) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2066, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_026) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRE LRI EN; 4 ('RTL') (line 288771) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2066, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE LRI ES; 4 ('RTL') (line 288772) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2066, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE LRI ET; 4 ('RTL') (line 288773) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2066, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE LRI CS; 4 ('RTL') (line 288774) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2066, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE LRI NSM; 4 ('RTL') (line 288775) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2066, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE LRI ON; 4 ('RTL') (line 288776) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2066, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE RLI L; 4 ('RTL') (line 288777) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2067, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE RLI EN; 4 ('RTL') (line 288778) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2067, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE RLI AN; 4 ('RTL') (line 288779) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2067, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE FSI L; 4 ('RTL') (line 288780) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2068, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_027) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRE FSI EN; 4 ('RTL') (line 288781) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2068, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE FSI ES; 4 ('RTL') (line 288782) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2068, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE FSI ET; 4 ('RTL') (line 288783) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2068, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE FSI CS; 4 ('RTL') (line 288784) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2068, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE FSI NSM; 4 ('RTL') (line 288785) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2068, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE FSI ON; 4 ('RTL') (line 288786) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2068, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO LRI L; 4 ('RTL') (line 288787) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2066, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO LRI EN; 4 ('RTL') (line 288788) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2066, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO LRI ES; 4 ('RTL') (line 288789) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2066, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO LRI ET; 4 ('RTL') (line 288790) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2066, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_028) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRO LRI CS; 4 ('RTL') (line 288791) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2066, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO LRI NSM; 4 ('RTL') (line 288792) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2066, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO LRI ON; 4 ('RTL') (line 288793) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2066, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO RLI L; 4 ('RTL') (line 288794) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2067, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO RLI EN; 4 ('RTL') (line 288795) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2067, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO RLI AN; 4 ('RTL') (line 288796) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2067, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO FSI L; 4 ('RTL') (line 288797) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2068, 0x0041 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO FSI EN; 4 ('RTL') (line 288798) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2068, 0x0030 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO FSI ES; 4 ('RTL') (line 288799) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2068, 0x002B }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO FSI ET; 4 ('RTL') (line 288800) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2068, 0x0023 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_029) { expected_levels = { 1, -1, 4, 6 }; expected_reordered_indices = { 2, 3, 0 }; { // FSI LRO FSI CS; 4 ('RTL') (line 288801) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2068, 0x002C }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO FSI NSM; 4 ('RTL') (line 288802) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2068, 0x0300 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO FSI ON; 4 ('RTL') (line 288803) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2068, 0x0021 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } expected_levels = { 1, -1, 4, 7 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRE LRI R; 4 ('RTL') (line 288809) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2066, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE LRI AL; 4 ('RTL') (line 288810) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2066, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO LRI R; 4 ('RTL') (line 288811) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2066, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO LRI AL; 4 ('RTL') (line 288812) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2066, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE LRI R; 4 ('RTL') (line 288813) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2066, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE LRI AL; 4 ('RTL') (line 288814) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2066, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO LRI R; 4 ('RTL') (line 288815) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2066, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_030) { expected_levels = { 1, -1, 4, 7 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRO LRI AL; 4 ('RTL') (line 288816) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2066, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE LRI R; 4 ('RTL') (line 288817) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2066, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE LRI AL; 4 ('RTL') (line 288818) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2066, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO LRI R; 4 ('RTL') (line 288819) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2066, 0x05BE }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO LRI AL; 4 ('RTL') (line 288820) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2066, 0x0608 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } expected_levels = { 1, -1, 4, 8 }; expected_reordered_indices = { 2, 3, 0 }; { // LRI LRE LRI AN; 4 ('RTL') (line 288826) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2066, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE FSI AN; 4 ('RTL') (line 288827) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x2068, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO LRI AN; 4 ('RTL') (line 288828) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2066, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRO FSI AN; 4 ('RTL') (line 288829) std::vector<uint32_t> const cps = { 0x2066, 0x202D, 0x2068, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE LRI AN; 4 ('RTL') (line 288830) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2066, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_031) { expected_levels = { 1, -1, 4, 8 }; expected_reordered_indices = { 2, 3, 0 }; { // RLI LRE FSI AN; 4 ('RTL') (line 288831) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x2068, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO LRI AN; 4 ('RTL') (line 288832) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2066, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRO FSI AN; 4 ('RTL') (line 288833) std::vector<uint32_t> const cps = { 0x2067, 0x202D, 0x2068, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE LRI AN; 4 ('RTL') (line 288834) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2066, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE FSI AN; 4 ('RTL') (line 288835) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x2068, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO LRI AN; 4 ('RTL') (line 288836) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2066, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRO FSI AN; 4 ('RTL') (line 288837) std::vector<uint32_t> const cps = { 0x2068, 0x202D, 0x2068, 0x0660 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // LRI LRE R B; 4 ('RTL') (line 288843) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x05BE, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE R S; 4 ('RTL') (line 288844) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x05BE, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE R WS; 4 ('RTL') (line 288845) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x05BE, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_032) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // LRI LRE R LRI; 4 ('RTL') (line 288846) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x05BE, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE R RLI; 4 ('RTL') (line 288847) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x05BE, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE R FSI; 4 ('RTL') (line 288848) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x05BE, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE R PDI; 4 ('RTL') (line 288849) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x05BE, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE AL B; 4 ('RTL') (line 288850) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0608, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE AL S; 4 ('RTL') (line 288851) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0608, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE AL WS; 4 ('RTL') (line 288852) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0608, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE AL LRI; 4 ('RTL') (line 288853) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0608, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE AL RLI; 4 ('RTL') (line 288854) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0608, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // LRI LRE AL FSI; 4 ('RTL') (line 288855) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0608, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_033) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // LRI LRE AL PDI; 4 ('RTL') (line 288856) std::vector<uint32_t> const cps = { 0x2066, 0x202A, 0x0608, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE R B; 4 ('RTL') (line 288857) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x05BE, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE R S; 4 ('RTL') (line 288858) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x05BE, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE R WS; 4 ('RTL') (line 288859) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x05BE, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE R LRI; 4 ('RTL') (line 288860) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x05BE, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE R RLI; 4 ('RTL') (line 288861) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x05BE, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE R FSI; 4 ('RTL') (line 288862) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x05BE, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE R PDI; 4 ('RTL') (line 288863) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x05BE, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE AL B; 4 ('RTL') (line 288864) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0608, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE AL S; 4 ('RTL') (line 288865) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0608, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_034) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI LRE AL WS; 4 ('RTL') (line 288866) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0608, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE AL LRI; 4 ('RTL') (line 288867) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0608, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE AL RLI; 4 ('RTL') (line 288868) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0608, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE AL FSI; 4 ('RTL') (line 288869) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0608, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI LRE AL PDI; 4 ('RTL') (line 288870) std::vector<uint32_t> const cps = { 0x2067, 0x202A, 0x0608, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE R B; 4 ('RTL') (line 288871) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x05BE, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE R S; 4 ('RTL') (line 288872) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x05BE, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE R WS; 4 ('RTL') (line 288873) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x05BE, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE R LRI; 4 ('RTL') (line 288874) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x05BE, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE R RLI; 4 ('RTL') (line 288875) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x05BE, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_035) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLE R FSI; 4 ('RTL') (line 288876) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x05BE, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE R PDI; 4 ('RTL') (line 288877) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x05BE, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE AL B; 4 ('RTL') (line 288878) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0608, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE AL S; 4 ('RTL') (line 288879) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0608, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE AL WS; 4 ('RTL') (line 288880) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0608, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE AL LRI; 4 ('RTL') (line 288881) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0608, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE AL RLI; 4 ('RTL') (line 288882) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0608, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE AL FSI; 4 ('RTL') (line 288883) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0608, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE AL PDI; 4 ('RTL') (line 288884) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0608, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ES B; 4 ('RTL') (line 288885) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002B, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_036) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLE ES S; 4 ('RTL') (line 288886) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002B, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ES WS; 4 ('RTL') (line 288887) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002B, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ES LRI; 4 ('RTL') (line 288888) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002B, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ES RLI; 4 ('RTL') (line 288889) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002B, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ES FSI; 4 ('RTL') (line 288890) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002B, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ES PDI; 4 ('RTL') (line 288891) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002B, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ET B; 4 ('RTL') (line 288892) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0023, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ET S; 4 ('RTL') (line 288893) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0023, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ET WS; 4 ('RTL') (line 288894) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0023, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ET LRI; 4 ('RTL') (line 288895) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0023, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_037) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLE ET RLI; 4 ('RTL') (line 288896) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0023, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ET FSI; 4 ('RTL') (line 288897) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0023, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ET PDI; 4 ('RTL') (line 288898) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0023, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE CS B; 4 ('RTL') (line 288899) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002C, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE CS S; 4 ('RTL') (line 288900) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002C, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE CS WS; 4 ('RTL') (line 288901) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002C, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE CS LRI; 4 ('RTL') (line 288902) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002C, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE CS RLI; 4 ('RTL') (line 288903) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002C, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE CS FSI; 4 ('RTL') (line 288904) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002C, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE CS PDI; 4 ('RTL') (line 288905) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x002C, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_038) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLE NSM B; 4 ('RTL') (line 288906) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0300, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE NSM S; 4 ('RTL') (line 288907) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0300, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE NSM WS; 4 ('RTL') (line 288908) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0300, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE NSM LRI; 4 ('RTL') (line 288909) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0300, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE NSM RLI; 4 ('RTL') (line 288910) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0300, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE NSM FSI; 4 ('RTL') (line 288911) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0300, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE NSM PDI; 4 ('RTL') (line 288912) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0300, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ON B; 4 ('RTL') (line 288913) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0021, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ON S; 4 ('RTL') (line 288914) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0021, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ON WS; 4 ('RTL') (line 288915) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0021, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_039) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLE ON LRI; 4 ('RTL') (line 288916) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0021, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ON RLI; 4 ('RTL') (line 288917) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0021, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ON FSI; 4 ('RTL') (line 288918) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0021, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLE ON PDI; 4 ('RTL') (line 288919) std::vector<uint32_t> const cps = { 0x2067, 0x202B, 0x0021, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO L B; 4 ('RTL') (line 288920) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0041, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO L S; 4 ('RTL') (line 288921) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0041, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO L WS; 4 ('RTL') (line 288922) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0041, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO L LRI; 4 ('RTL') (line 288923) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0041, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO L RLI; 4 ('RTL') (line 288924) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0041, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO L FSI; 4 ('RTL') (line 288925) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0041, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_040) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLO L PDI; 4 ('RTL') (line 288926) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0041, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO R B; 4 ('RTL') (line 288927) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x05BE, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO R S; 4 ('RTL') (line 288928) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x05BE, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO R WS; 4 ('RTL') (line 288929) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x05BE, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO R LRI; 4 ('RTL') (line 288930) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x05BE, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO R RLI; 4 ('RTL') (line 288931) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x05BE, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO R FSI; 4 ('RTL') (line 288932) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x05BE, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO R PDI; 4 ('RTL') (line 288933) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x05BE, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AL B; 4 ('RTL') (line 288934) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0608, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AL S; 4 ('RTL') (line 288935) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0608, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_041) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLO AL WS; 4 ('RTL') (line 288936) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0608, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AL LRI; 4 ('RTL') (line 288937) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0608, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AL RLI; 4 ('RTL') (line 288938) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0608, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AL FSI; 4 ('RTL') (line 288939) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0608, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AL PDI; 4 ('RTL') (line 288940) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0608, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO EN B; 4 ('RTL') (line 288941) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0030, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO EN S; 4 ('RTL') (line 288942) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0030, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO EN WS; 4 ('RTL') (line 288943) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0030, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO EN LRI; 4 ('RTL') (line 288944) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0030, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO EN RLI; 4 ('RTL') (line 288945) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0030, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_042) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLO EN FSI; 4 ('RTL') (line 288946) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0030, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO EN PDI; 4 ('RTL') (line 288947) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0030, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ES B; 4 ('RTL') (line 288948) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002B, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ES S; 4 ('RTL') (line 288949) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002B, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ES WS; 4 ('RTL') (line 288950) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002B, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ES LRI; 4 ('RTL') (line 288951) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002B, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ES RLI; 4 ('RTL') (line 288952) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002B, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ES FSI; 4 ('RTL') (line 288953) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002B, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ES PDI; 4 ('RTL') (line 288954) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002B, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ET B; 4 ('RTL') (line 288955) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0023, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_043) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLO ET S; 4 ('RTL') (line 288956) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0023, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ET WS; 4 ('RTL') (line 288957) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0023, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ET LRI; 4 ('RTL') (line 288958) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0023, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ET RLI; 4 ('RTL') (line 288959) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0023, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ET FSI; 4 ('RTL') (line 288960) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0023, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ET PDI; 4 ('RTL') (line 288961) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0023, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AN B; 4 ('RTL') (line 288962) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0660, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AN S; 4 ('RTL') (line 288963) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0660, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AN WS; 4 ('RTL') (line 288964) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0660, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AN LRI; 4 ('RTL') (line 288965) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0660, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_044) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLO AN RLI; 4 ('RTL') (line 288966) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0660, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AN FSI; 4 ('RTL') (line 288967) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0660, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO AN PDI; 4 ('RTL') (line 288968) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0660, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO CS B; 4 ('RTL') (line 288969) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002C, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO CS S; 4 ('RTL') (line 288970) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002C, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO CS WS; 4 ('RTL') (line 288971) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002C, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO CS LRI; 4 ('RTL') (line 288972) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002C, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO CS RLI; 4 ('RTL') (line 288973) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002C, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO CS FSI; 4 ('RTL') (line 288974) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002C, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO CS PDI; 4 ('RTL') (line 288975) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x002C, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_045) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLO NSM B; 4 ('RTL') (line 288976) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0300, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO NSM S; 4 ('RTL') (line 288977) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0300, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO NSM WS; 4 ('RTL') (line 288978) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0300, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO NSM LRI; 4 ('RTL') (line 288979) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0300, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO NSM RLI; 4 ('RTL') (line 288980) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0300, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO NSM FSI; 4 ('RTL') (line 288981) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0300, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO NSM PDI; 4 ('RTL') (line 288982) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0300, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ON B; 4 ('RTL') (line 288983) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0021, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ON S; 4 ('RTL') (line 288984) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0021, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ON WS; 4 ('RTL') (line 288985) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0021, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_046) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // RLI RLO ON LRI; 4 ('RTL') (line 288986) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0021, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ON RLI; 4 ('RTL') (line 288987) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0021, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ON FSI; 4 ('RTL') (line 288988) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0021, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // RLI RLO ON PDI; 4 ('RTL') (line 288989) std::vector<uint32_t> const cps = { 0x2067, 0x202E, 0x0021, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE R B; 4 ('RTL') (line 288990) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x05BE, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE R S; 4 ('RTL') (line 288991) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x05BE, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE R WS; 4 ('RTL') (line 288992) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x05BE, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE R LRI; 4 ('RTL') (line 288993) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x05BE, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE R RLI; 4 ('RTL') (line 288994) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x05BE, 0x2067 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE R FSI; 4 ('RTL') (line 288995) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x05BE, 0x2068 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } } TEST(bidi, bidi_577_047) { expected_levels = { 1, -1, 5, 1 }; expected_reordered_indices = { 3, 2, 0 }; { // FSI LRE R PDI; 4 ('RTL') (line 288996) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x05BE, 0x2069 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE AL B; 4 ('RTL') (line 288997) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0608, 0x2029 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE AL S; 4 ('RTL') (line 288998) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0608, 0x0009 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE AL WS; 4 ('RTL') (line 288999) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0608, 0x0020 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } { // FSI LRE AL LRI; 4 ('RTL') (line 289000) std::vector<uint32_t> const cps = { 0x2068, 0x202A, 0x0608, 0x2066 }; std::vector<int> const levels = bidi_levels(cps.begin(), cps.end(), 1); int i = 0; for (int l : expected_levels) { if (0 <= l) { EXPECT_EQ(levels[i], l) << "i=" << i; ++i; } } EXPECT_EQ((int)levels.size(), i); std::vector<int> const reordered = bidi_reordered_indices(cps.begin(), cps.end(), 1); i = 0; for (int idx : expected_reordered_indices) { // Skip FSI, LRI, RLI, and PDI. if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered[i], cps[idx]) << std::hex << " 0x" << reordered[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } std::vector<int> reordered_2; for (auto subrange : boost::text::bidirectional_subranges(cps, 1)) { for (auto cp : subrange) { reordered_2.push_back(cp); } } i = 0; for (int idx : expected_reordered_indices) { if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) { EXPECT_EQ(reordered_2[i], cps[idx]) << std::hex << " 0x" << reordered_2[i] << " 0x" << cps[idx] << std::dec << " i=" << i; } ++i; } EXPECT_EQ(i, (int)reordered_2.size()); } }
32.942691
77
0.404844
[ "vector" ]
887ba3ed1f8290e413639dcf119cf2e3777b3361
4,380
hpp
C++
R5/R5Prm/R5PrmComponentImpl.hpp
genemerewether/fprime
fcdd071b5ddffe54ade098ca5d451903daba9eed
[ "Apache-2.0" ]
5
2019-10-22T03:41:02.000Z
2022-01-16T12:48:31.000Z
R5/R5Prm/R5PrmComponentImpl.hpp
genemerewether/fprime
fcdd071b5ddffe54ade098ca5d451903daba9eed
[ "Apache-2.0" ]
27
2019-02-07T17:58:58.000Z
2019-08-13T00:46:24.000Z
R5/R5Prm/R5PrmComponentImpl.hpp
genemerewether/fprime
fcdd071b5ddffe54ade098ca5d451903daba9eed
[ "Apache-2.0" ]
3
2019-01-01T18:44:37.000Z
2019-08-01T01:19:39.000Z
// ====================================================================== // \title R5PrmImpl.hpp // \author tcanham // \brief hpp file for R5Prm component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. Any commercial use must be negotiated with the Office // of Technology Transfer at the California Institute of Technology. // // This software may be subject to U.S. export control laws and // regulations. By accepting this document, the user agrees to comply // with all U.S. export laws and regulations. User has the // responsibility to obtain export licenses, or other export authority // as may be required before exporting such information to foreign // countries or providing access to foreign persons. // ====================================================================== #ifndef R5Prm_HPP #define R5Prm_HPP #include "R5/R5Prm/R5PrmComponentAc.hpp" #include <Fw/Types/Serializable.hpp> #include <R5/Ports/PrmEntry.hpp> #include <R5/R5Prm/R5PrmComponentImplCfg.hpp> #define SECTOR_SIZE 4096 #define PARAMETER_SECTOR 1 #define BACKUP_SECTOR 2 #define UPPER_BANK_PTR ((uint8_t*)0xF0200000) #define BYTES_PER_WRITE 8 // TODO: Find a good value for this #define LOOP_MAX_IDX 1000000 // Bitfields to determine if a parameter's value is valid #define BITFIELD_PARAMETER(X) ((R5::MAX_R5_PARAMS * (4 * 3)) + (X)) // CRC32 of all parameters #define CRC_PARAMETER 4092 #define NUM_CRC32_CALCS 128 namespace R5 { class R5PrmComponentImpl : public R5PrmComponentBase { public: // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Construct object R5Prm //! R5PrmComponentImpl( #if FW_OBJECT_NAMES == 1 const char *const compName /*!< The component name*/ #else void #endif ); //! Initialize object R5Prm //! void init( const NATIVE_INT_TYPE instance = 0 /*!< The instance number*/ ); //! load from flash void load(void); //! Destroy object R5Prm //! ~R5PrmComponentImpl(void); // Set the parameter array to 0. Currently used during testing void clear_parameter_memory(void); PRIVATE: // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- //! Handler implementation for set //! void set_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ R5::PrmEntry &prm, bool &valid ); //! Handler implementation for get //! void get_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ R5::PrmEntry &prm, bool &valid ); //! Handler implementation for write //! void write_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ bool force ); //! Handler implementation for check //! void check_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ PrmWriteStatus &stat ); //! Check if a parameter id has a value bool have_parameter(uint32_t param_id); typedef enum { CS_INIT, CS_CALC_CRC, CS_INIT_FLASH, CS_PRIMARY_ENABLE, CS_PRIMARY_ENABLE_WAIT, CS_PRIMARY_ERASE, CS_PRIMARY_ERASE_WAIT, CS_PRIMARY_WRITE, CS_PRIMARY_WRITE_WAIT, CS_BACKUP_ENABLE, CS_BACKUP_ENABLE_WAIT, CS_BACKUP_ERASE, CS_BACKUP_ERASE_WAIT, CS_BACKUP_WRITE, CS_BACKUP_WRITE_WAIT, CS_DONE } CommitState; uint8_t m_parameters[SECTOR_SIZE]; uint32_t m_writesLeft; uint8_t* m_writeAddress; uint8_t* m_paramAddress; uint32_t m_crc32; uint32_t m_crc_calcs_left; PrmWriteStatus m_prmStatus; CommitState m_commitState; Fw::ExternalSerializeBuffer m_extParamBuffer; }; } // end namespace R5 #endif
26.707317
79
0.58516
[ "object" ]
8881ad5466613ddce66baac8b14726fb3b885e05
4,210
cpp
C++
unit/testing-utils/require_goto_statements.cpp
chrisr-diffblue/cbmc
854b26fec145ebb345cf45c9512201143c823cd1
[ "BSD-4-Clause" ]
null
null
null
unit/testing-utils/require_goto_statements.cpp
chrisr-diffblue/cbmc
854b26fec145ebb345cf45c9512201143c823cd1
[ "BSD-4-Clause" ]
2
2018-06-18T10:34:36.000Z
2018-07-03T15:43:57.000Z
unit/testing-utils/require_goto_statements.cpp
jeannielynnmoulton/cbmc
1d4af6d88ec960677170049a8a89a9166b952996
[ "BSD-4-Clause" ]
null
null
null
/*******************************************************************\ Module: Unit test utilities Author: DiffBlue Limited. All rights reserved. \*******************************************************************/ #include "require_goto_statements.h" #include "catch.hpp" #include <algorithm> #include <util/expr_iterator.h> /// Expand value of a function to include all child codets /// \param function_value: The value of the function (e.g. got by looking up /// the function in the symbol table and getting the value) /// \return: All ID_code statements in the tree rooted at \p function_value std::vector<codet> require_goto_statements::get_all_statements(const exprt &function_value) { std::vector<codet> statements; for(auto sub_expression_it = function_value.depth_begin(); sub_expression_it != function_value.depth_end(); ++sub_expression_it) { if(sub_expression_it->id() == ID_code) { statements.push_back(to_code(*sub_expression_it)); } } return statements; } /// Find assignment statements of the form \p structure_name.\component_name = /// \param statements: The statements to look through /// \param structure_name: The name of variable of type struct /// \param component_name: The name of the component that should be assigned /// \return: All the assignments to that component. std::vector<code_assignt> require_goto_statements::find_struct_component_assignments( const std::vector<codet> &statements, const irep_idt &structure_name, const irep_idt &component_name) { std::vector<code_assignt> component_assignments; for(const auto &assignment : statements) { if(assignment.get_statement() == ID_assign) { const code_assignt &code_assign = to_code_assign(assignment); if(code_assign.lhs().id() == ID_member) { const auto &member_expr = to_member_expr(code_assign.lhs()); const auto &symbol = member_expr.symbol(); if( symbol.get_identifier() == structure_name && member_expr.get_component_name() == component_name) { component_assignments.push_back(code_assign); } } } } return component_assignments; } /// For a given variable name, gets the assignments to it in the provided /// instructions. /// \param pointer_name: The name of the variable /// \param instructions: The instructions to look through /// \return: A structure that contains the null assignment if found, and a /// vector of all other assignments require_goto_statements::pointer_assignment_locationt require_goto_statements::find_pointer_assignments( const irep_idt &pointer_name, const std::vector<codet> &instructions) { pointer_assignment_locationt locations; for(const codet &statement : instructions) { if(statement.get_statement() == ID_assign) { const code_assignt &code_assign = to_code_assign(statement); if( code_assign.lhs().id() == ID_symbol && to_symbol_expr(code_assign.lhs()).get_identifier() == pointer_name) { if( code_assign.rhs() == null_pointer_exprt(to_pointer_type(code_assign.lhs().type()))) { locations.null_assignment = code_assign; } else { locations.non_null_assignments.push_back(code_assign); } } } } return locations; } /// Find the declaration of the specific variable. /// \param variable_name: The name of the variable. /// \param entry_point_instructions: The statements to look through /// \return The declaration statement corresponding to that variable /// \throws no_decl_found_exceptiont if no declaration of the specific /// variable is found const code_declt &require_goto_statements::require_declaration_of_name( const irep_idt &variable_name, const std::vector<codet> &entry_point_instructions) { for(const auto &statement : entry_point_instructions) { if(statement.get_statement() == ID_decl) { const auto &decl_statement = to_code_decl(statement); if(decl_statement.get_identifier() == variable_name) { return decl_statement; } } } throw no_decl_found_exceptiont(variable_name.c_str()); }
31.41791
78
0.686223
[ "vector" ]
88857296d58708a6e4d777bcad831556948986b2
727
hpp
C++
software/perception/maps/src/libs/mini-maps/Utils.hpp
liangfok/oh-distro
eeee1d832164adce667e56667dafc64a8d7b8cee
[ "BSD-3-Clause" ]
92
2016-01-14T21:03:50.000Z
2021-12-01T17:57:46.000Z
software/perception/maps/src/libs/mini-maps/Utils.hpp
liangfok/oh-distro
eeee1d832164adce667e56667dafc64a8d7b8cee
[ "BSD-3-Clause" ]
62
2016-01-16T18:08:14.000Z
2016-03-24T15:16:28.000Z
software/perception/maps/src/libs/mini-maps/Utils.hpp
liangfok/oh-distro
eeee1d832164adce667e56667dafc64a8d7b8cee
[ "BSD-3-Clause" ]
41
2016-01-14T21:26:58.000Z
2022-03-28T03:10:39.000Z
#ifndef _maps_Utils_hpp_ #define _maps_Utils_hpp_ #include <Eigen/Geometry> #include <vector> namespace maps { class Utils { public: static bool isOrthographic(const Eigen::Matrix4f& iMatrix); static bool composeViewMatrix(Eigen::Projective3f& oMatrix, const Eigen::Matrix3f& iCalib, const Eigen::Isometry3f& iPose, const bool iIsOrthographic); static bool factorViewMatrix(const Eigen::Projective3f& iMatrix, Eigen::Matrix3f& oCalib, Eigen::Isometry3f& oPose, bool& oIsOrthographic); static uint64_t rand64(); }; } #endif
25.964286
66
0.57359
[ "geometry", "vector" ]
888864b1a0db251ee7bfe716a3ad5220b4692c84
7,113
cpp
C++
Libs/GuiSys/CompImage.cpp
dns/Cafu
77b34014cc7493d6015db7d674439fe8c23f6493
[ "MIT" ]
3
2020-04-11T13:00:31.000Z
2020-12-07T03:19:10.000Z
Libs/GuiSys/CompImage.cpp
DNS/Cafu
77b34014cc7493d6015db7d674439fe8c23f6493
[ "MIT" ]
null
null
null
Libs/GuiSys/CompImage.cpp
DNS/Cafu
77b34014cc7493d6015db7d674439fe8c23f6493
[ "MIT" ]
1
2020-04-11T13:00:04.000Z
2020-04-11T13:00:04.000Z
/* Cafu Engine, http://www.cafu.de/ Copyright (c) Carsten Fuchs and other contributors. This project is licensed under the terms of the MIT license. */ #include "CompImage.hpp" #include "AllComponents.hpp" #include "GuiImpl.hpp" #include "Window.hpp" #include "UniScriptState.hpp" #include "MaterialSystem/Mesh.hpp" #include "MaterialSystem/Renderer.hpp" extern "C" { #include <lua.h> #include <lualib.h> #include <lauxlib.h> } #if defined(_WIN32) && defined(_MSC_VER) // Turn off warning C4355: 'this' : used in base member initializer list. #pragma warning(disable:4355) #endif using namespace cf::GuiSys; /************************************/ /*** ComponentImageT::VarMatNameT ***/ /************************************/ ComponentImageT::VarMatNameT::VarMatNameT(const char* Name, const std::string& Value, const char* Flags[], ComponentImageT& CompImg) : TypeSys::VarT<std::string>(Name, Value, Flags), m_CompImg(CompImg) { } // The compiler-written copy constructor would copy m_CompImg from Var.m_CompImg, // but we must obviously use the reference to the proper parent instance instead. ComponentImageT::VarMatNameT::VarMatNameT(const VarMatNameT& Var, ComponentImageT& CompImg) : TypeSys::VarT<std::string>(Var), m_CompImg(CompImg) { } void ComponentImageT::VarMatNameT::Set(const std::string& v) { // Make sure that m_CompImg actually refers to the ComponentImageT instance that contains us! assert(this == &m_CompImg.m_MatName); TypeSys::VarT<std::string>::Set(v); MatSys::Renderer->FreeMaterial(m_CompImg.m_MatInst); m_CompImg.m_MatInst = NULL; if (m_CompImg.GetWindow() && !v.empty()) { m_CompImg.m_MatInst = MatSys::Renderer->RegisterMaterial( m_CompImg.GetWindow()->GetGui().GetMaterialManager().GetMaterial(v)); } } /***********************/ /*** ComponentImageT ***/ /***********************/ namespace { const char* FlagsIsColor[] = { "IsColor", NULL }; const char* FlagsIsMaterial[] = { "IsMaterial", NULL }; } const char* ComponentImageT::DocClass = "This component adds an image to its window."; const cf::TypeSys::VarsDocT ComponentImageT::DocVars[] = { { "Material", "The name of the image material." }, { "Color", "The color with which the image is tinted." }, { "Alpha", "The alpha component of the color." }, { NULL, NULL } }; ComponentImageT::ComponentImageT() : ComponentBaseT(), m_MatName("Material", "", FlagsIsMaterial, *this), m_MatInst(NULL), m_Color("Color", Vector3fT(1, 1, 1), FlagsIsColor), m_Alpha("Alpha", 1.0f) { FillMemberVars(); } ComponentImageT::ComponentImageT(const ComponentImageT& Comp) : ComponentBaseT(Comp), m_MatName(Comp.m_MatName, *this), m_MatInst(NULL), m_Color(Comp.m_Color), m_Alpha(Comp.m_Alpha) { // There is no need to do anything with m_MatInst here: assert(GetWindow() == NULL); FillMemberVars(); } void ComponentImageT::FillMemberVars() { GetMemberVars().Add(&m_MatName); GetMemberVars().Add(&m_Color); GetMemberVars().Add(&m_Alpha); } ComponentImageT::~ComponentImageT() { // Applications can work with `ComponentImageT`s before having initialized // the `MatSys::Renderer`, for example in `AppCaWE::WriteLuaDoxygenHeaders()`. if (MatSys::Renderer) { MatSys::Renderer->FreeMaterial(m_MatInst); m_MatInst = NULL; } } ComponentImageT* ComponentImageT::Clone() const { return new ComponentImageT(*this); } void ComponentImageT::UpdateDependencies(WindowT* Window) { const bool WindowChanged = Window != GetWindow(); ComponentBaseT::UpdateDependencies(Window); // m_Transform = NULL; if (WindowChanged) { MatSys::Renderer->FreeMaterial(m_MatInst); m_MatInst = NULL; } if (!GetWindow()) return; // // It would be possible to break this loop as soon as we have assigned a non-NULL pointer to m_Transform. // // However, this is only because the Transform component is, at this time, the only sibling component that // // we're interested in, whereas the loop below is suitable for resolving additional dependencies, too. // for (unsigned int CompNr = 0; CompNr < GetWindow()->GetComponents().Size(); CompNr++) // { // IntrusivePtrT<ComponentBaseT> Comp = GetWindow()->GetComponents()[CompNr]; // // if (m_Transform == NULL) // m_Transform = dynamic_pointer_cast<ComponentTransformT>(Comp); // } if (WindowChanged && !m_MatName.Get().empty()) { m_MatInst = MatSys::Renderer->RegisterMaterial( GetWindow()->GetGui().GetMaterialManager().GetMaterial(m_MatName.Get())); } } void ComponentImageT::Render() const { // MatSys::Renderer->SetCurrentAmbientLightColor(m_Color); MatSys::Renderer->SetCurrentMaterial(m_MatInst ? m_MatInst : GetWindow()->GetGui().GetDefaultRM()); static MatSys::MeshT BackMesh(MatSys::MeshT::Quads); BackMesh.Vertices.Overwrite(); BackMesh.Vertices.PushBackEmpty(4); // Just a single quad for the image rectangle. for (unsigned int VertexNr = 0; VertexNr < 4; VertexNr++) { for (unsigned int i = 0; i < 3; i++) BackMesh.Vertices[VertexNr].Color[i] = m_Color.Get()[i]; BackMesh.Vertices[VertexNr].Color[3] = m_Alpha.Get(); } const float x1 = 0.0f; const float y1 = 0.0f; const float x2 = GetWindow()->GetTransform()->GetSize().x; const float y2 = GetWindow()->GetTransform()->GetSize().y; BackMesh.Vertices[0].SetOrigin(x1, y1); BackMesh.Vertices[0].SetTextureCoord(0.0f, 0.0f); BackMesh.Vertices[1].SetOrigin(x2, y1); BackMesh.Vertices[1].SetTextureCoord(1.0f, 0.0f); BackMesh.Vertices[2].SetOrigin(x2, y2); BackMesh.Vertices[2].SetTextureCoord(1.0f, 1.0f); BackMesh.Vertices[3].SetOrigin(x1, y2); BackMesh.Vertices[3].SetTextureCoord(0.0f, 1.0f); MatSys::Renderer->RenderMesh(BackMesh); } static const cf::TypeSys::MethsDocT META_toString = { "__tostring", "This method returns a readable string representation of this object.", "string", "()" }; int ComponentImageT::toString(lua_State* LuaState) { // ScriptBinderT Binder(LuaState); // IntrusivePtrT<ComponentImageT> Comp = Binder.GetCheckedObjectParam< IntrusivePtrT<ComponentImageT> >(1); lua_pushfstring(LuaState, "image component"); return 1; } /***********************************/ /*** TypeSys-related definitions ***/ /***********************************/ void* ComponentImageT::CreateInstance(const cf::TypeSys::CreateParamsT& Params) { return new ComponentImageT(); } const luaL_Reg ComponentImageT::MethodsList[] = { { "__tostring", toString }, { NULL, NULL } }; const cf::TypeSys::MethsDocT ComponentImageT::DocMethods[] = { META_toString, { NULL, NULL, NULL, NULL } }; const cf::TypeSys::TypeInfoT ComponentImageT::TypeInfo(GetComponentTIM(), "GuiSys::ComponentImageT", "GuiSys::ComponentBaseT", ComponentImageT::CreateInstance, MethodsList, DocClass, DocMethods, NULL, DocVars);
28.338645
210
0.662168
[ "mesh", "render", "object", "transform" ]
888c6030b3cc9be98d3f3f9ce175d58a4929689c
1,183
hpp
C++
modules/math/source/blub/math/plane.hpp
qwertzui11/voxelTerrain
05038fb261893dd044ae82fab96b7708ea5ed623
[ "MIT" ]
96
2015-02-02T20:01:24.000Z
2021-11-14T20:33:29.000Z
modules/math/source/blub/math/plane.hpp
qwertzui11/voxelTerrain
05038fb261893dd044ae82fab96b7708ea5ed623
[ "MIT" ]
12
2016-06-04T15:45:30.000Z
2020-02-04T11:10:51.000Z
modules/math/source/blub/math/plane.hpp
qwertzui11/voxelTerrain
05038fb261893dd044ae82fab96b7708ea5ed623
[ "MIT" ]
19
2015-09-22T01:21:45.000Z
2020-09-30T09:52:27.000Z
#ifndef BLUB_MATH_PLANE_HPP #define BLUB_MATH_PLANE_HPP #include "blub/math/vector3.hpp" namespace Ogre { class Plane; } namespace blub { class plane { public: #ifndef BLUB_NO_OGRE3D plane(const Ogre::Plane &vec); operator Ogre::Plane() const; #endif plane(); plane(const plane& other); plane(vector3 p0, vector3 p1, vector3 p2); plane(vector3 pos, vector3 normal); plane(const vector3 &normal, const real &d); /** This is a pseudodistance. The sign of the return value is positive if the point is on the positive side of the plane, negative if the point is on the negative side, and zero if the point is on the plane. @par The absolute value of the return value is the true distance only when the plane normal is a unit length vector. */ real getDistance (const vector3 &rkPoint) const; bool operator==(const plane& rhs) const { return rhs.d == d && rhs.normal == normal; } bool operator!=(const plane& rhs) const { return rhs.d != d || rhs.normal != normal; } public: vector3 normal; real d; }; } #endif // BLUB_MATH_PLANE_HPP
20.050847
72
0.646661
[ "vector" ]
888d08f4f18f49f706f207f610ac2d7b6ea5a20b
2,148
cpp
C++
test/iterator.cpp
jspaaks/cuda-wrapper
66262b819d55814d35cdb88a7eb9ab3b67fadaf0
[ "BSD-3-Clause" ]
4
2016-01-07T05:05:15.000Z
2020-12-14T05:20:03.000Z
test/iterator.cpp
jspaaks/cuda-wrapper
66262b819d55814d35cdb88a7eb9ab3b67fadaf0
[ "BSD-3-Clause" ]
2
2016-06-03T15:48:01.000Z
2016-09-01T15:58:30.000Z
test/iterator.cpp
jspaaks/cuda-wrapper
66262b819d55814d35cdb88a7eb9ab3b67fadaf0
[ "BSD-3-Clause" ]
5
2015-03-09T11:07:14.000Z
2022-03-14T12:28:59.000Z
/* * Copyright (C) 2020 Jaslo Ziska * * This file is part of cuda-wrapper. * * This software may be modified and distributed under the terms of the * 3-clause BSD license. See accompanying file LICENSE for details. */ #define BOOST_TEST_MODULE iterator #include <boost/test/unit_test.hpp> #include <type_traits> #include <cuda_wrapper/cuda_wrapper.hpp> #include <cuda_wrapper/iterator_category.hpp> BOOST_AUTO_TEST_CASE(convertible) { // the device iterator tag should not be convertible to std::random_access_iterator_tag BOOST_CHECK((std::is_convertible< cuda::device_random_access_iterator_tag , std::random_access_iterator_tag >::value) == false); // host iterator tag should be convertible to std::random_access_iterator_tag BOOST_CHECK((std::is_convertible< cuda::host_random_access_iterator_tag , std::random_access_iterator_tag >::value) == true); // managed memory iterator tag must be convertible to host, device and std::random_access_iterator_tag BOOST_CHECK((std::is_convertible< cuda::managed_random_access_iterator_tag , std::random_access_iterator_tag >::value) == true); BOOST_CHECK((std::is_convertible< cuda::managed_random_access_iterator_tag , cuda::host_random_access_iterator_tag >::value) == true); BOOST_CHECK((std::is_convertible< cuda::managed_random_access_iterator_tag , cuda::device_random_access_iterator_tag >::value) == true); } BOOST_AUTO_TEST_CASE(vectors) { BOOST_CHECK((std::is_same< typename std::iterator_traits<cuda::memory::device::vector<int>::iterator>::iterator_category , cuda::device_random_access_iterator_tag >::value) == true); BOOST_CHECK((std::is_same< typename std::iterator_traits<cuda::memory::host::vector<int>::iterator>::iterator_category , cuda::host_random_access_iterator_tag >::value) == true); BOOST_CHECK((std::is_same< typename std::iterator_traits<cuda::memory::managed::vector<int>::iterator>::iterator_category , cuda::managed_random_access_iterator_tag >::value) == true); }
34.645161
106
0.721601
[ "vector" ]
888e122df738a7a789455f21254e0cfab3139c4b
5,114
hh
C++
core/inc/com/centreon/broker/config/state.hh
sdelafond/centreon-broker
21178d98ed8a061ca71317d23c2026dbc4edaca2
[ "Apache-2.0" ]
null
null
null
core/inc/com/centreon/broker/config/state.hh
sdelafond/centreon-broker
21178d98ed8a061ca71317d23c2026dbc4edaca2
[ "Apache-2.0" ]
null
null
null
core/inc/com/centreon/broker/config/state.hh
sdelafond/centreon-broker
21178d98ed8a061ca71317d23c2026dbc4edaca2
[ "Apache-2.0" ]
null
null
null
/* ** Copyright 2011-2012,2017 Centreon ** ** 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. ** ** For more information : contact@centreon.com */ #ifndef CCB_CONFIG_STATE_HH # define CCB_CONFIG_STATE_HH # include <list> # include <map> # include <string> # include "com/centreon/broker/config/endpoint.hh" # include "com/centreon/broker/config/logger.hh" # include "com/centreon/broker/namespace.hh" CCB_BEGIN() namespace config { /** * @class state state.hh "com/centreon/broker/config/state.hh" * @brief Full configuration state. * * A fully parsed configuration is represented within this class * which holds mandatory parameters as well as optional parameters, * along with object definitions. */ class state { public: state(); state(state const& other); ~state(); state& operator=(state const& other); void broker_id(unsigned int id) throw (); unsigned int broker_id() const throw (); void broker_name(std::string const& name); std::string const& broker_name() const throw (); void cache_directory(std::string const& dir); std::string const& cache_directory() const throw (); void command_file(std::string const& file); std::string const& command_file() const throw(); void command_protocol(std::string const& prot); std::string const& command_protocol() const throw(); void clear(); std::list<endpoint>& endpoints() throw (); std::list<endpoint> const& endpoints() const throw (); void event_queue_max_size( unsigned int val) throw (); unsigned int event_queue_max_size() const throw (); void flush_logs(bool flush) throw (); bool flush_logs() const throw (); void log_thread_id(bool log_id) throw (); bool log_thread_id() const throw (); void log_timestamp(logging::timestamp_type log_time) throw (); logging::timestamp_type log_timestamp() const throw (); void log_human_readable_timestamp( bool human_log_time) throw (); bool log_human_readable_timestamp() const throw(); std::list<logger>& loggers() throw (); std::list<logger> const& loggers() const throw (); std::string const& module_directory() const throw (); void module_directory( std::string const& dir); std::list<std::string>& module_list() throw (); std::list<std::string> const& module_list() const throw (); std::map<std::string, std::string>& params() throw (); std::map<std::string, std::string> const& params() const throw (); void poller_id(unsigned int id) throw (); unsigned int poller_id() const throw (); void poller_name(std::string const& name); std::string const& poller_name() const throw (); private: void _internal_copy(state const& other); unsigned int _broker_id; std::string _broker_name; std::string _cache_directory; std::string _command_file; std::string _command_protocol; std::list<endpoint> _endpoints; unsigned int _event_queue_max_size; bool _flush_logs; bool _log_thread_id; logging::timestamp_type _log_timestamp; bool _log_human_readable_timestamp; std::list<logger> _loggers; std::string _module_dir; std::list<std::string> _module_list; std::map<std::string, std::string> _params; unsigned int _poller_id; std::string _poller_name; }; } CCB_END() #endif // !CCB_CONFIG_STATE_HH
44.859649
91
0.529136
[ "object" ]
888eb2e5b0ecc3a143e34760a549e4cab3e97a35
1,423
cpp
C++
src/libloom/dictionary.cpp
It4innovations/HyperLoom
e2594d3f921c24f6e47cefad46888c2746e685dd
[ "DOC" ]
12
2018-06-05T13:03:30.000Z
2022-03-31T14:30:01.000Z
src/libloom/dictionary.cpp
It4innovations/HyperLoom
e2594d3f921c24f6e47cefad46888c2746e685dd
[ "DOC" ]
null
null
null
src/libloom/dictionary.cpp
It4innovations/HyperLoom
e2594d3f921c24f6e47cefad46888c2746e685dd
[ "DOC" ]
2
2019-12-03T10:08:01.000Z
2022-03-08T05:59:10.000Z
#include "dictionary.h" #include "libloom/log.h" #include <assert.h> using namespace loom; using namespace loom::base; Dictionary::Dictionary() { } Id Dictionary::find_symbol_or_fail(const std::string &symbol) const { auto i = symbol_to_id.find(symbol); if(i == symbol_to_id.end()) { logger->critical("Unknown symbol '{}'", symbol); exit(1); } assert(i->second != -1); return i->second; } Id Dictionary::find_symbol(const std::string &symbol) const { auto i = symbol_to_id.find(symbol); if(i == symbol_to_id.end()) { return -1; } assert(i->second != -1); return i->second; } Id Dictionary::find_or_create(const std::string &symbol) { auto i = symbol_to_id.find(symbol); if (i == symbol_to_id.end()) { int new_id = symbol_to_id.size(); symbol_to_id[symbol] = new_id; return new_id; } else { return i->second; } } const std::string& Dictionary::translate(Id id) { for (auto &i : symbol_to_id) { if (i.second == id) { return i.first; } } assert(0); } std::vector<std::string> Dictionary::get_all_symbols() const { std::vector<std::string> symbols; int size = symbol_to_id.size(); symbols.resize(size); for (auto &i : symbol_to_id) { assert(i.second >= 0 && i.second < size); symbols[i.second] = i.first; } return symbols; }
20.623188
67
0.59733
[ "vector" ]
8891477fa1b349a280b9691d03491b2eeb8e651f
2,595
cpp
C++
src/utils/file_helpers.cpp
AvocadoML/Avocado
9595cc5994d916f0ecb24873a5afa98437977fb5
[ "Apache-2.0" ]
null
null
null
src/utils/file_helpers.cpp
AvocadoML/Avocado
9595cc5994d916f0ecb24873a5afa98437977fb5
[ "Apache-2.0" ]
null
null
null
src/utils/file_helpers.cpp
AvocadoML/Avocado
9595cc5994d916f0ecb24873a5afa98437977fb5
[ "Apache-2.0" ]
null
null
null
/* * file_helpers.cpp * * Created on: Jun 17, 2021 * Author: Maciej Kozarzewski */ #include <Avocado/utils/file_helpers.hpp> #include <Avocado/utils/zip_wrapper.hpp> #include <fstream> #include <iterator> #include <iostream> #include <filesystem> #include <algorithm> namespace avocado { FileSaver::FileSaver(const std::string &path) : path(path), stream(path, std::ofstream::out) { } std::string FileSaver::getPath() const { return path; } void FileSaver::save(const Json &json, const SerializedObject &binary_data, int indent, bool compress) { std::string json_string = json.dump(indent); std::vector<char> to_save(json_string.begin(), json_string.end()); to_save.push_back('\n'); to_save.insert(to_save.end(), binary_data.data(), binary_data.data() + binary_data.size()); if (compress == true) to_save = ZipWrapper::compress(to_save); stream.write(to_save.data(), to_save.size()); } void FileSaver::close() { stream.close(); } FileLoader::FileLoader(const std::string &path, bool uncompress) { if (std::filesystem::exists(path) == false) throw std::runtime_error("File '" + path + "' does not exist"); uintmax_t filesize = std::filesystem::file_size(path); loaded_data.assign(filesize, '\0'); std::fstream file(path, std::fstream::in); if (file.good() == false) throw std::runtime_error("File '" + path + "' could not be opened"); file.read(loaded_data.data(), filesize); file.close(); if (uncompress == true) loaded_data = ZipWrapper::uncompress(loaded_data); split_point = std::min(loaded_data.size(), find_split_point()); load_all_data(); } const Json& FileLoader::getJson() const noexcept { return json; } Json& FileLoader::getJson() noexcept { return json; } const SerializedObject& FileLoader::getBinaryData() const noexcept { return binary_data; } SerializedObject& FileLoader::getBinaryData() noexcept { return binary_data; } void FileLoader::load_all_data() { std::string str(loaded_data.begin(), loaded_data.begin() + split_point); json = Json::load(str); binary_data.save(loaded_data.data() + split_point, loaded_data.size() - split_point); } size_t FileLoader::find_split_point() const noexcept { int opened_braces = 0; for (size_t i = 0; i < loaded_data.size(); i++) { if (loaded_data[i] == '{' || loaded_data[i] == '[') opened_braces++; if (loaded_data[i] == '}' || loaded_data[i] == ']') opened_braces--; if (opened_braces == 0) return i + 2; // +1 for }, another +1 for \n } return loaded_data.size(); } } /* namespace ml */
25.95
103
0.676301
[ "vector" ]
889cde90ac7d46384bef252a9eda2a3ef47fd350
1,221
cpp
C++
C++/Data_Structures/CountInversions.cpp
snehnakrani14/HactoberFest21
1d387ff4efec1f17fe20d42f46490564c5a87b52
[ "Unlicense" ]
1
2021-10-04T14:39:02.000Z
2021-10-04T14:39:02.000Z
C++/Data_Structures/CountInversions.cpp
snehnakrani14/HactoberFest21
1d387ff4efec1f17fe20d42f46490564c5a87b52
[ "Unlicense" ]
1
2021-10-06T04:41:55.000Z
2021-10-06T04:41:55.000Z
C++/Data_Structures/CountInversions.cpp
snehnakrani14/HactoberFest21
1d387ff4efec1f17fe20d42f46490564c5a87b52
[ "Unlicense" ]
1
2021-10-08T12:31:04.000Z
2021-10-08T12:31:04.000Z
#include <bits/stdc++.h> using namespace std; int merge(vector<int>& input,int start,int mid,int end){ int i = start; int j = mid+1; vector<int> temp; int count = 0; while(i<=mid&&j<=end){ if(input[i]>input[j]) { count+=mid-i+1; temp.push_back(input[j]); j++; } else { temp.push_back(input[i]); i++; } } while(i<=mid) temp.push_back(input[i++]); while(j<=end) temp.push_back(input[j++]); for(int i = start;i<=end;i++) input[i] = temp[i-start]; return count; } int countInversions(vector<int>& input,int start,int end){ int inversions = 0; if(start>=end) return 0; else { int mid = (start+end)/2; inversions+= countInversions(input,start,mid); inversions+= countInversions(input,mid+1,end); inversions+= merge(input,start,mid,end); } return inversions; } int main() { int t; cin>>t; while(t--){ int n; cin>>n; vector<int> input(n); for(int i = 0;i<n;i++) cin>>input[i]; cout<<countInversions(input,0,n-1)<<endl; for(int i = 0;i<n;i++) cout<<input[i]<<" "; } return 0; }
25.4375
59
0.520885
[ "vector" ]
88a141241f286f8470b4e4670c8f442c831dbb70
6,865
hpp
C++
Tests/workspace-fmt/serialize-test.hpp
magiruuvelvet/QAPI-IDE
7634acfd4a46075abefad0a2d6fded263b5d222d
[ "BSD-3-Clause" ]
2
2019-08-16T16:08:00.000Z
2019-11-01T00:47:52.000Z
Tests/workspace-fmt/serialize-test.hpp
magiruuvelvet/QAPI-IDE
7634acfd4a46075abefad0a2d6fded263b5d222d
[ "BSD-3-Clause" ]
8
2019-07-03T09:02:51.000Z
2019-07-27T13:01:35.000Z
Tests/workspace-fmt/serialize-test.hpp
magiruuvelvet/QAPI-IDE
7634acfd4a46075abefad0a2d6fded263b5d222d
[ "BSD-3-Clause" ]
null
null
null
#include <workspace/workspace.hpp> #include <bandit/bandit.h> #include <benchmark.hpp> using namespace snowhouse; using namespace bandit; go_bandit([]{ describe("WorkspaceFormat", []{ benchmark_it("[serialize empty workspace]", [&]{ Workspace workspace("test workspace"); const std::vector<std::uint8_t> expected = { 0xA2, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x6E, 0x74, 0x65, 0x73, 0x74, 0x20, 0x77, 0x6F, 0x72, 0x6B, 0x73, 0x70, 0x61, 0x63, 0x65, 0x6D, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x73, 0x80, }; AssertThat(workspace.serialize(), Equals(expected)); AssertThat(workspace.serializeJson(), Equals(R"({"name":"test workspace","requestgroups":[]})")); }); benchmark_it("[serialize workspace with empty request groups]", [&]{ Workspace workspace("test workspace"); workspace.addRequestGroup(Workspace::RequestGroup("group 1")); workspace.addRequestGroup(Workspace::RequestGroup("group 2")); const std::vector<std::uint8_t> expected = { 0xA2, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x6E, 0x74, 0x65, 0x73, 0x74, 0x20, 0x77, 0x6F, 0x72, 0x6B, 0x73, 0x70, 0x61, 0x63, 0x65, 0x6D, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x73, 0x82, 0xA2, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x67, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x20, 0x31, 0x68, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x80, 0xA2, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x67, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x20, 0x32, 0x68, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x80, }; AssertThat(workspace.serialize(), Equals(expected)); AssertThat(workspace.serializeJson(), Equals(R"({"name":"test workspace","requestgroups":[{"name":"group 1","requests":[]},{"name":"group 2","requests":[]}]})")); }); benchmark_it("[serialize workspace with data]", [&]{ Workspace workspace("test workspace"); Workspace::RequestGroup g1("group 1"); g1.addRequest(Workspace::Request("req 1", "http://localhost")); workspace.addRequestGroup(g1); Workspace::RequestGroup g2("group 2"); g2.addRequest(Workspace::Request("req 1", "http://127.0.0.1/v1/api")); g2.addRequest(Workspace::Request("req 2", "http://127.0.0.1/v2/api")); workspace.addRequestGroup(g2); const std::vector<std::uint8_t> expected = { 0xA2, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x6E, 0x74, 0x65, 0x73, 0x74, 0x20, 0x77, 0x6F, 0x72, 0x6B, 0x73, 0x70, 0x61, 0x63, 0x65, 0x6D, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x73, 0x82, 0xA2, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x67, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x20, 0x31, 0x68, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x81, 0xA3, 0x67, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0xA0, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x65, 0x72, 0x65, 0x71, 0x20, 0x31, 0x63, 0x75, 0x72, 0x6C, 0x70, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, 0xA2, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x67, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x20, 0x32, 0x68, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x82, 0xA3, 0x67, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0xA0, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x65, 0x72, 0x65, 0x71, 0x20, 0x31, 0x63, 0x75, 0x72, 0x6C, 0x77, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x31, 0x2F, 0x76, 0x31, 0x2F, 0x61, 0x70, 0x69, 0xA3, 0x67, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0xA0, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x65, 0x72, 0x65, 0x71, 0x20, 0x32, 0x63, 0x75, 0x72, 0x6C, 0x77, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x31, 0x2F, 0x76, 0x32, 0x2F, 0x61, 0x70, 0x69, }; AssertThat(workspace.serialize(), Equals(expected)); AssertThat(workspace.serializeJson(), Equals(R"({"name":"test workspace","requestgroups":[{"name":"group 1","requests":[{"headers":{},"name":"req 1","url":"http://localhost"}]},{"name":"group 2","requests":[{"headers":{},"name":"req 1","url":"http://127.0.0.1/v1/api"},{"headers":{},"name":"req 2","url":"http://127.0.0.1/v2/api"}]}]})")); }); benchmark_it("[serialize workspace with headers]", [&]{ Workspace workspace("test workspace"); Workspace::RequestGroup g1("group 1"); g1.addRequest(Workspace::Request("req 1", "http://localhost", {{"Content-Type", "application/json"}})); workspace.addRequestGroup(g1); const std::vector<std::uint8_t> expected = { 0xA2, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x6E, 0x74, 0x65, 0x73, 0x74, 0x20, 0x77, 0x6F, 0x72, 0x6B, 0x73, 0x70, 0x61, 0x63, 0x65, 0x6D, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x73, 0x81, 0xA2, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x67, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x20, 0x31, 0x68, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x81, 0xA3, 0x67, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0xA1, 0x6C, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x54, 0x79, 0x70, 0x65, 0x81, 0x70, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x6A, 0x73, 0x6F, 0x6E, 0x64, 0x6E, 0x61, 0x6D, 0x65, 0x65, 0x72, 0x65, 0x71, 0x20, 0x31, 0x63, 0x75, 0x72, 0x6C, 0x70, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x68, 0x6F, 0x73, 0x74, }; AssertThat(workspace.serialize(), Equals(expected)); AssertThat(workspace.serializeJson(), Equals(R"({"name":"test workspace","requestgroups":[{"name":"group 1","requests":[{"headers":{"Content-Type":["application/json"]},"name":"req 1","url":"http://localhost"}]}]})")); }); }); });
51.616541
324
0.529206
[ "vector" ]
88a31f614f9af21148ef7a26170d25dce073cda5
285
cpp
C++
451A - Game With Sticks.cpp
lionrocker/codeforces-solutions
02703ff02dab98d30ef01e52b5a1acc1d8596862
[ "MIT" ]
null
null
null
451A - Game With Sticks.cpp
lionrocker/codeforces-solutions
02703ff02dab98d30ef01e52b5a1acc1d8596862
[ "MIT" ]
null
null
null
451A - Game With Sticks.cpp
lionrocker/codeforces-solutions
02703ff02dab98d30ef01e52b5a1acc1d8596862
[ "MIT" ]
null
null
null
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, m; cin >> n >> m; int smaller = n > m ? m : n; if (smaller % 2 == 0) cout << "Malvika" << endl; else cout << "Akshat" << endl; return 0; }
12.954545
34
0.501754
[ "vector" ]
88b6baab7674c026e64fbe394171e3d91725513f
2,926
cpp
C++
source/main.cpp
ShawnHymel/example-standalone-inferencing
3b6ff47c841de62b1ae03a05b6795cb1c5a899f4
[ "Apache-2.0" ]
null
null
null
source/main.cpp
ShawnHymel/example-standalone-inferencing
3b6ff47c841de62b1ae03a05b6795cb1c5a899f4
[ "Apache-2.0" ]
null
null
null
source/main.cpp
ShawnHymel/example-standalone-inferencing
3b6ff47c841de62b1ae03a05b6795cb1c5a899f4
[ "Apache-2.0" ]
1
2022-02-06T06:03:05.000Z
2022-02-06T06:03:05.000Z
#include <stdio.h> #include "edge-impulse-sdk/classifier/ei_run_classifier.h" // Callback function declaration static int get_signal_data(size_t offset, size_t length, float *out_ptr); // Raw features copied from test sample static const float features[] = { // Copy raw features here (e.g. from the 'Model testing' page) }; int main(int argc, char **argv) { signal_t signal; // Wrapper for raw input buffer ei_impulse_result_t result; // Used to store inference output EI_IMPULSE_ERROR res; // Return code from inference // Calculate the length of the buffer size_t buf_len = sizeof(features) / sizeof(features[0]); // Make sure that the length of the buffer matches expected input length if (buf_len != EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE) { printf("ERROR: The size of the input buffer is not correct.\r\n"); printf("Expected %d items, but got %d\r\n", EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE, (int)buf_len); return 1; } // Assign callback function to fill buffer used for preprocessing/inference signal.total_length = EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE; signal.get_data = &get_signal_data; // Perform DSP pre-processing and inference res = run_classifier(&signal, &result, false); // Print return code and how long it took to perform inference printf("run_classifier returned: %d\r\n", res); printf("Timing: DSP %d ms, inference %d ms, anomaly %d ms\r\n", result.timing.dsp, result.timing.classification, result.timing.anomaly); // Print the prediction results (object detection) #if EI_CLASSIFIER_OBJECT_DETECTION == 1 printf("Object detection bounding boxes:\r\n"); for (uint32_t i = 0; i < EI_CLASSIFIER_OBJECT_DETECTION_COUNT; i++) { ei_impulse_result_bounding_box_t bb = result.bounding_boxes[i]; if (bb.value == 0) { continue; } printf(" %s (%f) [ x: %u, y: %u, width: %u, height: %u ]\r\n", bb.label, bb.value, bb.x, bb.y, bb.width, bb.height); } // Print the prediction results (classification) #else printf("Predictions:\r\n"); for (uint16_t i = 0; i < EI_CLASSIFIER_LABEL_COUNT; i++) { printf(" %s: ", ei_classifier_inferencing_categories[i]); printf("%.5f\r\n", result.classification[i].value); } #endif // Print anomaly result (if it exists) #if EI_CLASSIFIER_HAS_ANOMALY == 1 printf("Anomaly prediction: %.3f\r\n", result.anomaly); #endif return 0; } // Callback: fill a section of the out_ptr buffer when requested static int get_signal_data(size_t offset, size_t length, float *out_ptr) { for (size_t i = 0; i < length; i++) { out_ptr[i] = (features + offset)[i]; } return EIDSP_OK; }
34.023256
79
0.634313
[ "object", "model" ]
88b819af8c117df8faa7b102d47c1ba062f992a7
730
cpp
C++
Dataset/JC/valid/mergesort/cpp/3250.cpp
kkcookies99/UAST
fff81885aa07901786141a71e5600a08d7cb4868
[ "MIT" ]
1
2019-05-03T19:27:45.000Z
2019-05-03T19:27:45.000Z
Dataset/JC/valid/mergesort/cpp/3250.cpp
kkcookies99/UAST
fff81885aa07901786141a71e5600a08d7cb4868
[ "MIT" ]
null
null
null
Dataset/JC/valid/mergesort/cpp/3250.cpp
kkcookies99/UAST
fff81885aa07901786141a71e5600a08d7cb4868
[ "MIT" ]
null
null
null
#include <vector> using namespace std; template<class Iterator> int mergesort(Iterator first, Iterator last) { int n = last - first; if (n < 2) return 0; Iterator mid = first + n / 2; int sum = mergesort(first, mid) + mergesort(mid, last); typedef typename iterator_traits<Iterator>::value_type value_type; vector<value_type> seq(n); auto r = seq.begin(); Iterator p = first, q = mid; while (p < mid && q < last) if (*p <= *q) { *r++ = *p++; } else { *r++ = *q++; sum += mid - p; } while (p < mid) *r++ = *p++; while (q < last) *r++ = *q++; for (int i = 0; i < n; ++i) *(first + i) = seq[i]; return sum; }
24.333333
70
0.49863
[ "vector" ]
88c6c9c3c6ab48ee37dde21d400f005dff88c28b
6,028
cc
C++
engines/ep/tests/module_tests/bloomfilter_test.cc
nawazish-couchbase/kv_engine
132f1bb04c9212bcac9e401d069aeee5f63ff1cd
[ "MIT", "BSD-3-Clause" ]
104
2017-05-22T20:41:57.000Z
2022-03-24T00:18:34.000Z
engines/ep/tests/module_tests/bloomfilter_test.cc
nawazish-couchbase/kv_engine
132f1bb04c9212bcac9e401d069aeee5f63ff1cd
[ "MIT", "BSD-3-Clause" ]
3
2017-11-14T08:12:46.000Z
2022-03-03T11:14:17.000Z
engines/ep/tests/module_tests/bloomfilter_test.cc
nawazish-couchbase/kv_engine
132f1bb04c9212bcac9e401d069aeee5f63ff1cd
[ "MIT", "BSD-3-Clause" ]
71
2017-05-22T20:41:59.000Z
2022-03-29T10:34:32.000Z
/* * Copyright 2016-Present Couchbase, Inc. * * Use of this software is governed by the Business Source License included * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified * in that file, in accordance with the Business Source License, use of this * software will be governed by the Apache License, Version 2.0, included in * the file licenses/APL2.txt. */ #include <unordered_set> #include <folly/portability/GTest.h> #include <random> #include "bloomfilter.h" #include "tests/module_tests/test_helpers.h" #include <platform/murmurhash3.h> class BloomFilterTest : public ::testing::Test {}; // Test the size calculation when creating a bloom filter. // See: https://en.wikipedia.org/wiki/Bloom_filter TEST_F(BloomFilterTest, SizeCalculation) { struct Params { size_t keys; size_t bits; size_t hashes; }; std::vector<Params> params{{1, 10, 7}, {10, 96, 7}, {100, 959, 7}, {1000, 9585, 7}, {10000, 95851, 7}, {100000, 958506, 7}}; for (const auto& p : params) { BloomFilter bf(p.keys, 0.01, BFILTER_ENABLED); EXPECT_EQ(p.bits, bf.getFilterSize()) << "For keys=" << p.keys; EXPECT_EQ(p.hashes, bf.getNoOfHashes()) << "For keys=" << p.keys; } } // Test the filtering of the bloom filter. // Add N keys, then test that all N keys "may" exist in filter. TEST_F(BloomFilterTest, PositiveCheck) { // Generate N keys. First insert them all, then check they all exist. const int numKeys = 10000; const double targetFalsePositive = 0.01; // Create bloom filter sized for the given number of keys, and insert them // all. BloomFilter bf(numKeys, targetFalsePositive, BFILTER_ENABLED); for (int i = 0; i < numKeys; i++) { bf.addKey(makeStoredDocKey("key_" + std::to_string(i))); } // Test - check the N keys for existence for (int i = 0; i < numKeys; i++) { auto key = makeStoredDocKey("key_" + std::to_string(i)); EXPECT_TRUE(bf.maybeKeyExists(key)) << "For key:" << key.to_string(); } } // Test the false positive rate of the bloom filter. // Only expect a FP _close_ to the estimated (given the probabilstic nature // of the Bloom filter). TEST_F(BloomFilterTest, FalsePositiveRate) { // Generate 2 x N keys. First half will be inserted, second half // will be tested for membership - any which are found are false positives. const int numKeys = 10000; const double targetFalsePositive = 0.01; // Create bloom filter sized for the given number of keys, and insert them // all. BloomFilter bf(numKeys, targetFalsePositive, BFILTER_ENABLED); for (int i = 0; i < numKeys; i++) { bf.addKey(makeStoredDocKey("key_" + std::to_string(i))); } // Test - check the next N keys for existence int falsePositives = 0; for (int i = 0; i < numKeys; i++) { if (bf.maybeKeyExists( makeStoredDocKey("key_" + std::to_string(numKeys + i)))) { falsePositives++; } } // Allow a FP rate 10% either way. const int expectedFalsePositives = numKeys * targetFalsePositive; EXPECT_NEAR(expectedFalsePositives, falsePositives, expectedFalsePositives * 0.1); } class BloomFilterDocKeyTest : public BloomFilter, public ::testing::TestWithParam<std::tuple<CollectionID, CollectionID>> { public: BloomFilterDocKeyTest() : BloomFilter(10000, 0.01, BFILTER_ENABLED) { } }; /* * The following test is just checking for some basic hashing properties * for all namespaces, not checking for distribution quality etc... */ TEST_P(BloomFilterDocKeyTest, check_hashing) { if (std::get<0>(GetParam()) != std::get<1>(GetParam())) { auto key1 = StoredDocKey("key", std::get<0>(GetParam())); auto key2 = StoredDocKey("key", std::get<1>(GetParam())); std::unordered_set<uint64_t> key1_hashes; std::unordered_set<uint64_t> key2_hashes; // Always insert the first two hashes then check every subsequent hash // has no match in the set. key1_hashes.insert(hashDocKey(key1, 0)); key2_hashes.insert(hashDocKey(key2, 0)); for (size_t i = 1; i < noOfHashes; i++) { EXPECT_EQ(0, key1_hashes.count(hashDocKey(key1, i))); EXPECT_EQ(0, key2_hashes.count(hashDocKey(key1, i))); EXPECT_EQ(0, key1_hashes.count(hashDocKey(key2, i))); EXPECT_EQ(0, key2_hashes.count(hashDocKey(key2, i))); key1_hashes.insert(hashDocKey(key1, i)); key2_hashes.insert(hashDocKey(key2, i)); } } } TEST_P(BloomFilterDocKeyTest, check_addKey) { auto key1 = StoredDocKey("key", std::get<0>(GetParam())); auto key2 = StoredDocKey("key", std::get<1>(GetParam())); addKey(key1); addKey(key2); if (std::get<0>(GetParam()) != std::get<1>(GetParam())) { EXPECT_EQ(2, getNumOfKeysInFilter()); } else { EXPECT_EQ(1, getNumOfKeysInFilter()); } } TEST_P(BloomFilterDocKeyTest, check_maybeKeyExist) { auto key1 = StoredDocKey("key", std::get<0>(GetParam())); auto key2 = StoredDocKey("key", std::get<1>(GetParam())); addKey(key1); EXPECT_EQ(1, getNumOfKeysInFilter()); if (std::get<0>(GetParam()) != std::get<1>(GetParam())) { EXPECT_FALSE(maybeKeyExists(key2)); } else { EXPECT_TRUE(maybeKeyExists(key2)); } } // Test params includes our labelled collections that have 'special meaning' and // one normal collection ID (100) static std::vector<CollectionID> allDocNamespaces = { {CollectionID::Default, CollectionID::System, 100}}; INSTANTIATE_TEST_SUITE_P( DocNamespace, BloomFilterDocKeyTest, ::testing::Combine(::testing::ValuesIn(allDocNamespaces), ::testing::ValuesIn(allDocNamespaces)));
36.533333
80
0.633378
[ "vector" ]
88ced352db547d1972f0f3306b27da6dc098fbb8
4,702
cxx
C++
main/winaccessibility/source/service/AccParagraphEventListener.cxx
Grosskopf/openoffice
93df6e8a695d5e3eac16f3ad5e9ade1b963ab8d7
[ "Apache-2.0" ]
679
2015-01-06T06:34:58.000Z
2022-03-30T01:06:03.000Z
main/winaccessibility/source/service/AccParagraphEventListener.cxx
Grosskopf/openoffice
93df6e8a695d5e3eac16f3ad5e9ade1b963ab8d7
[ "Apache-2.0" ]
102
2017-11-07T08:51:31.000Z
2022-03-17T12:13:49.000Z
main/winaccessibility/source/service/AccParagraphEventListener.cxx
Grosskopf/openoffice
93df6e8a695d5e3eac16f3ad5e9ade1b963ab8d7
[ "Apache-2.0" ]
331
2015-01-06T11:40:55.000Z
2022-03-14T04:07:51.000Z
/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 <com/sun/star/accessibility/XAccessible.hpp> #include <com/sun/star/accessibility/AccessibleStateType.hpp> #include <com/sun/star/accessibility/AccessibleEventId.hpp> #include <com/sun/star/accessibility/AccessibleRole.hpp> #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp> #include "AccParagraphEventListener.hxx" #include "AccObjectManagerAgent.hxx" #include "unomsaaevent.hxx" using namespace com::sun::star::uno; using namespace com::sun::star::accessibility; AccParagraphEventListener::AccParagraphEventListener(com::sun::star::accessibility::XAccessible* pAcc, AccObjectManagerAgent* Agent) :AccContainerEventListener(pAcc, Agent) {} AccParagraphEventListener::~AccParagraphEventListener() { } /** * Uno's event notifier when event is captured * @param AccessibleEventObject the event object which contains information about event */ void AccParagraphEventListener::notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException) { switch (aEvent.EventId) { case AccessibleEventId::CARET_CHANGED: handleCaretChangedEvent(aEvent.OldValue, aEvent.NewValue); break; case AccessibleEventId::VISIBLE_DATA_CHANGED: handleVisibleDataChangedEvent(); break; case AccessibleEventId::BOUNDRECT_CHANGED: handleBoundrectChangedEvent(); break; //Added for paragraph selected state. case AccessibleEventId::STATE_CHANGED: { short State; if( (aEvent.NewValue >>= State) && (State == AccessibleStateType::SELECTED) ) { pAgent->IncreaseState( pAccessible, State); break; } else if( (aEvent.OldValue >>= State) && (State == AccessibleStateType::SELECTED) ) { pAgent->DecreaseState( pAccessible, State); break; } AccContainerEventListener::notifyEvent(aEvent); break; } case AccessibleEventId::TEXT_SELECTION_CHANGED: handleTextSelectionChangedEvent(); break; default: AccContainerEventListener::notifyEvent(aEvent); break; } } /** * handle the CARET_CHANGED event * @param oldValue in UNO, this parameter is always NULL * @param newValue in UNO, this parameter is always NULL */ void AccParagraphEventListener::handleCaretChangedEvent(Any oldValue, Any newValue) { pAgent->UpdateLocation(pAccessible); pAgent->NotifyAccEvent(UM_EVENT_OBJECT_CARETCHANGE, pAccessible); } /** * handle the VISIBLE_DATA_CHANGED event */ void AccParagraphEventListener::handleVisibleDataChangedEvent() { AccEventListener::handleVisibleDataChangedEvent(); } /** * handle the BOUNDRECT_CHANGED event */ void AccParagraphEventListener::handleBoundrectChangedEvent() { AccEventListener::handleBoundrectChangedEvent(); } /** * set the new state and fire the MSAA event * @param state new state id * @param enable true if state is set, false if state is unset */ void AccParagraphEventListener::setComponentState(short state, bool enable ) { // only the following state can be fired state event. switch (state) { case AccessibleStateType::EDITABLE: // no msaa state break; case AccessibleStateType::MULTI_LINE: // no msaa state mapping break; case AccessibleStateType::SINGLE_LINE: // no msaa state mapping break; default: AccContainerEventListener::setComponentState(state, enable); break; } } void AccParagraphEventListener::handleTextSelectionChangedEvent() { pAgent->NotifyAccEvent(UM_EVENT_TEXT_SELECTION_CHANGED, pAccessible); }
32.205479
132
0.692046
[ "object" ]
88f4c1f2d5b5a6f00d1871235ebada7bb35b76a6
14,126
cpp
C++
src/EventTraceKit.EtwCore/Source/TdhMessageFormatter.cpp
ljani/event-trace-kit
59a217fbaecfc87b3915e2494a8d25593d04ae99
[ "MIT" ]
10
2018-07-14T07:29:59.000Z
2021-10-30T17:53:26.000Z
src/EventTraceKit.EtwCore/Source/TdhMessageFormatter.cpp
ljani/event-trace-kit
59a217fbaecfc87b3915e2494a8d25593d04ae99
[ "MIT" ]
3
2019-06-07T08:29:11.000Z
2020-10-14T15:05:33.000Z
src/EventTraceKit.EtwCore/Source/TdhMessageFormatter.cpp
ljani/event-trace-kit
59a217fbaecfc87b3915e2494a8d25593d04ae99
[ "MIT" ]
3
2020-09-22T19:33:23.000Z
2021-10-30T22:59:45.000Z
#include "etk/TdhMessageFormatter.h" #include "etk/ADT/Span.h" #include "etk/Support/ErrorHandling.h" #include <evntcons.h> #include <in6addr.h> #include <strsafe.h> #include <tdh.h> namespace etk { namespace { template<typename T, typename U> ETK_ALWAYS_INLINE T GetAt(U* ptr, size_t offset) { return reinterpret_cast<T>(reinterpret_cast<uint8_t*>(ptr) + offset); } // The mapped string values defined in a manifest will contain a trailing space // in the EVENT_MAP_ENTRY structure. Replace the trailing space with a null- // terminating character, so that the bit mapped strings are correctly formatted. void RemoveTrailingSpace(EVENT_MAP_INFO* mapInfo) { for (ULONG i = 0; i < mapInfo->EntryCount; ++i) { EVENT_MAP_ENTRY const& entry = mapInfo->MapEntryArray[i]; wchar_t* str = GetAt<wchar_t*>(mapInfo, entry.OutputOffset); str[wcslen(str) - 1] = L'\0'; } } template<typename T> ULONG GetProperty(EVENT_RECORD const* record, PROPERTY_DATA_DESCRIPTOR& pdd, T& value) { return TdhGetProperty(const_cast<EVENT_RECORD*>(record), 0, nullptr, 1, &pdd, sizeof(value), reinterpret_cast<PBYTE>(&value)); } ULONG GetProperty(EventInfo info, EVENT_PROPERTY_INFO const& property, USHORT& value) { PROPERTY_DATA_DESCRIPTOR pdd = {}; if (!info.TryGetAt(property.NameOffset, pdd.PropertyName)) return ERROR_EVT_INVALID_EVENT_DATA; pdd.ArrayIndex = ULONG_MAX; DWORD count = 0; // Expects the count to be defined by a UINT16 or UINT32 ULONG ec = GetProperty(info.Record(), pdd, count); if (ec != ERROR_SUCCESS) { value = 0; return ec; } value = static_cast<USHORT>(count); return ec; } // Get the length of the property data. For MOF-based events, the size is // inferred from the data type of the property. For manifest-based events, the // property can specify the size of the property value using the length // attribute. The length attribute can specify the size directly or specify the // name of another property in the event data that contains the size. If the // property does not include the length attribute, the size is inferred from the // data type. The length will be zero for variable length, null-terminated // strings and structures. ULONG GetPropertyLength(EventInfo info, EVENT_PROPERTY_INFO const& propInfo, USHORT* propertyLength) { // If the property is a binary blob and is defined in a manifest, the // property can specify the blob's size or it can point to another property // that defines the blob's size. The PropertyParamLength flag indicates // where the blob's size is defined. if ((propInfo.Flags & PropertyParamLength) == PropertyParamLength) { auto const& lengthProperty = info->EventPropertyInfoArray[propInfo.lengthPropertyIndex]; return GetProperty(info, lengthProperty, *propertyLength); } if (propInfo.length > 0) { *propertyLength = propInfo.length; return ERROR_SUCCESS; } // If the property is a binary blob and is defined in a MOF class, the // extension qualifier is used to determine the size of the blob. // However, if the extension is IPAddrV6, we must determine the property // length because the EVENT_PROPERTY_INFO.length field will be zero. if (propInfo.nonStructType.InType == TDH_INTYPE_BINARY && propInfo.nonStructType.OutType == TDH_OUTTYPE_IPV6) { *propertyLength = static_cast<USHORT>(sizeof(IN6_ADDR)); } else if (propInfo.nonStructType.InType == TDH_INTYPE_UNICODESTRING || propInfo.nonStructType.InType == TDH_INTYPE_ANSISTRING || (propInfo.Flags & PropertyStruct) == PropertyStruct) { *propertyLength = propInfo.length; } else { wprintf(L"Unexpected length of 0 for intype %d and outtype %d\n", propInfo.nonStructType.InType, propInfo.nonStructType.OutType); return ERROR_EVT_INVALID_EVENT_DATA; } return ERROR_SUCCESS; } // Gets the size of the array. For MOF-based events, the size is specified in // the declaration or using the MAX qualifier. For manifest-based events, the // property can specify the size of the array using the count attribute. The // count attribute can specify the size directly or specify the name of another // property in the event data that contains the size. ULONG GetArraySize(EventInfo info, EVENT_PROPERTY_INFO const& propInfo, USHORT* arraySize) { if ((propInfo.Flags & PropertyParamCount) == 0) { *arraySize = propInfo.count; return ERROR_SUCCESS; } EVENT_PROPERTY_INFO const& paramInfo = info->EventPropertyInfoArray[propInfo.countPropertyIndex]; return GetProperty(info, paramInfo, *arraySize); } // Both MOF-based events and manifest-based events can specify name/value maps. // The map values can be integer values or bit values. If the property specifies // a value map, get the map. ULONG GetEventMapInfo(EVENT_RECORD const* event, wchar_t const* mapName, DWORD decodingSource, EVENT_MAP_INFO*& mapInfo, std::vector<BYTE>& mapBuffer) { mapInfo = new (mapBuffer.data()) EVENT_MAP_INFO; // Retrieve the required buffer size for the map info. DWORD bufferSize = static_cast<DWORD>(mapBuffer.size()); ULONG ec = TdhGetEventMapInformation(const_cast<EVENT_RECORD*>(event), const_cast<wchar_t*>(mapName), bufferSize ? mapInfo : nullptr, &bufferSize); if (ec == ERROR_INSUFFICIENT_BUFFER) { mapBuffer.resize(bufferSize); mapInfo = new (mapBuffer.data()) EVENT_MAP_INFO; ec = TdhGetEventMapInformation(const_cast<EVENT_RECORD*>(event), const_cast<wchar_t*>(mapName), mapInfo, &bufferSize); } if (ec == ERROR_SUCCESS) { if (decodingSource == DecodingSourceXMLFile) RemoveTrailingSpace(mapInfo); } else if (ec == ERROR_NOT_FOUND) { ec = ERROR_SUCCESS; // This case is okay. } return ec; } ULONG GetEventMapInfo(EventInfo info, EVENT_PROPERTY_INFO const& propertyInfo, EVENT_MAP_INFO*& mapInfo, std::vector<BYTE>& mapBuffer) { if (propertyInfo.nonStructType.MapNameOffset == 0) return ERROR_SUCCESS; wchar_t const* mapName; if (!info.TryGetAt(propertyInfo.nonStructType.MapNameOffset, mapName)) return ERROR_EVT_INVALID_EVENT_DATA; ULONG ec = GetEventMapInfo(info.Record(), mapName, info->DecodingSource, mapInfo, mapBuffer); if (ec != ERROR_SUCCESS) return ec; return ERROR_SUCCESS; } ULONG FormatProperty(TRACE_EVENT_INFO const& tei, EVENT_MAP_INFO const* emi, unsigned pointerSize, EVENT_PROPERTY_INFO const& pi, USHORT propertyLength, cspan<std::byte> userData, ULONG* bufferSize, wchar_t* buffer, USHORT* userDataConsumed) { return TdhFormatProperty( const_cast<TRACE_EVENT_INFO*>(&tei), const_cast<EVENT_MAP_INFO*>(emi), static_cast<ULONG>(pointerSize), pi.nonStructType.InType, pi.nonStructType.OutType, propertyLength, static_cast<USHORT>(userData.size()), const_cast<BYTE*>(reinterpret_cast<BYTE const*>(userData.data())), bufferSize, buffer, userDataConsumed); } ULONG FormatProperty(EventInfo info, EVENT_PROPERTY_INFO const& propInfo, size_t pointerSize, cspan<std::byte>& userData, std::wstring& sink, std::vector<wchar_t>& buffer, std::vector<BYTE>& mapBuffer) { ULONG ec; USHORT propertyLength = 0; ec = GetPropertyLength(info, propInfo, &propertyLength); if (ec != ERROR_SUCCESS) return ec; // Get the size of the array if the property is an array. USHORT arraySize = 0; ec = GetArraySize(info, propInfo, &arraySize); if (ec != ERROR_SUCCESS) return ec; for (USHORT k = 0; k < arraySize; ++k) { // If the property is a structure, print the members of the structure. if ((propInfo.Flags & PropertyStruct) == PropertyStruct) { DWORD lastMember = propInfo.structType.StructStartIndex + propInfo.structType.NumOfStructMembers; for (USHORT j = propInfo.structType.StructStartIndex; j < lastMember; ++j) { EVENT_PROPERTY_INFO const& pi = info->EventPropertyInfoArray[j]; ec = FormatProperty(info, pi, pointerSize, userData, sink, buffer, mapBuffer); if (ec != ERROR_SUCCESS) return ec; } continue; } // Get the name/value mapping if the property specifies a value map. EVENT_MAP_INFO* mapInfo = nullptr; if (propInfo.nonStructType.MapNameOffset != 0) { ec = GetEventMapInfo(info, propInfo, mapInfo, mapBuffer); if (ec != ERROR_SUCCESS) return ec; } DWORD bufferSize = 0; USHORT userDataConsumed = 0; bufferSize = static_cast<DWORD>(buffer.size() * sizeof(wchar_t)); ec = FormatProperty(*info.Info(), mapInfo, pointerSize, propInfo, propertyLength, userData, &bufferSize, buffer.data(), &userDataConsumed); if (ec == ERROR_INSUFFICIENT_BUFFER) { buffer.resize(bufferSize / sizeof(wchar_t)); ec = FormatProperty(*info.Info(), mapInfo, pointerSize, propInfo, propertyLength, userData, &bufferSize, buffer.data(), &userDataConsumed); } if (ec != ERROR_SUCCESS) return ec; buffer.resize(bufferSize / sizeof(wchar_t)); userData.remove_prefix(userDataConsumed); sink.append(buffer.data(), buffer.size() - 1); // buffer is null-terminated. } return ec; } } // namespace bool TdhMessageFormatter::FormatEventMessage(EventInfo const info, size_t const pointerSize, wchar_t* const buffer, size_t const bufferSize) { if (!info) return false; cspan<std::byte> userData = info.UserData(); if (info.IsStringOnly()) { (void)StringCchCopyNW(buffer, bufferSize, reinterpret_cast<wchar_t const*>(userData.data()), userData.size() / sizeof(wchar_t)); return true; } formattedProperties.clear(); formattedPropertiesOffsets.clear(); formattedPropertiesPointers.clear(); wchar_t const* const message = info.EventMessage(); if (!message) return FormatMofEvent(info, pointerSize, buffer, bufferSize); for (ULONG i = 0; i < info->TopLevelPropertyCount; ++i) { auto const& pi = info->EventPropertyInfoArray[i]; size_t begin = formattedProperties.size(); DWORD const ec = FormatProperty(info, pi, pointerSize, userData, formattedProperties, propertyBuffer, mapBuffer); if (ec != ERROR_SUCCESS) return false; formattedProperties.push_back(0); formattedPropertiesOffsets.push_back(begin); } for (auto const& begin : formattedPropertiesOffsets) formattedPropertiesPointers.push_back( reinterpret_cast<DWORD_PTR>(&formattedProperties[begin])); auto const formatFlags = FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY; DWORD const numWritten = FormatMessageW(formatFlags, message, 0, 0, buffer, bufferSize, reinterpret_cast<va_list*>(formattedPropertiesPointers.data())); return numWritten != 0; #if 0 wchar_t const* ptr = info.EventMessage(); while (ptr) { auto begin = ptr; while (*ptr && *ptr != L'%') ++ptr; if (ptr != begin) sink.append(begin, ptr - begin); if (!*ptr) break; ++ptr; // Skip % if (*ptr == L'n') { ++ptr; sink += L'\n'; continue; } begin = ptr; int index = 0; while (*ptr && *ptr >= L'0' && *ptr <= L'9') { if (index >= 255) break; // FIXME index = (index * 10) + (*ptr - L'0'); ++ptr; } if (ptr == begin) { // Invalid char after %, ignore. ++ptr; sink += L'%'; sink += *ptr; continue; } if (index < 1 || static_cast<unsigned>(index) > info->TopLevelPropertyCount) { sink.append(begin, ptr - begin); continue; } sink.append(formattedProperties, formattedPropertiesOffsets[index - 1], formattedPropertiesOffsets[index] - formattedPropertiesOffsets[index - 1]); } return true; #endif } bool TdhMessageFormatter::FormatMofEvent(EventInfo const& info, size_t const pointerSize, wchar_t* const buffer, size_t const bufferSize) { cspan<std::byte> userData = info.UserData(); for (ULONG i = 0; i < info->TopLevelPropertyCount; ++i) { auto const& pi = info->EventPropertyInfoArray[i]; if (i > 0) formattedProperties.append(L"; "); if (wchar_t const* propertyName = info.GetStringAt(pi.NameOffset)) { formattedProperties.append(propertyName); formattedProperties.append(L": "); } DWORD const ec = FormatProperty(info, pi, pointerSize, userData, formattedProperties, propertyBuffer, mapBuffer); if (ec != ERROR_SUCCESS) return false; } (void)StringCchCopyNW(buffer, bufferSize, formattedProperties.data(), formattedProperties.length()); return true; } } // namespace etk
36.786458
95
0.625442
[ "vector" ]
88f51eb151ad8e41fc369fb5c5a1efb682d008b2
1,237
hpp
C++
boost/boost_1_56_0/boost/geometry/strategies/distance_comparable_to_regular.hpp
cooparation/caffe-android
cd91078d1f298c74fca4c242531989d64a32ba03
[ "BSD-2-Clause-FreeBSD" ]
133
2018-04-20T14:09:40.000Z
2021-08-15T11:51:25.000Z
boost/boost_1_56_0/boost/geometry/strategies/distance_comparable_to_regular.hpp
cooparation/caffe-android
cd91078d1f298c74fca4c242531989d64a32ba03
[ "BSD-2-Clause-FreeBSD" ]
61
2015-05-27T11:20:11.000Z
2019-12-20T15:06:21.000Z
boost/boost_1_56_0/boost/geometry/strategies/distance_comparable_to_regular.hpp
cooparation/caffe-android
cd91078d1f298c74fca4c242531989d64a32ba03
[ "BSD-2-Clause-FreeBSD" ]
83
2018-04-27T03:58:02.000Z
2022-01-11T09:23:40.000Z
// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2014, Oracle and/or its affiliates. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html #ifndef BOOST_GEOMETRY_STRATEGIES_DISTANCE_COMPARABLE_TO_REGULAR_HPP #define BOOST_GEOMETRY_STRATEGIES_DISTANCE_COMPARABLE_TO_REGULAR_HPP #include <boost/geometry/core/tags.hpp> #include <boost/geometry/core/cs.hpp> #include <boost/geometry/algorithms/not_implemented.hpp> namespace boost { namespace geometry { namespace strategy { namespace distance { #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS namespace services { template < typename ComparableStrategy, typename Strategy, typename Geometry1, typename Geometry2, typename CsTag1 = typename cs_tag<Geometry1>::type, typename CsTag2 = typename cs_tag<Geometry2>::type > struct comparable_to_regular : geometry::not_implemented<CsTag1, CsTag2> {}; } // namespace services #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS }} // namespace strategy::distance }} // namespace boost::geometry #endif // BOOST_GEOMETRY_STRATEGIES_DISTANCE_COMPARABLE_TO_REGULAR_HPP
22.907407
73
0.787389
[ "geometry" ]
88f6a627ddcc89f9d231015936dcd93de499102f
1,744
cpp
C++
core/helpers/Feeder/TCPFeeder/Packet.cpp
sears-s/fluffi
5f2f6d019041a6268199b69bf2f34487b18b84fe
[ "MIT" ]
96
2019-09-19T10:28:05.000Z
2022-02-28T11:53:06.000Z
core/helpers/Feeder/TCPFeeder/Packet.cpp
sears-s/fluffi
5f2f6d019041a6268199b69bf2f34487b18b84fe
[ "MIT" ]
123
2019-11-19T09:47:14.000Z
2021-10-19T03:10:51.000Z
core/helpers/Feeder/TCPFeeder/Packet.cpp
sears-s/fluffi
5f2f6d019041a6268199b69bf2f34487b18b84fe
[ "MIT" ]
23
2019-11-11T06:04:56.000Z
2022-02-11T15:35:26.000Z
/* Copyright 2017-2020 Siemens AG 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. Author(s): Thomas Riedmaier */ #include "stdafx.h" #include "Packet.h" Packet::Packet(const std::vector<char> & packetBytes, WHAT_TODO_AFTER_SEND whatTodo) : m_packetBytes(packetBytes), m_waitForBytes(), m_whatTodo(whatTodo), m_waitMS(-1) { } Packet::Packet(const std::vector<char> & packetBytes, WHAT_TODO_AFTER_SEND whatTodo, int waitMS) : m_packetBytes(packetBytes), m_waitForBytes(), m_whatTodo(whatTodo), m_waitMS(waitMS) { } Packet::Packet(const std::vector<char> & packetBytes, WHAT_TODO_AFTER_SEND whatTodo, std::vector<char> waitForBytes) : m_packetBytes(packetBytes), m_waitForBytes(waitForBytes), m_whatTodo(whatTodo), m_waitMS(-1) { } Packet::~Packet() { }
32.90566
118
0.78383
[ "vector" ]
88f93269d02fcac2abd24ea003fc9b2188628412
3,171
cpp
C++
httpC/Request.cpp
worldyun/httpC
fc5a3985c6e02b32508b236c3c9607ab3b1dc023
[ "Apache-2.0" ]
null
null
null
httpC/Request.cpp
worldyun/httpC
fc5a3985c6e02b32508b236c3c9607ab3b1dc023
[ "Apache-2.0" ]
null
null
null
httpC/Request.cpp
worldyun/httpC
fc5a3985c6e02b32508b236c3c9607ab3b1dc023
[ "Apache-2.0" ]
null
null
null
#include "Request.h" #include <string> #include <map> #include <iostream> #include "UrlCode.h" #include "StringP.h" #include <vector> #include "json.hpp" #include <sstream> using json = nlohmann::json; using namespace std; void Request::requestPaser(string reqHeader, string reqBody) { //处理Http头 //cout << reqHeader; vector<string> tempHeader; StringP::strSplit(reqHeader, tempHeader, "\r\n", 2); if (tempHeader.size() > 1) { string firstLine = tempHeader.at(0); vector<string> firstLineData; StringP::strSplit(firstLine, firstLineData, " ", 2); if (firstLineData.size() == 3) { this->reqHeaderData["httpMethod"] = firstLineData.at(0); this->reqHeaderData["url"] = firstLineData.at(1); this->url = firstLineData.at(1); this->host = StringP::strFindLeft(this->url, ":"); vector<string> urlData; StringP::strSplit(this->url, urlData, "?"); if (urlData.size() > 1) { this->dataPaser(urlData.at(1), this->getData); } this->router = urlData.at(0); this->reqHeaderData["versions"] = firstLineData.at(2); vector<string>::iterator oneLine; for (oneLine = tempHeader.begin() + 1; oneLine != tempHeader.end(); oneLine++) { vector<string> oneLineDatas; StringP::strSplit(*oneLine, oneLineDatas, ": ", 2); if (oneLineDatas.size() == 2) { this->reqHeaderData[oneLineDatas.at(0)] = oneLineDatas.at(1); } } } } //cout << this->reqHeaderData.dump(4); //处理Cookies if (this->reqHeaderData.find("Cookie") != this->reqHeaderData.end()) { string strCookies = reqHeaderData.find("Cookie").value(); vector<string> vecCookies; StringP::strSplit(strCookies, vecCookies, "; ", 2); vector<string>::iterator iter; for (iter = vecCookies.begin(); iter != vecCookies.end(); iter++) { vector<string> keyVlue; StringP::strSplit(*iter, keyVlue, "="); if (keyVlue.size() == 2) { this->cookies[keyVlue.at(0)] = keyVlue.at(1); } } } //cout << this->cookies.dump(4); //处理Post数据 if (reqBody.length() > 0) { this->dataPaser(reqBody, this->postData); } } void Request::dataPaser(string strData , json& data) { strData = urldecode(strData); if (strData[0] != '{') { vector<string> datas; StringP::strSplit(strData, datas, "&", 2); vector<string>::iterator index; for (index = datas.begin(); index != datas.end(); index++) { vector<string> keyValue; StringP::strSplit(*index, keyValue, "="); if (keyValue.size() == 2) { data[keyValue.at(0)] = keyValue.at(1); } } } else { try { data = json::parse(strData); } catch (const std::exception&) { // 计划:写入日志文件 } } //cout << data.dump(4) << endl; } string Request::getGetData(string key) { json::iterator strmapIter; strmapIter = this->getData.find(key); if (strmapIter != getData.end()) { return strmapIter.value(); } return ""; } string Request::getPostData(string key) { json::iterator strmapIter; strmapIter = this->postData.find(key); if (strmapIter != postData.end()) { return strmapIter.value(); } return ""; }
24.206107
82
0.613056
[ "vector" ]
88fbe22e1df9d6ab32104c2ba932c6314e7beea0
177
cc
C++
src/main.cc
samkrew/node_mbus
a15a9e006c14ef2d8b818030bf1feabb86e54f66
[ "MIT" ]
null
null
null
src/main.cc
samkrew/node_mbus
a15a9e006c14ef2d8b818030bf1feabb86e54f66
[ "MIT" ]
null
null
null
src/main.cc
samkrew/node_mbus
a15a9e006c14ef2d8b818030bf1feabb86e54f66
[ "MIT" ]
null
null
null
#include <nan.h> #include "mbus-master.h" using namespace v8; void init(Handle<Object> exports, Handle<Object> module) { MbusMaster::Init(module); } NODE_MODULE(mbus, init)
17.7
58
0.728814
[ "object" ]
88ff42926744dc1d103f974df0749c696bd317fa
1,179
cpp
C++
plugins/robots/common/twoDModel/src/engine/items/colorFieldItem.cpp
ladaegorova18/trik-studio
f8d9ce50301fd93c948ac774e85c0e6bfff820bc
[ "Apache-2.0" ]
17
2019-06-04T06:22:47.000Z
2022-02-11T18:27:25.000Z
plugins/robots/common/twoDModel/src/engine/items/colorFieldItem.cpp
ladaegorova18/trik-studio
f8d9ce50301fd93c948ac774e85c0e6bfff820bc
[ "Apache-2.0" ]
1,248
2019-02-21T19:32:09.000Z
2022-03-29T16:50:04.000Z
plugins/robots/common/twoDModel/src/engine/items/colorFieldItem.cpp
khodand/trik-studio
3d2de6809d38b621433c7ccb1cd98da8868d022d
[ "Apache-2.0" ]
17
2019-02-12T07:58:23.000Z
2022-03-10T11:39:21.000Z
/* Copyright 2007-2015 QReal Research Group * * 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 "colorFieldItem.h" using namespace twoDModel::items; ColorFieldItem::ColorFieldItem(QGraphicsItem* parent) : graphicsUtils::AbstractItem(parent) { setZValue(ZValue::Shape); } ColorFieldItem::~ColorFieldItem() { } QColor ColorFieldItem::color() const { return pen().color(); } void ColorFieldItem::setColor(const QColor &color) { setPenColor(color.name()); setBrushColor(color.name()); update(); } int ColorFieldItem::thickness() const { return pen().width(); } void ColorFieldItem::setThickness(int thickness) { setPenWidth(thickness); update(); }
23.117647
75
0.741306
[ "shape" ]
322fd54fed91255d1f57cfe578320caa9d6f3a20
1,078
cpp
C++
puzzle06/puzzle06_1.cpp
schnaader/AdventOfCode2021
0808282f90e4ef97edf130f228435860f332e1d3
[ "Apache-2.0" ]
1
2021-12-19T12:34:03.000Z
2021-12-19T12:34:03.000Z
puzzle06/puzzle06_1.cpp
schnaader/AdventOfCode2021
0808282f90e4ef97edf130f228435860f332e1d3
[ "Apache-2.0" ]
null
null
null
puzzle06/puzzle06_1.cpp
schnaader/AdventOfCode2021
0808282f90e4ef97edf130f228435860f332e1d3
[ "Apache-2.0" ]
null
null
null
#include <stdio.h> #include <iostream> #include <fstream> #include <sstream> #include <string> #include <vector> #include <array> int main() { int sum_unmarked = 0; //std::ifstream input("example.txt"); std::ifstream input("input.txt"); if (!input.is_open()) { printf("Error opening file\n"); return -1; } std::vector<int> fish_timers; std::string first_line; getline(input, first_line); std::istringstream fl(first_line); std::string number; while (getline(fl, number, ',')) { fish_timers.push_back(atoi(number.c_str())); } printf("Fish count: %li\n", fish_timers.size()); for (int i = 0; i < 80; i++) { std::vector<int> new_timers; int spawn_count = 0; int new_timer; for (auto timer: fish_timers) { if (timer > 0) { new_timer = timer - 1; } else if (timer == 0) { new_timer = 6; spawn_count++; } new_timers.push_back(new_timer); } for (int i = 0; i < spawn_count; i++) { new_timers.push_back(8); } fish_timers = new_timers; } printf("Fish count after 80 days: %li\n", fish_timers.size()); }
19.6
63
0.630798
[ "vector" ]
323695eceedbfdf3eaf8623e53e318cddcf55302
7,557
cpp
C++
unittests/testMath.cpp
shamanDevel/DiffDVR
99fbe9f114d0097daf402bde2ae35f18dade335d
[ "BSD-3-Clause" ]
12
2021-08-02T04:51:48.000Z
2022-01-14T18:02:27.000Z
unittests/testMath.cpp
shamanDevel/DiffDVR
99fbe9f114d0097daf402bde2ae35f18dade335d
[ "BSD-3-Clause" ]
2
2021-11-04T14:23:30.000Z
2022-02-28T10:30:13.000Z
unittests/testMath.cpp
shamanDevel/DiffDVR
99fbe9f114d0097daf402bde2ae35f18dade335d
[ "BSD-3-Clause" ]
4
2021-07-16T10:23:45.000Z
2022-01-04T02:51:43.000Z
#include <catch.hpp> #include <random> #include <vector> #include <Eigen/Core> #include <torch/torch.h> #include <renderer_utils.cuh> #include <losses.h> #include "check_adjoint.h" #include "test_utils.h" //namespace std { // template < class T > // inline std::ostream& operator << (std::ostream& os, const std::vector<T>& v) // { // os << "["; // for (typename std::vector<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) // { // os << " " << *ii; // } // os << " ]"; // return os; // } //} TEST_CASE("LogSumExp-double", "[math]") { std::default_random_engine rnd(42); std::uniform_real_distribution<double> distr(-5, +5); for (int N=1; N<=10; ++N) { DYNAMIC_SECTION("N=" << N) { std::vector<double> values(N); for (int i = 0; i < N; ++i) values[i] = distr(rnd); const auto valuesLambda = [values](int i) {return values[i]; }; double resultActual = kernel::logSumExp<double>(N, valuesLambda); //naive double resultExpected = 0; for (int i = 0; i < N; ++i) resultExpected += rexp(values[i]); resultExpected = rlog(resultExpected); REQUIRE(resultActual == Approx(resultExpected)); } } } TEST_CASE("LogSumExp-double4", "[math]") { std::default_random_engine rnd(42); std::uniform_real_distribution<double> distr(-5, +5); for (int N = 1; N <= 10; ++N) { DYNAMIC_SECTION("N=" << N) { std::vector<double4> values(N); for (int i = 0; i < N; ++i) { values[i] = make_double4( distr(rnd), distr(rnd), distr(rnd), distr(rnd)); } const auto valuesLambda = [values](int i) {return values[i]; }; double4 resultActual = kernel::logSumExp<double4>(N, valuesLambda); //naive double4 resultExpected = make_double4(0); for (int i = 0; i < N; ++i) resultExpected += rexp(values[i]); resultExpected = rlog(resultExpected); REQUIRE(resultActual.x == Approx(resultExpected.x)); REQUIRE(resultActual.y == Approx(resultExpected.y)); REQUIRE(resultActual.z == Approx(resultExpected.z)); REQUIRE(resultActual.w == Approx(resultExpected.w)); } } } TEST_CASE("LogSumExp-scaling-double", "[math]") { std::default_random_engine rnd(42); std::uniform_real_distribution<double> distr(-5, +5); for (int N = 1; N <= 10; ++N) { DYNAMIC_SECTION("N=" << N) { std::vector<double> values(N); std::vector<double> scaling(N); for (int i = 0; i < N; ++i) { values[i] = distr(rnd); scaling[i] = fabs(distr(rnd)); } INFO("values: " << values); INFO("scaling: " << scaling); const auto valuesLambda = [values](int i) {return values[i]; }; const auto scalingLambda = [scaling](int i) {return scaling[i]; }; double resultActual = kernel::logSumExpWithScaling<double>( N, valuesLambda, scalingLambda); //naive double resultExpected = 0; for (int i = 0; i < N; ++i) resultExpected += scaling[i] * rexp(values[i]); resultExpected = rlog(resultExpected); REQUIRE(resultActual == Approx(resultExpected)); } } } TEST_CASE("LogSumExp-scaling-double4", "[math]") { std::default_random_engine rnd(42); std::uniform_real_distribution<double> distr(-5, +5); for (int N = 1; N <= 10; ++N) { DYNAMIC_SECTION("N=" << N) { std::vector<double4> values(N); std::vector<double> scaling(N); for (int i = 0; i < N; ++i) { values[i] = make_double4( distr(rnd), distr(rnd), distr(rnd), distr(rnd)); scaling[i] = fabs(distr(rnd)); } const auto valuesLambda = [values](int i) {return values[i]; }; const auto scalingLambda = [scaling](int i) {return scaling[i]; }; double4 resultActual = kernel::logSumExpWithScaling<double4>( N, valuesLambda, scalingLambda); //naive double4 resultExpected = make_double4(0); for (int i = 0; i < N; ++i) resultExpected += scaling[i] * rexp(values[i]); resultExpected = rlog(resultExpected); REQUIRE(resultActual.x == Approx(resultExpected.x)); REQUIRE(resultActual.y == Approx(resultExpected.y)); REQUIRE(resultActual.z == Approx(resultExpected.z)); REQUIRE(resultActual.w == Approx(resultExpected.w)); } } } TEST_CASE("LogMSE-double", "[math]") { std::default_random_engine rnd(42); std::uniform_real_distribution<double> distr(-5, +5); for (int i = 1; i <= 50; ++i) { INFO("i: " << i); double logX = distr(rnd); double logY = distr(rnd); double x = exp(logX), y = exp(logY); INFO("x=" << x << ", y=" << y); double mseExpected = (x - y) * (x - y); double mseActualLog = kernel::logMSE(logX, logY); double mseActual = exp(mseActualLog); REQUIRE(mseActual == Approx(mseExpected)); } } TEST_CASE("LogL1-double", "[math]") { std::default_random_engine rnd(42); std::uniform_real_distribution<double> distr(-5, +5); for (int i = 1; i <= 50; ++i) { INFO("i: " << i); double logX = distr(rnd); double logY = distr(rnd); double x = exp(logX), y = exp(logY); INFO("x=" << x << ", y=" << y); double l1Expected = fabs(x - y); double l1ActualLog = kernel::logL1(logX, logY); double l1Actual = exp(l1ActualLog); REQUIRE(l1Actual == Approx(l1Expected)); } } TEST_CASE("Adjoint-LogMSE", "[adjoint]") { typedef empty TmpStorage_t; typedef Eigen::VectorXd Vector_t; auto forward = [](const Vector_t& x, TmpStorage_t* tmp) -> Vector_t { double logX = x[0], logY = x[1]; double res = kernel::logMSE(logX, logY); Vector_t rese(1); rese[0] = res; return rese; }; auto adjoint = [](const Vector_t& x, const Vector_t& e, const Vector_t& g, Vector_t& z, const TmpStorage_t& tmp) { double logX = x[0], logY = x[1]; double adjOut = g[0]; double adjLogX, adjLogY; kernel::adjLogMSE(logX, logY, adjOut, adjLogX, adjLogY); z[0] = adjLogX; z[1] = adjLogY; }; std::default_random_engine rnd(42); std::uniform_real_distribution<double> distr(-5, +5); int N = 20; for (int i = 0; i < N; ++i) { INFO("N=" << i); Vector_t x(2); for (int j = 0; j < 2; ++j) x[j] = distr(rnd); checkAdjoint<Vector_t, TmpStorage_t>(x, forward, adjoint, 1e-5, 1e-5, 1e-6); } } TEST_CASE("Adjoint-Log1", "[adjoint]") { typedef empty TmpStorage_t; typedef Eigen::VectorXd Vector_t; auto forward = [](const Vector_t& x, TmpStorage_t* tmp) -> Vector_t { double logX = x[0], logY = x[1]; double res = kernel::logL1(logX, logY); Vector_t rese(1); rese[0] = res; return rese; }; auto adjoint = [](const Vector_t& x, const Vector_t& e, const Vector_t& g, Vector_t& z, const TmpStorage_t& tmp) { double logX = x[0], logY = x[1]; double adjOut = g[0]; double adjLogX, adjLogY; kernel::adjLogL1(logX, logY, adjOut, adjLogX, adjLogY); z[0] = adjLogX; z[1] = adjLogY; }; std::default_random_engine rnd(42); std::uniform_real_distribution<double> distr(-5, +5); int N = 20; for (int i = 0; i < N; ++i) { INFO("N=" << i); Vector_t x(2); for (int j = 0; j < 2; ++j) x[j] = distr(rnd); checkAdjoint<Vector_t, TmpStorage_t>(x, forward, adjoint, 1e-5, 1e-5, 1e-6); } } TEST_CASE("Adjoint-LogMSE-Full", "[adjoint]") { torch::Tensor logX = torch::randn({ 4,5 }, at::TensorOptions().dtype(c10::kDouble).device(c10::kCUDA)) .requires_grad_(true); torch::Tensor logY = torch::randn({ 4,5 }, at::TensorOptions().dtype(c10::kDouble).device(c10::kCUDA)) .requires_grad_(true); torch::Tensor out = renderer::logMSE(logX, logY); torch::Tensor grad_out = torch::rand_like(out); auto grad_inputs = torch::autograd::grad( { out }, { logX, logY }, { grad_out }); torch::Tensor grad_logX = grad_inputs[0]; torch::Tensor grad_logY = grad_inputs[1]; std::cout << "grad_logX:\n" << grad_logX << std::endl; }
25.880137
85
0.628292
[ "vector" ]
323ae261b43ef5435453741d99917e01ba689b0d
8,518
cpp
C++
humble-crap/humble-network.cpp
lukesalisbury/humble-crap
814c551cfdfa2687d531b50d350a0d2a6f5cf832
[ "Unlicense" ]
2
2015-02-02T23:40:03.000Z
2016-02-17T17:58:18.000Z
humble-crap/humble-network.cpp
lukesalisbury/humble-crap
814c551cfdfa2687d531b50d350a0d2a6f5cf832
[ "Unlicense" ]
null
null
null
humble-crap/humble-network.cpp
lukesalisbury/humble-crap
814c551cfdfa2687d531b50d350a0d2a6f5cf832
[ "Unlicense" ]
null
null
null
/**************************************************************************** * Copyright © Luke Salisbury * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgement in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. ****************************************************************************/ #include <zlib.h> #include "humble-network.hpp" #include "global.hpp" QNetworkAccessManager * getNetworkManager(); QByteArray gUncompress(const QByteArray &data) { if (data.size() <= 4) { qWarning("gUncompress: Input data is truncated"); return QByteArray(); } QByteArray result; int ret; z_stream strm; static const int CHUNK_SIZE = 1024; char out[CHUNK_SIZE]; // allocate inflate state strm.zalloc = nullptr; strm.zfree = nullptr; strm.opaque = nullptr; strm.avail_in = static_cast<uInt>(data.size()); strm.next_in = (Bytef*)(data.data()); ret = inflateInit2(&strm, 15 + 32); // gzip decoding if (ret != Z_OK) return QByteArray(); // run inflate() do { strm.avail_out = CHUNK_SIZE; strm.next_out = (Bytef*)(out); ret = inflate(&strm, Z_NO_FLUSH); Q_ASSERT(ret != Z_STREAM_ERROR); // state not clobbered switch (ret) { case Z_NEED_DICT: ret = Z_DATA_ERROR; // and fall through [[clang::fallthrough]]; case Z_DATA_ERROR: case Z_MEM_ERROR: (void)inflateEnd(&strm); return QByteArray(); } result.append(out, CHUNK_SIZE - strm.avail_out); } while (strm.avail_out == 0); // clean up and return inflateEnd(&strm); return result; } /** * @brief HumbleNetworkRequest::HumbleNetworkRequest */ HumbleNetworkRequest::HumbleNetworkRequest(): sslMissing(0) { /* Setup webManager */ this->webManager = getNetworkManager(); connect( this->webManager, SIGNAL( sslErrors(QNetworkReply*, const QList<QSslError>) ), SLOT( sslError(QNetworkReply*, const QList<QSslError> ))); connect( this->webManager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( finishRequest(QNetworkReply*)) ); if ( !QSslSocket::supportsSsl() ) { this->errorMessage = "OpenSSL not installed"; qDebug() << this->errorMessage; this->sslMissing = true; emit requestError( this->errorMessage, nullptr, 0 ); } } /** * @brief HumbleNetworkRequest::appendPost * @param key * @param value */ void HumbleNetworkRequest::appendPost(QString key, QString value) { if ( this->postData.length() > 0 ) { this->postData.append("&"); } this->postData.append(key); this->postData.append("="); this->postData.append(value); } /** * @brief HumbleNetworkRequest::retrieveContent * @return */ QByteArray HumbleNetworkRequest::retrieveContent() { qDebug() << "retrieveContent"; return this->downloadData; } /** * @brief HumbleNetworkRequest::writeContent * @param outputFile * @return */ bool HumbleNetworkRequest::writeContent(QString outputFile) { qDebug() << "writeContent"; QString path = QStandardPaths::writableLocation( QStandardPaths::DataLocation ); QFile f(path + "/" + outputFile); f.open( QIODevice::WriteOnly|QIODevice::Truncate ); f.write( this->downloadData ); f.close(); return true; } /** * @brief HumbleNetworkRequest::makeRequest * @return */ bool HumbleNetworkRequest::makeRequest(QUrl url, QString requester) { if ( QSslSocket::supportsSsl() ) { QNetworkRequest request; //request.setRawHeader("User-Agent", "Humble-bundle Content Retrieving APplication - http://github.org/lukesalisbury/humble-crap"); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); request.setRawHeader("Accept-Encoding", "gzip,deflate" ); request.setRawHeader("Accept-Language", "en-US,en;q=0.5" ); //request.setRawHeader("Connection", "keep-alive" ); request.setRawHeader("Accept", "application/json, text/javascript, */*; q=0.01" ); request.setRawHeader("DNT", "1" ); if ( !requester.isEmpty() ) request.setRawHeader("X-Requested-By", requester.toUtf8() ); request.setRawHeader("origin", HUMBLEURL_COOKIE); request.setRawHeader("referer", HUMBLEURL_COOKIE); if ( !this->csrfPreventionToken.isEmpty() ) { request.setRawHeader("CSRF-Prevention-Token", this->csrfPreventionToken.toUtf8() ); this->csrfPreventionToken = ""; // Unset token, incase we reuse this object } request.setUrl( url ); //qDebug() << "Url" << url << " - " << this->postData.toPercentEncoding("=&"); if ( this->postData.length() > 0 ) { this->reply = this->webManager->post( request, this->postData.toPercentEncoding("=&") ); this->postData.clear(); } else { this->reply = this->webManager->get( request ); } connect( this->reply, SIGNAL( downloadProgress( qint64, qint64 )), this, SLOT(downloadProgress( qint64, qint64 )) ); return true; } else { } return false; } QNetworkCookieJar *HumbleNetworkRequest::getCookies() { return this->webManager->cookieJar(); } bool HumbleNetworkRequest::setCookies(QNetworkCookieJar * cookies_jar) { this->webManager->setCookieJar(cookies_jar); return false; } /** * @brief HumbleNetworkRequest::printCookies * @param content */ void HumbleNetworkRequest::printCookies() { QNetworkCookieJar * cookies = this->webManager->cookieJar(); QList<QNetworkCookie> list = cookies->cookiesForUrl( QUrl(HUMBLEURL_COOKIE) ); for (int i = 0; i < list.size(); ++i) { qDebug() << list.at(i).name() << "-" << list.at(i).value(); } } /** * @brief HumbleNetworkRequest::sslError * @param pReply * @param errors */ void HumbleNetworkRequest::sslError(QNetworkReply* pReply, const QList<QSslError> & errors ) { this->errorMessage = "SSL Error"; qDebug() << "Network Error:" << pReply->errorString(); for (int i = 0; i < errors.size(); ++i) { qDebug() << "SSL Error:" << errors.at(i).errorString(); } emit requestError( this->errorMessage, nullptr, 0 ); } /** * @brief HumbleNetworkRequest::downloadProgress * @param bytesReceived * @param bytesTotal */ void HumbleNetworkRequest::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { emit requestProgress(bytesReceived, bytesTotal); } /** * @brief HumbleNetworkRequest::finishRequest * @param pReply */ void HumbleNetworkRequest::finishRequest( QNetworkReply* pReply ) { //QVariant variantCookies = this->reply->header(QNetworkRequest::SetCookieHeader); if ( pReply == this->reply ) { QVariant redirectionTarget = pReply->attribute(QNetworkRequest::RedirectionTargetAttribute); QUrl url = redirectionTarget.toUrl(); qint16 code = static_cast<qint16>(pReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()); QByteArray data = pReply->readAll(); if ( pReply->rawHeader("Content-Encoding") == "gzip") { this->downloadData = gUncompress(data); } else { this->downloadData = data; } pReply->deleteLater(); if ( pReply->error() ) { //qDebug() << tr("Download failed: %1. %2").arg(pReply->errorString(), pReply->url().toString()); //QList<QByteArray> headerList = pReply->rawHeaderList(); //foreach(QByteArray head, headerList) { // qDebug() << head << ":" << pReply->rawHeader(head); //} this->errorMessage = pReply->errorString(); emit requestError( this->errorMessage, this->downloadData, code ); } else if ( url.path() == "/login") { //qDebug() << tr("Login failed") << url.query(); this->errorMessage = "Login failed"; emit requestError( this->errorMessage, this->downloadData, code ); } else if ( url.isEmpty() ) { qDebug() << tr("Download Successful: %1").arg(pReply->url().toString()); //QList<QByteArray> headerList = pReply->rawHeaderList(); //foreach(QByteArray head, headerList) { // qDebug() << head << ":" << pReply->rawHeader(head); //} emit requestSuccessful( this->downloadData ); } else { qDebug() << tr("New URL requested") << pReply->url().toString(); this->makeRequest( url ); } } }
28.019737
147
0.682202
[ "object" ]
3240687bf8e8372931afff6d8d8d502fa4f7e457
5,281
cpp
C++
methods/slmm/slmmir_lauritzen_diag.cpp
ambrad/COMPOSE
0bda7aeaf2b8494c7de8cd179c22e340b08eda6e
[ "BSD-3-Clause" ]
3
2018-12-30T20:01:25.000Z
2020-07-22T23:44:14.000Z
methods/slmm/slmmir_lauritzen_diag.cpp
E3SM-Project/COMPOSE
0bda7aeaf2b8494c7de8cd179c22e340b08eda6e
[ "BSD-3-Clause" ]
8
2019-02-06T19:08:31.000Z
2020-04-24T03:40:49.000Z
methods/slmm/slmmir_lauritzen_diag.cpp
ambrad/COMPOSE
0bda7aeaf2b8494c7de8cd179c22e340b08eda6e
[ "BSD-3-Clause" ]
2
2019-01-16T03:58:31.000Z
2019-02-06T22:45:43.000Z
#include "slmmir_p_refine.hpp" #include "slmmir_lauritzen_diag.hpp" #include <vector> extern "C" { void correlation_diag(const Real* f1, const Real* f2, int K, const Real* dA, Real* real_mixing, Real* overshooting, Real* range_pres_unmixing); void filament_diag(int K, const Real* f1, const Real* dA, Real* fila_t0, int linit, Real* thresholds, Real* fila_tf); } static void write_mixing_plot_data (const Real* cb, const Real* ccb, const Int n, const D2Cer& d2cer, const std::string& out_prefix) { const Int cnn = d2cer.get_cnn(); std::vector<Real> cgdata(2*cnn); auto* const cbd = cgdata.data(); auto* const ccbd = cgdata.data() + cnn; d2cer.d2c(cb, cbd); d2cer.d2c(ccb, ccbd); FILE* fid = fopen((out_prefix + "-lauritzen-diag.dat").c_str(), "w"); std::vector<float> cgsp(2*cnn); for (int i = 0; i < 2*cnn; ++i) cgsp[i] = cgdata[i]; auto* const cbdsp = cgsp.data(); auto* const ccbdsp = cgsp.data() + cnn; fwrite(&cnn, sizeof(Int), 1, fid); fwrite(cbd, sizeof(*cbdsp), cnn, fid); fwrite(ccbd, sizeof(*ccbdsp), cnn, fid); fclose(fid); } struct LauritzenDiag::Impl { Int nsteps_per_12days, len; std::vector<Real> thresholds, fila_t0, fila_tf, fila_t0_me, fila_tf_me; Int tidx_cosbells, tidx_corrcosbells; bool expensive_io, ran_cor, ran_fil, ran_me; Real real_mixing, overshooting, range_pres_unmixing; Real real_mixing_me, overshooting_me, range_pres_unmixing_me; }; LauritzenDiag ::LauritzenDiag (const Int nsteps_per_12days, const Int len, const std::vector<gallery::InitialCondition::Shape>& ics, const Real* tracer_data, const Real* dA, const bool expensive_io) { #ifdef SLMMIR_LAURITZEN_DIAG p = std::make_shared<Impl>(); p->expensive_io = expensive_io; p->nsteps_per_12days = nsteps_per_12days; p->len = len; p->thresholds.resize(100); p->fila_t0.resize(100); p->fila_tf.resize(100); p->fila_t0_me.resize(100); p->fila_tf_me.resize(100); p->tidx_cosbells = p->tidx_corrcosbells = -1; p->ran_cor = p->ran_fil = p->ran_me = false; for (size_t i = 0; i < ics.size(); ++i) { if (ics[i] == gallery::InitialCondition::Shape::CosineBells) p->tidx_cosbells = i; else if (ics[i] == gallery::InitialCondition::Shape::CorrelatedCosineBells) p->tidx_corrcosbells = i; } if (p->tidx_cosbells >= 0) filament_diag(len, tracer_data + p->tidx_cosbells*len, dA, p->fila_t0.data(), 1, nullptr, nullptr); #endif } bool LauritzenDiag ::run (const Int step, const Real* tracer_data, const Real* dA, const D2Cer& d2cer, const std::string& out_prefix) { #ifdef SLMMIR_LAURITZEN_DIAG if (p->tidx_cosbells < 0) return false; const bool day6 = ((p->nsteps_per_12days % 2 == 0) && (step + 1 == p->nsteps_per_12days/2)); if ( ! day6) return false; filament_diag(p->len, tracer_data + p->tidx_cosbells * p->len, dA, p->fila_t0.data(), 0, p->thresholds.data(), p->fila_tf.data()); p->ran_fil = true; if (p->tidx_corrcosbells < 0) return false; correlation_diag(tracer_data + p->tidx_cosbells * p->len, tracer_data + p->tidx_corrcosbells * p->len, p->len, dA, &p->real_mixing, &p->overshooting, &p->range_pres_unmixing); if (p->expensive_io) write_mixing_plot_data(tracer_data + p->tidx_cosbells * p->len, tracer_data + p->tidx_corrcosbells * p->len, p->len, d2cer, out_prefix); p->ran_cor = true; return p->ran_fil && p->ran_cor; #endif return false; } void LauritzenDiag ::run_me (const Int n, const Real* tracer_data, const Real* dA, const bool first) { #ifdef SLMMIR_LAURITZEN_DIAG if ( ! (p->ran_fil || first) || p->ran_me) return; if ( ! first) p->ran_me = true; if (first) filament_diag(n, tracer_data + p->tidx_cosbells * n, dA, p->fila_t0_me.data(), 1, nullptr, nullptr); else filament_diag(n, tracer_data + p->tidx_cosbells * n, dA, p->fila_t0_me.data(), 0, p->thresholds.data(), p->fila_tf_me.data()); if (p->tidx_corrcosbells < 0) return; correlation_diag(tracer_data + p->tidx_cosbells * n, tracer_data + p->tidx_corrcosbells * n, n, dA, &p->real_mixing_me, &p->overshooting_me, &p->range_pres_unmixing_me); #endif } void LauritzenDiag::print () { if (p->ran_cor) { printf("L l_r %8.2e l_u %8.2e l_o %8.2e\n", p->real_mixing, p->range_pres_unmixing, p->overshooting); if (p->ran_me) printf("L me l_r %8.2e l_u %8.2e l_o %8.2e\n", p->real_mixing_me, p->range_pres_unmixing_me, p->overshooting_me); } if (p->ran_fil) { printf("L thr"); Int n = 0; for (size_t i = 0; i < p->thresholds.size(); ++i) { if (p->thresholds[i] < 0) { n = i; break; } printf(" %1.3f", p->thresholds[i]); } printf("\nL fil"); for (Int i = 0; i < n; ++i) printf(" %1.2f", p->fila_tf[i]); printf("\n"); if (p->ran_me) { printf("\nL me fil"); for (Int i = 0; i < n; ++i) printf(" %1.2f", p->fila_tf_me[i]); printf("\n"); } } }
37.453901
90
0.608597
[ "shape", "vector" ]
3245d2468b4ff47ffc4e508eac46f5a0120cfdc1
4,702
cpp
C++
grammar/json/lex-number.cpp
tociyuki/libtoml-cxx11
64b4017273e5c94b9bdd57fca3efc6bc6663ac4e
[ "Unlicense" ]
null
null
null
grammar/json/lex-number.cpp
tociyuki/libtoml-cxx11
64b4017273e5c94b9bdd57fca3efc6bc6663ac4e
[ "Unlicense" ]
null
null
null
grammar/json/lex-number.cpp
tociyuki/libtoml-cxx11
64b4017273e5c94b9bdd57fca3efc6bc6663ac4e
[ "Unlicense" ]
null
null
null
#include <cstdlib> #include <iostream> #include <string> #include <vector> #include "../check-builder.hpp" #include "../layoutable.hpp" enum { TOKEN_INVALID, TOKEN_SCALAR, TOKEN_STRING, TOKEN_LBRACE, TOKEN_RBRACE, TOKEN_LBRACKET, TOKEN_RBRACKET, TOKEN_COLON, TOKEN_COMMA, TOKEN_ENDMARK, }; struct toml_number_type : public layoutable, public check_builder_type { // character class enum { ZERO = 1, DIGIT, POINT, EXP, PLUS, MINUS, MATCH }; std::vector<int> base; std::vector<int> check; bool defined; toml_number_type () : check_builder_type (), base (), check (), defined (false) {} void define_charset () { charset (0, 127, 0); charset ('0', ZERO); charset ('1','9', DIGIT); charset ('.', POINT); charset ('e', EXP); charset ('E', EXP); charset ('+', PLUS); charset ('-', MINUS); } void define_state () { // RFC 7159 JSON 6. Numbers // [-]? ([0] / [1-9][0-9]*) ([.] [0-9]+)? ([eE][+-]?[0-9]+)? to (1, MINUS, 2); to (1, ZERO, 3); to (1, DIGIT, 4); to (2, ZERO, 3); to (2, DIGIT, 4); to (3, POINT, 5); to (3, EXP, 7); to (3, MATCH, 1); to (4, ZERO, 4); to (4, DIGIT, 4); to (4, POINT, 5); to (4, EXP, 7); to (4, MATCH, 1); to (5, ZERO, 6); to (5, DIGIT, 6); to (6, ZERO, 6); to (6, DIGIT, 6); to (6, EXP, 7); to (6, MATCH, 2); to (7, PLUS, 8); to (7, MINUS, 8); to (7, ZERO, 9); to (7, DIGIT, 9); to (8, ZERO, 9); to (8, DIGIT, 9); to (9, ZERO, 9); to (9, DIGIT, 9); to (9, MATCH, 2); } toml_number_type& define () { if (defined) return *this; defined = true; define_charset (); define_state (); squarize_table (); pack_table (base, check); return *this; } std::string render (std::string const& layout) { std::string s = render_int (layout, "@<ncclass@>", cclass.size () / 8); s = render_int (s, "@<nlookup@>", cclass.size ()); s = render_int (s, "@<nbase@>", base.size ()); s = render_int (s, "@<ncheck@>", check.size ()); s = render_cclass (s, "@<cclass@>\n", cclass); s = render_vector_dec (s, "@<base@>\n", base); s = render_vector_hex (s, "@<check@>\n", check); s = render_int (s, "@<match@>", MATCH); return std::move (s); } }; std::string const layout (R"EOS( int json_decoder_type::scan_number (value_type& value) { enum { NSHIFT = @<ncheck@> }; static const uint32_t CCLASS[@<ncclass@>] = { @<cclass@> }; static const int BASE[@<nbase@>] = { @<base@> }; static const int SHIFT[NSHIFT] = { @<check@> }; static const uint32_t MATCH = @<match@>U; int kind = TOKEN_INVALID; std::wstring literal; std::string::const_iterator s = iter; std::string::const_iterator const e = string.cend (); for (int next_state = 1; s <= e; ++s) { uint32_t octet = s == e ? '\0' : ord (*s); int const cls = s == e ? 0 : lookup_cls (CCLASS, @<nlookup@>U, octet); int const prev_state = next_state; next_state = 0; int const j = BASE[prev_state] + cls; int const m = BASE[prev_state] + MATCH; if (0 < j && j < NSHIFT && (SHIFT[j] & 0xff) == prev_state) next_state = (SHIFT[j] >> 8) & 0xff; if (next_state && s < e) literal.push_back (octet); if (0 < m && m < NSHIFT && (SHIFT[m] & 0xff) == prev_state) { int isfixnum = 1 == ((SHIFT[m] >> 8) & 0xff); if (isfixnum) try { value = ::wjson::fixnum (std::stoll (literal)); } catch (std::out_of_range) { isfixnum = false; } if (! isfixnum) try { value = ::wjson::flonum (std::stod (literal)); } catch (std::out_of_range) { value = ::wjson::null (); return TOKEN_INVALID; } kind = TOKEN_SCALAR; iter = s; } if (! next_state) break; } return kind; } )EOS" ); int main () { toml_number_type number; std::cout << number.define ().render (layout); return EXIT_SUCCESS; }
26.122222
86
0.461293
[ "render", "vector" ]
3247cd7cfcf68d572c4491617d7d4a1a5652c1db
1,171
cpp
C++
cpp/random_codes.cpp
simnalamburt/snippets
8ba4cfcb1305d2b82ea892e3305613eeb7ba382b
[ "ECL-2.0", "Apache-2.0", "MIT-0", "MIT" ]
31
2016-01-27T07:03:25.000Z
2022-02-25T07:59:11.000Z
cpp/random_codes.cpp
simnalamburt/snippets
8ba4cfcb1305d2b82ea892e3305613eeb7ba382b
[ "ECL-2.0", "Apache-2.0", "MIT-0", "MIT" ]
1
2015-01-26T01:27:21.000Z
2015-01-30T16:16:30.000Z
cpp/random_codes.cpp
simnalamburt/snippets
8ba4cfcb1305d2b82ea892e3305613eeb7ba382b
[ "ECL-2.0", "Apache-2.0", "MIT-0", "MIT" ]
3
2017-02-07T04:17:56.000Z
2020-06-12T05:01:31.000Z
// C++11 #include <unordered_set> #include <vector> #include <random> #include <string> #include <iostream> constexpr int64_t ipow(int64_t base, int exp, int64_t result = 1) { return exp < 1 ? result : ipow(base*base, exp/2, (exp % 2) ? result*base : result); } int main() { using namespace std; constexpr size_t desired_count = 1000000; constexpr size_t code_digit_count = 6; constexpr size_t upper_bound = ipow(16, code_digit_count); random_device device; default_random_engine gen(device()); uniform_int_distribution<uint32_t> dist(0, upper_bound - 1); // [0, upper_bound - 1] unordered_set<uint32_t> selected; for (size_t i = 0; i < desired_count; ++i) { uint32_t int_code; do { int_code = dist(gen); } while (selected.find(int_code) != selected.cend()); selected.insert(int_code); } vector<string> codes; codes.reserve(desired_count); for (const auto int_code : selected) { char buffer[7]; sprintf(buffer, "%06x", int_code); codes.emplace_back(buffer); } for (const auto code : codes) { cout << code << '\n'; } }
25.456522
88
0.627669
[ "vector" ]
325c8d5a04c7b1e9ce2b98d608270a11c41d93d0
2,421
cpp
C++
src/RA_md5factory.cpp
Jamiras/RAIntegration
ccf3dea24d81aefdcf51535f073889d03272b259
[ "MIT" ]
71
2018-04-15T13:02:43.000Z
2022-03-26T11:19:18.000Z
src/RA_md5factory.cpp
Jamiras/RAIntegration
ccf3dea24d81aefdcf51535f073889d03272b259
[ "MIT" ]
309
2018-04-15T12:10:59.000Z
2022-01-22T20:13:04.000Z
src/RA_md5factory.cpp
Jamiras/RAIntegration
ccf3dea24d81aefdcf51535f073889d03272b259
[ "MIT" ]
17
2018-04-17T16:09:31.000Z
2022-03-04T08:49:03.000Z
#include "RA_md5factory.h" #include "RA_Defs.h" #include "services\IFileSystem.hh" #include "services\ServiceLocator.hh" #include <rcheevos/src/rhash/md5.h> namespace { constexpr static unsigned int MD5_STRING_LEN = 32; } std::string RAFormatMD5(const BYTE* digest) { char buffer[33] = ""; Expects(digest != nullptr); sprintf_s(buffer, MD5_STRING_LEN + 1, "%02x%02x%02x%02x%02x%02x%02x%02x" "%02x%02x%02x%02x%02x%02x%02x%02x", digest[0], digest[1], digest[2], digest[3], digest[4], digest[5], digest[6], digest[7], digest[8], digest[9], digest[10], digest[11], digest[12], digest[13], digest[14], digest[15]); return std::string(buffer, 32); } std::string RAGenerateMD5(const std::string& sStringToMD5) { md5_state_t pms{}; md5_byte_t digest[16]{}; static_assert(sizeof(md5_byte_t) == sizeof(char), "Must be equivalent for the MD5 to work!"); const md5_byte_t* bytes; GSL_SUPPRESS_TYPE1 bytes = reinterpret_cast<const md5_byte_t*>(sStringToMD5.c_str()); md5_init(&pms); md5_append(&pms, bytes, gsl::narrow_cast<int>(sStringToMD5.length())); md5_finish(&pms, digest); return RAFormatMD5(digest); } std::string RAGenerateMD5(const BYTE* pRawData, size_t nDataLen) { md5_state_t pms; md5_byte_t digest[16]; static_assert(sizeof(md5_byte_t) == sizeof(BYTE), "Must be equivalent for the MD5 to work!"); md5_init(&pms); md5_append(&pms, pRawData, gsl::narrow_cast<int>(nDataLen)); md5_finish(&pms, digest); return RAFormatMD5(digest); } std::string RAGenerateMD5(const std::vector<BYTE> DataIn) { return RAGenerateMD5(DataIn.data(), DataIn.size()); } std::string RAGenerateFileMD5(const std::wstring& sPath) { md5_state_t pms{}; md5_byte_t digest[16]{}; md5_byte_t bytes[4096]{}; static_assert(sizeof(md5_byte_t) == sizeof(uint8_t), "Must be equivalent for the MD5 to work!"); auto& pFileSystem = ra::services::ServiceLocator::Get<ra::services::IFileSystem>(); auto pFile = pFileSystem.OpenTextFile(sPath); if (pFile == nullptr) return ""; md5_init(&pms); do { size_t nBytes = pFile->GetBytes(static_cast<uint8_t*>(bytes), sizeof(bytes)); if (nBytes == 0) break; md5_append(&pms, bytes, gsl::narrow_cast<int>(nBytes)); } while (true); md5_finish(&pms, digest); return RAFormatMD5(digest); }
26.604396
102
0.666254
[ "vector" ]
325cef79de4304edccd910f2b9fb06168b86e4f6
5,622
cxx
C++
PWGLF/RESONANCES/AliRsnCutDelta.cxx
maroozm/AliPhysics
22ec256928cfdf8f800e05bfc1a6e124d90b6eaf
[ "BSD-3-Clause" ]
114
2017-03-03T09:12:23.000Z
2022-03-03T20:29:42.000Z
PWGLF/RESONANCES/AliRsnCutDelta.cxx
maroozm/AliPhysics
22ec256928cfdf8f800e05bfc1a6e124d90b6eaf
[ "BSD-3-Clause" ]
19,637
2017-01-16T12:34:41.000Z
2022-03-31T22:02:40.000Z
PWGLF/RESONANCES/AliRsnCutDelta.cxx
maroozm/AliPhysics
22ec256928cfdf8f800e05bfc1a6e124d90b6eaf
[ "BSD-3-Clause" ]
1,021
2016-07-14T22:41:16.000Z
2022-03-31T05:15:51.000Z
// // This cut implements all the checks done to accept a track as a proton or pion // for the pPb analysis using 2013 runs. // It is based on standard cuts on track quality and nsigma cuts // with respect to the TPC and TOF signals for the PID. // #include <Riostream.h> #include "AliPID.h" #include "AliPIDResponse.h" #include "AliRsnCutDelta.h" ClassImp(AliRsnCutDelta) //__________________________________________________________________________________________________ AliRsnCutDelta::AliRsnCutDelta(const char *name,AliPID::EParticleType pid, Bool_t TPCMethod, Bool_t usePPb) : AliRsnCut(name, AliRsnTarget::kDaughter), fPID(pid), fNSigmaTPC(3.0), fLimitTPC(0.350), fNSigmaTOF(3.0), fTPCMethod(TPCMethod), fNSigmaTPCProton(3.0), fNSigmaTPCPion(3.0), fNSigmaTOFProton(3.0), fNSigmaTOFPion(3.0), fTPCMomProton(1.1), fTOFMomProton(2.5), fEtaRange(0.8), fTPCNCluster(70), fPtDepDCASigma(1.0), fCutQuality(Form("%sQuality", name)) { // // Constructor // Initialize the contained cuts and sets defaults // if(usePPb) { Double_t a=0; a=fPtDepDCASigma*0.0105; Double_t b=0; b=fPtDepDCASigma*0.0350; // track quality fCutQuality.SetPtRange(0.15, 1E+20); fCutQuality.SetEtaRange(-fEtaRange, fEtaRange); fCutQuality.SetDCARPtFormula(Form("%f+%f/pt^1.1",a,b)); fCutQuality.SetDCAZmax(2.0); fCutQuality.SetSPDminNClusters(1); fCutQuality.SetMinNCrossedRowsTPC(70, kTRUE); fCutQuality.SetMinNCrossedRowsOverFindableClsTPC(0.8, kTRUE); fCutQuality.SetMaxChi2TPCConstrainedGlobal(36); fCutQuality.SetTPCmaxChi2(4.0); fCutQuality.SetRejectKinkDaughters(); fCutQuality.SetAODTestFilterBit(5); } else { Double_t a=0; a=fPtDepDCASigma*0.0026*7; Double_t b=0; b=fPtDepDCASigma*0.05*7; // track quality fCutQuality.SetPtRange(0.15, 1E+20); fCutQuality.SetEtaRange(-fEtaRange, fEtaRange); fCutQuality.SetDCARPtFormula(Form("%f+%f/pt^1.01",a,b)); //("0.0182+0.0350/pt^1.01"); fCutQuality.SetDCAZmax(2.0); fCutQuality.SetSPDminNClusters(1); fCutQuality.SetITSminNClusters(0); fCutQuality.SetITSmaxChi2(1E+20); fCutQuality.SetTPCminNClusters(fTPCNCluster); fCutQuality.SetTPCmaxChi2(4.0); fCutQuality.SetRejectKinkDaughters(); fCutQuality.SetAODTestFilterBit(5); } } // //__________________________________________________________________________________________________ Bool_t AliRsnCutDelta::IsSelected(TObject *obj) { // // Global check // // coherence check if (!TargetOK(obj)) return kFALSE; // check track AliVTrack *track = fDaughter->Ref2Vtrack(); if (!track) { if (!fDaughter->GetRef()) AliWarning("NULL ref"); return kFALSE; } // check flags if ((track->GetStatus() & AliESDtrack::kTPCin ) == 0) return kFALSE; if ((track->GetStatus() & AliESDtrack::kTPCrefit) == 0) return kFALSE; if ((track->GetStatus() & AliESDtrack::kITSrefit) == 0) return kFALSE; // quality if (!fCutQuality.IsSelected(obj)) return kFALSE; // check initialization of PID object AliPIDResponse *pid = fEvent->GetPIDResponse(); if (!pid) { AliFatal("NULL PID response"); return kFALSE; } // check if TOF is matched // and computes all values used in the PID cut Bool_t isTOF = MatchTOF(track); Double_t pTPC = track->GetTPCmomentum(); Double_t pTOF = track->P(); Double_t nsTPC = TMath::Abs(pid->NumberOfSigmasTPC(track, fPID)); Double_t nsTPCProton = TMath::Abs(pid->NumberOfSigmasTPC(track, AliPID::kProton)); Double_t nsTPCPion = TMath::Abs(pid->NumberOfSigmasTPC(track, AliPID::kPion)); Double_t nsTOFProton = TMath::Abs(pid->NumberOfSigmasTOF(track, AliPID::kProton)); Double_t nsTOF = TMath::Abs(pid->NumberOfSigmasTOF(track, fPID)); Double_t maxTPC = 1E20; Double_t maxTOF = 1E20; if (fTPCMethod) { if(fPID == AliPID::kPion) { if(nsTPCPion>fNSigmaTPCPion) return kFALSE; maxTPC = fNSigmaTPCPion; if(nsTPC > maxTPC) return kFALSE; return kTRUE; } else if (fPID == AliPID::kProton) { if(nsTPCPion<=fNSigmaTPCPion) return kFALSE; if(pTPC>=fTPCMomProton) return kFALSE; if(nsTPCProton>fNSigmaTPCProton) return kFALSE; maxTPC = fNSigmaTPCProton; if(nsTPC > maxTPC) return kFALSE; return kTRUE; } } else { if(fPID == AliPID::kProton) { if(!isTOF) return kFALSE; if(nsTPCProton>fNSigmaTPCProton) return kFALSE; if(pTOF >= fTOFMomProton) return kFALSE; if(nsTOFProton>fNSigmaTOFProton) return kFALSE; maxTOF = fNSigmaTOFProton; if (nsTOF > maxTOF) return kFALSE; return kTRUE; } else if (fPID == AliPID::kPion) { if(isTOF && nsTPCProton<=fNSigmaTPCProton && pTOF < fTOFMomProton && nsTOFProton<=fNSigmaTOFProton) return kFALSE; if(nsTPCPion>fNSigmaTPCPion) return kFALSE; maxTPC = fNSigmaTPCPion; if (nsTPC > maxTPC) return kFALSE; return kTRUE; }//pion pid } //else tpcmethod return kTRUE; } //__________________________________________________________________________________________________ Bool_t AliRsnCutDelta::MatchTOF(const AliVTrack *vtrack) { // // Checks if the track has matched the TOF detector // if (!vtrack) { AliWarning("NULL argument: impossible to check status"); return kFALSE; } Bool_t isTOFout = ((vtrack->GetStatus() & AliESDtrack::kTOFout) != 0); Bool_t isTIME = ((vtrack->GetStatus() & AliESDtrack::kTIME) != 0); return (isTOFout && isTIME); }
30.064171
121
0.686055
[ "object" ]
325d8a30af0286c4f4772c6db786ac5d1eebe00e
3,863
hpp
C++
model.hpp
yang-zzhong/sql-builder
6fbf1c5435698a4c5c67e8e24ad271964473b827
[ "MIT" ]
null
null
null
model.hpp
yang-zzhong/sql-builder
6fbf1c5435698a4c5c67e8e24ad271964473b827
[ "MIT" ]
null
null
null
model.hpp
yang-zzhong/sql-builder
6fbf1c5435698a4c5c67e8e24ad271964473b827
[ "MIT" ]
1
2019-12-24T18:30:54.000Z
2019-12-24T18:30:54.000Z
#pragma once #include "adapter.hpp" #include "col.hpp" #include <memory> #include <vector> #include <functional> namespace boosql { class model { public: const std::string & table_name() { return _table_name; } model() { _adapter = new sqlite_adapter(); _auto_delete_adapter = true; } model(const model & m) { _adapter = m._adapter->clone(); _auto_delete_adapter = true; _table_name = m._table_name; _where_condition = m._where_condition; } model(adapter * adapter) : _adapter(adapter) {} model(adapter * adapter, const std::string & table_name) : _adapter(adapter), _table_name(table_name) { } model(const std::string & table_name) { _adapter = new sqlite_adapter(); _auto_delete_adapter = true; _table_name = table_name; } virtual std::string where_str() { std::string ret; for(auto i = _where_condition.begin(); i != _where_condition.end(); ++i) { ret.append((*i).str(_adapter, table_name())); } return ret; } virtual std::string where_str(std::vector<std::string> & params) { std::string ret; for(auto i = _where_condition.begin(); i != _where_condition.end(); ++i) { ret.append((*i).str(_adapter, table_name(), params)); } return ret; } virtual ~model() { if (_auto_delete_adapter) { delete _adapter; } } virtual const std::string& str() = 0; virtual const std::string& str(std::vector<std::string> &) = 0; protected: void append_where() { std::string w = where_str(); if (w.length() > 0) { _sql.append( " WHERE " ); _sql.append(w); } } void append_where(std::vector<std::string> & params) { std::string w = where_str(params); if (w.length() > 0) { _sql.append( " WHERE " ); _sql.append(w); } } void and_where(const std::string & condition) { _where_condition.push_back(col().o_and()); _where_condition.push_back(col()(condition)); } void and_where(const col & condition) { _where_condition.push_back(col().o_and()); _where_condition.push_back(condition); } void or_where(const std::string & condition) { _where_condition.push_back(col().o_or()); _where_condition.push_back(col()(condition)); } void or_where(const col & condition) { _where_condition.push_back(col().o_or()); _where_condition.push_back(condition); } template <class T> void quote(std::function<void(T& model)> callback, T& model) { if (_where_condition.size() > 0) { _where_condition.push_back(col().o_and()); } _where_condition.push_back(col().quote_begin()); callback(model); _where_condition.push_back(col().quote_end()); } void where(const std::string& condition) { if (_where_condition.size() > 0) { _where_condition.push_back(col().o_and()); } _where_condition.push_back(col()(condition)); } void where(const col& condition) { int s = _where_condition.size(); if (s > 0) { col last = _where_condition.back(); if (!last.empty() && last.last().val != "(") { _where_condition.push_back(col().o_and()); } } _where_condition.push_back(condition); } void reset() { _table_name.clear(); _where_condition.clear(); } protected: std::string _sql; adapter * _adapter; bool _auto_delete_adapter = false; std::string _table_name; private: std::vector<col> _where_condition; }; }
23.412121
82
0.56614
[ "vector", "model" ]
325ebc83fd8955afa6e873522ae72ab3820f1981
1,718
hpp
C++
include/Thread/Thread.hpp
saanj1/Thread
125aed7776913edafe1f614abaa124e75852d0b4
[ "MIT" ]
1
2020-09-30T06:28:28.000Z
2020-09-30T06:28:28.000Z
include/Thread/Thread.hpp
saanj1/Thread
125aed7776913edafe1f614abaa124e75852d0b4
[ "MIT" ]
null
null
null
include/Thread/Thread.hpp
saanj1/Thread
125aed7776913edafe1f614abaa124e75852d0b4
[ "MIT" ]
null
null
null
#pragma once /** * @file Thread.hpp * @author Sanjeev Kumar M * @date 28/09/2020 12::00 * * This module defines Thread::Thread class */ #include <signal.h> namespace Thread { enum class ThreadStatus : uint8_t { Ok, Failed, AlreadyStarted, }; class Thread { public: //Life cycle management ~Thread() { if (_m_thread_id != -1) { pthread_kill(_m_thread_id, SIGUSR1); } } Thread(const Thread&) noexcept = delete; Thread(Thread&&) noexcept = delete; Thread& operator=(const Thread&) = delete; Thread& operator=(Thread&&) = delete; public: //This is the constructor Thread() : _m_thread_id(-1) {} /** * This function used to start the thread execution */ ThreadStatus run() { if (_m_thread_id != -1) return ThreadStatus::AlreadyStarted; if (pthread_create(&_m_thread_id, nullptr, &start_thread, this) == -1) return ThreadStatus::Failed; return ThreadStatus::Ok; } protected: /** * The function must be implemented by the child classes * the main thread execution code goes in this function */ virtual void thread_main() = 0; /** * This function is used to stop the thread * execution */ private: /** * This function actually calls the thread_main * function on the calling object * * @param[in] * __thread_addr - address of the calling object */ static void* start_thread(void* __thread_addr) { static_cast<Thread*>(__thread_addr)->thread_main(); } /** * This holds the if of the created * pthread */ pthread_t _m_thread_id; }; }
22.025641
66
0.600116
[ "object" ]
3260405e30841b7c5c6a4d43c60b8908939294ad
2,872
hpp
C++
numerical-methods-2_iterative-methods/relaxation_method.hpp
DmitriBogdanov/numerical-methods-2_iterative-methods
3a557b00feffa3eff306d444ec2e81feed74d324
[ "MIT" ]
null
null
null
numerical-methods-2_iterative-methods/relaxation_method.hpp
DmitriBogdanov/numerical-methods-2_iterative-methods
3a557b00feffa3eff306d444ec2e81feed74d324
[ "MIT" ]
null
null
null
numerical-methods-2_iterative-methods/relaxation_method.hpp
DmitriBogdanov/numerical-methods-2_iterative-methods
3a557b00feffa3eff306d444ec2e81feed74d324
[ "MIT" ]
null
null
null
#pragma once #include <tuple> // returning multiple variables #include "cmatrix.hpp" #include "math_helpers.hpp" // @return 1 => aproximate solution // @return 2 => number of iterations inline std::tuple<DMatrix, unsigned int> relaxation_method(const DMatrix &Diagonals, const DMatrix &b, double w, StopCondition stopCond) { const auto N = Diagonals.rows(); // Find ||C|| and ||CU|| through C[i][j] = -A[i][j] / A[i][i] and C[i][i] = 0 double normC = 0.; double normCU = 0.; for (size_t i = 0; i < N; ++i) { // Abuse the fact that matrix is tridiagonal double sumC = std::abs(Diagonals[i][0]) + std::abs(Diagonals[i][2]); double sumCU = std::abs(Diagonals[i][2]); normC = std::max(normC, sumC / Diagonals[i][1]); normCU = std::max(normCU, sumCU / Diagonals[i][1]); } std::cout << ">>> ||C|| = " << normC << "]\n"; std::cout << ">>> ||CU|| = " << normCU << "]\n"; // Finally, iteration DMatrix X(N, 1); // current X estimate DMatrix X0(N, 1); // previous X estimate size_t iterations = 0; fill(X0, 0.); // first estimate is zero-vector DMatrix buffer(N, 1); bool flag = false; // true => stop iteration //double minerr = INF; // Handle stop condition switch (stopCond.type) { case StopConditionType::MAX_ESTIMATE: stopCond.max_iterations = std::ceil(max_iteration_estimate(stopCond.epsilon, normC, vector_difference_norm(X0, *stopCond.precise_solution))); break; case StopConditionType::MIN_ESTIMATE: break; case StopConditionType::DEFAULT: stopCond.epsilon = stopCond.epsilon * (1. - normC) / normC; break; default: throw std::runtime_error("ERROR: Unknown stop condition"); } do { ++iterations; // Compute new X for (size_t i = 0; i < N; ++i) { // Compute X[i] = (1 - w) X0[i] + w / A[i][i] ( b[i] - SUM_0<=j<i { A[i][j] X[j] } - SUM_i+1<=j<N { A[i][j] X0[j] } ) double sum1 = (i > 0) ? Diagonals[i][0] * X(i - 1) : 0.; double sum2 = (i < N - 1) ? Diagonals[i][2] * X0(i + 1) : 0.; // checks 'i' so we don't go out of bounds X(i) = (1. - w) * X0(i) + (b(i) - sum1 - sum2) * w / Diagonals[i][1]; } // Handle stop condition switch (stopCond.type) { case StopConditionType::MAX_ESTIMATE: flag = false; break; case StopConditionType::MIN_ESTIMATE: flag = (vector_difference_norm(X, *stopCond.precise_solution) < stopCond.epsilon); /*if (vector_difference_norm(X, X0) < minerr) { minerr = vector_difference_norm(X, X0); std::cout << "[" << iterations << "] -> " << vector_difference_norm(X, *stopCond.precise_solution) << '\n'; }*/ break; case StopConditionType::DEFAULT: flag = (vector_difference_norm(X, X0) < stopCond.epsilon); break; default: throw std::runtime_error("ERROR: Unknown stop condition"); } // Now X becomes X0 X0 = X; } while (!flag && iterations < stopCond.max_iterations); return { X, iterations }; }
28.435644
143
0.626741
[ "vector" ]
32659f3bb19278026a8acaf5d7788e81fbb5dfac
4,019
cpp
C++
catkin_ws/src/ball_chaser/src/process_image.cpp
milan-r-shah/RoboND_Map_My_World
45d7fd7be19d3cf1d47a3e52f6cf0ac7b9cbf1d8
[ "MIT" ]
null
null
null
catkin_ws/src/ball_chaser/src/process_image.cpp
milan-r-shah/RoboND_Map_My_World
45d7fd7be19d3cf1d47a3e52f6cf0ac7b9cbf1d8
[ "MIT" ]
null
null
null
catkin_ws/src/ball_chaser/src/process_image.cpp
milan-r-shah/RoboND_Map_My_World
45d7fd7be19d3cf1d47a3e52f6cf0ac7b9cbf1d8
[ "MIT" ]
null
null
null
#include "ros/ros.h" #include "ball_chaser/DriveToTarget.h" #include <sensor_msgs/Image.h> // Define a global client that can request services ros::ServiceClient client; // This function calls the command_robot service to drive the robot in the specified direction void drive_robot(float lin_x, float ang_z) { // Request a service and pass the velocities to it to drive the robot ball_chaser::DriveToTarget srv; srv.request.linear_x = lin_x; srv.request.angular_z = ang_z; client.call(srv); } // This callback function continuously executes and reads the image data void process_image_callback(const sensor_msgs::Image img) { int white_pixel = 255; // Loop through each pixel in the image and check if there's a bright white one // Then, identify if this pixel falls in the left, mid, or right side of the image // Depending on the white ball position, call the drive_bot function and pass velocities to it // Request a stop when there's no white ball seen by the camera // Number of white pixels in the left, middle, and right part of the image, respectively int left_white_pixel_cnt = 0; int middle_white_pixel_cnt = 0; int right_white_pixel_cnt = 0; for(int h=0; h<img.height; h++) { // In 'sensor_msgs/image', data is arranged in a 1D vector whereby one pixel is represented by three consecutive bytes (uint8) comprising // the RED, BLUE, and GREEN color information. // So, in each iteration, I'm checking three consecutive pixels/bytes for(int s=0; s<img.step; s+=3) { if((img.data[img.step*h + s] == white_pixel) && (img.data[img.step*h + s + 1] == white_pixel) && (img.data[img.step*h+ s + 2] == white_pixel)) { // Dividing the image width or to be precise its 'step' into three parts by 30% left, next 40% into middle, & remaining 30% into right // Left part of an image if(s < 0.3*img.step) { left_white_pixel_cnt++; } // Middle part of an image else if(s >= 0.3*img.step && s < 0.7*img.step) { middle_white_pixel_cnt++; } // Right part of an image else { right_white_pixel_cnt++; } } } } // First, check if there is a white ball in the image or not // If not then stop if((left_white_pixel_cnt == 0) && (middle_white_pixel_cnt == 0) && (right_white_pixel_cnt == 0)) { drive_robot(0.0, 0.0); } // if it is then check it's in which part of the image else { // If the white ball is in the left side of the image, turn right if((left_white_pixel_cnt > right_white_pixel_cnt) && (left_white_pixel_cnt > middle_white_pixel_cnt)) { drive_robot(0.3, 0.3); } // If the white ball is in the middle part of the image, go straight else if((middle_white_pixel_cnt > left_white_pixel_cnt) && (middle_white_pixel_cnt > right_white_pixel_cnt)) { drive_robot(0.3, 0.0); } // If the white ball is in the right side of the image, turn right else { drive_robot(0.3, -0.3); } } } int main(int argc, char** argv) { // Initialize the process_image node and create a handle to it ros::init(argc, argv, "process_image"); ros::NodeHandle n; // Define a client service capable of requesting services from command_robot client = n.serviceClient<ball_chaser::DriveToTarget>("/ball_chaser/command_robot"); // Subscribe to /camera/rgb/image_raw topic to read the image data inside the process_image_callback function ros::Subscriber sub1 = n.subscribe("/camera/rgb/image_raw", 10, process_image_callback); // Handle ROS communication events ros::spin(); return 0; }
36.87156
154
0.618064
[ "vector" ]
3268298e90e4f73e469964bafa4d39ece3bb01c2
53,980
cpp
C++
client/v6client.cpp
Abhayakara/dhcpng
b2499071ce5dbf36de5bf88ba9eb54047319dbd3
[ "MIT" ]
null
null
null
client/v6client.cpp
Abhayakara/dhcpng
b2499071ce5dbf36de5bf88ba9eb54047319dbd3
[ "MIT" ]
null
null
null
client/v6client.cpp
Abhayakara/dhcpng
b2499071ce5dbf36de5bf88ba9eb54047319dbd3
[ "MIT" ]
null
null
null
/* v6client.cpp * * DHCPv6 protocol engine class. */ /* Copyright (c) 2005-2006 Nominum, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of Nominum 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 NOMINUM 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 NOMINUM OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef lint static char ocopyright[] __attribute__((unused)) = "$Id: v6client.cpp,v 1.22 2012/04/01 21:26:34 mellon Exp $ Copyright (c) 2005-2006 Nominum, Inc. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" #include "version.h" #include "client/v6client.h" #include "client/controller.h" #include "client/client.h" /* This is so that we can do option_space_encapsulate without consing up * a special data string every time. */ static struct data_string dhcpv6 = { 0, (const unsigned char *)"dhcpv6", 6, 1 }; DHCPv6Client::DHCPv6Client(struct interface_info *ip, DHCPClientController *ctlr, u_int8_t *duid_string, int duid_size) { config = ((struct client_config *)safemalloc(sizeof (struct client_config))); memcpy(config, &top_level_config, sizeof top_level_config); config->interface = ip; duid = (duid_t *)safemalloc(duid_size + sizeof (u_int32_t)); duid->len = duid_size; memcpy((char *)&duid->data, duid_string, duid_size); log_info("DHCPv6 Client DUID is %s", print_hex_1(duid->len, (unsigned char *)&duid->data, 80)); xid = random(); state = S6_UNMANAGED; next_state = S6_UNMANAGED; retransmit_count = 0; ias = (struct ia *)safemalloc(sizeof (struct ia)); memset(ias, 0, sizeof *ias); ias->id = htonl(ip->index); controller = ctlr; responses = selected_response = 0; server_identifier = 0; send_options = 0; recv_options = 0; sending_name = 0; relay_destination.len = 0; } int DHCPv6Client::set_relay_destination(char *dest) { struct in6_addr in6; if (!inet_pton(AF_INET6, dest, &in6)) { printf("bad destination: %s\n", dest); return 0; } printf("Destination %s: ", dest); fflush(stdout); dump_raw(destination.iabuf, 16); dump_raw((const unsigned char *)&in6, sizeof in6); memcpy(relay_destination.iabuf, &in6, 16); relay_destination.len = 16; return 1; } bool DHCPv6Client::mine(struct dhcpv6_response *rsp) { /* Check for a DUID match. If it matches, the packet is * for this client object. */ struct option_cache *oc = lookup_option(&dhcpv6_option_space, rsp->options, DHCPV6_DUID); /* Get the DUID option. */ if (!oc) { log_info("Dropping %s: no DUID", rsp->name); return 0; } if (duid->len != oc->data.len || memcmp(&duid->data, oc->data.data, oc->data.len)) return 0; return 1; } void DHCPv6Client::state_startup() { /* Start up after about five tenths of a second, and then try the * S6_SOLICITING or S6_INFORM states. */ if (config->interface->v6configured) addTimeout(cur_time + (random() % 5000000) * 1000ULL, S6_INFORM); else if (config->interface->ipv6_addr_count > 0) addTimeout(cur_time + (random() % 5000000) * 1000ULL, S6_SOLICITING); else { log_info("Can't do DHCPv6 on a non-IPv6 network."); state_unmanaged(); } next_state_time = 0; } void DHCPv6Client::state_confirm() { /* Make a DHCP Solicit packet, and set appropriate per-interface flags. */ state = S6_CONFIRMING; make_client_options(0); if (relay_destination.len == 16) destination = relay_destination; else destination = iaddr_all_agents_and_servers; first_sending = cur_time; sending = DHCPV6_CONFIRM; sending_name = "DHCP Confirm"; next_state_time = 0; next_state = S6_CONFIRMING; xid = random() & 0xFFFFFF; next_state_time = 0; /* Send the initial solicit. */ send_normal_packet(); } /* Called when a lease has completely expired and we've been unable to renew it, or when we're first starting up. */ void DHCPv6Client::state_soliciting() { /* Make a DHCP Solicit packet, and set appropriate per-interface flags. */ state = S6_SOLICITING; make_client_options(0); if (relay_destination.len == 16) destination = relay_destination; else destination = iaddr_all_agents_and_servers; first_sending = cur_time; sending = DHCPV6_SOLICIT; sending_name = "DHCP Solicit"; next_state_time = 0; next_state = S6_SOLICITING; xid = random() & 0xFFFFFF; next_state_time = 0; /* Send the initial solicit. */ send_normal_packet(); } /* Called when a lease has completely expired and we've been unable to renew it, or when we're first starting up. */ void DHCPv6Client::state_rapid() { /* Make a DHCP Solicit packet, and set appropriate per-interface flags. Include a rapid commit option. */ state = S6_RAPID; make_client_options(0); if (relay_destination.len == 16) destination = relay_destination; else destination = iaddr_all_agents_and_servers; first_sending = cur_time; sending = DHCPV6_SOLICIT; sending_name = "DHCP Solicit"; next_state_time = 0; next_state = S6_RAPID; xid = random() & 0xFFFFFF; next_state_time = 0; /* Send the initial solicit. */ send_normal_packet(); } /* Called when a lease has completely expired and we've been unable to renew it, or when we're first starting up. */ void DHCPv6Client::state_release() { /* Make a DHCP Solicit packet, and set appropriate per-interface flags. Include a rapid commit option. */ state = S6_RELEASING; make_client_options(server_identifier); if (relay_destination.len == 16) destination = relay_destination; else destination = iaddr_all_agents_and_servers; first_sending = cur_time; sending = DHCPV6_RELEASE; sending_name = "DHCP Release"; next_state_time = 0; next_state = S6_UNMANAGED; xid = random() & 0xFFFFFF; next_state_time = 0; retransmit_count = 3; /* Send the initial solicit. */ send_normal_packet(); } /* Called when we are just doing an information request. */ void DHCPv6Client::state_inform() { /* Make a DHCP Solicit packet, and set appropriate per-interface flags. */ state = S6_INFORM; make_client_options(0); xid = random(); if (relay_destination.len == 16) destination = relay_destination; else destination = iaddr_all_agents_and_servers; first_sending = cur_time; sending = DHCPV6_INFORMATION_REQUEST; sending_name = "DHCP Information Request"; next_state_time = 0; next_state = S6_INFORM; xid = random() & 0xFFFFFF; next_state_time = 0; /* Send the initial solicit. */ send_normal_packet(); } /* Send out a DHCPDISCOVER packet, and set a timeout to send out another one after the right interval has expired. If we don't get an offer by the time we reach the panic interval, call the panic function. */ void DHCPv6Client::send_normal_packet() { struct option *opt; struct option_cache *oc; struct buffer *bp; int elapsed; struct data_string packet; ssize_t result; struct sockaddr_in6 dest; char addrbuf[128]; int caplen_offset = -1; memset(&dest, 0, sizeof dest); dest.sin6_family = AF_INET6; dest.sin6_port = remote_port_dhcpv6; #ifdef HAVE_SA_LEN dest.sin6_len = sizeof dest; #endif memcpy(&dest.sin6_addr, destination.iabuf, 16); /* Figure out the next interval. If it's currently zero (i.e., we * haven't sent any packets yet), set it to the preconfigured * initial interval; otherwise, add to it a random number between * zero and two times itself. On average, this means that it will * double with every transmission. */ if (!interval) interval = config->initial + ((random () >> 2) % (2 * config->initial)); else interval += ((random () >> 2) % (2 * interval)); /* Don't backoff past cutoff. */ if (interval > config->cutoff) interval = ((config->cutoff / 2) + ((random () >> 2) % config->cutoff)); /* Record the number of seconds since we started sending; max it out * at 2^16-1. */ delete_option(&dhcpv6_option_space, send_options, DHCPV6_ELAPSED_TIME); /* Elapsed time is specified in hundredths of a second. */ elapsed = (cur_time - first_sending) / (1000000000ULL / 100); if (elapsed > 65535) elapsed = 65535; bp = buffer_allocate(2); putUShort(bp->data, elapsed); opt = find_option(&dhcpv6_option_space, DHCPV6_ELAPSED_TIME); oc = make_const_option_cache(&bp, 0, 2, opt); save_option(&dhcpv6_option_space, send_options, oc); /* Start out with a 200 byte buffer; the option encapsulation code * will expand it as needed. */ memset(&packet, 0, sizeof packet); packet.buffer = buffer_allocate(200); packet.data = packet.buffer->data; packet.len = 0; /* If we are faking up a relay header, do it now. */ if (relay_destination.len == 16) { packet.buffer->data[0] = DHCPV6_RELAY_FORWARD; packet.len++; packet.buffer->data[1] = 0; /* hop count */ packet.len++; memcpy(&packet.buffer->data[packet.len], config->interface->ipv6s, sizeof (struct in6_addr)); packet.len += 16; memcpy(&packet.buffer->data[packet.len], config->interface->ipv6s, sizeof (struct in6_addr)); packet.len += 16; putUShort(&packet.buffer->data[packet.len], DHCPV6_RELAY_MESSAGE); packet.len += 2; caplen_offset = packet.len; putUShort(&packet.buffer->data[packet.len], 0); packet.len += 2; } /* The DHCPv6 message header consists of a single byte of message * type, followed by three bytes of transaction ID in sort-of * network byte order. There's no pretty way to do this, but we * can at least take advantage of the fact that the MSB of a 32-bit * integer stored in network byte order corresponds to the first * byte, so what we do is to encode the transaction ID as a 32-bit * number, and then overwrite the MSB with the type code. */ putULong(&packet.buffer->data[packet.len], xid); packet.buffer->data[packet.len] = sending; packet.len = packet.len + 4; /* Now we can just encapsulate the options into the packet fairly * painlessly. */ if (!option_space_encapsulate(&packet, send_options, &dhcpv6)) log_fatal ("Couldn't encapsulate %s", sending_name); /* If we're faking up a relay-forward message, put a length on the Relay Message option. */ if (caplen_offset != -1) { printf("caplen = %d packet len = %d offset = %d\n", caplen_offset, packet.len, packet.len - caplen_offset - 2); putUShort(&packet.buffer->data[caplen_offset], packet.len - caplen_offset - 2); } inet_ntop(AF_INET6, &dest.sin6_addr, addrbuf, sizeof addrbuf); log_info ("%s on %s to %s xid %x port %d interval %.2lfs", sending_name, (config->name ? config->name : config->interface->name), addrbuf, xid, ntohs(dest.sin6_port), ((double)interval / 1000000000.0)); /* Send out a packet. */ result = send_packet(config->interface, packet.buffer->data, packet.len, (struct sockaddr *)&dest); /* If there is no next state into which we are going to time out, * or if the next resend interval comes before that timeout, * schedule a retransmission. If something comes in before the * retransmission, the timeout will be canceled. */ if (!next_state_time || next_state_time > cur_time + interval) { if (retransmit_count > 0) { retransmit_count--; if (retransmit_count == 0) addTimeout(cur_time, next_state); else { retransmit = cur_time + interval; addTimeout(retransmit, state); } } else { retransmit = cur_time + interval; addTimeout(retransmit, state); } /* If there is a next state, and the next retransmission would happen * after the timeout that brings us to the next state, then instead * of scheduling a retransmission, schedule the transition into the * next state. */ } else addTimeout(next_state_time, next_state); } void DHCPv6Client::make_client_options(struct buffer *sid) { unsigned i; struct option_cache *oc; struct buffer *bp = (struct buffer *)0; struct option *opt; struct ia *ia; struct option_cache *ia_options = 0; char buf[128]; send_options = new_option_state(); /* Figure out how many parameters were requested. */ for (i = 0; config->dhcpv6_requested_options[i]; i++) ; bp = buffer_allocate(i * 2); for (i = 0; config->dhcpv6_requested_options[i]; i++) putUShort(&bp->data[i * 2], config->dhcpv6_requested_options [i]); opt = find_option(&dhcpv6_option_space, DHCPV6_REQUESTED_OPTIONS); oc = make_const_option_cache(&bp, 0, i * 2, opt); save_option(&dhcpv6_option_space, send_options, oc); /* Rapid commit option. */ if (state == S6_RAPID) { bp = buffer_allocate(0); opt = find_option(&dhcpv6_option_space, DHCPV6_RAPID_COMMIT); oc = make_const_option_cache(&bp, 0, 0, opt); save_option(&dhcpv6_option_space, send_options, oc); } /* Send a DUID option with our DUID. */ bp = buffer_allocate(duid->len); memcpy(bp->data, &duid->data, duid->len); opt = find_option(&dhcpv6_option_space, DHCPV6_DUID); oc = make_const_option_cache(&bp, 0, duid->len, opt); save_option(&dhcpv6_option_space, send_options, oc); /* Send a server identifier if we have one. */ if (sid) { opt = find_option(&dhcpv6_option_space, DHCPV6_SERVER_IDENTIFIER); oc = make_const_option_cache(&sid, 0, sid->size, opt); save_option(&dhcpv6_option_space, send_options, oc); } if (gethostname(buf, sizeof buf) == 0) { int len; printf("got FQDN: %s\n", buf); opt = find_option(&dhcpv6_option_space, DHCPV6_FQDN); bp = buffer_allocate(strlen(buf) + 10); /* XXX */ len = dns_fqdn_to_wire(&bp->data[1], (unsigned char *)buf, strlen(buf)); bp->data[0] = 1; oc = make_const_option_cache(&bp, 0, len + 2, opt); save_option(&dhcpv6_option_space, send_options, oc); } else { perror("Client FQDN"); } if (state != S6_INFORM) { /* Make IA options... */ for (ia = ias; ia; ia = ia->next) { oc = (struct option_cache *)safemalloc(sizeof *oc); memset(oc, 0, sizeof *oc); make_ia_option(&oc->data, ia, 1); oc->option = find_option(&dhcpv6_option_space, DHCPV6_IA_NA); /* Make a linked list of IA options, and when we've made the * last IA option, stash it in client->send_options. */ oc->next = ia_options; ia_options = oc; } if (ia_options) save_option(&dhcpv6_option_space, send_options, ia_options); } } /* Given a DHCPv6 response, make sure it's actually destined for the * client that received it. If there's more than one client attached * to a particular interface, it's going to be a good idea to cycle * through all the clients on the interface that received this packet * to see if one of them is the one that's supposed to have gotten it. * For now we're only doing one client state object per interface, so * this test should always succeed unless the packet is a bogon. */ int DHCPv6Client::associate_v6_response(const unsigned char *packet, struct dhcpv6_response *response, const char *name) { /* If it's a DHCP Reconfigure, we need to look for * a matching IA, because we don't yet have a * transaction ID to match. We will never get * a reconfigure that doesn't contain any IAs, * at least in theory. */ if (packet[0] == DHCPV6_RECONFIGURE) { if (ias_congruent(&response->ias, ias)) goto match; } else if (response->xid == (xid & 0xFFFFFF)) { goto match; } log_info("Dropping %s: no match for xid = %lx, xid = %lx, duid = %s", name, (unsigned long)response->xid, (unsigned long)xid, print_hex_1(duid->len, (const unsigned char *)&duid->data, 80)); return false; match: response->state = this; response->interface = config->interface; return true; } /* Check to see if two sets of IAs contain all the same IAs. Return 1 if * yes, 0 if no. We do not assume that the lists are sorted the same way, * so we just have to go through both lists looking for ias that are not in * the other. We treat empty lists as never being congruent, because the * point is to look for a match, not to look for two mistakes. * * As a side effect, ias_congruent reorders the new list so that it's in * the same order as the original list. */ int DHCPv6Client::ias_congruent(struct ia **new_ia_list, struct ia *my_ia_list) { struct ia *a, *b; struct ia **reordered; int num_ias = 0; /* Empty lists are never congruent. */ if (!new_ia_list || !*new_ia_list || !my_ia_list) return 0; b = *new_ia_list; while (b) { for (a = my_ia_list; a; a = a->next) if (b->id == a->id) goto again; /* We didn't find the IA that B is pointing for any value * of A, so the IA sets aren't congruent. */ return 0; again: num_ias++; b = b->next; } reordered = (struct ia **)safemalloc(num_ias * sizeof *reordered); num_ias = 0; a = my_ia_list; while (a) { for (b = *new_ia_list; b; b = b->next) if (b->id == a->id) goto more; /* We didn't find the IA that A is pointing to for any value * of B, so the IA sets aren't congruent. */ return 0; more: reordered[num_ias++] = b; a = a->next; } /* It was neither the case that the list ia1 contained ias that were * not in list ia2, nor that list ia2 contained ias that were not in * the list ia1, so the lists are congruent. */ /* Reorder the new list. */ reordered[num_ias - 1]->next = 0; while (--num_ias > 0) reordered[num_ias - 1]->next = reordered[num_ias]; *new_ia_list = reordered[0]; return 1; } /* A server is offering us service in response to a solicit, * or at least so one hopes. */ void DHCPv6Client::advertise(struct dhcpv6_response *response, struct sockaddr_in6 *from, const unsigned char *packet, unsigned length) { struct ia *ia; struct ia_addr *addr; u_int64_t next; struct option_cache *oc; char buf[128]; if (state != S6_SOLICITING && state != S6_SELECTING && state != S6_RAPID) { log_info("Dropping DHCP Advertise from %s: not soliciting or selecting", inet_ntop(from->sin6_family, (char *)&from->sin6_addr, buf, sizeof buf)); return; } /* We need a server identifier or it's useless. */ oc = lookup_option(&dhcpv6_option_space, response->options, DHCPV6_SERVER_IDENTIFIER); if (!oc) { log_info("Dropping DHCP Advertise from %s: no server identifier", inet_ntop(from->sin6_family, (char *)&from->sin6_addr, buf, sizeof buf)); return; } /* Associate it with a transaction. Associate function will log * error if there is one. */ if (!associate_v6_response(packet, response, "DHCP Advertise")) { log_info("%s: associate failed.", inet_ntop(from->sin6_family, (char *)&from->sin6_addr, buf, sizeof buf)); return; } log_info("Accepting DHCP Advertise from %s.", inet_ntop(from->sin6_family, (char *)&from->sin6_addr, buf, sizeof buf)); /* The packet appears to be a response to us. However, it may be * a negative response: "I can't give you an address - sorry. */ for (ia = response->ias; ia; ia = ia->next) { if (ia->addresses) goto have_addrs; } /* Okay, no addresses. We want to save the negative response, * because if it's the only one we get within the time limit, we * will want to display whatever message it contains, but it's not * good enough to trigger us to stop trying to get a useful response, * unless we've already passed the selecting timeout. */ goto can_pick; have_addrs: /* If the IAs are not the ones we asked for, the packet is just bogus, * and we can and should ignore it. */ if (!ias_congruent(&response->ias, response->state->ias)) { log_info("Dropping DHCP Advertise from %s: IAs are not congruent.", inet_ntop(from->sin6_family, (char *)&from->sin6_addr, buf, sizeof buf)); return; } /* Now make sure that the offered addresses are actually worth having. * Right now the criteron is, is there a single offered address with * a preferred lifetime greater than zero. We might get fancier * later. Suggestions solicited. * * BTW, it's possible that we might get an IA that offers an address * with a preferred lifetime of zero, and another address with a non- * zero preferred lifetime. That's not a bad thing - it just means * that an address we'd asked to be renewed got deprecated. But each * IA should contain at least one address with a preferred lifetime * greater than zero, or else we've effectively been told not to * use the network. */ next = MAX_TIME; for (ia = response->ias; ia; ia = ia->next) { ia->expiry = MAX_TIME; for (addr = ia->addresses; addr; addr = addr->next) { if (addr->preferred && addr->preferred < ia->expiry) ia->expiry = addr->preferred; } /* No usable addresses. */ if (ia->expiry == MAX_TIME) ia->expiry = 0; /* The message contains addresses, but none that we want. */ if (ia->expiry < next) { next = ia->expiry; } } /* If next is zero, at lease one IA had no usable addresses. */ if (!next) { log_info("Dropping DHCP Advertise from %s: one or more IAs had " "no usable addresses.", inet_ntop(from->sin6_family, (char *)&from->sin6_addr, buf, sizeof buf)); return; } /* If we get this far, the DHCP Advertise is pretty believable, * so we'll add it to the list and kick off the countdown to * the time when we have to make a decision on what address to * use. We stop retransmitting DHCP Solicit messages at this * point, but keep listening for DHCP Advertises. * * It would be good at this point to pay attention to the preference * option; however, my personal opinion on the preference option is * that it isn't interesting unless the DHCP Advertise has been * authenticated, and since we don't do authentication yet, I'm not * putting in any code to pay attention to it. * * Another point about that is that I think the server preference * option is most important in an environment where you (a) want * to make a decision as quickly as possible and (b) can't afford * to waste bandwidth. * * XXX So if you, the honored reader, are using this code in, * XXX for example, a cell phone, then you may want to put in * XXX some code here to correctly handle the preference option, * XXX even in the absence of DHCP authentication, particularly * XXX since you may have already done some authentication at * XXX another layer. */ can_pick: /* Stop sending DHCP Solicit messages. */ clearTimeouts(); /* Save the response. */ response->next = responses; responses = response; /* Add a timeout at which we will choose one of the responses, or * if that time has already passed, just make the choice. */ if (cur_time < first_sending + config->select) addTimeout((first_sending + config->select), S6_SELECTING); else state_selecting(); } /* Pick_advertisement gets called when we've gotten at least one response * from a DHCP server in response to an ongoing DHCP Solicit attempt. * It's possible that none of the advertisements we've gotten include * usable IP addresses, and it's also possible that we may have gotten * more than one response that contains usable IP addresses. */ void DHCPv6Client::state_selecting() { struct ia *my_ia, *offered_ia; struct ia_addr *my_addr, *offered_addr; struct dhcpv6_response *rsp; struct option_cache *oc; next_state_time = 0; state = S6_SELECTING; /* First make sure that we actually asked for some addresses. If * we did not, which will be the case for a newly-booting client, then * we don't want to just automatically take the first response because * it failed to not extend the zero addresses we requested. */ for (my_ia = ias; my_ia; my_ia = my_ia->next) { if (my_ia->addresses) goto did_ask; } /* If we fell out of the for loop, we didn't send any IA_ADDRs to * the server. */ goto did_not_ask; did_ask: /* See if we can find a response from a DHCPv6 server that * extends the lifetimes on all of the addresses we had * previously. */ for (rsp = responses; rsp; rsp = rsp->next) { /* We are able to assume that the list of ias in the response * contains the same IAs, in the same order, as the list on * the client state object, because we have already called * ias_congruent(), which ensures that as one of its exit * conditions on success. We would never see the response * here if its IA list were not congruent. */ for ((my_ia = ias), (offered_ia = rsp->ias); my_ia && offered_ia; (my_ia = my_ia->next), (offered_ia = offered_ia->next)) { for (my_addr = my_ia->addresses; my_addr; my_addr = my_addr->next) { for (offered_addr = offered_ia->addresses; offered_addr; offered_addr = offered_addr->next) { if (!memcmp(offered_addr->address.iabuf, my_addr->address.iabuf, 16)) { if (my_addr->preferred < cur_time + offered_addr->preferred) goto good; break; } } /* We get here either if my address isn't * on the address list, or if the preferred * lifetime hasn't been extended. In either * case, we're not going to jump on this offer. */ goto not_so_good; /* We get here if the current address on the * my_ia address list that we're looking at * got a good offer. Basically, a single bad * offer is going to knock us out, so if we * fall off the bottom of the ia for loop * below, we have a good offer. */ good: continue; } } /* At this point we got through all the IAs in the current * response, and all the addresses in those IAs, and they * were all renewed, so the response at which we are currently * looking is the best; there's no need to look further. */ goto happy; /* If we get here, this response didn't meet the qualifications * described in the previous comment, so we're going to keep * looking in hopes of finding a response that does. */ not_so_good: continue; } /* If we get to here, it's either because we didn't ask for any * specific addresses, or because none of the responses honored * whatever request we did make. So at this point we just need * to look for a response that gave us at least one address with * a nonzero preferred lifetime for each interface. */ did_not_ask: for (rsp = responses; rsp; rsp = rsp->next) { /* We may have got a response that was just an error message, * with no IAs. In that case, don't try to use it. */ if (!rsp->ias) goto unusable; for (offered_ia = rsp->ias; offered_ia; offered_ia = offered_ia->next) { for (offered_addr = offered_ia->addresses; offered_addr; offered_addr = offered_addr->next) { /* Right now we're saying if the offer is * greater than zero, it's good, but probably * we should make it a useful interval; I * am just not sure how long or short to * make it. If we're dealing with a * non-hostile server, comparing against * zero is fine - it's only in the case * of a DoS attack that we'd want to be * more picky. And there are so many * potential DoS attacks. :'( */ if (offered_addr->preferred > 0) goto content; } /* If we get here, then the IA we're looking at * didn't get an address. For now we assume that * in order for an offer to be usable, it has to * satisfy all IAs, so if we get here, the offer * isn't usable. */ goto unusable; break; /* If we get here, the IA got a usable address, so * we're content. */ content: continue; } /* If we get here, it means that we were content with the * addresses offered on all IAs on this response. So we * can use this response: we're happy. */ goto happy; /* We skip down to here if one of the IAs in the response * didn't get an address; that means that the response we * are looking at is unusable, so we keep looking. */ unusable: continue; } /* If we get here, it means that none of the responses were * usable - none of them satisfied our request for addresses on * all the IAs we sent. It is possible that one or more * responses contain an explanatory message, so now we search * for one and print it if we can. */ oc = 0; for (rsp = responses; rsp; rsp = rsp->next) { oc = lookup_option(&dhcpv6_option_space, rsp->options, DHCPV6_STATUS_CODE); if (!oc) { for (offered_ia = rsp->ias; offered_ia; offered_ia = offered_ia->next) { oc = lookup_option(&dhcpv6_option_space, offered_ia->recv_options, DHCPV6_STATUS_CODE); if (oc) break; for (offered_addr = offered_ia->addresses; offered_addr; offered_addr = offered_addr->next) { oc = lookup_option(&dhcpv6_option_space, offered_ia->recv_options, DHCPV6_STATUS_CODE); if (oc) break; } if (oc) break; } } if (oc) break; } if (oc && oc->data.len >= 2) { const char *message; int status_code = getUShort(oc->data.data); if (oc->data.len > 2) { char *msg = (char *)safemalloc(oc->data.len - 1); memcpy(msg, oc->data.data + 2, oc->data.len - 2); msg[oc->data.len - 2] = 0; message = msg; } else { switch(status_code) { case DHCPV6_SUCCESS: goto bogus; case DHCPV6_UNSPECIFIED_FAILURE: goto bogus; case DHCPV6_NO_ADDRS_AVAILABLE: message = "No addresses available."; break; /* We should never have to print either of * the following two messages, because the DHCP * server should have offered us some other * binding and just attached this message to * the binding we requested. */ case DHCPV6_BINDING_UNAVAILABLE: message = "Requested address not available."; break; case DHCPV6_BINDING_NOT_ON_LINK: message = "Requested address not on link."; break; /* We should never get this because we're * following the protocol (right?). */ case DHCPV6_USE_MULTICAST: message = "Server demands multicast."; break; default: goto bogus; } } /* When we get here, message should be pointing to * some string. */ log_info("Advertise Select: %s", message); if (controller) { controller->start(config, "FAILURE"); controller->add_item("MESSAGE", "%s", message); controller->add_item("STATUS6_CODE", "%d", status_code); controller->finish(0, 0, 0); } } else { bogus: log_info("Advertise Select: we received one or more DHCP " "Advertise messages, but none of these included " "any usable IP addresses, and none of them included " "a status message explaining why, so we will keep " "sending Solicit messages in hopes of better luck."); } /* Because we didn't get any valid responses, we need to keep * trying. */ responses = 0; if (cur_time >= retransmit) send_normal_packet(); else addTimeout(retransmit, state); return; /* However we get to happy, rsp is pointing to a response that we * are willing to take. */ happy: /* We can forget about all the other responses. */ responses = 0; /* We need to remember the response we got, so we can compare it to * the response we get in the DHCP Reply message. */ selected_response = rsp; rsp->next = 0; /* Steal the received options and the ia_addrs that we got in the * response and put them on our IA. */ for ((my_ia = ias), (offered_ia = rsp->ias); my_ia && offered_ia; (my_ia = my_ia->next), (offered_ia = offered_ia->next)) { my_ia->addresses = offered_ia->addresses; my_ia->recv_options = offered_ia->recv_options; /* Set the preferred and valid lifetimes on the addresses * we've been offered to zero, so that we don't accidentally * try to use these before they're confirmed. I don't think * there will be a code path where this can happen, but better * safe than sorry. */ for (my_addr = my_ia->addresses; my_addr; my_addr = my_addr->next) { my_addr->preferred = 0; my_addr->valid = 0; } } /* Go into the requesting state (we're sort of borrowing state * names from the DHCPv4 client for now, since v6 doesn't define * state names (not a complaint, btw!). */ state_requesting(); } /* Called when we have chosen from amongst one or more DHCP Advertise * messages and need to confirm our choice with the DHCP server. */ void DHCPv6Client::state_requesting() { /* We don't accept advertises that don't have server identifiers, so * this should be safe. */ struct option_cache *oc = lookup_option(&dhcpv6_option_space, selected_response->options, DHCPV6_SERVER_IDENTIFIER); server_identifier = buffer_allocate(oc->data.len); memcpy(server_identifier->data, oc->data.data, oc->data.len); /* Make a DHCP Request packet, and set appropriate per-interface flags. */ make_client_options(server_identifier); /* Generate a new transaction ID. */ xid = random() & 0xFFFFFF; /* client->destination is already set. */ state = S6_REQUESTING; /* We don't update client->first_sending yet. */ /* We do need to reset the retry interval. */ interval = 0; /* Give up if we don't have a response from the server 90 seconds * from now. */ next_state_time = cur_time + NANO_SECONDS(90); next_state = S6_SOLICITING; /* We're now sending a DHCP Request. */ sending = DHCPV6_REQUEST; sending_name = "DHCP Request"; /* Send the initial solicit. */ send_normal_packet(); } /* A response to an information-request message or any message * responding to a request to acquire, renew or extend addresses on * IAs. */ void DHCPv6Client::reply(struct dhcpv6_response *response, struct sockaddr_in6 *from, const unsigned char *data, unsigned length) { struct ia *my_ia, *confirmed_ia; struct ia_addr *addr; u_int64_t expiry; char buf[128]; const char *reason; /* Decode the response. If it's bogus, drop it and keep waiting. * The reason we keep waiting here and for subsequent drops is that * it's possible that an attacker could send us a bogus DHCP Reply * to get us to go back to soliciting, and we'd like to wait * for a legitimate reply from the server we selected instead. * It's also possible to get a stray DHCP Reply as a result of a retry, * while we're in the wrong state, and again we don't want this to * derail us. */ /* rsp = decode_dhcpv6_packet(data, length, "DHCP Reply"); if (!rsp) return; */ /* Associate it with a transaction. Associate function will log * error if there is one. */ if (!associate_v6_response(data, response, "DHCP Reply")) return; if (response->state->state != S6_REQUESTING && response->state->state != S6_RENEWING && response->state->state != S6_INFORM && response->state->state != S6_REBINDING && response->state->state != S6_CONFIRMING && response->state->state != S6_RAPID && response->state->state != S6_RELEASING) { log_info("Dropping DHCP Reply: not expected in state %d", response->state->state); return; } /* XXX Check all these drops against the spec. It may not be * XXX correct to do all of these drops, except possibly in the * XXX S6_REQUESTING case. */ if (response->state->state == S6_INFORM) { if (response->ias) { log_info("Dropping DHCP Information Request Reply:" "contains IA_NA options."); return; } goto inform; } if (response->state->state == S6_RELEASING) { if (response->ias) { log_info("Dropping DHCP Release Reply:" "contains IA_NA options."); return; } goto inform; } if (response->state->state == S6_CONFIRMING) { if (response->ias) { log_info("Dropping DHCP Confirm Reply:" "contains IA_NA options."); return; } /* A reply to a Confirm shouldn't contain any configuration * information at all; all we really care about is the status * code and the transaction ID, which we already checked. */ struct option_cache *oc = lookup_option(&dhcpv6_option_space, response->options, DHCPV6_STATUS_CODE); if (oc->data.len < 2) { log_info("DHCP Confirm Reply: dropping message with short status."); return; } int status_code = getUShort(oc->data.data); switch(status_code) { case DHCPV6_SUCCESS: log_info("DHCP Confirm Reply: on-link status confirmed"); if (rebind_time < cur_time) state_rebinding(); if (renewal_time < cur_time) state_renewing(); state_bound(); return; case DHCPV6_UNSPECIFIED_FAILURE: case DHCPV6_NO_ADDRS_AVAILABLE: case DHCPV6_BINDING_UNAVAILABLE: case DHCPV6_USE_MULTICAST: default: log_info("Dropping DHCP Confirm Reply:" "contains bogus status code %d.", status_code); return; case DHCPV6_BINDING_NOT_ON_LINK: log_info("DHCP Confirm Reply: not on-link."); /* Drop all our addresses. */ if (controller) { controller->start(config, "DHCP Reply"); for (my_ia = response->state->ias; my_ia; my_ia = my_ia->next) { controller->send_ia(my_ia); for (addr = my_ia->addresses; addr; addr = addr->next) controller->send_ia_addr("remove", addr); my_ia->addresses = 0; my_ia->recv_options = 0; } controller->finish(0, 0, 0); } state_soliciting(); return; } } else { /* If there are no IAs, or the IAs are not the ones we * asked for, the packet is just bogus, and we can and * should ignore it. */ if (!response->ias) { log_info("Dropping DHCP Reply: no IA_NA options."); return; } if (!ias_congruent(&response->ias, response->state->ias)) { log_info("Dropping DHCP Reply: IAs are not congruent."); return; } /* Make sure that this Reply actually configures all the IAs * we asked to have configured. */ for (confirmed_ia = response->ias; confirmed_ia; confirmed_ia = confirmed_ia->next) { for (addr = confirmed_ia->addresses; addr; addr = addr->next) { if (addr->preferred > 0 || addr->valid > 0) goto ia_has_address; } log_info("Dropping DHCP Reply: does not configure all IAs."); state_soliciting(); return; ia_has_address: ; } } inform: log_info("Accepting DHCP Reply from %s.", inet_ntop(from->sin6_family, (char *)&from->sin6_addr, buf, sizeof buf)); /* Steal the received options. */ recv_options = response->options; response->options = 0; switch(response->state->state) { case S6_REQUESTING: case S6_RENEWING: case S6_REBINDING: case S6_RAPID: reason = "configured"; break; case S6_INFORM: reason = "informed"; break; case S6_CONFIRMING: reason = "confirmed"; break; case S6_RELEASING: reason = "released"; break; default: /* can't get here. */ reason = "oops"; break; } /* Now we have to say what happened. */ if (controller) controller->start(config, reason); /* Now we have to do adds and deletes. In the case of a DHCP Reply * while requesting, we actually just have to do adds - for every * address in every IA, we do an add. */ for ((my_ia = response->state->ias), (confirmed_ia = response->ias); my_ia && confirmed_ia; (my_ia = my_ia->next), (confirmed_ia = confirmed_ia->next)) { if (controller) controller->send_ia(confirmed_ia); /* If we're in the requesting state, we are only going to be * adding addresses, not deleting any. */ if (state == S6_REQUESTING) goto just_adds; /* Look for addresses we had, but no longer have, and * do deletes on them. At the same time, for any address * that we had, and still have, do an update. */ for (addr = my_ia->addresses; addr; addr = addr->next) { struct ia_addr *na; for (na = confirmed_ia->addresses; na; na = na->next) { if (!memcmp(na->address.iabuf, addr->address.iabuf, 16)) { if (controller) controller->send_ia_addr("update", na); goto found_addr; } } /* If we fall out the bottom of the loop, this is an * address that *didn't* get renewed. */ if (controller) controller->send_ia_addr("remove", addr); found_addr: ; } /* Now look for addresses we didn't have, but now do have. */ for (addr = confirmed_ia->addresses; addr; addr = addr->next) { struct ia_addr *na; for (na = my_ia->addresses; na; na = na->next) { if (!memcmp(na->address.iabuf, addr->address.iabuf, 16)) { goto found_addr_1; } } /* If we fall out the bottom of the loop, this is an * address that is in the server message, but not in * our old list of addresses - thus, a new address. */ if (controller) controller->send_ia_addr("add", addr); found_addr_1: ; } /* Skip over the code for the selecting state. */ goto steal_conf; /* Look for addresses that are valid. */ just_adds: for (addr = confirmed_ia->addresses; addr; addr = addr->next) { if (addr->preferred > 0 || addr->valid > 0) { if (controller) controller->send_ia_addr("add", addr); } } steal_conf: /* Steal the new address configuration and options from each * IA as we go. */ my_ia->addresses = confirmed_ia->addresses; confirmed_ia->addresses = 0; my_ia->recv_options = confirmed_ia->recv_options; confirmed_ia->recv_options = 0; } /* If we're releasing, we should exit the loop with my_ia still pointing * at something. */ if (state == S6_RELEASING && my_ia != NULL) { for (addr = my_ia->addresses; addr; addr = addr->next) { if (controller) controller->send_ia_addr("remove", addr); } my_ia->addresses = 0; my_ia->recv_options = 0; } if (controller) { controller->send_options(recv_options); controller->finish(0, 0, 0); } /* For DHCP Release, we are done. */ if (state == S6_RELEASING) { state_unmanaged(); return; } /* XXX for DHCP Information Request, we need to extract the information * XXX request time according to the new draft and set up a timeout * XXX at which time we will send another information request. * XXX Actually, maybe Network Manager should do this. */ if (state == S6_INFORM) { struct option_cache *option = lookup_option(&dhcpv6_option_space, recv_options, DHCPV6_INFORMATION_REFRESH_TIME); if (!option) { #if 0 log_info("choosing IRT_DEFAULT expiry time.\n"); #endif expiry = DHCPV6_IRT_DEFAULT; } else if (option->next) { log_info("Dropping DHCP Information Request Reply:" "contains multiple refresh times."); return; } else { if (option->data.len != 4) { log_info("Dropping DHCP Information Request " "Reply: contains multiple refresh " "times."); return; } expiry = getULong(option->data.data); if (expiry < DHCPV6_IRT_MINIMUM) { log_info("Ignoring DHCP Information Refresh " "Time: renewal time is too short."); expiry = DHCPV6_IRT_MINIMUM; } else if (expiry > DHCPV6_IRT_MAXIMUM) { log_info("Ignoring default Information " "Refresh Time: renewal time is too " "long; either it's misconfigured or " "it's a denial of service attack."); return; } #if 0 else log_info("choosing expiry time from option.\n"); #endif } /* Add a timeout to refresh the information at the * interval we figured out. */ clearTimeouts(); addTimeout(cur_time + NANO_SECONDS(expiry), S6_INFORM); time_t t = SECONDS(cur_time + NANO_SECONDS(expiry)); ctime_r(&t, buf); buf[strlen(buf) - 1] = 0; log_info("Information refresh time: %s", buf); /* XXX we haven't taken into account that the user might ask for * XXX an information request even though we're not doing lite * XXX on this client. */ return; } /* Figure out when we need to send a renewal. Also, tweak preferred and * valid times to be relative to the epoch, rather than relative to when the * server generated the packet, and get rid of IA_ADDRs that no longer * contain usable addresses. */ expiry = MAX_TIME; renewal_time = MAX_TIME; rebind_time = MAX_TIME; for (my_ia = response->state->ias; my_ia; my_ia = my_ia->next) { struct ia_addr *prev = 0; /* Figure out when *this* IA expires. This is going to be the * longest preferred time of all the IA_ADDRS in the IA. */ my_ia->expiry = 0; /* Do the IA_ADDR cleanup and find expiry time. */ for (addr = my_ia->addresses; addr; addr = addr->next) { if (addr->preferred > my_ia->expiry) { my_ia->expiry = addr->preferred; } /* Get rid of any IA_ADDRs in the response that are * just telling us something we asked for is no * longer valid. */ if (addr->preferred == 0 && addr->valid == 0) { if (prev) prev->next = addr->next; else my_ia->addresses = addr->next; } else { /* Make the preferred and valid times absolute * instead of relative. */ addr->preferred = response->received_time + NANO_SECONDS(addr->preferred); addr->valid = response->received_time + NANO_SECONDS(addr->valid); } prev = addr; } /* If the renewal, rebind or expiry times on this IA are shorter than * the times we've figured out for other IAs, use the times from this * IA - this IA needs to be renewed sooner. * This is problematic, since RFC3315 wants us not to renew an IA earlier * than the t1 time on that IA, but I don't really see a way around it * other than handling IAs in separate messages. Maybe that's the * right thing to do, but I don't particularly want to do it this way. * We talked about this quite extensively, but that discussion doesn't * seem to be reflected in RFC3315, more's the pity. */ if (renewal_time > my_ia->t1) renewal_time = my_ia->t1; if (rebind_time > my_ia->t2) rebind_time = my_ia->t2; if (expiry > my_ia->expiry) expiry = my_ia->expiry; } /* Server doesn't have to specify T1/T2? */ if (renewal_time == 0) renewal_time = expiry * 5 / 8; if (rebind_time == 0) rebind_time = expiry * 7 / 8; /* At this point client->expiry should contain the lowest of the maximum * preferred times from each IA in the response. The DHCP * server specifies when to try to renew the IAs and when to try to * rebind them; we decide when to start doing a solicit based on the * minumum preferred lifetime. */ renewal_time = cur_time + NANO_SECONDS(renewal_time); rebind_time = cur_time + NANO_SECONDS(rebind_time); solicit_time = cur_time + NANO_SECONDS(expiry); if (renewal_time > solicit_time) renewal_time = solicit_time; if (rebind_time > solicit_time) rebind_time = solicit_time; state_bound(); } /* We enter this state when we've finished either getting a new IP address * for the first time, or renewing an IP address subsequently. */ void DHCPv6Client::state_bound() { char buf[128]; char vtbuf[26]; char ptbuf[26]; struct ia *my_ia; struct ia_addr *addr; time_t t; for (my_ia = ias; my_ia; my_ia = my_ia->next) { for (addr = my_ia->addresses; addr; addr = addr->next) { t = SECONDS(cur_time + addr->valid); ctime_r(&t, vtbuf); vtbuf[strlen(vtbuf) - 1] = 0; t = SECONDS(cur_time + addr->preferred); ctime_r(&t, ptbuf); ptbuf[strlen(ptbuf) - 1] = 0; log_info("Bound to %s, valid = %s, preferred = %s", inet_ntop(AF_INET6, addr->address.iabuf, buf, sizeof buf), vtbuf, ptbuf); } } t = SECONDS(renewal_time); ctime_r(&t, buf); buf[strlen(buf) - 1] = 0; log_info("Renewal time: %s", buf); clearTimeouts(); state = S6_BOUND; addTimeout(renewal_time, S6_RENEWING); } /* Called when we have chosen from amongst one or more DHCP Advertise * messages and need to confirm our choice with the DHCP server. */ void DHCPv6Client::state_renewing() { /* Make a DHCP Request packet, and set appropriate per-interface flags. */ make_client_options(server_identifier); /* Generate a transaction ID for the renewal. */ xid = random() & 0xFFFFFF; /* XXX We should handle the case here where the server sent the unicast * XXX option. */ if (relay_destination.len == 16) destination = relay_destination; else destination = iaddr_all_agents_and_servers; state = S6_RENEWING; first_sending = cur_time; interval = 0; /* Give up if we don't have a response from the server 90 seconds * from now. */ next_state_time = rebind_time; next_state = S6_REBINDING; /* We're now sending a DHCP Renew. */ sending = DHCPV6_RENEW; sending_name = "DHCP Renew"; /* Send the initial renew. */ send_normal_packet(); } /* Called when we've been trying to renew a particular client state and * have been unable to do so. When 7/8th of the time available on the * shortest valid address has expired, we send a DHCP Rebind message in * hopes that some other server will be able to help us. */ void DHCPv6Client::state_rebinding() { /* Make a DHCP Request packet, and set appropriate per-interface flags. */ make_client_options(0); /* Make a new transaction ID for the rebinding state. */ xid = random() & 0xFFFFFF; /* When we're rebinding, we always multicast. */ if (relay_destination.len == 16) destination = relay_destination; else destination = iaddr_all_agents_and_servers; state = S6_REBINDING; /* Keep client->first_sending from the renew. */ interval = 0; /* Give up if we don't have a response from the server 90 seconds * from now. */ next_state_time = solicit_time; next_state = S6_SOLICITING; /* We're now sending a DHCP Rebind. */ sending = DHCPV6_REBIND; sending_name = "DHCP Rebind"; /* Send the initial solicit. */ send_normal_packet(); } /* When we get into the unmanaged state, only some kind of user or management * tool intervention can get us back out of it - this is where we go when * we've determined that we're not supposed to manage this interface. */ void DHCPv6Client::state_unmanaged() { clearTimeouts(); state = S6_UNMANAGED; next_state_time = 0; } /* This is called whenever a timer expires for this client state machine. * If the timeout requires us to change states, we do so; otherwise we * assume that we have to retransmit the current packet, since there's no * other cause for a timeout to happen. */ void DHCPv6Client::event(const char *evname, int newState, int status) { /* If this timeout triggers a state transition, make the transition. */ if (newState != state) { switch(newState) { case S6_SOLICITING: state_soliciting(); break; case S6_SELECTING: state_selecting(); break; case S6_REQUESTING: state_requesting(); break; case S6_BOUND: state_bound(); break; case S6_RENEWING: state_renewing(); break; case S6_REBINDING: state_rebinding(); break; case S6_INFORM: state_inform(); break; case S6_UNMANAGED: state_unmanaged(); break; } } /* Otherwise, it's triggering a retransmission. */ send_normal_packet(); } /* Local Variables: */ /* mode:c++ */ /* c-file-style:"gnu" */ /* end: */
29.691969
122
0.654668
[ "object" ]
326ea85db60c52b39d297e2d43d4b705a0b57747
9,348
hpp
C++
terminalpp/include/terminalpp/terminal.hpp
CalielOfSeptem/septem
fe7a615eb6c279d3746ee78de8864b5e07bf7e3e
[ "MIT" ]
1
2017-03-30T14:31:33.000Z
2017-03-30T14:31:33.000Z
terminalpp/include/terminalpp/terminal.hpp
HoraceWeebler/septem
fe7a615eb6c279d3746ee78de8864b5e07bf7e3e
[ "MIT" ]
null
null
null
terminalpp/include/terminalpp/terminal.hpp
HoraceWeebler/septem
fe7a615eb6c279d3746ee78de8864b5e07bf7e3e
[ "MIT" ]
null
null
null
#pragma once #include "terminalpp/extent.hpp" #include "terminalpp/point.hpp" #include "terminalpp/string.hpp" #include "terminalpp/token.hpp" #include "terminalpp/detail/parser.hpp" #include <boost/optional.hpp> #include <string> #include <vector> namespace terminalpp { //* ========================================================================= /// \brief A class responsible for combining the knowledge and state of a /// terminal window to know what the best way to respresent a given string is. /// \par /// Note: the terminal itself does not send any results anywhere -- instead, /// a string is returned that is an ANSI sequence of character that will cause /// the required action to be accomplished on the remote terminal -- although /// the function descriptions are written as if that were so. That is just /// for clarity's sake (it's easier to write "moves the cursor to the /// position" than "returns a string that represents the ANSI sequence of /// characters that will move the cursor to the position." //* ========================================================================= class TERMINALPP_EXPORT terminal { public : enum class control_mode { seven_bit, eight_bit, }; // In erase_in_display, there is the choice of erasing every line // above the cursor, every line below the cursor, or the entire // display. enum class erase_display { below, above, all }; // In erase_in_line, there is the choice of eraseing everything // to the left of the cursor, everything to the right of the cursor, // or everything on the current line. enum class erase_line { right, left, all }; //* ===================================================================== /// \brief A set of flags that determine how a terminal should behave /// over a datastream. //* ===================================================================== struct behaviour { constexpr behaviour() : can_use_eight_bit_control_codes(false), uses_eight_bit_control_codes_by_default(false), supports_cha(true), supports_cha_default(true), supports_cup_default_row(false), supports_cup_default_column(true), supports_cup_default_all(true), supports_basic_mouse_tracking(false), supports_all_mouse_motion_tracking(false), supports_window_title_bel(false), supports_window_title_st(false), unicode_in_all_charsets(false) { } // Eight bit control codes save on a character each time an ANSI // control code is used. This could amount to quite the saving over // time. bool can_use_eight_bit_control_codes : 1; // If a terminal can use eight bit control codes, it may require a // code to enable that sequence. Some terminals may default to using // eight bit control codes, but not understand the enable sequence, so // it should only be used if actually required. bool uses_eight_bit_control_codes_by_default : 1; // True if the terminal supports Cursor Horizontal Absolute bool supports_cha : 1; // True if the terminal supports the use of a default argument // in Cursor Horizontal Absolute bool supports_cha_default : 1; // True if the terminal supports the use of a default row argument // (only) in Cursor Position. bool supports_cup_default_row : 1; // True if the terminal supports the use of a default column argument // (only) in Cursor Position. bool supports_cup_default_column : 1; // True if the terminal supports the use of both arguments being // default in Cursor Position bool supports_cup_default_all : 1; // True if the terminal supports basic mouse tracking. bool supports_basic_mouse_tracking : 1; // True if the terminal supports all mouse motion tracking. bool supports_all_mouse_motion_tracking : 1; // True if the window title can be set with the BEL terminator. bool supports_window_title_bel : 1; // True if the window title can be set with the ST terminator. bool supports_window_title_st : 1; // True if unicode can be used in all charsets; false if unicode // can only be used in the default charset; bool unicode_in_all_charsets : 1; }; //* ===================================================================== /// \brief Constructor //* ===================================================================== explicit terminal(behaviour const &beh = behaviour{}); //* ===================================================================== /// \brief Returns a string that will initialize the terminal. /// Based on the behaviour passed in the constructor, returns a string /// that can be sent to the terminal to put it into the best control mode /// that it can handle. //* ===================================================================== std::string init(); //* ===================================================================== /// \brief Returns a string that will enable the best possible mouse /// mode for the terminal. //* ===================================================================== std::string enable_mouse(); //* ===================================================================== /// \brief Returns a string that will set the window title of the /// terminal. //* ===================================================================== std::string set_window_title(std::string const &title); //* ===================================================================== /// \brief Sets the (local) size of the terminal. /// There is nothing transmitted by this. This is so that the client /// can set how large the terminal is expected to be. This affects /// things like when does a cursor scroll the screen, etc. //* ===================================================================== void set_size(extent const &size); //* ===================================================================== /// \brief Show the cursor. //* ===================================================================== std::string show_cursor(); //* ===================================================================== /// \brief Hide the cursor. //* ===================================================================== std::string hide_cursor(); //* ===================================================================== /// \brief Saves the current cursor position. //* ===================================================================== std::string save_cursor(); //* ===================================================================== /// \brief Restores the previously saved cursor position. //* ===================================================================== std::string restore_cursor(); //* ===================================================================== /// \brief Move the cursor to the specified position. Note: terminals are /// 1-based. I.e. the origin position is (1,1). //* ===================================================================== std::string move_cursor(point const &pt); //* ===================================================================== /// \brief Reads a stream of data. //* ===================================================================== std::vector<token> read(std::string const &data); //* ===================================================================== /// \brief Writest the specified element. //* ===================================================================== std::string write(element const &elem); //* ===================================================================== /// \brief Writes the specified sequence of characters. //* ===================================================================== std::string write(string const &str); //* ===================================================================== /// \brief Erases the display in the specified manner. //* ===================================================================== std::string erase_in_display(erase_display how); //* ===================================================================== /// \brief Erases the current line in the specified manner. //* ===================================================================== std::string erase_in_line(erase_line how); private : enum class cursor_mode : bool { hidden, shown, }; behaviour behaviour_; control_mode control_mode_ = control_mode::seven_bit; boost::optional<cursor_mode> cursor_mode_; boost::optional<point> cursor_position_; boost::optional<point> saved_cursor_position_; boost::optional<extent> size_; element last_element_; detail::parser parser_; }; }
41.546667
78
0.474968
[ "vector" ]
3275a2d120539b6a6adb1d4d3fa317fe44686e23
13,350
cpp
C++
CS479/Project_1/code_files/bayes_classifier.cpp
T-R0D/Past-Courses
0edc83a7bf09515f0d01d23a26df2ff90c0f458a
[ "MIT" ]
7
2017-03-13T17:32:26.000Z
2021-09-27T16:51:22.000Z
CS479/Project_1/code_files/bayes_classifier.cpp
T-R0D/Past-Courses
0edc83a7bf09515f0d01d23a26df2ff90c0f458a
[ "MIT" ]
1
2021-05-29T19:54:02.000Z
2021-05-29T19:54:52.000Z
CS479/Project_1/code_files/bayes_classifier.cpp
T-R0D/Past-Courses
0edc83a7bf09515f0d01d23a26df2ff90c0f458a
[ "MIT" ]
25
2016-10-18T03:31:44.000Z
2020-12-29T13:23:10.000Z
/** @file bayes_classifier.cpp @author Terence Henriod Project 1: Bayesian Minimum Error Classification @brief Class implementations for the BayesClassifier defined in bayes_classifier.h. @version Original Code 1.00 (3/8/2014) - T. Henriod */ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HEADER FILES / NAMESPACES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ // Class Declaration #include "bayes_classifier.h" // Other Dependencies #include <cassert> #include <iostream> #include <fstream> #include <Eigen/Dense> // -I /home/thenriod/Desktop/cpp_libs/Eigen_lib /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ================================================================================ CLASS FUNCTION IMPLEMENTATIONS ================================================================================ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONSTRUCTOR(S) / DESTRUCTOR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /** GameState The default constructor for a game state. Constructs and initilizes an empty GameState. @pre -# The GameState object is given an appropriate identifier. @post -# A new, empty GameState will be initialized. @code @endcode */ BayesClassifier::BayesClassifier() { // variables int ndx = 0; Eigen::Vector2d temp_mean; temp_mean << 1, 1; Eigen::Matrix2d temp_matrix; temp_matrix << 1, 0, 0, 1; // initialize all members for( ndx = 0; ndx < NUM_FEATURES; ndx++ ) { prior_probabilities.push_back( double( 1.0 / NUM_FEATURES ) ); } for( ndx = 0; ndx < NUM_FEATURES; ndx++ ) { mean_vectors.push_back( temp_mean ); } for( ndx = 0; ndx < NUM_FEATURES; ndx++ ) { covariance_matrices.push_back( temp_matrix ); } assumption_case_ = CASE_THREE; // no return - constructor } BayesClassifier::BayesClassifier( const BayesClassifier& other ) { // no return - copy constructor } BayesClassifier& BayesClassifier::operator=( const BayesClassifier& other ) { // return *this return *this; } BayesClassifier::~BayesClassifier() { // no return - destructor } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MUTATORS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ void BayesClassifier::clear() { // no return - void } void BayesClassifier::setMean( const Eigen::Vector2d& new_mean_vector, const int which_class ) { // variables // none // set the appropriate mean vector mean_vectors[which_class] = new_mean_vector; // no return - void } void BayesClassifier::setCovariance( const Eigen::Matrix2d& new_covariance_matrix, const int which_class ) { // variables // none // set the appropriate covariance matrix covariance_matrices[which_class] = new_covariance_matrix; // case: the new case was case 1 if( assumption_case_ == CASE_ONE ) { // update the variance variance = covariance_matrices[CLASS_ONE]( 0, 0 ); } // no return - void } void BayesClassifier::setPriorProbabilities( const double class_one_prior ) { // assert pre-conditions assert( ( class_one_prior >= 0.0 ) && ( class_one_prior <= 1.0 ) ); // assert( class_one_prior == ( 1 - class_one_prior ) ); // hopefully doubles don't screw this up // they do // variables // none // set the new prior probability prior_probabilities[0] = class_one_prior; prior_probabilities[1] = 1 - class_one_prior; // no return - void } void BayesClassifier::setAssumptionCase( const int new_case ) { // set the new case TODO: automate this assumption_case_ = new_case; // case: the new case was case 1 if( assumption_case_ == CASE_ONE ) { // update the variance variance = covariance_matrices[CLASS_ONE]( 0, 0 ); } } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ACCESSORS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ void BayesClassifier::performAnalysis( const string input_file, const string output_file ) { // variables fstream file; TestData temp; char delimiter; int num_data = 0; int ndx = 0; int num_misclassified = 0; double test_error_rate = 0.5; double beta_start = 0.5; vector<TestData> data; Chernoff chernoff_bound; // read in all of the data file.clear(); file.open( input_file.c_str(), fstream::in ); while( file.good() ) { // read in a line of data file >> temp.feature_vector(0) >> delimiter >> temp.feature_vector(1) >> delimiter >> temp.actual_class; // store the data data.push_back( temp ); // count the data num_data++; } file.close(); // classify all of the data for( ndx = 0; ndx < num_data; ndx++ ) { // classify an object data[ndx].classified_as = assignToClass( data[ndx].feature_vector ); // case: it was classified correctly if( data[ndx].classified_as == data[ndx].actual_class ) { // mark and count this as a correct classification data[ndx].correctly_classified = CORRECT; } // case: it was not classified correctly else { // mark this as an incorrect classification data[ndx].correctly_classified = INCORRECT; num_misclassified++; } } // compute the error rate of the test test_error_rate = double( num_misclassified ) / double( num_data ); // find chernoff bound chernoff_bound = findChernoffBound( beta_start, 0 ); // output the results to file file.clear(); file.open( output_file.c_str(), fstream::out ); file << "Number of data: " << ( num_data - 1 ) << endl << "Number of incorrect classifications: " << num_misclassified << endl << "Test Sample Error Rate: " << test_error_rate << endl << "Battacharyya bound: " << findBattacharyyaBound() << endl << "Chernoff bound: " << chernoff_bound.bound << endl << " beta*: " << chernoff_bound.beta << endl; for( ndx = 0; ndx < num_data; ndx++ ) { // write the delimited data to the file file << data[ndx].feature_vector(0) << ", " << data[ndx].feature_vector(1) << ", " << data[ndx].actual_class << ", " << data[ndx].classified_as << ", " << data[ndx].correctly_classified << endl; } file.close(); // no return - void } string BayesClassifier::assignToClass( Eigen::Vector2d& input_vector ) { // variables string classification_result; double discriminant_difference = 0; // calculate the difference of the discriminants discriminant_difference = calculateDiscriminant( input_vector, CLASS_ONE ) - calculateDiscriminant( input_vector, CLASS_TWO ); // case: the difference has a positive result if( discriminant_difference > 0 ) { // the object is likely in class one classification_result = "ONE"; } // case: the difference has a negative result else { // the object is likely in class two classification_result = "TWO"; } // return the resulting assignment return classification_result; } double BayesClassifier::calculateDiscriminant( const Eigen::Vector2d& input_vector, const int which_class ) { // variables double discriminant_result = 0; double first_sum_term = 0; double second_sum_term = 0; double third_sum_term = 0; double fourth_sum_term = 0; double fifth_sum_term = 0; Eigen::Vector2d mean; Eigen::Matrix2d inverse_covariance_matrix; Eigen::Vector2d intermediate_row; Eigen::Vector2d intermediate_col; Eigen::Matrix2d intermediate_mat; // get the appropriate mean ready mean = mean_vectors[which_class]; // prepare an inverse of the covariance matrix for the computations inverse_covariance_matrix = covariance_matrices[which_class].inverse(); // case: the assumptions are not that of case 1 if( assumption_case_ != CASE_ONE ) { // compute the first summative term of the discriminant function intermediate_mat = -0.5 * inverse_covariance_matrix; intermediate_row = ( input_vector.transpose() * intermediate_mat ); first_sum_term = intermediate_row.dot( input_vector ); // compute the second summative term of the discriminant function second_sum_term = ( inverse_covariance_matrix * mean ).transpose().dot( input_vector ); // compute the third summative term of the discriminant function intermediate_row = -0.5 * mean; intermediate_row = intermediate_row.transpose() * inverse_covariance_matrix; third_sum_term = intermediate_row.transpose().dot( mean ); // compute the fourth summative term of the discriminant function fourth_sum_term = -0.5 * log( covariance_matrices[which_class].determinant() ); } // case: we are assuming case 1 assumptions else { // compute the first term ( 1/s^2 * mean * x ) intermediate_row = ( 1.0 / variance ) * mean; first_sum_term = intermediate_row.transpose().dot( input_vector ); // compute the second term intermediate_row = ( -1.0 / ( 2 * variance ) ) * mean; second_sum_term = intermediate_row.transpose().dot( mean ); } // compute the last summative term of the discriminant function fifth_sum_term = log( prior_probabilities[which_class] ); // sum the terms to get the discriminant result discriminant_result = first_sum_term + second_sum_term + third_sum_term + fourth_sum_term + fifth_sum_term; // return the discriminant result return discriminant_result; } Chernoff BayesClassifier::findChernoffBound( double beta_star, int level ) { // variables Chernoff chernoff_bound; chernoff_bound.beta = beta_star; Chernoff left_attempt; Chernoff right_attempt; double beta_increment = 0.0249999; double prior_product = 0.0; double kappa_of_beta = 0; // compute the prior product prior_product = pow( prior_probabilities[0], beta_star ) * pow( prior_probabilities[1], ( 1.0 - beta_star ) ); // kappa( beta* ) kappa_of_beta = kappaF( beta_star ); // compute the Chernoff bound chernoff_bound.bound = prior_product * exp( -1.0 * kappa_of_beta ); // case: we aren't 1000 levels deep if( level < 20 ) { // find two different possible bounds left_attempt = findChernoffBound( beta_star - beta_increment, level + 1 ); right_attempt = findChernoffBound( beta_star + beta_increment, level + 1 ); // test to find the lowest bound if( left_attempt.bound < chernoff_bound.bound ) { chernoff_bound = left_attempt; } if( right_attempt.bound < chernoff_bound.bound ) { chernoff_bound = right_attempt; } } // return the Chernoff bound return chernoff_bound; } double BayesClassifier::findBattacharyyaBound() { // variables double battacharyya_bound = 1; double kappa_of_beta = 0; double root_prior_product = 0; double root_covariance_det_product = 0; Eigen::Vector2d mean_difference; Eigen::Matrix2d covariance_sum; // compute the square root term root_prior_product = sqrt( prior_probabilities[0] * prior_probabilities[1] ); // compute kappa( 0.5 ) kappa_of_beta = kappaF( 0.5 ); // compute sqrt( P( w1 ) * P( w2 ) ) * e^( -kappa( 0.5 ) ) battacharyya_bound = root_prior_product * exp( -1.0 * kappa_of_beta ); // return the Battacharrya bound return battacharyya_bound; } double BayesClassifier::kappaF( const double beta ) { // variables double kappa_of_beta = 0; double beta_complement = 1.0 - beta; double beta_product_over_two = 0; double root_prior_product = 0; double root_covariance_det_product = 0; double log_denominator = 0; Eigen::Vector2d mean_difference; Eigen::Vector2d intermediate_row; Eigen::Matrix2d scaled_covariance_sum; // compute (beta * beta^c) / 2 beta_product_over_two = ( beta * beta_complement ) / 2; // compute the mean difference u2 - u1 (to be used later) mean_difference = mean_vectors[0] - mean_vectors[1]; // compute the scaled covariance sum beta^c * E1 + beta * E2 // (to be used later) scaled_covariance_sum = ( beta_complement * covariance_matrices[0] ) + ( beta * covariance_matrices[1] ); // compute the logarithm denominator (to be used later) log_denominator = pow( covariance_matrices[0].determinant(), beta_complement ); log_denominator *= pow( covariance_matrices[1].determinant(), beta ); // compute the first term in the sum intermediate_row = beta_product_over_two * mean_difference; intermediate_row = intermediate_row.transpose() * scaled_covariance_sum.inverse(); kappa_of_beta = intermediate_row.transpose() * mean_difference; // compute the second term in the sum kappa_of_beta += 0.5 * log( scaled_covariance_sum.determinant() / log_denominator ); // return the result return kappa_of_beta; }
28.046218
100
0.622846
[ "object", "vector" ]
327872044274ed0ea7567550690da20d38df7a88
16,353
hpp
C++
src/gltf_loader.hpp
abbaswasim/vulkaned
15ff8b76d0d52bff2700ffe9107dab75d92638af
[ "Apache-2.0" ]
null
null
null
src/gltf_loader.hpp
abbaswasim/vulkaned
15ff8b76d0d52bff2700ffe9107dab75d92638af
[ "Apache-2.0" ]
null
null
null
src/gltf_loader.hpp
abbaswasim/vulkaned
15ff8b76d0d52bff2700ffe9107dab75d92638af
[ "Apache-2.0" ]
null
null
null
// VulkanEd Source Code // Wasim Abbas // http://www.waZim.com // Copyright (c) 2021 // // 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. // // Version: 1.0.0 #include "utils.hpp" #include <array> #include <cstdint> #include <filesystem> #include <foundation/rortypes.hpp> #include <math/rormatrix4.hpp> #include <math/rorvector2.hpp> #include <math/rorvector3.hpp> #include <math/rorvector4.hpp> #include <profiling/rorlog.hpp> #include <string> #include <unordered_map> #include <vector> #define CGLTF_IMPLEMENTATION #include "cgltf.h" #include "ctpl_stl.h" namespace ast { // struct Vertex // { // ror::Vector3f m_position; // ror::Vector3f m_normal; // ror::Vector2f m_texture_coordinate; // ror::Vector3f m_color; // }; struct Attribute { size_t m_offset{0}; // Start of the data size_t m_count{0}; // How much of the data we need int32_t m_buffer_index{-1}; // Where the data is // TODO: Add types, float, int, vec2, vec4 etc // At the moment assuming position3, normal3, uv2, color3 all float // while index scalar of unsigned int 16 type }; enum array_index { position, normal, texture_coordinate, color, indices }; struct Primitive { std::array<Attribute, 5> m_arrays; int32_t m_material_index{-1}; bool m_has_indices{false}; }; struct Mesh { std::vector<Primitive> m_parts; }; struct Node { int32_t m_parent{-1}; std::vector<uint32_t> m_children; int32_t m_mesh_index{-1}; ror::Matrix4f m_transformation; }; enum class AlphaMode { opaque, mask, blend }; enum class TextureFilter { nearest = 9728, linear = 9729, nearest_mipmap_nearest = 9984, linear_mipmap_nearest = 9985, nearest_mipmap_linear = 9986, linear_mipmap_linear = 9987 }; enum class TextureWrap { clamp_to_edge = 33071, mirrored_repeat = 33648, repeat = 10497 }; struct Material { ror::Vector4f m_base_color_factor{1.0f}; ror::Vector4f m_metalic_roughness_occlusion_factor{1.0f, 1.0f, 1.0f, 1.0f}; ror::Vector4f m_emissive_factor{0.0f, 0.0f, 0.0f, 1.0f}; int32_t m_base_color_texture_index{-1}; int32_t m_metalic_roughness_occlusion_texture_index{-1}; int32_t m_normal_texture_index{-1}; AlphaMode m_alpha_mode{AlphaMode::opaque}; float32_t m_alpha_cutoff{0.5f}; bool m_double_sided{false}; }; struct Sampler { TextureFilter m_mag_filter{TextureFilter::linear}; TextureFilter m_min_filter{TextureFilter::linear_mipmap_linear}; TextureWrap m_wrap_s{TextureWrap::repeat}; TextureWrap m_wrap_t{TextureWrap::repeat}; }; struct Texture { int32_t m_image_index{-1}; int32_t m_sampler_index{-1}; }; // Inspired by https://github.com/SaschaWillems/Vulkan/blob/master/examples/gltfloading/gltfloading.cpp class ROAR_ENGINE_ITEM GLTFModel { public: FORCE_INLINE GLTFModel() = default; //! Default constructor FORCE_INLINE GLTFModel(const GLTFModel &a_other) = default; //! Copy constructor FORCE_INLINE GLTFModel(GLTFModel &&a_other) noexcept = default; //! Move constructor FORCE_INLINE GLTFModel &operator=(const GLTFModel &a_other) = default; //! Copy assignment operator FORCE_INLINE GLTFModel &operator=(GLTFModel &&a_other) noexcept = default; //! Move assignment operator FORCE_INLINE virtual ~GLTFModel() noexcept = default; //! Destructor void virtual temp(); void load_from_file(std::filesystem::path a_filename) { ctpl::thread_pool tp(static_cast<int32_t>(std::thread::hardware_concurrency() - 1)); cgltf_options options{}; // Default setting cgltf_data * data{nullptr}; cgltf_result result = cgltf_parse_file(&options, a_filename.c_str(), &data); cgltf_result buffers_result = cgltf_load_buffers(&options, data, a_filename.c_str()); if (buffers_result != cgltf_result_success) ror::log_critical("Can't load gltf binary data"); std::filesystem::path root_dir = a_filename.parent_path(); if (result == cgltf_result_success) { std::unordered_map<cgltf_image *, int32_t> image_to_index{}; std::unordered_map<cgltf_sampler *, int32_t> sampler_to_index{}; std::unordered_map<cgltf_texture *, int32_t> texture_to_index{}; std::unordered_map<cgltf_material *, int32_t> material_to_index{}; std::unordered_map<cgltf_buffer *, int32_t> buffer_to_index{}; std::unordered_map<cgltf_mesh *, int32_t> mesh_to_index{}; std::unordered_map<cgltf_node *, uint32_t> node_to_index{}; std::vector<std::future<utl::TextureImage>> future_texures{data->images_count}; auto lambda = [&](int a_thread_id, std::filesystem::path& a_texture_path) -> utl::TextureImage { (void) a_thread_id; // ror::log_critical("Going to load texture {}", a_texture_path.c_str()); return utl::read_texture_from_file(a_texture_path.c_str()); }; // Read all the images for (size_t i = 0; i < data->images_count; ++i) { assert(data->images[i].uri && "Image URI is null, only support URI based images"); auto texture_path = root_dir / data->images[i].uri; future_texures[i] = tp.push(lambda, texture_path); image_to_index.emplace(&data->images[i], i); } for (size_t i = 0; i < data->images_count; ++i) { this->m_images.emplace_back(future_texures[i].get()); } // Lets have a default sampler at index 0 this->m_samplers.emplace_back(); // Read all the samplers for (size_t i = 0; i < data->samplers_count; ++i) { Sampler sampler; sampler.m_mag_filter = static_cast<TextureFilter>(data->samplers[i].mag_filter); sampler.m_min_filter = static_cast<TextureFilter>(data->samplers[i].min_filter); sampler.m_wrap_s = static_cast<TextureWrap>(data->samplers[i].wrap_s); sampler.m_wrap_t = static_cast<TextureWrap>(data->samplers[i].wrap_t); this->m_samplers.emplace_back(sampler); sampler_to_index.emplace(&data->samplers[i], i + 1); // Index 0 is default hence the +1 } for (size_t i = 0; i < data->textures_count; ++i) { assert(data->textures[i].image && "Texture must have an image"); Texture t; t.m_image_index = (image_to_index.find(data->textures[i].image) != image_to_index.end() ? image_to_index[data->textures[i].image] : -1); assert(t.m_image_index != -1 && "No image loaded for the texture"); if (data->textures[i].sampler != nullptr) { t.m_sampler_index = (sampler_to_index.find(data->textures[i].sampler) != sampler_to_index.end() ? sampler_to_index[data->textures[i].sampler] : -1); } // If no samplers provided use default at index 0 if (t.m_sampler_index == -1) t.m_sampler_index = 0; this->m_textures.emplace_back(t); texture_to_index.emplace(&data->textures[i], i); } // Read all the materials for (size_t i = 0; i < data->materials_count; ++i) { auto convert_to_vec4 = [](float input[4]) { return ror::Vector4f{input[0], input[1], input[2], input[3]}; }; cgltf_material &mat = data->materials[i]; Material material; material.m_double_sided = mat.double_sided; material.m_alpha_cutoff = mat.alpha_cutoff; if (mat.has_pbr_metallic_roughness) { material.m_base_color_factor = convert_to_vec4(mat.pbr_metallic_roughness.base_color_factor); material.m_metalic_roughness_occlusion_factor.x = mat.pbr_metallic_roughness.metallic_factor; material.m_metalic_roughness_occlusion_factor.y = mat.pbr_metallic_roughness.roughness_factor; material.m_metalic_roughness_occlusion_texture_index = texture_to_index.find(mat.pbr_metallic_roughness.metallic_roughness_texture.texture) != texture_to_index.end() ? texture_to_index[mat.pbr_metallic_roughness.metallic_roughness_texture.texture] : -1; material.m_base_color_texture_index = texture_to_index.find(mat.pbr_metallic_roughness.base_color_texture.texture) != texture_to_index.end() ? texture_to_index[mat.pbr_metallic_roughness.base_color_texture.texture] : -1; } material.m_normal_texture_index = texture_to_index.find(mat.normal_texture.texture) != texture_to_index.end() ? texture_to_index[mat.normal_texture.texture] : -1; switch (mat.alpha_mode) { case cgltf_alpha_mode_opaque: material.m_alpha_mode = AlphaMode::opaque; break; case cgltf_alpha_mode_mask: material.m_alpha_mode = AlphaMode::mask; break; case cgltf_alpha_mode_blend: material.m_alpha_mode = AlphaMode::blend; break; } material_to_index.emplace(&mat, i); } assert(data->buffers_count > 0 && "No buffers loaded"); for (size_t i = 0; i < data->buffers_count; ++i) { std::vector<uint8_t> buffer(static_cast<uint8_t *>(data->buffers[i].data), static_cast<uint8_t *>(data->buffers[i].data) + data->buffers[i].size); this->m_buffers.emplace_back(buffer); buffer_to_index.emplace(&data->buffers[i], i); } // Read all the meshes for (size_t i = 0; i < data->meshes_count; ++i) { Mesh mesh; cgltf_mesh &cmesh = data->meshes[i]; for (size_t j = 0; j < cmesh.primitives_count; ++j) { cgltf_primitive &cprim = cmesh.primitives[j]; Primitive prim{}; if (cprim.has_draco_mesh_compression) ror::log_critical("Mesh has draco mesh compression but its not supported"); if (cprim.material) prim.m_material_index = material_to_index.find(cprim.material) != material_to_index.end() ? material_to_index[cprim.material] : -1; assert(cprim.type == cgltf_primitive_type_triangles && "Mesh primitive type is not triangles which is the only supported type at the moment"); if (cprim.indices) { assert(cprim.indices->type == cgltf_type_scalar && "Indices are not the right type, only SCALAR indices supported"); assert(cprim.indices->component_type == cgltf_component_type_r_16u && "Indices are not in the right component right, only uint16_t supported"); assert(cprim.indices->buffer_view && "Indices doesn't have a valid buffer view"); // assert(cprim.indices->buffer_view->type == cgltf_buffer_view_type_indices && "Indices buffer view type is wrong"); type is alway invalid, because no such thing in bufferView in glTF if (cprim.indices->buffer_view->has_meshopt_compression) ror::log_critical("Mesh has meshopt_compression but its not supported"); prim.m_has_indices = true; prim.m_arrays[array_index::indices].m_count = cprim.indices->count; prim.m_arrays[array_index::indices].m_buffer_index = buffer_to_index.find(cprim.indices->buffer_view->buffer) != buffer_to_index.end() ? buffer_to_index[cprim.indices->buffer_view->buffer] : -1; prim.m_arrays[array_index::indices].m_offset = cprim.indices->buffer_view->offset; } for (size_t k = 0; k < cmesh.primitives[j].attributes_count; ++k) { cgltf_attribute &attrib = cmesh.primitives[j].attributes[k]; assert(attrib.data->buffer_view && "Attribute doesn't have a valid buffer view"); array_index current_index = array_index::position; switch (attrib.type) { case cgltf_attribute_type_position: assert(attrib.data->component_type == cgltf_component_type_r_32f && attrib.data->type == cgltf_type_vec3 && "Position not in the right format, float3 required"); current_index = array_index::position; break; case cgltf_attribute_type_normal: current_index = array_index::normal; assert(attrib.data->component_type == cgltf_component_type_r_32f && attrib.data->type == cgltf_type_vec3 && "Normal not in the right format, float3 required"); break; case cgltf_attribute_type_texcoord: current_index = array_index::texture_coordinate; assert(attrib.data->component_type == cgltf_component_type_r_32f && attrib.data->type == cgltf_type_vec2 && "Texture coordinate not in the right format, float2 required"); break; case cgltf_attribute_type_color: current_index = array_index::color; assert(attrib.data->component_type == cgltf_component_type_r_32f && attrib.data->type == cgltf_type_vec3 && "Color not in the right format, float3 required"); break; case cgltf_attribute_type_tangent: case cgltf_attribute_type_joints: case cgltf_attribute_type_weights: case cgltf_attribute_type_invalid: assert(0 && "Attribute not supported yet"); break; } assert(attrib.data->buffer_view != nullptr && "No buffer view present in attribute accessor"); assert(!attrib.data->is_sparse && "Don't support sparse attribute accessors"); prim.m_arrays[current_index].m_buffer_index = buffer_to_index.find(attrib.data->buffer_view->buffer) != buffer_to_index.end() ? buffer_to_index[attrib.data->buffer_view->buffer] : -1; prim.m_arrays[current_index].m_count = attrib.data->count; prim.m_arrays[current_index].m_offset = attrib.data->buffer_view->offset; } mesh.m_parts.emplace_back(prim); } m_meshes.emplace_back(mesh); mesh_to_index.emplace(&cmesh, i); } // Read all the nodes for (size_t i = 0; i < data->nodes_count; ++i) { cgltf_node &cnode = data->nodes[i]; Node node; node.m_mesh_index = utl::static_cast_safe<int32_t>(i); this->m_nodes.emplace_back(node); // Will fill the rest later node_to_index.emplace(&cnode, i); } // Read the scene // Flattens all scenes into a node tree for (size_t i = 0; i < data->scenes_count; ++i) { Node node; cgltf_scene &scene = data->scenes[i]; for (size_t j = 0; j < scene.nodes_count; ++j) { cgltf_node *cnode = scene.nodes[j]; node.m_mesh_index = mesh_to_index.find(cnode->mesh) != mesh_to_index.end() ? mesh_to_index[cnode->mesh] : -1; cgltf_node_transform_local(cnode, node.m_transformation.m_values); for (size_t k = 0; k < cnode->children_count; ++k) { assert(node_to_index.find(cnode->children[k]) != node_to_index.end() && "Children not found in the inserted nodes"); uint32_t child_index = node_to_index[cnode->children[k]]; if (cnode->children[k]->mesh) this->m_nodes[child_index].m_mesh_index = mesh_to_index.find(cnode->children[k]->mesh) != mesh_to_index.end() ? mesh_to_index[cnode->children[k]->mesh] : -1; cgltf_node_transform_local(cnode->children[k], this->m_nodes[child_index].m_transformation.m_values); this->m_nodes[child_index].m_parent = utl::static_cast_safe<int32_t>(node_to_index[cnode]); node.m_children.push_back(child_index); } } } cgltf_free(data); } else { ror::log_critical("Can't load gltf file {}", a_filename.c_str()); } } protected: private: std::vector<utl::TextureImage> m_images; std::vector<Texture> m_textures; std::vector<Sampler> m_samplers; std::vector<Material> m_materials; std::vector<Mesh> m_meshes; std::vector<Node> m_nodes; std::vector<std::vector<uint8_t>> m_buffers; // Single set of buffers for all data }; void GLTFModel::temp() {} } // namespace ast
36.748315
258
0.691433
[ "mesh", "vector" ]
327c76ea8c2c02b21abce51e1210ccf0f09d2186
21,641
cpp
C++
IGraphics/Controls/IControls.cpp
onqel/iPlug2
d6d4c45935119fe87bf9049861a2e004df605b80
[ "Zlib" ]
null
null
null
IGraphics/Controls/IControls.cpp
onqel/iPlug2
d6d4c45935119fe87bf9049861a2e004df605b80
[ "Zlib" ]
null
null
null
IGraphics/Controls/IControls.cpp
onqel/iPlug2
d6d4c45935119fe87bf9049861a2e004df605b80
[ "Zlib" ]
null
null
null
/* ============================================================================== This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers. See LICENSE.txt for more info. ============================================================================== */ /** * @file * @brief IControls implementation * @ingroup Controls */ #include "IControls.h" #pragma mark - VECTOR CONTROLS const IColor IVKeyboardControl::DEFAULT_BK_COLOR = IColor(255, 70, 70, 70); const IColor IVKeyboardControl::DEFAULT_WK_COLOR = IColor(255, 240, 240, 240); const IColor IVKeyboardControl::DEFAULT_PK_COLOR = IColor(60, 0, 0, 0); const IColor IVKeyboardControl::DEFAULT_FR_COLOR = DEFAULT_BK_COLOR; IVButtonControl::IVButtonControl(IRECT bounds, IActionFunction actionFunc, const char* label, const IVStyle& style, bool labelInButton, bool valueInButton, IVShape shape, float angle) : IButtonControlBase(bounds, actionFunc) , IVectorBase(style, labelInButton, valueInButton) , mShape(shape) , mAngle(angle) { mText = style.valueText; AttachIControl(this, label); mDblAsSingleClick = true; } void IVButtonControl::Draw(IGraphics& g) { DrawBackGround(g, mRECT); DrawWidget(g); DrawLabel(g); DrawValue(g, false); } void IVButtonControl::DrawWidget(IGraphics& g) { bool pressed = (bool) GetValue(); switch (mShape) { case kVShapeCircle: DrawPressableCircle(g, mWidgetBounds, mWidgetBounds.W()/3.5f /*TODO: fix bodge*/, pressed, mMouseIsOver); break; case kVShapeRectangle: DrawPressableRectangle(g, mWidgetBounds, pressed, mMouseIsOver); break; case kVShapeTriangle: DrawPressableTriangle(g, mWidgetBounds, mAngle, pressed, mMouseIsOver); break; default: break; } } void IVButtonControl::OnResize() { SetTargetRECT(CalculateRects(mRECT, true)); SetDirty(false); } bool IVButtonControl::IsHit(float x, float y) const { return mWidgetBounds.Contains(x, y); } IVSwitchControl::IVSwitchControl(IRECT bounds, int paramIdx, const char* label, const IVStyle& style, bool valueInButton) : ISwitchControlBase(bounds, paramIdx, SplashClickActionFunc) , IVectorBase(style, false, valueInButton) { AttachIControl(this, label); mText = style.valueText; if(valueInButton) mText.mVAlign = mStyle.valueText.mVAlign = IText::kVAlignMiddle; mDblAsSingleClick = true; } IVSwitchControl::IVSwitchControl(IRECT bounds, IActionFunction actionFunc, const char* label, const IVStyle& style, int numStates, bool valueInButton) : ISwitchControlBase(bounds, kNoParameter, actionFunc, numStates) , IVectorBase(style, false, valueInButton) { AttachIControl(this, label); mText = style.valueText; if(valueInButton) mText.mVAlign = mStyle.valueText.mVAlign = IText::kVAlignMiddle; mDblAsSingleClick = true; } void IVSwitchControl::Draw(IGraphics& g) { DrawBackGround(g, mRECT); DrawWidget(g); DrawLabel(g); DrawValue(g, false); } void IVSwitchControl::DrawWidget(IGraphics& g) { DrawPressableRectangle(g, mWidgetBounds, mMouseDown, mMouseIsOver); } void IVSwitchControl::SetDirty(bool push, int valIdx) { IControl::SetDirty(push); const IParam* pParam = GetParam(); if(pParam) pParam->GetDisplayForHost(mValueStr); } void IVSwitchControl::OnResize() { SetTargetRECT(CalculateRects(mRECT, true)); SetDirty(false); } bool IVSwitchControl::IsHit(float x, float y) const { return mWidgetBounds.Contains(x, y); } IVToggleControl::IVToggleControl(IRECT bounds, int paramIdx, const char* offText, const char* onText, const char* label, const IVStyle& style) : IVSwitchControl(bounds, paramIdx, label, style, true) , mOnText(onText) , mOffText(offText) { //TODO: assert boolean? } IVToggleControl::IVToggleControl(IRECT bounds, IActionFunction actionFunc, const char* offText, const char* onText, const char* label, const IVStyle& style, bool initialState) : IVSwitchControl(bounds, actionFunc, label, style, 2, true) , mOnText(onText) , mOffText(offText) { SetValue((double) initialState); } void IVToggleControl::DrawValue(IGraphics& g, bool mouseOver) { if(mouseOver) g.FillRect(COLOR_TRANSLUCENT, mValueBounds); if(GetValue() > 0.5) g.DrawText(mStyle.valueText, mOnText.Get(), mValueBounds); else g.DrawText(mStyle.valueText, mOffText.Get(), mValueBounds); } IVRadioButtonControl::IVRadioButtonControl(IRECT bounds, int paramIdx, IActionFunction actionFunc, int numStates, const char* label, const IVStyle& style, IVShape shape, float buttonSize) : ISwitchControlBase(bounds, paramIdx, actionFunc, numStates) , IVectorBase(style) , mShape(shape) , mButtonSize(buttonSize) { AttachIControl(this, label); mDblAsSingleClick = true; mText = style.valueText; mText.mAlign = IText::kAlignNear; //TODO? mText.mVAlign = IText::kVAlignMiddle; //TODO? mStyle.drawShadows = false; //TODO? if(GetParam()) { for (int i = 0; i < mNumStates; i++) { mLabels.Add(new WDL_String(GetParam()->GetDisplayText(i))); } } } IVRadioButtonControl::IVRadioButtonControl(IRECT bounds, IActionFunction actionFunc, const std::initializer_list<const char*>& options, const char* label, const IVStyle& style, IVShape shape, float buttonSize) : ISwitchControlBase(bounds, kNoParameter, actionFunc, static_cast<int>(options.size())) , IVectorBase(style) , mShape(shape) , mButtonSize(buttonSize) { AttachIControl(this, label); mDblAsSingleClick = true; mText = style.valueText; mText.mAlign = mStyle.valueText.mAlign = IText::kAlignNear; //TODO? mText.mVAlign = mStyle.valueText.mVAlign = IText::kVAlignMiddle; //TODO? for (auto& option : options) { mLabels.Add(new WDL_String(option)); } } void IVRadioButtonControl::Draw(IGraphics& g) { DrawBackGround(g, mRECT); DrawLabel(g); DrawWidget(g); } void IVRadioButtonControl::DrawButton(IGraphics& g, const IRECT& r, bool pressed, bool mouseOver) { switch (mShape) { case kVShapeCircle: DrawPressableCircle(g, r.FracRectHorizontal(0.25f), mButtonSize, pressed, mouseOver); break; case kVShapeRectangle: DrawPressableRectangle(g, r.FracRectHorizontal(0.25f).GetCentredInside(mButtonSize), pressed, mouseOver); break; case kVShapeTriangle: DrawPressableTriangle(g, r.FracRectHorizontal(0.25f).GetCentredInside(mButtonSize), 90., pressed, mouseOver); break; default: break; } } void IVRadioButtonControl::DrawWidget(IGraphics& g) { int hit = GetSelectedIdx(); for (int i = 0; i < mNumStates; i++) { IRECT r = mButtons.Get()[i]; DrawButton(g, r, i == hit, mMouseOverButton == i); if (mLabels.Get(i)) { r = r.FracRectHorizontal(0.7f, true); i == hit ? mText.mFGColor = COLOR_WHITE : mText.mFGColor = COLOR_BLACK; g.DrawText(mText, mLabels.Get(i)->Get(), r); } } } bool IVRadioButtonControl::IsHit(float x, float y) const { bool hit = false; for (int i = 0; i < mNumStates; i++) { hit |= mButtons.Get()[i].FracRectHorizontal(0.25f).Contains(x, y); } return hit; } void IVRadioButtonControl::OnMouseDown(float x, float y, const IMouseMod& mod) { int hit = -1; for (int i = 0; i < mNumStates; i++) { if(mButtons.Get()[i].FracRectHorizontal(0.25f).Contains(x, y)) { hit = i; break; } } if(hit > -1) SetValue(((double) hit * (1./(double) (mNumStates-1)))); SetDirty(true); } void IVRadioButtonControl::OnMouseOver(float x, float y, const IMouseMod& mod) { mMouseOverButton = -1; for (int i = 0; i < mNumStates; i++) { if(mButtons.Get()[i].FracRectHorizontal(0.25f).Contains(x, y)) { mMouseOverButton = i; break; } } ISwitchControlBase::OnMouseOver(x, y, mod); SetDirty(false); } void IVRadioButtonControl::OnResize() { SetTargetRECT(CalculateRects(mRECT)); mButtons.Resize(0); for (int i = 0; i < mNumStates; i++) { mButtons.Add(mWidgetBounds.SubRect(kVertical /*TODO: optional direction*/, mNumStates, i)); } SetDirty(false); } IVKnobControl::IVKnobControl(IRECT bounds, int paramIdx, const char* label, const IVStyle& style, bool valueIsEditable, float aMin, float aMax, EDirection direction, double gearing) : IKnobControlBase(bounds, paramIdx, direction, gearing) , IVectorBase(style) , mAngleMin(aMin) , mAngleMax(aMax) { DisablePrompt(!valueIsEditable); mText = style.valueText; AttachIControl(this, label); } IVKnobControl::IVKnobControl(IRECT bounds, IActionFunction actionFunction, const char* label, const IVStyle& style, bool valueIsEditable, float aMin, float aMax, EDirection direction, double gearing) : IKnobControlBase(bounds, kNoParameter, direction, gearing) , IVectorBase(style) , mAngleMin(aMin) , mAngleMax(aMax) { DisablePrompt(!valueIsEditable); mText = style.valueText; SetActionFunction(actionFunction); AttachIControl(this, label); } void IVKnobControl::Draw(IGraphics& g) { DrawBackGround(g, mRECT); DrawWidget(g); DrawLabel(g); DrawValue(g, mValueMouseOver); } void IVKnobControl::DrawWidget(IGraphics& g) { float radius; if(mWidgetBounds.W() > mWidgetBounds.H()) radius = (mWidgetBounds.H()/2.5f /*TODO: fix bodge*/); else radius = (mWidgetBounds.W()/2.5f /*TODO: fix bodge*/); const float cx = mWidgetBounds.MW(), cy = mWidgetBounds.MH(); if(!IsGrayed()) { const float v = mAngleMin + ((float) GetValue() * (mAngleMax - mAngleMin)); g.DrawArc(GetColor(kFR), cx, cy, radius + 5.f, mAngleMin, v, 0, 3.f); DrawPressableCircle(g, mWidgetBounds, radius, false, mMouseIsOver & !mValueMouseOver); g.DrawRadialLine(GetColor(kFR), cx, cy, v, 0.7f * radius, 0.9f * radius, 0, mStyle.frameThickness); } else { g.FillCircle(GetColor(kOFF), cx, cy, radius); } } void IVKnobControl::OnMouseDown(float x, float y, const IMouseMod& mod) { if(mStyle.showValue && mValueBounds.Contains(x, y)) { PromptUserInput(mValueBounds); } else { if(mStyle.hideCursor) GetUI()->HideMouseCursor(true, true); IKnobControlBase::OnMouseDown(x, y, mod); } } void IVKnobControl::OnMouseUp(float x, float y, const IMouseMod& mod) { if(mStyle.hideCursor) GetUI()->HideMouseCursor(false); SetDirty(true); } void IVKnobControl::OnMouseOver(float x, float y, const IMouseMod& mod) { if(mStyle.showValue && !mDisablePrompt) mValueMouseOver = mValueBounds.Contains(x,y); IKnobControlBase::OnMouseOver(x, y, mod); } void IVKnobControl::OnResize() { SetTargetRECT(CalculateRects(mRECT)); SetDirty(false); } bool IVKnobControl::IsHit(float x, float y) const { if(!mDisablePrompt) { if(mValueBounds.Contains(x,y)) return true; } return mWidgetBounds.Contains(x, y); } void IVKnobControl::SetDirty(bool push, int valIdx) { IKnobControlBase::SetDirty(push); const IParam* pParam = GetParam(); if(pParam) pParam->GetDisplayForHostWithLabel(mValueStr); } void IVKnobControl::OnInit() { const IParam* pParam = GetParam(); if(pParam) pParam->GetDisplayForHostWithLabel(mValueStr); } IVSliderControl::IVSliderControl(IRECT bounds, int paramIdx, const char* label, const IVStyle& style, bool valueIsEditable, EDirection dir, bool onlyHandle, float handleSize, float trackSize) : ISliderControlBase(bounds, paramIdx, dir, onlyHandle, handleSize) , IVectorBase(style) , mTrackSize(trackSize) { DisablePrompt(!valueIsEditable); mText = style.valueText; AttachIControl(this, label); } IVSliderControl::IVSliderControl(IRECT bounds, IActionFunction aF, const char* label, const IVStyle& style, bool valueIsEditable, EDirection dir, bool onlyHandle, float handleSize, float trackSize) : ISliderControlBase(bounds, aF, dir, onlyHandle, handleSize) , IVectorBase(style) , mTrackSize(trackSize) { DisablePrompt(!valueIsEditable); mText = style.valueText; AttachIControl(this, label); } void IVSliderControl::Draw(IGraphics& g) { DrawBackGround(g, mRECT); DrawWidget(g); DrawLabel(g); DrawValue(g, mValueMouseOver); } void IVSliderControl::DrawWidget(IGraphics& g) { const float halfHandleSize = mHandleSize / 2.f; //track IRECT filledTrack = mTrack.FracRect(mDirection, (float) GetValue()); g.FillRect(GetColor(kSH), mTrack); g.FillRect(GetColor(kFG), filledTrack); g.DrawRect(GetColor(kFR), mTrack); float cx, cy; if(mDirection == kVertical) { cx = filledTrack.MW(); cy = filledTrack.T; } else { cx = filledTrack.R; cy = filledTrack.MH(); } //Handle if(mStyle.drawShadows && !mStyle.emboss) g.FillCircle(GetColor(kSH), cx + mStyle.shadowOffset, cy + mStyle.shadowOffset, halfHandleSize); g.FillCircle(GetColor(kFG), cx, cy, halfHandleSize); if(GetMouseIsOver()) g.FillCircle(GetColor(kHL), cx, cy, halfHandleSize); g.DrawCircle(GetColor(kFR), cx, cy, halfHandleSize, 0, mStyle.frameThickness); g.DrawCircle(GetColor(kON), cx, cy, halfHandleSize * 0.7f, 0, mStyle.frameThickness); } void IVSliderControl::OnMouseDown(float x, float y, const IMouseMod& mod) { if(mStyle.showValue && mValueBounds.Contains(x, y)) { PromptUserInput(mValueBounds); } else { if(mStyle.hideCursor) GetUI()->HideMouseCursor(true, false); ISliderControlBase::OnMouseDown(x, y, mod); } } void IVSliderControl::OnMouseUp(float x, float y, const IMouseMod& mod) { if(mStyle.hideCursor) GetUI()->HideMouseCursor(false); SetDirty(true); } void IVSliderControl::OnMouseOver(float x, float y, const IMouseMod& mod) { if(mStyle.showValue && !mDisablePrompt) mValueMouseOver = mValueBounds.Contains(x,y); ISliderControlBase::OnMouseOver(x, y, mod); } void IVSliderControl::OnResize() { SetTargetRECT(CalculateRects(mRECT)); if(mDirection == kVertical) mTrack = mWidgetBounds.GetPadded(-mHandleSize).GetMidHPadded(mTrackSize); else mTrack = mWidgetBounds.GetPadded(-mHandleSize).GetMidVPadded(mTrackSize); SetDirty(false); } bool IVSliderControl::IsHit(float x, float y) const { if(!mDisablePrompt) { if(mValueBounds.Contains(x,y)) { return true; } } return mWidgetBounds.Contains(x, y); } void IVSliderControl::SetDirty(bool push, int valIdx) { ISliderControlBase::SetDirty(push); const IParam* pParam = GetParam(); if(pParam) pParam->GetDisplayForHostWithLabel(mValueStr); } void IVSliderControl::OnInit() { const IParam* pParam = GetParam(); if(pParam) pParam->GetDisplayForHostWithLabel(mValueStr); } IVRangeSliderControl::IVRangeSliderControl(IRECT bounds, int paramIdxLo, int paramIdxHi, const char* label, const IVStyle& style, // bool valueIsEditable = false, EDirection dir, bool onlyHandle, float handleSize, float trackSize) : IVSliderControl(bounds, paramIdxLo, label, style, false, dir, onlyHandle, handleSize, trackSize) { SetNVals(2); SetParamIdx(paramIdxLo, 0); SetParamIdx(paramIdxHi, 1); } void IVRangeSliderControl::DrawWidget(IGraphics & g) { g.FillRect(GetColor(kBG), mWidgetBounds); //const float halfHandleSize = mHandleSize / 2.f; //track const float minVal = (float) std::min(GetValue(0), GetValue(1)); const float maxVal = (float) std::max(GetValue(0), GetValue(1)); IRECT filledTrack = { mTrack.L, mTrack.B - (maxVal * mTrack.H()), mTrack.R, mTrack.B - (minVal * mTrack.H()) }; g.FillRect(GetColor(kSH), mTrack); g.FillRect(GetColor(kFG), filledTrack); g.DrawRect(GetColor(kFR), mTrack); float cx[2]; float cy[2]; if (mDirection == kVertical) { cx[0] = cx[1] = filledTrack.MW(); cy[0] = filledTrack.T; cy[1] = filledTrack.B; } else { cx[0] = filledTrack.L; cx[1] = filledTrack.R; cy[0] = cy[1] = filledTrack.MH(); } ////Handles //for (int i = 0; i < 2; i++) //{ // if (mDrawShadows && !mEmboss) // g.FillCircle(GetColor(kSH), cx[i] + mShadowOffset, cy[i] + mShadowOffset, halfHandleSize); // g.FillCircle(GetColor(kFG), cx[i], cy[i], halfHandleSize); // if (GetMouseIsOver()) // g.FillCircle(GetColor(kHL), cx[i], cy[i], halfHandleSize); // g.DrawCircle(GetColor(kFR), cx[i], cy[i], halfHandleSize, 0, mFrameThickness); // g.DrawCircle(GetColor(kON), cx[i], cy[i], halfHandleSize * 0.7f, 0, mFrameThickness); //} } void IVRangeSliderControl::OnMouseDown(float x, float y, const IMouseMod & mod) { if(mDirection == kVertical) mMouseDownVal = 1.f - (y-mRECT.T) / mRECT.H(); else mMouseDownVal = (x-mRECT.L) / mRECT.W(); } void IVRangeSliderControl::OnMouseDrag(float x, float y, float dX, float dY, const IMouseMod & mod) { SnapToMouse(x, y, mDirection, mTrack); } void IVRangeSliderControl::SnapToMouse(float x, float y, EDirection direction, IRECT& bounds, int valIdx, float scalar /* TODO: scalar! */) { bounds.Constrain(x, y); double newVal; if(direction == kVertical) newVal = 1.f - (y-bounds.T) / bounds.H(); else newVal = (x-bounds.L) / bounds.W(); double* pHighVal; double* pLowVal; if(mMouseDownVal > newVal) { pHighVal = &mMouseDownVal; pLowVal = &newVal; } else { pHighVal = &newVal; pLowVal = &mMouseDownVal; } SetValue(std::round(*pHighVal / 0.001 ) * 0.001, 0); SetValue(std::round(*pLowVal / 0.001 ) * 0.001, 1); SetDirty(true, valIdx); } IVXYPadControl::IVXYPadControl(IRECT bounds, const std::initializer_list<int>& params, const char* label, const IVStyle& style, float handleRadius) : IControl(bounds, params) , IVectorBase(style) , mHandleRadius(handleRadius) { AttachIControl(this, label); } void IVXYPadControl::Draw(IGraphics& g) { DrawBackGround(g, mRECT); DrawLabel(g); if(mStyle.drawFrame) g.DrawRect(GetColor(kFR), mWidgetBounds, nullptr, mStyle.frameThickness); DrawWidget(g); } void IVXYPadControl::DrawWidget(IGraphics& g) { float xpos = GetValue(0) * mWidgetBounds.W(); float ypos = GetValue(1) * mWidgetBounds.H(); g.DrawVerticalLine(GetColor(kSH), mWidgetBounds, 0.5); g.DrawHorizontalLine(GetColor(kSH), mWidgetBounds, 0.5); g.PathClipRegion(mWidgetBounds.GetPadded(-0.5 * mStyle.frameThickness)); DrawPressableCircle(g, IRECT(mWidgetBounds.L + xpos-mHandleRadius, mWidgetBounds.B - ypos-mHandleRadius, mWidgetBounds.L + xpos+mHandleRadius, mWidgetBounds.B -ypos+mHandleRadius), mHandleRadius, mMouseDown, mMouseIsOver); } void IVXYPadControl::OnMouseDown(float x, float y, const IMouseMod& mod) { mMouseDown = true; if(mStyle.hideCursor) GetUI()->HideMouseCursor(true, false); OnMouseDrag(x, y, 0., 0., mod); } void IVXYPadControl::OnMouseUp(float x, float y, const IMouseMod& mod) { if(mStyle.hideCursor) GetUI()->HideMouseCursor(false); mMouseDown = false; SetDirty(true); } void IVXYPadControl::OnMouseDrag(float x, float y, float dX, float dY, const IMouseMod& mod) { mRECT.Constrain(x, y); float xn = (x - mRECT.L) / mRECT.W(); float yn = 1.f - ((y - mRECT.T) / mRECT.H()); SetValue(xn, 0); SetValue(yn, 1); SetDirty(true); } void IVXYPadControl::OnResize() { SetTargetRECT(CalculateRects(mRECT)); SetDirty(false); } #pragma mark - BITMAP CONTROLS void IBSwitchControl::OnMouseDown(float x, float y, const IMouseMod& mod) { if (mBitmap.N() > 1) SetValue(GetValue() + 1.0 / (double)(mBitmap.N() - 1)); else SetValue(GetValue() + 1.0); if (GetValue() > 1.001) SetValue(0.); SetDirty(); } IBSliderControl::IBSliderControl(IRECT bounds, int paramIdx, const IBitmap& bitmap, EDirection dir, bool onlyHandle) : ISliderControlBase(bounds, paramIdx, dir, onlyHandle) , IBitmapBase(bitmap) { mTrack = bounds; // TODO: check } IBSliderControl::IBSliderControl(float x, float y, int len, int paramIdx, const IBitmap& bitmap, EDirection dir, bool onlyHandle) : ISliderControlBase(IRECT(x, y, x + bitmap.W(), y + len), paramIdx) , IBitmapBase(bitmap) { if (dir == kVertical) { mRECT = mTargetRECT = IRECT(x, y, x + bitmap.W(), y + len); mTrack = mRECT.GetPadded(0, -(float) bitmap.H(), 0, 0); } else { mRECT = mTargetRECT = IRECT(x, y, x + len, y + bitmap.H()); mTrack = mRECT.GetPadded(0, 0, -(float) bitmap.W(), 0); } } void IBSliderControl::Draw(IGraphics& g) { IRECT r = GetHandleBounds(); g.DrawBitmap(mBitmap, r, 1, &mBlend); } void IBSliderControl::OnRescale() { mBitmap = GetUI()->GetScaledBitmap(mBitmap); } void IBSliderControl::OnResize() { SetDirty(false); } IRECT IBSliderControl::GetHandleBounds(double value) const { if (value < 0.0) value = GetValue(); IRECT r(mRECT.L, mRECT.T, mRECT.L + mBitmap.W(), mRECT.T + mBitmap.H()); if (mDirection == kVertical) { float offs = (1.f - (float) value) * mTrack.H(); r.T += offs; r.B += offs; } else { float offs = (float) value * mTrack.W(); r.L += offs; r.R += offs; } return r; }
25.640995
225
0.663139
[ "shape", "vector" ]
327c8a96e872d4229a024db15e79273905df66e9
1,056
cpp
C++
loj/p132.cpp
freedomDR/coding
310a68077de93ef445ccd2929e90ba9c22a9b8eb
[ "MIT" ]
null
null
null
loj/p132.cpp
freedomDR/coding
310a68077de93ef445ccd2929e90ba9c22a9b8eb
[ "MIT" ]
null
null
null
loj/p132.cpp
freedomDR/coding
310a68077de93ef445ccd2929e90ba9c22a9b8eb
[ "MIT" ]
null
null
null
#include<bits/stdc++.h> using namespace std; using ll = long long; inline int lb(int p) { return p & -p; } void add(vector<ll> &a, int p, ll v) { while(p < (int)a.size()) { a[p] += v; p += lb(p); } } ll getSum(vector<ll> &a, int p) { ll sum = 0; while(p > 0) { sum += a[p]; p -= lb(p); } return sum; } int main() { ios::sync_with_stdio(false);cin.tie(0); int n, q; cin >> n >> q; vector<ll> a(n+1), pre(n+1), d1(n+2), d2(n+2); for(int i = 1; i <= n; i++) { cin >> a[i]; pre[i] = pre[i-1] + a[i]; } while(q--) { int op; cin >> op; if(op == 1) { int l, r, v; cin >> l >> r >> v; add(d1, l, v); add(d2, l, 1ll*v*l); add(d1, r+1, -v); add(d2, r+1, 1ll*-v*(r+1)); } else { int l, r; cin >> l >> r; cout << (pre[r]+getSum(d1, r)*(r+1)-getSum(d2,r))-(pre[l-1]+getSum(d1,l-1)*l-getSum(d2,l-1)) << endl; } } return 0; }
18.526316
113
0.393939
[ "vector" ]
32819e83544c705bb50bda581fcf4a9c9cc2ddcd
11,567
cpp
C++
src/QMCTools/LCAOH5Parser.cpp
bwvdg/qmcpack
cd09fc54b36de2579c9802f5e64b7ec15506f3c3
[ "NCSA" ]
null
null
null
src/QMCTools/LCAOH5Parser.cpp
bwvdg/qmcpack
cd09fc54b36de2579c9802f5e64b7ec15506f3c3
[ "NCSA" ]
null
null
null
src/QMCTools/LCAOH5Parser.cpp
bwvdg/qmcpack
cd09fc54b36de2579c9802f5e64b7ec15506f3c3
[ "NCSA" ]
null
null
null
////////////////////////////////////////////////////////////////////////////////////// // This file is distributed under the University of Illinois/NCSA Open Source License. // See LICENSE file in top directory for details. // // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. // // File developed by: Anouar Benali, benali@anl.gov, Argonne National Laboratory // // File created by: Anouar Benali, benali@anl.gov, Argonne National Laboratory ////////////////////////////////////////////////////////////////////////////////////// #include "QMCTools/LCAOH5Parser.h" #include <fstream> #include <iterator> #include <algorithm> #include <set> #include <map> #include <sstream> char *binpad (unsigned long int n, size_t sz); LCAOParser::LCAOParser() { basisName = "Gaussian"; Normalized = "no"; BohrUnit=true; MOtype="Canonical"; angular_type="cartesian"; readtype=0; FixValence=true; NFZC=0; } LCAOParser::LCAOParser(int argc, char** argv): QMCGaussianParserBase(argc,argv) { basisName = "Gaussian"; Normalized = "no"; BohrUnit=true; MOtype="Canonical"; angular_type="cartesian"; SpinRestricted=true; readtype=0; FixValence=true; NFZC=0; } void LCAOParser::parse(const std::string& fname) { hdf_archive hin; if(!hin.open(fname.c_str(),H5F_ACC_RDONLY)) { std::cerr<<"Could not open H5 file"<<std::endl; abort(); } hin.push("application"); hin.read(CodeName,"code"); hin.pop(); std::cout<<"Converting Wavefunction from the "<<CodeName<<" Code"<<std::endl; hin.push("PBC"); hin.read(PBC,"PBC"); hin.pop(); std::cout <<"Periodic Boundary Comditions: " <<(PBC?("yes"):("no")) << std::endl; std::cout.flush(); hin.push("parameters"); hin.read(ECP,"ECP"); std::cout <<"usingECP: " <<(ECP?("yes"):("no")) << std::endl; std::cout.flush(); // multideterminant=false; std::cout <<"Multideterminant: " <<(multideterminant?("yes"):("no")) << std::endl; hin.read(SpinRestricted,"SpinResticted"); if(SpinRestricted) { hin.read(numAO,"numAO"); hin.read(numMO,"numMO"); } else { int numAO_up,numAO_dn,numMO_up,numMO_dn; hin.read(numAO_up,"numAO_up"); hin.read(numMO_up,"numMO_up"); hin.read(numAO_dn,"numAO_dn"); hin.read(numMO_dn,"numMO_dn"); if (numAO_up==numAO_dn) numAO=numAO_up; else { std::cout<<"numAO_up="<<numAO_up<<" numAO_dn="<<numAO_dn<<std::endl; std::cerr<<"The number of AO for the up Orbitals are different than the number of AOs for down orbitals. This is probably an error in your "<<CodeName<<" input. Please contact QMCPACK developers"<<std::endl; abort(); } if (numMO_up==numMO_dn) numMO=numMO_up; else { std::cout<<"numMO_up="<<numMO_up<<" numMO_dn="<<numMO_dn<<std::endl; std::cerr<<"The number of MO for the up Orbitals are different than the number of MOs for down orbitals. This is probably an error in your "<<CodeName<<" input. Please contact QMCPACK developers"<<std::endl; abort(); } } std::cout <<"NUMBER OF AOs: " <<numAO << std::endl; SizeOfBasisSet = numAO; std::cout <<"Size of Basis Set: " <<SizeOfBasisSet << std::endl; std::cout <<"NUMBER OF MOs: " <<numMO << std::endl; bool bohr=true; hin.read(bohr,"Unit"); std::cout<<"Unit in Bohr="<<bohr<<std::endl; BohrUnit=bohr; hin.read(NumberOfAlpha,"NbAlpha"); hin.read(NumberOfBeta,"NbBeta"); hin.read(NumberOfEls,"NbTotElec"); hin.read(SpinMultiplicity,"spin"); std::cout <<"Number of alpha electrons: " <<NumberOfAlpha << std::endl; std::cout <<"Number of beta electrons: " <<NumberOfBeta << std::endl; std::cout <<"Number of electrons: " <<NumberOfEls << std::endl; std::cout <<"SPIN MULTIPLICITY: " <<SpinMultiplicity << std::endl; hin.pop(); hin.push("atoms"); hin.read(NumberOfAtoms,"number_of_atoms"); std::cout <<"NUMBER OF ATOMS: " <<NumberOfAtoms << std::endl; hin.close(); IonSystem.create(NumberOfAtoms); GroupName.resize(NumberOfAtoms); if (PBC){ getCell(fname); getKpts(fname); if (debug){ getGaussianCenters(fname); getMO(fname); } } getGeometry(fname); if(multideterminant) { outputFile; hdf_archive hin; if(!hin.open(outputFile.c_str(),H5F_ACC_RDONLY)) { std::cerr<<"Could not open H5 file"<<std::endl; abort(); } if(!hin.push("MultiDet")) { std::cerr<<"Could not open H5 file"<<std::endl; abort(); } else { hin.read(ci_size,"NbDet"); CIcoeff.clear(); CIalpha.clear(); CIbeta.clear(); CIcoeff.resize(ci_size); CIalpha.resize(ci_size); CIbeta.resize(ci_size); hin.read(ci_nstates,"nstate"); int N_int; const int bit_kind = 64; hin.read(N_int,"Nbits"); Matrix<unsigned long int> tempAlpha(ci_size,N_int); hin.read(tempAlpha,"CI_Alpha"); Matrix<unsigned long int> tempBeta(ci_size,N_int); hin.read(tempBeta,"CI_Beta"); std::string MyCItempAlpha,MyCItempBeta; MyCItempAlpha.resize(ci_nstates+1); MyCItempBeta.resize(ci_nstates+1); for (int ni=0; ni<ci_size;ni++) { int j=0; int jj=0; for (int k=0; k<N_int; k++) { for(int i=0; i<bit_kind;i++) { if ( j <ci_nstates ) { MyCItempAlpha[j] = binpad(tempAlpha[ni][k],bit_kind)[i]; j++; } if ( jj <ci_nstates ) { MyCItempBeta[jj] = binpad(tempBeta[ni][k],bit_kind)[i]; jj++; } } } CIalpha[ni]=MyCItempAlpha; CIbeta[ni]=MyCItempBeta; } hin.read(CIcoeff,"Coeff"); int ds=SpinMultiplicity-1; int neb= (NumberOfEls-ds)/2; int nea= NumberOfEls-NumberOfBeta; ci_nea= NumberOfAlpha; ci_neb= NumberOfBeta; ci_nca = nea-ci_nea; ci_ncb = neb-ci_neb; std::cout <<" Done reading CIs!!"<< std::endl; hin.close(); } } } void LCAOParser::getCell(const std::string& fname) { X.resize(3); Y.resize(3); Z.resize(3); hdf_archive hin; if(!hin.open(fname.c_str(),H5F_ACC_RDONLY)) { std::cerr<<"Could not open H5 file"<<std::endl; abort(); } hin.push("Cell"); Matrix<double> LatticeVec(3,3); hin.read(LatticeVec,"LatticeVectors"); X[0]=LatticeVec[0][0]; X[1]=LatticeVec[0][1]; X[2]=LatticeVec[0][2]; Y[0]=LatticeVec[1][0]; Y[1]=LatticeVec[1][1]; Y[2]=LatticeVec[1][2]; Z[0]=LatticeVec[2][0]; Z[1]=LatticeVec[2][1]; Z[2]=LatticeVec[2][2]; hin.close(); std::cout<<"Lattice parameters in Bohr:"<<std::endl; std::cout<<X[0]<<" "<<X[1]<<" "<<X[2]<<std::endl; std::cout<<Y[0]<<" "<<Y[1]<<" "<<Y[2]<<std::endl; std::cout<<Z[0]<<" "<<Z[1]<<" "<<Z[2]<<std::endl; } void LCAOParser::getGeometry(const std::string& fname) { hdf_archive hin; if(!hin.open(fname.c_str(),H5F_ACC_RDONLY)) { std::cerr<<"Could not open H5 file"<<std::endl; abort(); } hin.push("atoms"); //atomic numbers std::vector<int> atomic_number; std::vector<double> q,pos; tags.clear(); //read atomic info //MAP: (Atom Number, Species Index) std::vector<int> idx(NumberOfAtoms); std::map<int,int> AtomIndexmap; hin.read(idx,"species_ids"); for(int i=0; i<NumberOfAtoms; i++) { AtomIndexmap.insert(std::pair<int,int>(i,idx[i]) ); } for(int i=0; i<NumberOfAtoms; i++) { std::string speciesName("species_"); speciesName=speciesName + std::to_string(AtomIndexmap[i]); hin.push(speciesName); int zint; double z; std::string Name; hin.read(zint,"atomic_number"); atomic_number.push_back(zint); hin.read(z,"charge"); q.push_back(z); hin.read(Name,"name"); tags.push_back(Name); hin.pop(); } Matrix<double> IonPos(NumberOfAtoms,3); hin.read(IonPos,"positions"); SpeciesSet& species(IonSystem.getSpeciesSet()); for(int i=0; i<NumberOfAtoms; i++) { IonSystem.R[i][0]=IonPos[i][0]; IonSystem.R[i][1]=IonPos[i][1]; IonSystem.R[i][2]=IonPos[i][2]; GroupName[i]=IonName[atomic_number[i]]; int speciesID = species.addSpecies(GroupName[i]); IonSystem.GroupID[i]=speciesID; species(AtomicNumberIndex,speciesID)=atomic_number[i]; species(IonChargeIndex,speciesID)=q[i]; } hin.close(); } void LCAOParser::getKpts(const std::string& fname) { Matrix <double> MyVec(1,3); hdf_archive hin; if(!hin.open(fname.c_str(),H5F_ACC_RDONLY)) { std::cerr<<"Could not open H5 file"<<std::endl; abort(); } hin.push("Nb_KPTS"); hin.read(NbKpts,"Nbkpts"); hin.pop(); Kpoints_Coord.resize(NbKpts); for (int i=0; i<NbKpts;i++) { Kpoints_Coord[i].resize(3); std::stringstream ss; ss << "KPTS_" << i; if(!hin.push(ss.str())) { std::cerr<<"Could not find coordinates for Kpoint Nb"<<i<<std::endl; abort(); } hin.read(MyVec,"Coord"); hin.pop(); std::cout<<"MyCoord="<<MyVec[0][0]<<" "<<MyVec[0][1]<<" "<<MyVec[0][2]<<std::endl; Kpoints_Coord[i][0]=MyVec[0][0]; Kpoints_Coord[i][1]=MyVec[0][1]; Kpoints_Coord[i][2]=MyVec[0][2]; } hin.close(); } char *binpad (unsigned long int n, size_t sz) { static char s[64 + 1] = {0}; char *p = s + 64 ; for (int i = sz ; i > 0; i--) *--p = ( (n>> (i-1) ) & 1) ? '1' : '0'; return p; } void LCAOParser::getMO(const std::string & fname) { EigVal_alpha.resize(numMO); EigVal_beta.resize(numMO); EigVec.resize(2*SizeOfBasisSet*numMO); std::string setname; Matrix<double> CartMat(SizeOfBasisSet,SizeOfBasisSet); hdf_archive hin; if(!hin.open(fname.c_str(),H5F_ACC_RDONLY)) { std::cerr<<"Could not open H5 file"<<std::endl; abort(); } char name[72]; sprintf(name,"%s","/KPTS_0/eigenset_0"); setname=name; if(!hin.read(CartMat,setname)) { setname="SPOSet::putFromH5 Missing "+setname+" from HDF5 File."; APP_ABORT(setname.c_str()); } hin.close(); //hin.push("KPTS_0"); //hin.read(CartMat,"eingenset_0"); int cnt=0; for(int i=0; i<numMO; i++) for(int k=0; k<SizeOfBasisSet; k++) EigVec[cnt++] = CartMat[i][k]; int btot=numMO*SizeOfBasisSet; int n=btot/4, b=0; int dn=btot-n*4; std::ostringstream eig; eig.setf(std::ios::scientific, std::ios::floatfield); eig.setf(std::ios::right,std::ios::adjustfield); eig.precision(14); eig << "\n"; for(int k=0; k<n; k++) { eig << std::setw(22) << EigVec[b] << std::setw(22) << EigVec[b+1] << std::setw(22) << EigVec[b+2] << std::setw(22) << EigVec[b+3] << "\n"; b += 4; } for(int k=0; k<dn; k++) { eig << std::setw(22) << EigVec[b++]; } std::cout<<eig.str().c_str()<<std::endl; std::cout <<"Finished reading MO." << std::endl; hin.close(); } void LCAOParser::getGaussianCenters(const std::string fname) { }
25.590708
223
0.561252
[ "vector" ]
328fea593ba0fd1bc466d971f186abe80b34901b
2,338
cpp
C++
src/_leetcode/leet_455.cpp
turesnake/leetPractice
a87b9b90eb8016038d7e5d3ad8e50e4ceb54d69b
[ "MIT" ]
null
null
null
src/_leetcode/leet_455.cpp
turesnake/leetPractice
a87b9b90eb8016038d7e5d3ad8e50e4ceb54d69b
[ "MIT" ]
null
null
null
src/_leetcode/leet_455.cpp
turesnake/leetPractice
a87b9b90eb8016038d7e5d3ad8e50e4ceb54d69b
[ "MIT" ]
null
null
null
/* * ====================== leet_455.cpp ========================== * -- tpr -- * CREATE -- 2020.04.14 * MODIFY -- * ---------------------------------------------------------- * 455. 分发饼干 */ #include "innLeet.h" namespace leet_455 {//~ // 用最小堆来管理 int findContentChildren( std::vector<int>& g, std::vector<int>& s) { if( g.empty() || s.empty() ){ return 0; } std::priority_queue<int, std::vector<int>, std::greater<int>> childs ( std::greater<int>{}, std::move(g) ); std::priority_queue<int, std::vector<int>, std::greater<int>> cooks ( std::greater<int>{}, std::move(s) ); int out {0}; for( ; !(childs.empty()||cooks.empty()); childs.pop(),cooks.pop(),out++ ){ while( cooks.top() < childs.top() ){ cooks.pop(); if( cooks.empty() ){ return out; } } } return out; } // vector原地排序,同时通过 尾端pop 的方式来管理 int findContentChildren_2( std::vector<int>& g, std::vector<int>& s) { if( g.empty() || s.empty() ){ return 0; } std::sort( g.begin(), g.end(), std::greater<int>{} ); std::sort( s.begin(), s.end(), std::greater<int>{} ); int out {0}; for( ; !(g.empty()||s.empty()); g.pop_back(),s.pop_back(),out++ ){ while( s.back() < g.back() ){ s.pop_back(); while( s.empty() ){ return out; } } } return out; } // vector原地排序,用指针来遍历 // 和第二种在性能上没太大区别 int findContentChildren_3( std::vector<int>& g, std::vector<int>& s) { if( g.empty() || s.empty() ){ return 0; } std::sort( g.begin(), g.end() ); std::sort( s.begin(), s.end() ); auto gi = g.begin(); auto si = s.begin(); int out {0}; for( ; gi!=g.end()&&si!=s.end(); gi++,si++,out++ ){ while( *si < *gi ){ si++; if( si==s.end() ){ return out; } } } return out; } //=========================================================// void main_(){ std::vector<int> g { 1,2 }; std::vector<int> s { 1,2,3 }; auto ret = findContentChildren_3( g, s ); cout << "ret = " << ret << endl; debug::log( "\n~~~~ leet: 455 :end ~~~~\n" ); } }//~
24.103093
78
0.420445
[ "vector" ]
3296ab783bebfae5d545a1a5e1e3de44ec639b84
5,911
hpp
C++
sycl/include/CL/sycl/interop_handle.hpp
tiwaria1/llvm
616a396db0610ae0c1992361af005a869ef81897
[ "Apache-2.0" ]
null
null
null
sycl/include/CL/sycl/interop_handle.hpp
tiwaria1/llvm
616a396db0610ae0c1992361af005a869ef81897
[ "Apache-2.0" ]
null
null
null
sycl/include/CL/sycl/interop_handle.hpp
tiwaria1/llvm
616a396db0610ae0c1992361af005a869ef81897
[ "Apache-2.0" ]
null
null
null
//==------------ interop_handle.hpp --- SYCL interop handle ----------------==// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #pragma once #include <CL/sycl/access/access.hpp> #include <CL/sycl/accessor.hpp> #include <CL/sycl/backend_types.hpp> #include <CL/sycl/detail/accessor_impl.hpp> #include <CL/sycl/detail/common.hpp> #include <CL/sycl/detail/defines.hpp> #include <CL/sycl/detail/pi.hpp> #include <memory> __SYCL_INLINE_NAMESPACE(cl) { namespace sycl { namespace detail { class AccessorBaseHost; class ExecCGCommand; class DispatchHostTask; class queue_impl; class device_impl; class context_impl; } // namespace detail class queue; class device; class context; class interop_handle { public: /// Receives a SYCL accessor that has been defined as a requirement for the /// command group, and returns the underlying OpenCL memory object that is /// used by the SYCL runtime. If the accessor passed as parameter is not part /// of the command group requirements (e.g. it is an unregistered placeholder /// accessor), the exception `cl::sycl::invalid_object` is thrown /// asynchronously. template <backend BackendName = backend::opencl, typename DataT, int Dims, access::mode Mode, access::target Target, access::placeholder IsPlh> typename std::enable_if< Target != access::target::host_buffer, typename interop<BackendName, accessor<DataT, Dims, Mode, Target, IsPlh>>::type>::type get_native_mem(const accessor<DataT, Dims, Mode, Target, IsPlh> &Acc) const { #ifndef __SYCL_DEVICE_ONLY__ const auto *AccBase = static_cast<const detail::AccessorBaseHost *>(&Acc); return getMemImpl<BackendName, DataT, Dims, Mode, Target, IsPlh>( detail::getSyclObjImpl(*AccBase).get()); #else (void)Acc; // we believe this won't be ever called on device side return nullptr; #endif } template <backend BackendName = backend::opencl, typename DataT, int Dims, access::mode Mode, access::target Target, access::placeholder IsPlh> typename std::enable_if< Target == access::target::host_buffer, typename interop<BackendName, accessor<DataT, Dims, Mode, Target, IsPlh>>::type>::type get_native_mem(const accessor<DataT, Dims, Mode, Target, IsPlh> &) const { throw invalid_object_error("Getting memory object out of host accessor is " "not allowed", PI_INVALID_MEM_OBJECT); } /// Returns an underlying OpenCL queue for the SYCL queue used to submit the /// command group, or the fallback queue if this command-group is re-trying /// execution on an OpenCL queue. The OpenCL command queue returned is /// implementation-defined in cases where the SYCL queue maps to multiple /// underlying OpenCL objects. It is responsibility of the SYCL runtime to /// ensure the OpenCL queue returned is in a state that can be used to /// dispatch work, and that other potential OpenCL command queues associated /// with the same SYCL command queue are not executing commands while the host /// task is executing. template <backend BackendName = backend::opencl> auto get_native_queue() const noexcept -> typename interop<BackendName, queue>::type { return reinterpret_cast<typename interop<BackendName, queue>::type>( getNativeQueue()); } /// Returns an underlying OpenCL device associated with the SYCL queue used /// to submit the command group, or the fallback queue if this command-group /// is re-trying execution on an OpenCL queue. template <backend BackendName = backend::opencl> auto get_native_device() const noexcept -> typename interop<BackendName, device>::type { return reinterpret_cast<typename interop<BackendName, device>::type>( getNativeDevice()); } /// Returns an underlying OpenCL context associated with the SYCL queue used /// to submit the command group, or the fallback queue if this command-group /// is re-trying execution on an OpenCL queue. template <backend BackendName = backend::opencl> auto get_native_context() const noexcept -> typename interop<BackendName, context>::type { return reinterpret_cast<typename interop<BackendName, context>::type>( getNativeContext()); } private: using ReqToMem = std::pair<detail::Requirement *, pi_mem>; public: // TODO set c-tor private interop_handle(std::vector<ReqToMem> MemObjs, const std::shared_ptr<detail::queue_impl> &Queue, const std::shared_ptr<detail::device_impl> &Device, const std::shared_ptr<detail::context_impl> &Context) : MQueue(Queue), MDevice(Device), MContext(Context), MMemObjs(std::move(MemObjs)) {} private: template <backend BackendName, typename DataT, int Dims, access::mode Mode, access::target Target, access::placeholder IsPlh> auto getMemImpl(detail::Requirement *Req) const -> typename interop<BackendName, accessor<DataT, Dims, Mode, Target, IsPlh>>::type { return reinterpret_cast<typename interop< BackendName, accessor<DataT, Dims, Mode, Target, IsPlh>>::type>( getNativeMem(Req)); } pi_native_handle getNativeMem(detail::Requirement *Req) const; pi_native_handle getNativeQueue() const; pi_native_handle getNativeDevice() const; pi_native_handle getNativeContext() const; std::shared_ptr<detail::queue_impl> MQueue; std::shared_ptr<detail::device_impl> MDevice; std::shared_ptr<detail::context_impl> MContext; std::vector<ReqToMem> MMemObjs; }; } // namespace sycl } // __SYCL_INLINE_NAMESPACE(cl)
39.939189
80
0.696329
[ "object", "vector" ]
329784efd2864c7e59ba29c61ccc47fdc66daf7d
492
cpp
C++
AtCoderBeginnersSelection/ABC081B/main.cpp
ryokohbato/AtCoder
1e5379dde57549f987ef8ab628230ad5fa1b60b8
[ "MIT" ]
null
null
null
AtCoderBeginnersSelection/ABC081B/main.cpp
ryokohbato/AtCoder
1e5379dde57549f987ef8ab628230ad5fa1b60b8
[ "MIT" ]
null
null
null
AtCoderBeginnersSelection/ABC081B/main.cpp
ryokohbato/AtCoder
1e5379dde57549f987ef8ab628230ad5fa1b60b8
[ "MIT" ]
null
null
null
#include <bits/stdc++.h> using namespace std; int divideCount(int number) { int count = 0; while(number % 2 == 0) { count++; number = number / 2; } return count; } int main() { int N; cin >> N; vector<int> A_divide_count(N); for (int i = 0; i < N; i++) { int currentA; cin >> currentA; A_divide_count.at(i) = divideCount(currentA); } sort(A_divide_count.begin(), A_divide_count.end()); cout << A_divide_count.at(0) << endl; return 0; }
15.375
53
0.583333
[ "vector" ]
329e6a6d5f1c0f7d7d420c8d31bb58a61b50c2f6
12,770
cpp
C++
Co-Simulation/Sumo/sumo-1.7.0/src/libsumo/VehicleType.cpp
uruzahe/carla
940c2ab23cce1eda1ef66de35f66b42d40865fb1
[ "MIT" ]
null
null
null
Co-Simulation/Sumo/sumo-1.7.0/src/libsumo/VehicleType.cpp
uruzahe/carla
940c2ab23cce1eda1ef66de35f66b42d40865fb1
[ "MIT" ]
null
null
null
Co-Simulation/Sumo/sumo-1.7.0/src/libsumo/VehicleType.cpp
uruzahe/carla
940c2ab23cce1eda1ef66de35f66b42d40865fb1
[ "MIT" ]
null
null
null
/****************************************************************************/ // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo // Copyright (C) 2017-2020 German Aerospace Center (DLR) and others. // This program and the accompanying materials are made available under the // terms of the Eclipse Public License 2.0 which is available at // https://www.eclipse.org/legal/epl-2.0/ // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License 2.0 are satisfied: GNU General Public License, version 2 // or later which is available at // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later /****************************************************************************/ /// @file VehicleType.cpp /// @author Gregor Laemmel /// @date 04.04.2017 /// // C++ TraCI client API implementation /****************************************************************************/ #include <config.h> #include <microsim/MSNet.h> #include <microsim/MSVehicleControl.h> #include <microsim/MSVehicleType.h> #include <libsumo/TraCIConstants.h> #include <utils/emissions/PollutantsInterface.h> #include <utils/vehicle/SUMOVehicleParserHelper.h> #include "Helper.h" #include "VehicleType.h" namespace libsumo { // =========================================================================== // static member initializations // =========================================================================== SubscriptionResults VehicleType::mySubscriptionResults; ContextSubscriptionResults VehicleType::myContextSubscriptionResults; // =========================================================================== // static member definitions // =========================================================================== std::vector<std::string> VehicleType::getIDList() { std::vector<std::string> ids; MSNet::getInstance()->getVehicleControl().insertVTypeIDs(ids); return ids; } int VehicleType::getIDCount() { return (int)getIDList().size(); } double VehicleType::getLength(const std::string& typeID) { return getVType(typeID)->getLength(); } double VehicleType::getMaxSpeed(const std::string& typeID) { return getVType(typeID)->getMaxSpeed(); } double VehicleType::getActionStepLength(const std::string& typeID) { return getVType(typeID)->getActionStepLengthSecs(); } double VehicleType::getSpeedFactor(const std::string& typeID) { return getVType(typeID)->getSpeedFactor().getParameter()[0]; } double VehicleType::getSpeedDeviation(const std::string& typeID) { return getVType(typeID)->getSpeedFactor().getParameter()[1]; } double VehicleType::getAccel(const std::string& typeID) { return getVType(typeID)->getCarFollowModel().getMaxAccel(); } double VehicleType::getDecel(const std::string& typeID) { return getVType(typeID)->getCarFollowModel().getMaxDecel(); } double VehicleType::getEmergencyDecel(const std::string& typeID) { return getVType(typeID)->getCarFollowModel().getEmergencyDecel(); } double VehicleType::getApparentDecel(const std::string& typeID) { return getVType(typeID)->getCarFollowModel().getApparentDecel(); } double VehicleType::getImperfection(const std::string& typeID) { return getVType(typeID)->getCarFollowModel().getImperfection(); } double VehicleType::getTau(const std::string& typeID) { return getVType(typeID)->getCarFollowModel().getHeadwayTime(); } std::string VehicleType::getVehicleClass(const std::string& typeID) { return toString(getVType(typeID)->getVehicleClass()); } std::string VehicleType::getEmissionClass(const std::string& typeID) { return PollutantsInterface::getName(getVType(typeID)->getEmissionClass()); } std::string VehicleType::getShapeClass(const std::string& typeID) { return getVehicleShapeName(getVType(typeID)->getGuiShape()); } double VehicleType::getMinGap(const std::string& typeID) { return getVType(typeID)->getMinGap(); } double VehicleType::getWidth(const std::string& typeID) { return getVType(typeID)->getWidth(); } double VehicleType::getHeight(const std::string& typeID) { return getVType(typeID)->getHeight(); } TraCIColor VehicleType::getColor(const std::string& typeID) { return Helper::makeTraCIColor(getVType(typeID)->getColor()); } double VehicleType::getMinGapLat(const std::string& typeID) { return getVType(typeID)->getMinGapLat(); } double VehicleType::getMaxSpeedLat(const std::string& typeID) { return getVType(typeID)->getMaxSpeedLat(); } std::string VehicleType::getLateralAlignment(const std::string& typeID) { return toString(getVType(typeID)->getPreferredLateralAlignment()); } std::string VehicleType::getParameter(const std::string& typeID, const std::string& key) { return getVType(typeID)->getParameter().getParameter(key, ""); } LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(VehicleType) int VehicleType::getPersonCapacity(const std::string& typeID) { return getVType(typeID)->getPersonCapacity(); } void VehicleType::setLength(const std::string& typeID, double length) { getVType(typeID)->setLength(length); } void VehicleType::setMaxSpeed(const std::string& typeID, double speed) { getVType(typeID)->setMaxSpeed(speed); } void VehicleType::setActionStepLength(const std::string& typeID, double actionStepLength, bool resetActionOffset) { getVType(typeID)->setActionStepLength(SUMOVehicleParserHelper::processActionStepLength(actionStepLength), resetActionOffset); } void VehicleType::setVehicleClass(const std::string& typeID, const std::string& clazz) { getVType(typeID)->setVClass(getVehicleClassID(clazz)); } void VehicleType::setSpeedFactor(const std::string& typeID, double factor) { getVType(typeID)->setSpeedFactor(factor); } void VehicleType::setSpeedDeviation(const std::string& typeID, double deviation) { getVType(typeID)->setSpeedDeviation(deviation); } void VehicleType::setEmissionClass(const std::string& typeID, const std::string& clazz) { getVType(typeID)->setEmissionClass(PollutantsInterface::getClassByName(clazz)); } void VehicleType::setShapeClass(const std::string& typeID, const std::string& shapeClass) { getVType(typeID)->setShape(getVehicleShapeID(shapeClass)); } void VehicleType::setWidth(const std::string& typeID, double width) { getVType(typeID)->setWidth(width); } void VehicleType::setHeight(const std::string& typeID, double height) { getVType(typeID)->setHeight(height); } void VehicleType::setMinGap(const std::string& typeID, double minGap) { getVType(typeID)->setMinGap(minGap); } void VehicleType::setAccel(const std::string& typeID, double accel) { getVType(typeID)->setAccel(accel); } void VehicleType::setDecel(const std::string& typeID, double decel) { MSVehicleType* v = getVType(typeID); v->setDecel(decel); // automatically raise emergencyDecel to ensure it is at least as high as decel if (decel > v->getCarFollowModel().getEmergencyDecel()) { if (v->getParameter().cfParameter.count(SUMO_ATTR_EMERGENCYDECEL) > 0) { // notify user only if emergencyDecel was previously specified WRITE_WARNING("Automatically setting emergencyDecel to " + toString(decel) + " for vType '" + typeID + "' to match decel."); } v->setEmergencyDecel(decel); } } void VehicleType::setEmergencyDecel(const std::string& typeID, double decel) { MSVehicleType* v = getVType(typeID); v->setEmergencyDecel(decel); if (decel < v->getCarFollowModel().getMaxDecel()) { WRITE_WARNING("New value of emergencyDecel (" + toString(decel) + ") is lower than decel (" + toString(v->getCarFollowModel().getMaxDecel()) + ")"); } } void VehicleType::setApparentDecel(const std::string& typeID, double decel) { getVType(typeID)->setApparentDecel(decel); } void VehicleType::setImperfection(const std::string& typeID, double imperfection) { getVType(typeID)->setImperfection(imperfection); } void VehicleType::setTau(const std::string& typeID, double tau) { getVType(typeID)->setTau(tau); } void VehicleType::setColor(const std::string& typeID, const TraCIColor& c) { getVType(typeID)->setColor(Helper::makeRGBColor(c)); } void VehicleType::setMinGapLat(const std::string& typeID, double minGapLat) { getVType(typeID)->setMinGapLat(minGapLat); } void VehicleType::setMaxSpeedLat(const std::string& typeID, double speed) { getVType(typeID)->setMaxSpeedLat(speed); } void VehicleType::setLateralAlignment(const std::string& typeID, const std::string& latAlignment) { getVType(typeID)->setPreferredLateralAlignment(SUMOXMLDefinitions::LateralAlignments.get(latAlignment)); } void VehicleType::copy(const std::string& origTypeID, const std::string& newTypeID) { getVType(origTypeID)->duplicateType(newTypeID, true); } void VehicleType::setParameter(const std::string& typeID, const std::string& name, const std::string& value) { ((SUMOVTypeParameter&)getVType(typeID)->getParameter()).setParameter(name, value); } LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(VehicleType, VEHICLETYPE) MSVehicleType* VehicleType::getVType(std::string id) { MSVehicleType* t = MSNet::getInstance()->getVehicleControl().getVType(id); if (t == nullptr) { throw TraCIException("Vehicle type '" + id + "' is not known"); } return t; } std::shared_ptr<VariableWrapper> VehicleType::makeWrapper() { return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults); } bool VehicleType::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) { return handleVariableWithID(objID, objID, variable, wrapper); } bool VehicleType::handleVariableWithID(const std::string& objID, const std::string& typeID, const int variable, VariableWrapper* wrapper) { switch (variable) { case TRACI_ID_LIST: return wrapper->wrapStringList(objID, variable, getIDList()); case ID_COUNT: return wrapper->wrapInt(objID, variable, getIDCount()); case VAR_LENGTH: return wrapper->wrapDouble(objID, variable, getLength(typeID)); case VAR_HEIGHT: return wrapper->wrapDouble(objID, variable, getHeight(typeID)); case VAR_MINGAP: return wrapper->wrapDouble(objID, variable, getMinGap(typeID)); case VAR_MAXSPEED: return wrapper->wrapDouble(objID, variable, getMaxSpeed(typeID)); case VAR_ACCEL: return wrapper->wrapDouble(objID, variable, getAccel(typeID)); case VAR_DECEL: return wrapper->wrapDouble(objID, variable, getDecel(typeID)); case VAR_EMERGENCY_DECEL: return wrapper->wrapDouble(objID, variable, getEmergencyDecel(typeID)); case VAR_APPARENT_DECEL: return wrapper->wrapDouble(objID, variable, getApparentDecel(typeID)); case VAR_ACTIONSTEPLENGTH: return wrapper->wrapDouble(objID, variable, getActionStepLength(typeID)); case VAR_IMPERFECTION: return wrapper->wrapDouble(objID, variable, getImperfection(typeID)); case VAR_TAU: return wrapper->wrapDouble(objID, variable, getTau(typeID)); case VAR_SPEED_FACTOR: return wrapper->wrapDouble(objID, variable, getSpeedFactor(typeID)); case VAR_SPEED_DEVIATION: return wrapper->wrapDouble(objID, variable, getSpeedDeviation(typeID)); case VAR_VEHICLECLASS: return wrapper->wrapString(objID, variable, getVehicleClass(typeID)); case VAR_EMISSIONCLASS: return wrapper->wrapString(objID, variable, getEmissionClass(typeID)); case VAR_SHAPECLASS: return wrapper->wrapString(objID, variable, getShapeClass(typeID)); case VAR_WIDTH: return wrapper->wrapDouble(objID, variable, getWidth(typeID)); case VAR_COLOR: return wrapper->wrapColor(objID, variable, getColor(typeID)); case VAR_MINGAP_LAT: return wrapper->wrapDouble(objID, variable, getMinGapLat(typeID)); case VAR_MAXSPEED_LAT: return wrapper->wrapDouble(objID, variable, getMaxSpeedLat(typeID)); case VAR_LATALIGNMENT: return wrapper->wrapString(objID, variable, getLateralAlignment(typeID)); case VAR_PERSON_CAPACITY: return wrapper->wrapInt(objID, variable, getPersonCapacity(typeID)); default: return false; } } } /****************************************************************************/
29.62877
156
0.687314
[ "vector" ]
32a8c01ff126511309b3c14d2a92d72d7567bcce
1,319
cpp
C++
NativeFileSystemWatcher/src/NativeFileSystemWatcher/DelayedFileSystemWatcher.cpp
sanastasiou/FileSystemWatcher
acda746228dd351688969bfd41e3c7bbd607f287
[ "MIT" ]
10
2015-04-12T08:17:05.000Z
2019-01-11T12:55:04.000Z
NativeFileSystemWatcher/src/NativeFileSystemWatcher/DelayedFileSystemWatcher.cpp
fcccode/FileSystemWatcher
acda746228dd351688969bfd41e3c7bbd607f287
[ "MIT" ]
null
null
null
NativeFileSystemWatcher/src/NativeFileSystemWatcher/DelayedFileSystemWatcher.cpp
fcccode/FileSystemWatcher
acda746228dd351688969bfd41e3c7bbd607f287
[ "MIT" ]
5
2015-09-22T16:18:56.000Z
2021-04-02T04:46:14.000Z
#pragma managed(push, off) #include "NativeFileSystemWatcher/DelayedFileSystemWatcher.h" namespace Windows { namespace File { DelayedFileSystemWatcher::DelayedFileSystemWatcher(IFileSystemWatcher::FileSystemString const & dir, ::DWORD changeFlags, ::BOOL const watchSubDir, IFileSystemWatcher * const eventHandler, IFileSystemWatcher::FileSystemString includeFilter, IFileSystemWatcher::FileSystemString excludeFilter, bool restartOnError, unsigned int delay, std::vector<::BYTE>::size_type const bufferSize ) : NativeFileSystemWatcher(dir, changeFlags, watchSubDir, eventHandler, includeFilter, excludeFilter, restartOnError, bufferSize), _delay(delay) { } DelayedFileSystemWatcher::~DelayedFileSystemWatcher() { } } //namespace File } //namespace Windows #pragma managed(pop)
39.969697
135
0.488249
[ "vector" ]
32ab156cdd89bcb94cf3645ab3100ba8a495b5e0
3,591
cpp
C++
hackathon/XuanZhao/consensus/branchtree.cpp
zzhmark/vaa3d_tools
3ca418add85a59ac7e805d55a600b78330d7e53d
[ "MIT" ]
1
2021-12-27T19:14:03.000Z
2021-12-27T19:14:03.000Z
hackathon/XuanZhao/consensus/branchtree.cpp
zzhmark/vaa3d_tools
3ca418add85a59ac7e805d55a600b78330d7e53d
[ "MIT" ]
null
null
null
hackathon/XuanZhao/consensus/branchtree.cpp
zzhmark/vaa3d_tools
3ca418add85a59ac7e805d55a600b78330d7e53d
[ "MIT" ]
null
null
null
#include "branchtree.h" #include <iostream> using namespace std; bool Branch::get_r_pointsIndex_of_branch(vector<V3DLONG> &r_points, NeuronTree &nt) { // qDebug()<<"headPointIndex: "<<headPointIndex<<" endPointIndex: "<<endPointIndex; int tmp = endPointIndex; r_points.push_back(tmp); while(tmp != headPointIndex) { // qDebug()<<"tmp: "<<tmp; tmp = nt.hashNeuron.value(nt.listNeuron[tmp].parent); r_points.push_back(tmp); } return true; } bool Branch::get_pointsIndex_of_branch(vector<V3DLONG> &points, NeuronTree &nt) { vector<V3DLONG> r_points; this->get_r_pointsIndex_of_branch(r_points,nt); while(!r_points.empty()) { int tmp=r_points.back(); r_points.pop_back(); points.push_back(tmp); } return true; } bool BranchTree::initialize(NeuronTree t) { nt.deepCopy(t); vector<V3DLONG> ori = vector<V3DLONG>(); V3DLONG num_p=nt.listNeuron.size(); vector<vector<V3DLONG> > children=vector<vector<V3DLONG> >(num_p,vector<V3DLONG>()); for(V3DLONG i=0;i<num_p;++i) { V3DLONG prt=nt.listNeuron[i].parent; if(prt != -1){ V3DLONG prtIndex = nt.hashNeuron.value(prt); children.at(prtIndex).push_back(i); }else { ori.push_back(i); } } vector<V3DLONG> queue = vector<V3DLONG>(); queue.insert(queue.begin(),ori.begin(),ori.end()); cout<<"queue size: "<<queue.size()<<endl; cout<<"initial head_point,end_point"<<endl; while(!queue.empty()) { V3DLONG tmp=queue.front(); queue.erase(queue.begin()); vector<V3DLONG>& child = children.at(tmp); // cout<<"child size: "<<child.size()<<endl; for(int i=0;i<child.size();++i) { Branch branch; branch.headPointIndex = tmp; int cIndex = child.at(i); while(children.at(cIndex).size() == 1) { cIndex = children.at(cIndex).at(0); } if(children.at(cIndex).size() >= 1) { queue.push_back(cIndex); } branch.endPointIndex = cIndex; branchs.push_back(branch); } } //initial parent cout<<"initial parent"<<endl; cout<<"branch size: "<<branchs.size()<<endl; for(int i=0;i<branchs.size();++i) { cout<<i<<endl; if(nt.listNeuron.at(branchs[i].headPointIndex).parent < 0) { branchs[i].parent = 0; } else { for(int j=0; j<branchs.size(); ++j) { if(branchs[i].headPointIndex == branchs[j].endPointIndex) { branchs[i].parent = &branchs[j]; } } } } //initial level for(int i=0; i<branchs.size(); ++i) { Branch* tmp; tmp = &branchs[i]; int level=0; while(tmp->parent != 0) { level++; tmp = tmp->parent; } branchs[i].level=level; } cout<<"--------------------initialize end--------------"; return true; } bool BranchTree::get_level_index(vector<int> &level_index, int level){ for(int i=0; i<branchs.size(); i++){ if(branchs[i].level == level){ level_index.push_back(i); } } return true; } int BranchTree::get_max_level(){ int max = 0; for(int i=0; i<branchs.size(); i++){ if(branchs[i].level > max){ max = branchs[i].level; } } return max; }
24.765517
88
0.527151
[ "vector" ]
32ae8b674c4b95a451a3f29d9ead3238445669b3
442
cpp
C++
LeetCode/Explore/December-LeetCoding-Challenge/#Day#8_PairsOfSongsWithTotalDurationsDivisibleBy60_sol1_math_O(N)_time_O(60)_extra_space_56ms_23.4MB.cpp
Tudor67/Competitive-Programming
ae4dc6ed8bf76451775bf4f740c16394913f3ff1
[ "MIT" ]
1
2022-01-26T14:50:07.000Z
2022-01-26T14:50:07.000Z
LeetCode/Problems/Algorithms/#1010_PairsOfSongsWithTotalDurationsDivisibleBy60_sol1_math_O(N)_time_O(60)_extra_space_56ms_23.4MB.cpp
Tudor67/Competitive-Programming
ae4dc6ed8bf76451775bf4f740c16394913f3ff1
[ "MIT" ]
null
null
null
LeetCode/Problems/Algorithms/#1010_PairsOfSongsWithTotalDurationsDivisibleBy60_sol1_math_O(N)_time_O(60)_extra_space_56ms_23.4MB.cpp
Tudor67/Competitive-Programming
ae4dc6ed8bf76451775bf4f740c16394913f3ff1
[ "MIT" ]
null
null
null
class Solution { public: int numPairsDivisibleBy60(vector<int>& time) { vector<int> count(60, 0); for(int t: time){ count[t % 60] += 1; } int pairs = (long long)count[0] * (count[0] - 1) / 2 + (long long)count[30] * (count[30] - 1) / 2; for(int t = 1; t < 30; ++t){ pairs += count[t] * count[60 - t]; } return pairs; } };
27.625
107
0.427602
[ "vector" ]
32bc9705136957be23c89c14a4ebae75bc2b0ff0
2,076
hpp
C++
src/glPack.hpp
wkretzsch/insti
2b173afcb59bc424cbb2993a73381126ea0f844d
[ "MIT" ]
8
2017-10-01T13:05:21.000Z
2022-01-17T08:46:58.000Z
src/glPack.hpp
rwdavies/GLPhase
1728721aed7407ce00fc2113651baf998978961b
[ "MIT" ]
null
null
null
src/glPack.hpp
rwdavies/GLPhase
1728721aed7407ce00fc2113651baf998978961b
[ "MIT" ]
1
2018-11-01T21:18:19.000Z
2018-11-01T21:18:19.000Z
#ifndef _GLPACK_HPP #define _GLPACK_HPP static_assert(__cplusplus > 199711L, "Program requires C++11 capable compiler"); #include <vector> #include <cassert> #include <cmath> #include <limits> #include "utils.hpp" #include "glVQ.hpp" #include <limits> #include <utility> #include <gsl/gsl_rng.h> #include "globals.h" #ifndef NCUDA #include <vector_types.h> #endif // we want our chars to be unsigned namespace GLPackHelper { struct Init { const std::vector<float> &inGLs; gsl_rng &rng; unsigned numSamps = 0; unsigned sampleStride = 0; bool useVQ = false; // 32 % numBits needs to be zero unsigned numBitsPerGL = 8; Init(const std::vector<float> &GLs, gsl_rng &rng) : inGLs(GLs), rng(rng) {}; }; } class GLPack { private: const unsigned m_numSamps; const std::vector<float> &m_inGLs; const unsigned m_sampleStride; const unsigned m_numSites; const bool m_useVQ; unsigned m_numBitsPerGL; unsigned m_numGLsPeruint32_t; unsigned m_nextSampIdx = 0; unsigned m_lastSampIdx = 0; GLVQ m_VQ; uint32_t GLIdxs2uint32_t(const std::vector<unsigned> &glIdxs) const; unsigned char GLs2VQChar(const std::vector<unsigned> &glIdxs, size_t glIdx, size_t numGLsPerChar) const; unsigned char GLTrio2Char(unsigned idx) const; unsigned char GL2HalfChar(float GL) const; public: // set VQBits > 0 for vector quantization GLPack(const GLPackHelper::Init &init); std::vector<uint32_t> GetPackedGLs(); unsigned GetSampleStride() const { return m_sampleStride; } unsigned GetNextSampIdx() const { return m_nextSampIdx; } unsigned GetLastSampIdx() const { return m_lastSampIdx; } unsigned GetNumSites() const { return m_numSites; } unsigned GetNumSamps() const { return m_numSamps; } // return the number of VQ bits otherwise 8 unsigned GetNumBitsPerGL() const { return m_numBitsPerGL; } // vector of size bits per sample * 2 (hom ref, alt) // gl of hom alt is max(1 - hom ref - alt,1) std::vector<std::pair<float, float> > GetCodeBook() const { return m_VQ.GetCodeBook(); } }; #endif
25.62963
80
0.716281
[ "vector" ]
32d82b8e055307c2c1e9c899c442427bc11581b1
4,802
cpp
C++
iotvideo/src/v20191126/model/DevTokenInfo.cpp
li5ch/tencentcloud-sdk-cpp
12ebfd75a399ee2791f6ac1220a79ce8a9faf7c4
[ "Apache-2.0" ]
null
null
null
iotvideo/src/v20191126/model/DevTokenInfo.cpp
li5ch/tencentcloud-sdk-cpp
12ebfd75a399ee2791f6ac1220a79ce8a9faf7c4
[ "Apache-2.0" ]
null
null
null
iotvideo/src/v20191126/model/DevTokenInfo.cpp
li5ch/tencentcloud-sdk-cpp
12ebfd75a399ee2791f6ac1220a79ce8a9faf7c4
[ "Apache-2.0" ]
null
null
null
/* * Copyright (c) 2017-2019 THL A29 Limited, a Tencent company. All Rights Reserved. * * 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 <tencentcloud/iotvideo/v20191126/model/DevTokenInfo.h> using TencentCloud::CoreInternalOutcome; using namespace TencentCloud::Iotvideo::V20191126::Model; using namespace rapidjson; using namespace std; DevTokenInfo::DevTokenInfo() : m_accessIdHasBeenSet(false), m_tidHasBeenSet(false), m_accessTokenHasBeenSet(false), m_expireTimeHasBeenSet(false) { } CoreInternalOutcome DevTokenInfo::Deserialize(const Value &value) { string requestId = ""; if (value.HasMember("AccessId") && !value["AccessId"].IsNull()) { if (!value["AccessId"].IsString()) { return CoreInternalOutcome(Error("response `DevTokenInfo.AccessId` IsString=false incorrectly").SetRequestId(requestId)); } m_accessId = string(value["AccessId"].GetString()); m_accessIdHasBeenSet = true; } if (value.HasMember("Tid") && !value["Tid"].IsNull()) { if (!value["Tid"].IsString()) { return CoreInternalOutcome(Error("response `DevTokenInfo.Tid` IsString=false incorrectly").SetRequestId(requestId)); } m_tid = string(value["Tid"].GetString()); m_tidHasBeenSet = true; } if (value.HasMember("AccessToken") && !value["AccessToken"].IsNull()) { if (!value["AccessToken"].IsString()) { return CoreInternalOutcome(Error("response `DevTokenInfo.AccessToken` IsString=false incorrectly").SetRequestId(requestId)); } m_accessToken = string(value["AccessToken"].GetString()); m_accessTokenHasBeenSet = true; } if (value.HasMember("ExpireTime") && !value["ExpireTime"].IsNull()) { if (!value["ExpireTime"].IsUint64()) { return CoreInternalOutcome(Error("response `DevTokenInfo.ExpireTime` IsUint64=false incorrectly").SetRequestId(requestId)); } m_expireTime = value["ExpireTime"].GetUint64(); m_expireTimeHasBeenSet = true; } return CoreInternalOutcome(true); } void DevTokenInfo::ToJsonObject(Value &value, Document::AllocatorType& allocator) const { if (m_accessIdHasBeenSet) { Value iKey(kStringType); string key = "AccessId"; iKey.SetString(key.c_str(), allocator); value.AddMember(iKey, Value(m_accessId.c_str(), allocator).Move(), allocator); } if (m_tidHasBeenSet) { Value iKey(kStringType); string key = "Tid"; iKey.SetString(key.c_str(), allocator); value.AddMember(iKey, Value(m_tid.c_str(), allocator).Move(), allocator); } if (m_accessTokenHasBeenSet) { Value iKey(kStringType); string key = "AccessToken"; iKey.SetString(key.c_str(), allocator); value.AddMember(iKey, Value(m_accessToken.c_str(), allocator).Move(), allocator); } if (m_expireTimeHasBeenSet) { Value iKey(kStringType); string key = "ExpireTime"; iKey.SetString(key.c_str(), allocator); value.AddMember(iKey, m_expireTime, allocator); } } string DevTokenInfo::GetAccessId() const { return m_accessId; } void DevTokenInfo::SetAccessId(const string& _accessId) { m_accessId = _accessId; m_accessIdHasBeenSet = true; } bool DevTokenInfo::AccessIdHasBeenSet() const { return m_accessIdHasBeenSet; } string DevTokenInfo::GetTid() const { return m_tid; } void DevTokenInfo::SetTid(const string& _tid) { m_tid = _tid; m_tidHasBeenSet = true; } bool DevTokenInfo::TidHasBeenSet() const { return m_tidHasBeenSet; } string DevTokenInfo::GetAccessToken() const { return m_accessToken; } void DevTokenInfo::SetAccessToken(const string& _accessToken) { m_accessToken = _accessToken; m_accessTokenHasBeenSet = true; } bool DevTokenInfo::AccessTokenHasBeenSet() const { return m_accessTokenHasBeenSet; } uint64_t DevTokenInfo::GetExpireTime() const { return m_expireTime; } void DevTokenInfo::SetExpireTime(const uint64_t& _expireTime) { m_expireTime = _expireTime; m_expireTimeHasBeenSet = true; } bool DevTokenInfo::ExpireTimeHasBeenSet() const { return m_expireTimeHasBeenSet; }
26.240437
136
0.680966
[ "model" ]
77f8cb3c5d9afa00754fbd876e67300efb8c1982
6,116
cpp
C++
src/main.cpp
bkille/RAMBO
e47fcc132e2e31a9e517e7d71ba19675f3f1eb51
[ "Apache-2.0" ]
18
2020-04-15T04:54:28.000Z
2021-12-17T02:44:12.000Z
src/main.cpp
bkille/RAMBO
e47fcc132e2e31a9e517e7d71ba19675f3f1eb51
[ "Apache-2.0" ]
null
null
null
src/main.cpp
bkille/RAMBO
e47fcc132e2e31a9e517e7d71ba19675f3f1eb51
[ "Apache-2.0" ]
4
2020-01-23T05:33:33.000Z
2020-07-03T19:54:20.000Z
#include <iomanip> #include <iostream> #include <fstream> #include <math.h> #include <sstream> #include <string> #include <string.h> #include <algorithm> #include <omp.h> #include <chrono> #include <list> #include <vector> #include <filesystem> #include "CLI/App.hpp" #include "CLI/Validators.hpp" #include "spdlog/spdlog.h" #include "CLI/CLI.hpp" #include "tqdm.h" #include "bitArray.h" #include "MyBloom.h" #include "Rambo_construction.h" #include "utils.h" using namespace std; namespace fs = std::filesystem; int main(int argc, char** argv){ /* *Command line parsing */ CLI::App app{"RAMBO application"}; app.require_subcommand(1, 1); CLI::App* build_sub = app.add_subcommand("build", "Build database")->fallthrough(); std::vector<fs::path> input_files; fs::path input_kmers_file = ""; fs::path database_output_dir("database_dir"); fs::path query_output_prefix("query"); bool verbose = false; bool show_progress = false; unsigned int num_threads = 1; // Generic flags app.add_flag( "-v,--verbose", verbose, "Display debug output" ); app.add_flag( "--show-progress", show_progress, "Display progress bars" ); app.add_option( "-p,--threads", num_threads, "Number of threads to use" ); // Build flags int n_per_set = 100000000; //cardinality of each set float FPR = 0.01; int R_all = 10; int B_all = 50; build_sub->add_option( "input-files", input_files, "Input files" )->required()->check(CLI::ExistingFile); build_sub->add_option( "-o,--output", database_output_dir, "Directory to store serialized output" ); build_sub->add_option( "-R, --repitions", R_all, "Number of repititions in RAMBO index" ); build_sub->add_option( "-B, --blooms-per-rep", B_all, "Number of bloom filters per repitition" ); build_sub->add_option( "-n, --bloom-size", n_per_set, "Size of each bloom filter (in bits)" ); // Insert flags CLI::App* insert_sub = app.add_subcommand("insert", "Insert samples into database")->fallthrough(); fs::path database_dir; insert_sub->add_option( "input-files", input_files, "Input files" )->required()->check(CLI::ExistingFile); insert_sub->add_option( "-d,--database", database_dir, "Path to RAMBO database directory" )->required()->check(CLI::ExistingDirectory); // Query flags CLI::App* query_sub = app.add_subcommand("query", "Check if query is in database")->fallthrough(); bool flatten_input = false; query_sub->add_option( "input-files", input_files, "Input files. For each file, RAMBO will check if database contains any entries which are a superset of the input file. Use the --flatten flag if each kmer should be treated independently" )->check(CLI::ExistingFile); //query_sub->add_flag( //"-f,--flatten", //flatten_input, //"Treat each kmer from each input file as an individual sample" //); query_sub->add_option( "-d,--database", database_dir, "Path to RAMBO database directory" )->required()->check(CLI::ExistingDirectory); query_sub->add_option( "-o,--output", query_output_prefix, "Prefix to TSV output file. Results will be stored at <prefix>_results.tsv" ); CLI11_PARSE(app, argc, argv); /* *Constants and assertions */ spdlog::set_level(verbose ? spdlog::level::debug : spdlog::level::info); // Set global log level to debug omp_set_num_threads(num_threads); /* *Main workflow */ if (app.got_subcommand("build")) { // constructor RAMBO myRambo(n_per_set, FPR, R_all, B_all, input_files); myRambo.serializeRAMBO(database_output_dir); } else if (app.got_subcommand("insert")) { RAMBO rambo(database_dir); spdlog::info("Inserting kmers..."); tqdm bar; unsigned int prog_i = 0; #pragma omp parallel { #pragma omp for schedule(dynamic) for (unsigned int i = 0; i < input_files.size(); ++i) { auto input_f = input_files[i]; rambo.insertion(input_f); if (show_progress) { #pragma omp critical { prog_i += 1; bar.progress(prog_i, input_files.size()); } } } } bar.finish(); rambo.serializeRAMBO(database_dir); } else if(app.got_subcommand("query")){ fs::path output_file = fs::path(query_output_prefix.string() + "_results.tsv"); RAMBO rambo(database_dir); spdlog::info("Querying RAMBO index..."); for (fs::path input_f: input_files) { rambo.query_kmers(input_f, output_file); } // Implement once fasta support is added //if (flatten_input) { //for (fs::path input_f: input_files) { //rambo.query_kmers(input_f, output_file); //} //} else { //for (fs::path input_f: input_files) { //auto results = rambo.query_full_file(input_f, show_progress); //if (results.size() > 0) { //spdlog::info("{} found in the following samples:", input_f.stem().string()); //for (auto sample : results) { //std::cout << sample << " "; //} //std::cout << std::endl; //} else { //spdlog::info("{} not found in database!", input_f.stem().string()); //} //} //} } return 0; }
31.204082
199
0.550033
[ "vector" ]
77f8e3318cab218221ec15823ade940339120d2e
2,599
cpp
C++
Tameran/Tameran/GameWindow.cpp
Zokerus/Tameran
7bf20aae2c5bba3db972b09862528e6a21187c1d
[ "MIT" ]
1
2017-09-21T18:08:45.000Z
2017-09-21T18:08:45.000Z
Tameran/Tameran/GameWindow.cpp
Zokerus/Tameran
7bf20aae2c5bba3db972b09862528e6a21187c1d
[ "MIT" ]
null
null
null
Tameran/Tameran/GameWindow.cpp
Zokerus/Tameran
7bf20aae2c5bba3db972b09862528e6a21187c1d
[ "MIT" ]
null
null
null
#include "GameWindow.h" Tameran::GameWindow::GameWindow(HINSTANCE hInst, char* pArgs) : GameWindow(hInst, pArgs, "DirectX Window", 1024, 768, false, false) {} Tameran::GameWindow::GameWindow(HINSTANCE hInst, char* pArgs, const std::string title) : GameWindow(hInst, pArgs, title, 1024, 768, false, false) {} Tameran::GameWindow::GameWindow(HINSTANCE hInst, char* pArgs, const unsigned int screenWidth, const unsigned int screenHeight) : GameWindow(hInst, pArgs, "DirectX Window", screenWidth, screenHeight, false, false) {} Tameran::GameWindow::GameWindow(HINSTANCE hInst, char* pArgs, const std::string title, const unsigned int screenWidth, const unsigned int screenHeight) : GameWindow(hInst, pArgs, title, screenWidth, screenHeight, false, false) {} Tameran::GameWindow::GameWindow(HINSTANCE hInst, char * pArgs, const std::string title, const unsigned int screenWidth, const unsigned int screenHeight, bool fullscreen, bool vsync) : IGameWindow(hInst, pArgs, title, screenWidth, screenHeight, fullscreen, vsync), direct3D(this), shaderManager(direct3D.GetDevice(), hWnd), camera(), input(screenWidth, screenHeight, hInst, hWnd), gameStateManager(), titleScreen(this, &direct3D, &shaderManager, &camera, &input), menuScreen(this, &direct3D, &shaderManager, &camera, &input), loadingScreen(this, &direct3D, &shaderManager, &camera, &input), gameScreen(this, &direct3D, &shaderManager, &camera, &input) { //Set the initial position of the camera and build the matrices needed for rendering camera.SetPosition(DirectX::XMFLOAT3(0.0f, 1.0f, -10.0f)); camera.Render(true); //add the title screen to the gamestate manager gameStateManager.ChangeState(&titleScreen); } Tameran::GameWindow::~GameWindow() {} bool Tameran::GameWindow::Update(float eTime) { bool result = true; //Update the input class result = input.Update(); if (!result) { return false; } //Update the gamestate manager result = gameStateManager.Update(eTime); if (!result) { return false; } if (input.IsKeyDown(DIK_LALT) && input.IsKeyReleased(DIK_SPACE)) { SwitchFullscreen(); //Just a Prototype direct3D.SetFullScreen(fullscreen); } if (input.IsKeyReleased(DIK_ESCAPE)) { return false; } return true; } bool Tameran::GameWindow::Draw(float eTime) { bool result = true; //Clear the buffers to begin the scene direct3D.BeginFrame(DirectX::Colors::CornflowerBlue); //Draw something //Render the gamestate manager result = gameStateManager.Draw(eTime); if (!result) { return false; } //Present the rendered scene to the screen direct3D.EndFrame(); return true; }
29.873563
199
0.744132
[ "render" ]
ae026128f298e67cad8cdd8773bb4fc9d1426183
36,611
cpp
C++
eclipse_workspace/gmatch/src/SelectProfilesPanel.cpp
GPMSoftware/GPM
a2e0b9eed52bb4ecf07770831a54985815f7d866
[ "MIT" ]
null
null
null
eclipse_workspace/gmatch/src/SelectProfilesPanel.cpp
GPMSoftware/GPM
a2e0b9eed52bb4ecf07770831a54985815f7d866
[ "MIT" ]
null
null
null
eclipse_workspace/gmatch/src/SelectProfilesPanel.cpp
GPMSoftware/GPM
a2e0b9eed52bb4ecf07770831a54985815f7d866
[ "MIT" ]
null
null
null
/* * (c) Crown copyright 2009-2015. * * This software is distributed under the MIT License. * (See accompanying file LICENSE.txt or copy at * http://opensource.org/licenses/MIT) */ /* * SelectProfilesPanel.cpp * * Created on: Jul 29, 2010 * Author: gareth */ #include "SelectProfilesPanel.h" #include "MegaChoiceDialog.h" #include "gmatch.h" #include "MyFrame.h" #include "fand/dbmatch.h" #include "fand/MessageStream.h" INIT_MESSAGES("SelectProfilesPanel"); #include "fand/messages.h" #include "wx/statline.h" #include <UnitTest++/UnitTest++.h> using namespace std; const unsigned int COMBO_MAX = 20; // maximum number of items to display in a combo box const unsigned int SINGLE_CHOICE_MAX = 100; // maximum number of items to display in a wxSingleChoiceDialog extern boost::shared_ptr<Database> db; std::map<std::string, std::string> SelectProfilesPanel::m_searches; // Named searches std::set<SelectProfilesPanel*> SelectProfilesPanel::m_instances; // pointers to all instances int MultiSelector::Selector::next_id = 0; // used to generate unique IDs for selectors BEGIN_EVENT_TABLE(MultiSelector::Selector, wxPanel) EVT_BUTTON(ID_NEWB, MultiSelector::Selector::OnNew) EVT_BUTTON(ID_DELB, MultiSelector::Selector::OnDel) EVT_BUTTON(ID_LOGIC, MultiSelector::Selector::OnLogic) EVT_COMBOBOX(ID_FCOMBO, MultiSelector::Selector::OnChangeField) EVT_COMBOBOX(ID_VCOMBO, MultiSelector::Selector::OnChangeValue) EVT_TEXT(ID_VTEXT, MultiSelector::Selector::OnChangeValue) EVT_BUTTON(ID_BROWSE, MultiSelector::Selector::OnBrowse) END_EVENT_TABLE(); BEGIN_EVENT_TABLE(SelectProfilesPanel, wxPanel) EVT_BUTTON(wxID_FIND, SelectProfilesPanel::OnFind) EVT_TEXT(ID_KM, SelectProfilesPanel::OnChangeValue) EVT_TEXT(ID_MGRS, SelectProfilesPanel::OnChangeValue) EVT_COMBOBOX(ID_SCOMBO, SelectProfilesPanel::OnChangeSearch) EVT_BUTTON(ID_SAVE_SEARCH, SelectProfilesPanel::OnSave) EVT_BUTTON(ID_DEL_SEARCH, SelectProfilesPanel::OnDelete) END_EVENT_TABLE(); // This is a 'ctype facet' that defines which characters are treated // as whitespace. We want to use ',' as a separator, and NOT ' ' so that // values can contain ' '. struct field_reader: std::ctype<char> { field_reader(): std::ctype<char>(get_table()) {} static std::ctype_base::mask const* get_table() { static std::vector<std::ctype_base::mask> rc(table_size, std::ctype_base::mask()); rc['\n'] = std::ctype_base::space; rc[','] = std::ctype_base::space; return &rc[0]; } }; SelectProfilesPanel::SelectProfilesPanel( wxWindow *parent, wxString const &title, wxWindowID winid, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxPanel(parent, winid, pos, size, style, name) , m_saved(0) , m_saveBtn(0) , m_delBtn(0) , m_selectp(0) , m_findBtn(0) , m_pcountLbl(0) , m_km(0) , m_mgrs(0) , findNotify(0) { setup(title); // add self to set of instances m_instances.insert(this); } SelectProfilesPanel::~SelectProfilesPanel() { // remove self from list of instances std::set<SelectProfilesPanel*>::iterator it = m_instances.find(this); Assert2(it != m_instances.end(), "SelectProfilesPanel::~SelectProfilesPanel: oops"); m_instances.erase(it); } MultiSelector::Selector::Selector(MultiSelector *parent) : wxPanel(parent->m_scrolled, wxID_ANY) , multisel(parent) , sizer(0) , field(0) , value(0) , newBtn(0) , delBtn(0) , logicBtn(0) , logic(true) // OR logic , mode(COMBO_BOX) , id(next_id++) { setup(); } void MultiSelector::Selector::setup() { sizer = new wxBoxSizer(wxHORIZONTAL); field = new wxComboBox(this, ID_FCOMBO, _(""), wxDefaultPosition, wxSize(200, 30), multisel->fstrings(), wxCB_DROPDOWN | wxCB_READONLY); // start with comboBox visible value = new wxComboBox(this, ID_VCOMBO, _(""), wxDefaultPosition, wxDefaultSize, multisel->vstrings(), wxCB_DROPDOWN | wxCB_READONLY); // ... and the text/browse controls hidden text = new wxTextCtrl(this, ID_VTEXT, _("")); text->Hide(); browse = new wxButton(this, ID_BROWSE, _("..."), wxDefaultPosition, wxSize(30, 30)); browse->Hide(); browse->SetToolTip(wxT("Browse...")); newBtn = new wxButton(this, ID_NEWB, _("+"), wxDefaultPosition, wxSize(30, 30)); newBtn->SetToolTip(wxT("new Selector")); delBtn = new wxButton(this, ID_DELB, _("-"), wxDefaultPosition, wxSize(30, 30)); delBtn->SetToolTip(wxT("delete Selector")); logicBtn = new wxButton(this, ID_LOGIC, _("|"), wxDefaultPosition, wxSize(30, 30)); logicBtn->SetBackgroundColour(*wxLIGHT_GREY); logicBtn->SetToolTip(wxT("and / or")); sizer->Add(logicBtn, 0, wxEXPAND | wxALL, 1); sizer->Add(field, 0, wxEXPAND | wxALL, 1); sizer->Add(value, 1, wxEXPAND | wxALL, 1); sizer->Add(text, 1, wxEXPAND | wxALL, 1); sizer->Add(browse, 0, wxEXPAND | wxALL, 1); sizer->Add(newBtn, 0, wxEXPAND | wxALL, 1); sizer->Add(delBtn, 0, wxEXPAND | wxALL, 1); this->SetSizer(sizer); // after everything else is constructed field->SetSelection(0); // default to Profile Key } wxArrayString MultiSelector::fstrings() // array of field names { wxArrayString ret; for (size_t i=0; i<m_sel_fields.size(); ++i) { ret.push_back( wxString(m_sel_fields[i].name.c_str(), *wxConvCurrent) ); } return ret; } wxArrayString MultiSelector::vstrings() // array of default values { wxArrayString ret; // ret.push_back(_("One")); // ret.push_back(_("Two")); // ret.push_back(_("Three")); return ret; } void MultiSelector::setup(wxString const &title) { std::map<std::string, DBField> meta_fields; if (!db->listMetaFields(meta_fields)) { error << "MultiSelector::Selector::setup: can't read metadata field names" << endl; } m_sel_fields.push_back(SelectorField("Profile Key", "profile_key")); m_sel_fields.push_back(SelectorField("Dataset", "dataset")); std::map<std::string, DBField>::const_iterator it; for (it = meta_fields.begin(); it != meta_fields.end(); ++it) { m_sel_fields.push_back(SelectorField(it->first, it->second.field_name, it->second.field_type)); } m_selsizer = new wxBoxSizer(wxVERTICAL); m_scrolled = new wxScrolledWindow(this, wxID_ANY, wxPoint(0,0), wxSize(465,150), wxVSCROLL); int pixelsPerUnitX = 10; int pixelsPerUnitY = 10; int unitsX = 10; int unitsY = 1000; // m_scrolled->SetBackgroundColour( "GREEN" ); m_scrolled->SetScrollbars(pixelsPerUnitX, pixelsPerUnitY, unitsX, unitsY); addSelectorPos(0); m_scrolled->SetSizer(m_selsizer); } int MultiSelector::findSelector(int id) { for (size_t i=0; i<m_selectors.size(); ++i) { if (m_selectors[i]->id == id) { return i; } } return -1; } void MultiSelector::addSelectorPos(int pos) { Selector *sel = new Selector(this); if (pos == 0) { sel->logicBtn->Enable(false); sel->delBtn->Enable(false); } m_selectors.insert(m_selectors.begin()+pos, sel); m_selsizer->Insert(pos, sel, 0, wxEXPAND | wxALL, 2); m_selsizer->Layout(); m_scrolled->FitInside(); } void MultiSelector::addSelectorId(int id) { int pos = findSelector(id); Assert2(pos>=0, "oops"); addSelectorPos(pos+1); // insert after } void MultiSelector::delSelectorPos(int pos) { Selector *sel = m_selectors[pos]; m_selectors.erase(m_selectors.begin()+pos); sel->Destroy(); m_selsizer->Layout(); m_scrolled->FitInside(); } void MultiSelector::delSelectorId(int id) { int pos = findSelector(id); Assert2(pos>=0, "oops"); if (m_selectors.size() > 1) // don't delete the only item { delSelectorPos(pos); } } // remove all selectors including the first void MultiSelector::clear() { int n = m_selectors.size(); for (int i=n-1; i>=0; --i) { delSelectorPos(i); } } const DBField* MultiSelector::findDBFieldFromName(const string& name) { DBField *ret = 0; for (size_t i=0; i<m_sel_fields.size(); ++i) { if (m_sel_fields[i].name == name) { ret = &m_sel_fields[i].db_field; break; } } return ret; } // return the query from the MultiSelector std::string MultiSelector::sqlQuery() { string sql_query = ""; for (size_t i=0; i<m_selectors.size(); ++i) { string name = m_selectors[i]->getName(); const DBField *dbf = findDBFieldFromName(name); Assert2(dbf, "MultiSelector::sqlQuery(): field not found"); string value_str = m_selectors[i]->getValue(); if (dbf->field_name.empty() || value_str.empty()) continue; if (! sql_query.empty()) { sql_query = "( " + sql_query + (m_selectors[i]->logic ? " ) OR " : " ) AND "); } if (dbf->field_type == "DOUBLE") // do a numeric comparison { // if value field does not start with a comparison op then assume = if ( (value_str.find("=") != 0) && (value_str.find("!=") != 0) && (value_str.find("<") != 0) && (value_str.find("<=") != 0) && (value_str.find(">") != 0) && (value_str.find(">=") != 0) && (value_str.find("<>") != 0) ) { value_str = "= " + value_str; } sql_query += dbf->field_name + " " + value_str; // no quotes needed for numeric value } else // is a string type { // does value contain SQL metacharacters? if (value_str.find_first_of("_%") != value_str.npos) { // use LIKE sql_query += dbf->field_name + " LIKE '" + value_str + "'"; } else { // use a string '=' search sql_query += dbf->field_name + " = '" + value_str + "'"; } } } return sql_query; } void MultiSelector::update() { for (size_t i=0; i<m_selectors.size(); ++i) { m_selectors[i]->update(); } } void MultiSelector::Selector::OnNew(wxCommandEvent& event) { cout << "OnNew(): Event Id = " << event.GetId() << " Selector ID = " << id << endl; multisel->addSelectorId(id); multisel->hasChanged(); MyFrame::refreshMessageWindow(); } void MultiSelector::Selector::OnDel(wxCommandEvent& event) { cout << "OnDel(): Event Id = " << event.GetId() << " Selector ID = " << id << endl; multisel->delSelectorId(id); multisel->hasChanged(); MyFrame::refreshMessageWindow(); } void MultiSelector::Selector::OnLogic(wxCommandEvent& event) { cout << "OnLogic(): Event Id = " << event.GetId() << " Selector ID = " << id << endl; logic = ! logic; setLogicBtn(logic); multisel->hasChanged(); MyFrame::refreshMessageWindow(); } static std::string geoBoxQuery(std::string mylat, std::string mylon, std::string dist) { return "( geoBox(s_lat, s_long, " + mylat + ", " + mylon + ", " + dist + ") = TRUE ) "; } static std::string geoCircleQuery(std::string mylat, std::string mylon, std::string dist) { return "( geoCircle(s_lat, s_long, " + mylat + ", " + mylon + ", " + dist + ") = TRUE ) "; } static std::string distQuery(std::string mylat, std::string mylon, std::string dist) { if (mylat.empty() || mylon.empty() || dist.empty()) { return ""; } // return geoBoxQuery(mylat, mylon, dist); // surprisingly, this is slower than geoCircleQuery return geoCircleQuery(mylat, mylon, dist); } LatLonStrings SelectProfilesPanel::latLonStrings() { LatLonStrings ret; string mgrs_string(m_mgrs->GetValue().ToUTF8()); if ( !mgrs_string.empty() ) { ret = ::latLonStrings(mgrs_string); } return ret; } // return the distance query std::string SelectProfilesPanel::distQuery() { LatLonStrings latlon = latLonStrings(); return ::distQuery(latlon.lat, latlon.lon, std::string(m_km->GetValue().ToUTF8())); } static std::string sqlWhereClause(std::string dist_query, std::string sel_query) { // construct where clause like: // dist_query AND ( meta_query OR ... meta_query ) if ( dist_query.empty() && sel_query.empty() ) { return ""; } string where_clause = dist_query; if ( ! dist_query.empty() && ! sel_query.empty() ) { sel_query = "AND (" + sel_query + ")"; } where_clause += sel_query; return where_clause; } static std::string sqlFullQuery(std::string dist_query, std::string sel_query) { // construct query like: // SELECT * FROM Profiles WHERE where_clause string where_clause = sqlWhereClause(dist_query, sel_query); if ( where_clause.empty() ) { return ""; } string sql_query = "SELECT * FROM Profiles WHERE " + where_clause; return sql_query; } // return the query for the entire panel std::string SelectProfilesPanel::sqlQuery() { return sqlFullQuery(distQuery(), m_selectp->sqlQuery()); } // return the query for the entire panel std::string SelectProfilesPanel::sqlWhereClause() { return ::sqlWhereClause(distQuery(), m_selectp->sqlQuery()); } MultiSelector * SelectProfilesPanel::createMultiSelector(SelectProfilesPanel *parent, wxString const &title) { MultiSelector* panel = new MultiSelector(parent, title, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER); return panel; } void SelectProfilesPanel::OnFind(wxCommandEvent& event) { cout << "OnFind(): Id = " << event.GetId() << endl; string sql_query = sqlQuery(); if (sql_query.empty()) { error << "SelectProfilesPanel::OnFind(): SQL query is empty" << endl; } else { // don't read - just check the size and return a ProfileRangeDB if (!db->isConnected()) { cout << "SelectProfilesPanel::OnFind(): No database connection" << endl; } else { ProfileRangeDB prdb(db, sql_query); m_selected_profiles = ProfileRange(prdb); // report how many found size_t len = 32; wxChar buf[len]; int num_profiles_found = m_selected_profiles.size(); wxSnprintf(buf, len, _("%d Profiles Selected"), num_profiles_found); m_pcountLbl->SetLabel(buf); if (num_profiles_found == 0) { error << "SelectProfilesPanel::OnFind(): 0 Profiles found" << endl; } else { ok << "SelectProfilesPanel::OnFind(): " << num_profiles_found << " Profiles found" << endl; } // grey out the button until a control is changed m_findBtn->Enable(false); } } if (findNotify) (*findNotify)(); } void SelectProfilesPanel::OnDelete(wxCommandEvent& event) { cout << "OnDelete(): Event Id = " << event.GetId() << endl; string sel(m_saved->GetValue().ToUTF8()); if (sel.empty()) { // pop up error dialog wxMessageBox( _("Select a search to delete and try again."), _("Delete search"), wxOK | wxICON_EXCLAMATION, this); return; } std::map<std::string, std::string>::iterator it; if ( (it = m_searches.find(sel)) == m_searches.end() ) { // pop up error dialog wxMessageBox( "Error: no search named " + sel, _("Delete search"), wxOK | wxICON_EXCLAMATION, this); return; } else { // delete search if (wxYES == wxMessageBox("Delete search " + sel + "?", _("Delete search"), wxNO_DEFAULT | wxYES_NO | wxICON_EXCLAMATION, this)) { cout << "Delete search: " << sel << endl; m_searches.erase(it); int d = m_saved->FindString(wxString(sel.c_str(), *wxConvCurrent)); m_saved->Delete(d); m_saved->SetValue(""); } } saveSearchesToFile(); updateSearches(); MyFrame::refreshMessageWindow(); } void SelectProfilesPanel::OnSave(wxCommandEvent& event) { cout << "OnSave(): Event Id = " << event.GetId() << endl; string sel(m_saved->GetValue().ToUTF8()); if (sel.empty()) { // pop up error dialog wxMessageBox( _("Enter a search name and try again."), _("Save search"), wxOK | wxICON_EXCLAMATION, this); return; } ostringstream oss; oss << *this; std::map<std::string, std::string>::const_iterator it; if ( (it = m_searches.find(sel)) == m_searches.end() ) { // new saved search if (wxYES == wxMessageBox("Save search as " + sel + "?", _("Save search"), wxNO_DEFAULT | wxYES_NO | wxICON_EXCLAMATION, this)) { cout << "Save search: new search " << sel << endl; m_searches[sel] = oss.str(); m_saved->Append(wxString(sel.c_str(), *wxConvCurrent)); } } else { // pop up confirm dialog to overwrite if (wxYES == wxMessageBox(sel + " exists. Overwrite?", _("Save search"), wxNO_DEFAULT | wxYES_NO | wxICON_EXCLAMATION, this)) { cout << "Save search: overwriting " << sel << endl; m_searches[sel] = oss.str(); } } saveSearchesToFile(); updateSearches(); MyFrame::refreshMessageWindow(); } void SelectProfilesPanel::refresh() { // update all selection lists m_selectp->update(); } // update the choices in the value combo void MultiSelector::Selector::updateValues(DBField const *dbf) { vals.clear(); if (dbf->field_type == "DOUBLE") { // use the text widget alone mode = TEXT; value->Hide(); text->Show(); text->Clear(); browse->Hide(); } else { // NB getting all the values can take a few seconds if we are querying for // profile IDs and there are say 1 million profiles. // We optimize by searching only for the first SINGLE_CHOICE_MAX + 1 elements. // In the case of a MEGA_CHOICE we must do a full search when the browse button is pressed. if (!db->listValues(dbf->field_name, vals, SINGLE_CHOICE_MAX + 1)) { error << "SelectProfilesPanel::refreshDatasetList(): " << dbf->field_name << " could not be read: " << endl; } // remove NULL if present set<string>::const_iterator it = vals.find(""); if (it != vals.end()) { vals.erase(it); } if (vals.size() > COMBO_MAX) { if (vals.size() > SINGLE_CHOICE_MAX) { // use the text/browse buttons with MegaChoice dialog mode = MEGA_CHOICE; } else { // use the text/browse buttons with wxSingleChoiceDialog mode = SINGLE_CHOICE; } value->Hide(); text->Show(); text->Clear(); browse->Show(); } else { // use Combo box mode = COMBO_BOX; value->Show(); text->Hide(); browse->Hide(); if (vals.empty()) { value->Clear(); } else { setItemContainerStrings(value, vals); value->SetSelection(0); } } } multisel->m_selsizer->Layout(); multisel->m_scrolled->FitInside(); } std::string MultiSelector::Selector::getLogic() const { return logic ? "OR" : "AND"; } std::string MultiSelector::Selector::getName() const { string name(field->GetValue().ToUTF8()); return name; } void MultiSelector::Selector::setLogic(string logic_str) { logic = logic_str == "OR" ? true : false; setLogicBtn(logic); } void MultiSelector::Selector::setLogicBtn(bool logic) { logicBtn->SetLabel(logic ? _("|") : _("&&")); } void MultiSelector::Selector::setName(string const &name) { field->SetValue(name); } std::string MultiSelector::Selector::getValue() const { string value_str; switch (mode) { case Selector::COMBO_BOX: value_str = value->GetValue().ToUTF8(); break; case Selector::SINGLE_CHOICE: case Selector::TEXT: case Selector::MEGA_CHOICE: value_str = text->GetValue().ToUTF8(); break; default: Assert2(0, "MultiSelector::Selector::getValue(): oops"); } cleanup(value_str); // remove leading/trailing space return value_str; } std::string MultiSelector::Selector::getStreamedValue() const { // for streaming we represent the empty string as ' ' string ret = getValue(); if (ret.empty()) ret = " "; return ret; } void MultiSelector::Selector::setValue(string const &val_str) { string value_str; switch (mode) { case Selector::COMBO_BOX: value->SetValue(val_str); break; case Selector::SINGLE_CHOICE: case Selector::TEXT: case Selector::MEGA_CHOICE: text->SetValue(val_str); break; default: Assert2(0, "MultiSelector::Selector::setValue(): oops"); } } void MultiSelector::Selector::setStreamedValue(string const &val_str) { // for streaming we represent the empty string as ' ' setValue( val_str == " " ? "" : val_str); } const DBField * MultiSelector::Selector::getDbf() { string name(field->GetValue().ToUTF8()); const DBField *dbf = multisel->findDBFieldFromName(name); if (!dbf) { cout << "MultiSelector::Selector::dbf(): field name = " << name << endl; Assert2(false, "MultiSelector::Selector::dbf(): field not found"); } return dbf; } void MultiSelector::Selector::update() { updateValues(getDbf()); } void MultiSelector::Selector::OnChangeField(wxCommandEvent& event) { cout << "value(): Event Id = " << event.GetId() << " Selector ID = " << id << endl; // update the choices in the value combo update(); multisel->hasChanged(); MyFrame::refreshMessageWindow(); } void MultiSelector::Selector::OnChangeValue(wxCommandEvent& event) { cout << "OnChangeValue(): Event Id = " << event.GetId() << " Selector ID = " << id << endl; multisel->hasChanged(); MyFrame::refreshMessageWindow(); } void MultiSelector::Selector::OnBrowse(wxCommandEvent& event) { cout << "OnBrowse(): Event Id = " << event.GetId() << " Selector ID = " << id << endl; switch(mode) { case SINGLE_CHOICE: singleChoice(); break; case MEGA_CHOICE: megaChoice(); break; default: Assert2(0, "MultiSelector::Selector::OnBrowse: mode error"); } } void MultiSelector::Selector::megaChoice() { // make sure we have the entire list of values const DBField *dbf = getDbf(); if (!db->listValues(dbf->field_name, vals)) { error << "MultiSelector::Selector::megaChoice(): " << dbf->field_name << " could not be read: " << endl; } // pop up MegaChoiceDialog (SINGLE mode) to select profile key MegaChoiceDialog dialog(NULL, wxID_ANY, _("Select Profile Key"), vals); int ret; if ((ret = dialog.ShowModal()) == wxID_OK) { text->SetValue(dialog.GetStringSelection()); multisel->hasChanged(); MyFrame::refreshMessageWindow(); } } void MultiSelector::Selector::singleChoice() { // pop up a single selection dialog wxArrayString choices; set<string>::const_iterator it; for (it = vals.begin(); it != vals.end(); ++it) { choices.push_back( wxString(it->c_str(), *wxConvCurrent) ); } wxSingleChoiceDialog dialog(this, field->GetValue(), _("Select"), choices); dialog.SetSelection(0); if (dialog.ShowModal() == wxID_OK) { text->SetValue(dialog.GetStringSelection()); multisel->hasChanged(); MyFrame::refreshMessageWindow(); } } void SelectProfilesPanel::OnChangeValue(wxCommandEvent& event) { cout << "OnChangeValue(): Event Id = " << event.GetId() << endl; hasChanged(); MyFrame::refreshMessageWindow(); } void SelectProfilesPanel::hasChanged() { // when one of the controls is changed, reset the number of profiles to 0 // and enable the Find Profiles button m_selected_profiles.clear(); m_pcountLbl->SetLabel(_("0 Profiles Selected")); m_findBtn->Enable(true); m_saved->SetValue(""); if (findNotify) (*findNotify)(); } void addDBFunctions(Database & db) { // The magic number 111 is the distance subtended by one degree at the surface of the earth in km // R = 6378km // D = R * 2pi / 360 = 111 string geoBoxDefn = "CREATE FUNCTION geoBox (lat DOUBLE, lon DOUBLE, mylat DOUBLE, mylon DOUBLE, dist DOUBLE)\n" "RETURNS BOOL DETERMINISTIC\n" "BEGIN\n" "set @dlon = dist/abs(cos(radians(mylat))*111);\n" "set @dlat = dist/111;\n" "RETURN lon BETWEEN (mylon - @dlon) AND (mylon + @dlon) AND\n" " lat BETWEEN (mylat - @dlat) AND (mylat + @dlat);\n" "END\n"; string geoDistDefn = "CREATE FUNCTION geoDist (lat DOUBLE, lon DOUBLE, mylat DOUBLE, mylon DOUBLE)\n" "RETURNS DOUBLE DETERMINISTIC\n" "BEGIN\n" "RETURN 6378 * 2 * ASIN(SQRT( POWER(SIN(radians(mylat - lat)/ 2), 2) + " "COS(radians(mylat)) * COS(radians(lat)) * " "POWER(SIN(radians(mylon - lon) / 2), 2) ));\n" "END\n"; string geoCircleDefn = "CREATE FUNCTION geoCircle (lat DOUBLE, lon DOUBLE, mylat DOUBLE, mylon DOUBLE, dist DOUBLE)\n" "RETURNS BOOL DETERMINISTIC\n" "RETURN (geoDist(lat, lon, mylat, mylon) <= dist)\n"; (void)db.do_sql("DROP FUNCTION geoBox"); (void)db.do_sql("DROP FUNCTION geoDist"); (void)db.do_sql("DROP FUNCTION geoCircle"); if (!db.do_sql(geoBoxDefn) || !db.do_sql(geoDistDefn) || !db.do_sql(geoCircleDefn)) { error << "SelectProfilesPanel::setup: can't define geoBox/geoDist functions" << endl; } } void SelectProfilesPanel::setup(wxString const &title) { addDBFunctions(*db); wxPanel *panel = this; m_findBtn = new wxButton(panel, wxID_FIND, _("Find Profiles")); wxStaticText *label0 = new wxStaticText(panel, wxID_ANY, _("Searches:")); m_saved = new wxComboBox(panel, ID_SCOMBO, wxEmptyString, wxDefaultPosition, wxSize(80, wxDefaultCoord)); m_saveBtn = new wxButton(panel, ID_SAVE_SEARCH, _("Save..."), wxDefaultPosition, wxSize(50, wxDefaultCoord)); m_delBtn = new wxButton(panel, ID_DEL_SEARCH, _("Delete..."), wxDefaultPosition, wxSize(50, wxDefaultCoord)); m_pcountLbl = new wxStaticText(panel, wxID_ANY, _("0 Profiles Selected")); wxStaticLine* line1 = new wxStaticLine ( this, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); wxStaticText *label1 = new wxStaticText(panel, wxID_ANY, _(" Metadata:")); m_selectp = createMultiSelector(this, _("title")); wxStaticLine* line2 = new wxStaticLine ( this, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); // wxStaticText *label2 = new wxStaticText(panel, wxID_ANY, _(" AND Distance:")); wxStaticText *l_dist = new wxStaticText(panel, wxID_ANY, _("&& Distance")); m_km = new wxTextCtrl(this, ID_KM, _("")); wxStaticText *l_km = new wxStaticText(panel, wxID_ANY, _("(km) from point")); m_mgrs = new wxTextCtrl(this, ID_MGRS, _("")); wxStaticText *l_mgrs = new wxStaticText(panel, wxID_ANY, _("(MGRS)")); wxBoxSizer *vSizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *hSizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *hSizer2 = new wxBoxSizer( wxHORIZONTAL ); vSizer->Add(hSizer, 0, wxEXPAND | wxALL, 5); hSizer->Add(m_findBtn, 0, wxCENTRE | wxRIGHT, 2); hSizer->Add(m_pcountLbl, 0, wxCENTRE | wxRIGHT, 2); hSizer->Add(1, 1, 1, wxEXPAND | wxALL, 2); hSizer->Add(label0, 0, wxCENTRE | wxLEFT, 2); hSizer->Add(m_saved, 0, wxCENTRE | wxLEFT, 2); hSizer->Add(m_saveBtn, 0, wxCENTRE | wxLEFT, 2); hSizer->Add(m_delBtn, 0, wxCENTRE | wxLEFT, 2); vSizer->Add(line1, 0, wxEXPAND | wxUP, 5); vSizer->Add(label1, 0, wxEXPAND | wxUP, 5); vSizer->Add(m_selectp, 1, wxEXPAND | wxUP, 5); vSizer->Add(line2, 0, wxEXPAND | wxUP, 5); // vSizer->Add(label2, 0, wxEXPAND | wxUP, 5); vSizer->Add(hSizer2, 0, wxEXPAND | wxALL, 5); hSizer2->Add(l_dist, 0, wxCENTRE | wxRIGHT, 5); hSizer2->Add(m_km, 1, wxEXPAND | wxRIGHT, 5); hSizer2->Add(l_km, 0, wxCENTRE | wxRIGHT, 5); hSizer2->Add(m_mgrs, 1, wxEXPAND | wxRIGHT, 5); hSizer2->Add(l_mgrs, 0, wxCENTRE | wxRIGHT, 5); panel->SetSizer(vSizer); vSizer->SetSizeHints(this); loadSearchesFromFile(); } void SelectProfilesPanel::loadSearchesFromFile() { ifstream ifs(".fand_searches"); m_searches.clear(); string line; while (getline(ifs, line)) { string search_name, search; int n = line.find(','); search_name = line.substr(0, n); // up to first ',' search = line.substr(n+1); // beyond first ',' m_searches[search_name] = search; } refreshSearches(); } void SelectProfilesPanel::refreshSearches() { // refresh the list of searches displayed in the ComboBox m_saved->Clear(); std::map<std::string, std::string>::const_iterator it; for (it = m_searches.begin(); it != m_searches.end(); ++it) { m_saved->Append(wxString(it->first.c_str(), *wxConvCurrent)); } } void SelectProfilesPanel::saveSearchesToFile() { // Save as one line per search ofstream ofs(".fand_searches"); std::map<std::string, std::string>::const_iterator it; for (it = m_searches.begin(); it != m_searches.end(); ++it) { ofs << it->first << "," << it->second << "\n"; } ofs.close(); } void SelectProfilesPanel::updateSearches() { std::set<SelectProfilesPanel*>::iterator it; for (it = m_instances.begin(); it != m_instances.end(); ++it) { (*it)->refreshSearches(); } } std::ostream & operator<<(std::ostream &os, const MultiSelector &a) { for (int i=a.m_selectors.size()-1; i>=0; --i) // Reverse order { MultiSelector::Selector *s = a.m_selectors[i]; os << s->getLogic() << "," << s->getName() << "," << s->getStreamedValue() << ","; } return os; } std::istream & operator>>(std::istream &is, MultiSelector &a) { a.clear(); is.imbue(std::locale(std::locale(), new field_reader())); string logic, name, value; while (is >> logic >> name >> value) { a.addSelectorPos(0); MultiSelector::Selector *s = a.m_selectors[0]; s->setLogic(logic); s->setName(name); s->update(); s->setStreamedValue(value); if (a.m_selectors.size() > 1) { s = a.m_selectors[1]; s->logicBtn->Enable(true); s->delBtn->Enable(true); } } if (a.m_selectors.empty()) { a.addSelectorPos(0); } MyFrame::refreshMessageWindow(); return is; } std::string getStreamed(wxTextCtrl *p) { string ret = std::string(p->GetValue().ToUTF8()); return ret == "" ? " " : ret; } void setStreamed(wxTextCtrl *p, string const &val) { p->SetValue(val == " " ? "" : val); } std::ostream & operator<<(std::ostream &os, const SelectProfilesPanel &a) { // distance os << getStreamed(a.m_km) << "," << getStreamed(a.m_mgrs) << ","; // MultiSelector if (a.m_selectp) { os << *(a.m_selectp); } return os; } std::istream & operator>>(std::istream &is, SelectProfilesPanel &a) { is.imbue(std::locale(std::locale(), new field_reader())); // distance string km_str, mgrs_str; is >> km_str >> mgrs_str; setStreamed(a.m_km, km_str); setStreamed(a.m_mgrs, mgrs_str); // MultiSelector if (a.m_selectp) { is >> *(a.m_selectp); } return is; } void SelectProfilesPanel::OnChangeSearch(wxCommandEvent& event) { cout << "OnChangeSearch(): Event Id = " << event.GetId() << endl; recallSearch(); MyFrame::refreshMessageWindow(); } void SelectProfilesPanel::recallSearch() { string sel(m_saved->GetStringSelection().ToUTF8()); std::map<std::string, std::string>::const_iterator it; if ( (it = m_searches.find(sel)) != m_searches.end() ) { istringstream iss(it->second); iss >> *this; } hasChanged(); // make sure we are still displaying the selected search name m_saved->SetValue(sel); } // A // -------------------------- // | \ B | // | \ | // | C \ | // F | X | D // | | // | | // | E | // -------------------------- // // dist = 111km; d_lat = 1; d_long = 0.5; // X(60, -3) // A(62, -3) : 222 km N // B(60.72, -1.56) : 113 km NE // C(60.63, -1.74) : 99 km NE // D(60, -0.94) : 120 km E // E(59.1, -3) : 100 km S // F(60, -5.16) : 120 km W // static char meta_defns[] = "SAMPLE_LAT, s_lat, DOUBLE\n" "SAMPLE_LONG, s_long, DOUBLE\n" "WIS, wis, VARCHAR(16)\n" "CEXE, cexe, VARCHAR(16)\n" "LAB, lab, VARCHAR(16)\n" "TAT, tat, VARCHAR(16)\n" "DEF, def, VARCHAR(16)\n"; struct Dist_test { Dist_test() : db(new Database("test", meta_defns)) , idA(Identifiler, "SAMPLE_A-FULL", // ID 1, // contributors 0.001, // delta 0, // mutation rate reference, // evidence_type "BADDIES", // dataset "SAMPLE_A", // sample_id "FULL") // profile_id , idB(Identifiler, "SAMPLE_B-FULL", 1, 0.001, 0, reference, "BADDIES", "SAMPLE_B", "FULL") , idC(Identifiler, "SAMPLE_C-FULL", 1, 0.001, 0, reference, "BADDIES", "SAMPLE_C", "FULL") , idD(Identifiler, "SAMPLE_D-FULL", 1, 0.001, 0, reference, "BADDIES", "SAMPLE_D", "FULL") , idE(Identifiler, "SAMPLE_E-FULL", 1, 0.001, 0, reference, "BADDIES", "SAMPLE_E", "FULL") , idF(Identifiler, "SAMPLE_F-FULL", 1, 0.001, 0, reference, "BADDIES", "SAMPLE_F", "FULL") , A(idA), B(idB), C(idC), D(idD), E(idE), F(idF) { A.m_metadata["s_lat"] = "62"; A.m_metadata["s_long"] = "-3"; B.m_metadata["s_lat"] = "60.72"; B.m_metadata["s_long"] = "-1.56"; C.m_metadata["s_lat"] = "60.63"; C.m_metadata["s_long"] = "-1.74"; D.m_metadata["s_lat"] = "60"; D.m_metadata["s_long"] = "-0.94"; E.m_metadata["s_lat"] = "59.1"; E.m_metadata["s_long"] = "-3"; F.m_metadata["s_lat"] = "60"; F.m_metadata["s_long"] = "-5.16"; } boost::shared_ptr<Database> db; ProfileData idA, idB, idC, idD, idE, idF; DBProfile A, B, C, D, E, F; }; // check distance functions TEST_FIXTURE(Dist_test, dist_test) { CHECK_EQUAL(true, db->connect()); CHECK_EQUAL(true, db->clear()); CHECK_EQUAL(0, db->size()); CHECK_EQUAL(true, db->insert(A)); CHECK_EQUAL(true, db->insert(B)); CHECK_EQUAL(true, db->insert(C)); CHECK_EQUAL(true, db->insert(D)); CHECK_EQUAL(true, db->insert(E)); CHECK_EQUAL(true, db->insert(F)); CHECK_EQUAL(6, db->size()); addDBFunctions(*db); // // test geoBox // string sql_query1 = sqlFullQuery(geoBoxQuery("60", "-3", "111"), ""); // cout << sql_query1 << endl; ProfileRangeDB prdb_box(db, sql_query1); // should have found B, C, E CHECK_EQUAL(3, prdb_box.size()); prdb_box.readMyData(); CHECK_EQUAL("SAMPLE_B-FULL", prdb_box[0].data().m_id.c_str()); CHECK_EQUAL("SAMPLE_C-FULL", prdb_box[1].data().m_id.c_str()); CHECK_EQUAL("SAMPLE_E-FULL", prdb_box[2].data().m_id.c_str()); // // test geoCircle // string sql_query2 = sqlFullQuery(geoCircleQuery("60", "-3", "111"), ""); ProfileRangeDB prdb_dist(db, sql_query2); // should have found C, E CHECK_EQUAL(2, prdb_dist.size()); prdb_dist.readMyData(); CHECK_EQUAL("SAMPLE_C-FULL", prdb_dist[0].data().m_id.c_str()); CHECK_EQUAL("SAMPLE_E-FULL", prdb_dist[1].data().m_id.c_str()); } void setID(ProfileData &id, char c, int i) { ostringstream oss; oss << "SAMPLE_ " << c << i; id.m_id = oss.str(); id.m_profile_id = "FULL"; id.m_sample_id = id.m_id + "-" + id.m_profile_id; } #if 0 // results: // // control: count profiles = 0.02 // control: read profiles = 4.04 // geoBox: count profiles = 0.91 // geoBox: read profiles = 3.16 // geoCircle: count profiles = 0.55 // geoCircle: read profiles = 2.44 // // ie geoCircle is actually faster than geoBox // TEST_FIXTURE(Dist_test, dist_timings) { CHECK_EQUAL(true, db->connect()); CHECK_EQUAL(true, db->clear()); CHECK_EQUAL(0, db->size()); int N = 10000; for (int i=0; i<N; ++i) { setID(A.m_data, 'A', i); CHECK_EQUAL(true, db->insert(A)); setID(B.m_data, 'B', i); CHECK_EQUAL(true, db->insert(B)); setID(C.m_data, 'C', i); CHECK_EQUAL(true, db->insert(C)); setID(D.m_data, 'D', i); CHECK_EQUAL(true, db->insert(D)); setID(E.m_data, 'E', i); CHECK_EQUAL(true, db->insert(E)); setID(F.m_data, 'F', i); CHECK_EQUAL(true, db->insert(F)); } CHECK_EQUAL(6*N, db->size()); addDBFunctions(*db); // // control: no distance calculation // string sql_query0 = sqlFullQuery("", "dataset = 'BADDIES'"); Timer t; ProfileRangeDB prdb_control(db, sql_query0); t.stop(); cout << "control: count profiles = " << t << endl; // should have found everything CHECK_EQUAL(6*N, prdb_control.size()); t.start(); prdb_control.readMyData(); t.stop(); cout << "control: read profiles = " << t << endl; // // test geoBox // string sql_query1 = sqlFullQuery(geoBoxQuery("60", "-3", "111"), ""); t.start(); ProfileRangeDB prdb_box(db, sql_query1); t.stop(); cout << "geoBox: count profiles = " << t << endl; // should have found B, C, E CHECK_EQUAL(3*N, prdb_box.size()); t.start(); prdb_box.readMyData(); t.stop(); cout << "geoBox: read profiles = " << t << endl; // // time geoCircle // string sql_query2 = sqlFullQuery(geoCircleQuery("60", "-3", "111"), ""); t.start(); ProfileRangeDB prdb_dist(db, sql_query2); t.stop(); cout << "geoCircle: count profiles = " << t << endl; // should have found C, E CHECK_EQUAL(2*N, prdb_dist.size()); t.start(); prdb_dist.readMyData(); t.stop(); cout << "geoCircle: read profiles = " << t << endl; } #endif
25.058864
138
0.637186
[ "vector" ]
ae1e526549bc0745380cc3fdcb1489fa1df357bc
4,326
hpp
C++
openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/include/xyz/openbmc_project/Time/Owner/server.hpp
sotaoverride/backup
ca53a10b72295387ef4948a9289cb78ab70bc449
[ "Apache-2.0" ]
null
null
null
openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/include/xyz/openbmc_project/Time/Owner/server.hpp
sotaoverride/backup
ca53a10b72295387ef4948a9289cb78ab70bc449
[ "Apache-2.0" ]
null
null
null
openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/include/xyz/openbmc_project/Time/Owner/server.hpp
sotaoverride/backup
ca53a10b72295387ef4948a9289cb78ab70bc449
[ "Apache-2.0" ]
null
null
null
#pragma once #include <map> #include <string> #include <sdbusplus/sdbus.hpp> #include <sdbusplus/server.hpp> #include <systemd/sd-bus.h> #include <tuple> #include <variant> namespace sdbusplus { namespace xyz { namespace openbmc_project { namespace Time { namespace server { class Owner { public: /* Define all of the basic class operations: * Not allowed: * - Default constructor to avoid nullptrs. * - Copy operations due to internal unique_ptr. * - Move operations due to 'this' being registered as the * 'context' with sdbus. * Allowed: * - Destructor. */ Owner() = delete; Owner(const Owner&) = delete; Owner& operator=(const Owner&) = delete; Owner(Owner&&) = delete; Owner& operator=(Owner&&) = delete; virtual ~Owner() = default; /** @brief Constructor to put object onto bus at a dbus path. * @param[in] bus - Bus to attach to. * @param[in] path - Path to attach at. */ Owner(bus::bus& bus, const char* path); enum class Owners { BMC, Host, Both, Split, }; using PropertiesVariant = std::variant< Owners>; /** @brief Constructor to initialize the object from a map of * properties. * * @param[in] bus - Bus to attach to. * @param[in] path - Path to attach at. * @param[in] vals - Map of property name to value for initialization. */ Owner(bus::bus& bus, const char* path, const std::map<std::string, PropertiesVariant>& vals, bool skipSignal = false); /** Get value of TimeOwner */ virtual Owners timeOwner() const; /** Set value of TimeOwner with option to skip sending signal */ virtual Owners timeOwner(Owners value, bool skipSignal); /** Set value of TimeOwner */ virtual Owners timeOwner(Owners value); /** @brief Sets a property by name. * @param[in] _name - A string representation of the property name. * @param[in] val - A variant containing the value to set. */ void setPropertyByName(const std::string& _name, const PropertiesVariant& val, bool skipSignal = false); /** @brief Gets a property by name. * @param[in] _name - A string representation of the property name. * @return - A variant containing the value of the property. */ PropertiesVariant getPropertyByName(const std::string& _name); /** @brief Convert a string to an appropriate enum value. * @param[in] s - The string to convert in the form of * "xyz.openbmc_project.Time.Owner.<value name>" * @return - The enum value. */ static Owners convertOwnersFromString(const std::string& s); private: /** @brief sd-bus callback for get-property 'TimeOwner' */ static int _callback_get_TimeOwner( sd_bus*, const char*, const char*, const char*, sd_bus_message*, void*, sd_bus_error*); /** @brief sd-bus callback for set-property 'TimeOwner' */ static int _callback_set_TimeOwner( sd_bus*, const char*, const char*, const char*, sd_bus_message*, void*, sd_bus_error*); static constexpr auto _interface = "xyz.openbmc_project.Time.Owner"; static const vtable::vtable_t _vtable[]; sdbusplus::server::interface::interface _xyz_openbmc_project_Time_Owner_interface; sdbusplus::SdBusInterface *_intf; Owners _timeOwner{}; }; /* Specialization of sdbusplus::server::bindings::details::convertForMessage * for enum-type Owner::Owners. * * This converts from the enum to a constant c-string representing the enum. * * @param[in] e - Enum value to convert. * @return C-string representing the name for the enum value. */ std::string convertForMessage(Owner::Owners e); } // namespace server } // namespace Time } // namespace openbmc_project } // namespace xyz } // namespace sdbusplus
31.347826
79
0.587147
[ "object" ]
ae2354570c86a6437acc9744e3aab3dcf939f121
1,277
cpp
C++
algorithms/suminbuffer.cpp
VITObelgium/geodynamix
6d3323bc4cae1b85e26afdceab2ecf3686b11369
[ "MIT" ]
null
null
null
algorithms/suminbuffer.cpp
VITObelgium/geodynamix
6d3323bc4cae1b85e26afdceab2ecf3686b11369
[ "MIT" ]
null
null
null
algorithms/suminbuffer.cpp
VITObelgium/geodynamix
6d3323bc4cae1b85e26afdceab2ecf3686b11369
[ "MIT" ]
1
2021-06-16T11:55:27.000Z
2021-06-16T11:55:27.000Z
#include "gdx/algo/suminbuffer.h" namespace gdx { // summed circular area, using sliding window technique. Much slower than integral image technique. void compute_circle_border_offsets(const int radius /*cells*/, std::vector<Cell>& plusRight, std::vector<Cell>& minLeft, std::vector<Cell>& plusDown, std::vector<Cell>& minTop) { plusRight.clear(); minLeft.clear(); plusDown.clear(); minTop.clear(); const int rad2 = radius * radius; for (int dR = -radius; dR <= +radius; ++dR) { const int dR2 = dR * dR; for (int dC = -radius; dC <= +radius; ++dC) { if (dR2 + dC * dC <= rad2 && dR2 + (dC + 1) * (dC + 1) > rad2) { plusRight.emplace_back(dR, dC); // its a right border } if (dR2 + dC * dC <= rad2 && dR2 + (dC - 1) * (dC - 1) > rad2) { minLeft.emplace_back(dR, dC - 1); // its a left border } if (dR2 + dC * dC <= rad2 && (dR + 1) * (dR + 1) + dC * dC > rad2) { plusDown.emplace_back(dR, dC); // its bottom border } if (dR2 + dC * dC <= rad2 && (dR - 1) * (dR - 1) + dC * dC > rad2) { minTop.emplace_back(dR - 1, dC); // its top border } } } } }
35.472222
100
0.507439
[ "vector" ]
ae2438562a71136369270aefccaa464cb4ffb001
1,710
cc
C++
HLTrigger/JetMET/src/AlphaT.cc
pasmuss/cmssw
566f40c323beef46134485a45ea53349f59ae534
[ "Apache-2.0" ]
null
null
null
HLTrigger/JetMET/src/AlphaT.cc
pasmuss/cmssw
566f40c323beef46134485a45ea53349f59ae534
[ "Apache-2.0" ]
null
null
null
HLTrigger/JetMET/src/AlphaT.cc
pasmuss/cmssw
566f40c323beef46134485a45ea53349f59ae534
[ "Apache-2.0" ]
null
null
null
#include <numeric> #include <cmath> #include "HLTrigger/JetMET/interface/AlphaT.h" double AlphaT::value_(std::vector<bool> * jet_sign) const { // Clear pseudo-jet container if (jet_sign) { jet_sign->clear(); jet_sign->resize(et_.size()); } // check the size of the input collection if (et_.size() == 0) // empty jet collection, return AlphaT = 0 return 0.; if (et_.size() > (unsigned int) std::numeric_limits<unsigned int>::digits) // too many jets, return AlphaT = a very large number return std::numeric_limits<double>::max(); // Momentum sums in transverse plane const double sum_et = std::accumulate( et_.begin(), et_.end(), 0. ); const double sum_px = std::accumulate( px_.begin(), px_.end(), 0. ); const double sum_py = std::accumulate( py_.begin(), py_.end(), 0. ); // Minimum Delta Et for two pseudo-jets double min_delta_sum_et = sum_et; if(setDHtZero_){ min_delta_sum_et = 0.; }else{ for (unsigned int i = 0; i < (1U << (et_.size() - 1)); i++) { //@@ iterate through different combinations double delta_sum_et = 0.; for (unsigned int j = 0; j < et_.size(); ++j) { //@@ iterate through jets if (i & (1U << j)) delta_sum_et -= et_[j]; else delta_sum_et += et_[j]; } delta_sum_et = std::abs(delta_sum_et); if (delta_sum_et < min_delta_sum_et) { min_delta_sum_et = delta_sum_et; if (jet_sign) { for (unsigned int j = 0; j < et_.size(); ++j) (*jet_sign)[j] = ((i & (1U << j)) == 0); } } } } // Alpha_T return (0.5 * (sum_et - min_delta_sum_et) / std::sqrt( sum_et*sum_et - (sum_px*sum_px+sum_py*sum_py) )); }
31.666667
109
0.596491
[ "vector" ]
ae26303ba74be148559dda44769fec7cdcc4fb7d
1,550
cpp
C++
CounterStatistic.cpp
fakeNetflix/facebook-repo-treadmill
c38d09e1faa44c296b49111bbe45760ce84212be
[ "BSD-3-Clause" ]
null
null
null
CounterStatistic.cpp
fakeNetflix/facebook-repo-treadmill
c38d09e1faa44c296b49111bbe45760ce84212be
[ "BSD-3-Clause" ]
null
null
null
CounterStatistic.cpp
fakeNetflix/facebook-repo-treadmill
c38d09e1faa44c296b49111bbe45760ce84212be
[ "BSD-3-Clause" ]
null
null
null
/* * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * */ #include "treadmill/CounterStatistic.h" #include "treadmill/Util.h" #include <mutex> #include <unordered_map> #include <glog/logging.h> namespace facebook { namespace windtunnel { namespace treadmill { /** * Print out all the statistic */ void CounterStatistic::printStatistic() const { LOG(INFO) << "Count: " << count_; for (const auto& p : subkey_count_) { LOG(INFO) << "Count[" << p.first << "]: " << p.second; } } folly::dynamic CounterStatistic::toDynamic() const { folly::dynamic map = folly::dynamic::object; map["count"] = this->count_; for (const auto& p : subkey_count_) { map[p.first] = p.second; } return map; } std::unordered_map<std::string, int64_t> CounterStatistic::getCounters() const { std::unordered_map<std::string, int64_t> m; m[name_] = count_; for (const auto& p : subkey_count_) { m[name_ + '.' + p.first] = p.second; } return m; } void CounterStatistic::combine(const Statistic& stat0) { const CounterStatistic& stat = dynamic_cast<const CounterStatistic&>(stat0); count_ += stat.count_; for (const auto& p : stat.subkey_count_) { subkey_count_[p.first] += p.second; } } } // namespace treadmill } // namespace windtunnel } // namespace facebook
23.846154
80
0.676774
[ "object" ]